Page 1 of 1
Help with AI
Posted: Mon Nov 30, 2009 7:05 pm
by Rustybolts
What i am wanting to achieve is for the player to follow a ship defined in mission through a wormhole. For this to happen i think it would be best for said ship to only start its hyperspace on sight of player ship or maybe if it has been targeted by playership any thoughts on this and how would i achieve this?
Would it be best to create my own AI or use ExitingTraderAI
Code: Select all
{
"TRAVEL_ON_SIGHT_OF_PLAYER" = {
ATTACKED = (setTargetToPrimaryAggressor, "setStateTo: ATTACK_SHIP");
"DESIRED_RANGE_ACHIEVED" = ("setStateTo: EXIT_SYSTEM");
ENTER = (
setDestinationToCurrentLocation,
"setDesiredRangeTo: 1000.0",
performFlyToRangeFromDestination
);
"EXIT_SYSTEM" = {
ENTER = ();
EXIT = ();
UPDATE = (performHyperSpaceExit);
"WITCHSPACE OKAY" = ();
"WITCHSPACE BLOCKED" = (setTargetToFoundTarget, setDestinationWithinTarget, "setDesiredRangeTo: 10000.0", performFlyToRangeFromDestination);
};
Upon the target ship exiting from Witchspace i wish to change the AI to either pirate or trader haven't decided which. Would i achieve this in the ship script through.
switchAITo: pirateAI.plist ..............etc
I think mainly what i am after is a few pointers before i take the plunge with AI
Re: Help with AI
Posted: Mon Nov 30, 2009 10:21 pm
by Eric Walch
Rustybolts wrote:Upon the target ship exiting from Witchspace i wish to change the AI to either pirate or trader haven't decided which. Would i achieve this in the ship script through.
switchAITo: pirateAI.plist ..............etc
I think mainly what i am after is a few pointers before i take the plunge with AI
The easiest to do is start with a copy of parts from exitingTraderAI. Just remember: when the player follows, the current AI is restarted with the GLOBAL state, but with the waiting message: "EXITED WITCHSPACE".
That message can be used to change AI after the jump, like exitingTrader does with
Code: Select all
"EXITED WITCHSPACE" = ("switchAITo: enteringTraderAI.plist");
So you don't need the ship script for this AI switch.
Posted: Mon Nov 30, 2009 10:31 pm
by Rustybolts
Thanks for reply.
One question just to clarify things for me the GLOBAL state is this just the first "stack" in the AI.plist.
So in above code the GLOBAL state would be in stack
*edit* have just re-read page on wiki i now understand it to be that the GLOBAL state needs to be defined in the plist e.g using above code
Code: Select all
GLOBAL = {
ENTER = ("setStateTo: TRAVEL_ON_SIGHT_OF_PLAYER");
EXIT = ();
UPDATE = (); };
}
so GLOBAL is the first state a object with given AI will enter into from the AI stack.
Code: Select all
"TRAVEL_ON_SIGHT_OF_PLAYER" = {
ATTACKED = (setTargetToPrimaryAggressor, "setStateTo: ATTACK_SHIP");
"EXITED WITCHSPACE" = ("switchAITo: enteringTraderAI.plist");
"DESIRED_RANGE_ACHIEVED" = ("setStateTo: EXIT_SYSTEM");
ENTER = (
setDestinationToCurrentLocation,
"setDesiredRangeTo: 1000.0",
performFlyToRangeFromDestination
);
Posted: Tue Dec 01, 2009 11:21 am
by Eric Walch
Rustybolts wrote:Tso GLOBAL is the first state a object with given AI will enter into from the AI stack.
Yes, that is the one the system looks for to start things. You could do your stuff already in that state, but it is common practice to immediately jump to an other state in that enter to work in a state with a more descriptive name.
Just one warning.
performHyperSpaceExit adds a new ship with the same role at the current witch-space entry point. (don't confuse this with the jumping ship because that only appears in the other system after a jump). This is to keep the number of ships in the current system constant. It is mainly used for traders. For every trader that jumps out of the system near the station, another is added near the witch-space entry point.
For custom AI scripts this is often undesired and the use of
performHyperSpaceExitWithoutReplacing is better.
Posted: Tue Dec 01, 2009 4:35 pm
by Rustybolts
Eric Walch wrote:
Just one warning. performHyperSpaceExit adds a new ship with the same role at the current witch-space entry point. (don't confuse this with the jumping ship because that only appears in the other system after a jump). This is to keep the number of ships in the current system constant. It is mainly used for traders. For every trader that jumps out of the system near the station, another is added near the witch-space entry point.
For custom AI scripts this is often undesired and the use of performHyperSpaceExitWithoutReplacing is better.
Ah thanks for your help i didn't use performHyperSpaceExitWithoutReplacing because i thought if you follow this ship it wouldn't appear in next system. Many thanks