Skip to content

Commit

Permalink
Load sound-triggered traps with more safety
Browse files Browse the repository at this point in the history
Delete test-only trap function "sound_detect"
Add dummy trap
  • Loading branch information
RenechCDDA committed May 30, 2024
1 parent 8249ff5 commit 58f5446
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
12 changes: 0 additions & 12 deletions data/json/traps.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/trap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/trap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 2 additions & 7 deletions src/trapfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 }
}
};

Expand Down

0 comments on commit 58f5446

Please sign in to comment.