From 46a80c5456a39d659ae88648004a33c5001cd3ee Mon Sep 17 00:00:00 2001 From: RenechCDDA <84619419+RenechCDDA@users.noreply.github.com> Date: Thu, 30 May 2024 14:44:17 -0400 Subject: [PATCH] Load sound-triggered traps with more safety Delete test-only trap function "sound_detect" Add dummy trap --- data/json/traps.json | 12 ------------ src/trap.cpp | 6 ++++++ src/trap.h | 2 +- src/trapfunc.cpp | 9 ++------- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/data/json/traps.json b/data/json/traps.json index ecfcea1fd47b5..e6ec7e1b260d6 100644 --- a/data/json/traps.json +++ b/data/json/traps.json @@ -1168,18 +1168,6 @@ "copy-from": "trap_base", "effect_str": "EOC_PORTAL_STORM_DUNGEON_NEXT_LEVEL" }, - { - "type": "trap", - "id": "tr_noisetest", - "name": "noise test trap", - "color": "light_cyan", - "symbol": "_", - "visibility": 0, - "avoidance": 8, - "difficulty": 0, - "action": "sound_detect", - "sound_threshold": [ 15, 25 ] - }, { "type": "trap", "id": "tr_teeth", diff --git a/src/trap.cpp b/src/trap.cpp index 5d327f79ec7c1..df14529751b0d 100644 --- a/src/trap.cpp +++ b/src/trap.cpp @@ -429,6 +429,12 @@ void trap::check_consistency() debugmsg( "trap %s has unknown item as component %s", t.id.str(), item_type.str() ); } } + if( t.sound_threshold.first > t.sound_threshold.second ) { + debugmsg( "trap %s has higher min sound threshold than max and can never trigger", t.id.str() ); + } + if( t.sound_threshold.first > 0 != t.sound_threshold.second > 0 ) { + debugmsg( "trap %s has bad sound threshold of 0 and will trigger on anything", t.id.str() ); + } } } diff --git a/src/trap.h b/src/trap.h index 518d9d423ea27..848054e380861 100644 --- a/src/trap.h +++ b/src/trap.h @@ -65,7 +65,7 @@ bool map_regen( const tripoint &p, Creature *c, item *i ); bool drain( const tripoint &p, Creature *c, item *i ); bool snake( const tripoint &p, Creature *c, item *i ); bool cast_spell( const tripoint &p, Creature *critter, item * ); -bool sound_detect( const tripoint &p, Creature *, item * ); +bool dummy_trap( const tripoint &p, Creature *critter, item * ); } // namespace trapfunc struct vehicle_handle_trap_data { diff --git a/src/trapfunc.cpp b/src/trapfunc.cpp index 791010d0a2937..63709e1344863 100644 --- a/src/trapfunc.cpp +++ b/src/trapfunc.cpp @@ -1636,13 +1636,8 @@ bool trapfunc::snake( const tripoint &p, Creature *, item * ) return true; } -/** - * Made to test sound-triggered traps. - * Warning: generating a sound can trigger sound-triggered traps. - */ -bool trapfunc::sound_detect( const tripoint &p, Creature *, item * ) +bool trapfunc::dummy_trap( const tripoint &, Creature *, item * ) { - sounds::sound( p, 10, sounds::sound_t::alert, _( "Sound Detected!" ), false, "misc" ); return true; } @@ -1690,7 +1685,7 @@ const trap_function &trap_function_from_string( const std::string &function_name { "drain", trapfunc::drain }, { "spell", trapfunc::cast_spell }, { "snake", trapfunc::snake }, - { "sound_detect", trapfunc::sound_detect } + { "dummy_trap", trapfunc::dummy_trap } } };