aliens

Author Topic: TFTD: USO chance to hit the interceptor  (Read 3313 times)

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
TFTD: USO chance to hit the interceptor
« on: October 13, 2020, 12:37:11 am »
UFOpaedia here claims that all USO weapons have 60% chance to hit.
https://www.ufopaedia.org/index.php/Alien_Submarines

However, I have tested it a little bit and it feels like it is about just half of it. Both from visual frequency of "X-COM craft is damaged" comparing to "USO returns fire" and from calculating how much damage craft sustained after engagement. If it is 60% then craft should be about twice as more damaged then I calculated. Anybody can give more insight on that?

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: TFTD: USO chance to hit the interceptor
« Reply #1 on: October 13, 2020, 01:26:22 am »
The damage each hit does is randomized as well - it does 0-100% of the USO's weapon power, which would average out to give you the half of what you expect: https://github.com/OpenXcom/OpenXcom/blob/da95e73f7da88781227f4da0262b525e6fffaad2/src/Geoscape/DogfightState.cpp#L889

The accuracy is definitely 60%: https://github.com/OpenXcom/OpenXcom/blob/da95e73f7da88781227f4da0262b525e6fffaad2/src/Geoscape/DogfightState.cpp#L1238

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
Re: TFTD: USO chance to hit the interceptor
« Reply #2 on: October 13, 2020, 01:38:21 am »
Ah. This is 0-100% for USO weapon. That explains it. I thought it is 50-100% as for X-COM weapons.
Thank you.

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
Re: TFTD: USO chance to hit the interceptor
« Reply #3 on: October 13, 2020, 02:03:42 am »
What about interceptor chance to hit UFO here?
https://github.com/OpenXcom/OpenXcom/blob/da95e73f7da88781227f4da0262b525e6fffaad2/src/Geoscape/DogfightState.cpp#L833

It seems that minimal chance is 50% even with zero accuracy. And then it grows very fast even with low accuracy. For example chance for 50% accuracy weapon to hit smallest UFO is 90%!!! And to his largest one is even 150%!
Did I understood this formula correctly? If so then torpedoes should almost never miss. However, I quite often see them do so. Like maybe 1/3 times.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: TFTD: USO chance to hit the interceptor
« Reply #4 on: October 13, 2020, 04:16:20 am »
X-Com weapons indeed have a 50-100% damage range. You're probably interpreting the accuracy formula wrong - it is possible to have a 0% accuracy weapon that never hits, easy to test by modding a weapon accuracy to 0. The accuracy follows the formula described here: https://www.ufopaedia.org/index.php/Craft_Combat_Mechanics#Accuracy_Mechanics

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
Re: TFTD: USO chance to hit the interceptor
« Reply #5 on: October 13, 2020, 08:35:28 pm »
Hmm. This mechanics description doesn't match this piece of code that determines whether UFO is hit.
https://github.com/OpenXcom/OpenXcom/blob/da95e73f7da88781227f4da0262b525e6fffaad2/src/Geoscape/DogfightState.cpp#L833

Can you comment on this code? Is it relevant one?

Keep in mind that the accuracy article you pointed at is for original game where people tried to observe values. Whereas my question is about openxcom with the open code. And, probably, slightly different implementation that may lead to differences.



Let's compare both formulas side by side.

The one from wiki
Code: [Select]
[1+(3/UFOsize)]/2 * Weapon Accuracy

The one from openxcom code
Code: [Select]
RNG::percent((p->getAccuracy() * (100 + 300 / (5 - _ufoSize)) + 100) / 200)

I am not sure what RNG::percent is but would assume that it returns true with percentage given as an argument. So its argument expression above is a final accuracy against given UFO.
If this assumption is correct then the openxcom formula for accuracy can be simplified like that:
Code: [Select]
(Weapon Accuracy * (1 + 3 / (5 - _ufoSize)) + 1) / 2

I guess the "3 / (5 - _ufoSize)" part is same as "3/UFOsize" part in wiki formula just expressed in different variables. So if we replace it with wiki expression for the sake of simplification it turns into:
Code: [Select]
(Weapon Accuracy * (1 + 3/UFOsize) + 1) / 2

As you can see, it is almost identical except that "+1" thingy which effectivelly just adds flat 50% toward to hit chance.
« Last Edit: October 13, 2020, 09:08:18 pm by Alpha Centauri Bear »

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
Re: TFTD: USO chance to hit the interceptor
« Reply #6 on: October 13, 2020, 09:16:51 pm »
I have also tested it with 0% accuracy weapon in openxcom and confirm that it never hits. So it must me I am interpreting openxcom expression incorrectly.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9101
    • View Profile
Re: TFTD: USO chance to hit the interceptor
« Reply #7 on: October 13, 2020, 09:39:33 pm »
As you can see, it is almost identical except that "+1" thingy which effectivelly just adds flat 50% toward to hit chance.

It adds 0.5%, not 50%.
Check the brackets and operation precedence.

The OpenXcom formula is correct.
The Wiki formula is just written in a "human friendly" way, but is technically incorrect. It would give completely wrong values, considering integer division.

Btw. integer division is also the reason why that 0.5% is there at all... to round small UFO factor from 87.5% up to 88%.
For all other UFOs it is irrelevant, because integer division will round it down even with the extra 0.5%:
- very small 80.5% gets rounded down to 80%
- medium 100.5% to 100%
- large 125.5% to 125%
- very large 200.5% to 200%

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
Re: TFTD: USO chance to hit the interceptor
« Reply #8 on: October 13, 2020, 10:51:31 pm »
0.5% indeed. Thank you for pointing this out! I was confused with a lot of zeroes in formula.