Skip to content

Commit

Permalink
Replace hardcoded water terrain checks with flags
Browse files Browse the repository at this point in the history
This should expand coverage and make sure that all shallow and deep
water types are appropriately used.
  • Loading branch information
anothersimulacrum committed May 8, 2020
1 parent fdb8229 commit 0768933
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 61 deletions.
24 changes: 12 additions & 12 deletions data/json/furniture_and_terrain/terrain-liquids.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"symbol": "~",
"color": "light_blue",
"move_cost": 5,
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "SHALLOW_WATER" ],
"connects_to": "WATER",
"examine_action": "water_source"
},
Expand All @@ -22,7 +22,7 @@
"color": "light_blue",
"move_cost": 5,
"roof": "t_rock_roof",
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "INDOORS" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "INDOORS", "SHALLOW_WATER" ],
"connects_to": "WATER",
"examine_action": "water_source"
},
Expand Down Expand Up @@ -63,7 +63,7 @@
"color": "light_blue",
"looks_like": "t_water_sh",
"move_cost": 5,
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "SHALLOW_WATER" ],
"connects_to": "WATER",
"examine_action": "water_source"
},
Expand All @@ -78,7 +78,7 @@
"looks_like": "t_water_sh",
"move_cost": 5,
"roof": "t_rock_roof",
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "INDOORS" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "INDOORS", "SHALLOW_WATER" ],
"connects_to": "WATER",
"examine_action": "water_source"
},
Expand All @@ -91,7 +91,7 @@
"symbol": "~",
"color": "light_blue",
"move_cost": 6,
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "CURRENT" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "CURRENT", "SHALLOW_WATER" ],
"connects_to": "WATER",
"examine_action": "water_source"
},
Expand All @@ -106,7 +106,7 @@
"color": "light_blue",
"move_cost": 6,
"roof": "t_rock_roof",
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "CURRENT", "INDOORS" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "FISHABLE", "CURRENT", "INDOORS", "SHALLOW_WATER" ],
"connects_to": "WATER",
"examine_action": "water_source"
},
Expand Down Expand Up @@ -147,7 +147,7 @@
"looks_like": "t_water_sh",
"color": "light_blue",
"move_cost": 5,
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "SALT_WATER", "FISHABLE" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "SALT_WATER", "FISHABLE", "SHALLOW_WATER" ],
"connects_to": "WATER",
"examine_action": "water_source"
},
Expand All @@ -162,7 +162,7 @@
"looks_like": "t_swater_sh",
"move_cost": 5,
"roof": "t_rock_roof",
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "SALT_WATER", "FISHABLE", "INDOORS" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "SALT_WATER", "FISHABLE", "INDOORS", "SHALLOW_WATER" ],
"connects_to": "WATER",
"examine_action": "water_source"
},
Expand All @@ -175,7 +175,7 @@
"looks_like": "t_water_dp",
"color": "blue",
"move_cost": 8,
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "SALT_WATER", "DEEP_WATER", "FISHABLE" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "SALT_WATER", "DEEP_WATER", "FISHABLE", "SHALLOW_WATER" ],
"connects_to": "WATER",
"examine_action": "water_source"
},
Expand Down Expand Up @@ -215,7 +215,7 @@
"looks_like": "t_water_pool",
"color": "light_blue",
"move_cost": 5,
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "INDOORS" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "INDOORS", "SHALLOW_WATER" ],
"examine_action": "water_source"
},
{
Expand All @@ -239,7 +239,7 @@
"looks_like": "t_water_pool",
"color": "light_blue",
"move_cost": 5,
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "SHALLOW_WATER" ],
"examine_action": "water_source"
},
{
Expand All @@ -251,7 +251,7 @@
"looks_like": "t_water_murky",
"color": "light_green",
"move_cost": 6,
"flags": [ "TRANSPARENT", "SWIMMABLE" ],
"flags": [ "TRANSPARENT", "SWIMMABLE", "SHALLOW_WATER" ],
"examine_action": "water_source"
},
{
Expand Down
3 changes: 2 additions & 1 deletion doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ List of known flags, used in both `terrain.json` and `furniture.json`.
- ```CONSOLE``` Used as a computer.
- ```CONTAINER``` Items on this square are hidden until looted by the player.
- ```DECONSTRUCT``` Can be deconstructed.
- ```DEEP_WATER```
- ```DEEP_WATER``` This is water that can submerge the player
- ```DESTROY_ITEM``` Items that land here are destroyed. See also `NOITEM`
- ```DIFFICULT_Z``` Most zombies will not be able to follow you up this terrain ( i.e a ladder )
- ```DIGGABLE_CAN_DEEPEN``` Diggable location can be dug again to make deeper (e.g. shallow pit to deep pit).
Expand Down Expand Up @@ -581,6 +581,7 @@ List of known flags, used in both `terrain.json` and `furniture.json`.
- ```SALT_WATER``` Source of salt water (works for terrains with examine action "water_source").
- ```SEALED``` Can't use <kbd>e</kbd> to retrieve items; must smash them open first.
- ```SEEN_FROM_ABOVE``` Visible from a higher level (provided the tile above has no floor)
- ```SHALLOW_WATER``` This is water that is not deep enough to submerge the player.
- ```SHARP``` May do minor damage to players/monsters passing through it.
- ```SHORT``` Feature too short to collide with vehicle protrusions. (mirrors, blades).
- ```SIGN``` Show written message on examine.
Expand Down
9 changes: 1 addition & 8 deletions src/advanced_inv_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,7 @@ void advanced_inv_area::init()
}

// water?
static const std::array<ter_id, 8> ter_water = {
{t_water_dp, t_water_pool, t_swater_dp, t_water_sh, t_swater_sh, t_sewage, t_water_moving_dp, t_water_moving_sh }
};
auto ter_check = [this]
( const ter_id & id ) {
return g->m.ter( this->pos ) == id;
};
if( std::any_of( ter_water.begin(), ter_water.end(), ter_check ) ) {
if( g->m.has_flag_ter( TFLAG_SHALLOW_WATER, pos ) || g->m.has_flag_ter( TFLAG_DEEP_WATER, pos ) ) {
flags.append( _( " WATER" ) );
}

Expand Down
15 changes: 8 additions & 7 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5328,14 +5328,15 @@ void Character::update_bodytemp()
sheltered ),
bp_windpower );
// If you're standing in water, air temperature is replaced by water temperature. No wind.
const ter_id ter_at_pos = g->m.ter( pos() );
// Convert to 0.01C
if( ( ter_at_pos == t_water_dp || ter_at_pos == t_water_pool || ter_at_pos == t_swater_dp ||
ter_at_pos == t_water_moving_dp ) ||
( ( ter_at_pos == t_water_sh || ter_at_pos == t_swater_sh || ter_at_pos == t_sewage ||
ter_at_pos == t_water_moving_sh ) &&
( bp == bodypart_id( "foot_l" ) || bp == bodypart_id( "foot_r" ) || bp == bodypart_id( "leg_l" ) ||
bp == bodypart_id( "leg_r" ) ) ) ) {
static const std::set<bodypart_id> lowers {
bodypart_id( "foot_l" ),
bodypart_id( "foot_r" ),
bodypart_id( "leg_l" ),
bodypart_id( "leg_r" )
};
if( g->m.has_flag_ter( TFLAG_DEEP_WATER, pos() ) ||
( g->m.has_flag_ter( TFLAG_SHALLOW_WATER, pos() ) && lowers.count( bp ) ) ) {
adjusted_temp += water_temperature - Ctemperature; // Swap out air temp for water temp.
windchill = 0;
}
Expand Down
8 changes: 2 additions & 6 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,12 +1325,8 @@ void construct::done_mine_upstair( const tripoint &p )
return;
}

static const std::set<ter_id> liquids = {{
t_water_sh, t_sewage, t_water_dp, t_water_pool, t_water_moving_sh, t_water_moving_dp,
}
};

if( liquids.count( tmpmap.ter( local_tmp ) ) > 0 ) {
if( tmpmap.has_flag_ter( TFLAG_SHALLOW_WATER, local_tmp ) ||
tmpmap.has_flag_ter( TFLAG_DEEP_WATER, local_tmp ) ) {
g->m.ter_set( p.xy(), t_rock_floor ); // You dug a bit before discovering the problem
add_msg( m_warning, _( "The rock above is rather damp. You decide *not* to mine water." ) );
unroll_digging( 12 );
Expand Down
6 changes: 2 additions & 4 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ bool map::displace_vehicle( vehicle &veh, const tripoint &dp )
bool map::displace_water( const tripoint &p )
{
// Check for shallow water
if( has_flag( "SWIMMABLE", p ) && !has_flag( TFLAG_DEEP_WATER, p ) ) {
if( has_flag_ter( TFLAG_SHALLOW_WATER, p ) ) {
int dis_places = 0;
int sel_place = 0;
for( int pass = 0; pass < 2; pass++ ) {
Expand All @@ -1203,9 +1203,7 @@ bool map::displace_water( const tripoint &p )
|| has_flag( TFLAG_DEEP_WATER, temp ) ) {
continue;
}
ter_id ter0 = ter( temp );
if( ter0 == t_water_sh ||
ter0 == t_water_dp || ter0 == t_water_moving_sh || ter0 == t_water_moving_dp ) {
if( has_flag_ter( TFLAG_SHALLOW_WATER, p ) || has_flag_ter( TFLAG_DEEP_WATER, p ) ) {
continue;
}
if( pass != 0 && dis_places == sel_place ) {
Expand Down
1 change: 1 addition & 0 deletions src/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ static const std::unordered_map<std::string, ter_bitflags> ter_bitflags_map = {
{ "WALL", TFLAG_WALL }, // connects to other walls
{ "NO_SCENT", TFLAG_NO_SCENT }, // cannot have scent values, which prevents scent diffusion through this tile
{ "DEEP_WATER", TFLAG_DEEP_WATER }, // Deep enough to submerge things
{ "SHALLOW_WATER", TFLAG_SHALLOW_WATER }, // Water, but not deep enough to submerge the player
{ "CURRENT", TFLAG_CURRENT }, // Water is flowing.
{ "HARVESTED", TFLAG_HARVESTED }, // harvested. will not bear fruit.
{ "PERMEABLE", TFLAG_PERMEABLE }, // gases can flow through.
Expand Down
1 change: 1 addition & 0 deletions src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ enum ter_bitflags : int {
TFLAG_UNSTABLE,
TFLAG_WALL,
TFLAG_DEEP_WATER,
TFLAG_SHALLOW_WATER,
TFLAG_CURRENT,
TFLAG_HARVESTED,
TFLAG_PERMEABLE,
Expand Down
26 changes: 3 additions & 23 deletions src/sounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1388,16 +1388,6 @@ void sfx::do_footstep()
ter_str_id( "t_machinery_old" ),
ter_str_id( "t_machinery_electronic" ),
};
static const std::set<ter_str_id> water = {
ter_str_id( "t_water_moving_sh" ),
ter_str_id( "t_water_moving_dp" ),
ter_str_id( "t_water_sh" ),
ter_str_id( "t_water_dp" ),
ter_str_id( "t_swater_sh" ),
ter_str_id( "t_swater_dp" ),
ter_str_id( "t_water_pool" ),
ter_str_id( "t_sewage" ),
};
static const std::set<ter_str_id> chain_fence = {
ter_str_id( "t_chainfence" ),
};
Expand All @@ -1421,7 +1411,7 @@ void sfx::do_footstep()
play_variant_sound( "plmove", "walk_metal", heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
return;
} else if( water.count( terrain ) > 0 ) {
} else if( terrain->has_flag( TFLAG_DEEP_WATER ) || terrain->has_flag( TFLAG_SHALLOW_WATER ) ) {
play_variant_sound( "plmove", "walk_water", heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
return;
Expand All @@ -1440,20 +1430,10 @@ void sfx::do_footstep()
void sfx::do_obstacle( const std::string &obst )
{
int heard_volume = sfx::get_heard_volume( g->u.pos() );
//const auto terrain = g->m.ter( g->u.pos() ).id();
static const std::set<std::string> water = {
"t_water_sh",
"t_water_dp",
"t_water_moving_sh",
"t_water_moving_dp",
"t_swater_sh",
"t_swater_dp",
"t_water_pool",
"t_sewage",
};
if( sfx::has_variant_sound( "plmove", obst ) ) {
play_variant_sound( "plmove", obst, heard_volume, 0, 0.8, 1.2 );
} else if( water.count( obst ) > 0 ) {
} else if( ter_id( obst )->has_flag( TFLAG_SHALLOW_WATER ) ||
ter_id( obst )->has_flag( TFLAG_DEEP_WATER ) ) {
play_variant_sound( "plmove", "walk_water", heard_volume, 0, 0.8, 1.2 );
} else {
play_variant_sound( "plmove", "clear_obstacle", heard_volume, 0, 0.8, 1.2 );
Expand Down

0 comments on commit 0768933

Please sign in to comment.