Angband
Functions | Variables
game-world.c File Reference

Game core management of the game world. More...

#include "angband.h"
#include "cmds.h"
#include "effects.h"
#include "game-world.h"
#include "generate.h"
#include "init.h"
#include "mon-make.h"
#include "mon-move.h"
#include "mon-util.h"
#include "obj-curse.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-knowledge.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-timed.h"
#include "player-util.h"
#include "source.h"
#include "target.h"
#include "trap.h"
#include "z-queue.h"

Functions

bool is_daytime (void)
 Say whether it's daytime or not. More...
 
int turn_energy (int speed)
 The amount of energy gained in a turn by a player or monster. More...
 
static void recharged_notice (const struct object *obj, bool all)
 If player has inscribed the object with "!!", let him know when it's recharged. More...
 
static void recharge_objects (void)
 Recharge activatable objects in the player's equipment and rods in the inventory and on the ground. More...
 
void play_ambient_sound (void)
 Play an ambient sound dependent on dungeon level, and day or night in town. More...
 
static void decrease_timeouts (void)
 Helper for process_world – decrement player->timed[] and curse effect fields. More...
 
static void make_noise (struct player *p)
 Every turn, the character makes enough noise that nearby monsters can use it to home in. More...
 
static void update_scent (void)
 Characters leave scent trails for perceptive monsters to track. More...
 
void process_world (struct chunk *c)
 Handle things that need updating once every 10 game turns. More...
 
static void process_player_cleanup (void)
 Housekeeping after the processing of a player command. More...
 
void process_player (void)
 Process player commands from the command queue, finishing when there is a command using energy (any regular game command), or we run out of commands and need another from the user, or the character changes level or dies, or the game is stopped. More...
 
void on_new_level (void)
 Housekeeping on arriving on a new level. More...
 
static void on_leave_level (void)
 Housekeeping on leaving a level. More...
 
void run_game_loop (void)
 The main game loop. More...
 

Variables

u16b daycount = 0
 
u32b seed_randart
 
u32b seed_flavor
 
s32b turn
 
bool character_generated
 
bool character_dungeon
 
const byte extract_energy [200]
 This table allows quick conversion from "speed" to "energy" The basic function WAS ((S>=110) ? (S-110) : (100 / (120-S))) Note that table access is much quicker than computation. More...
 

Detailed Description

Game core management of the game world.

Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Function Documentation

static void decrease_timeouts ( void  )
static
bool is_daytime ( void  )
static void make_noise ( struct player p)
static

Every turn, the character makes enough noise that nearby monsters can use it to home in.

This function actually just computes distance from the player; this is used in combination with the player's stealth value to determine what monsters can hear. We mark the player's grid with 0, then fill in the noise field of every grid that the player can reach with that "noise" (actally distance) plus the number of steps needed to reach that grid

  • so higher values mean further from the player.

Monsters use this information by moving to adjacent grids with lower noise values, thereby homing in on the player even though twisty tunnels and mazes. Monsters have a hearing value, which is the largest sound value they can detect.

References cave, ddx_ddd, ddy_ddd, heatmap::grids, chunk::height, i_to_yx(), chunk::noise, player::px, player::py, q_free(), q_len(), q_new(), q_pop_int, q_push_int, square_in_bounds(), square_isnoflow(), chunk::width, and yx_to_i().

Referenced by process_world().

static void on_leave_level ( void  )
static

Housekeeping on leaving a level.

References EVENT_MESSAGE_FLUSH, event_signal(), notice_stuff(), redraw_stuff(), and update_stuff().

Referenced by run_game_loop().

void on_new_level ( void  )
void play_ambient_sound ( void  )

Play an ambient sound dependent on dungeon level, and day or night in town.

References player::depth, is_daytime(), and sound().

Referenced by on_new_level(), and process_world().

void process_player ( void  )

Process player commands from the command queue, finishing when there is a command using energy (any regular game command), or we run out of commands and need another from the user, or the character changes level or dies, or the game is stopped.

Notice the annoying code to handle "pack overflow", which must come first just in case somebody manages to corrupt the savefiles by clever use of menu commands or something. (Can go? NRM)

Notice the annoying code to handle "monster memory" changes, which allows us to avoid having to update the window flags every time we change any internal monster memory field, and also reduces the number of times that the recall window must be redrawn.

References CMD_GAME, cmd_get_nrepeats(), CMD_SLEEP, cmdq_pop(), cmdq_push(), effect_simple(), player_upkeep::energy_use, EVENT_CHECK_INTERRUPT, EVENT_COMMAND_REPEAT, EVENT_REFRESH, event_signal(), player_upkeep::generate_level, handle_stuff(), player::is_dead, player_upkeep::monster_race, notice_stuff(), NULL, pack_overflow(), player_has, player_resting_complete_special(), player_upkeep::playing, PR_MONSTER, process_player_cleanup(), player_upkeep::redraw, source_none(), player::timed, and player::upkeep.

Referenced by run_game_loop().

static void process_player_cleanup ( void  )
static
void process_world ( struct chunk c)
static void recharge_objects ( void  )
static
static void recharged_notice ( const struct object obj,
bool  all 
)
static

If player has inscribed the object with "!!", let him know when it's recharged.

-LM- Also inform player when first item of a stack has recharged. -HK- Notify all recharges w/o inscription if notify_recharge option set -WP-

References object::artifact, disturb(), msg, object::note, object::number, object_desc(), ODESC_BASE, OPT, and quark_str().

Referenced by recharge_objects().

void run_game_loop ( void  )
int turn_energy ( int  speed)

The amount of energy gained in a turn by a player or monster.

References extract_energy, angband_constants::move_energy, and z_info.

Referenced by describe_effect(), process_monsters(), process_world(), and run_game_loop().

static void update_scent ( void  )
static

Characters leave scent trails for perceptive monsters to track.

Scent is rather more limited than sound. Many creatures cannot use it at all, it doesn't extend very far outwards from the character's current position, and monsters can use it to home in the character, but not to run away.

Scent is valued according to age. When a character takes his turn, scent is aged by one, and new scent is laid down. Monsters have a smell value which indicates the oldest scent they can detect. Grids where the player has never been will have scent 0. The player's grid will also have scent 0, but this is OK as no monster will ever be smelling it.

References cave, ddx_ddd, ddy_ddd, heatmap::grids, chunk::height, player::px, player::py, chunk::scent, square_in_bounds(), square_isnoscent(), and chunk::width.

Referenced by process_world().

Variable Documentation

bool character_dungeon
bool character_generated
u16b daycount = 0
const byte extract_energy[200]
Initial value:
=
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3,
3, 3, 3, 3, 3, 4, 4, 4, 4, 4,
5, 5, 5, 5, 6, 6, 7, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 36, 37, 37,
38, 38, 39, 39, 40, 40, 40, 41, 41, 41,
42, 42, 42, 43, 43, 43, 44, 44, 44, 44,
45, 45, 45, 45, 45, 46, 46, 46, 46, 46,
47, 47, 47, 47, 47, 48, 48, 48, 48, 48,
49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
}

This table allows quick conversion from "speed" to "energy" The basic function WAS ((S>=110) ? (S-110) : (100 / (120-S))) Note that table access is much quicker than computation.

Note that the table has been changed at high speeds. From "Slow (-40)" to "Fast (+30)" is pretty much unchanged, but at speeds above "Fast (+30)", one approaches an asymptotic effective limit of 50 energy per turn. This means that it is relatively easy to reach "Fast (+30)" and get about 40 energy per turn, but then speed becomes very "expensive", and you must get all the way to "Fast (+50)" to reach the point of getting 45 energy per turn. After that point, furthur increases in speed are more or less pointless, except to balance out heavy inventory.

Note that currently the fastest monster is "Fast (+30)".

Referenced by turn_energy().

u32b seed_flavor
u32b seed_randart
s32b turn