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

Add weight_on_wheels method #73466

Merged
merged 3 commits into from
May 10, 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
18 changes: 17 additions & 1 deletion src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3401,6 +3401,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 @@ -4493,7 +4509,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 @@ -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;
Expand Down
Loading