Skip to content

Commit

Permalink
Set item variable "weight" to milligrams, because that is used in `it…
Browse files Browse the repository at this point in the history
…em::weight` when the value of that variable is loaded.
  • Loading branch information
BevapDin committed Nov 20, 2019
1 parent d536146 commit 7b946fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9263,7 +9263,8 @@ int item::contain_monster( const tripoint &target )
new_weight = 200000;
break;
}
set_var( "weight", new_weight );
// Above is old code. It uses gram as units for monster weight.
set_var( "weight", to_milligram( units::from_gram( new_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
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 7b946fe

Please sign in to comment.