Skip to content

Commit

Permalink
Add set_flag function using ter_bitflags parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg committed Aug 29, 2021
1 parent 128a0e9 commit ab2e056
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
#include "trap.h"
#include "type_id.h"

static const std::string flag_DIGGABLE( "DIGGABLE" );
static const std::string flag_LOCKED( "LOCKED" );
static const std::string flag_TRANSPARENT( "TRANSPARENT" );

namespace
{

Expand Down Expand Up @@ -184,7 +180,8 @@ static const std::unordered_map<std::string, ter_bitflags> ter_bitflags_map = {
{ "Z_TRANSPARENT", TFLAG_Z_TRANSPARENT }, // Doesn't block vision passing through the z-level
{ "SMALL_PASSAGE", TFLAG_SMALL_PASSAGE }, // A small passage, that large or huge things cannot pass through
{ "SUN_ROOF_ABOVE", TFLAG_SUN_ROOF_ABOVE }, // This furniture has a "fake roof" above, that blocks sunlight (see #44421).
{ "FUNGUS", TFLAG_FUNGUS } // Fungal covered.
{ "FUNGUS", TFLAG_FUNGUS }, // Fungal covered.
{ "LOCKED", TFLAG_LOCKED } // Fungal covered.
}
};

Expand Down Expand Up @@ -368,7 +365,7 @@ furn_t null_furniture_t()
new_furniture.movecost = 0;
new_furniture.move_str_req = -1;
new_furniture.transparent = true;
new_furniture.set_flag( flag_TRANSPARENT );
new_furniture.set_flag( TFLAG_TRANSPARENT );
new_furniture.examine_func = iexamine_function_from_string( "none" );
new_furniture.max_volume = DEFAULT_MAX_VOLUME_IN_SQUARE;
return new_furniture;
Expand All @@ -389,8 +386,8 @@ ter_t null_terrain_t()
new_terrain.light_emitted = 0;
new_terrain.movecost = 0;
new_terrain.transparent = true;
new_terrain.set_flag( flag_TRANSPARENT );
new_terrain.set_flag( flag_DIGGABLE );
new_terrain.set_flag( TFLAG_TRANSPARENT );
new_terrain.set_flag( TFLAG_DIGGABLE );
new_terrain.examine_func = iexamine_function_from_string( "none" );
new_terrain.max_volume = DEFAULT_MAX_VOLUME_IN_SQUARE;
return new_terrain;
Expand Down Expand Up @@ -543,6 +540,24 @@ void map_data_common_t::set_flag( const std::string &flag )
}
}

void map_data_common_t::set_flag( const ter_bitflags flag )
{
bitflags.set( flag );
if( !transparent && flag == TFLAG_TRANSPARENT ) {
transparent = true;
}
// wall connection check for JSON backwards compatibility
if( flag == TFLAG_WALL || flag == TFLAG_CONNECT_TO_WALL ) {
set_connects( "WALL" );
}
for( const auto &f : ter_bitflags_map ) {
if( f.second == flag ) {
flags.insert( f.first );
break;
}
}
}

void map_data_common_t::set_connects( const std::string &connect_group_string )
{
const auto it = ter_connects_map.find( connect_group_string );
Expand Down Expand Up @@ -1368,10 +1383,10 @@ void ter_t::check() const
}
// Check transition consistency for opening/closing terrain. Has an obvious
// exception for locked terrains - those aren't expected to be locked again
if( open && open->close && open->close != id && !has_flag( flag_LOCKED ) ) {
if( open && open->close && open->close != id && !has_flag( TFLAG_LOCKED ) ) {
debugmsg( "opening terrain %s for %s doesn't reciprocate", open.c_str(), id.c_str() );
}
if( close && close->open && close->open != id && !has_flag( flag_LOCKED ) ) {
if( close && close->open && close->open != id && !has_flag( TFLAG_LOCKED ) ) {
debugmsg( "closing terrain %s for %s doesn't reciprocate", close.c_str(), id.c_str() );
}

Expand Down
3 changes: 3 additions & 0 deletions src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ enum ter_bitflags : int {
TFLAG_Z_TRANSPARENT,
TFLAG_SUN_ROOF_ABOVE,
TFLAG_FUNGUS,
TFLAG_LOCKED,

NUM_TERFLAGS
};
Expand Down Expand Up @@ -426,6 +427,8 @@ struct map_data_common_t {

void set_flag( const std::string &flag );

void set_flag( const ter_bitflags flag );

int connect_group = 0;

void set_connects( const std::string &connect_group_string );
Expand Down

0 comments on commit ab2e056

Please sign in to comment.