Actions

Special:Badtitle/NS100:AI Scripting

From Populous Wiki

Revision as of 00:54, 14 December 2007 by Dan (talk | contribs)

What is a script?

A script is a set of instructions that Populous: the beginning reads and uses to command the computer controlled players.

Each level can have up to 3 scripts used at once, for each tribe respectively.

A script must also have an accompanying attribute file, which stores the default values for all internal_attribute_variables and the restrictions on buildings/spells similar to a header file used to set default restrictions for the player; I find it easier to simply set them all ON and simply not include them in the script if you do not wish the AI to use them. There is a built-in tool to do this on this scripter.


A script can be as simple as the following:


<syntax lang="popscript">

{

IF ( INT_MY_NUM_PEOPLE < 10 ) { DO GIVE_UP_AND_SULK ON } ELSE { SET INT_ATTR_EXPANSION 50 } ENDIF

} SCRIPT_END


</syntax>


Populous cannot read that and utilise it to control the AI so you need a compiler to compile it to the correct format, and stored in files such as cpscr010.dat (located in the …Bullfrog\Populous\levels directory)

The compiler we will be using for this tutorial is World Editor’s compiler, and can be found here. This also includes an attribute file editor, but as I have already stated – this is not really necessary. You will also need a plain text editor (such as notepad) to edit the scripts in their decompiled form.



A basic script layout

<syntax lang="popscript"> { IF ( INT_GAME_TURN == 0 ) { // set starting attributes

SET INT_ATTR_EXPANSION 50 SET INT_ATTR_MAX_BUILDINGS_ON_GO 5 SET INT_ATTR_HOUSE_PERCENTAGE 20

} </syntax>

This part is triggered as soon as the level starts (game turn 0)

And is usually used to set up initial attributes and anything else that has to be done immediately on level start.

<syntax lang="popscript">

ELSE { // rest of script

DO CONVERT_AT_MARKER 10 DO SPELL_ATTACK INT_ANGEL_OF_DEATH 10 -1

} ENDIF

} SCRIPT_END


</syntax>

Everything else that you need to do is put in this area.


Variables

<syntax lang="popscript">

INT_GAME_TURN </syntax>

is an internal game variable and cannot be changed by the script – it is however changed by populous as the game progresses and can still be referenced to in order to trigger things, which is what happens initially at the start of the level with most scripts.


<syntax lang="popscript">INT_ATTR_EXPANSION</syntax> is an internal attribute variable and be changed by the script and controls the ai’s behaviour throughout the level. You can tell it is an attribute variable as it starts with INT_ATTR.


To change an attribute you use the SET command like this:

SET Internal attribute Variable constant/user variable


Exemplar: <syntax lang="popscript"> SET INT_ATTR_EXPANSION 10 SET INT_ATTR_EXPANSION $var1 </syntax>


User Variables

There is also another type of variable which you can create yourself, a limit of 64 possible. They start with the dollar sign prefix ($) and may contain indentifiers, constants, internal attribute variables or internal game variables.


Exemplar:

<syntax lang="popscript"> SET $var1 INT_BLAST SET $var2 INT_MY_NUM_PEOPLE SET $var3 10 SET $var4 INT_M_SPELL_BLAST_COST </syntax>