Talk:Chance to Hit (EU2012)

From UFOpaedia
Revision as of 12:44, 16 January 2013 by Bomb Bloke (talk | contribs)
Jump to navigation Jump to search

A few messy late-night notes whilst I work out in me own mind how this here accuracy system works.

Most guns seem to have the same figures as far as accuracy goes. See how on the Weapons_(EU2012) page just about all of them have the same range of 27? Yeah, that means they get the same accuracy bonuses. Haven't checked the laser/alloy shotguns yet but a vanilla pistol has the same accuracy as a heavy plasma for eg.

Bonuses like the light plasma's 10% aim chance are tacked onto the final score. So if a heavy plasma has a 65% chance to hit after adding all bonuses and minusing all penalties, the the lpr would've got 75%.

Crit chance has nothing to do with chance to hit. A shotgun is as likely to crit at near or far range (assuming it can actually hit something), which is a bit unintuitive when you consider how a real shotgun works...

The pistol foundry crit chance upgrade shows up in the geoscape when viewing weapon info as being 20%. In battle, it doesn't show up at all.

The pistol foundry aim chance upgrade shows as 10% in the battlescape, but doesn't show in the geoscape. The scope crit upgrade doesn't appear to work at all.

Do alien defense bonuses show up prior to researching them? Would hope so, otherwise the displayed shot percents are messed up... Which they are for normal/easy mode anyways, apparently you get a hidden bonus on those modes which gets larger with each consecutive miss you make.

A few logged bonuses at different ranges on a flat surface:

Weapon Range Type Crit Angle 0 1 2 3 4 5
Pistol Medium (27) 0 Straight 41 37 32 28 23
Pistol Medium (27) 0 Diagonal 41 35 28 22 16 9
Shotgun Short (10) 20 Straight 56 52 44 40 32
Shotgun Short (10) 20 Diagonal 56 48 40 32 24 16

(Range 0 acquired by placing a trooper where a thinman is scripted to drop, first Slingshot mission has such a position that's really easy to get to).

Thinking of it as a penalty system, you get something like -4.5 for every square you are away from the target, so eg max bonus of 41 - 4.5 = 36.5 (rounded up to 37), -4.5 = 32, -4.5 = 27.5 (rounded up to 28), etc. This bonus can't go negative, so once you move out of range to get it at all, your accuracy isn't really hindered by moving further back. Likewise, if you're too far back to get the bonus, if you don't move far enough forward you STILL won't get any bonus.

Figures suggest that Pythagoras is used to work out the distance as need be. So moving away on a diagonal line (one tile on each axis), multiply 4.5 by 1.4 (add the squares of one to each other to get two, then take the root of that), penalty becomes 6.3. 41 - 6.3 = 35.7 (should be 34.something), -6.3 = 29.4 (should be 27.something), -6.3 = 23.1 (should be 21.something), -6.3 = 16.8 (should be 15.something)... this suggests range 0 is really a 40.something bonus, not an exact 41. Probably 40.6 or somesuch.

Shotgun figures don't make a lot of sense moving along one axis, but diagonally (along two axises) it looks like just -8 each time. -5.7 along the straight then? Still doesn't add up, might've somehow mislogged. Shotgun gets a penalty at longer ranges. Not sure about other guns, you probably get out of range before that happens.

-  Bomb Bloke (Talk/Contribs) 09:10, 13 January 2013 (EST)

BB, check this link on the Multiplayer section of the 2K forums: [[1]]. There's also a link there to a Google Docs table where someone already did that math, I've been wanting to add that but I haven't had time yet. Hobbes 17:46, 13 January 2013 (EST)

Ah, that's awesome, thanks! Unfortunately it lacks the actual maths I'm after, but there's plenty of data to work with.

Very interesting that so many weapons have the same "range". For eg, the game reports the assault rifle is a "short" range weapon, but all other data seems to indicate it's the same as most of the other guns (which are flagged as "medium").

The guy also notes a "jitter" element affecting his logged stats, which I also picked up on one or two tests. It may be that distance is plotted from between the units - larger units being effectively "closer", so you may get a better range bonus when facing down a sectopod then you do a drone. Or maybe the game just fudges the numbers a little every now and then to try and hide the feeling that all troops are the same. Or maybe it has something to do with direction...

Anyway, thinking some more, the "bonus" for close range attacks with standard guns is probably rounded down, not up. This'd suggest that for most guns, the formula is something like:

41.6 - root(square of x range + square of y range) * 4.5

So for eg, if you're talking four squares away it's:

41.6 - root(4^2 + 0) * 4.5 = 41.6 - 4 * 4.5 = 41.6 - 18 = 23.6

Or diagonally at range five it's:

41.6 - root(5^2 + 5^2) * 4.5 = 41.6 - root(50) * 4.5 = 41.6 - ~7 * 4.5 = 41.6 - 31.8 = 9.7

Or diagonally at range two it's:

41.6 - root(2^2 + 2^2) * 4.5 = 41.6 - root(8) * 4.5 = 41.6 - ~2.8 * 4.5 = 41.6 - 12.7 = 28.9

Good enough!

For the shotgun, the maths seems to be (but isn't exactly) something like:

56 - int( 8 * root of (square of x range + square of y range) / root(2) ), and don't ignore the bonus if it goes negative.

(Though the base shotgun is the only gun with range 10, so as the laser/alloy versions have range 27, the formula is probably a little different again for them).

So at ranges 1 through to 5 it's:

56 - int( 8 * root(1^2 + 0^2) / root(2) ) = 56 - int( 8 * 1 / root(2) ) = 56 - int( 8 / root(2) ) = 56 - int( 5.65 ) = 56 - 5 = 51

56 - int( 8 * root(2^2 + 0^2) / root(2) ) = 56 - int( 8 * 2 / root(2) ) = 56 - int( 16 / root(2) ) = 56 - int( 11.31 ) = 56 - 11 = 45

56 - int( 8 * root(3^2 + 0^2) / root(2) ) = 56 - int( 8 * 3 / root(2) ) = 56 - int( 24 / root(2) ) = 56 - int( 16.97 ) = 56 - 16 = 40

56 - int( 8 * root(4^2 + 0^2) / root(2) ) = 56 - int( 8 * 4 / root(2) ) = 56 - int( 32 / root(2) ) = 56 - int( 22.62 ) = 56 - 22 = 34

56 - int( 8 * root(5^2 + 0^2) / root(2) ) = 56 - int( 8 * 5 / root(2) ) = 56 - int( 40 / root(2) ) = 56 - int( 28.28 ) = 56 - 28 = 28

Yeah, something like that. Will have to scratch my head a bit more as it's usually 1-2% off. May be "eight and a bit" instead of just eight. Will want to log more values on the diagonal to be sure.

1 to 5 on the diagonal does look pretty clear with the few values I have though:

56 - int( 8 * root(1^2 + 1^2) / root(2) ) = 56 - int( 8 * root(2) / root(2) ) = 56 - 8 * 1 = 56 - 8 = 48

56 - int( 8 * root(2^2 + 2^2) / root(2) ) = 56 - int( 8 * root(8) / root(2) ) = 56 - 8 * 2 = 56 - 16 = 40

56 - int( 8 * root(3^2 + 3^2) / root(2) ) = 56 - int( 8 * root(18) / root(2) ) = 56 - 8 * 3 = 56 - 24 = 32

56 - int( 8 * root(4^2 + 4^2) / root(2) ) = 56 - int( 8 * root(32) / root(2) ) = 56 - 8 * 4 = 56 - 32 = 24

56 - int( 8 * root(5^2 + 5^2) / root(2) ) = 56 - int( 8 * root(50) / root(2) ) = 56 - 8 * 5 = 56 - 40 = 16

-  Bomb Bloke (Talk/Contribs) 08:53, 14 January 2013 (EST)

Or it's 56 - 4 * int( 2 * root of (square of x range + square of y range) / root(2) ). What with the common factor of 4 and all. Duh.

56 - 4 * int( 2 * root(1^2 + 0^2) / root(2) ) = 56 - 4 * int( 2 * 1 / root(2) ) = 56 - 4 * int( 2 / root(2) ) = 56 - 4 * int( 1.42 ) = 56 - 4 = 52

56 - 4 * int( 2 * root(2^2 + 0^2) / root(2) ) = 56 - 4 * int( 2 * 2 / root(2) ) = 56 - 4 * int( 4 / root(2) ) = 56 - 4 * int( 2.82 ) = 56 - 8 = 48

56 - 4 * int( 2 * root(3^2 + 0^2) / root(2) ) = 56 - 4 * int( 2 * 3 / root(2) ) = 56 - 4 * int( 6 / root(2) ) = 56 - 4 * int( 4.24 ) = 56 - 16 = 40

56 - 4 * int( 2 * root(4^2 + 0^2) / root(2) ) = 56 - 4 * int( 2 * 4 / root(2) ) = 56 - 4 * int( 8 / root(2) ) = 56 - 4 * int( 5.66 ) = 56 - 20 = 36 (Matches the Google docs spreadsheet, but not my observed results!)

56 - 4 * int( 2 * root(5^2 + 0^2) / root(2) ) = 56 - 4 * int( 2 * 5 / root(2) ) = 56 - 4 * int( 10 / root(2) ) = 56 - 4 * int( 7.07 ) = 56 - 28 = 28

So yeah that's shotguns.

With most range 27 weapons at a range of two tiles, the spreadsheet indicates a range bonus of 33. I got 32. Why? Tests reveal it's because of the direction. Without spamming more example calculations showing why, that means the base bonus along one axis is a very nice round 42, but along the other it's 41.6. For some reason. Presumably something similar is going on with shotguns (which means you can get a +4% bonus at certain ranges depending on which direction you approach), but I'll have to scratch my head a little bit as to where to stick the relevant number. My first guess is it's a +0.4 bonus to whatever value is to be rounded down before multiplying by 4. I'd need a whole bunch more logged results to be certain. Bah. Wish I could copy'n'paste units around the board like I can for the old game...

And laser/alloy shotguns are probably the same formula but maybe a different range bonus. Something higher then 56 probably, again that'll require more logs. The results should make it possible to work out what "range 27" actually means though, so those numbers should be the most interesting.

Anyway. Snipers!

-27.5 + root(square of x range + square of y range) * 2 * root(2), ignore the bonus if it goes positive.

This works pretty well but there's enough jitter to suggest that direction adds a bonus in there somewhere too.

-  Bomb Bloke (Talk/Contribs) 07:20, 15 January 2013 (EST)

I've had the discussion on the 2K forums before of how to translate the game values (weapon range, movement) into reality, ie, how much tiles is 27 or 12. From the tactical battles 27 should correspond to 17 tiles (the sight limit for your units) and the 12 to either 7 tiles or 15 (depends if dashing is included. One value that comes from here is that it costs 1.6 to move 1 tile horizontally or vertically. If you apply that 1.6 constant per tile to firing then 27 = 16.875 tiles, which also fits the battle results.
The game files also have the termination 'ft' for some range numbers so the numbers can merely be feet. Hobbes 07:38, 15 January 2013 (EST)

That'd about make sense, but pulling some figures for alloy shotguns (range 27), I find them exactly the same as the regular version... which has a range of 10. And can fire right up to about the sight range limit. That is to say, it appears weapon "range" has absolutely nothing to do with anything... Except reaction fire, maybe, though the weapons page already shows a separate field for "reaction range". And then there's "reaction angle".... I get the impression those numbers are simply unused remnants of scrapped features.

Ah well! Saves a bit of time I suppose in that I don't have to try and factor it into the equations, which are probably about as complete as they need to be (short of someone pulling the exact coding out of the executable). Or maybe the figures on the weapons page are just plain wrong, I dunno. -  Bomb Bloke (Talk/Contribs) 07:44, 16 January 2013 (EST)