Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and jsonize item dropping and trap conversion in trap-vehicle interaction #33459

Merged
merged 7 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 49 additions & 7 deletions data/json/traps.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@
"difficulty": 3,
"action": "beartrap",
"drops": [ "beartrap" ],
"vehicle_data": { "damage": 300, "sound_volume": 8, "sound": "SNAP!", "sound_type": "trap", "sound_variant": "bear_trap" }
"vehicle_data": {
"damage": 300,
"sound_volume": 8,
"sound": "SNAP!",
"sound_type": "trap",
"sound_variant": "bear_trap",
"remove_trap": true,
"spawn_items": [ "beartrap" ]
}
},
{
"type": "trap",
Expand All @@ -136,7 +144,15 @@
"difficulty": 4,
"action": "beartrap",
"drops": [ "beartrap" ],
"vehicle_data": { "damage": 300, "sound_volume": 8, "sound": "SNAP!", "sound_type": "trap", "sound_variant": "bear_trap" }
"vehicle_data": {
"damage": 300,
"sound_volume": 8,
"sound": "SNAP!",
"sound_type": "trap",
"sound_variant": "bear_trap",
"remove_trap": true,
"spawn_items": [ "beartrap" ]
}
},
{
"type": "trap",
Expand Down Expand Up @@ -202,13 +218,14 @@
"action": "crossbow",
"drops": [ "string_36", "crossbow", "bolt_steel" ],
"vehicle_data": {
"remove_trap": true,
"chance": 30,
"damage": 300,
"sound_volume": 1,
"sound": "Clank!",
"sound_type": "fire_gun",
"sound_variant": "crossbow"
"sound_variant": "crossbow",
"remove_trap": true,
"spawn_items": [ "crossbow", "string_6", { "id": "bolt_steel", "chance": 0.9 } ]
}
},
{
Expand All @@ -224,13 +241,36 @@
"action": "shotgun",
"drops": [ "string_36", "shotgun_d", { "item": "shot_00", "quantity": 2, "charges": 1 } ],
"vehicle_data": {
"remove_trap": true,
"chance": 70,
"damage": 300,
"sound_volume": 60,
"sound": "Bang!",
"sound_type": "fire_gun",
"sound_variant": "shotgun_d"
"sound_variant": "shotgun_d",
"set_trap": "tr_shotgun_2_1"
}
},
{
"type": "trap",
"id": "tr_shotgun_2_1",
"trigger_weight": 200,
"name": "shotgun trap",
"color": "red",
"symbol": "^",
"visibility": 4,
"avoidance": 5,
"difficulty": 6,
"action": "shotgun",
"drops": [ "string_36", "shotgun_d", { "item": "shot_00", "quantity": 1, "charges": 1 } ],
"vehicle_data": {
"chance": 70,
"damage": 300,
"sound_volume": 60,
"sound": "Bang!",
"sound_type": "fire_gun",
"sound_variant": "shotgun_d",
"remove_trap": true,
"spawn_items": [ "shotgun_d", "string_6" ]
}
},
{
Expand All @@ -251,7 +291,9 @@
"sound_volume": 60,
"sound": "Bang!",
"sound_type": "fire_gun",
"sound_variant": "shotgun_s"
"sound_variant": "shotgun_s",
"remove_trap": true,
"spawn_items": [ "shotgun_s", "string_6" ]
}
},
{
Expand Down
10 changes: 1 addition & 9 deletions gfx/ChestHole16Tileset/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -50771,15 +50771,7 @@
"rotates": false
},
{
"id": "shotgun_trap",
"fg": 2602
},
{
"id": "tr_shotgun_2",
"fg": 2602
},
{
"id": "tr_shotgun_1",
"id": [ "shotgun_trap", "tr_shotgun_2", "tr_shotgun_2_1", "tr_shotgun_1" ],
"fg": 2602
},
{
Expand Down
10 changes: 1 addition & 9 deletions gfx/ChestHole32Tileset/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -50746,15 +50746,7 @@
"rotates": false
},
{
"id": "shotgun_trap",
"fg": 2602
},
{
"id": "tr_shotgun_2",
"fg": 2602
},
{
"id": "tr_shotgun_1",
"id": [ "shotgun_trap", "tr_shotgun_2", "tr_shotgun_2_1", "tr_shotgun_1" ],
"fg": 2602
},
{
Expand Down
4 changes: 2 additions & 2 deletions gfx/ChestHole32Tileset_iso/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12635,8 +12635,8 @@
"rotates": false
},
{
"fg": 2602,
"id": ["shotgun_trap", "tr_shotgun_2", "tr_shotgun_1"]
"id": [ "shotgun_trap", "tr_shotgun_2", "tr_shotgun_2_1", "tr_shotgun_1" ],
"fg": 2602
},
{
"fg": 2603,
Expand Down
10 changes: 1 addition & 9 deletions gfx/ChestHoleTileset/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -50781,15 +50781,7 @@
"rotates": false
},
{
"id": "shotgun_trap",
"fg": 2602
},
{
"id": "tr_shotgun_2",
"fg": 2602
},
{
"id": "tr_shotgun_1",
"id": [ "shotgun_trap", "tr_shotgun_2", "tr_shotgun_2_1", "tr_shotgun_1" ],
"fg": 2602
},
{
Expand Down
2 changes: 1 addition & 1 deletion gfx/HitButton_iso/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5113,7 +5113,7 @@
"fg": 1591
},
{
"id": ["rm20", "rm120c", "pipe_combination_gun", "blunderbuss", "shotgun_sawn", "shotgun_s", "shotgun_d", "remington_870", "mossberg_500", "ksg", "m1014", "saiga_12", "l_def_12", "revolver_shotgun", "pipe_shotgun", "pipe_double_shotgun", "pipe_shotgunsawn", "bigun", "abzats", "shotgun_trap", "tr_shotgun_1", "tr_shotgun_2" ],
"id": ["rm20", "rm120c", "pipe_combination_gun", "blunderbuss", "shotgun_sawn", "shotgun_s", "shotgun_d", "remington_870", "mossberg_500", "ksg", "m1014", "saiga_12", "l_def_12", "revolver_shotgun", "pipe_shotgun", "pipe_double_shotgun", "pipe_shotgunsawn", "bigun", "abzats", "shotgun_trap", "tr_shotgun_1", "tr_shotgun_2", "tr_shotgun_2_1" ],
"fg": 1592
},
{
Expand Down
8 changes: 1 addition & 7 deletions gfx/HoderTileset/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1899,13 +1899,7 @@
"rotates":false
},
{
"id":"tr_shotgun_2",
"fg":1403,
"bg":191,
"rotates":false
},
{
"id":"tr_shotgun_1",
"id": [ "tr_shotgun_2", "tr_shotgun_2_1", "tr_shotgun_1" ],
"fg":1403,
"bg":191,
"rotates":false
Expand Down
8 changes: 2 additions & 6 deletions gfx/MSX++DeadPeopleEdition/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -88310,11 +88310,7 @@
"rotates": false
},
{
"id": "tr_shotgun_2",
"fg": 3932
},
{
"id": "tr_shotgun_1",
"id": [ "tr_shotgun_2", "tr_shotgun_2_1", "tr_shotgun_1" ],
"fg": 3932
},
{
Expand Down Expand Up @@ -130112,4 +130108,4 @@
]
}
]
}
}
6 changes: 1 addition & 5 deletions gfx/MShock24TilesetModded/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22751,11 +22751,7 @@
"rotates": false
},
{
"id": "tr_shotgun_2",
"fg": 2851
},
{
"id": "tr_shotgun_1",
"id": [ "tr_shotgun_2", "tr_shotgun_2_1", "tr_shotgun_1" ],
"fg": 2851
},
{
Expand Down
6 changes: 1 addition & 5 deletions gfx/MShock32TilesetModded/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22751,11 +22751,7 @@
"rotates": false
},
{
"id": "tr_shotgun_2",
"fg": 2851
},
{
"id": "tr_shotgun_1",
"id": [ "tr_shotgun_2", "tr_shotgun_2_1", "tr_shotgun_1" ],
"fg": 2851
},
{
Expand Down
6 changes: 1 addition & 5 deletions gfx/MshockXotto+/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -35400,11 +35400,7 @@
"rotates": false
},
{
"id": "tr_shotgun_2",
"fg": 3932
},
{
"id": "tr_shotgun_1",
"id": [ "tr_shotgun_2", "tr_shotgun_2_1", "tr_shotgun_1" ],
"fg": 3932
},
{
Expand Down
2 changes: 1 addition & 1 deletion gfx/RetroDaysTileset/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@
{ "id": "crossbow_trap", "fg": 857, "rotates": false },
{ "id": "tr_nailboard", "fg": 858, "rotates": false },
{ "id": "board_trap", "fg": 859, "rotates": false },
{ "id": [ "tr_shotgun_1", "tr_shotgun_2" ], "fg": 860, "rotates": false },
{ "id": [ "tr_shotgun_1", "tr_shotgun_2", "tr_shotgun_2_1" ], "fg": 860, "rotates": false },
{ "id": "shotgun_trap", "fg": 861, "rotates": false },
{ "id": "tr_tripwire", "fg": 862, "rotates": false },
{ "id": "tripwire", "fg": 863, "rotates": false },
Expand Down
4 changes: 4 additions & 0 deletions gfx/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,10 @@
"id":"tr_shotgun_2",
"rotates":false
},
{
"id":"tr_shotgun_2_1",
"rotates":false
},
{
"id":"tr_shotgun_1",
"rotates":false
Expand Down
7 changes: 7 additions & 0 deletions gfx/tile_config_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,13 @@
"rotates":false,
"multitile":false
},
{
"id": "tr_shotgun_2_1",
"fg":-1,
"bg":-1,
"rotates":false,
"multitile":false
},
{
"id": "tr_shotgun_1",
"fg":-1,
Expand Down
35 changes: 17 additions & 18 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,24 +543,6 @@ vehicle *map::move_vehicle( vehicle &veh, const tripoint &dp, const tileray &fac
}
}

// Now we're gonna handle traps we're standing on (if we're still moving).
if( !vertical && can_move ) {
const auto wheel_indices = veh.wheelcache; // Don't use a reference here, it causes a crash.
for( auto &w : wheel_indices ) {
const tripoint wheel_p = veh.global_part_pos3( w );
if( one_in( 2 ) && displace_water( wheel_p ) ) {
sounds::sound( wheel_p, 4, sounds::sound_t::movement, _( "splash!" ), false,
"environment", "splash" );
}

veh.handle_trap( wheel_p, w );
if( !has_flag( "SEALED", wheel_p ) ) {
// TODO: Make this value depend on the wheel
smash_items( wheel_p, 5 );
}
}
}

const int last_turn_dec = 1;
if( veh.last_turn < 0 ) {
veh.last_turn += last_turn_dec;
Expand Down Expand Up @@ -606,6 +588,23 @@ vehicle *map::move_vehicle( vehicle &veh, const tripoint &dp, const tileray &fac
veh.possibly_recover_from_skid();
}
}
// Now we're gonna handle traps we're standing on (if we're still moving).
if( !vertical && can_move ) {
const auto wheel_indices = veh.wheelcache; // Don't use a reference here, it causes a crash.
for( auto &w : wheel_indices ) {
const tripoint wheel_p = veh.global_part_pos3( w );
if( one_in( 2 ) && displace_water( wheel_p ) ) {
sounds::sound( wheel_p, 4, sounds::sound_t::movement, _( "splash!" ), false,
"environment", "splash" );
}

veh.handle_trap( wheel_p, w );
if( !has_flag( "SEALED", wheel_p ) ) {
// TODO: Make this value depend on the wheel
smash_items( wheel_p, 5 );
}
}
}
// Redraw scene
// But only if the vehicle was seen before or after the move
if( seen || sees_veh( g->u, veh, true ) ) {
Expand Down
18 changes: 18 additions & 0 deletions src/trap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ void trap::load( JsonObject &jo, const std::string & )
vehicle_data.sound = jv.get_string( "sound", "" );
vehicle_data.sound_type = jv.get_string( "sound_type", "" );
vehicle_data.sound_variant = jv.get_string( "sound_variant", "" );
vehicle_data.spawn_items.clear();
if( jv.has_array( "spawn_items" ) ) {
JsonArray ja = jv.get_array( "spawn_items" );
while( ja.has_more() ) {
if( ja.test_object() ) {
JsonObject joitm = ja.next_object();
vehicle_data.spawn_items.emplace_back( joitm.get_string( "id" ), joitm.get_float( "chance" ) );
} else {
vehicle_data.spawn_items.emplace_back( ja.next_string(), 1.0 );
}
}
}
vehicle_data.set_trap = trap_str_id::NULL_ID();
if( jv.read( "set_trap", vehicle_data.set_trap ) ) {
vehicle_data.remove_trap = false;
}
}
}

Expand Down Expand Up @@ -257,6 +273,7 @@ tr_caltrops_glass,
tr_tripwire,
tr_crossbow,
tr_shotgun_2,
tr_shotgun_2_1,
tr_shotgun_1,
tr_engine,
tr_blade,
Expand Down Expand Up @@ -324,6 +341,7 @@ void trap::finalize()
tr_tripwire = trapfind( "tr_tripwire" );
tr_crossbow = trapfind( "tr_crossbow" );
tr_shotgun_2 = trapfind( "tr_shotgun_2" );
tr_shotgun_2_1 = trapfind( "tr_shotgun_2_1" );
tr_shotgun_1 = trapfind( "tr_shotgun_1" );
tr_engine = trapfind( "tr_engine" );
tr_blade = trapfind( "tr_blade" );
Expand Down
6 changes: 6 additions & 0 deletions src/trap.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ void snake( const tripoint &p, Creature *c, item *i );
} // namespace trapfunc

struct vehicle_handle_trap_data {
using itype_id = std::string;

bool remove_trap = false;
bool do_explosion = false;
bool is_falling = false;
Expand All @@ -73,6 +75,9 @@ struct vehicle_handle_trap_data {
std::string sound;
std::string sound_type;
std::string sound_variant;
// the double represents the count or chance to spawn.
std::vector<std::pair<itype_id, double>> spawn_items;
trap_str_id set_trap = trap_str_id::NULL_ID();
};

using trap_function = std::function<void( const tripoint &, Creature *, item * )>;
Expand Down Expand Up @@ -254,6 +259,7 @@ tr_caltrops_glass,
tr_tripwire,
tr_crossbow,
tr_shotgun_2,
tr_shotgun_2_1,
tr_shotgun_1,
tr_engine,
tr_blade,
Expand Down
Loading