Skip to content

Commit

Permalink
Add weight_on_wheels method (#73466)
Browse files Browse the repository at this point in the history
* Add weight on wheels method

* Update src/vehicle.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/vehicle.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
natsirt721 and github-actions[bot] authored May 10, 2024
1 parent 58914c1 commit 1bfc562
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3484,6 +3484,22 @@ 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
Expand Down Expand Up @@ -4576,7 +4592,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 );

Expand Down
3 changes: 3 additions & 0 deletions src/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,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;
Expand Down

0 comments on commit 1bfc562

Please sign in to comment.