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: 4419
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

Now we're off to the last folder, "###_Team Behaviour_Teams Lost"

The purpose of these scripts is to alter counters when teams fail and die. Like the last folder, these scripts follow a very predictable pattern.

Number 1: (Again, you should know where these are... if not, it's a little test :p)

TYPE: [SAnd][ENH]
NAME: "###_B_TLB_Tanks"
              
Code

*** IF ***
    True.
*** THEN ***
Add 1 to counter '###_TLB_Tanks'
Add 1 to counter '###_TL_Overall'
Reduce the AI priority forTeam '<This Team>' by its Failure Priority Decrease amount.


I'm hoping that by now you're getting a hang of scripting and can tell what a script does quite quickly. This script adds to loss counters and makes the team less important to the AI. This is part of the system that makes the AI choose where to attack and with what to use.

Of course, you can't just have the TLB (which stands for Team Lost Back), you need Centre and Flank too... so, duplicate this twice and alter the one single letter you need to :p

              
Code

...
Add 1 to counter '###_TL#_Tanks'
...


Okay, now we're done with our Tanks, but what about Troops? It's time to hit that copy button again! Three more duplicates, and this time replace the "Tanks" with "Troops".

Once you have your six scripts, it's time to go up a folder to "###_Team Behaviour_Sequential Scripts"

Here we have the orders that teams will execute when they're built. The scripts consist of a pair. One, the _BO_ (Build Orders) one is what the team is told to do once built, and it tells to team to execute another script sequentially (_BS_ Build Sequential)... So: (Actions in Scripting/Flags and Team/SequentialScript)

TYPE: [SAnd][ENH]
NAME: "###_BO_Generic_Attack Back"
              
Code

*** IF ***
    True.
*** THEN ***
Set Flag named '###_INFANTRY BUILDING' to FALSE
Set Flag named '###_VEHICLE BUILDING' to FALSE
Team '<This Team>' executes Script '###_BS_Generic_Attack Back' sequentially.


Paired with: (Actions in Skirmish Only/Move and Team/Attack)

TYPE: [SAnd][ENH]
NAME: "###_BS_Generic_Attack Back"
              
Code

*** IF ***
    True.
*** THEN ***
Have Team '<This Team>' move to the start of enemy path 'Backdoor'.
Have Team '<This Team>' approach the enemy using path 'Backdoor', as a team is TRUE
Team '<This Team>' attack anything in area '[Skirmish]EnemyInnerPerimeter'


Okay, the first script tells the AI that it's free to start building other things, and that the team should execute the second script sequentially. Sequentially means it carries out the first action, then the second, then the third, and so on... So, the team will move to the start of the Backdoor path, then move along it, then attack anything inside the enemy base.

Now, this is only the scripts required for a generic team to attack the back, so you need duplicates of both of these for Centre and Flank too! Get copying!

Time for some more copying too... you'll need to make BO scripts for both tanks and troops, for Back, Centre and Flank too... so that's another 6 scripts... However, all you need to change is which flag is set to false, the teams can still use the Generic BS script... So here's two examples:

TYPE: [SAnd][ENH]
NAME: "###_BO_Tanks_Attack Back"
              
Code

*** IF ***
    True.
*** THEN ***
Set Flag named '###_VEHICLE BUILDING' to FALSE
Team '<This Team>' executes Script '###_BS_Generic_Attack Back' sequentially.


TYPE: [SAnd][ENH]
NAME: "###_BO_Troops_Attack Flank"
              
Code

*** IF ***
    True.
*** THEN ***
Set Flag named '###_INFANTRY BUILDING' to FALSE
Team '<This Team>' executes Script '###_BS_Generic_Attack Flank' sequentially.


Right, now we're getting into the really really tedious parts of making the AI, and as such I'm going to leave it here for this part. There should be 3 folders left that contain no scripts, and these 3 will contain by far the most. The build conditions are the mountain of scripts that tell your AI when to build squads of units. My Only War Cadian Hard AI has 65 of these buggers...

Save!

Return to top