XCOM 2/Aim Bonuses

Whenever one of your units makes an attack against an enemy, you will likely have a random chance to hit. Aim is the stat that governs how likely you are to hit your shots. Each point of aim equals one percentage point of hit chance.

Increasing your aim is the most consistent way to improve your soldier's lethality in the field. Missing fewer shots means generally fewer inconveniences suffered in the field. Aim can be improved in a variety of ways both on and off the battlefield.

In battle, your chance to hit any shot is Aim-Defense. Actually calculating aim and defense requires a few modifiers

Soldier base aim stat
Each soldier has a base aim stat. In vanilla, this is determined entirely by their class and rank. In War of the Chosen, soldiers may boost their base aim stat by going on covert actions.

All Rookies have 65 aim

Weapon Range Bonus
"Close Range?" ~Central Officer Bradford, 2015

Most XCOM weaponry receives a bonus to their aim as they get closer to the enemy. Furthermore, some weapon types receive penalties to their aim when fighting at an inappropriate range. For example, Shotguns get a bonus to aim against any target within 10 squares and a penalty to their aim against any target beyond 11 squares. As a general rule, alien weaponry does not benefit from weapon range bonuses.

Short Range Weapons include Shotguns, Pistols, Bullpups, and Templar Autopistols, and the Arashi


 * ''Note: at exactly 10 tiles away, a magnetic or plasma shotgun will have +3 aim, not +2 aim

Medium Range Weapons include assault rifles and cannons. This is the only weapon category which never receives a penalty to aim due to weapon range. Oddly, they receive noticeably different bonuses depending on what tier of weapon you are using.

The only Long-Range Weapon is the sniper rifle. It can never receive weapon range bonuses, it can only receive penalties for being too close

Lastly, the Vektor Rifle has its own set of weapon range tables. It most closely resembles the medium range table.

Cover
By far the most common form of defense boost is cover. As long as a unit stands against cover, they have a defense bonus against all ranged attacks which come from the other side of that cover.

High cover (sometimes referred to as "full cover") provides +40 defense. Low cover (sometimes referred to as "half cover") provides +20 defense.

Whenever an attack comes from an angle that could be prevented by both high cover and low cover, it faces the high cover hit penalty. If an attack hits a unit who is not benefiting from any kind of cover, that unit is "flanked", and the attack has an extra 40 crit.

Aliens may not earn a cover bonus to defense against shots from concealed XCOM operatives. However, if an enemy unit is standing next to something that would provide cover, any shot taken against that target will not get the +40 crit that it would normally earn from a "flanking" shot.

Overwatch shots made against moving targets are always flanking shots and ignore any cover bonuses the target would have had. Overwatch shots made against stationary targets (from the Covering Fire or Threat Assessment abilities) do not ignore cover, and will have their aim penalized according to the enemy's cover.

Some units may not take cover at all, and so cannot earn a boost to defense due to cover. That said, shots taken against these units can never receive the +40 crit that one would normally earn from a "flanking" shot. These units may not take cover, but they also cannot be flanked. The XCOM Spark is the only playable unit with this property. Alien units with this property include the Faceless, ADVENT Turret, ADVENT MEC, Berserker, Archon, ADVENT Heavy MEC, Andromedon Shell form, Chryssalid, Sectopod, and Gatekeeper.

Configs
Class aim data found in XCOM 2 configs: XCOM 2\XComGame\Config\DefaultClassData.ini for the vanilla classes, XCOM 2\XComGame\DLC\DLC_3\Config\XComClassData.ini for the SPARK, and XCOM 2\XCom2-WarOfTheChosen\XComGame\Config\DefaultClassData.ini for the resistance heroes

Weapon range data was found in XCOM 2 WotC configs: XCOM 2\XCom2-WarOfTheChosen\XComGame\Config\DefaultGameData_WeaponData.ini. Weapon category (whether a weapon was a close, medium, or long range weapon) was found in WotC source code: XComGame\Classes\X2Item_XpackWeapons.uc