From fbb59eb1c4d13adcd2c8d3fee0b764788fdb9aa0 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 8 Apr 2019 21:10:20 +0200 Subject: [PATCH] Inherit weight/volume of components not result --- src/item.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 4f1850d0fa4d6..75e613c47efdc 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -3251,14 +3251,16 @@ units::mass item::weight( bool include_contents ) const return 0_gram; } - units::mass ret = 0_gram; - if( is_craft() ) { - ret = units::from_gram( get_var( "weight", to_gram( find_type( making->result() )->weight ) ) ); - } else { - ret = units::from_gram( get_var( "weight", to_gram( type->weight ) ) ); + units::mass ret = 0_gram; + for( auto it : components ) { + ret += it.weight(); + } + return ret; } + units::mass ret = 0_gram; + ret = units::from_gram( get_var( "weight", to_gram( type->weight ) ) ); if( has_flag( "REDUCED_WEIGHT" ) ) { ret *= 0.75; @@ -3345,8 +3347,13 @@ units::volume item::base_volume() const if( is_corpse() ) { return corpse_volume( corpse ); } + if( is_craft() ) { - return find_type( making->result() )->volume; + units::volume ret = 0_ml; + for( auto it : components ) { + ret += it.base_volume(); + } + return ret; } if( count_by_charges() ) { @@ -3371,7 +3378,11 @@ units::volume item::volume( bool integral ) const } if( is_craft() ) { - return find_type( making->result() )->volume; + units::volume ret = 0_ml; + for( auto it : components ) { + ret += it.volume(); + } + return ret; } const int local_volume = get_var( "volume", -1 );