Scout/Sniper AI is my latest OXCE+ project, adding squadsight capabilities for the aliens; now they can camp in smoke just like you! The code adds two new unit parameters that control this behavior:
- spotter: -1 - When a unit has a nonzero scout value, it sets a flag on any units it spots that allows sniper-enabled enemy units to "know" about the spotted target. The value placed here determines the number of turns the knowledge of the spotted target is available, -1 sets the value to the unit's intelligence score and 0 disables this behavior.
- sniper: 75 - This determines the percent probability that the AI unit will act on knowledge of targets spotted by scouts. When active, the sniper AI will pick from a list of the spotted targets and attempt to attack them whether or not the sniper can 'see' the target.
The choice of attack type depends on the sniper's weapons, accuracy, intelligence, and aggression. The AI calculates a score for each firing mode available on the weapon as well as considering throwing a grenade, and then picks the attack based on which mode it thinks will be the most efficient. The exact formula is:
score = number of shots * accuracy / percent TU cost of the attack, where accuracy will be modified by the UFO extender formula if that option is turned on (recommended).
The score is then modified by intelligence: score = score * RNG::(100 - int_coeff * (10 - intelligence), 100 + int_coeff * (10 - intelligence)), and is further modified by aggression for auto shot:
score = score * (100 + aggro_coeff * (aggression - 1))
The coefficients are explained below.
How this score is affected by intelligence and aggression is determined by these global parameters:
- fireChoiceIntelCoeff: 5 - This parameter is a measure of how much a unit's intelligence matters when determining what the most efficient firing mode is; lower intelligence means more randomness in the choice, while 10 intelligence means the unit will always pick the most efficient mode. Defaults to 5, which leads to a 50%-150% RNG roll modifier to score for 0 intelligence, reducing linearly to 100%-100% at 10 intelligence.
- fireChoiceAggroCoeff: 5 - This parameter measures how much a unit's aggression bumps up the chances of using auto shot - aggression above 1 will be an increasing multiplier to the efficiency score for auto shot, while aggression of 0 will be a decrease. Default value is 5.
The ruleset for using these values will look like this:
units:
- type: STR_SECTOID_SOLDIER
sniper: 75 # Sectoid soldiers have a 75% chance of taking a sniper action when the AI has determined it will attack
- type: STR_SECTOID_NAGIVATOR
spotter: -1 # Sectoid navigators will spot for the soldiers, giving them as many turns to act on your soldiers as the navigator's intelligence
ai:
fireChoiceIntelCoeff: 10 # Make the choice of attack more RNG dependent
fireChoiceAggroCoeff: 1 # Aggression doesn't matter as much
The source code is available on my GitHub page (https://github.com/ohartenstein23/OpenXcom/commit/17879ecceaaa004f9d80c2a227193d904f44e5e4).
Edit 171110: This is an official part of OXCE+, so the links for my repository above are deprecated. This post will remain for documentation.