Project Perfect Mod Forums
:: Home :: Get Hosted :: PPM FAQ :: Forum FAQ :: Privacy Policy :: Search :: Memberlist :: Usergroups :: Register :: Profile :: Log in to check your private messages :: Log in ::


The time now is Thu Mar 28, 2024 11:15 pm
All times are UTC + 0
How to Make an AI for your Mission Map
Moderators: Generals Moderators, Global Moderators
Post new topic   Reply to topic Page 1 of 1 [1 Post] Mark the topic unread ::  View previous topic :: View next topic
Author Message
DaFool
Defense Minister


Joined: 07 Nov 2006

PostPosted: Sat Sep 25, 2010 11:41 pm    Post subject:  How to Make an AI for your Mission Map Reply with quote  Mark this post and the followings unread

How to Make an AI for your Mission Map

This is advanced tutorial.
If you haven’t already, please read this tutorial: http://www.ppmsite.com/forum/viewtopic.php?t=28488

Step 1: Making it Testable.
So you already have your map set up with all the terrain, textures, and any units/structures/etc you want already pre-placed.  The first thing you are going to want to do is go to Edit->Edit Player List.  This allows you to control some basic aspects of who is on the map, what color everyone is, and most importantly, who is computer controlled.  You want every player that is not the player to be computer-controlled, thus allowing the actual (human) player to be able to play as the right army in the mission.  If you have not already added your map to your mod, it will appear in the Custom Map section of the Skirmish Game menu, and will work exactly the same.

Generals does let you make missions in which the Player can be any faction he wants, all you need to do is add a normal player start waypoint, and add a player to be human in the Player List.  This is done in the General’s Challenge mode.

Step 2: Making Pre-Placed Objects Smarter
Depending on how you designed your mission, you may have plenty of pre-placed units lying around.  To make them more useful, you should up the aggressiveness level on them by click on them and then increasing their aggressiveness level in the object properties window.  If you are using several units from factions other than who the opponent is suppose to be (say you want a laser tank to be under the command of the air force general your mission is about) you can change the team here also.  You can also give units special names that you can reference in scripting, or add them to custom teams (which allows you do a lot of things very simply via scripting).

When I make a mission, I like to make each difficulty a little different qualitatively, so often I add extra pre-placed objects such as defensive structures and add them to a custom team called ‘hard team’.  I can then make a script that on easy and medium difficulties will remove all the units from the playing world that are a part of that team.

Step 3: Basic Scripting

There are many things you can do with map scripting, from cinematic intros to precisely controlling a single unit’s behavior, but this tutorial is about adding AI, so I’ll tell you about that.  The first thing you are going to want to set up is the diplomacy settings, so that everyone isn’t allied at the beginning of the game.  

Create a new script, with the condition of “If True” and the Action if True condition “Player->Alliances->Change how Players relate to other players”.  You can then how one player considers another player (as Friend, Neutral, or Enemy).  You should do this so that all the players involve have how they treat each other defined.

Another important script to set up is the Victory Condition, which can vary in so many ways.  Its up to you to decide what the victory conditions are, but the example I’ll give is that of eliminating the enemy from the map.  You’re IF condition should be “Player->Destroyed->All Units and Buildings Destroyed” Which the enemy player defined.  Your THEN condition will be “Multiplayer->Announce Victory”.  The IF condition is completely up to you, be creative.

Step 4: Setting up the AI

Now with what amounts to the beginning and the end of the mission out of the way, lets start focusing on the AI.  You are going to want it to be able to produce units, so you’ll need a script where the Script Condition is ‘True’ (or when a timer expires if you are making an intro) and the Then statement is “Player->Build->Player is Able to Produce Units/Buildings” Where the player is defined as you AI’s faction.

Generals allows you to create sets of Attack Priorities that the AI will use.  This involves two parts; defining the units and setting the attack priorities for each object type.  The script that defines the units has the condition of “True” and the THEN of “Scripting->ObjectTypeList->Add Object Type”.  You can Define the Object Type List however you want, usually its something general like “infantry” or can be more specific like “heroes”.  So create an object type, and then you’ll want to add a unit to this type.  So you click where it says ‘add’, and then choose an object from the list.  You’ll need to do this for all the objects the human player can build, and define several general categories (infantry, vehicles, structures, aircraft, etc).  Use the copy button to save time.  You will then want a script to set the attack priorities.  Again, the condition is ‘True’, and the then statement will be “Attack Priority Set->Create Set->Modify a set’s priority for a single unit type”.  Define a new attack Priority, then for the Object Type, go down to Object Lists, and select one of the Object Types you had previously defined.  You can then select a numerical value for the priority that the AI will use when determining what to attack.  I usually have the numbers go from 1-100.  You should then define how the Attack Priority treats each object type.

You can create several sets of Attack Priorities if you want the AI to have say, Anti-Infantry squads that go around with a high attack priority against infantry, and a reduced priority against others.

You will need to create Conditions for the AI’s teams.  This will let the AI know when they can start building various teams that have a certain Condition.  You usually have the Condition go into effect right away (With an IF of ‘True’) or after a timer has expired, or you can be creative (perhaps when the human player has units cross into a certain area).  The Ifs may vary, but the THENs will all be null operations.  Usually I make Conditions for Guard Team start right away and attack waves come later on.

You must also create waypoint paths that the AI’s teams will use to navigate to the enemy.  You can also create looped paths for guard teams.  Make as many paths as you wish to use, and label them accordingly (Attack Path 1, Flank Attack 1, Guard Path 1, ect etc).  You should also create a waypoint that will be used as a rally point by your teams to meet up (because the members of the team can be coming from different production places).

Step 5: Creating Teams

This is the part where the bulk of the work is done creating exactly how the AI will attack.  There’s two basic types of teams you should be creating now; Guard Teams and Attack Teams.  Select the AI player and create a new team.  You can now define what units you want in the team, name the team, and enter in a few important things.  You can set the ‘Home Position’ to the waypoint I spoke of above that is placed where you want the units to initially go.  You can set the Condition to whatever Condition you defined early that tells the AI when to start building this Team.  You can also set the priority for this team.  You can pretty much create as many teams as you want, each representing either a guard team or an attack wave.

Step 6: Scripting the Teams

Once you have created your fill of teams, go back to the scripts.  You should now make scripts for you various teams.  The conditions should all be ‘True’.  The THENs will vary.  For your scripts, the first then will define which attack priority the team that will be using this script shall use, and the second will define how the team behaves.  So first you will have “AttackPrioritySte->ApplySet->Apply A Team’s Attack Priority Set” Define the team as “this team” and you whichever Attack Priority set that you wish to use.  Secondly, you will define how the tea will behave.  Your really have many options, but for the sake of this tutorial, I will have the team follow a waypoint path.  Go to “Team->Move->Set to Follow a Waypoint Path” Define the Team as the one which you want to use this script, and the waypoint path that the team shall follow.  You have the option of whether you want to team to move together, which I suggest you do.  Make scripts for all your teams.

Go back to your teams and select one of them.  Click on the behavior tab, and you now select which scripts the team uses.  For the On Create Script, select the corresponding script.  While on the Behavior tab, you can also edit the aggressiveness of the team.  If you want the team to stop and attack units while it is moving along the waypoint path, up the aggressiveness.  

Step 7: Your Move!

You have now completed the basics of mission AI and your AI will now attack as competently as you made it.  World Builder Scripting gives you a lot of options, and you can customize your AI as much as you want to.


EDIT:  It should be noted that the scripts which are Conditions for Teams and Behavior scripts for Teams should have the script option 'subroutine' checked and 'deactivate after success' unchecked.


Key Words: #Tutorials #Mapping #Generals #ZeroHour #WorldBuilder 

_________________
Please, read the signature rules of the forum.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [1 Post] Mark the topic unread ::  View previous topic :: View next topic
 
Share on TwitterShare on FacebookShare on Google+Share on DiggShare on RedditShare on PInterestShare on Del.icio.usShare on Stumble Upon
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © phpBB Group

[ Time: 0.1531s ][ Queries: 11 (0.0098s) ][ Debug on ]