Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Investigating gratuitous police attacks

For test results, bug reports, announcements of new builds etc.

Moderators: another_commander, winston, Getafix

Post Reply
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Investigating gratuitous police attacks

Post by dybal »

Those gratuitous police attacks have become more frequent...

I put a lot of traces in oolite-priorityai.js and in OOJSShip.m, and yesterday when I got attacked by police out of the blue I've got this in the Latest.log:

Code: Select all

21:38:10.130 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Considering branch with 9 entries, target:None
21:38:10.130 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Considering: entry 0
21:38:10.130 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Considering: entry 1
21:38:10.130 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Conditions met
21:38:10.130 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Executing behaviour
21:38:10.364 [dybal.trace]: OOJSShip, GalCop Sheriff: FIR483-QU1 target set to player  <== this one attacked me later
21:38:10.365 [dybal.trace]: OOJSShip, GalCop Viper: SGJ299-QU1 target set to player
21:38:10.631 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Considering branch with 9 entries, target:None
21:38:10.631 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Considering: entry 0
21:38:10.632 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Considering: entry 1
21:38:10.632 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Conditions met
21:38:10.632 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Viper Interceptor: MHY368-QU1: Executing behaviour
<...>
21:38:29.806 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Sheriff: FIR483-QU1: Considering branch with 9 entries, target:Adder: Fool's Bait
21:38:29.806 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Sheriff: FIR483-QU1: Considering: entry 0
21:38:29.807 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Sheriff: FIR483-QU1: Considering: entry 1
21:38:29.807 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Sheriff: FIR483-QU1: Conditions met
21:38:29.807 [oolite-libPriorityAI]: dybal: AI 'Oolite Police AI', configurationAcquireCombatTarget: GalCop Sheriff: FIR483-QU1 already have player ship as target
21:38:29.807 [oolite-libPriorityAI]: _reconsiderList: AI 'Oolite Police AI', GalCop Sheriff: FIR483-QU1: Executing behaviour
21:38:29.807 [oolite-libPriorityAI]: dybal: AI 'Oolite Police AI', behaviourDestroyCurrentTarget: GalCop Sheriff: FIR483-QU1 asks for help against player
21:38:29.807 [oolite-libPriorityAI]: dybal: AI 'Oolite Police AI', responseComponent_standard_helpRequestReceived: GalCop Sheriff: FIR483-QU1 adds player ship to defense targets due to help request from GalCop Sheriff: FIR483-QU1
21:38:29.807 [dybal.trace]: OOJSShip.ShipAddDefenseTarget, adding player ship to GalCop Sheriff: FIR483-QU1 defense targets
21:38:29.807 [dybal.trace]: addDefenseTarget: GalCop Sheriff: FIR483-QU1 (police) added player as defense target
21:38:29.808 [oolite-libPriorityAI]: dybal: AI 'Oolite Police AI', responseComponent_standard_helpRequestReceived: GalCop Viper Interceptor: RBZ805-QU1 adds player ship to defense targets due to help request from GalCop Sheriff: FIR483-QU1
From the traces, this priority in oolite-policeAI was acted upon:

Code: Select all

        { // 1
            condition: ai.conditionInCombat,
            configuration: ai.configurationAcquireCombatTarget,
            behaviour: ai.behaviourDestroyCurrentTarget,
            reconsider: 5
        },
So condition: ai.conditionInCombat was true and the Viper already had the player ship as its target when that iteration of priorityAI started, so ai.configurationAcquireCombatTarget kept it and the behaviour got me attacked.

That leads to two questions:
  • a) Why the player ship became (and stayed) the Viper target: I didn't try to put traces in the core game for when the player ship becomes a ship's target, but I put something in OOJSShip.m for when that was done by a script, and some script assigned the player ship as the [Viper that started the attack]'s target 19s before the attack
  • b) Why conditionInCombat turned true then (the Viper patrol was attacking a fugitive for some time): looking at PriorityAIController.prototype.conditionInCombat, it would return true if the cached value (set in previous run of the same function) was true or if the alertCondition turned red. Since this condition occurs only in that entry in the priority list in the policeAI, any time that cache were initialized as true while the player was the ship's target would already have started an attack, so it must have been a change to red alert, but as far as I could see there was no direct attack on that ship
Right now my traces in priorityAI's _reconsiderList only output if the NPC is in scanner range of the player ship, I'm adding "anywhere if the player ship is the target" to the conditions and logging the distance to the player ship to see if I can get a clue on (b), but for (a) is it possible to get the JavaScript stack in the Objective C code? It would make far easier to locate the code and thus the circumstances that led to the player ship being the ship's target...
Last edited by dybal on Tue Nov 10, 2020 8:31 pm, edited 2 times in total.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6557
Joined: Wed Feb 28, 2007 7:54 am

Re: Investigating gratuitous police attacks

Post by another_commander »

What is a Galcop Sheriff?
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Investigating gratuitous police attacks

Post by dybal »

another_commander wrote: Tue Nov 10, 2020 2:20 pm
What is a Galcop Sheriff?
Yep!

EDIT: I misread it as "Was it a Galcop Sheriff" :oops: :cry:
Last edited by dybal on Tue Nov 10, 2020 8:22 pm, edited 1 time in total.
User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 523
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Investigating gratuitous police attacks

Post by Nite Owl »

another_commander wrote: Tue Nov 10, 2020 2:20 pm
What is a Galcop Sheriff?
From the Convoys OXZ. The leader in a GalCop Viper Convoy.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Investigating gratuitous police attacks

Post by dybal »

dybal wrote: Tue Nov 10, 2020 1:54 pm
  • b) Why conditionInCombat turned true then (the Viper patrol was attacking a fugitive for some time): looking at PriorityAIController.prototype.conditionInCombat, it would return true if the cached value (set in previous run of the same function) was true or if the alertCondition turned red. Since this condition occurs only in that entry in the priority list in the policeAI, any time that cache were initialized as true while the player was the ship's target would already have started an attack, so it must have been a change to red alert, but as far as I could see there was no direct attack on that ship
Right now my traces in priorityAI's _reconsiderList only output if the NPC is in scanner range of the player ship, I'm adding "anywhere if the player ship is the target" to the conditions and logging the distance to the player ship to see if I can get a clue on (b), but for (a) is it possible to get the JavaScript stack in the Objective C code? It would make far easier to locate the code and thus the circumstances that led to the player ship being the ship's target...
I looked at the code for changing into red alert in the core game and it looks like the Galcop Sheriff got in range of one of its escorts that was in an attack behaviour and that got it into red alert which made conditionInCombat true, and then it just kept its target (the player ship) in configurationAcquireCombatTarget. I put some traces in ShipEntity's realAlertCondition so I know the reason for the red alert next time it happens.

The changes in conditions for my traces in priorityAI's _reconsiderList might hopefully show why the player became a target in the first place next time it happens.

But if my guess about what happened is true, I think the ship's target should be null'ed in ShipEntity's realAlertCondition when the ship is "borrowing" trouble from its group peers and let priorityAi's configurationAcquireCombatTarget do its job from a clean slate.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6557
Joined: Wed Feb 28, 2007 7:54 am

Re: Investigating gratuitous police attacks

Post by another_commander »

dybal wrote: Tue Nov 10, 2020 8:51 pm
[...] and then it just kept its target (the player ship) in configurationAcquireCombatTarget.
The question here would be, why was the player the sheriff's target to begin with? Having a ship as a target means it was already designated as an enemy.

I would check what AI is the sheriff running on and see what conditions would make the player become its target,
User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 523
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Investigating gratuitous police attacks

Post by Nite Owl »

Do you have phkb's Bounty System OXZ installed? If you do it contains a piece of equipment called a Warrant Scanner. NPCs, including GalCops, can have this installed as well. What it does is scan nearby ships for outstanding warrants. The key here is that the ship being scanned must first be targeted. Perhaps you were targeted for such a scan then somehow that got switched by the AI into an attack. Why that switch was made is the unknown. Unless you have a Fugitive Level Bounty from another system sitting on your head. The Warrant Scanner also checks for those. You may be clean in the current system but listed as a Fugitive somewhere else. There is a security screen at GalCop aligned stations that allows you to check for such outstanding warrants, just in case you might have forgotten about them. GalCop, under the Bounty System, never forgets a Fugitive. Bounty System is part of my Ooniverse and the scans from NPCs and GalCops happen all the time. The difference being that they do not turn into attacks unless something is done on my part, like shooting at or colliding with a GalCop. No outstanding Bounties from anywhere on me, at the moment.
Last edited by Nite Owl on Thu Nov 12, 2020 2:29 am, edited 1 time in total.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Investigating gratuitous police attacks

Post by dybal »

The Galcop Sheriff AI is the oolite Police AI.

Yes, I would like to know why I was targeted... I still have to look at the lower priorities in the Police AI to see if there's anything there, but if there's the player ship wasn't in scanner range when it happened or I would have traces from the PriorityAI next to the trace from OOJSShip.m ... I was hoping there was a way to instrument OOJSShip to discover where the targeting came from, in case it wasn't from the priorityAI.

Yes, I have phkb's Bounty System OXP installed, and it crossed my mind I might have been targeted for a scan, but I was thinking more about an AI-mandated one done through the core game, but from a_c comment above the player ship wouldn't have to be made a target for that. I will look at that OXP code to see if it's NPC-enabled (that is, if anything is hooked into a ship script, usually through a shipSpawned event handler).

I just have done a broken Adder start in IronMan mode, I'm a single jump from Lave, so I'm pretty sure there aren't any out-system offenses... I just looked into the savefile and the BountySystem_Offences missionVariable isn't there, so no offenses.

This has been happening one or two times each game session... one of them involved a trader group instead of a police group: I was running from a group of pirates (IronMan and sold the Pulse laser for cash), saw a trader group, headed into their middle and then everybody was shooting at me... another looong run barrel rolling (manually) to the main station dragging dozens of hostiles along! But that happened before I started instrumenting code for it, so I don't have a log from the episode.
Last edited by dybal on Wed Nov 11, 2020 12:47 pm, edited 1 time in total.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6557
Joined: Wed Feb 28, 2007 7:54 am

Re: Investigating gratuitous police attacks

Post by another_commander »

If this happens once or twice per session, then please try a few sessions without any OXPs installed, because I do not recall this ever being a problem in the recent releases. It's best if we can exclude the case of a core bug.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6557
Joined: Wed Feb 28, 2007 7:54 am

Re: Investigating gratuitous police attacks

Post by another_commander »

And here is a cool trick. If you are on the test release of Oolite and are connected to the debug console, you can get a JS trace anywhere you like if you enter the keyword debugger; inside your script. For example:

Code: Select all

this.playerWillBuyNewShip = function(shipKey, shipyard_info, price, tradeIn)
{
	if ( shipyard_info &&
		price &&
		tradeIn)
	{
		log("playerWillBuyNewShip", "shipKey: " + shipKey + " shipyard_info: " + shipyard_info + " price: " + price + " tradeIn:" + tradeIn);
	}
	debugger;
}
produces:

Code: Select all

06:58:42.398 [playerWillBuyNewShip]: shipKey: asp_blue_white-PLAYER shipyard_info: [object Object] price: 377300 tradeIn:210000
06:58:42.398 [script.javaScript.debugger]: debugger invoked during AddOns.anon-script:
06:58:42.398 [script.javaScript.stackTrace]:  0 (../AddOns/Config/script.js:13) <anonymous function>
06:58:42.398 [script.javaScript.stackTrace]:     this: [Script "AddOns.anon-script" version (nil)]
06:58:42.398 [script.javaScript.stackTrace]:     tradeIn: 210000
06:58:42.398 [script.javaScript.stackTrace]:     price: 377300
06:58:42.399 [script.javaScript.stackTrace]:     shipyard_info: {...}
06:58:42.399 [script.javaScript.stackTrace]:     shipKey: "asp_blue_white-PLAYER"
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Investigating gratuitous police attacks

Post by dybal »

another_commander wrote: Wed Nov 11, 2020 7:04 am
And here is a cool trick. If you are on the test release of Oolite and are connected to the debug console, you can get a JS trace anywhere you like if you enter the keyword debugger; inside your script.
Thanks, a_c!

I didn't know about that, and it will come in handy to trace back the context of a priorityAI auxiliary function to the actual priority entry in the AI being run.
another_commander wrote: Wed Nov 11, 2020 5:44 am
If this happens once or twice per session, then please try a few sessions without any OXPs installed, because I do not recall this ever being a problem in the recent releases. It's best if we can exclude the case of a core bug.
I will try to cut back on the installed OXPs as much as possible for some game sessions, but I think I will have to keep some, like Space Crowds, since usually the events come in two categories: Space Crowds creates a pirate vs police scenario ahead of me as I torus, I'm decanted in scanner range of it and before I can get them away from scanner range it happens, or Space Crowds creates a pirate gang ahead of me as I torus, I'm decanted, they attack, I run to the nearest station dragging them with me, the station patrol engages them and then it happens.

There were events like that with 1.88 (it hasn't been one year yet since I discovered Oolite...), but my behaviour pattern then was different: I didn't lurk around a pirate vs police scenario to gather escape capsules and debris for $ (broken Adder start :P ), and I didn't run as much from trouble: nowadays, my Ooniverse has energy (EEU, NEU and energy grids) and defensive equipments (shields, shield boosters, shield equalizer and capacitors, shield cycler) functional for NPCs, which make the well kitted out NPCs from Shipversion OXP _much_ tougher and running is usually the best option... and I didn't use to bait the pirates into following me to a place where I could get someone else to engage them (GalCop stations and Deep Space Dredgers).

But we can't prove a negative: if it happens we would be certain there's a core game (priorityAI included) bug, but if it doesn't, we can't be certain there isn't and I simply wasn't able to trigger it in a reduced scenario.

I'm starting to look into SpiderMonkey docs to see if there's a way to trace back the calls to OOJSShip that set the player ship as the target of a police ship not engaged in the fray. Discovering who is doing that and understanding why it's doing that would be the best way of finding a way to correct this.
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Investigating gratuitous police attacks

Post by dybal »

I think I found it...

I tried to wrap OOJavaScriptEngine's OOJSDumpStack in a public method and used it in OOJSShip... it didn't exactly work, but generated a runtime exception:

Code: Select all

13:51:45.608 [dybal.trace]: OOJSShip, GalCop Viper Interceptor: SQK825-QU1 target set to player at 32103401.817554
13:51:45.772 [script.javaScript.exception.ooliteDefined]: ***** JavaScript exception (BountySystem_WarrantScanner 0.11): Error: Native exception: OOJavaScriptEngine(class) does not recognize dump_stack:
13:51:45.772 [script.javaScript.exception.ooliteDefined]:       AddOns/bountySystem-0.11.mod.oxz/Scripts/bountysystem_npcscan.js, line 100.
and that points to BountySystem OXP, as Nite Owl suggested!
User avatar
Milo
---- E L I T E ----
---- E L I T E ----
Posts: 466
Joined: Mon Sep 17, 2018 5:01 pm

Re: Investigating gratuitous police attacks

Post by Milo »

I've experienced the same thing, being attacked by police who are engaged in combat with someone else while I was minding my own business nearby (with clean legal status). I did a similar investigation to what dybal outlined, but I never found the root cause for why the police were targeting me.

It's good to know that if we change Bounty System OXP to avoid targeting the player while running a scan, that might prevent this from occurring, but I think a more robust fix would be to change police Priority AI so that it does not assume that just because the police are targeting a ship, that the target is an enemy. If the target has clean legal status, I think the AI should look for a new target. Attacking police always adds bounty (if I recall correctly?) so if the player is actually attacking the police, they would not have clean legal status.

Ironically, in Bounty System OXP, the police only scan the player if the player has clean legal status, so having a small bounty could actually be safer.
Post Reply