NPC ship "jousting" in v1.74.2 and v1.75 trunk

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

Moderators: winston, another_commander, Getafix

Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Switeck »

I'm often seeing NPC ships "jousting" with each other...where they fire until they score a hit, then turn away to open up the range, then turn and fire again till they score 1 hit, then turn away again and open up the range.
The damage inflicted adds up so slowly that neither will die unless something else interrupts them.

I'm guessing this is due to a glitch-in-the-logic bug.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Commander McLane »

This is part of the AI behaviour and has been there forever.

I think it's a problem of getting too close to each other. In this case the AI seeks to bring some distance between itself and the opponent, and while doing so nothing else happens. It's also the reason why NPCs don't fire very often during fights with the player.

It's the AI behaviours FLY_TO_TARGET_SIX and FLY_TO_TARGET_TWELVE which I find are kept for too long.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Smivs »

That probably explains why getting really close is so effective :evil:
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Eric Walch »

Switeck wrote:
I'm often seeing NPC ships "jousting" with each other...where they fire until they score a hit, then turn away to open up the range, then turn and fire again till they score 1 hit, then turn away again and open up the range.
The attack code itself is never looking for laser beams hitting a target. The attack will proceed for hits and misses on the same way. It is probably pure coincidence that ships retreat after scoring a hit. Probably because they were close already.

Only the receiving end can react on a hit. But that sounds logic when being hit. Fights going on and on is probably planned. 50% of the ships use target_twelve attacks. These ships are very inefficient in their attacks and often fail to kill their target. I think it is written that way to leave ships in the game for the player to deal with :D (When you spawn two ships in one command, you will in most cases have one ship of both categories because bahaviour is based in ID nr)

What also can go on indefinitely is one ship in attack_from_target and the other in attack_to_target. It is hardcoded that the "to" ship never flies faster than the "from" ship. And the code was written so that they can lock up in this situation just outside of laser range.
In my build I changed this for some months that the "to" ship will fly up to 5% faster than the "from" ship. That way they will eventually come in each others fire range and have a shootout so that at least one can return to its normal business.
But that would mean that also the player can not flee indefinitely for a stronger ship. That means a significant change in game behaviour, I didn't want to add, although I personally would like it.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Switeck »

Eric Walch wrote:
The attack code itself is never looking for laser beams hitting a target. The attack will proceed for hits and misses on the same way. It is probably pure coincidence that ships retreat after scoring a hit. Probably because they were close already.

Only the receiving end can react on a hit. But that sounds logic when being hit. Fights going on and on is probably planned.
Some pirates and traders do "break off" after scoring just 1 hit on their chosen target. It is definitely keyed on them scoring a hit rather than BEING hit. They open up the distance, then turn and fire again. If they fail to score a hit, they risk ramming and then pass each other. And that's why I call it "jousting"...because I have on rare occasion seen them ram each other. ...And probably contributes to NPC ships ramming the player as well.

For all I know, it could be that opening the distance becomes "top priority" after scoring a hit on an enemy ship.

Code: Select all

- (void)actOnInstincts	// set ship behaviour from most urgent instinct
{
	if (most_urgent_instinct)
	{
...
				if (urgency > most_urgent)
				{
					most_urgent = urgency;
					most_urgent_instinct = instincts[i];
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by JensAyton »

Switeck wrote:

Code: Select all

- (void)actOnInstincts	// set ship behaviour from most urgent instinct
{
	if (most_urgent_instinct)
This code is unused. It’s part of an incomplete AI rewrite that Giles was working on before he quit. (This applies to everything related to OOBrain and OOInstinct.)
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Switeck »

Where should I refer to then for ai logic?
I'll root out what's causing what I'm seeing if only I knew where to look. :lol:
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by JensAyton »

At the level you’re interested in, most of the action is in the behaviour_foo methods in ShipEntity.m.

Note that any big changes will fall foul of the feature freeze and won’t be accepted before MNSR.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Eric Walch »

Switeck wrote:
Where should I refer to then for ai logic?
I'll root out what's causing what I'm seeing if only I knew where to look. :lol:
As Ahruman writes, it is all in the various behaviour_foo code starting about at line 2940.

Just a big -- SPOILER ALERT-- Once you have read those lines and start to understand them, combat is no longer what it was!
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Switeck »

Since I'm using wordpad in windows, I don't even have a clue what line number I'm on.
But I did text searches for FLY_TO_TARGET_SIX and FLY_TO_TARGET_TWELVE which were mentioned earlier.
Nothing jumps out at me as the cause of the behavior I'm seeing. :?
User avatar
CheeseRedux
---- E L I T E ----
---- E L I T E ----
Posts: 827
Joined: Fri Oct 02, 2009 6:50 pm

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by CheeseRedux »

Switeck wrote:
Since I'm using wordpad in windows, I don't even have a clue what line number I'm on.
http://notepad-plus-plus.org/
"Actually this is a common misconception... I do *not* in fact have a lot of time on my hands at all! I just have a very very very very bad sense of priorities."
--Dean C Engelhardt
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Switeck »

Oolite v1.75 beta Jousting match.zip
http://www.mediafire.com/?81jvdx88u43jhrj

These series of pictures shows how NPC ships (in particular, the Cobra 3) will "joust" -- once it scores 1 hit, it turns away, opens range, turns back again, fires till it gets 1 hit, then turns away again. :(
The short txt file is a clip of the log showing the AI attack states the 2 NPC ships are in.

I'll be attempting to decipher the source code again...though it still looks very alien to me, totally different than script.js code. :(
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Eric Walch »

Switeck wrote:
These series of pictures shows how NPC ships (in particular, the Cobra 3) will "joust" -- once it scores 1 hit, it turns away, opens range, turns back again, fires till it gets 1 hit, then turns away again. :(
The short txt file is a clip of the log showing the AI attack states the 2 NPC ships are in.
In a few pictures I see what you describe. But knowing that part of the code I am pretty sure that ships don't react on their own hits. A shame you are not on a mac. The target inspector is an excellent tool for debugging this kind of behaviour. It could be that the attacking ship is in behaviour_attack_target_twelve. In that case it aims for a position of 1250 meter above the target. But with a random desired_range of 750 to 2000 meter it can still mean that it heads directly to the target, when the target is so stupid to fly in the line of fire. The attacking ship will not change course as long at the position of 1250 meter above the target is still within the desired range. But than, then the target is hit, the target rolls and the position above the target moves strongly so that is leaves the desired_range. This forces the attacker to reset its course. But that is not a reaction of the hit, but a reaction of course alteration of the target. Although this would not explain a full turn away.

I'll take a lookout for such npc-npc behaviour. In understanding this it is very important to know the exact behaviours of both ships. And with the mac target inspector, you can follow that live on two floating windows.

It looks a bit like:
Image
On the left you see two windows associated with the trader and on the right the same two belonging to the pirate.

I followed above two ships. With this pair I also see what you witnessed. I now think I know what happens. The attacking ship is in target_twelve mode, not able to get a shot on the ship. Keeping an eye on the frustration level, I see a steady increase of frustration. When frustration hits 10, the attacker randomly re-evaluates its tactic and frustration is set back to zero. Sometimes this change of tactic means flying away. But the firing of a ship happens fully independent of the tactic: Anytime a target appears directly in front, the ship can fire.

So on carefully following the jousting, I see frustration hit its maximum, the ship is turning and during this turn, the target passes his front and he fires while retreating. So he is not retreating after a hit, but he retreats and makes a hit while retreating.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by Eric Walch »

I did another search in the code, because my above explanation can't explain it fully. When the frustration hits 10 seconds it changes tactics, but only between the three ATTACK_TO variants. And the ship goes into a ATTACK_FROM mode. So I dove a bit deeper. Lucky enough there are only five places were BEHAVIOUR_ATTACK_FLY_FROM_TARGET is set. Four immediately fell off leaving one other in the friendly fire check.

Code: Select all

if ([hunter group] == group || (iAmTheLaw && uAreTheLaw))
Populator added pirated are part of a "wolfpack" group, but script added pirates can have a null group. And that happens here. Both groups are equal because both groups are null. A bit higher in the code there is a check for group != nil but this one also needs that check.
The friendly fire check only examines ships in BEHAVIOUR_ATTACK_FLY_TO_TARGET. So, the BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE ship gets frustrated, switches to BEHAVIOUR_ATTACK_FLY_TO_TARGET, scores a hit and immediately goes into BEHAVIOUR_ATTACK_FLY_FROM_TARGET.

Jousting solved now and I update the code accordingly.
Last edited by Eric Walch on Sun Feb 20, 2011 12:52 pm, edited 2 times in total.
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8515
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Re: NPC ship "jousting" in v1.74.2 and v1.75 trunk

Post by DaddyHoggy »

Eric Walch wrote:
Switeck wrote:
These series of pictures shows how NPC ships (in particular, the Cobra 3) will "joust" -- once it scores 1 hit, it turns away, opens range, turns back again, fires till it gets 1 hit, then turns away again. :(
The short txt file is a clip of the log showing the AI attack states the 2 NPC ships are in.
In a few pictures I see what you describe. But knowing that part of the code I am pretty sure that ships don't react on their own hits. A shame you are not on a mac. The target inspector is an excellent tool for debugging this kind of behaviour. It could be that the attacking ship is in behaviour_attack_target_twelve. In that case it aims for a position of 1250 meter above the target. But with a random desired_range of 750 to 2000 meter it can still mean that it heads directly to the target, when the target is so stupid to fly in the line of fire. The attacking ship will not change course as long at the position of 1250 meter above the target is still within the desired range. But than, then the target is hit, the target rolls and the position above the target moves strongly so that is leaves the desired_range. This forces the attacker to reset its course. But that is not a reaction of the hit, but a reaction of course alteration of the target. Although this would not explain a full turn away.

I'll take a lookout for such npc-npc behaviour. In understanding this it is very important to know the exact behaviours of both ships. And with the mac target inspector, you can follow that live on two floating windows.

It looks a bit like:
Image
On the left you see two windows associated with the trader and on the right the same two belonging to the pirate.

I followed above two ships. With this pair I also see what you witnessed. I now think I know what happens. The attacking ship is in target_twelve mode, not able to get a shot on the ship. Keeping an eye on the frustration level, I see a steady increase of frustration. When frustration hits 10, the attacker randomly re-evaluates its tactic and frustration is set back to zero. Sometimes this change of tactic means flying away. But the firing of a ship happens fully independent of the tactic: Anytime a target appears directly in front, the ship can fire.

So on carefully following the jousting, I see frustration hit its maximum, the ship is turning and during this turn, the target passes his front and he fires while retreating. So he is not retreating after a hit, but he retreats and makes a hit while retreating.
AI fascinates me - mainly because I do not understand it very well (although my MSc Thesis was on Neural Networks but very different from finite-state machines) and would like too (for example the "doctrinally correct" AI in ModSAF is particularly irksome and rarely does what you want it to do and is also a FSM. So, knowing what the behaviour of the two AIs are and therefore understanding why they're doing it - does that give you any clue of whether the behaviour is right - and if it's not - does it give you any clue of how to improve it?

EDIT: Ninja'd by Eric's speedy code diving! :wink:
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
Post Reply