cave-map.c File Reference

Lighting and map management functions. More...

#include "angband.h"
#include "cave.h"
#include "init.h"
#include "monster.h"
#include "mon-predicate.h"
#include "obj-ignore.h"
#include "obj-pile.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-timed.h"
#include "trap.h"


void map_info (unsigned y, unsigned x, struct grid_data *g)
 This function takes a grid location (x, y) and extracts information the player is allowed to know about it, filling in the grid_data structure passed in 'g'. More...
void square_note_spot (struct chunk *c, int y, int x)
 Memorize interesting viewable object/features in the given grid. More...
void square_light_spot (struct chunk *c, int y, int x)
 Tell the UI that a given map location has been updated. More...
static void cave_light (struct point_set *ps)
 This routine will Perma-Light all grids in the set passed in. More...
static void cave_unlight (struct point_set *ps)
 This routine will "darken" all grids in the set passed in. More...
static void cave_room_aux (struct point_set *seen, int y, int x)
void light_room (int y1, int x1, bool light)
 Illuminate or darken any room containing the given location. More...
void wiz_light (struct chunk *c, struct player *p, bool full)
 Light up the dungeon using "claravoyance". More...
void cave_illuminate (struct chunk *c, bool daytime)
 Light or Darken the town. More...
void cave_known (struct player *p)
 Make map features known, except wall/lava surrounded by wall/lava. More...

Detailed Description

Lighting and map management functions.

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

void cave_illuminate ( struct chunk c,
bool  daytime 
void cave_known ( struct player p)

Make map features known, except wall/lava surrounded by wall/lava.

References cave, player::cave, ddx_ddd, ddy_ddd, square::feat, chunk::height, square_isbright(), square_isprojectable(), chunk::squares, and chunk::width.

Referenced by prepare_next_level().

static void cave_light ( struct point_set ps)

This routine will Perma-Light all grids in the set passed in.

This routine is used (only) by "light_room()"

Dark grids are illuminated.

Also, process all affected monsters.

SMART monsters always wake up when illuminated NORMAL monsters wake up 1/4 the time when illuminated STUPID monsters wake up 1/10 the time when illuminated

References cave, i, square::info, monster::m_timed, square::mon, mon_clear_timed(), MON_TMD_FLG_NOTIFY, monster_is_smart(), monster_is_stupid(), point_set::n, point_set::pts, randint0, sqinfo_on, square_light_spot(), square_monster(), chunk::squares, loc::x, and loc::y.

Referenced by light_room().

static void cave_room_aux ( struct point_set seen,
int  y,
int  x 
static void cave_unlight ( struct point_set ps)

This routine will "darken" all grids in the set passed in.

In addition, some of these grids will be "unmarked".

This routine is used (only) by "light_room()"

References cave, i, square::info, point_set::n, point_set::pts, sqinfo_off, square_forget(), square_isbright(), square_isfloor(), square_light_spot(), chunk::squares, loc::x, and loc::y.

Referenced by light_room().

void light_room ( int  y1,
int  x1,
bool  light 
void map_info ( unsigned  y,
unsigned  x,
struct grid_data g 

This function takes a grid location (x, y) and extracts information the player is allowed to know about it, filling in the grid_data structure passed in 'g'.

The information filled in is as follows:

  • g->f_idx is filled in with the terrain's feature type, or FEAT_NONE if the player doesn't know anything about the grid. The function makes use of the "mimic" field in terrain in order to allow one feature to look like another (hiding secret doors, invisible traps, etc). This will return the terrain type the player "Knows" about, not necessarily the real terrain.
  • g->m_idx is set to the monster index, or 0 if there is none (or the player doesn't know it).
  • g->first_kind is set to the object_kind of the first object in a grid that the player knows about, or NULL for no objects.
  • g->muliple_objects is true if there is more than one object in the grid that the player knows and cares about (to facilitate any special floor stack symbol that might be used).
  • g->in_view is true if the player can currently see the grid - this can be used to indicate field-of-view, such as through the OPT(player, view_bright_light) option.
  • g->lighting is set to indicate the lighting level for the grid: LIGHTING_DARK for unlit grids, LIGHTING_LIT for inherently light grids (lit rooms, etc), LIGHTING_TORCH for grids lit by the player's light source, and LIGHTING_LOS for grids in the player's line of sight. Note that lighting is always LIGHTING_LIT for known "interesting" grids like walls.
  • g->is_player is true if the player is on the given grid.
  • g->hallucinate is true if the player is hallucinating something "strange" for this grid - this should pick a random monster to show if the m_idx is non-zero, and a random object if first_kind is non-zero.

NOTES: This is called pretty frequently, whenever a grid on the map display needs updating, so don't overcomplicate it.

Terrain is remembered separately from objects and monsters, so can be shown even when the player can't "see" it. This leads to things like doors out of the player's view still change from closed to open and so on.

TODO: Hallucination is currently disabled (it was a display-level hack before, and we need it to be a knowledge-level hack). The idea is that objects may turn into different objects, monsters into different monsters, and terrain may be objects, monsters, or stay the same.

References cave, player::cave, cave_monster(), grid_data::f_idx, f_info, square::feat, FEAT_NONE, FEAT_PASS_RUBBLE, FEAT_PERM, grid_data::first_kind, trap::flags, grid_data::hallucinate, chunk::height, ignore_known_item_ok(), grid_data::in_view, grid_data::is_player, k_info, object::kind, grid_data::lighting, LIGHTING_DARK, LIGHTING_LIT, LIGHTING_LOS, LIGHTING_TORCH, lookup_feat(), grid_data::m_idx, feature::mimic, square::mon, chunk::mon_max, monster_is_visible(), grid_data::multiple_objects, trap::next, object::next, NULL, one_in_, OPT, square_isglow(), square_isknown(), square_isseen(), square_istrap(), square_memorize(), square_object(), chunk::squares, player::timed, trap::timeout, grid_data::trap, square::trap, trf_has, unknown_gold_kind, unknown_item_kind, grid_data::unseen_money, grid_data::unseen_object, and chunk::width.

Referenced by display_map(), is_unknown(), prt_map(), prt_map_aux(), and update_maps().

void square_light_spot ( struct chunk c,
int  y,
int  x 
void square_note_spot ( struct chunk c,
int  y,
int  x 

Memorize interesting viewable object/features in the given grid.

This function should only be called on "legal" grids.

This function will memorize the object and/or feature in the given grid, if they are (1) see-able and (2) interesting. Note that all objects are interesting, all terrain features except floors (and invisible traps) are interesting, and floors (and invisible traps) are interesting sometimes (depending on various options involving the illumination of floor grids).

The automatic memorization of all objects and non-floor terrain features as soon as they are displayed allows incredible amounts of optimization in various places, especially "map_info()" and this function itself.

Note that the memorization of objects is completely separate from the memorization of terrain features, preventing annoying floor memorization when a detected object is picked up from a dark floor, and object memorization when an object is dropped into a floor grid which is memorized but out-of-sight.

This function should be called every time the "memorization" of a grid (or the object in a grid) is called into question, such as when an object is created in a grid, when a terrain feature "changes" from "floor" to "non-floor", and when any grid becomes "see-able" for any reason.

This function is called primarily from the "update_view()" function, for each grid which becomes newly "see-able".

References cave, square_isknown(), square_issecrettrap(), square_isseen(), square_know_pile(), square_memorize(), and square_reveal_trap().

Referenced by become_aware(), floor_carry(), monster_turn_grab_objects(), project_o(), square_set_feat(), square_verify_trap(), uncurse_object(), and update_one().

void wiz_light ( struct chunk c,
struct player p,
bool  full 

Light up the dungeon using "claravoyance".

This function "illuminates" every grid in the dungeon, memorizes all "objects" (or notes the existence of an object "if" full is true), and memorizes all grids as with magic mapping.

References ddx_ddd, ddy_ddd, chunk::height, i, square::info, PR_ITEMLIST, PR_MAP, PR_MONLIST, PU_MONSTERS, PU_UPDATE_VIEW, player_upkeep::redraw, sqinfo_on, square_forget(), square_in_bounds(), square_in_bounds_fully(), square_isfloor(), square_ismark(), square_isnotknown(), square_isvisibletrap(), square_know_pile(), square_mark(), square_memorize(), square_seemslikewall(), square_sense_pile(), square_unmark(), chunk::squares, player_upkeep::update, player::upkeep, and chunk::width.

Referenced by cave_generate(), effect_handler_LIGHT_LEVEL(), and get_debug_command().