Skip to content

Commit

Permalink
Merge pull request #35606 from BevapDin/hfu
Browse files Browse the repository at this point in the history
Fix weight of folded vehicles / items containing animals
  • Loading branch information
ZhilkinSerg authored Nov 22, 2019
2 parents 198a526 + f17cea4 commit da9ae7c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
22 changes: 2 additions & 20 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9244,26 +9244,8 @@ int item::contain_monster( const tripoint &target )
set_var( "contained_name", f.type->nname() );
set_var( "name", string_format( _( "%s holding %s" ), type->nname( 1 ),
f.type->nname() ) );
m_size mon_size = f.get_size();
int new_weight = 0;
switch( mon_size ) {
case MS_TINY:
new_weight = 1000;
break;
case MS_SMALL:
new_weight = 40750;
break;
case MS_MEDIUM:
new_weight = 81500;
break;
case MS_LARGE:
new_weight = 120000;
break;
case MS_HUGE:
new_weight = 200000;
break;
}
set_var( "weight", new_weight );
// Need to add the weight of the empty container because item::weight uses the "weight" variable directly.
set_var( "weight", to_milligram( type->weight + f.get_weight() ) );
g->remove_zombie( f );
return 0;
}
Expand Down
6 changes: 6 additions & 0 deletions src/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ inline constexpr quantity<value_type, mass_in_milligram_tag> from_kilogram(
return from_gram( v * 1000 );
}

template<typename value_type>
inline constexpr value_type to_milligram( const quantity<value_type, mass_in_milligram_tag> &v )
{
return v.value();
}

template<typename value_type>
inline constexpr value_type to_gram( const quantity<value_type, mass_in_milligram_tag> &v )
{
Expand Down
5 changes: 0 additions & 5 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6327,11 +6327,6 @@ void vehicle::calc_mass_center( bool use_precalc ) const
m_part += p != nullptr ? p->get_weight() : 0_gram;
}

if( vp.part().has_flag( vehicle_part::animal_flag ) ) {
std::int64_t animal_mass = vp.part().base.get_var( "weight", 0 );
m_part += units::from_gram( animal_mass );
}

if( use_precalc ) {
xf += vp.part().precalc[0].x * m_part;
yf += vp.part().precalc[0].y * m_part;
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ bool vehicle::fold_up()
}

if( can_be_folded ) {
bicycle.set_var( "weight", to_gram( total_mass() ) );
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 );
Expand Down

0 comments on commit da9ae7c

Please sign in to comment.