Dynamic AI Planning

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
KnightsFan
Second Lance Corporal
Second Lance Corporal
Posts: 108
Joined: Fri Mar 06, 2009 9:34 pm

Dynamic AI Planning

Post by KnightsFan »

My problem is that I want my AI to go after different objectives at different times during my campaign map. Somehow, they always manage to go the opposite direction leaving me facing hordes of blood-thirsty droids. Is there a way to either 1. Activate/deactivate barriers, 2. Do the same for planning hubs or connection or 3. Inexorably force the AI to attack a certain region?

Thanks.
Xavious
Sith Master
Sith Master
Posts: 2783
Joined: Mon Jun 12, 2006 3:46 pm

Re: Dynamic AI Planning

Post by Xavious »

Try these:

Code: Select all

BlockPlanningGraphArcs("ConnectionName");
DisableBarriers("BarrierName");
UnblockPlanningGraphArcs("ConnectionName");
EnableBarriers("BarrierName");
They're in the shipped Mustafar map; it's how they make sure the AI don't try to run across the bridge when it's out.
User avatar
KnightsFan
Second Lance Corporal
Second Lance Corporal
Posts: 108
Joined: Fri Mar 06, 2009 9:34 pm

Re: Dynamic AI Planning

Post by KnightsFan »

Yay! Thanks! But why do you have ";" at the end of each one? Does that actually do anything in LUA?
Edit: The AI are walking straight through the barrier now... and I didn't disable it yet :faint:
RepSharpshooter
Gametoast Staff
Gametoast Staff
Posts: 1351
Joined: Tue Jul 10, 2007 4:10 pm

Re: Dynamic AI Planning

Post by RepSharpshooter »

Are they following a path through the barrier? if so, disable that connection with lua as well.
FragMe!
Gametoast Staff
Gametoast Staff
Posts: 2244
Joined: Sat May 13, 2006 12:34 am
Projects :: Not sure keep changing my mind.
Games I'm Playing :: F1 and SWBF
xbox live or psn: No gamertag set
Location: Origin name GT_FragMe
Contact:

Re: Dynamic AI Planning

Post by FragMe! »

Here is something from PsychoFred's site (which is a good source of information the link can be found in the FAQ)
Hidden/Spoiler:
gtw 6-17-05

Lua functions for scripting the AI in the mission scripts:

*******************************************************************************
- ClearAIGoals( team )

Removes all previous AI goals for this team. You should call
this before you set the first goals for a team, since teams 1, 2, and 3
start out with a default Conquest goal.

for example:
ClearAIGoals( 1 )


*******************************************************************************
- DeleteAIGoal( goalHandle )

Remove the specified goal. goalHandle is the handle returned by AddAIGoal.

for example:
DeleteAIGoal( handle )


*******************************************************************************
int AddAIGoal( team, goaltype, weight )
int AddAIGoal( team, goaltype, weight, target1 )
int AddAIGoal( team, goaltype, weight, target1, target2 )

Add an AI goal for this team. Returns a handle to the new goal.


goaltype can be one of these:

"Conquest" - plays like BF1 on the command posts
AddAIGoal( team, "Conquest", weight );

"Deathmatch" - just kill everyone
AddAIGoal( team, "Deathmatch", weight );

"Destroy" - destroy the target (a gameobject pointer, or a character index)
AddAIGoal( team, "Destroy", weight, gameObjectPtr );
AddAIGoal( team, "Destroy", weight, integerChrIdx );

"Defend" - defend the target (a gameobject pointer, or a character index)
AddAIGoal( team, "Defend", weight, gameObjectPtr );
AddAIGoal( team, "Defend", weight, integerChrIdx );

"CTFOffense" - try to get the specified flag and bring it back to the specified region
AddAIGoal( team, "CTFOffense", weight, regionName );
AddAIGoal( team, "CTFOffense", weight, regionName, flagPtr );

"CTFDefense" - protect the specified flag, and hunt down and return it when its stolen
AddAIGoal( team, "CTFDefense", weight );
AddAIGoal( team, "CTFDefense", weight, flagPtr );

"Follow" - follow around the target (like defend, but uses a tight follow)
AddAIGoal( team, "Follow", weight, gameObjectPtr);


Weight is a relative weight for this goal. Since you can specify more than one goal
for a team at a time, this specifies how the guys are divided. A goal with weight 2
will get twice as many guys as the goal with weight 1. The size of the numbers doesn't
matter and they don't have to add up to 100 or anything.

The goals for Conquest and Deathmatch don't require a target, since
they figure that out automatically. When you give a Defend, Destroy,
or CTF goal, it has to know what object you want to atttack or protect.

for example:

ClearAIGoals( 1 )
AddAIGoal( 1, "CTFOffense", 50, GetRegionName(team1captureregion) )
AddAIGoal( 1, "CTFDefense", 50 )
ClearAIGoals( 2 )
AddAIGoal( 2, "CTFOffense", 25, GetRegionName(team2captureregion) )
AddAIGoal( 2, "CTFDefense", 50 )
AddAIGoal( 2, "Destroy", 25, sheldBunkerObjPtr )

This will set up a CTF game with half of team 1's guys on offense and half on
defense. Team 2 will have half their guys on defense, a quarter on offense, and
a quarter trying to destroy the shield bunker (a GameObject). Once they kill that it will
automatically rebalance the remaining goals so that 1/3 of the guys are on ctf offense
and 2/3 are on ctf defense.


Or you can specify flags:

ClearAIGoals( 1 )
AddAIGoal( 1, "CTFOffense", 30, GetRegionName(team1captureregion), team2FlagAPtr )
AddAIGoal( 1, "CTFOffense", 30, GetRegionName(team1captureregion), team2FlagBPtr )
AddAIGoal( 1, "CTFDefense", 40, team1FlagCPtr )

This will send some guys to get 'FlagA' and return it to 'team1captureregion', some
other guys to get 'FlagB' and return it there, and the other 40% will defend their
own flagC.


Destroy and Defend can specify GameObjects or Character indices:

ClearAIGoals( 1 )
AddAIGoal( 1, "Defend", 100, 0 )
ClearAIGoals( 2 )
AddAIGoal( 2, "Destroy", 50, 0 )
AddAIGoal( 2, "Destroy", 50, atatPtr )

This sets up all of team 1 to defend Character(0), which is the player. Here you could also
put the index of a special character (ie Leia or anyone) you spawn in somewhere. Team 2 is
set to kill Character(0) (the player again) and also destroy the ATAT specified by atatPtr.
User avatar
KnightsFan
Second Lance Corporal
Second Lance Corporal
Posts: 108
Joined: Fri Mar 06, 2009 9:34 pm

Re: Dynamic AI Planning

Post by KnightsFan »

I already knew about most of those, FragMe. They don't seem to work very well.

Code: Select all

AddAIGoal(ATT, "Conquest", 100, "cp4")
...And about 4/80 AI head the opposite direction of CP4.

Code: Select all

AddAIGoal(DEF, "Defend", 100, "cp4")
AddAIGoal(ATT, "Conquest", 50, "cp4")
...And I find myself fighting fighting the entire CIS force (ATT) yet my buddies (DEF) only occasionally try to support me.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Dynamic AI Planning

Post by Frisbeetarian »

Keep in mind that the number you use doesn't matter, as long as the AI only have one objective per team.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Dynamic AI Planning

Post by [RDH]Zerted »

KnightsFan wrote:...why do you have ";" at the end of each one? Does that actually do anything in LUA?...
; are optional in Lua. I believe you can use them to put more than one command on the a single line (but I didn't look that up to be sure). Example:

Code: Select all

x=5; why=7; y="no reason"
Post Reply