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

AI message fun

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

Post Reply
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

AI message fun

Post 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.
User avatar
Roberto
---- E L I T E ----
---- E L I T E ----
Posts: 318
Joined: Sun Jun 11, 2006 1:16 pm
Location: London, UK

Post 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".
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post 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.
User avatar
Roberto
---- E L I T E ----
---- E L I T E ----
Posts: 318
Joined: Sun Jun 11, 2006 1:16 pm
Location: London, UK

Post 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.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post 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?
Post Reply