OpenXcom Forum

Modding => OpenXcom Extended => OXCE Suggestions DONE => Topic started by: ohartenstein23 on August 28, 2017, 03:44:59 pm

Title: [Documentation] Scout/Sniper AI
Post by: ohartenstein23 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:

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:

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 (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.
Title: Re: [EXE] Scout/Sniper AI
Post by: ohartenstein23 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:


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.
Title: Re: [EXE] Scout/Sniper AI
Post by: mumble 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...
Title: Re: [EXE] Scout/Sniper AI
Post by: Meridian 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
Title: Re: [Documentation] Scout/Sniper AI
Post by: Eddie 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?
Title: Re: [Documentation] Scout/Sniper AI
Post by: ohartenstein23 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.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Eddie 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.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Meridian 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.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Ronios 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.
Title: Re: [Documentation] Scout/Sniper AI
Post by: ohartenstein23 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.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Juku121 on December 21, 2021, 11:35:24 am
And it is up to the modder to decide the weight for type 1 and type 2.
Does this reference the 'sniper: XX' chance? Because if so, I don't think it quite addresses the original question which essentially asked about having two different sniping behaviours, not two different behaviours for snipers.

If Meridian indeed meant two different sniping patterns, I'd be very interested to know how that works. Or worked, if it's been changed before or after.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Vakrug on June 10, 2023, 03:39:16 pm
After searching for a while about how exactly Spotter/Sniper mechanics works, I stumbled upon this post. Since Spotter/Sniper mechanics is very counterintuitive, I was hoping at least here get a definitive answers.

This post will remain for documentation.
Sorry for rudeness, but this is very crappy documentation. Nothing in the first post indicates that a soldier gets spotted if it hits a spotter! Even after some discussion about this in the next posts. Do you think that it is such a small and insignificant detail, that is is not worth mentioning?

So what exactly makes a soldier being spotted by a spotter? There are lot of rumors out there, I will list some of them:
Title: Re: [Documentation] Scout/Sniper AI
Post by: Juku121 on June 10, 2023, 05:48:06 pm
Does killing a spotter ends "being spotted"? Or a spotter needs to be "one shoted"? Or is it just a rumor?
Rumour.

Does hitting a spotter with a grenade prevents being spotted? What about mortars? What about rocket launchers? What
about "rocket missed a target, but hit a wall, so a target still get damaged"? Is there other "silent" methods to kill?
Generally, yes. To be spotted for snipers, you need to either 1) be 'seen' or 2) be hit with a 'projectile'. Rockets and mortars count, if they hit the enemy first. Grenades do not.

In practice, it's quite difficult to predict with precision what will and won't happen, especially since there is also the 'spotted' flag that follows somewhat different rules but can invite a spotter over, including enemies dying over several turns from bleeding; the general difficulty of determining whether an enemy sees your troops, or indeed knowing what kinds of things your opponent can or cannot see (psi-vision, night vision, heat vision, camo on either party, etc).
Title: Re: [Documentation] Scout/Sniper AI
Post by: Vakrug on June 10, 2023, 07:29:23 pm
To be spotted for snipers, you need to either 1) be 'seen' or 2) be hit with a 'projectile'.
So is it safe to kill with melee weapons (from behind, of course)? What about flamethrowers? I am not sure do they shoot projectiles or not.

If only this mechanics was better documented (including in game), so much interesting things could be done, like "silent" weapons (shurikens or spy pistols, for example) that don't cause being spotted.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Juku121 on June 10, 2023, 08:10:14 pm
Melee kills are 'safe' in the sense that if you kill an unaware spotter, that won't spot you for snipers. He/she/it will still spot you for regular AI when dying, no matter how sneaky you were. Never mind that stealthing up to an enemy and remaining unseen after the kill are no small feats.

If you mean XCF flamethrowers, they're basically short-range grenade launchers, and the sheet of flames is a projectile. Given how close you need to be and how inaccurate the weapon is, I'd guess it'd be an exercise in frustration trying to stay unsnipered by using one to kill enemies 'silently'.

No idea if other mods are different.

The whole engine isn't really setup for combat stealth, UI included. So while I share your frustrations regarding the sniper-spotter mechanic, this lack of stealth isn't really 'vanilla' sniper-spotter's fault.

I think Finnik's fork had some more stealth mechanics? And Xilmi's AI of course has its own spotting system, which specifically excludes this 'hit and get spotted' feature.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Vakrug on June 10, 2023, 09:10:05 pm
All right, the conclusion to all of this is if you want to remain unseen -- don't shoot, use grenades!

So while I share your frustrations regarding the sniper-spotter mechanic, this lack of stealth isn't really 'vanilla' sniper-spotter's fault.
It is not the mechanics itself is what I am frustrated about. It is the developers attitude: "AI will cheat, but we will not tell players about that! Players will never find that out, just feels more challenges!"

Oh, do you know how I was frustrated while playing Civ6? There are megabytes of civilopeadia articles about game mechanics and NOT A SINGLE WORD about what affects difficulty level and how construction time increases with each unit/building built! And this is not the most sinister example...
Title: Re: [Documentation] Scout/Sniper AI
Post by: Scamps on June 10, 2023, 09:22:45 pm
AI will cheat, but we will not tell players about that

Piratez show whether your unit is spotted for some armors. So there is technical possibility, but no one has done a mod yet.

Edit: That's how I learned that hitting a spotter counts ;-)

If you meant documentation, not ingame, your concern is valid. Just dont be too harsh on developers. Documentation being the last thing in development cycle is pretty common. Some projects don't have any :)
Title: Re: [Documentation] Scout/Sniper AI
Post by: Vakrug on June 10, 2023, 11:27:25 pm
Just dont be too harsh on developers. Documentation being the last thing in development cycle is pretty common.
The first post of this thread supposed to be the documentation. It is literally written there! And yet it is so misleading, that I guess it is done by purpose. Was it so hard to add something like "hitting spotter with projectile also reveals"? Especially after the discussion.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Meridian on June 10, 2023, 11:43:44 pm
Sorry for rudeness, but this is very crappy documentation. Nothing in the first post indicates that a soldier gets spotted if it hits a spotter! Even after some discussion about this in the next posts. Do you think that it is such a small and insignificant detail, that is is not worth mentioning?

It is not documented there, because it was not added in this feature.
Marking the shooter as spotted when hitting the enemy has been in the game since 1994.

Some details here (offset 8 ): https://www.ufopaedia.org/index.php/UNITPOS.DAT

Do you think that it is such a small and insignificant detail, that is is not worth mentioning?

It's definitely a significant detail.
But I don't see a need to document something that is (or should) be documented elsewhere already.

Nothing in the first post indicates that the spotter may die or fall unconscious if it is hit :)
Should we have documented that as well?

It is not the mechanics itself is what I am frustrated about. It is the developers attitude: "AI will cheat, but we will not tell players about that! Players will never find that out, just feels more challenges!"

Barking up the wrong tree here.
I don't like it either, but I won't remove it, because it is vanilla.
Go take the argument with Julian.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Vakrug on June 11, 2023, 12:47:13 am
Marking the shooter as spotted when hitting the enemy has been in the game since 1994.
:o That is a really big news to me!
Now I have more questions and some old questions should be repeated.
So, what I understood from the UNITPOS.DAT article, is that "being spotted BY REGULAR alien" allows psi attack, but not regular attacks. And with this new Scout/Sniper AI it is possible to "be spotted by A SPOTTER" and that will open door for shooting and grenade throwing, am I right?
Also it looks like damaging alien with a grenade opens door for psi attacks, but not shooting even if that alien was a spotter.

Now I hate unstructured and unsearchable articles in ufopaedia.org even more...
Title: Re: [Documentation] Scout/Sniper AI
Post by: psavola on June 11, 2023, 07:26:59 am
As already noted, I believe the "vanilla spotting" feature - which depends on the intelligence values - is something very different than scout/sniper feature, because in vanilla the enemy units can't shoot at you unless they have personally obtained a vision at you on that specific turn (but they can do PSI attacks and I believe blaster launcher shots as well, but I don't think it applies to grenades).

There was extensive discussion and testing on sniper/spotter mechanics in XCF thread recently (https://openxcom.org/forum/index.php/topic,8199.msg155034.html#msg155034) and Juku who made a lot of tests summed it up pretty well here. I'll mention the thread here for the references and more detail. My XCF playtesting also confirms it that throwing grenades (provided that instant grenades is turned off) does not trigger "spotting", and I have used the tactic of throwing a lot of grenades and intentionally not shooting anyone who is a "spotter" for the first 10 turns or so, a very viable tactic in certain missions where there are a lot of spotters and snipers (where, in addition to shooting, the snipers are also very liable to throw grenades at you). If you just throw grenades, from the cover of darkness and/or smoke, neither the spotters or snipers can do anything against you unless they personally come close enough to spot my troops - otherwise you would get bombarded with dozens of shots and grenades.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Meridian on June 11, 2023, 09:33:03 am
As already noted, I believe the "vanilla spotting" feature - which depends on the intelligence values - is something very different than scout/sniper feature, because in vanilla the enemy units can't shoot at you unless they have personally obtained a vision at you on that specific turn

Not sure what to tell you, but just try shooting a Muton into the back with a pistol... he will turn around and shoot back at you without ever seeing you.

So, what I understood from the UNITPOS.DAT article, is that "being spotted BY REGULAR alien" allows psi attack, but not regular attacks.

It allows psi attacks and launcher attacks without LOS.

It doesn't allow normal attacks without LOS.

But it's not "useless", the alien AI can and does use the "spotted" flag for decision making. For example to set up an ambush, etc.
(Don't ask how, I won't have the time or patience to explain.)

And with this new Scout/Sniper AI it is possible to "be spotted by A SPOTTER" and that will open door for shooting and grenade throwing, am I right?

With Scout/Sniper turned on, the snipers are allowed to shoot/grenade the scouted targets also without LOS.
That's the only difference (and the heart of this feature).

Now I hate unstructured and unsearchable articles in ufopaedia.org even more...

@everybody: Xcom is complex, more complex than you know. No matter how much you know, or how much you think you know, you always know less than 20%. Btw. I am no exception to this rule. No one is. The sooner you accept this, the sooner you'll be able to play and enjoy this game without losing hair.
Title: Re: [Documentation] Scout/Sniper AI
Post by: Meridian on June 11, 2023, 09:39:28 am
Piratez show whether your unit is spotted for some armors. So there is technical possibility, but no one has done a mod yet.

Edit: That's how I learned that hitting a spotter counts ;-)

If you meant documentation, not ingame, your concern is valid. Just dont be too harsh on developers. Documentation being the last thing in development cycle is pretty common. Some projects don't have any :)

Just FYI, before someone asks, those armors indicate the classic vanilla spotted flag.

There is no possibility to indicate the scouted flag yet.
(but it would be trivial to add such support)
Title: Re: [Documentation] Scout/Sniper AI
Post by: Vakrug on June 11, 2023, 10:05:34 am
@everybody: Xcom is complex, more complex than you know. No matter how much you know, or how much you think you know, you always know less than 20%. Btw. I am no exception to this rule. No one is. The sooner you accept this, the sooner you'll be able to play and enjoy this game without losing hair.
Again...  ::)
You walk into scientific library and noticed that all books are scattered completely randomly. Some books hide inside other books, some are hidden in almost inaccessible corners. And when you ask a libraryman how to navigate in all of this and where is table of content, libraryman answers with "science is a complex thing!" then turns around and sacrifices few animals to the statue of Wikipedia...
Title: Re: [Documentation] Scout/Sniper AI
Post by: Nord on June 22, 2023, 07:53:48 am
Sorry if i use wrong topic.

A question: if sniper/spotter algorithm allows aliens to shoot from afar, will it work for melee enemy, allowing them to move to spotted non-visible prey?
Title: Re: [Documentation] Scout/Sniper AI
Post by: Meridian on June 22, 2023, 09:47:01 am
A question: if sniper/spotter algorithm allows aliens to shoot from afar, will it work for melee enemy, allowing them to move to spotted non-visible prey?

No, there is no such functionality implemented atm.