From 076893311724d464ec2fd3836436c26c295e3914 Mon Sep 17 00:00:00 2001 From: anothersimulacrum <42699974+anothersimulacrum@users.noreply.github.com> Date: Thu, 7 May 2020 12:27:09 -0700 Subject: [PATCH] Replace hardcoded water terrain checks with flags This should expand coverage and make sure that all shallow and deep water types are appropriately used. --- .../terrain-liquids.json | 24 ++++++++--------- doc/JSON_FLAGS.md | 3 ++- src/advanced_inv_area.cpp | 9 +------ src/character.cpp | 15 ++++++----- src/construction.cpp | 8 ++---- src/map.cpp | 6 ++--- src/mapdata.cpp | 1 + src/mapdata.h | 1 + src/sounds.cpp | 26 +++---------------- 9 files changed, 32 insertions(+), 61 deletions(-) diff --git a/data/json/furniture_and_terrain/terrain-liquids.json b/data/json/furniture_and_terrain/terrain-liquids.json index ef8bb276260a8..b13a9ad606725 100644 --- a/data/json/furniture_and_terrain/terrain-liquids.json +++ b/data/json/furniture_and_terrain/terrain-liquids.json @@ -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" }, @@ -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" }, @@ -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" }, @@ -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" }, @@ -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" }, @@ -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" }, @@ -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" }, @@ -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" }, @@ -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" }, @@ -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" }, { @@ -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" }, { @@ -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" }, { diff --git a/doc/JSON_FLAGS.md b/doc/JSON_FLAGS.md index 917d50cca4f85..8d9635c7d2f4a 100644 --- a/doc/JSON_FLAGS.md +++ b/doc/JSON_FLAGS.md @@ -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). @@ -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 e 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. diff --git a/src/advanced_inv_area.cpp b/src/advanced_inv_area.cpp index c1d3ece6fa8e5..9756d74b6002b 100644 --- a/src/advanced_inv_area.cpp +++ b/src/advanced_inv_area.cpp @@ -171,14 +171,7 @@ void advanced_inv_area::init() } // water? - static const std::array 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" ) ); } diff --git a/src/character.cpp b/src/character.cpp index 66a416503920e..b2f8217ca13e7 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -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 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; } diff --git a/src/construction.cpp b/src/construction.cpp index e8ab54f34d788..758ae29a32363 100644 --- a/src/construction.cpp +++ b/src/construction.cpp @@ -1325,12 +1325,8 @@ void construct::done_mine_upstair( const tripoint &p ) return; } - static const std::set 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 ); diff --git a/src/map.cpp b/src/map.cpp index 4723782760c6e..157ec0fd0b475 100755 --- a/src/map.cpp +++ b/src/map.cpp @@ -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++ ) { @@ -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 ) { diff --git a/src/mapdata.cpp b/src/mapdata.cpp index 3df4c7302ceef..e04f86ed665fd 100644 --- a/src/mapdata.cpp +++ b/src/mapdata.cpp @@ -160,6 +160,7 @@ static const std::unordered_map 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. diff --git a/src/mapdata.h b/src/mapdata.h index 0fc3b11797291..3f620c1eb5292 100644 --- a/src/mapdata.h +++ b/src/mapdata.h @@ -186,6 +186,7 @@ enum ter_bitflags : int { TFLAG_UNSTABLE, TFLAG_WALL, TFLAG_DEEP_WATER, + TFLAG_SHALLOW_WATER, TFLAG_CURRENT, TFLAG_HARVESTED, TFLAG_PERMEABLE, diff --git a/src/sounds.cpp b/src/sounds.cpp index f1b2c8ee1ee80..33ada16846c49 100644 --- a/src/sounds.cpp +++ b/src/sounds.cpp @@ -1388,16 +1388,6 @@ void sfx::do_footstep() ter_str_id( "t_machinery_old" ), ter_str_id( "t_machinery_electronic" ), }; - static const std::set 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 chain_fence = { ter_str_id( "t_chainfence" ), }; @@ -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; @@ -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 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 );