diff --git a/data/json/gates.json b/data/json/gates.json index fa467f0ec44cb..5f1968fd16afe 100644 --- a/data/json/gates.json +++ b/data/json/gates.json @@ -2,39 +2,17 @@ { "type" : "gate", "handle" : "t_gates_mech_control", - "wall" : "t_wall", - "door" : "t_door_metal_locked", - "floor" : "t_floor", - "messages" : { - "pull" : "You turn the handle...", - "open" : "The gate is opened!", - "close" : "The gate is closed!", - "fail" : "The gate can't be closed!" - }, - "moves" : 1800, - "bashing_damage" : 40 - }, - { - "type" : "gate", - "handle" : "t_gates_control_concrete", - "wall" : "t_concrete_wall", - "door" : "t_door_metal_locked", - "floor" : "t_floor", - "messages" : { - "pull" : "You turn the handle...", - "open" : "The gate is opened!", - "close" : "The gate is closed!", - "fail" : "The gate can't be closed!" - }, - "moves" : 1800, - "bashing_damage" : 40 - }, - { - "type" : "gate", - "handle" : "t_gates_control_brick", - "wall" : "t_brick_wall", + "other_handles" : [ + "t_gates_control_concrete", + "t_gates_control_brick" + ], "door" : "t_door_metal_locked", "floor" : "t_floor", + "walls" : [ + "t_wall", + "t_concrete_wall", + "t_brick_wall" + ], "messages" : { "pull" : "You turn the handle...", "open" : "The gate is opened!", @@ -50,6 +28,7 @@ "wall" : "t_wall_wood", "door" : "t_door_metal_locked", "floor" : "t_dirtfloor", + "walls" : "t_wall_wood", "messages" : { "pull" : "You pull the rope...", "open" : "The barn doors opened!", @@ -62,9 +41,9 @@ { "type" : "gate", "handle" : "t_palisade_pulley", - "wall" : "t_palisade", "door" : "t_palisade_gate", "floor" : "t_palisade_gate_o", + "walls" : "t_palisade", "messages" : { "pull" : "You pull the rope...", "open" : "The palisade gate swings open!", @@ -77,9 +56,9 @@ { "type" : "gate", "handle" : "t_gates_control_metal", - "wall" : "t_wall_metal", "door" : "t_door_metal_locked", "floor" : "t_metal_floor", + "walls" : "t_wall_metal", "messages" : { "pull" : "You throw the lever...", "open" : "The door rises!", diff --git a/src/gates.cpp b/src/gates.cpp index def08b11c8a75..5eed53159cb87 100644 --- a/src/gates.cpp +++ b/src/gates.cpp @@ -17,18 +17,15 @@ using gate_id = string_id; struct gate_data { gate_data() : - wall(), - door(), - floor(), moves( 0 ), bash_dmg( 0 ), was_loaded( false ) {}; gate_id id; - ter_str_id wall; ter_str_id door; ter_str_id floor; + std::vector walls; std::string pull_message; std::string open_message; @@ -40,6 +37,7 @@ struct gate_data { bool was_loaded; void load( JsonObject &jo ); + bool is_suitable_wall( const tripoint &pos ) const; }; gate_id get_gate_id( const tripoint &pos ) @@ -47,15 +45,15 @@ gate_id get_gate_id( const tripoint &pos ) return gate_id( g->m.get_ter( pos ).str() ); } -generic_factory gates_data( "gate type", "handle" ); +generic_factory gates_data( "gate type", "handle", "other_handles" ); } void gate_data::load( JsonObject &jo ) { - mandatory( jo, was_loaded, "wall", wall ); mandatory( jo, was_loaded, "door", door ); mandatory( jo, was_loaded, "floor", floor ); + mandatory( jo, was_loaded, "walls", walls, string_id_reader {} ); if( !was_loaded || jo.has_member( "messages" ) ) { JsonObject messages_obj = jo.get_object( "messages" ); @@ -70,6 +68,15 @@ void gate_data::load( JsonObject &jo ) optional( jo, was_loaded, "bashing_damage", bash_dmg, 0 ); } +bool gate_data::is_suitable_wall( const tripoint &pos ) const +{ + const auto wid = g->m.ter( pos ); + const auto iter = std::find_if( walls.begin(), walls.end(), [ wid ]( const ter_str_id & wall ) { + return wall.id() == wid; + } ); + return iter != walls.end(); +} + void gates::load_gates( JsonObject &jo ) { gates_data.load( jo ); @@ -110,7 +117,7 @@ void gates::open_gate( const tripoint &pos ) static const tripoint dir[4] = { { 1, 0, 0 }, { 0, 1, 0 }, { -1, 0, 0 }, { 0, -1, 0 } }; const tripoint wall_pos = pos + dir[i]; - if( g->m.ter( wall_pos ) != gate.wall.id() ) { + if( !gate.is_suitable_wall( wall_pos ) ) { continue; }