Skip to content

Commit

Permalink
fix: Handle "relative" and "proportional" with encumbrance (#5858)
Browse files Browse the repository at this point in the history
* Handle relative and proportional with encumbrance

* Handle proportional/relative with item encumbrance
  • Loading branch information
Coolthulhu authored Jan 6, 2025
1 parent 61cba34 commit dfe8ee3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
1 change: 0 additions & 1 deletion data/json/items/armor/ballistic_armor.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"price_postapoc": "15 USD",
"//": "Mono-material as it likely would need to be taken apart to repair, plus the material of the vest is less of a factor on resistances.",
"material": [ "soil" ],
"coverage": 85,
"encumbrance": 45,
"material_thickness": 6,
"extend": { "flags": [ "OVERSIZE", "FRAGILE" ] },
Expand Down
1 change: 0 additions & 1 deletion data/json/items/armor/torso_armor.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@
"description": "A cuirass made from large pieces of carved bone, laced together like lamellar armor. Tough but stiff, and a bit brittle.",
"material": [ "bone_heavy" ],
"color": "white",
"encumbrance": 12,
"warmth": 12,
"environmental_protection": 1,
"valid_mods": [ ],
Expand Down
30 changes: 30 additions & 0 deletions data/mods/TEST_DATA/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -785,5 +785,35 @@
"name": { "str": "damageable anti-bullet armor" },
"description": "This armor protects from bullets, but can be damaged to protect a bit less.",
"material_thickness": 10
},
{
"id": "test_override_armor_copyfrom_encumbrance",
"repairs_like": "survivor_suit",
"type": "ARMOR",
"category": "armor",
"name": { "str": "copyable armor with encumbrance" },
"description": "This armor has some encumbrance.",
"weight": "100 g",
"volume": "1 L",
"price": 1,
"price_postapoc": 1,
"symbol": "[",
"looks_like": "touring_suit",
"color": "dark_gray",
"material": [ "cotton" ],
"warmth": 0,
"material_thickness": 1,
"encumbrance": 10,
"coverage": 100,
"covers": [ "torso", "arm_l", "arm_r", "head", "leg_l", "leg_r" ]
},
{
"id": "test_override_armor_copyfrom_proportional_encumbrance",
"copy-from": "test_override_armor_copyfrom_encumbrance",
"type": "ARMOR",
"category": "armor",
"name": { "str": "proportionally encumbering armor" },
"description": "This armor has half the encumbrance of some other armor.",
"proportional": { "weight": 0.5, "encumbrance": 0.5, "price": 10, "warmth": 2 }
}
]
20 changes: 12 additions & 8 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,16 +2035,20 @@ void Item_factory::load( islot_armor &slot, const JsonObject &jo, const std::str
assign_coverage_from_json( jo, "covers", temp_cover_data, slot.sided );
slot.data[0].covers = temp_cover_data;
} else { // This item has copy-from and already has taken data from parent
if( jo.has_int( "encumbrance" ) ) {
slot.data[0].encumber = jo.get_int( "encumbrance" );
if( slot.data.size() > 1 && ( jo.has_int( "encumbrance" ) ||
jo.has_int( "max_encumbrance" ) ||
jo.has_int( "coverage" ) ) ) {
jo.throw_error( "Legacy armor format only supported for items with exactly 1 armor data entry. Use \"armor_portion_data\" instead." );
}
// DISGUSTING hack
int old_encumbrance = slot.data[0].encumber;
assign( jo, "encumbrance", slot.data[0].encumber, strict );
if( old_encumbrance != slot.data[0].encumber ) {
slot.data[0].max_encumber = slot.data[0].encumber;
}
if( jo.has_int( "max_encumbrance" ) ) {
slot.data[0].max_encumber = jo.get_int( "max_encumbrance" );
}
if( jo.has_int( "coverage" ) ) {
slot.data[0].coverage = jo.get_int( "coverage" );
}
assign( jo, "max_encumbrance", slot.data[0].max_encumber, strict );

assign( jo, "coverage", slot.data[0].coverage, strict );
body_part_set temp_cover_data;
assign_coverage_from_json( jo, "covers", temp_cover_data, slot.sided );
if( temp_cover_data.any() ) {
Expand Down

0 comments on commit dfe8ee3

Please sign in to comment.