Difference between revisions of "Talk:Damage"

From UFOpaedia
Jump to navigation Jump to search
(→‎Damage Doubling: (range rolled?))
Line 133: Line 133:
  
 
Thank you Zaimoni. And what about the rolled range and steps? Is is e.g. 0.00 - 2.00 x Average, or (zero) to (2 * Average) in integer steps, or ? That's probably a hard thing to deduce, it might need code inspection. [[User:Spike|Spike]] 11:54, 7 April 2008 (PDT)
 
Thank you Zaimoni. And what about the rolled range and steps? Is is e.g. 0.00 - 2.00 x Average, or (zero) to (2 * Average) in integer steps, or ? That's probably a hard thing to deduce, it might need code inspection. [[User:Spike|Spike]] 11:54, 7 April 2008 (PDT)
 +
 +
: I think I identified the code for this. Standard damage goes like this:
 +
.text:0040DF58 66 8B 0D E8 83 47 00    mov    cx, currentWeapon_damage
 +
.text:0040DF5F 66 D1 E1                shl    cx, 1
 +
.text:0040DF62 51                      push    ecx                            ; rndMax
 +
.text:0040DF63 E8 E8 F8 02 00          call    GetRandom_0_n
 +
.text:0040DF68 83 C4 04                add    esp, 4
 +
.text:0040DF6B 8B C8                  mov    ecx, eax
 +
: which means damage*2*rand()
 +
: For HE damage:
 +
.text:0040DF36 66 A1 E8 83 47 00      mov    ax, currentWeapon_damage
 +
.text:0040DF3C 50                      push    eax                            ; rndMax
 +
.text:0040DF3D E8 0E F9 02 00          call    GetRandom_0_n
 +
.text:0040DF42 66 8B C8                mov    cx, ax
 +
.text:0040DF45 83 C4 04                add    esp, 4
 +
.text:0040DF48 0F BF 05 E8 83 47 00    movsx  eax, currentWeapon_damage
 +
.text:0040DF4F 99                      cdq
 +
.text:0040DF50 2B C2                  sub    eax, edx
 +
.text:0040DF52 D1 F8                  sar    eax, 1
 +
.text:0040DF54 03 C8                  add    ecx, eax
 +
: which is damage*rand()+damage/2
 +
: rand() is base on a linear congruent generator:
 +
.text:0045FA65 A1 58 68 47 00          mov    eax, rand_internal_state
 +
.text:0045FA6A 69 C0 FD 43 03 00      imul    eax, 214013
 +
.text:0045FA70 05 C3 9E 26 00          add    eax, 2531011
 +
.text:0045FA75 A3 58 68 47 00          mov    rand_internal_state, eax
 +
.text:0045FA7A C1 F8 10                sar    eax, 10h
 +
.text:0045FA7D 25 FF 7F 00 00          and    eax, 7FFFh
 +
.text:0045FA82 C3                      retn
 +
: (For the curious, it is the [http://en.wikipedia.org/wiki/Linear_congruential_generator#LCGs_in_common_use Microsoft Visual/Quick C/C++ version])). HTH. [[User:Seb76|Seb76]] 13:06, 7 April 2008 (PDT)

Revision as of 20:06, 7 April 2008

I remember reading in a thread somewhere, that weapons do up to double damage at all times, not just on X-COM soldiers. This means that the rated in-game values are actually the averages. I think it was in Zombie's "Damage Modifiers" thread. Can anyone confirm or deny this, because the formula at the top of the page, with the 0.5 and 2 in it, is confusing to me?

In my understanding, it was simply like this:

A rifle, rated as 30 damage, will actually do anywhere from 0-60 damage. Then you multiply this by the damage modifiers and then subtract the armour...

--Danial 18:08, 23 Oct 2005 (PDT)


That's the impression I'm getting from what I've seen... that actually it's the average that's being shown in the game. So I'm with you. Want to ask Zombie? Or I can. --MikeTheRed 11:17, 24 Oct 2005 (PDT)


Exactly correct guys. All damage numbers listed by the game's UFOpaedia are averages. I believe I mentioned this fact in my 3rd or 4th post in the Damage Modifiers thread at the StrategyCore forums. For most weapons/ammo, the Minimum is 0 and the Maximum is Average * 2. The weapons/ammo in this category include Armor Piercing, Laser, Plasma, Stun Rod and the Small Launcher's Stun Bomb.

The types of ammo that don't quite follow that category are Incendiary and High Explosives. The HE Minimum is AVE/2, while the Maximum is AVE*3/2. However, if you average the min and the max, it is still what the game mentions. Overall, it's a smaller range of damage that can be inflicted, and that means the probability of the higher damages showing up is greater than an ammo with the same max.

Example 1:

HE ammo with 100 listed strength
Min = 50
Ave = 100
Max = 150
Probability of max showing up = 1/(150-50+1) = 0.990%

AP ammo with 75 listed strength
Min = 0
Ave = 75
Max = 150
Probability of max showing up = 1/(150-0+1) = 0.662%

Conclusion: if you have the choice between HE with 100 listed damage and a normal weapon with 75, choose the HE. However, if you have two types of ammo with the same average, things become different.

Example 2:

HE ammo with 100 listed strength
Min = 50
Ave = 100
Max = 150
Probability of max showing up = 1/(150-50+1) = 0.990%

AP ammo with 100 listed strength
Min = 0
Ave = 100
Max = 200
Probability of max showing up = 1/(200-0+1) = 0.498%

Unfortunately, we are comparing apples to oranges in this case since the max for the AP is much greater than HE. In reality, AP ammo will out-perform the HE according to this: 1 / (AP max - HE Max + 1), or 1 / (200-150+1) = 1.961%. That's almost double the HE doing it's max of 0.990%. By this you would be tempted to outfit all your troopers with AP instead of HE with the same listed damage. But wait. HE will actually out-perform AP according to this: 1 / (HE min - AP min + 1), or 1 / (50-0+1) = 1.961%.

Conclusion: Is either ammo better? Nope, it's a crap-shoot. The probability of the AP under-performing the HE's min negates its probability of out-performing the HE's max. But there is one fact than still remains: the HE always does a minimum damage > 0, and it's damage affects an area instead of a single tile. This might be beneficial to soldiers since every shot that connects (or even falls a bit short) will damage the target.

Incendiary weapon strength is theorized to determine the area of flames, not the damage inflicted. Damage for that type is either 0 or between 5 and 10 depending if the unit catches fire, or between 1 and 12 if the unit is standing in fire. Hope this helps. --Zombie 15:06, 24 Oct 2005 (PDT)


Great stuff, Z! Thanks for clarifying. Danial or I will move this to the Damage Formula page soon. It's great to have sweeping generalities in black and white :) -MikeTheRed 17:39, 24 Oct 2005 (PDT)


I'm just making a quick note:

We seem to be missing an explanation on fatal wounds received from penetrating damage. Can anyone recall where we tucked this information away? I know we got down to the bottom of this somewhere... and it's not under health or fatal wounds.

- NKF

Melee damage ranges

What's the damage range used for melee attacks (stun rods/alien terrorists)? 0 to x2, x0.5 to x1.5, or something else?--Ethereal Cereal 00:36, 14 March 2007 (PDT)


For Stun Rods and HTH alien attacks the range is 0-2x.--Zombie 08:45, 14 March 2007 (PDT)

Cool Table, Zombie

Thanks so much for making the time to put that there. It must have taken some tweaking.

To me, though, the mind's eye notices differences more quickly. Which is to say, here, to have made all the 100s be "-" and then the rest be +20 or -10 or whatever.

Just a thought. Please delete this after reading it! - MikeTheRed 00:14, 6 July 2007 (PDT)

Probabilities

So weapons may do anything from zero to twice their nominal damage. I have the impression that this isn't totally random, but sort of a bell-curvish distribution. Laser Rifle vs Floater should require two hits about 1/3rd of the time and it feels as if one-shot kills were a lot more common. However, I don't have any actual data to back this up.

Also, can it be that the soldier's firing accuracy does matter? That good marksmen not only have a higher to-hit chance to begin with, but also receive a bonus on their damage roll? --Schnobs 18:45, 10 November 2007 (PST)

Typo in damage modifiers table

Looks like there is a typo in the table for incendiary damage against personal armor. 0 is listed while it should be 80. I spotted this one, there might be others. Here is the raw data I have:

.data:0046DE58 damageModifierAP         dw 64h,64h,64h,64h,64h,64h,64h,3Ch,64h,64h,64h,64h,50h,3Ch; 0
.data:0046DE74 damageModifierIncendiary dw 64h,64h,50h, 0,28h,46h,46h,64h, 0,50h,0AAh,64h,64h,64h; 0
.data:0046DE90 damageModifierHE         dw 64h,64h,64h,64h,4Bh,64h,64h,64h,82h,64h,64h,50h,3Ch,50h; 0
.data:0046DEAC damageModifierLaser      dw 64h,64h,64h,64h,64h,64h,64h,64h,64h,64h,64h,96h,64h,46h; 0
.data:0046DEC8 damageModifierPlasma     dw 64h,64h,64h,64h,64h,64h,64h,64h,64h,64h,64h,50h,64h,46h; 0
.data:0046DEE4 damageModifierStun       dw 64h,64h,5Ah,50h,64h,64h,50h,64h,64h,5Ah,64h,64h,64h, 0; 0
.data:0046DF00 damageModifierMelee      dw 64h,78h,64h,64h,5Ah,64h,64h,64h,64h,64h,64h,64h,64h,64h; 0
.data:0046DF1C damageModifierAcidSpit   dw 64h,0A0h,6Eh,64h,28h,64h,64h,64h,64h,64h,64h,64h,64h,64h; 0
I've personally stood my soldiers in personal armor in flames without them taking any damage. Arrow Quivershaft 19:16, 9 February 2008 (PST)


The damage modifiers from the executable are correct, it's just that certain armor types override those values. For instance, Personal Armor is listed at 80% against incendiary in the executable, but in real-life situations soldiers wearing this armor type are completely safe from fire. I suppose we should make a note of this. --Zombie 21:33, 13 February 2008 (PST)


Damage Doubling

Sirgalahadwizard's last edit got me wondering:

(edit: In TFTD, the listed weapon damage in the UFOpaedia is still the average damage caused, but the difference from UFO is that random weapon damage is rolled twice and averaged, which produces values which are more often closer to the average)

Doesn't that just result in the same thing? I mean, it still results in damage being anywhere between 0 - 200%. Even in UFO, most of the damage does tends to fall somewhere along the average.

However, it has got me wondering about how the number is actually doubled. I don't think we've ever chronicled how UFO doubles the damage. Whether it's doubled by rolling a random number and feeding the doubled damaged as the range for the random value, or like the one mentioned: rolled twice, added up and then halved.

- NKF 21:53, 13 March 2008 (PDT)

Statistically, the more dice you roll, the closer you'll get to the average. Take a d6. Rolling 1d6, you have an equal chance of getting any value, 1-6. With 2d6, you have 36 different combos, of which nearly half of them (16) are 6, 7, or 8, all right in the middle. Whereas the chances of getting a 2 or 12 are only 1 in 36 each! So no, they aren't the same; rolling twice means that, statistically, you'll get values in the middle far more often than outliers.
As for how damage was calculated...I think it multiplies the average by a random interger between 0 and 2, with decimals out to hundereths. Or something along those lines. Arrow Quivershaft 21:57, 13 March 2008 (PDT)
Oh, no question about the difference in value distribution of the two methods. I just meant that either method still allows for values between 0 to 200%. I'm just wondering what the game actually uses and to find out if UFO uses a different method from TFTD. - NKF 22:38, 13 March 2008 (PDT)
That, I have no idea on. Sorry. I'd actually suspect that the method used is the same...TFTD was just a quick skin change of UFO. Very little actual code got changed, they just played around with the number bits for stats to change stuff. And the names and graphics, obviously. The thicker skin(higher armor) of the TFTD aliens may mask this, though. Arrow Quivershaft 22:46, 13 March 2008 (PDT)

One thing I'm not clear on from reading the above is whether the damage roll for UFO Defense is rolled once or twice. In other words, is it linear or bell-curved. Sounds like we believe TFTD is rolled twice and averaged, and it does seem reasonable to suppose that UFO is also rolled twice since it's substantially the same game engine. Can anyone provide any more information? I'm trying to get an exact formula for effective average damage vs armourin UFO Defence, so I need to know if the function is linear or gaussian, and if gaussian, how many rolls. Also do we know what the range & granularity is. E.g. is it 0% to 100% in units of 1%, or 0 to maximum damage in units of 1, etc? Spike 07:02, 5 April 2008 (PDT)

Zombie has explicitly verified that the damage roll for UFO Defense is only once. Also, the result of rolling twice and averaging is pretty much a right triangle, not a bell curve. [Not exactly, because of integer truncation; there are three ways to roll zero but only one way to roll maximum, for instance.] -- Zaimoni 13:38, 6 Apr 2008 (CDT)
In contrast: rolling twice, and then adding, is as close to a right triangle as a discrete probability distribution can get. -- Zaimoni 16:10, 6 Apr 2008 (CDT)

Thank you Zaimoni. And what about the rolled range and steps? Is is e.g. 0.00 - 2.00 x Average, or (zero) to (2 * Average) in integer steps, or ? That's probably a hard thing to deduce, it might need code inspection. Spike 11:54, 7 April 2008 (PDT)

I think I identified the code for this. Standard damage goes like this:
.text:0040DF58 66 8B 0D E8 83 47 00    mov     cx, currentWeapon_damage
.text:0040DF5F 66 D1 E1                shl     cx, 1
.text:0040DF62 51                      push    ecx                             ; rndMax
.text:0040DF63 E8 E8 F8 02 00          call    GetRandom_0_n
.text:0040DF68 83 C4 04                add     esp, 4
.text:0040DF6B 8B C8                   mov     ecx, eax
which means damage*2*rand()
For HE damage:
.text:0040DF36 66 A1 E8 83 47 00       mov     ax, currentWeapon_damage
.text:0040DF3C 50                      push    eax                             ; rndMax
.text:0040DF3D E8 0E F9 02 00          call    GetRandom_0_n
.text:0040DF42 66 8B C8                mov     cx, ax
.text:0040DF45 83 C4 04                add     esp, 4
.text:0040DF48 0F BF 05 E8 83 47 00    movsx   eax, currentWeapon_damage
.text:0040DF4F 99                      cdq
.text:0040DF50 2B C2                   sub     eax, edx
.text:0040DF52 D1 F8                   sar     eax, 1
.text:0040DF54 03 C8                   add     ecx, eax
which is damage*rand()+damage/2
rand() is base on a linear congruent generator:
.text:0045FA65 A1 58 68 47 00          mov     eax, rand_internal_state
.text:0045FA6A 69 C0 FD 43 03 00       imul    eax, 214013
.text:0045FA70 05 C3 9E 26 00          add     eax, 2531011
.text:0045FA75 A3 58 68 47 00          mov     rand_internal_state, eax
.text:0045FA7A C1 F8 10                sar     eax, 10h
.text:0045FA7D 25 FF 7F 00 00          and     eax, 7FFFh
.text:0045FA82 C3                      retn
(For the curious, it is the Microsoft Visual/Quick C/C++ version)). HTH. Seb76 13:06, 7 April 2008 (PDT)