From 2088cd22aaa75e2e57e1545d378b3bda29c88f39 Mon Sep 17 00:00:00 2001 From: shmakota <47482311+shmakota@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:23:54 -0600 Subject: [PATCH] fix: folding vehicles fold up into proper item (#5845) * unhardcode folding vehicle. remove "folded" from naming scheme, and lower first letter. * remove "Foldable" from wheelchair name * condense if else statement back down --- data/json/vehicles/carts.json | 2 +- src/vehicle_use.cpp | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/data/json/vehicles/carts.json b/data/json/vehicles/carts.json index 55ff473e455d..4df91d6fdf67 100644 --- a/data/json/vehicles/carts.json +++ b/data/json/vehicles/carts.json @@ -296,7 +296,7 @@ { "id": "wheelchair", "type": "vehicle", - "name": "Foldable wheelchair", + "name": "Wheelchair", "blueprint": [ "#" ], "parts": [ { "x": 0, "y": 0, "part": "folding_frame" }, diff --git a/src/vehicle_use.cpp b/src/vehicle_use.cpp index 150c5e28af83..922e9180c103 100644 --- a/src/vehicle_use.cpp +++ b/src/vehicle_use.cpp @@ -912,7 +912,7 @@ 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 ); @@ -920,10 +920,9 @@ bool vehicle::fold_up() } } - // create a folding [non]bicycle item - detached_ptr bicycle = item::spawn( can_be_folded ? "generic_folded_vehicle" : - "folding_bicycle", - calendar::turn ); + // Create the item + detached_ptr 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" ) ) { @@ -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