Craft Combat Mechanics

From UFOpaedia
Revision as of 22:24, 18 October 2020 by Alpha Centauri Bear (talk | contribs) (→‎Alternative closing speed observations)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This article attempts to summarise everything we know about craft combat game mechanics - particularly what happens in the Interception Window. This started with some empirical research I did, and has been greatly enhanced by code decompilation done by Xusilak, Seb76, Morgan525/Tycho, and others. Spike 19:08, 8 September 2012 (EDT)

X-Com Behaviour

Note: In all of the following sections, I refer to "game seconds". But actually this is a supposition. What I'm actually measuring is multiples of the firing interval of a standard Cannon. This is stated in the in-game UFOPaedia to be 2 (game) seconds. It may or may not be meaningful to talk about these being actual game seconds. Maybe they are no more than multiples of the Cannon firing interval. And quite possibly the Cannon firing interval itself is not fixed, but is variable.

Rate of Fire

Rate of Fire is hugely important, as (along with accuracy and damage) it is a major determinant of firepower (the rate at which damage is inflicted on an enemy craft). It turns out that the in game UFOPaedia information on rates of fire is significantly incorrect.

Observed Rates of Fire

The quoted fire rates (or rather fire intervals) in the in-game UFOPaedia are wrong. Results from experiment show the following provisional information:

Weapon:         Average Fire Interval (gs)       UFOPaedia
                Aggressive/Standard/Cautious     Value (gs)
Cannon                   2 /  2 /  2                 2
Laser Cannon            12 / 12 / 12                 4
Plasma Cannon           12 / 12 / 12                 6
Stingray                16 / 24 / 32                15
Avalanche               24 / 36 / 48                20
Fusion Ball             16 / 24 / 32                25

Since there is some uncertainty as to whether X-Craft fire rates are constant or variable, and whether the actual fire interval of a Cannon actually is two game seconds (other than "by definition"), this can be restated in multiples of the Cannon fire interval:

Weapon:         Average Fire Interval (vs C)     UFOPaedia
                Aggressive/Standard/Cautious     Value (vs C)
Cannon                   1 /  1 /  1                 1
Laser Cannon             6 /  6 /  6                 2
Plasma Cannon            6 /  6 /  6                 3
Stingray                 8 / 12 / 16                 5
Avalanche               12 / 18 / 24                10
Fusion Ball              8 / 12 / 16                12.5

These fire rates/intervals are significantly different from those previously understood. In particular we see a massive increase the relative fire rate of conventional Cannon versus other weapons, identical fire rates for Plasma Cannon and Laser Cannon, and quite similar fire rates as between advanced Cannon and Stingray launchers. This has a major impact on computed firepower and payload characteristics for all weapons, and on the relative differences between weapons.

It should be noted that in almost every case, these observed fire interval values deviate from the advertised values, and in fact they deviate from values coded into the "craft" data structures of the game executable, which are shown by the in game UFOPedia. The observed values don't even have the same relative relationship as the reported values. The fire intervals in the craft data structure are ignored in combat.

Projectile Travel Time

Also consider that all missiles AND cannons actually travel to their target and have a speed delta that is added on top of the XCraft's. This information is the first four numbers before the weapons' rates of fire in the executable. Tycho 07:03, 3 July 2012 (EDT)

Though logically, the projectile speed won't affect the rate of fire, it should just create 1. a start lag between the start of firing, and the first hit/miss 2. an end lag, of wasted rounds fired that were fired before the UFO was shot down/escaped, but were still in-flight when the UFO was shot down/escaped. The projectile speed should not affect the actual rate of fire, apart from these lags. Of course, in average use, the lag factors will affect the average effective operational rate of fire, and the average operational ammo consumption per engagement.
Do you see any evidence of the distance to target changing in Cautious vs Standard vs Aggressive attack mode? I didn't see any, but my methods are pretty crude compared to yours. Spike 17:57, 3 July 2012 (EDT)

If you mean for missiles, no. The part of the interception subroutine that handles missiles only tracks the distance each missile travels and then compares this to the distance to target of the UFO *from the Xcraft* and the maximum range of the missile. If the distance traveled equals the distance to target, it goes through the attack sequence. Each missile is calculated separately but I think the randomization routine is old and since the attack for both missiles, fired in tandem, are calculated microseconds apart, you get nearly the same number generated for both.Tycho 06:37, 4 July 2012 (EDT)

Actually you are right that projectile speed vs distance would affect rate of fire, IF only one projectile (or any limited number of projectiles) were allowed to be in flight at the same time. For cannons this is definitely not true, you can see in the interception window that multiple projectiles are in flight. But this might be the case with missiles. If only one missile is allowed in flight (per launcher), then RoF will be strongly determined by projectile speed vs distance to target. In a lot of my tests I "controlled" for distance by hacking all weapon ranges to 70km, so that the distance to target was always 70km. Maybe I should have done more tests with variable range. I did do some tests with variable range, enough to convince myself it wasn't a factor, but maybe I was wrong. Maybe projectile speed vs distance is a factor, but only for missiles, and maybe that somehow explains the differences in effective rate of fire for missiles in Cautious vs Standard vs Aggressive mode? Spike 23:14, 6 September 2012 (EDT)

Effect of Attack Mode on Rate of Fire

The other major observation in the data above is that Attack Mode does influence rate of fire, but only for missile/launcher weapons. If we take Aggressive mode as the baseline, firing intervals for launched weapons only increase as follows:

Attack Mode  Firing Interval  Firing Rate
Aggressive       x 1.0           nominal
Standard         x 1.5           x 2/3
Cautious         x 2.0           x 1/2

In effect this penalises launcher weapons when used at stand off range (Standard), especially when weapon types are mixed on the same aircraft (Cautious). Conversely, it gives a high offensive premium to conducting launched weapon attacks in Aggressive mode, conceding the defensive advantage of stand-off range.

Firepower Based on Observed Rates of Fire

The observed rates of fire change the firepower relationships between weapons.

Armament       Rate(gs) Mode     Firepower
Cannon          1/2      ALL      40
Stingray        1/16     Agg      98
                1/24     Std      65
                1/32     Cau      49
Avalanche       1/24     Agg      107
                1/36     Std      71
                1/48     Cau      53
Laser Cannon    1/12     ALL      65
Plasma Beam     1/12     ALL      187
Fusion Ball     1/16     Agg      460
                1/24     Std      307
                1/32     Cau      230

(The firepower value above is just an arbitrary relative number based on 16gs of firing)

Observations: since even paired launchers must be used in Standard attack mode in order to maintain stand-off distance, it's interesting to compare their Standard firepower figure with the figures for the cannon weapons. In which case we see, for example, that the Laser Cannon is a very close match for the Avalanche in firepower - and can keep firing for 400 game seconds (gs) rather than the Avalanche's endurance of (in Standard mode) 72gs. Of course, stand-off distance is itself a massive advantage which cannot be ignored.

Where Rate of Fire Is (Not) Coded

There are no effects from changing the game executable XCom craft weapon data firing interval offsets (starting at offset 0x6fb18 in WinCE geoscape.exe). Neither for missile-type weapons nor gun-type weapons. There is an RoF effect when changing offset 0x10 of UFOs in the craft data at 0x6f9a8. This affects the built-in weapons of UFOs only, and is not used for XCom craft. My conclusion is that the RoFs values in the craft weapon data structure for XCom craft weapons are ignored in combat, that the actual values are hard coded elsewhere in the executable, and are proportional to the values given above at Observed Rates of Fire. The only effect of hacking these craft data weapon values is to change what is listed in the in-game UFOPaedia; there is no actual combat effect.

Damage Mechanics

Air combat damage inflicted by X-Com craft is a random value between 50% and 100% of the listed damage, which should be understood as the maximum damage. Unlike for Battlescape combat, the listed damage value is not the expected value per hit. The expected damage per hit will be 75% of the listed damage.

In contrast, damage inflicted by alien craft is 0-100% of the listed weapon power (damage), which again should be interpreted as a maximum damage value. In this case the expected average damage per hit will be approximately 50% of the UFO/USO's listed weapon power.

This has been validated by decompilation analysis performed by Morgan525/Tycho. See User:Morgan525#Comparison_of_Damage_routines

Accuracy Mechanics

Accuracy is a function of the weapon type used, as listed in the in-game UFOPaedia. Unlike ground combat there are almost certain to be no skill factors involved. There are probably no tactical factors involved. There is some speculation that different Attack Modes might create accuracy modifiers, but no hard evidence. This needs to be tested. The testing should control for Attack Mode and for range (separately), to make sure these don't have an impact on accuracy. They should also control for target size/type in case that is a factor.

I can confirm this as I have found the algorithm in the executable. See my discussion page. Tycho 06:39, 3 July 2012 (EDT)

The standard algorithm for X-Com attack accuracy varies with target size but not with game difficulty level (nor with attack mode). The formula is:

[1+(3/UFOsize)]/2 * Weapon Accuracy

With the UFOsize value going down as UFOs get bigger. In other words, for a typical Medium (size=3) target, the adjusted accuracy is equal to the base unadjusted weapon accuracy.

UFO Extender / TFTDextender provide an option to alter X-Com attack accuracy based on a seperate difficulty rating specified in the INI and target size.


Closing Range

I did some tests on timing events in the Interception Window. In particular, I was interested in seeing how long an XCom aircraft is exposed to enemy fire, whilst closing range to the target. In other words, what happens when the XCom aircraft's weapons do not give it a full stand-off advantage. I use the stated 2 game second (2gs) firing interval of the Cannon as a timer (and verified it using a Stingray as a timer in a second set of a tests).

Here are my findings:

  1. In the Interception Window, all aircraft close range with the enemy at the same rate (measured in shots fired).
    1. This is regardless of whether the aircraft is an Interceptor (2100 kts, Acc=3) or an Avenger (5400 kts, Acc=10).
    2. This is also regardless of whether the attack mode is Cautious, Standard, or Aggressive
    3. Of course, the range that the aircraft will attempt to close to, and hold, does depend on the attack mode
    4. The approach speed of 2 mutually approaching aircraft is 0.5km per game second, i.e. 1800 kmh / 900 kts (assuming the Cannon rate of fire to be 1 per 2 game seconds).
    5. Evidence for this:
      1. Closing from 70km to 30km, 40 volleys of Cannon fire are fired, at 1 / 2gs
      2. 40 volleys x 2gs = 80 gs time taken to close
      3. 40km / 80gs = 0.5 km/s
    6. This was also cross checked with a (hacked) Stingray launcher (zero damage, 75km range, 100 rounds) as the timer.
      1. Closing from 75km to 0km. 10 rounds fired. Stingray fire rate is 1 / 15 or 16gs [in Aggressive Mode]
      2. 10 x 15 gs = Time taken was 150 - 160 gs,
      3. 75km / 150 gs = 0.5 km/s
  2. The fire rate for missiles varies with the attack mode, but the fire rate for cannon type weapons seems to be unchanged. See more below.
  3. Or it's just barely possible that the fire rate, and the closing speed, both change by the same margin and remain in the same ratio.
    1. However I think this is unlikely and it violates Occam's Razor.
    2. Also, even if true, it doesn't really make any difference.
  4. The initial opening range on the Interception Window is 75km (600 distance units).
    1. That is the maximum distance visible, at the top of the window. Opening range = maximum range.
    2. UFOs seem to often settle at 70km range, if they are able to control the range.
    3. XComUtil does not let you enter a weapon range value above 75km. Probably Scott Jones was aware of this limit.
  5. Clearly, the Geoscape phase of Interception is different from the Interception Window
    1. Geoscape time freezes while you are in the Interception window
    2. Nothing happens at all until you hit the first button, so there's no rush
    3. On the Geoscape, relative aircraft speed is highly significant to whether an interception is possible.
    4. Possibly so is Acceleration (recent suggestions however that Acceleration is completely ignored).
  6. Caveats
    1. I didn't try multiple aircraft interceptions. Maybe these are different.
    2. I only tried one target type, a Small Scout (speed 2200 kts). It would be prudent to try other target types though.
    3. I think there's enough granularity in the tests I did (45 data points, greater than 100% difference in speed and acceleration between Interceptor and Avenger). But more is always good.
    4. I didn't test the speed of breaking off, or the speed of opening range after the initial closing. It's possible this is affected by aircraft speed and/or relative speed, and/or by acceleration.

Spike 19:38, 2 July 2009 (EDT)

Alternative closing speed observations

Tested in OpenXcom UFO and TFTD.

Equipped interceptor with Stingray missiles and Cannon to set an exact visible and audible approaching range range. It is audible because when interceptor approaches to Cannon fire range it starts firing noticeably loud. Set missile: range = 60, damage = 0, reload time = 10 (for all modes to not mess up with my observations), number of shots = enough to not run out of missiles with that frequent shooting. Set cannon: range = 10

This way I can clearly count number of missile shots when interceptor closes distance from 60 to 10 km = 50 km.

I did about 5 observations an in all of them I can count 20 missile shots. Sometimes maybe last shot was done a split second after cannon start firing. So probably 19.8 - 20 shots. That gives us 50 km / (20 shots * 10 s) = 0.25 km /s.

I have tried different reload times just to make sure I don't miscount number of shots and to see how big error I get. In all cases the 50 km closing time was around 200 s, give or take half a shot. I have also tested this in TFTD and got same results. This is about twice as slow comparing to previous author.

I have also independently computed estimated interceptor damage based on this closing time and enemy weapon power and fire rate. Results closely match to experimental observation when I use my approaching speed and they are noticeably off when I try to use Spike's numbers. So I have to conclude my speed is correct.

Note from Meridian

As meridian pointed out here, original XCom assumes UFOpaedia "second" to be equal *two* game ticks. Whereas OpenXcom assumes it to be equal *one* game tick. Hence the difference in calculated results.,8661.msg133010.html#msg133010

Alpha Centauri Bear

Control of Range

In general, the craft with the higher airspeed is able to control the engagement range within the Interception Window. Reportedly, Aggressive mode can override this behaviour for a short period of time. On the other hand, it may just be that the target is travelling below its maximum airspeed, as UFOs often do, but then accelerates to maximum speed to avoid a range it does not prefer to be at.

Update: An XCom craft with equal airspeed (Interceptor buffed to 2200 vs Small Scout @ 2200) can move to any desired range. A UFO with equal airspeed is unable to break off. So it seems that superior airspeed is required to break off, but equal airspeed is sufficient to control range. Or it may be simpler than that: if the opponent can't break off, then the attacker can always control the range. Spike 20:09, 13 July 2009 (EDT)

Question: Is it ever impossible for an XCom craft to break off from a UFO, due to the UFO's higher speed and/or aggression? I don't think so. The rules seem pretty different for UFOs, as opposed to XCom craft.

No. The code is written so that if the UFO has a higher maximum speed, the Xcraft can never disengaged. Tycho 06:46, 3 July 2012 (EDT)

Question: do UFOs attempt to hold an advantageous stand off range, as XCom craft do in Cautious and Standard attack modes?

No. The interception routine is strictly one-sided. The player chooses the range and when to attack. The UFO only responds if the Xcrafts comes into its weapon's range.Tycho 06:46, 3 July 2012 (EDT)

Question: Do UFOs use Attack modes in the same way that XCom craft do, and if so, what are the effects?

No. UFOs fire rate is based on an internal timer, which is reduced according to the game's difficulty level. Tycho 06:46, 3 July 2012 (EDT)

Standoff Is Independent of Range

Even if the range of a weapon is hacked to equal or exceed standoff range, it does not fire when in Standoff mode (or in Disengage). So Standoff mode also appears to mean "Weapons Safe". In fact, with a hacked weapon range, you can have the curious phenomenon that the craft actually pulls back from Standoff range (70km) to maximum firing range (eg 75km) when ordered into a Standard/Cautious attack.

Alien Behaviour

General Notes

The game provides very little access to UFO/USO behaviour, so understanding of UFO/USO mechanics is sketchier and information is harder to come by. However there are some facts to go on and some useful findings from code decompilation.

UFO craft weapons have a weapon strength and weapon range value stored in the game executable in the structCraftData format. This is the same structure that stores their speed, damage capacity, and size.

UFOs are capable of attempting to hold range, to close, and to break off, just like XCom aircraft. The behaviour is not well understood but appears in part to be influenced by the Attack mode of the XCom craft. Of course, initiating an attack often has an effect on this behaviour (e.g. the UFO attempts to break off).

UFOs are incapable of holding range or closing on their own initative. The player's choice of attack mode is the only factor that determines range. The only independent action a UFO can take is escape if the UFO is faster than the Xcraft and its escape timer has reached zero. Tycho

UFO Rate of Fire Mechanics

There is a value in structCraftData (at offset 0x10) which has a bearing on UFO weapons. This value ranges from 56 (decimal) for the smaller UFOs (including the unarmed Small Scout), down to 24 for the 3 largest types: Terror Ship, Supply Ship, Battleship. This is the base fire interval for the UFO weapon.

Seb76 has found from inspection that the firing interval varies randomly by 100%-200% of this base value, reduced by 2*Difficult Level (i.e. faster firing at higher difficulty level). (XCom craft weapon firing rates are not affected by Difficulty Level).

A countdown is stored in CRAFT.DAT at offset 0x26 and when it hits 0, the UFO fires. It is reset for the next shot with this formula:

tmp = offset10-2*difficultyLevel
nextShot = RAND(0,tmp)+tmp

So the average firing interval will be

1.5 x (structCraftData offset 0x10 - 2 x Difficulty)

Effect of Attack Mode on UFO RoF

From the formula above it does not seem the UFO RoF varies based on either XCom or Alien attack mode - Aggressive, Cautious, Defensive. This would fit with the UFO weapon being a "plasma cannon" type of weapon.

UFO Damage Mechanics

Damage inflicted by alien craft is 0-100% of the listed weapon power (damage), which again should be interpreted as a maximum damage value. In this case the expected average damage per hit will be approximately 50% of the UFO/USO's listed weapon power.

This has been discovered by decompilation analysis performed by Morgan525/Tycho. See User:Morgan525#Comparison_of_Damage_routines

UFO Accuracy Mechanics

... if the code is to be believed, UFOs have a 40.59% chance of missing in a perfect world, but the random number generator isn't perfect, so it's probably skewed in some direction. It doesn't appear to be modified by anything, at all. Here's a snippet:

.text:004470B7 6A 64                         push    100
.text:004470D5 E8 76 67 FF FF                call    GetRandom_0_n
.text:004470DA 83 C4 04                      add     esp, 4
.text:004470DD 66 3D 28 00                   cmp     ax, 40
.text:004470E1 0F 86 C4 00 00 00             jbe     exit
This could be translated to C as " if(GetRandom_0_n(100) <= 40) { return; } ", for the most part. What this does is skip all of the damage and destruction code if that GetRandom_0_n call rolls 0 through 40, for 41 values, out of 101 total possibilities. I am fairly certain that I recall UFOs missing frequently, as well. --Xusilak 15:36, 11 April 2010 (EDT)

UFOs have a flat 60% accuracy which is not affected by game difficulty, UFO size, or Xcraft attack stance. Tycho 06:50, 3 July 2012 (EDT)

UFO Extender / TFTDextender provide an option for UFO accuracy to vary with the difficulty level and X-craft attack mode. The difficulty level is independent of game difficulty and selected by the user in the INI.

General Behaviour

Survival Time of Multiple Attackers

Engaging a UFO with more than one attacking aircraft makes the UFO split its fire. This gives the attacking aircraft more time to perform attacks, before either being destroyed or being forced to disengage.

The following table gives the increased average survival time of attacking ships. The test scenario used XCom craft in Aggressive mode. The UFO was a Terror Ship. The test scenario did not consider survival by eliminating the UFO (the XCom craft were effectively unarmed). This was a pure endurance situation, the worst case scenario.

# of Attackers  Avg Survival Time  Expected  Deviation
    1           1.0 - nominal      1.0       100% nominal
    2           1.5                2.0       75%
    3           2.5                3.0       83.33% (5/6)
    4           3.0                4.0       75%

This is a slightly surprising result. In principle, if the total damage output of the UFO was constant, the average survival time would just be divided by the number of attackers; e.g. 2x as long for 2 attackers, 3x as long for 3 attackers, etc. The UFO actually seems to be doing more damage, or killing targets faster, when facing multiple XCom opponents. This is a result that requires an explanation. The survival time is measured in (zero-damage) rounds fired by the XCom aircraft. So another possibility is that the XCom aircraft are somehow able to fire more rounds when multiply engaged. However I don't think this is the case. It was not systematically tested but the XCom fire rates do not seem to increase noticeably when multiply engaged.

The results for 1, 2 and 4 attackers would be consistent with the UFO going into Aggressive Mode from Standard Mode when faced with multiple attackers. This would increase its RoF by 1/3, giving a 4/3 firepower increase and thus a 3/4 survival time for XCom. The attack mode is saved in INTER.DAT. It would be worth comparing saves of a single XCom interceptor with saves of multiple interceptors, and seeing what attack mode the UFO is in. Also to retest with more granularity (Cannon instead of Avalanche timers), in case the data for 3 attackers is actually nearer 2.25 = 75% Spike 16:13, 15 March 2010 (EDT)

So faced with multiple opponents, the rate of damage inflicted by the UFO seems to increase. Maybe this literally is a fudge factor, inserted by the game programmers to prevent these mobbing tactics from being too effective. Or it could be a consequence of something similar to an Attack Mode, for UFOs. Or it might be just an artefact of the test scenario - for example, in the test the UFOs were not taking any damage, perhaps this enables them to be more aggressive.

TFTD Submarine Combat Mechanics

Rate of Fire

Empirical Data

1. In multiples of the reload time of a Gas Cannon (shown as '1' below), reload times of other weapons are as follows:

Weapon Cau Std Agg
Gas      1   1   1
Ajax    16  12   8
DUP     24  18  12
Gauss    6   6   6
Sonic    6   6   6
PWT     16  12   8 

2. This is exactly the same as the equivalent EU craft weapons.

3. Range has absolutely no effect on these relative rates of fire / reload rates.

See also



  • Seems to be evidence from the special case of Ajax vs Survey Ship (base damage 60 vs damage capacity 60) that combat processing is aborted immediately upon a crash or destroyed result.
  • Also seems to be some evidence that to-hit and damage for a salvo is resolved with only one roll for each missile/round, not two independent rolls. (There was a comment to the effect that the RNG is primitive, the rolls are resolved microseconds apart, so the results are likely to be very similar.)
  • If true, the 2 preceding points probably also apply to XCOM:EU.
  • found offsets for Craft Weapons - see Talk:GEOSCAPE.EXE#TFTD_Sub_weapon_stats
    • also need to locate USO stats / Sub stats