**F2: damage calculation change, a FIX v5**

The latest version of my FIX has been thoroughly tested by NovaRain (one of this forum's most enthusiastic mod testers). It still follows the original ideas I had for this FIX, but now optimized and as efficient as possible.

Notes below:

My understanding of the game engine; as it applies to this change, is built on other great modders work:

--- ravachol, first to expose the damage calculation in the exe

--- Kanhef, Haenlomal, and Timeslip, exposing even more of the inner workings of the exe

--- Cubik2k, leading the way in discussions and attempting to change the damage calculation

--- all other contributers to threads that have discussed the problem and ways it could be solved in this forum

What I understand of the damage calculation in the exe:

(assumptions are based on knowing if they were anything else then the calculation would fail badly)

--- I don't know what the DR modifier value is if the attacking critter is not using a weapon or if the weapon does not use ammo, assumed to be 0 in this case

- it checks if the new sum is greater than or equal to 0, if not it sets this new value to 0

- if greater than or equal to 0, it then checks if the new sum is less than or equal to 100, if not it sets this new value to 100

- the new value is then stored for later use

--- armorDR+ammoDRM - at this point the value is between 0 and 100 inclusive

- it then multiplies the Critical Multiplier (CM) by the attacking critter's ammo damage multiplier (X)

--- CM is by default 2 or if the hit was determined to be a critical hit (happens somewhere before this) is set to a value from the critical hit table (I assume)

--- X is either 1, 2, or 3 based on known ammo types

--- I don't know what the X value is if the attacking critter is not using a weapon or if the weapon does not use ammo, assumed to be 1 in this case

- it then multiplies the attacking critter's ammo damage divisor (Y) by a value (I wish I knew what - ravachol mentioned the value was 1, but I have not confirmed this is always the case)

--- mystery value (MV)???

--- Y is either 1 or 2 based on known ammo types

--- I don't know what the Y value is if the attacking critter is not using a weapon or if the weapon does not use ammo, assumed to be 1 in this case

- it then gets the number of hits the target critter took

--- I assume if multiple targets were hit from a burst weapon that it is tracked elsewhere and once one target is handled, the next is sent through

- it then clears a counter thats tracks the number of hits processed

- it then stores the X*CM value for later

- it then checks if the number of hits is less than or equal to 0, if not it skips all else

--- I assume it then returns to see if there was another target hit or initiates the next critters/players turn

- if the number of hits is greater than 0, it then gets the range bonus (RB)

--- I assume RB to be default 0 unless the critter/player has the Bonus Ranged Damage perk

- it then adds RB to the raw random damage value (RD)

--- RD is dependant on the damage min.-max. of the attacking critter's weapon or whatever an unarmed critter is capable of

- it then multiplies this new value (ND) by X*CM

- it then checks if MV*Y is 0, if it is then it skips ahead

--- this leads me to believe that either MV or Y may be allowed to be 0 when called in

--- I suspect MV is what may be allowed to be 0 and if so then maybe it's associated to a weapon perk???

- it MV*Y is greater than 0, it then divides ND by MV*Y

- it then divides the new ND value by 2

--- this seems to be done because for whatever reason CM is by default 2 and always multiplied in thus to negate an increase in damage when there was no critical hit, divide by 2

--- when CM is not 2, this should also mean values in the critical hit table should always be even, as odd numbers would produce a decimal which would be dropped, I have not confirmed this

- it then multiples the new ND value by the combat difficulty setting value (CD)

--- CD appears to be either 72, 100, or 112

--- given the way the CD value is used, I assume if the player chose a setting of Easy then CD=112 and if Hard then CD=72, this is counter intuitive but it would not work correctly the other way around

- it then divides the new ND value by 100

--- this is meant to cause CD to be used as a percentage

--- unfortunately, again there is no rounding, any decimal value (remainder) is dropped after division

- it then subtracts the armor's damage threshold (armorDT) from the new ND value

- it checks if the new ND value is less than or equal to 0, if it is then it skips ahead to increment the counter

--- I assume it counts this as a hit with no damage, given the counter is increased but nothing is added to damage taken by the target

- if the ND value is greater than 0, it then holds on to this value, and separately multiplies this value by armorDR+ammoDRM

--- ND1 and ND2=ND1*armorDR+ammoDRM

- it then divides ND2 by 100

--- this is meant to cause armorDR+ammoDRM to be used as a percentage of damage resisted

--- unfortunately, again there is no rounding, any decimal value (remainder) is dropped after division

- it then subtracts ND2 from ND1

--- ND=ND1-ND2

- it then checks if ND the new ND value is less than or equal to 0, if it is then it skips ahead

--- I assume it counts this as a hit with no damage, given the counter is increased but nothing is added to damage taken by the target

- if the ND value is greater than 0, it then adds that value to the total damage the target will take

- it then increments the counter

--- this is where it skips ahead to if at the checks mentioned previously damage was 0 or less

- it then compares the counter value to the number of hits the target critter was going to take, if the counter value is less than the number of hits it loops back and starts again

- if the counter is equal to the number of hits then the damage calculation for that specific target critter is complete

Summarized without counter:

ND = net damage value

RD = random damage value produced from weapons hit damage range

RB = ranged bonus (RB=0 unless the player has Bonus Ranged Damage perk)

CM = critical hit damage multiplier (if no critical hit then CM=2, otherwise assigned value from critical hit table)

armorDR = armor damage resistance value

armorDT = armor damage threshold value

ammoX = ammo dividend

ammoY = ammo divisor

ammoDRM = ammo resistance modifier (only value allowed to be negative or positive in the equation)

CD = combat difficulty multiplier

MV = mystery value

armorDR+ammoDRM

if armorDR+ammoDRM >= 0 then skip next step

armorDR+ammoDRM=0

if armorDR+ammoDRM <= 100 then skip next step

armorDR+ammoDRM=100

X*CM

MV*Y

ND=RD+RB

ND=ND*(X*CM)

if MV*Y <= 0 then skip next step

ND=ND/(MV*Y)

ND=ND/2

ND=ND*CD

ND=ND/100

ND=ND-armorDT

if ND <=0 then skip for no damage, repeat loop or exit

N1=ND

N2=ND*armorDR+ammoDRM

N2=N2/100

ND=N1-N2

if ND <=0 then skip for no damage, repeat loop or exit

TD=TD+ND

1- Division is not using decimals or rounding numbers

2- The critical multiplier is applied too early in my opinion; how does one score a critical hit if it's unknown whether the hit got through the target's armor damage threshold or got past the target's armor damage resistance yet?

3- The ammo multiplier is applied incorrectly in my opinion; first, multiplying the damage value directly implies that the ammo itself somehow increases the min.-max. damage potential of the weapon (I disagree with this) and second, how is damage multiplied if it's unknown whether the hit got through the target's armor damage threshold or got past the target's armor damage resistance yet?

4- The ammo divisor is applied incorrectly in my opinion; dividing the damage by the ammo divisor only reduces the damage, why would anything about ammo be designed to reduce damage?

5- The difficulty setting is applied too early in my opinion; again, how do you apply something that is to either make the damage more or less if it's unknown whether you got by the target's armor yet?

Here's how I approached each of the flaws:

1- I have removed division; instead I applied division by using subtraction in a loop, tracking the number of times through the loop (the quotient) and the remainder, I use the remainder to determine if the quotient should be rounded up (quotient+1)

2- The critical multiplier (CM) is only applied after it is determined that the hit got through the target's armor

--- how else can a hit be considered critical unless it got past armor to hurt a supposedly sensitive spot on the target

3- The ammo multiplier (X) to me seemed out of place, so I compared all the ammo in the game

--- it seemed that JHP ammo was the one (for the most part) which had an X value greater than 1

--- so knowing JHP, was not designed to penetrate armor but rather when it did to fragment and cause more damage, I chose to use X to reduce the target's armor damage resistance

4- The ammo divisor (Y) to me seemed again out of place, so again I compared all the ammo in the game

--- it semed that AP ammo was the one (for the most part) which had a Y value greater than 1

--- so knowing AP, was designed to penetrate armor but not fragment, I chose to use Y to reduce the target's armor damage threshold

5- The combat difficulty setting (CD) felt wrong to apply like CM, if Easy or Hard were selected

--- so I looked at treating it as a decrease or increase to the target's armor damage resistence value, -20 for Easy and +20 for Hard

--- I tested a similiar decrease or increase to the target's armor damage threshold, and it had no meaningful affect

Some consequences and realizations to my approach:

1- Some ammo which has X greater than 1 and Y greater than 1, gets both advantages (currently only 2mm EC and 4.7mm caseless)

2- Some of the ammo does not follow the expected X and Y values for it's type (ex. HN AP needler cartridge has X=2 and Y=1, Rocket AP has X=1 and Y=1)

--- I consider this a bug in the ammo

3- After seeing the output of my rough calculation tool, I've come to the following conclusions:

--- the 9mm ammo is bugged, it was not intended to be AP ammo (X=1 and Y=2), it should have been JHP ammo (X=2 and Y=1)

--- the HN AP needler cartridge ammo is bugged, it was not intended to be JHP ammo (X=2 and Y=1), it should have been AP ammo (X=1 and Y=2)

--- the Cell ammo (both kinds) is bugged, it does nothing to modify the target's armor values, it should have been like JHP ammo in values (X=2 and Y=1)

--- other ammo that might be considered bugged following the same case as Cell ammo are: .45 Caliber, 9mm ball, 12 gauge shotgun shells, HN Needler cartridge

4- All weapons that use an ammo with X and Y values of 1 and an ammoDRM of 0 have no advantage whatsoever against the target's armor damage threshold and damage resistance (in the original calculation and mine)

--- this is why Laser weapons don't do much damage, its not the weapon, it's the ammo and the fact that most armor in the game have high laser damage resistance

5- I may be close to what the original devs had intended

--- ammo was always meant to affect how the target's armor reacted to a hit, not how it might increase the min.-max. of a weapon's damage potential

6- Ammo values are the biggest factor in whether a weapon is good or not, second is the weapon's min.-max.

7- Ammo, weapons, and armor values need tweaking; to my previous point, ammo more so than anything else

HTML/Javascript rough calculation tool --- https://www.dropbox.com/s/bcvsjftyficztus/newCalculator.html?dl=1

The rough calculation tool should be straight forward; you pick the ammo type, combat difficulty setting, and/or to have what I think the ammo value could be turned on or off

The min.-max. is set to what is possible for the weapons that use that ammo

(ex. if you pick .223 FMJ, use the weapon reference link and you'll see the .223 pistol has a min.=20 and a max.=30, all values for 20-30 would apply to that weapon)

Choosing "None" for ammo type is the same as unarmed or a melee weapon that is not powered

My damage calculation:

(the following is based on what I've built in HTML/Javascript)

assertions:

1- armor cannot have a negative damage threshold

2- armor cannot have a negative damage resistance

3- ammo cannot add damage resistance

4- in the exe a setting of Easy has CD greater than 100, and Hard less than 100

if armDT is less than 0 then armDT is set to 0

if amY is less than or equal to 0 then amY is set to 1

armDT is divided by amY

ND=RD-armDT

if armDR is less than 0 then armDR is set to 0

if amDRM is greater than 0 then amDRM=0-armDRM

if CD is greater than 100 then CD is set to -20

if CD is less than 100 then CD is set to 20

armDR=armDR+amDRM+CD

if amX is less than or equal to 0 then amX is set to 1

armDR is divided by amX

if armDR is greater than 0 then temp=(ND*armDR)/100, ND=ND-temp

if armDR is less than or equal to 0 then temp=(ND*small bonus percent)/100, ND=ND+temp

if ND is less than 0 then ND=0

(assembly version) if multiple hits it loops back through for each, just as the original did

Assembly code version of calculator to be included in sfall (simplified version) ---

just rename the file to AmmoMod.cpp, overwrite existing file in sfall and compile

(now included in sfall, see DamageMod.cpp for the new code)

Here is a link to the script plus ini JimTheDinosaur initially provided and that NovaRain tweaked, which allows you to set your own ammoX, ammoY, ammoDRM, and acM to be used with any damage calculation (original, my mod, or anyone elses) --- Glovz_Fix2.rar (initial values are set to what I think works best with my fix turned on)

Much appreciated Jim and NovaRain!

EDIT:

The new version is still DamageFormula=1 in the ini file for sfall, but now DamageFormula=2 is the new version plus a small tweak.

I changed the way the critical multiplier is applied in the second version to Critical Damage = Net Damage + (Net Damage * 25% * Critical Multiplier)

I always thought the critical multiplier was a little heavy handed, so this change reduces it bit. Makes things more interesting.

#### Attachments

Last edited by a moderator: