Help with AI

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

Moderators: winston, another_commander

Post Reply
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Help with AI

Post 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
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
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: Help with AI

Post 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.
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post 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

Code: Select all

"TRAVEL_ON_SIGHT_OF_PLAYER" = { 
*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
        ); 
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
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 »

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.
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post 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 :D
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
Post Reply