aliens

Author Topic: [Documentation] Scout/Sniper AI  (Read 3662 times)

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1904
  • Flamethrowers fry cyberdisk circuits
    • View Profile
[Documentation] Scout/Sniper AI
« on: August 28, 2017, 03:44:59 pm »
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:
Spoiler:
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:
Code: [Select]
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.

Edit 171110: This is an official part of OXCE+, so the links for my repository above are deprecated.  This post will remain for documentation.
« Last Edit: July 17, 2018, 02:37:12 pm by Meridian »

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1904
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Scout/Sniper AI
« Reply #1 on: October 04, 2017, 05:48:51 pm »
After cleaning up some of the code and adding some comments at Meridian's suggestion, I've also added a setting for an accuracy penalty for actions taken with no line-of-sight to the target.  This is a percentage multiplier on accuracy when firing on both empty tiles and units to which the firing unit has no LOS, set by the following ruleset options:

  • noLOSAccuracyPenaltyGlobal: 50 - This sets a global multiplier on accuracy when having no LOS, the example of 50 multiplies the accuracy by 50%.  Defaults to -1 to disable this feature unless specifically set on single items.
  • noLOSAccuracyPenalty: 75 - Same as the global setting, but only on individual weapons.  Overrides the global setting when not at the default of -1.

When a player unit fires on a target with a weapon that has this penalty, an alert will show, similar to the no line of fire message, using the string STR_NO_LOS_PENALTY.

A sample ruleset implementing this feature might look like this:
Code: [Select]
noLOSAccuracyPenaltyGlobal: 50

items:
  - type: STR_RIFLE
    noLOSAccuracyPenalty: 90 # makes the rifle better than most for sniping

extraStrings:
  - type: en-US
    strings:
      STR_NO_LOS_PENALTY: "Accuracy loss for no LOS!"

An amended commit is available at the link in the first post.

Edit: I made a mistake in my first post, the ruleset parameter "scout" should actually be "spotter."  I've amended the documentation to match, sorry.

Offline mumble

  • Colonel
  • ****
  • Posts: 338
    • View Profile
Re: [EXE] Scout/Sniper AI
« Reply #2 on: October 09, 2017, 05:29:11 am »
is it possible to exempt the LOS accuracy loss for shots within 1 tile of the target? One unfortunate side effect of this is trying to blow open certain segments of walls on purpose enforces the accuracy drop, which seems unrealistic when I'm only targeting DIRECTLY on the other side of the wall...

Offline Meridian

  • Global Moderator
  • Commander
  • ***
  • Posts: 6761
  • OXCE developer
    • View Profile
    • My Wiki
Re: [EXE] Scout/Sniper AI
« Reply #3 on: January 31, 2018, 08:38:21 pm »
UPDATE:

The LOS accuracy penalty has been reworked.

Current status:
1. If aiming at a unit, the vanilla LOS (line of sight) is checked... if you can see the unit (red enemy indicator box), there is no penalty, if you cannot see the unit (green enemy indicator box), there is penalty; LOF (line of fire) doesn't matter

This is 100% consistent with vanilla definition of LOS.

2. If aiming at a tile without a unit (or at a tile, which has a unit that you don't yet know about), vanilla LOF (line of fire) is checked and some parts of LOS checks are done too, not all (LOS checks done are: max view distance, day/night visibility, smoke). LOS checks not done are: psi vision, heat vision, camouflage/anti-camouflage. Arcing weapons and throwing considers LOF of a projectile-weapon (i.e. a straight line, not a parabola)!

There is no definition of LOS for tiles without a unit in vanilla... the algorithm above is the best definition I could think of.

PS: The aiming cursor (if extender accuracy user option is turned on) does consider the penalty now and correctly shows the real accuracy used for calculations.

PS2: A pretty nice side effect is that if a penalty is set, you can use it to test vanilla LOF check without actually shooting... some people may find it amusing... have fun

Offline Eddie

  • Commander
  • *****
  • Posts: 548
    • View Profile
Re: [Documentation] Scout/Sniper AI
« Reply #4 on: July 19, 2018, 04:02:44 am »
I recently played a night mission against sniper/spotter enabled enemies (Spartans in Piratez). The AI did things that felt a bit... cheaty.
Basically, cover of darkness does not work anymore. As soon as you land a hit on a spotter, whether he sees you or not, the shooter is marked as a valid sniper target. Then for two to three turns, the AI has maphack on that gal. You can run to the other end of the map in the cover of darkness, you still get hit with sniper fire (if there is line of fire). Save is attached if you want to experience what I mean.
Am I exaggerating or is that how the code works?

Behaviour that feels cheaty:
- Shooting a spotter without him seeing you still makes you a sniper target.
- Changing your position to a location no enemy can see does not save you.

I can see the logic of shooting in a direction from where you hear/see shots coming. But the targeting is too precise for that, and moving away/out of sight should save you. The AI did also throw grenades at me, which felt far more appropriate.

So... what is your opinion on this?

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1904
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [Documentation] Scout/Sniper AI
« Reply #5 on: July 19, 2018, 04:47:46 am »
The code is working exactly as intended, what you're running into are balance concerns.  If you think 2-3 turns of having to hide a soldier in cover is too punishing, then explain the reasoning to Dioxine.  Otherwise, you might have to learn new tactics to counteract it.

Included with this code is the ability to define a hefty accuracy penalty on these shots when you can't directly see the target, and this affects the AI too - so while they make take the shots, it's a lesser chance of being hit by them.

Offline Eddie

  • Commander
  • *****
  • Posts: 548
    • View Profile
Re: [Documentation] Scout/Sniper AI
« Reply #6 on: July 19, 2018, 01:19:19 pm »
What actually bothered me was not the balance but the logic of it. It took me a while before I could figure out what is going on. I made sure all my gals are in cover of darkness, but I still got shot. I thought there are some faint light sources I kept overlooking.

I can think of a counter tactic that is equally unlogical. You can use soldiers that have not been marked to form a wall. Hiding behind them will deny line of fire and prevent sniping. Not sure about grenades though.

There might be a way to improve the logic of the Scout/Sniper behaviour. Have two different types of target awareness. Targets that have actually been spotted this round behave as is now. The second class is targets that are marked but out of sight. These get handled differently by the AI.
Possible differences:
- Less likely to shoot, more likely to use grenade/explosive.
- Grenades targeted not on actual location but on the tile where the spotting occured / last known location.
- When a night mission, throw flare at the location.
- More accuracy penalty (shooting blindly into the dark).

If the AI can throw flares at you it would be more logical and even more dangerous.

I have no idea what the code looks like, please forgive me if I make suggestions that are impossible to implement.

Offline Meridian

  • Global Moderator
  • Commander
  • ***
  • Posts: 6761
  • OXCE developer
    • View Profile
    • My Wiki
Re: [Documentation] Scout/Sniper AI
« Reply #7 on: July 19, 2018, 01:28:29 pm »
I can think of a counter tactic that is equally unlogical. You can use soldiers that have not been marked to form a wall. Hiding behind them will deny line of fire and prevent sniping. Not sure about grenades though.

Sniper is not limited to sniping only (based on modder's decision).
They can just as easily shoot at your living wall.

There might be a way to improve the logic of the Scout/Sniper behaviour. Have two different types of target awareness. Targets that have actually been spotted this round behave as is now. The second class is targets that are marked but out of sight. These get handled differently by the AI.

That's exactly how it is implemented.
And it is up to the modder to decide the weight for type 1 and type 2.

I have no idea what the code looks like, please forgive me if I make suggestions that are impossible to implement.

Already implemented this way... unless there's a bug of course.

Offline Ronios

  • Sergeant
  • **
  • Posts: 16
    • View Profile
Re: [Documentation] Scout/Sniper AI
« Reply #8 on: December 23, 2020, 11:32:22 am »
After 2.5 years, I would like to draw your attention once again to the fact that this feature, although it works as intended, is absolutely at odds with the logic. We're talking about night missions in XCF. I perfectly understand that I can hide my people behind walls / stones, etc. But there are a lot of situations when there is a bare field around and it is impossible to hide physically.

Option one: The rat came under the light of a flashlight on the ground and ran away 20 meters from this place on the same turn. This was noticed by the spotter and at the enemy turn, without flashing or detection, it is completely unknown where the sniper kills the rat.
Option two: Any hit on an enemy marked "spotter", as described above, automatically makes a target out of the character. Only the death of the spotter(but not always) can stop this madness and using grenades that don't triggering reaction.

I managed to see many other points and understood well how it works. Don't you think it's better to use not the "current position of the character" in any situation, but to write down the coordinates of where the target was last seen or where the shot was fired from?

You can say that I can change the settings so that the opponents will stop shooting in the dark and will only be at a visible target at the moment, and you will be right. I can do that. But this does not change the fact that this mechanic is initially built on strange logic. In general, I think the possibility that opponents will shoot at the places from where my agents were shooting is very natural and interesting and I don't want to lose that cool mechanic.

I beg you, please reconsider the approach to this feature and make it a pleasant and interesting and not annoying (especially for ironman)

As an option, you can show all opponents who hit and did not kill the agents, for several turns at any point on the map, for honesty, so to speak ;D.
« Last Edit: December 23, 2020, 01:45:59 pm by Ronios »

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1904
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [Documentation] Scout/Sniper AI
« Reply #9 on: December 23, 2020, 03:43:10 pm »
As I've said in other threads on the same topic, no. I am not going to neuter this feature to make it "more enjoyable", "more realistic", or "more logical". It fits within the logic of the current AI and how it behaves. I want to leave it as a tool for modders to provide challenge where previously there was just advantage to the player. It should be dangerous to deal with open fields and make you pause to consider whether to advance or retreat/abort.

To specifically answer you point about marking a location - this opens up the feature to be more exploitable. In your example with the rat, changing the feature to your suggestion means that you can tie up all snipers on the map indefinitely shooting at a light by just showing your rat then running it away every turn.