Skip to content

Commit

Permalink
Move traps externs from int to string ids
Browse files Browse the repository at this point in the history
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 CleverRaven#44261 - see CleverRaven#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.
  • Loading branch information
anothersimulacrum committed Mar 7, 2021
1 parent 518b4fa commit 8730fc0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 84 deletions.
17 changes: 17 additions & 0 deletions data/core/traps.json
Original file line number Diff line number Diff line change
@@ -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 }
}
]
14 changes: 0 additions & 14 deletions data/json/traps.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,20 +529,6 @@
"difficulty": 99,
"action": "portal"
},
{
"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 }
},
{
"type": "trap",
"id": "tr_boobytrap",
Expand Down
70 changes: 23 additions & 47 deletions src/trap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,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()
{
Expand Down Expand Up @@ -389,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
Expand Down
45 changes: 22 additions & 23 deletions src/trap.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,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

0 comments on commit 8730fc0

Please sign in to comment.