Page 1 of 2

Too many Friendlies at Korolov Station

Posted: Sun Dec 27, 2009 7:27 pm
by infomaniac50
I'm having a problem with the AI Ships not wanting to undock from the Korolov Shipping station. None of the docked ships are freighters. They look like station defenders. There are many other ships waiting to dock as well. See image escort a palooza. enemy ships always seem to fly by the station on their way to somewhere else so i'm not sure if the station has just called in too many reinforcements.

Posted: Sun Dec 27, 2009 8:23 pm
by Aury
I had that same problem

And yes, I do beleive it is related to calling too many reinforcements.
It's even worse when one of those light IAV's gets killed by you when you are trying to kill the enemies at the station: because then all the defenders turn on you! (that early on, a bunch of centurions, let alone that mob of escort ships, will simply slaughter the player)

Re: Too many Friendlies at Korolov Station

Posted: Wed Dec 30, 2009 12:54 am
by george moromisato
infomaniac50 wrote:I'm having a problem with the AI Ships not wanting to undock from the Korolov Shipping station. None of the docked ships are freighters. They look like station defenders. There are many other ships waiting to dock as well. See image escort a palooza. enemy ships always seem to fly by the station on their way to somewhere else so i'm not sure if the station has just called in too many reinforcements.
Are you using any mods? What are those Molotoks doing there? What system are you in? If you've got a save file that reproduces the problem, I'd love to see it.

Posted: Wed Dec 30, 2009 10:08 pm
by infomaniac50
There are no mods on the RC version I run. As for the molotoks I'm not sure I think one of them is docked at the station. The system is Kaus Media. I've uploaded the save file here.

Posted: Thu Dec 31, 2009 11:34 pm
by Aury
oh yeah, same thing for me: no mods, just plain rc3

Posted: Thu Dec 31, 2009 11:37 pm
by Song
I'm using the G.O.D Mod.....and it happens to me as well. Not just Korolev, either. Friendly stations in general have too many ships docked.

..I once had to use the wonderful "Cause Havoc" button to clear up dock spaces, once. Generally I spawn a corsair to get them off, but it's really annoying. :evil:

Posted: Fri Jan 01, 2010 4:24 am
by george moromisato
infomaniac50 wrote:There are no mods on the RC version I run. As for the molotoks I'm not sure I think one of them is docked at the station. The system is Kaus Media. I've uploaded the save file here.
Thanks, the save file helps.

Unfortunately, I still can't figure out the problem. I've added some debug code so that hopefully I the next time it happens I can get more info. Meanwhile I've added code to Korolov to free up docks when needed.

Thanks!

Posted: Fri Jan 01, 2010 4:32 am
by Aury
Thanks ^^
those empty docking ports will be sorely needed ^^

(actually, I think all stations should have that)

Posted: Fri Jan 01, 2010 4:45 am
by Atarlost
It might be a good idea to hardcode the AI no never dock unless there are two open ports, always leaving the last for the player.

Posted: Sat Jan 02, 2010 3:28 pm
by Aury
Atarlost wrote:It might be a good idea to hardcode the AI no never dock unless there are two open ports, always leaving the last for the player.
mission ship docking would need to force the station to undock a ship. i think it should be managed station-side, not ship-side

Posted: Wed Jan 06, 2010 3:36 am
by george moromisato
This bug has had me worried recently. It was first reported in RC1:

http://www.neurohack.com/transcendence/ ... php?t=2426

But with infomaniac50's post and an email from Kris Parker I was able to narrow it down to a single point in the code.

In the Korolov code, when a freighter docks with Korolov, there is code that takes the escorts from the freighters and tells them to guard Korolov. The code is very simple (and made simpler below for readability):

Code: Select all

(enum (sysFindObject aObjDocked "sO:escort") theEscort
   (block Nil
      (shpCancelOrders theEscort)
      (shpOrder theEscort "guard" gSource)
      )
   )
sysFindObject returns all the ships that are ordered to escort aObjDocked (which is the freighter that just docked). We then enum over that list and tell the escorts to guard gSource (Korolov). Simple as can be.

The symptom that I was getting was that sometimes, under some conditions that I could not reproduce, sysFindObject was returning way more objects than just the ones that were escorting the freighter.

Once that happened, all those ships were ordered to guard Korolov.

But why was sysFindObject failing?

The fact that the problem only happened sometimes and the fact that savefiles never reproduced the problem meant to me that it had to be something in temporary memory (not something that's saved out with objects). Somehow memory was being corrupted.

Memory corruption is the scariest bug there is. There is no telling where it originates. A bug in some part of the code could be corrupting memory in a completely different part. The sympton that you see could be totally unrelated to the root of the problem.

I despaired for a bit, but there there two clues that made me feel better: (1) the bug only happened in sysFindObject--if some other part of the code were corrupting memory, then we would get all sorts of strange crashes. (2) Other uses of sysFindObject were working fine--it was just this particular case that seemed to fail sometimes.

After stepping through the code line by line for a while, I finally found it:

Notice that the criteria in the code above does not have a semi-colon at the end of the word 'escort':

(sysFindObject aObjDocked "sO:escort")

The code that parsed the criteria would correctly parse the word 'escort' but, expecting a semi-colon, would continue parsing the string past the end-string character. Once it got past the end of the string, it started parsing whatever garbage it found until it found another end-string character.

Most of the time, it would find the end-string character quickly and no harm would be done. But sometimes, depending on the state of temporary memory, it would find characters that altered the sense of the query.

In particular, if it found another 'O' character it would assume a new order, and if it couldn't understand the order, it just assumed any order. In other words, the criteria was being changed to find any ship with any order (not just the ones escorting the freighter).

This turned out to be a very serious bug. There were other parts of the game that had omitted the ending semi-colon--though it showed up most in Korolov because the query is run so often.

In RC5, I've fixed the code so that sysFindObject behaves properly. I feel a lot better.

Posted: Wed Jan 06, 2010 4:30 am
by alterecco
Oh man,

I wish I had been paying attention to this earlier...

I have several times run into this behaviour, just in completely different cases. As a result I always end all my criteria with semi-colons...

Will try to be more attentive in the future. I would have liked to be able to help with this one...

Posted: Wed Jan 06, 2010 5:17 am
by Prophet
Coincidentally, we were talking about ending semicolons in criteria strings in IRC just a few days ago. Perhaps we should add a reminder to the function help on Xelerus to prevent further occurances of this bug?

Posted: Wed Jan 06, 2010 5:27 am
by george moromisato
Prophet wrote:Coincidentally, we were talking about ending semicolons in criteria strings in IRC just a few days ago. Perhaps we should add a reminder to the function help on Xelerus to prevent further occurances of this bug?
That certainly wouldn't hurt. But I've fixed the specific problem in RC5.

I'm also considering allowing spaces as a delimeter. Thus:

(sysFindObject aObj "s O:escort +Ares")

The downside is that it means that attributes cannot have spaces (which, I think is OK).

What do you all think?

Posted: Wed Jan 06, 2010 5:52 am
by Atarlost
I think everyone so far has assumed attributes couldn't have spaces anyhow.