Author Topic: [Suggestion] Change the formula for calculating resistances from things.  (Read 1619 times)

Offline Ronios

  • Sergeant
  • **
  • Posts: 25
    • View Profile
Hello everyone!

Many of you have seen things like "webwear" that give our agents extra resistance against any type of damage.
"This ultra-light shirt made of Giant Spider silk can be worn under most armors. It works when kept in the backpack. Reduces the effects of Kinetic damage taken by 1/5, to a maximum Resistance of 50%. Concealable"
It can be seen from the description that the shirt reduces incoming damage by 1/5, but the total resistance (including armor) cannot exceed 50%.

If we pay a little attention to this, we will notice that in fact the shirt does not do this, because the current formula, used in xPiratez, is unnecessarily complicated.
Let's take a look at this formula:
Code: [Select]
          # CURRENT RES = CURRENT RES - ((1 - ITEM RES) * (CURRENT RES - ITEM ZERO POINT))

            # Only set resistance if better than current tag
            if and neq temp 0 lt itemResistMinimum temp;
              set currentResistance temp;
              set oneMinusResistance 100;
              sub temp itemResistMinimum;
              sub oneMinusResistance itemResistCoeff;
              muldiv temp oneMinusResistance 100;
              sub currentResistance temp;
              itemOwner.setTag Tag.UNIT_RESIST_TYPE_1 currentResistance;
            end;

Where:
CURRENT RES - currentResistance - the resistance of our armor.
ITEM RES - itemResistCoeff - item resistance (1/5 is 80% = 0.8 ).
ITEM ZERO POINT - itemResistMinimum - item resistance limit (50% = 0.5).
If we calculate our webwear for normal resistance (100% = 1) using this formula, we get the following:

CURRENT RES = 1 - (1 - 0.8 ) * (1 - 0.5) = 1 - 0.2 * 0.5 = 0.9 (90%).

The main question is, how did our 20% resistance turn into 10% under absolutely normal conditions and, most importantly, why? Of course, the point is "(CURRENT RES - ITEM ZERO POINT)", where we set as zero resistance value the minimum resistance of the thing, but not full immunity to damage(standard 0% in game).

I propose to change the formula so that if it is written 1/5, then exactly 1/5 of the current resistance is always given. These are 20% at 100%, 12% at 60%, etc. *. The new formula will look like this (much simpler and clearer):
CURRENT RES = ITEM RES * CURRENT RES = 1 * 0.8 = 0.8 (80%).
And for armor with 70% resistance - 0.7 * 0.8 = 0.56 (56%).

After that, we just do a check so that we do not get out of our 50%.
Code: [Select]
            # Only set resistance if better than current tag (Relative resistance)
            if and neq temp 0 lt itemResistMinimum temp;
              set currentResistance temp;
              muldiv currentResistance itemResistCoeff 100;
              if lt currentResistance itemResistMinimum;
                set currentResistance itemResistMinimum;
              end;
              itemOwner.setTag Tag.UNIT_RESIST_TYPE_1 currentResistance;
            end;

Need the opinion of other players whether such a change needs to be made. However, I personally think that it is much better when everything works exactly as it looks, as convenient and simple as possible for the players. Moreover, when Solarius Scorch adds new things of this kind, he will not have to puzzle over why the thing is not working correctly and how to do it right.

Good luck to all and Happy New Year! ;)

Offline Mrvex

  • Colonel
  • ****
  • Posts: 175
    • View Profile
Re: [Suggestion] Change the formula for calculating resistances from things.
« Reply #1 on: January 08, 2021, 04:49:14 pm »
I was kinda expecting this one, rare and obscure item to not work as intended. Given its the only item in the entire game capable of this.
Since this is pretty much a bugfix, i dont see why this couldnt be implemented.

And that aside, these items should be expanded to give more options since resistance boosting items are quite interesting on their own, just their weight needs to be increased so they arent a no-brainer items. Silkwear ofc is and will be light but if things like keramic underplates (against plasma/lasers) or blast padding, then yeah, that would be heavier.

Offline Ronios

  • Sergeant
  • **
  • Posts: 25
    • View Profile
Re: [Suggestion] Change the formula for calculating resistances from things.
« Reply #2 on: January 09, 2021, 07:50:02 pm »
I have thoroughly studied how scripts work in OXCE and in particular in this mechanics. Experienced all imaginable and unimaginable options, such as negative resistance. I also tested the possibilities of combining the same type of resistance from different things(of the same type and not). I checked it, of course, through the logs and just by shooting at soldiers in the game with different weapons (including those with static damage).

Everything works correctly and bonuses are applied correctly from one thing and from a sequence of different things (several of the same do not match).

By the way, heavy plates with resistance from plasma and laser would be good for a scout with light weapons, but with heavy weapons you would have to fight with standard protection.

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • ***
  • Posts: 11408
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: [Suggestion] Change the formula for calculating resistances from things.
« Reply #3 on: January 09, 2021, 08:20:20 pm »
I was kinda expecting this one, rare and obscure item to not work as intended. Given its the only item in the entire game capable of this.
Since this is pretty much a bugfix, i dont see why this couldnt be implemented.

This script has been imported from Piratez, where it's been for years now and was thoroughly tested  on many, many items. IT IS NOT BUGGED. IT WORKS EXACTLY AS DESIGNED.

Whether this should be changed or not is an open question.