Page 1 of 1

AI message fun

Posted: Sun Mar 16, 2008 9:21 am
by JensAyton
I just noticed a small wart: there are two AI messages called EXITED_WITCHSPACE and EXITED WITCHSPACE, used in different contexts. The underscored one is sent by addShips: and the system repopulator (which replaces ships that witchspace out with new ships with the same primary role, to keep the population of traders etc. constant). The other is sent by wormholes. Only the latter is used by built-in AIs, but the former was listed in the rather out-of-date AIReference.html. I can see three options here:
  • Leave it as it is.
  • Change the EXITED_WITCHSPACE to EXITED WITCHSPACE.
  • Send both in the place that now sends EXITED_WITCHSPACE.

Posted: Sun Mar 16, 2008 10:29 am
by Roberto
I've found "EXITED WITCHSPACE" useful for giving a ship instructions which should only apply when it's emerged from witchspace (not when it's just been added to a system), so I'd like to retain the distinction. Maybe the other message should be something like "JUST ADDED", though.

*EDIT* To clarify, by "emerged from witchspace" I mean "arrived in a system as a result of an in-game witchspace journey".

Posted: Sun Mar 16, 2008 10:59 am
by Eric Walch
I would say option 2. Just send "EXITED WITCHSPACE", the one that is in Pirate AI. I think it saves a lot of future confusion.

I have been playing a lot with those messages and never got it right. Now I start to see why. I saw "EXITED WITCHSPACE" in the pirate AI and tried to use it in a special trader that created its own wormhole. I looked in the code and saw that such a ship did sent a "EXITED_WITCHSPACE" but it never worked as I probably used the one without underscore that I copied from the pirateAI.

I now search for the buoy to detect if the ship was re-spawn near the witchpoint.

Posted: Sun Mar 16, 2008 11:06 am
by Roberto
That will screw my new AIs, though :( How else could I (or anyone) give a ship different instructions if it's not in its "home system"?

Even if the names are left as they are, as long as this is documented on the Wiki, I think it'll be OK.

Posted: Sun Mar 16, 2008 2:04 pm
by Eric Walch
Roberto wrote:
That will screw my new AIs, though :( How else could I (or anyone) give a ship different instructions if it's not in its "home system"?
Roberto, I think you are right.

For a version 1.70+ only there is no problem when you use the function performHyperSpaceExitWithoutReplacing, but when staying compatible with older versions one only can use: performHyperSpaceExit.

This function results in the current ship appearing in the next system with the message "EXITED WITCHSPACE" and simultaneously an other ship with the same role appears at the witchpoint of the current system with message "EXITED_WITCHSPACE".

Changing names completely would ruin backward compatibility. For a trader like ship it won't matter if both messages are the same. But for special missionships, the copy should act as it were a new ship (what it is) and the jumping ship should act as the original ship when interacting with the player.

Meaning: leave it as it is but make sure it is documented well. I now noticed that neither message was mentioned on the wiki with the performHyperSpaceExit command. I had never noticed there was a difference resulting in AI's not working as intended.

EDIT:
Is "EXITED_WITCHSPACE" working at all? In the past I have tried to use it, but I never succeeded in catching the message "EXITED_WITCHSPACE". I just tried it again with the new knowledge. Only for the original ship that jumped the "EXITED WITCHSPACE" is detected. Can it be that the code is wrong? When I look at the code:

Code: Select all

[ship leaveWitchspace];				// gets added to the universe here!
[[ship getAI] setState:@"GLOBAL"];	// must happen after adding to the universe!
[ship setStatus:STATUS_IN_FLIGHT];	// or ships may not werk rite d'uh!
In the part [ship leaveWitchspace] the message "EXITED_WITCHSPACE" is send. But than the command [[ship getAI] setState:@"GLOBAL"] is getting a new AI and setting it in the global state. Can it be that the message gets lost in this process?