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: folding vehicles fold up into proper item #5845

Merged
merged 3 commits into from
Dec 28, 2024
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
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
Loading