Skip to content

Commit

Permalink
Merge pull request #40594 from anothersimulacrum/hey-now
Browse files Browse the repository at this point in the history
Add ability to smash vehicle parts on removal
  • Loading branch information
ZhilkinSerg authored Jun 4, 2020
2 parents 04aa54f + ded6c8e commit a865ac0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
4 changes: 3 additions & 1 deletion data/json/vehicleparts/rotor.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"color": "light_blue",
"broken_symbol": "O",
"broken_color": "light_gray",
"flags": [ "ROTOR", "NO_INSTALL_PLAYER", "NO_UNINSTALL", "NO_REPAIR" ],
"flags": [ "ROTOR", "NO_INSTALL_PLAYER", "NO_REPAIR", "SMASH_REMOVE" ],
"description": "A set of aerofoil helicopter rotors, when spun at high speed, they generate thrust via lift."
},
{
Expand All @@ -21,6 +21,7 @@
"durability": 450,
"description": "A set of four military-grade helicopter rotor blades, used to provide lift by rotation.",
"damage_modifier": 80,
"requirements": { "removal": { "skills": [ [ "mechanics", 3 ] ], "time": "1 h", "using": "vehicle_weld_removal" } },
"breaks_into": [ { "item": "scrap", "count": [ 15, 30 ] }, { "item": "steel_chunk", "count": [ 8, 16 ] } ],
"damage_reduction": { "all": 66 }
},
Expand All @@ -35,6 +36,7 @@
"durability": 100,
"description": "A set of four military-grade helicopter rotor blades, used to provide lift by rotation.",
"damage_modifier": 80,
"requirements": { "removal": { "skills": [ [ "mechanics", 3 ] ], "time": "1 h", "using": "vehicle_weld_removal" } },
"breaks_into": [ { "item": "scrap", "count": [ 8, 15 ] }, { "item": "steel_chunk", "count": [ 2, 8 ] } ],
"damage_reduction": { "all": 22 }
},
Expand Down
1 change: 1 addition & 0 deletions doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ Those flags are added by the game code to specific items (that specific welder,
- ```SECURITY```
- ```SHARP``` Striking a monster with this part does cutting damage instead of bashing damage, and prevents stunning the monster.
- ```SIMPLE_PART``` This part can be installed or removed from that otherwise prevent modification.
- ```SMASH_REMOVE``` When you remove this part, instead of getting the item back, you will get the bash results.
- ```SOLAR_PANEL``` Recharges vehicle batteries when exposed to sunlight. Has a 1 in 4 chance of being broken on car generation.
- ```SPACE_HEATER``` There is separate command to toggle this part.
- ```STABLE``` Similar to `WHEEL`, but if the vehicle is only a 1x1 section, this single wheel counts as enough wheels.
Expand Down
33 changes: 25 additions & 8 deletions src/veh_interact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,8 +1723,10 @@ bool veh_interact::can_remove_part( int idx, const player &p )
sel_vehicle_part = &veh->parts[idx];
sel_vpart_info = &sel_vehicle_part->info();
std::string nmsg;
bool smash_remove = sel_vpart_info->has_flag( "SMASH_REMOVE" );

if( veh->has_part( "NO_MODIFY_VEHICLE" ) && !sel_vpart_info->has_flag( "SIMPLE_PART" ) ) {
if( veh->has_part( "NO_MODIFY_VEHICLE" ) && !sel_vpart_info->has_flag( "SIMPLE_PART" ) &&
!smash_remove ) {
msg = _( "This vehicle cannot be modified in this way.\n" );
return false;
} else if( sel_vpart_info->has_flag( "NO_UNINSTALL" ) ) {
Expand All @@ -1736,6 +1738,13 @@ bool veh_interact::can_remove_part( int idx, const player &p )
nmsg += string_format(
_( "<color_white>Removing the broken %1$s may yield some fragments.</color>\n" ),
sel_vehicle_part->name() );
} else if( smash_remove ) {
std::set<std::string> removed_names;
for( const item &it : sel_vehicle_part->pieces_for_broken_part() ) {
removed_names.insert( it.tname() );
}
nmsg += string_format( _( "<color_white>Removing the %1$s may yield:</color>\n> %2$s\n" ),
sel_vehicle_part->name(), enumerate_as_string( removed_names ) );
} else {
item result_of_removal = sel_vehicle_part->properties_to_item();
nmsg += string_format(
Expand Down Expand Up @@ -3128,25 +3137,33 @@ void veh_interact::complete_vehicle( player &p )
veh->tow_data.clear_towing();
}
bool broken = veh->parts[ vehicle_part ].is_broken();
bool smash_remove = veh->parts[vehicle_part].info().has_flag( "SMASH_REMOVE" );

if( broken ) {
p.add_msg_if_player( _( "You remove the broken %1$s from the %2$s." ),
veh->parts[ vehicle_part ].name(), veh->name );
} else if( smash_remove ) {
p.add_msg_if_player( _( "You smash the %1$s to bits, removing it from the %2$s." ),
veh->parts[ vehicle_part ].name(), veh->name );
} else {
p.add_msg_if_player( _( "You remove the %1$s from the %2$s." ),
veh->parts[ vehicle_part ].name(), veh->name );
}

if( !broken ) {
resulting_items.push_back( veh->parts[vehicle_part].properties_to_item() );
for( const auto &sk : vpinfo.install_skills ) {
if( broken ) {
item_group::ItemList pieces = veh->parts[vehicle_part].pieces_for_broken_part();
resulting_items.insert( resulting_items.end(), pieces.begin(), pieces.end() );
} else {
if( smash_remove ) {
item_group::ItemList pieces = veh->parts[vehicle_part].pieces_for_broken_part();
resulting_items.insert( resulting_items.end(), pieces.begin(), pieces.end() );
} else {
resulting_items.push_back( veh->parts[vehicle_part].properties_to_item() );
}
for( const std::pair<const skill_id, int> &sk : vpinfo.install_skills ) {
// removal is half as educational as installation
p.practice( sk.first, veh_utils::calc_xp_gain( vpinfo, sk.first ) / 2 );
}

} else {
auto pieces = veh->parts[vehicle_part].pieces_for_broken_part();
resulting_items.insert( resulting_items.end(), pieces.begin(), pieces.end() );
}

if( veh->parts.size() < 2 ) {
Expand Down

0 comments on commit a865ac0

Please sign in to comment.