From f1bb4a7ee201b30f964f3766568b7b844f04f18b Mon Sep 17 00:00:00 2001 From: anothersimulacrum Date: Sun, 14 Mar 2021 13:46:12 -0700 Subject: [PATCH] JSONize some trap features, replace trap int_id externs with string_ids (#47933) * JSONize trap sonar detectibility Add trap flags - just the same as normal flags, but for traps! Stick them in their own separate file to avoid confusion. * JSONize trap memorial messages light_snare and heavy_snare seem to no longer exist, or I couldn't find any reference to them but this and tilesets. Updated dissector trap message, and added a trap message to some traps (the hallway ones, one or two of the similar-but-not-the-same variants of existing traps). * JSONize trap temperature convection Not quite sure how to describe it, went the lazy route. * Move traps externs from int to string ids When loading the game without this content, these will now only give an error on the use of these, instead of at the end data loading for traps. Previously there were performance concerns with this, but this should be fine since #44261 - see #44500. tr_null must remain an int id, as it used in the string to int id conversion. This is fine, as it will always be loaded (it's in data/core). Move the ledge trap over to data/core as well, because everything will need the 'open space' trap. --- data/core/traps.json | 17 ++++++ data/json/flags/trap.json | 12 ++++ data/json/traps.json | 78 ++++++++++++++++++++++---- doc/JSON_FLAGS.md | 4 ++ doc/JSON_INFO.md | 1 + src/game.cpp | 3 +- src/memorial_logger.cpp | 114 +------------------------------------- src/trap.cpp | 85 ++++++++++++---------------- src/trap.h | 66 ++++++++++++++-------- 9 files changed, 184 insertions(+), 196 deletions(-) create mode 100644 data/core/traps.json create mode 100644 data/json/flags/trap.json diff --git a/data/core/traps.json b/data/core/traps.json new file mode 100644 index 0000000000000..da83ec74d9697 --- /dev/null +++ b/data/core/traps.json @@ -0,0 +1,17 @@ +[ + { + "//": "We're always going to need a 'nothing here' tile, we currently use traps for this.", + "type": "trap", + "id": "tr_ledge", + "name": "ledge", + "color": "i_cyan", + "memorial_male": { "ctxt": "memorial_female", "str": "Fell down a ledge." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Fell down a ledge." }, + "symbol": " ", + "visibility": 0, + "avoidance": 99999, + "difficulty": 99, + "action": "ledge", + "vehicle_data": { "is_falling": true } + } +] diff --git a/data/json/flags/trap.json b/data/json/flags/trap.json new file mode 100644 index 0000000000000..f213b6d193ef2 --- /dev/null +++ b/data/json/flags/trap.json @@ -0,0 +1,12 @@ +[ + { + "type": "json_flag", + "id": "SONAR_DETECTABLE", + "context": [ ] + }, + { + "type": "json_flag", + "id": "CONVECTS_TEMPERATURE", + "context": [ ] + } +] diff --git a/data/json/traps.json b/data/json/traps.json index 0cfb8c4e069db..d48d932157a79 100644 --- a/data/json/traps.json +++ b/data/json/traps.json @@ -4,6 +4,8 @@ "id": "tr_bubblewrap", "name": "bubble wrap", "color": "light_cyan", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped on bubble wrap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped on bubble wrap." }, "symbol": "_", "visibility": 0, "avoidance": 8, @@ -17,6 +19,8 @@ "id": "tr_glass", "name": "glass shards", "color": "light_cyan", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped on glass." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped on glass." }, "symbol": "_", "visibility": 6, "avoidance": 8, @@ -103,6 +107,8 @@ "id": "tr_microlab_shifting_hall", "name": "microlab shifting hall", "color": "brown", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a dimensional anomaly." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a dimensional anomaly." }, "symbol": ".", "visibility": 99, "avoidance": 99, @@ -116,6 +122,8 @@ "id": "tr_microlab_shifting_hall_2", "name": "microlab shifting hall", "color": "brown", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a dimensional anomaly." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a dimensional anomaly." }, "symbol": ".", "visibility": 99, "avoidance": 99, @@ -130,6 +138,8 @@ "trigger_weight": "200 g", "name": "bear trap", "color": "blue", + "memorial_male": { "ctxt": "memorial_male", "str": "Caught by a beartrap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Caught by a beartrap." }, "symbol": "^", "visibility": 2, "avoidance": 7, @@ -152,12 +162,15 @@ "trigger_weight": "200 g", "name": "buried bear trap", "color": "blue", + "memorial_male": { "ctxt": "memorial_male", "str": "Caught by a beartrap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Caught by a beartrap." }, "symbol": "^", "visibility": 9, "avoidance": 8, "difficulty": 4, "action": "beartrap", "drops": [ "beartrap" ], + "flags": [ "SONAR_DETECTABLE" ], "vehicle_data": { "damage": 300, "sound_volume": 8, @@ -173,6 +186,8 @@ "id": "tr_nailboard", "name": "spiked board", "color": "light_gray", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped on a spiked board." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped on a spiked board." }, "symbol": "_", "visibility": 1, "avoidance": 6, @@ -186,6 +201,8 @@ "id": "tr_caltrops", "name": "caltrops", "color": "dark_gray", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped on a caltrop." }, + "memorial_female": { "ctxt": "memorial_female", "str": "stepped on a caltrop." }, "symbol": "_", "visibility": 4, "avoidance": 6, @@ -199,6 +216,8 @@ "id": "tr_caltrops_glass", "name": "glass caltrops", "color": "dark_gray", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped on a glass caltrop." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped on a glass caltrop." }, "symbol": "_", "visibility": 6, "avoidance": 6, @@ -212,6 +231,8 @@ "id": "tr_tripwire", "name": "tripwire", "color": "light_red", + "memorial_male": { "ctxt": "memorial_male", "str": "Tripped on a tripwire." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Tripped on a tripwire." }, "symbol": "^", "visibility": 6, "avoidance": 4, @@ -225,6 +246,8 @@ "trigger_weight": "200 g", "name": "crossbow trap", "color": "green", + "memorial_male": { "ctxt": "memorial_male", "str": "Trigged a crossbow trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Trigged a crossbow trap." }, "symbol": "^", "visibility": 5, "avoidance": 4, @@ -248,6 +271,8 @@ "trigger_weight": "200 g", "name": "shotgun trap", "color": "red", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a shotgun trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a shotgun trap." }, "symbol": "^", "visibility": 4, "avoidance": 5, @@ -270,6 +295,8 @@ "trigger_weight": "200 g", "name": "shotgun trap", "color": "red", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a shotgun trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a shotgun trap." }, "symbol": "^", "visibility": 4, "avoidance": 5, @@ -293,6 +320,8 @@ "trigger_weight": "200 g", "name": "shotgun trap", "color": "red", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a shotgun trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a shotgun trap." }, "symbol": "^", "visibility": 4, "avoidance": 5, @@ -329,6 +358,8 @@ "id": "tr_blade", "name": "spinning blade", "color": "cyan", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a blade trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a blade trap." }, "symbol": "\\", "visibility": 0, "avoidance": 4, @@ -342,6 +373,8 @@ "trigger_weight": "200 g", "name": "land mine", "color": "red", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped on a land mine." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped on a land mine." }, "symbol": "^", "visibility": 1, "avoidance": 14, @@ -364,12 +397,15 @@ "trigger_weight": "200 g", "name": "buried land mine", "color": "red", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped on a land mine." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped on a land mine." }, "symbol": "_", "visibility": 10, "avoidance": 14, "difficulty": 10, "action": "landmine", "drops": [ "landmine" ], + "flags": [ "SONAR_DETECTABLE" ], "vehicle_data": { "do_explosion": true, "damage": 1000, @@ -386,6 +422,8 @@ "trigger_weight": "200 g", "name": "teleport pad", "color": "magenta", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a teleport trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a teleport trap." }, "symbol": "_", "visibility": 0, "avoidance": 15, @@ -398,6 +436,8 @@ "id": "tr_goo", "name": "goo pit", "color": "dark_gray", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped into thick goo." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped into thick goo." }, "symbol": "_", "visibility": 0, "avoidance": 15, @@ -409,6 +449,8 @@ "id": "tr_dissector", "name": "exposed high-energy conduit", "color": "cyan", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped into an exposed high-energy conduit." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped into an exposed high-energy conduit." }, "symbol": "7", "visibility": 2, "avoidance": 20, @@ -421,11 +463,14 @@ "id": "tr_sinkhole", "name": "sinkhole", "color": "brown", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped into a sinkhole." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped into a sinkhole." }, "symbol": "_", "visibility": 10, "avoidance": 14, "difficulty": 99, "action": "sinkhole", + "flags": [ "SONAR_DETECTABLE" ], "vehicle_data": { "damage": 500 } }, { @@ -433,6 +478,8 @@ "id": "tr_pit", "name": "pit", "color": "brown", + "memorial_male": { "ctxt": "memorial_male", "str": "Fell in a pit." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Fell in a pit." }, "symbol": "0", "visibility": 0, "avoidance": 8, @@ -445,6 +492,8 @@ "id": "tr_spike_pit", "name": "spiked pit", "color": "blue", + "memorial_male": { "ctxt": "memorial_male", "str": "Fell into a spiked pit." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Fell into a spiked pit." }, "symbol": "0", "visibility": 0, "avoidance": 8, @@ -457,11 +506,14 @@ "id": "tr_lava", "name": "lava", "color": "red", + "memorial_male": { "ctxt": "memorial_male", "str": "Stepped into lava." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Stepped into lava." }, "symbol": "~", "visibility": 0, "avoidance": 99, "difficulty": 99, "action": "lava", + "flags": [ "CONVECTS_TEMPERATURE" ], "vehicle_data": { "damage": 500 } }, { @@ -469,30 +521,22 @@ "id": "tr_portal", "name": "shimmering portal", "color": "magenta", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a teleoport trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a teleoport trap." }, "symbol": "%", "visibility": 0, "avoidance": 99, "difficulty": 99, "action": "portal" }, - { - "type": "trap", - "id": "tr_ledge", - "name": "ledge", - "color": "i_cyan", - "symbol": " ", - "visibility": 0, - "avoidance": 99999, - "difficulty": 99, - "action": "ledge", - "vehicle_data": { "is_falling": true } - }, { "type": "trap", "id": "tr_boobytrap", "trigger_weight": "200 g", "name": "booby trap", "color": "light_cyan", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a booby trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a booby trap." }, "symbol": "^", "visibility": 5, "avoidance": 4, @@ -514,6 +558,8 @@ "id": "tr_temple_flood", "name": "ledge", "color": "light_gray", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a flood trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a flood trap." }, "symbol": "^", "visibility": 9, "avoidance": 20, @@ -561,6 +607,8 @@ "id": "tr_shadow", "name": "", "color": "white", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a shadow trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a shadow trap." }, "symbol": "^", "visibility": 99, "avoidance": 99, @@ -573,6 +621,8 @@ "id": "tr_drain", "name": "", "color": "white", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a life-draining trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a life-draining trap." }, "symbol": "^", "visibility": 99, "avoidance": 99, @@ -585,6 +635,8 @@ "id": "tr_snake", "name": "", "color": "white", + "memorial_male": { "ctxt": "memorial_male", "str": "Triggered a shadow snake trap." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Triggered a shadow snake trap." }, "symbol": "^", "visibility": 99, "avoidance": 99, @@ -597,6 +649,8 @@ "id": "tr_glass_pit", "name": "glass pit", "color": "cyan", + "memorial_male": { "ctxt": "memorial_male", "str": "Fell into a pit filled with glass shards." }, + "memorial_female": { "ctxt": "memorial_female", "str": "Fell into a pit filled with glass shards." }, "symbol": "0", "visibility": 0, "avoidance": 8, diff --git a/doc/JSON_FLAGS.md b/doc/JSON_FLAGS.md index 1c727fbce1ee8..1c3c4c1f2e82b 100644 --- a/doc/JSON_FLAGS.md +++ b/doc/JSON_FLAGS.md @@ -206,6 +206,10 @@ These are handled through `ammo_types.json`. You can tag a weapon with these to - ```WIDE``` Prevents `HARDTOSHOOT` monster flag from having any effect. Implied by ```SHOT``` or liquid ammo. - ```NON_FOULING``` This ammo does not cause dirtying or blackpowder fouling on the gun when fired. +## Traps + +- ```SONAR_DETECTABLE``` This trap can be identified with ground-penetrating SONAR. +- ```CONVECTS_TEMPERATURE``` This trap convects temperature, like lava. ## Armor diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 97aee7655b8b6..82369db5cb8db 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -1960,6 +1960,7 @@ it is present to help catch errors. "spell_data": { "id": "bear_trap" }, // data required for trapfunc::spell() "trigger_weight": "200 g", // If an item with this weight or more is thrown onto the trap, it triggers. TODO: what is the default? "drops": [ "beartrap" ], // For disassembly? + "flags": [ "EXAMPLE_FLAG" ], // A set of valid flags for this trap "vehicle_data": { "damage": 300, "sound_volume": 8, diff --git a/src/game.cpp b/src/game.cpp index 5e161a35df947..1dec9200017fa 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1874,10 +1874,11 @@ int get_heat_radiation( const tripoint &location, bool direct ) int get_convection_temperature( const tripoint &location ) { + static const flag_id trap_convects( "CONVECTS_TEMPERATURE" ); int temp_mod = 0; map &here = get_map(); // Directly on lava tiles - int lava_mod = here.tr_at( location ) == tr_lava ? + int lava_mod = here.tr_at( location ).has_flag( trap_convects ) ? fd_fire->get_intensity_level().convection_temperature_mod : 0; // Modifier from fields for( auto fd : here.field_at( location ) ) { diff --git a/src/memorial_logger.cpp b/src/memorial_logger.cpp index 122180f7b8bd7..9de81018cf371 100644 --- a/src/memorial_logger.cpp +++ b/src/memorial_logger.cpp @@ -49,6 +49,7 @@ #include "skill.h" #include "stats_tracker.h" #include "translations.h" +#include "trap.h" #include "type_id.h" #include "units.h" @@ -57,36 +58,6 @@ static const efftype_id effect_datura( "datura" ); static const efftype_id effect_drunk( "drunk" ); static const efftype_id effect_jetinjector( "jetinjector" ); -static const trap_str_id tr_bubblewrap( "tr_bubblewrap" ); -static const trap_str_id tr_glass( "tr_glass" ); -static const trap_str_id tr_beartrap( "tr_beartrap" ); -static const trap_str_id tr_nailboard( "tr_nailboard" ); -static const trap_str_id tr_caltrops( "tr_caltrops" ); -static const trap_str_id tr_caltrops_glass( "tr_caltrops_glass" ); -static const trap_str_id tr_tripwire( "tr_tripwire" ); -static const trap_str_id tr_crossbow( "tr_crossbow" ); -static const trap_str_id tr_shotgun_2( "tr_shotgun_2" ); -static const trap_str_id tr_shotgun_1( "tr_shotgun_1" ); -static const trap_str_id tr_blade( "tr_blade" ); -static const trap_str_id tr_landmine( "tr_landmine" ); -static const trap_str_id tr_light_snare( "tr_light_snare" ); -static const trap_str_id tr_heavy_snare( "tr_heavy_snare" ); -static const trap_str_id tr_telepad( "tr_telepad" ); -static const trap_str_id tr_goo( "tr_goo" ); -static const trap_str_id tr_dissector( "tr_dissector" ); -static const trap_str_id tr_sinkhole( "tr_sinkhole" ); -static const trap_str_id tr_pit( "tr_pit" ); -static const trap_str_id tr_spike_pit( "tr_spike_pit" ); -static const trap_str_id tr_lava( "tr_lava" ); -static const trap_str_id tr_portal( "tr_portal" ); -static const trap_str_id tr_ledge( "tr_ledge" ); -static const trap_str_id tr_boobytrap( "tr_boobytrap" ); -static const trap_str_id tr_temple_flood( "tr_temple_flood" ); -static const trap_str_id tr_shadow( "tr_shadow" ); -static const trap_str_id tr_drain( "tr_drain" ); -static const trap_str_id tr_snake( "tr_snake" ); -static const trap_str_id tr_glass_pit( "tr_glass_pit" ); - static const trait_id trait_CANNIBAL( "CANNIBAL" ); static const trait_id trait_PSYCHOPATH( "PSYCHOPATH" ); static const trait_id trait_SAPIOVORE( "SAPIOVORE" ); @@ -655,87 +626,8 @@ void memorial_logger::notify( const cata::event &e ) character_id ch = e.get( "character" ); if( ch == avatar_id ) { trap_str_id trap = e.get( "trap" ); - if( trap == tr_bubblewrap ) { - add( pgettext( "memorial_male", "Stepped on bubble wrap." ), - pgettext( "memorial_female", "Stepped on bubble wrap." ) ); - } else if( trap == tr_glass ) { - add( pgettext( "memorial_male", "Stepped on glass." ), - pgettext( "memorial_female", "Stepped on glass." ) ); - } else if( trap == tr_beartrap ) { - add( pgettext( "memorial_male", "Caught by a beartrap." ), - pgettext( "memorial_female", "Caught by a beartrap." ) ); - } else if( trap == tr_nailboard ) { - add( pgettext( "memorial_male", "Stepped on a spiked board." ), - pgettext( "memorial_female", "Stepped on a spiked board." ) ); - } else if( trap == tr_caltrops ) { - add( pgettext( "memorial_male", "Stepped on a caltrop." ), - pgettext( "memorial_female", "Stepped on a caltrop." ) ); - } else if( trap == tr_caltrops_glass ) { - add( pgettext( "memorial_male", "Stepped on a glass caltrop." ), - pgettext( "memorial_female", "Stepped on a glass caltrop." ) ); - } else if( trap == tr_tripwire ) { - add( pgettext( "memorial_male", "Tripped on a tripwire." ), - pgettext( "memorial_female", "Tripped on a tripwire." ) ); - } else if( trap == tr_crossbow ) { - add( pgettext( "memorial_male", "Triggered a crossbow trap." ), - pgettext( "memorial_female", "Triggered a crossbow trap." ) ); - } else if( trap == tr_shotgun_1 || trap == tr_shotgun_2 ) { - add( pgettext( "memorial_male", "Triggered a shotgun trap." ), - pgettext( "memorial_female", "Triggered a shotgun trap." ) ); - } else if( trap == tr_blade ) { - add( pgettext( "memorial_male", "Triggered a blade trap." ), - pgettext( "memorial_female", "Triggered a blade trap." ) ); - } else if( trap == tr_light_snare ) { - add( pgettext( "memorial_male", "Triggered a light snare." ), - pgettext( "memorial_female", "Triggered a light snare." ) ); - } else if( trap == tr_heavy_snare ) { - add( pgettext( "memorial_male", "Triggered a heavy snare." ), - pgettext( "memorial_female", "Triggered a heavy snare." ) ); - } else if( trap == tr_landmine ) { - add( pgettext( "memorial_male", "Stepped on a land mine." ), - pgettext( "memorial_female", "Stepped on a land mine." ) ); - } else if( trap == tr_boobytrap ) { - add( pgettext( "memorial_male", "Triggered a booby trap." ), - pgettext( "memorial_female", "Triggered a booby trap." ) ); - } else if( trap == tr_telepad || trap == tr_portal ) { - add( pgettext( "memorial_male", "Triggered a teleport trap." ), - pgettext( "memorial_female", "Triggered a teleport trap." ) ); - } else if( trap == tr_goo ) { - add( pgettext( "memorial_male", "Stepped into thick goo." ), - pgettext( "memorial_female", "Stepped into thick goo." ) ); - } else if( trap == tr_dissector ) { - add( pgettext( "memorial_male", "Stepped into a dissector." ), - pgettext( "memorial_female", "Stepped into a dissector." ) ); - } else if( trap == tr_pit ) { - add( pgettext( "memorial_male", "Fell in a pit." ), - pgettext( "memorial_female", "Fell in a pit." ) ); - } else if( trap == tr_spike_pit ) { - add( pgettext( "memorial_male", "Fell into a spiked pit." ), - pgettext( "memorial_female", "Fell into a spiked pit." ) ); - } else if( trap == tr_glass_pit ) { - add( pgettext( "memorial_male", "Fell into a pit filled with glass shards." ), - pgettext( "memorial_female", "Fell into a pit filled with glass shards." ) ); - } else if( trap == tr_lava ) { - add( pgettext( "memorial_male", "Stepped into lava." ), - pgettext( "memorial_female", "Stepped into lava." ) ); - } else if( trap == tr_sinkhole ) { - add( pgettext( "memorial_male", "Stepped into a sinkhole." ), - pgettext( "memorial_female", "Stepped into a sinkhole." ) ); - } else if( trap == tr_ledge ) { - add( pgettext( "memorial_male", "Fell down a ledge." ), - pgettext( "memorial_female", "Fell down a ledge." ) ); - } else if( trap == tr_temple_flood ) { - add( pgettext( "memorial_male", "Triggered a flood trap." ), - pgettext( "memorial_female", "Triggered a flood trap." ) ); - } else if( trap == tr_shadow ) { - add( pgettext( "memorial_male", "Triggered a shadow trap." ), - pgettext( "memorial_female", "Triggered a shadow trap." ) ); - } else if( trap == tr_drain ) { - add( pgettext( "memorial_male", "Triggered a life-draining trap." ), - pgettext( "memorial_female", "Triggered a life-draining trap." ) ); - } else if( trap == tr_snake ) { - add( pgettext( "memorial_male", "Triggered a shadow snake trap." ), - pgettext( "memorial_female", "Triggered a shadow snake trap." ) ); + if( trap->has_memorial_msg() ) { + add( trap->memorial_msg( true ), trap->memorial_msg( false ) ); } } break; diff --git a/src/trap.cpp b/src/trap.cpp index d40d52ee58d58..3eb7195b13042 100644 --- a/src/trap.cpp +++ b/src/trap.cpp @@ -110,6 +110,17 @@ void trap::load( const JsonObject &jo, const std::string & ) mandatory( jo, was_loaded, "visibility", visibility ); mandatory( jo, was_loaded, "avoidance", avoidance ); mandatory( jo, was_loaded, "difficulty", difficulty ); + + optional( jo, was_loaded, "memorial_male", memorial_male ); + optional( jo, was_loaded, "memorial_female", memorial_female ); + + // Require either none, or both + if( !!memorial_male != !!memorial_female ) { + jo.throw_error( "Only one gender of memorial message specified for trap %s, but none or both required.", + id.str() ); + } + + optional( jo, was_loaded, "flags", _flags ); optional( jo, was_loaded, "trap_radius", trap_radius, 0 ); // TODO: Is there a generic_factory version of this? act = trap_function_from_string( jo.get_string( "action" ) ); @@ -195,8 +206,8 @@ bool trap::is_trivial_to_spot() const bool trap::detected_by_ground_sonar() const { - // @TODO make this a property - return loadid == tr_beartrap_buried || loadid == tr_landmine_buried || loadid == tr_sinkhole; + static const flag_id sonar_detectable = flag_id( "SONAR_DETECTABLE" ); + return has_flag( sonar_detectable ); } bool trap::detect_trap( const tripoint &pos, const Character &p ) const @@ -322,29 +333,28 @@ void trap::on_disarmed( map &m, const tripoint &p ) const ////////////////////////// // convenient int-lookup names for hard-coded functions -trap_id -tr_null, -tr_beartrap_buried, -tr_shotgun_2, -tr_shotgun_1, -tr_blade, -tr_landmine, -tr_landmine_buried, -tr_telepad, -tr_goo, -tr_dissector, -tr_sinkhole, -tr_pit, -tr_lava, -tr_portal, -tr_ledge, -tr_temple_flood, -tr_temple_toggle, -tr_glow, -tr_hum, -tr_shadow, -tr_drain, -tr_snake; +trap_id tr_null; +const trap_str_id tr_beartrap_buried( "tr_beartrap_buried" ); +const trap_str_id tr_shotgun_2( "tr_shotgun_2" ); +const trap_str_id tr_shotgun_1( "tr_shotgun_1" ); +const trap_str_id tr_blade( "tr_blade" ); +const trap_str_id tr_landmine( "tr_landmine" ); +const trap_str_id tr_landmine_buried( "tr_landmine_buried" ); +const trap_str_id tr_telepad( "tr_telepad" ); +const trap_str_id tr_goo( "tr_goo" ); +const trap_str_id tr_dissector( "tr_dissector" ); +const trap_str_id tr_sinkhole( "tr_sinkhole" ); +const trap_str_id tr_pit( "tr_pit" ); +const trap_str_id tr_lava( "tr_lava" ); +const trap_str_id tr_portal( "tr_portal" ); +const trap_str_id tr_ledge( "tr_ledge" ); +const trap_str_id tr_temple_flood( "tr_temple_flood" ); +const trap_str_id tr_temple_toggle( "tr_temple_toggle" ); +const trap_str_id tr_glow( "tr_glow" ); +const trap_str_id tr_hum( "tr_hum" ); +const trap_str_id tr_shadow( "tr_shadow" ); +const trap_str_id tr_drain( "tr_drain" ); +const trap_str_id tr_snake( "tr_snake" ); void trap::check_consistency() { @@ -378,31 +388,8 @@ void trap::finalize() funnel_traps.push_back( &t ); } } - const auto trapfind = []( const char *id ) { - return trap_str_id( id ).id(); - }; + tr_null = trap_str_id::NULL_ID().id(); - tr_beartrap_buried = trapfind( "tr_beartrap_buried" ); - tr_shotgun_2 = trapfind( "tr_shotgun_2" ); - tr_shotgun_1 = trapfind( "tr_shotgun_1" ); - tr_blade = trapfind( "tr_blade" ); - tr_landmine = trapfind( "tr_landmine" ); - tr_landmine_buried = trapfind( "tr_landmine_buried" ); - tr_telepad = trapfind( "tr_telepad" ); - tr_goo = trapfind( "tr_goo" ); - tr_dissector = trapfind( "tr_dissector" ); - tr_sinkhole = trapfind( "tr_sinkhole" ); - tr_pit = trapfind( "tr_pit" ); - tr_lava = trapfind( "tr_lava" ); - tr_portal = trapfind( "tr_portal" ); - tr_ledge = trapfind( "tr_ledge" ); - tr_temple_flood = trapfind( "tr_temple_flood" ); - tr_temple_toggle = trapfind( "tr_temple_toggle" ); - tr_glow = trapfind( "tr_glow" ); - tr_hum = trapfind( "tr_hum" ); - tr_shadow = trapfind( "tr_shadow" ); - tr_drain = trapfind( "tr_drain" ); - tr_snake = trapfind( "tr_snake" ); } std::string trap::debug_describe() const diff --git a/src/trap.h b/src/trap.h index 295d45eb92c33..91f7f55e728d9 100644 --- a/src/trap.h +++ b/src/trap.h @@ -137,6 +137,12 @@ struct trap { std::string map_regen; trap_function act; translation name_; + + cata::optional memorial_male; + cata::optional memorial_female; + + cata::flat_set _flags; + /** * If an item with this weight or more is thrown onto the trap, it triggers. */ @@ -166,6 +172,21 @@ struct trap { return loadid != id; } + bool has_flag( const flag_id &flag ) const { + return _flags.count( flag ); + } + + bool has_memorial_msg() const { + return memorial_male && memorial_female; + } + + std::string memorial_msg( bool male ) const { + if( male ) { + return memorial_male->translated(); + } + return memorial_female->translated(); + } + /** * Called when the player examines a tile. This is supposed to handled * all kind of interaction of the player with the trap, including removal. @@ -322,28 +343,27 @@ struct trap { const trap_function &trap_function_from_string( const std::string &function_name ); -extern trap_id -tr_null, -tr_beartrap_buried, -tr_shotgun_2, -tr_shotgun_1, -tr_blade, -tr_landmine, -tr_landmine_buried, -tr_telepad, -tr_goo, -tr_dissector, -tr_sinkhole, -tr_pit, -tr_lava, -tr_portal, -tr_ledge, -tr_temple_flood, -tr_temple_toggle, -tr_glow, -tr_hum, -tr_shadow, -tr_drain, -tr_snake; +extern trap_id tr_null; +extern const trap_str_id tr_beartrap_buried; +extern const trap_str_id tr_shotgun_2; +extern const trap_str_id tr_shotgun_1; +extern const trap_str_id tr_blade; +extern const trap_str_id tr_landmine; +extern const trap_str_id tr_landmine_buried; +extern const trap_str_id tr_telepad; +extern const trap_str_id tr_goo; +extern const trap_str_id tr_dissector; +extern const trap_str_id tr_sinkhole; +extern const trap_str_id tr_pit; +extern const trap_str_id tr_lava; +extern const trap_str_id tr_portal; +extern const trap_str_id tr_ledge; +extern const trap_str_id tr_temple_flood; +extern const trap_str_id tr_temple_toggle; +extern const trap_str_id tr_glow; +extern const trap_str_id tr_hum; +extern const trap_str_id tr_shadow; +extern const trap_str_id tr_drain; +extern const trap_str_id tr_snake; #endif // CATA_SRC_TRAP_H