Skip to content

Commit

Permalink
Merge pull request #77092 from RenechCDDA/appliance_tracks_damage_v2
Browse files Browse the repository at this point in the history
Re-implement #73588 damaged appliances track damage when transformed to item and back
  • Loading branch information
dseguin authored Oct 21, 2024
2 parents d5b7e72 + 34df54c commit d5265ca
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,11 @@ std::optional<int> deploy_appliance_actor::use( Character *p, item &it, const tr
}

it.spill_contents( suitable.value() );
place_appliance( tripoint_bub_ms( suitable.value() ), vpart_appliance_from_item( appliance_base ) );
if( !place_appliance( tripoint_bub_ms( suitable.value() ),
vpart_appliance_from_item( appliance_base ), it ) ) {
// failed to place somehow, cancel!!
return 0;
}
p->mod_moves( -to_moves<int>( 2_seconds ) );
return 1;
}
Expand Down
14 changes: 12 additions & 2 deletions src/veh_appliance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vpart_id vpart_appliance_from_item( const itype_id &item_id )
return vpart_ap_standing_lamp;
}

void place_appliance( const tripoint_bub_ms &p, const vpart_id &vpart,
bool place_appliance( const tripoint_bub_ms &p, const vpart_id &vpart,
const std::optional<item> &base )
{

Expand All @@ -64,18 +64,27 @@ void place_appliance( const tripoint_bub_ms &p, const vpart_id &vpart,

if( !veh ) {
debugmsg( "error constructing vehicle" );
return;
return false;
}

veh->add_tag( flag_APPLIANCE );

int partnum = -1;
if( base ) {
item copied = *base;
if( vpinfo.base_item != copied.typeId() ) {
// transform the deploying item into what it *should* be before storing it
copied.convert( vpinfo.base_item );
}
partnum = veh->install_part( point_zero, vpart, std::move( copied ) );
} else {
partnum = veh->install_part( point_zero, vpart );
}
if( partnum == -1 ) {
// unrecoverable, failed to be installed somehow
here.destroy_vehicle( veh );
return false;
}
veh->name = vpart->name();

veh->last_update = calendar::turn;
Expand Down Expand Up @@ -114,6 +123,7 @@ void place_appliance( const tripoint_bub_ms &p, const vpart_id &vpart,
if( vpinfo.has_flag( flag_HALF_CIRCLE_LIGHT ) && partnum != -1 ) {
orient_part( veh, vpinfo, partnum );
}
return true;
}

player_activity veh_app_interact::run( vehicle &veh, const point &p )
Expand Down
2 changes: 1 addition & 1 deletion src/veh_appliance.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class vehicle;
class ui_adaptor;

vpart_id vpart_appliance_from_item( const itype_id &item_id );
void place_appliance( const tripoint_bub_ms &p, const vpart_id &vpart,
bool place_appliance( const tripoint_bub_ms &p, const vpart_id &vpart,
const std::optional<item> &base = std::nullopt );

/**
Expand Down
4 changes: 4 additions & 0 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,10 @@ int vehicle::install_part( const point &dp, const vpart_id &type, item &&base,

int vehicle::install_part( const point &dp, vehicle_part &&vp )
{
if( vp.base.is_null() ) {
debugmsg( "Part to be installed is missing base item, did the constructor fail to set_base?" );
return -1;
}
const vpart_info &vpi = vp.info();
const ret_val<void> valid_mount = can_mount( dp, vpi );
if( !valid_mount.success() ) {
Expand Down
1 change: 1 addition & 0 deletions src/vehicle_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void vehicle_part::set_base( item &&new_base )
if( new_base.typeId() != info().base_item ) {
debugmsg( "new base '%s' doesn't match part type '%s', this is a bug",
new_base.typeId().str(), info().id.str() );
base = null_item_reference();
return;
}
base = std::move( new_base );
Expand Down

0 comments on commit d5265ca

Please sign in to comment.