Skip to content

Commit 3a17324

Browse files
authored
feat(balance): Use rigid storage first when calculating non-rigid encumbrance (#9692)
* Use rigid storage first when calculating non-rigid encumbrance * Fixes for non-rigid storage
1 parent 9623a79 commit 3a17324

4 files changed

Lines changed: 40 additions & 40 deletions

File tree

src/character.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,11 +2902,6 @@ void Character::inv_set_stack_favorite( int position, bool favorite )
29022902
inv.set_stack_favorite( position, favorite );
29032903
}
29042904

2905-
units::volume Character::inv_volume() const
2906-
{
2907-
return inv.volume();
2908-
}
2909-
29102905
void Character::inv_unsort()
29112906
{
29122907
inv.unsort();

src/character.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,6 @@ class Character : public Creature, public location_visitable<Character>
12931293

12941294
detached_ptr<item> inv_remove_item( item * );
12951295

1296-
units::volume inv_volume() const;
1297-
12981296
void inv_unsort();
12991297

13001298
void inv_clear();

src/item.cpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4199,22 +4199,10 @@ void item::final_info( std::vector<iteminfo> &info, const iteminfo_query &parts_
41994199
}
42004200

42014201
if( parts->test( iteminfo_parts::BASE_RIGIDITY ) ) {
4202-
if( const islot_armor *armor = find_armor_data() ) {
4203-
if( !type->rigid ) {
4204-
info.emplace_back( "BASE",
4205-
_( "* This item is <info>not rigid</info>. Its"
4206-
" volume and encumbrance increase with contents." ) );
4207-
} else {
4208-
bool any_encumb_increase = std::ranges::any_of( armor->data,
4209-
[]( armor_portion_data data ) {
4210-
return data.encumber != data.max_encumber;
4211-
} );
4212-
if( any_encumb_increase ) {
4213-
info.emplace_back( "BASE",
4214-
_( "* This item is <info>not rigid</info>. Its"
4215-
" volume and encumbrance increase with contents." ) );
4216-
}
4217-
}
4202+
if( is_non_rigid() ) {
4203+
info.emplace_back( "BASE",
4204+
_( "* This item is <info>not rigid</info>. Its"
4205+
" volume and encumbrance increase with contents." ) );
42184206
}
42194207
}
42204208

@@ -6138,6 +6126,21 @@ bool item::can_shatter() const
61386126
return only_made_of( is_glass ) || has_flag( flag_SHATTERS );
61396127
}
61406128

6129+
bool item::is_non_rigid() const
6130+
{
6131+
if( const islot_armor *armor = find_armor_data() ) {
6132+
if( !type->rigid ) {
6133+
return true;
6134+
}
6135+
bool any_encumb_increase = std::ranges::any_of( armor->data,
6136+
[]( armor_portion_data data ) {
6137+
return data.encumber != data.max_encumber;
6138+
} );
6139+
return any_encumb_increase;
6140+
}
6141+
return false;
6142+
}
6143+
61416144
void item::unset_flags()
61426145
{
61436146
const bool affects_processing = item_tags.count( flag_RADIO_ACTIVATION ) ||
@@ -6741,24 +6744,29 @@ int item::get_encumber( const Character &who, const bodypart_id &bodypart ) cons
67416744

67426745
contents_volume += contents.item_size_modifier();
67436746

6744-
if( who.is_worn( *this ) ) {
6747+
if( who.is_worn( *this ) && this->is_non_rigid() ) {
67456748
const islot_armor *armor = find_armor_data();
67466749

67476750
if( armor != nullptr ) {
67486751
for( const armor_portion_data &entry : armor->data ) {
6749-
if( entry.covers.test( bodypart.id() ) ) {
6750-
if( entry.max_encumber != 0 ) {
6751-
units::volume char_storage( 0_ml );
6752-
6753-
for( const item * const &e : who.worn ) {
6754-
char_storage += e->get_storage();
6752+
if( entry.max_encumber != 0 && entry.covers.test( bodypart.id() ) ) {
6753+
units::volume rigid_storage( 0_ml );
6754+
units::volume non_rigid_storage( 0_ml );
6755+
const units::volume volume_carried = who.volume_carried();
6756+
6757+
for( const item * const &e : who.worn ) {
6758+
if( e->is_non_rigid() ) {
6759+
non_rigid_storage += e->get_storage();
6760+
} else {
6761+
rigid_storage += e->get_storage();
67556762
}
6763+
}
67566764

6757-
if( char_storage != 0_ml ) {
6758-
// Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
6759-
contents_volume += units::from_milliliter( static_cast<int64_t>( armor->storage.value() ) *
6760-
who.inv_volume().value() / char_storage.value() );
6761-
}
6765+
if( volume_carried > rigid_storage && non_rigid_storage > 0_ml ) {
6766+
// Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
6767+
contents_volume += units::from_milliliter( static_cast<int64_t>( armor->storage.value() ) *
6768+
( static_cast<int64_t>( volume_carried.value() ) - rigid_storage.value() ) /
6769+
non_rigid_storage.value() );
67626770
}
67636771
}
67646772
}
@@ -6783,11 +6791,7 @@ int item::get_encumber_when_containing(
67836791
if( entry.covers.test( bodypart.id() ) ) {
67846792
encumber = entry.encumber;
67856793
// Non-rigid items add additional encumbrance proportional to their volume
6786-
bool any_encumb_increase = std::ranges::any_of( armor->data,
6787-
[]( armor_portion_data data ) {
6788-
return data.encumber != data.max_encumber;
6789-
} );
6790-
if( !type->rigid || any_encumb_increase ) {
6794+
if( this->is_non_rigid() ) {
67916795
const int capacity = get_total_capacity().value();
67926796
if( entry.max_encumber == 0 ) {
67936797
encumber += contents_volume / 500_ml;

src/item.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,9 @@ class item : public location_visitable<item>, public game_object<item>
17281728
/**If item made out of glass, or has the SHATTERS flag?*/
17291729
bool can_shatter() const;
17301730

1731+
/** If the item is non-rigid: either has rigid = false or max_encumber higher than encumber */
1732+
bool is_non_rigid() const;
1733+
17311734
/**
17321735
* @name Item properties
17331736
*

0 commit comments

Comments
 (0)