From e109ea8de12f7e2513e8f8796932d9dde710ef2a Mon Sep 17 00:00:00 2001 From: natsirt721 Date: Sat, 27 Apr 2024 21:57:35 -0400 Subject: [PATCH 1/3] Add weight on wheels method --- src/vehicle.cpp | 20 +++++++++++++++++++- src/vehicle.h | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index cf473f34f219c..557289a193b92 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3401,6 +3401,24 @@ units::mass vehicle::total_mass() const return mass_cache; } +units::mass vehicle::weight_on_wheels() const +{ + const units::mass vehicle_mass = total_mass(); + units::mass animal_mass = 0_gram; + for( const int e : engines ) { + const vehicle_part &vp = parts[e]; + if( vp.info().fuel_type == fuel_type_animal ) + { + monster *mon = get_monster( e ); + if( mon != nullptr && mon->has_effect( effect_harnessed )) + { + animal_mass += mon->get_weight(); + } + } + } + return vehicle_mass - animal_mass; +} + const point &vehicle::rotated_center_of_mass() const { // TODO: Bring back caching of this point @@ -4493,7 +4511,7 @@ float vehicle::k_traction( float wheel_traction_area ) const if( fraction_without_traction == 0 ) { return 1.0f; } - const float mass_penalty = fraction_without_traction * to_kilogram( total_mass() ); + const float mass_penalty = fraction_without_traction * to_kilogram( weight_on_wheels() ); float traction = std::min( 1.0f, wheel_traction_area / mass_penalty ); add_msg_debug( debugmode::DF_VEHICLE, "%s has traction %.2f", name, traction ); diff --git a/src/vehicle.h b/src/vehicle.h index 39947555a3be0..ca6ef79d6c568 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -1518,6 +1518,9 @@ class vehicle // get the total mass of vehicle, including cargo and passengers units::mass total_mass() const; + // Get the total mass of the vehicle minus the weight of any creatures that are + // powering it; ie, the mass of the vehicle that the wheels are supporting + units::mass weight_on_wheels() const; // Gets the center of mass calculated for precalc[0] coordinates const point &rotated_center_of_mass() const; From f1dc0305f48d455596c0db631f0bca628c580db1 Mon Sep 17 00:00:00 2001 From: natsirt721 Date: Sat, 4 May 2024 13:14:18 -0400 Subject: [PATCH 2/3] Update src/vehicle.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/vehicle.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 557289a193b92..7a23730473485 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3410,8 +3410,7 @@ units::mass vehicle::weight_on_wheels() const if( vp.info().fuel_type == fuel_type_animal ) { monster *mon = get_monster( e ); - if( mon != nullptr && mon->has_effect( effect_harnessed )) - { + if( mon != nullptr && mon->has_effect( effect_harnessed ) ) { animal_mass += mon->get_weight(); } } From 12c9881ad88a2b3ffd0ad248b926cbf5f9850fd6 Mon Sep 17 00:00:00 2001 From: natsirt721 Date: Sat, 4 May 2024 13:14:23 -0400 Subject: [PATCH 3/3] Update src/vehicle.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/vehicle.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 7a23730473485..5653b493f494e 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3407,8 +3407,7 @@ units::mass vehicle::weight_on_wheels() const units::mass animal_mass = 0_gram; for( const int e : engines ) { const vehicle_part &vp = parts[e]; - if( vp.info().fuel_type == fuel_type_animal ) - { + if( vp.info().fuel_type == fuel_type_animal ) { monster *mon = get_monster( e ); if( mon != nullptr && mon->has_effect( effect_harnessed ) ) { animal_mass += mon->get_weight();