From 7717ee18c92880b110491980c29f30ef00e1cf55 Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Fri, 4 Dec 2020 19:04:22 -0600 Subject: [PATCH] Adding a NO_SHOOT terrain Flag and example of use (#45730) --- data/mods/Magiclysm/terrain.json | 2 +- src/map.cpp | 9 ++++++--- src/mapdata.cpp | 1 + src/mapdata.h | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/data/mods/Magiclysm/terrain.json b/data/mods/Magiclysm/terrain.json index 61db387ca61df..b41dbaf4dff7c 100644 --- a/data/mods/Magiclysm/terrain.json +++ b/data/mods/Magiclysm/terrain.json @@ -72,7 +72,7 @@ "color": "light_cyan", "move_cost": 0, "roof": "t_flat_roof", - "flags": [ "TRANSPARENT", "ALARMED", "NOITEM", "WALL", "NO_SCENT", "AUTO_WALL_SYMBOL", "BLOCK_WIND" ], + "flags": [ "TRANSPARENT", "ALARMED", "NOITEM", "WALL", "NO_SCENT", "AUTO_WALL_SYMBOL", "BLOCK_WIND", "NO_SHOOT" ], "bash": { "str_min": 200, "str_max": 600, diff --git a/src/map.cpp b/src/map.cpp index d76543d6e1fd2..e96eaa22fac79 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3668,9 +3668,12 @@ void map::shoot( const tripoint &p, projectile &proj, const bool hit_items ) }; ter_id terrain = ter( p ); - if( terrain == t_wall_wood_broken || - terrain == t_wall_log_broken || - terrain == t_door_b ) { + if( terrain->has_flag( TFLAG_NO_SHOOT ) ) { + dam = 0.0f; + add_msg( _( "The shot is stopped by the %s" ), terrain->name() ); + } else if( terrain == t_wall_wood_broken || + terrain == t_wall_log_broken || + terrain == t_door_b ) { if( hit_items || one_in( 8 ) ) { // 1 in 8 chance of hitting the door dam -= rng( 20, 40 ); if( dam > 0 ) { diff --git a/src/mapdata.cpp b/src/mapdata.cpp index 2b4aca9a45468..01108afb80d59 100644 --- a/src/mapdata.cpp +++ b/src/mapdata.cpp @@ -158,6 +158,7 @@ static const std::unordered_map ter_bitflags_map = { { "NO_SIGHT", TFLAG_NO_SIGHT }, // Sight reduced to 1 on this tile { "FLAMMABLE_ASH", TFLAG_FLAMMABLE_ASH }, // oh hey fire. again. { "WALL", TFLAG_WALL }, // connects to other walls + { "NO_SHOOT", TFLAG_NO_SHOOT }, // terrain cannot be damaged by ranged attacks { "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 diff --git a/src/mapdata.h b/src/mapdata.h index b22ccf9f3ea66..d9cb445aab855 100644 --- a/src/mapdata.h +++ b/src/mapdata.h @@ -194,6 +194,7 @@ enum ter_bitflags : int { TFLAG_WALL, TFLAG_DEEP_WATER, TFLAG_SHALLOW_WATER, + TFLAG_NO_SHOOT, TFLAG_CURRENT, TFLAG_HARVESTED, TFLAG_PERMEABLE,