Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple layers support for map memory #36381

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ avatar::avatar()
show_map_memory = true;
active_mission = nullptr;
grab_type = OBJECT_NONE;
player_map_memory.init();
}

void avatar::toggle_map_memory()
Expand All @@ -128,15 +129,16 @@ void avatar::deserialize_map_memory( JsonIn &jsin )
player_map_memory.load( jsin );
}

memorized_terrain_tile avatar::get_memorized_tile( const tripoint &pos ) const
map_memory_tile avatar::get_memorized_tile( const tripoint &pos,
const map_memory_layer &layer ) const
{
return player_map_memory.get_tile( pos );
return player_map_memory.get_tile( pos, layer );
}

void avatar::memorize_tile( const tripoint &pos, const std::string &ter, const int subtile,
const int rotation )
const int rotation, const map_memory_layer &layer )
{
player_map_memory.memorize_tile( max_memorized_tiles(), pos, ter, subtile, rotation );
player_map_memory.memorize_tile( max_memorized_tiles(), pos, ter, subtile, rotation, layer );
}

void avatar::memorize_symbol( const tripoint &pos, const int symbol )
Expand Down Expand Up @@ -164,9 +166,9 @@ size_t avatar::max_memorized_tiles() const
return current_map_memory_capacity;
}

void avatar::clear_memorized_tile( const tripoint &pos )
void avatar::clear_memorized_tile( const tripoint &pos, const map_memory_layer &layer )
{
player_map_memory.clear_memorized_tile( pos );
player_map_memory.clear_memorized_tile( pos, layer );
}

std::vector<mission *> avatar::get_active_missions() const
Expand Down
6 changes: 3 additions & 3 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ class avatar : public player
bool should_show_map_memory();
/** Memorizes a given tile in tiles mode; finalize_tile_memory needs to be called after it */
void memorize_tile( const tripoint &pos, const std::string &ter, int subtile,
int rotation );
int rotation, const map_memory_layer &layer );
/** Returns last stored map tile in given location in tiles mode */
memorized_terrain_tile get_memorized_tile( const tripoint &p ) const;
map_memory_tile get_memorized_tile( const tripoint &p, const map_memory_layer &layer ) const;
/** Memorizes a given tile in curses mode; finalize_terrain_memory_curses needs to be called after it */
void memorize_symbol( const tripoint &pos, int symbol );
/** Returns last stored map tile in given location in curses mode */
int get_memorized_symbol( const tripoint &p ) const;
/** Returns the amount of tiles survivor can remember. */
size_t max_memorized_tiles() const;
void clear_memorized_tile( const tripoint &pos );
void clear_memorized_tile( const tripoint &pos, const map_memory_layer &layer );

/** Provides the window and detailed morale data */
void disp_morale();
Expand Down
134 changes: 31 additions & 103 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2176,8 +2176,8 @@ bool cata_tiles::draw_terrain( const tripoint &p, const lit_level ll, int &heigh
// do something to get other terrain orientation values
}
const std::string &tname = t.id().str();
if( g->m.check_and_set_seen_cache( p ) ) {
g->u.memorize_tile( g->m.getabs( p ), tname, subtile, rotation );
if( g->m.check_and_set_seen_cache( p, map_memory_layer::terrain ) ) {
g->u.memorize_tile( g->m.getabs( p ), tname, subtile, rotation, map_memory_layer::terrain );
}
// draw the actual terrain if there's no override
if( !neighborhood_overridden ) {
Expand Down Expand Up @@ -2207,110 +2207,38 @@ bool cata_tiles::draw_terrain( const tripoint &p, const lit_level ll, int &heigh
return draw_from_id_string( tname, C_TERRAIN, empty_string, p, subtile, rotation, lit, nv,
height_3d );
}
} else if( invisible[0] && has_terrain_memory_at( p ) ) {
} else if( invisible[0] && has_memory_at( p, map_memory_layer::terrain ) ) {
// try drawing memory if invisible and not overridden
const auto &t = get_terrain_memory_at( p );
const auto &t = get_memory_at( p, map_memory_layer::terrain );
return draw_from_id_string( t.tile, C_TERRAIN, empty_string, p, t.subtile, t.rotation,
LL_MEMORIZED, nv_goggles_activated, height_3d );
}
return false;
}

bool cata_tiles::has_memory_at( const tripoint &p ) const
bool cata_tiles::has_memory_at( const tripoint &p, const map_memory_layer &layer ) const
{
if( g->u.should_show_map_memory() ) {
const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) );
return !t.tile.empty();
}
return false;
}

bool cata_tiles::has_terrain_memory_at( const tripoint &p ) const
{
if( g->u.should_show_map_memory() ) {
const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) );
if( t.tile.substr( 0, 2 ) == "t_" ) {
return true;
}
}
return false;
}

bool cata_tiles::has_furniture_memory_at( const tripoint &p ) const
{
if( g->u.should_show_map_memory() ) {
const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) );
if( t.tile.substr( 0, 2 ) == "f_" ) {
return true;
}
}
return false;
}

bool cata_tiles::has_trap_memory_at( const tripoint &p ) const
{
if( g->u.should_show_map_memory() ) {
const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) );
if( t.tile.substr( 0, 3 ) == "tr_" ) {
return true;
}
}
return false;
}

bool cata_tiles::has_vpart_memory_at( const tripoint &p ) const
{
if( g->u.should_show_map_memory() ) {
const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) );
if( t.tile.substr( 0, 3 ) == "vp_" ) {
return true;
}
}
return false;
}

memorized_terrain_tile cata_tiles::get_terrain_memory_at( const tripoint &p ) const
{
if( g->u.should_show_map_memory() ) {
const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) );
if( t.tile.substr( 0, 2 ) == "t_" ) {
return t;
}
}
return {};
}

memorized_terrain_tile cata_tiles::get_furniture_memory_at( const tripoint &p ) const
{
if( g->u.should_show_map_memory() ) {
const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) );
if( t.tile.substr( 0, 2 ) == "f_" ) {
return t;
}
if( !g->u.should_show_map_memory() ) {
return false;
}
return {};
}

memorized_terrain_tile cata_tiles::get_trap_memory_at( const tripoint &p ) const
{
if( g->u.should_show_map_memory() ) {
const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) );
if( t.tile.substr( 0, 3 ) == "tr_" ) {
return t;
if( layer == map_memory_layer::num_map_memory_layer ) {
for( int i = 0; i < static_cast<int>( map_memory_layer::num_map_memory_layer ); i++ ) {
if( !g->u.get_memorized_tile( g->m.getabs( p ),
static_cast<map_memory_layer>( i ) ).tile.empty() ) {
return true;
}
}
return false;
}
return {};
return !g->u.get_memorized_tile( g->m.getabs( p ), layer ).tile.empty();
}

memorized_terrain_tile cata_tiles::get_vpart_memory_at( const tripoint &p ) const
map_memory_tile cata_tiles::get_memory_at( const tripoint &p, const map_memory_layer &layer ) const
{
if( g->u.should_show_map_memory() ) {
const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) );
if( t.tile.substr( 0, 3 ) == "vp_" ) {
return t;
}
if( !g->u.should_show_map_memory() ) {
return {};
}
return {};
return g->u.get_memorized_tile( g->m.getabs( p ), layer );
}

bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &height_3d,
Expand Down Expand Up @@ -2340,8 +2268,8 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei
int rotation = 0;
get_tile_values( f, neighborhood, subtile, rotation );
const std::string &fname = f.id().str();
if( g->m.check_and_set_seen_cache( p ) ) {
g->u.memorize_tile( g->m.getabs( p ), fname, subtile, rotation );
if( g->m.check_and_set_seen_cache( p, map_memory_layer::furniture ) ) {
g->u.memorize_tile( g->m.getabs( p ), fname, subtile, rotation, map_memory_layer::furniture );
}
// draw the actual furniture if there's no override
if( !neighborhood_overridden ) {
Expand Down Expand Up @@ -2377,9 +2305,9 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei
return draw_from_id_string( fname, C_FURNITURE, empty_string, p, subtile, rotation, lit, nv,
height_3d );
}
} else if( invisible[0] && has_furniture_memory_at( p ) ) {
} else if( invisible[0] && has_memory_at( p, map_memory_layer::furniture ) ) {
// try drawing memory if invisible and not overridden
const auto &t = get_furniture_memory_at( p );
const auto &t = get_memory_at( p, map_memory_layer::furniture );
return draw_from_id_string( t.tile, C_FURNITURE, empty_string, p, t.subtile, t.rotation,
LL_MEMORIZED, nv_goggles_activated, height_3d );
}
Expand Down Expand Up @@ -2414,8 +2342,8 @@ bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3
int rotation = 0;
get_tile_values( tr, neighborhood, subtile, rotation );
const std::string trname = tr.id().str();
if( g->m.check_and_set_seen_cache( p ) ) {
g->u.memorize_tile( g->m.getabs( p ), trname, subtile, rotation );
if( g->m.check_and_set_seen_cache( p, map_memory_layer::trap ) ) {
g->u.memorize_tile( g->m.getabs( p ), trname, subtile, rotation, map_memory_layer::trap );
}
// draw the actual trap if there's no override
if( !neighborhood_overridden ) {
Expand Down Expand Up @@ -2451,9 +2379,9 @@ bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3
return draw_from_id_string( trname, C_TRAP, empty_string, p, subtile, rotation, lit, nv,
height_3d );
}
} else if( invisible[0] && has_trap_memory_at( p ) ) {
} else if( invisible[0] && has_memory_at( p, map_memory_layer::trap ) ) {
// try drawing memory if invisible and not overridden
const auto &t = get_trap_memory_at( p );
const auto &t = get_memory_at( p, map_memory_layer::trap );
return draw_from_id_string( t.tile, C_TRAP, empty_string, p, t.subtile, t.rotation,
LL_MEMORIZED, nv_goggles_activated, height_3d );
}
Expand Down Expand Up @@ -2580,8 +2508,8 @@ bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d,
const int rotation = veh.face.dir();
const std::string vpname = "vp_" + vp_id.str();
if( !veh.forward_velocity() && !veh.player_in_control( g->u ) &&
g->m.check_and_set_seen_cache( p ) ) {
g->u.memorize_tile( g->m.getabs( p ), vpname, subtile, rotation );
g->m.check_and_set_seen_cache( p, map_memory_layer::vpart ) ) {
g->u.memorize_tile( g->m.getabs( p ), vpname, subtile, rotation, map_memory_layer::vpart );
}
if( !overridden ) {
const cata::optional<vpart_reference> cargopart = vp.part_with_feature( "CARGO", true );
Expand Down Expand Up @@ -2612,9 +2540,9 @@ bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d,
}
return ret;
}
} else if( invisible[0] && has_vpart_memory_at( p ) ) {
} else if( invisible[0] && has_memory_at( p, map_memory_layer::vpart ) ) {
// try drawing memory if invisible and not overridden
const auto &t = get_vpart_memory_at( p );
const auto &t = get_memory_at( p, map_memory_layer::vpart );
return draw_from_id_string( t.tile, C_VEHICLE_PART, empty_string, p, t.subtile, t.rotation,
LL_MEMORIZED, nv_goggles_activated, height_3d );
}
Expand Down
12 changes: 3 additions & 9 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,9 @@ class cata_tiles
void get_rotation_and_subtile( char val, int &rota, int &subtile );

/** Map memory */
bool has_memory_at( const tripoint &p ) const;
bool has_terrain_memory_at( const tripoint &p ) const;
bool has_furniture_memory_at( const tripoint &p ) const;
bool has_trap_memory_at( const tripoint &p ) const;
bool has_vpart_memory_at( const tripoint &p ) const;
memorized_terrain_tile get_terrain_memory_at( const tripoint &p ) const;
memorized_terrain_tile get_furniture_memory_at( const tripoint &p ) const;
memorized_terrain_tile get_trap_memory_at( const tripoint &p ) const;
memorized_terrain_tile get_vpart_memory_at( const tripoint &p ) const;
bool has_memory_at( const tripoint &p,
const map_memory_layer &layer = map_memory_layer::num_map_memory_layer ) const;
map_memory_tile get_memory_at( const tripoint &p, const map_memory_layer &layer ) const;

/** Drawing Layers */
bool would_apply_vision_effects( visibility_type visibility ) const;
Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5247,7 +5247,7 @@ void game::control_vehicle()
// If we reached here, we gained control of a vehicle.
// Clear the map memory for the area covered by the vehicle to eliminate ghost vehicles.
for( const tripoint &target : veh->get_points() ) {
u.clear_memorized_tile( m.getabs( target ) );
u.clear_memorized_tile( m.getabs( target ), map_memory_layer::vpart );
}
veh->is_following = false;
veh->is_patrolling = false;
Expand Down
2 changes: 1 addition & 1 deletion src/lru_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ const std::list<typename lru_cache<Key, Value>::Pair> &lru_cache<Key, Value>::li
}

// explicit template initialization for lru_cache of all types
template class lru_cache<tripoint, memorized_terrain_tile>;
template class lru_cache<tripoint, map_memory_tile>;
template class lru_cache<tripoint, int>;
template class lru_cache<point, char>;
19 changes: 15 additions & 4 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ void map::furn_set( const tripoint &p, const furn_id &new_furniture )
if( old_t.has_flag( TFLAG_NO_FLOOR ) != new_t.has_flag( TFLAG_NO_FLOOR ) ) {
set_floor_cache_dirty( p.z );
}
set_memory_seen_cache_dirty( p );
set_memory_seen_cache_dirty( p, map_memory_layer::furniture );

// TODO: Limit to changes that affect move cost, traps and stairs
set_pathfinding_cache_dirty( p.z );
Expand Down Expand Up @@ -1359,7 +1359,12 @@ uint8_t map::get_known_connections( const tripoint &p, int connect_group,
if( use_tiles ) {
is_memorized =
[&]( const tripoint & q ) {
return !g->u.get_memorized_tile( getabs( q ) ).tile.empty();
for( int i = 0; i < static_cast<int>( map_memory_layer::num_map_memory_layer ); i++ ) {
if( !g->u.get_memorized_tile( getabs( q ), static_cast<map_memory_layer>( i ) ).tile.empty() ) {
return true;
}
}
return false;
};
} else {
#endif
Expand Down Expand Up @@ -1519,7 +1524,7 @@ bool map::ter_set( const tripoint &p, const ter_id &new_terrain )
// It's a set, not a flag
support_cache_dirty.insert( p );
}
set_memory_seen_cache_dirty( p );
set_memory_seen_cache_dirty( p, map_memory_layer::terrain );

// TODO: Limit to changes that affect move cost, traps and stairs
set_pathfinding_cache_dirty( p.z );
Expand Down Expand Up @@ -6362,7 +6367,10 @@ void map::shift( const point &sp )
// Clear vehicle list and rebuild after shift
clear_vehicle_cache( gridz );
clear_vehicle_list( gridz );
shift_bitset_cache<MAPSIZE_X, SEEX>( get_cache( gridz ).map_memory_seen_cache, sp );
for( int i = 0; i < static_cast<int>( map_memory_layer::num_map_memory_layer ); i++ ) {
shift_bitset_cache<MAPSIZE_X, SEEX>( get_cache( gridz ).map_memory_seen_cache.at(
static_cast<map_memory_layer>( i ) ), sp );
}
shift_bitset_cache<MAPSIZE, 1>( get_cache( gridz ).field_cache, sp );
if( sp.x >= 0 ) {
for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) {
Expand Down Expand Up @@ -8261,6 +8269,9 @@ level_cache::level_cache()
veh_in_active_range = false;
std::fill_n( &veh_exists_at[0][0], map_dimensions, false );
max_populated_zlev = OVERMAP_HEIGHT;
for( int i = 0; i < static_cast<int>( map_memory_layer::num_map_memory_layer ); i++ ) {
init( static_cast<map_memory_layer>( i ) );
}
}

pathfinding_cache::pathfinding_cache()
Expand Down
Loading