Building an AI

Tutorial for Generals Gen

Avatar of Calamity_Jones

Calamity_Jones

Category: Code
Level: Expert
Created: Wednesday July 29, 2009 - 7:24
Updated: Sunday October 11, 2009 - 8:10
Views: 4427
Summary: A step by step guide to building an AI for your mod.
Rating
  • Staff-
  • Members-
  • Average-

0 votes

Page 1 2 3 4 5 6 7 8
Original Author: Calamity_Jones

####Part 2####

Ok, lets start with the map you'll be working with. You'll need to make a map as follows: (Indeed, every map you use should have a basic trigger area order like this)

User image

TA means Trigger Area and WP means Waypoint. The asterix indicates things that are pre-named in worldbuilder, so if you make a trigger area, the name "OuterPerimiter1" will be available in a drop-down list. The map should be fairly large too, 500x500 with borders of 50 is what I used.

The names should all be exactly as they appear in the diagram, with the hashes replaced with the player numbers. MAKE SURE THAT NO TRIGGER AREAS CROSS EACH OTHER! This will cause you problems! You can have an area inside and area, but no area that has crossing boundaries.

Now, add a player called Skirmish[Faction Name], make them the side of the faction and computer controlled.

You should have 3 names in your player list now:

              
Code

(neutural)
PlyrCivilian="PlyrCivilian"
Skirmish[Faction Name]="Skirmish[Faction Name]"


Right, let's get going, whip up the script editor. You should see three folders named after their owning players. For now, we'll ignore the civilian player (we will later add music here), add a folder inside the folder named after your faction and call it "###_MASTER COUNTER" The hashes should be replaced with a prefix that is a shortening of your faction name. So, for The Cadians faction in Only War, I used CAD, thus making the folder: "CAD_MASTER COUNTER".

Continue to add folders inside the faction root until you have this:

              
Code

###_MASTER COUNTER
###_Base Building
###_Cash Supply
###_Generals Powers
###_Setup
###_World Status
###_Upgrade
###_E_Build Conditions
###_N_Build Conditions
###_H_Build Conditions
###_Team Behaviour
###_Team Behaviour_Combat Zone
###_Team Behaviour_Priorities
###_Team Behaviour_Sequential Scripts
###_Team Behaviour_Teams Lost


You may have noticed my naming system by now. I use a system of listing the role of something in its name, seperating sections with underscores. So, ###_ means it belongs to the ### faction. Team Behaviour_ means the folder relates to team behaviour, and _Teams Lost means it relates to scripts on the loss of teams. I suggest you stick to a similar system.

Right, we'll start with some basic building blocks.

Into the "###_MASTER COUNTER" folder, add a [nsAD][ENH] script called "###_MASTER COUNTER_Set To 1 Initial" leave the condition as IF True and add the action "Set counter to a value" under Scripting/Counters with the value "Set '###_MASTER' to 1". You should have:

              
Code

*** IF ***
    True.
*** THEN ***
Set '###_MASTER' to 1


Add three more scripts as follows: (The condition is in Scripting, at the top of the list in which true appears)

TYPE: [nsAnd][ENH]
NAME: "###_MASTER COUNTER_Set To 1"
              
Code

*** IF ***
    Counter '###_MASTER' IS Equal To 3
    *AND* Counter '###_TL_Overall' IS Equal To 10
*** THEN ***
Set '###_MASTER' to 1
Set '###_TL_Overall' to 0


TYPE: [nsAnd][ENH]
NAME: "###_MASTER COUNTER_Set To 2"
              
Code

*** IF ***
    Counter '###_MASTER' IS Equal To 1
    *AND* Counter '###_TL_Overall' IS Greater Than or Equal To 3
*** THEN ***
Set '###_MASTER' to 2


TYPE: [nsAnd][ENH]
NAME: "###_MASTER COUNTER_Set To 3"
              
Code

*** IF ***
    Counter '###_MASTER' IS Equal To 2
    *AND* Counter '###_TL_Overall' IS Greater Than or Equal To 6
*** THEN ***
Set '###_MASTER' to 3


These scripts are what controls the behaviour of the AI, hence their name of master counter. Essentially, It starts at 1. Once three teams of units it has made have died, the timer goes to 2, and the AI will send different units, then when it has lost 6 teams, it goes to 3, and once it's lost 10 teams, it goes back to 1. Of course, depending on the complexity of AI you want to make, you can add more counter states to make the AI do more interesting things and try different tactics. Mine for Only War has 7 states for example, for now though, we'll stick with 3.

Return to top