From 59dd9db8ac1b4aad55b7b902c802003d9f3872c1 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 24 Nov 2006 10:31:14 +0000 Subject: [1581184] Fixed rotting food being visible outside LOS. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@487 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/abyss.cc | 1 + crawl-ref/source/acr.cc | 1 + crawl-ref/source/externs.h | 12 ++++- crawl-ref/source/files.cc | 6 ++- crawl-ref/source/player.cc | 1 + crawl-ref/source/tags.cc | 10 ++++ crawl-ref/source/tags.h | 2 +- crawl-ref/source/view.cc | 112 ++++++++++++++++++++++++++++++++------------- crawl-ref/source/view.h | 3 ++ 9 files changed, 112 insertions(+), 36 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/abyss.cc b/crawl-ref/source/abyss.cc index ca7c02b160..be6701534c 100644 --- a/crawl-ref/source/abyss.cc +++ b/crawl-ref/source/abyss.cc @@ -71,6 +71,7 @@ static void generate_area(unsigned char gx1, unsigned char gy1, for (j = 0; j < GYM; j++) { env.map[i][j] = 0; + env.map_col[i][j].clear(); } } diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 0e5dda5ef9..ef7bf4b03b 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -2728,6 +2728,7 @@ static bool initialise(void) igrd[i][j] = NON_ITEM; mgrd[i][j] = NON_MONSTER; env.map[i][j] = 0; + env.map_col[i][j].clear(); } } diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index ba69a74475..dced0b42aa 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -599,6 +599,15 @@ struct trap_struct unsigned char type; }; +struct map_colour +{ + short colour; + short flags; + + operator short () const { return colour; } + void clear() { colour = flags = 0; } +}; + struct crawl_environment { unsigned char rock_colour; @@ -612,7 +621,8 @@ struct crawl_environment FixedArray< int, GXM, GYM > igrid; // item grid FixedArray< unsigned char, GXM, GYM > cgrid; // cloud grid - FixedArray< unsigned short, GXM, GYM > map; // discovered terrain + FixedArray< unsigned short, GXM, GYM > map; // discovered terrain + FixedArray< map_colour, GXM, GYM > map_col; // map colours FixedArray< unsigned int, 19, 19> show; // view window char FixedArray< unsigned short, 19, 19> show_col; // view window colour diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index daea1295d9..25fc3a39a7 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -773,7 +773,10 @@ void load( unsigned char stair_taken, int load_mode, bool was_a_labyrinth, for (j = 0; j < GYM; j++) { if (just_created_level) + { env.map[i][j] = 0; + env.map_col[i][j].clear(); + } if (you.char_direction == DIR_ASCENDING && you.level_type != LEVEL_PANDEMONIUM) @@ -1154,8 +1157,9 @@ void save_level(int level_saved, bool was_a_labyrinth, char where_were_you) // 0.8 widened env.map to 2 bytes // 0.9 inscriptions (hp) // 0.10 Monster colour and spells separated from mons->number. + // 0.11 env colours moved into env.mapcol - write_tagged_file( saveFile, SAVE_MAJOR_VERSION, 10, TAGTYPE_LEVEL ); + write_tagged_file( saveFile, SAVE_MAJOR_VERSION, 11, TAGTYPE_LEVEL ); fclose(saveFile); diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index b6ef053e0d..e4af037825 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -2135,6 +2135,7 @@ void forget_map(unsigned char chance_forgotten) if (random2(100) < chance_forgotten) { env.map[xcount][ycount] = 0; + env.map_col[xcount][ycount].clear(); } } } diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index f671197067..1b875ccefb 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -1436,6 +1436,8 @@ static void tag_construct_level(struct tagHeader &th) { marshallByte(th, grd[count_x][count_y]); marshallShort(th, env.map[count_x][count_y]); + marshallShort(th, env.map_col[count_x][count_y].colour); + marshallShort(th, env.map_col[count_x][count_y].flags); marshallByte(th, env.cgrid[count_x][count_y]); } } @@ -1598,6 +1600,14 @@ static void tag_read_level( struct tagHeader &th, char minorVersion ) if ((env.map[i][j] & 0xFF) == 201) // what is this?? env.map[i][j] = (env.map[i][j] & 0xFF00U) | 239; + if (minorVersion >= 11) + { + env.map_col[i][j].colour = unmarshallShort(th); + env.map_col[i][j].flags = unmarshallShort(th); + } + else + env.map_col[i][j].clear(); + mgrd[i][j] = NON_MONSTER; env.cgrid[i][j] = unmarshallByte(th); diff --git a/crawl-ref/source/tags.h b/crawl-ref/source/tags.h index 65a00a208b..6b1701699e 100644 --- a/crawl-ref/source/tags.h +++ b/crawl-ref/source/tags.h @@ -59,7 +59,7 @@ time_t parse_date_string( char[20] ); /* *********************************************************************** * called from: acr * *********************************************************************** */ -void tag_init(long largest_tag = 50000); +void tag_init(long largest_tag = 100000); // last updated 22jan2001 {gdl} diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index d1ff9a3ef8..11aea1a7a0 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -64,6 +64,10 @@ #define MAP_CHARACTER_MASK 0x00ff +// Flags that define what the player remembers on this square. +#define MC_ITEM 0x01 +#define MC_MONS 0x02 + struct feature_def { unsigned short symbol; // symbol used for seen terrain @@ -109,6 +113,7 @@ static void set_show_backup( int ex, int ey ); // Applies EC_ colour substitutions and brands. static unsigned fix_colour(unsigned raw_colour); +static int get_viewobj_flags(int viewobj); //--------------------------------------------------------------- // @@ -181,12 +186,61 @@ bool is_envmap_detected_mons(int x, int y) return (env.map[x - 1][y - 1] & MAP_DETECTED_MONSTER); } +void set_envmap_glyph(int x, int y, int chr, int col, int object) +{ + set_envmap_char(x, y, chr); + set_envmap_col(x, y, col, get_viewobj_flags(object)); +} + void set_envmap_char( int x, int y, unsigned char chr ) { env.map[x - 1][y - 1] &= (~MAP_CHARACTER_MASK); // clear old first env.map[x - 1][y - 1] |= chr; } +void set_envmap_col( int x, int y, int colour ) +{ + env.map_col[x - 1][y - 1].colour = colour; + env.map_col[x - 1][y - 1].flags = 0; +} + +void set_envmap_col( int x, int y, int colour, int flags ) +{ + env.map_col[x - 1][y - 1].colour = colour; + env.map_col[x - 1][y - 1].flags = flags; +} + +inline void set_envmap_item(int x, int y, bool isitem) +{ + if (isitem) + env.map_col[x - 1][y - 1].flags |= MC_ITEM; + else + env.map_col[x - 1][y - 1].flags &= ~MC_ITEM; +} + +inline void set_envmap_mons(int x, int y, bool ismons) +{ + if (ismons) + env.map_col[x - 1][y - 1].flags |= MC_MONS; + else + env.map_col[x - 1][y - 1].flags &= ~MC_MONS; +} + +bool is_envmap_item(int x, int y) +{ + return (env.map_col[x - 1][y - 1].flags & MC_ITEM); +} + +bool is_envmap_mons(int x, int y) +{ + return (env.map_col[x - 1][y - 1].flags & MC_MONS); +} + +int get_envmap_col(int x, int y) +{ + return (env.map_col[x - 1][y - 1].colour); +} + bool is_terrain_known( int x, int y ) { return (env.map[x - 1][y - 1] & (MAP_MAGIC_MAPPED_FLAG | MAP_SEEN_FLAG)); @@ -223,6 +277,7 @@ void set_terrain_seen( int x, int y ) void clear_envmap_grid( int x, int y ) { env.map[x - 1][y - 1] = 0; + env.map_col[x - 1][y - 1].clear(); } void clear_envmap( void ) @@ -232,6 +287,7 @@ void clear_envmap( void ) for (int j = 0; j < GYM; j++) { env.map[i][j] = 0; + env.map_col[i][j].clear(); } } } @@ -284,6 +340,21 @@ static unsigned fix_colour(unsigned raw_colour) return (raw_colour); } +static int get_viewobj_flags(int object) +{ + // Check for monster glyphs. + if (object >= DNGN_START_OF_MONSTERS) + return (MC_MONS); + + // Check for item glyphs. + if (object >= DNGN_ITEM_ORB && object < DNGN_CLOUD) + return (MC_ITEM); + + // We don't care to look further; we could check for + // clouds here as well. + return (0); +} + static void get_symbol( unsigned int object, unsigned short *ch, unsigned short *colour ) { @@ -423,7 +494,6 @@ screen_buffer_t colour_code_map( int x, int y, bool item_colour, bool travel_colour ) { // XXX: Yes, the map array and the grid array are off by one. -- bwr - const int map_value = (unsigned char) env.map[x][y]; const unsigned short map_flags = env.map[x][y]; const int grid_value = grd[x + 1][y + 1]; @@ -445,30 +515,8 @@ screen_buffer_t colour_code_map( int x, int y, bool item_colour, if (tc == LIGHTGREEN || tc == LIGHTMAGENTA) return fix_colour(tc); - // XXX: Yeah, this is ugly, but until we have stored layers in the - // map we can't tell if we've seen a square, detected it, or just - // detected the item or monster on top... giving colour here will - // result in detect creature/item detecting features like stairs. -- bwr - if (map_value != get_sightmap_char(grid_value)) - { - // If there's an item on this square, change colour to indicate - // that, iff the item's glyph matches map_value. XXX: Potentially - // abusable? -- ds - int item = igrd[x + 1][y + 1]; - if (item_colour && item != NON_ITEM - && map_value == - get_sightmap_char(get_item_dngn_code(mitm[item]))) - { - unsigned ic = mitm[item].colour; - - if (mitm[item].link != NON_ITEM ) - ic |= COLFLAG_ITEM_HEAP; - - // If the item colour is the background colour, tweak it to WHITE - // instead to catch the player's eye. - return fix_colour( ic == tc? WHITE : ic ); - } - } + if (item_colour && is_envmap_item(x + 1, y + 1)) + return get_envmap_col(x + 1, y + 1); int feature_colour = DARKGREY; feature_colour = @@ -494,14 +542,11 @@ void clear_map() if (is_terrain_changed(x, y)) continue; - unsigned short envc = env.map[x][y] & MAP_CHARACTER_MASK; + unsigned short envc = get_envmap_char(x, y); if (!envc) continue; - const int item = igrd[x + 1][y + 1]; - if (item != NON_ITEM - && envc == - get_sightmap_char(get_item_dngn_code(mitm[item]))) + if (is_envmap_item(x, y)) continue; set_envmap_char(x, y, @@ -3444,7 +3489,7 @@ void viewwindow(bool draw_it, bool do_updates) unsigned short ch; get_symbol( object, &ch, &colour ); - set_envmap_char( gx, gy, ch ); + set_envmap_glyph( gx, gy, ch, colour, object ); set_terrain_seen( gx, gy ); set_envmap_detected_mons(gx, gy, false); set_envmap_detected_item(gx, gy, false); @@ -3490,7 +3535,7 @@ void viewwindow(bool draw_it, bool do_updates) if (buffy[bufcount] != 0) { // ... map that we've seen this - set_envmap_char( gx, gy, buffy[bufcount] ); + set_envmap_glyph( gx, gy, ch, colour, object ); set_terrain_seen( gx, gy ); set_envmap_detected_mons(gx, gy, false); set_envmap_detected_item(gx, gy, false); @@ -3512,7 +3557,8 @@ void viewwindow(bool draw_it, bool do_updates) && is_terrain_seen( gx, gy )) { get_symbol( Show_Backup[ex][ey], &ch, &colour ); - set_envmap_char( gx, gy, ch ); + set_envmap_glyph( gx, gy, ch, colour, + Show_Backup[ex][ey] ); } // Now we get to filling in both the unseen diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h index 26d17ada8c..75f385e1b0 100644 --- a/crawl-ref/source/view.h +++ b/crawl-ref/source/view.h @@ -116,6 +116,9 @@ bool is_feature(int feature, int x, int y); void set_envmap_char( int x, int y, unsigned char chr ); void set_envmap_detected_item(int x, int y, bool detected = true); void set_envmap_detected_mons(int x, int y, bool detected = true); +void set_envmap_col( int x, int y, int colour, int flags ); +void set_envmap_col( int x, int y, int colour ); + bool is_envmap_detected_item(int x, int y); bool is_envmap_detected_mons(int x, int y); void set_terrain_mapped( int x, int y ); -- cgit v1.2.3-54-g00ecf