Barotrauma icon indicating copy to clipboard operation
Barotrauma copied to clipboard

[Modding] Condition is not a % of item Health, but Health itself

Open ubertpendragon opened this issue 3 years ago • 10 comments

Disclaimers

  • [X] I have searched the issue tracker to check if the issue has already been reported.
  • [ ] My issue happened while using mods.

What happened?

Lets say I want to override an item. For example, I want to change reactor health:

<Item name="" identifier="reactor1" tags="reactor" type="Reactor" scale="0.5" linkable="true" category="Machine" damagedbyexplosions="true" damagedbyprojectiles="true" health="500" >

The problem is, reactors in vanilla have 100 condition by default, but that condition is not a % of health, it's actually health. This means instead of Dugong reactor spawning at 100% condition, the item spawns at 100% HEALTH aka 20% CONDITION

image

It also implies modifying values on all things regarding condition to adjust for health value, like deterioration that would have to be increased by x5.

Condition probably should reflect a % of health rather than health itself. Condition_Out already reflects a % of health image

ubertpendragon avatar Sep 08 '22 19:09 ubertpendragon

I think you've slightly misunderstood how the system works. None of these values are percentages: the Dugong reactor doesn't spawn at full condition because it's condition is currently 100, and you're modifying it's maximum condition to be 500.

You might want to use the property HealthMultiplier instead, which takes this into account and sets the condition % to match what it was before the maximum condition was increased.

There is also a property called ConditionPercentage, which might be what you're looking for.

It also implies modifying values on all things regarding condition to adjust for health value, like deterioration that would have to be increased by x5.

I'd say this is intentional: the point of increasing the item's maximum condition (= health) is to make it more durable. If we increased the deterioration (and other things that damage the item) to compensate, the increased condition would make no difference.

Regalis11 avatar Sep 09 '22 05:09 Regalis11

You might want to use the property HealthMultiplier instead, which takes this into account and sets the condition % to match what it was before the maximum condition was increased.

Unfortunately it still spawns at 20% condition

<Item name="" identifier="reactor1" tags="reactor" type="Reactor" scale="0.5" linkable="true" category="Machine" damagedbyexplosions="true" damagedbyprojectiles="true" healthmultiplier="5" >

It's a niche issue only pertaining to preplaced items and Override but it's been bugging me

ubertpendragon avatar Sep 09 '22 11:09 ubertpendragon

Ahh, yeah, you're right. Even though HealthMultiplier does take this into account, Condition is still serialized in the submarine files and overrides whatever value was set by HealthMultiplier. I think we might need to consider serializing ConditionPercentage instead of Condition.

Regalis11 avatar Sep 09 '22 11:09 Regalis11

Fixed in https://github.com/Regalis11/Barotrauma-development/commit/fd3f355a2e4173f3d3b6a1c33ba1fe2a7bf38251

Regalis11 avatar Sep 21 '22 06:09 Regalis11

Tested against dev commit https://github.com/Regalis11/Barotrauma-development/commit/749914f4707c8b61fc62ade029de1ff75aee3ac9.

Health multiplier doesn't work for item overrides (IE. reactor's) still leaving the item at the original condition for existing submarine items. It appears upgrading submarines works fine which uses health multipliers though.

NilanthAnimosus avatar Sep 28 '22 10:09 NilanthAnimosus

Fixed in https://github.com/Regalis11/Barotrauma-development/commit/ae48d5f5c588fee27866be67462644a599702c94

Regalis11 avatar Sep 28 '22 13:09 Regalis11

Tested against dev commit https://github.com/Regalis11/Barotrauma-development/commit/373b429eaed92741b3dd4dd58397917e06ad8647, no issues found, closing.

NilanthAnimosus avatar Sep 28 '22 16:09 NilanthAnimosus

Reopening: the fix caused item conditions to not load properly https://github.com/Regalis11/Barotrauma/issues/9956

Regalis11 avatar Sep 29 '22 07:09 Regalis11

Tested against release commit https://github.com/Regalis11/Barotrauma-development/commit/00f795275d20e02a91cf05792d31934e9a358ffe

Used a mod to override the reactor to 10x the health Via HealthMultiplier="10". Starting a new campaign I find it starts at 10% condition.

However when undocking this changes to 100% condition (and I double checked it was not repaired by an AI). using fuel rods and an oxygen mask I lowered some conditions and re-docked, nothing repaired so that issue seems fixed.

lowered reactor condition to around 50% with frag grenades, and it healed back up after undocking again to 100% (?)

NilanthAnimosus avatar Sep 30 '22 08:09 NilanthAnimosus

Another take at this, this time implemented in a bit more robust way https://github.com/Regalis11/Barotrauma-development/commit/abee1f83177eabb3ef19b13dacd8b85641ce3354

Regalis11 avatar Oct 05 '22 08:10 Regalis11

Tested against healthmultiplier-fix commit https://github.com/Regalis11/Barotrauma-development/commit/abee1f83177eabb3ef19b13dacd8b85641ce3354

When modding healthmultiplier it appears on new campaigns/missions and such existing items (saved into the submarine, such as a reactor) start off damaged. Nothing resets/changes health incorrectly between level transitions though (of any kind of item).

I think this may be because conditionpercentage has not been serialized in the vanilla submarines before starting missions/campaigns with them. When I create a campaign without a mod changing a healthmultiplier active, it works correctly when said mod is added on an existing campaign.

NilanthAnimosus avatar Oct 17 '22 12:10 NilanthAnimosus

I think this may be because conditionpercentage has not been serialized in the vanilla submarines before starting missions/campaigns with them

That's exactly what's causing it: it only works correctly after the sub/campaign has been saved using ConditionPercentage serialization instead of Condition. I think that's an acceptable downside though, as it'll only cause problems (or rather, work the same way it does now) during the transition period to the new serialization logic.

Regalis11 avatar Oct 17 '22 12:10 Regalis11

This does have a potential problem if your using healthmultipliers with old submarines though in say, Multiplayer mission mode (IE. player vs player, not campaign). It may trickle down and be easily solved with an update to vanilla submarines. On any submarine saved before the version this would release on for assumedly items not spawned in autofill, it does mean their effectively guaranteed to have problems with those sorts of mods (Unless there is a workaround?).

I am also not sure to how many add mods mid-campaign (Especially multiplayer with a pre-existing list). There is also the notion of what will happen to none-repairable items as I've not tried modifying the healthmultiplier of those. Could lead to old submarines with permanently smoking items as a result of a mod without the mod creator having a good work around I can think of for older submarines (Can they update current condition/health on version?).

I get newer submarines will not have this issue though, but I can see a few issue reports cropping up over time about it.

If the issues are fine I would at least recommend updating the vanilla submarines to have a serialized condition after merging, not sure if there is a way to make the fixes backwards compatible without more problems really.

NilanthAnimosus avatar Oct 17 '22 13:10 NilanthAnimosus

I think it's worth keeping in mind that's how it has always worked: the item would've appeared damaged if you modified the health with HealthMultiplier, yet afaik we haven't gotten a single report about that.

Anyway, I added a small improvement to the backwards compatibility now: if the item was in full condition relative to the prefab's default health, it'll stay in full condition when loading one of these outdated submarines.

Regalis11 avatar Oct 18 '22 15:10 Regalis11

Tested against dev commit https://github.com/Regalis11/Barotrauma-development/commit/179bd6800c8e6d1b02e01277e3792b5932221710, no issues found, closing.

NilanthAnimosus avatar Oct 21 '22 10:10 NilanthAnimosus