Skip to content

Commit

Permalink
fix: folding vehicles fold up into proper item (#5845)
Browse files Browse the repository at this point in the history
* unhardcode folding vehicle. remove "folded" from naming scheme, and lower first letter.

* remove "Foldable" from wheelchair name

* condense if else statement back down
  • Loading branch information
shmakota authored Dec 28, 2024
1 parent 262fa72 commit 2088cd2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion data/json/vehicles/carts.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
{
"id": "wheelchair",
"type": "vehicle",
"name": "Foldable wheelchair",
"name": "Wheelchair",
"blueprint": [ "#" ],
"parts": [
{ "x": 0, "y": 0, "part": "folding_frame" },
Expand Down
27 changes: 15 additions & 12 deletions src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,18 +912,17 @@ bool vehicle::fold_up()
add_msg( _( "You let go of %s as you fold it." ), name );
}

std::string itype_id = "folding_bicycle";
std::string itype_id = "generic_folded_vehicle";
for( const auto &elem : tags ) {
if( elem.compare( 0, 12, "convertible:" ) == 0 ) {
itype_id = elem.substr( 12 );
break;
}
}

// create a folding [non]bicycle item
detached_ptr<item> bicycle = item::spawn( can_be_folded ? "generic_folded_vehicle" :
"folding_bicycle",
calendar::turn );
// Create the item
detached_ptr<item> folding_veh_item = item::spawn( can_be_folded ? "generic_folded_vehicle" :
itype_id, calendar::turn );

// Drop stuff in containers on ground
for( const vpart_reference &vp : get_any_parts( "CARGO" ) ) {
Expand All @@ -944,21 +943,25 @@ bool vehicle::fold_up()
std::ostringstream veh_data;
JsonOut json( veh_data );
json.write( parts );
bicycle->set_var( "folding_bicycle_parts", veh_data.str() );
folding_veh_item->set_var( "folding_bicycle_parts", veh_data.str() );
} catch( const JsonError &e ) {
debugmsg( "Error storing vehicle: %s", e.c_str() );
}

// evalautes to true on foldable items (folding_bicycle, skateboard)
// and false on vehicles with folding flags (wheelchair, unicycle)
if( can_be_folded ) {
bicycle->set_var( "weight", to_milligram( total_mass() ) );
bicycle->set_var( "volume", total_folded_volume() / units::legacy_volume_factor );
bicycle->set_var( "name", string_format( _( "folded %s" ), name ) );
bicycle->set_var( "vehicle_name", name );
folding_veh_item->set_var( "weight", to_milligram( total_mass() ) );
folding_veh_item->set_var( "volume", total_folded_volume() / units::legacy_volume_factor );
// remove "folded" from name to allow for more flexibility with folded vehicle names. also lowers first character
folding_veh_item->set_var( "name", string_format( _( "%s" ), ( name.empty() ? name : std::string( 1,
std::tolower( name[0] ) ) + name.substr( 1 ) ) ) );
folding_veh_item->set_var( "vehicle_name", name );
// TODO: a better description?
bicycle->set_var( "description", string_format( _( "A folded %s." ), name ) );
folding_veh_item->set_var( "description", string_format( _( "A folded %s." ), name ) );
}

g->m.add_item_or_charges( global_part_pos3( 0 ), std::move( bicycle ) );
g->m.add_item_or_charges( global_part_pos3( 0 ), std::move( folding_veh_item ) );
g->m.destroy_vehicle( this );

// TODO: take longer to fold bigger vehicles
Expand Down

0 comments on commit 2088cd2

Please sign in to comment.