Most of the information here is for Warzone 3.1 and above.
WZScript language
Guide to scripting in the old WZScript language...
Introduction
Reminder: WZScript is being phased-out, you should be using Javascript API instead.
In order for Warzone scripts to function properly two files are required: a file with a .slo extension and a file with a .vlo extension.
A .slo file is the main part of the script and holds executable instructions while the .vlo file holds additional variable declarations necessary for the .slo file to function properly.
It is common for a script to deal with new or existing game components such as research topics, structures, unit bodies, propulsions, weapons etc. All these components are defined in appropriate text files like body.txt, structure.txt etc. If you want to use any of these components in your script - in your .slo file - like for example if you want to place certain structures on the map using scripts or enable certain research, you must first make these components available to your script by defining them in a .vlo file.
Roughly said a .slo file is equivalent to a ".c" file and .vlo to a header file in C/C++.
Specific skirmish/multiplayer notes:
Some of the file below does not apply to skirmish scripts! Make your changes to player0.slo and vlo -> player7.slo and vlo.
Comments
There are two type of comment for the script language. A multi-line comment is started by the characters /* and finishes with */. A single line comment is started by //.
Vlo files
When writing a script it is usually known what data (as defined in data .txt files, located in 'stats' folder) will be used in the script, so it is a good idea to start writing the script with a .vlo file.
Vlo files are structured as follows:
script "myScript.slo"
run
{
<variable_definitions>
}
In the first line a .slo file is attached to this particular .vlo file. variable_definitions that resides inside the curly braces is the heart of every .vlo file, it contains definitions of the data that will be used in the main script part - the .slo file. Each variable definition starts on a new line and is structured as follows:
<variable_name> <variable_type> <variable_value>
NOTE: Available data types are covered later.
For example if you want to have access to certain droid bodies, like "Python" in your script you have to define it in your .vlo file and assign it to a variable of type BODY with some descriptive name, like:
myPythonBody BODY "Body11ABT"
"Body11ABT" is an internal name of the "Python" body used by warzone, it is defined in the body.txt file. Since it is a string it must be put inside quotation marks. All components, be it some research, structure, droid template or a weapon is referred by its internal name in the game and are defined in the appropriate txt data files.
Each variable definition in a .vlo file starts on the new line and ends at the end of the line.
It is also possible to define arrays of some data type. For example if you want to use the following 3 research topics in your script you might want to define them like this:
myResearch[0] RESEARCHSTAt "R-Vehicle-Body11"
myResearch[1] RESEARCHSTAt "R-Vehicle-Prop-Tracks"
myResearch[2] RESEARCHSTAt "R-Vehicle-Prop-Hover"
This defines an array of size 3 of type RESEARCHSTAT.
Slo files
As already mentioned .slo file is the heart of every script, it is the place for the executable code. Slo files can be devided into 3 main parts:
Variable declarations
Event and function declaration
Executable code
Variables used throughout the script are defined in the Variable declarations part, with exception of the local variables, which are explained later.
For the .slo file to be able to access variables declared in the .vlo file they must be declared as public variables in the corresponding .slo file.
Coming back to the two examples above you will have to add following lines to the .slo file:
public BODy myPythonBody;
public RESEARCHSTAT myResearch[3];
Keyword public signals that the variable is defined in the corresponding .vlo files. Note that unlike in .vlo files variable declarations in .slo files end with a semicolon and unlike in .vlo files it is possible to declare more than one variable of the same type at once.
More generally a variable declaration in a .slo file looks like this:
<storage> <variable_type> <variable_name1> [, <variable_name2>, ...];
storage is one of public or private. public means that the variable is declared and defined in the corresponding .vlo file. private means the value is only used in the .slo file. Unlike local variables public and private variables are global variables that can be access from anywhere in the .slo file.
NOTE: All variables are initialized to their default values when created. STRUCTURE/DROID/FEATURE variables are initialized to NULLOBJECT, STRINGs to "", FLOATs to 0.0, INTs to 0, BOOLs to FALSE etc.
Event/trigger concept
In Warzone 2100 scripts executable code consists of events. An event is a list of instructions activated by some trigger attached to it. Event defines what to do, a trigger defines when to run an event, i. e. when to execute the code inside an event.
All events are structured as follows:
event <event_name>(<trigger>)
{
<code>
}
Example:
event myFirstEvent(every, 50)
{
console("Hello world!");
}
This piece of code will output "Hello world!" to the game console every 5 seconds. Note that triggers are put inside the round braces after the event name while code that is to be executed resides inside the curly braces. The syntax of the executable code is very close to the C/C++ syntax.
The only difference between a WZ event and a function as used in programming languages like C/C++ is that an event is not called or activated by another function, but rather by a trigger attached to it.
It is always possible to interrupt execution of an event with the exit keyword, which is a counterpart of the return keyword used for functions; exit keyword does not deactivate an event.
Example:
event myEvent(every, 10) //run every second
{
console ("this text will be printed every second");
if((gameTime / 10) > 60) //did more than a minute pass?
{
exit; //anything that comes after 'exit' will not be executed
console("this text will only get printed in the first");
}
}
Events must be defined before they can be referenced. If event definition comes after the place where this event is referenced it is necessary to declare this event beforehand in the event and function declaration section.
Events are declared like this:
event <event_name>;
Such a declaration reserves identifier used as event name.
Example:
event myEvent; //declaration of the event
...
// another event that references myEvent
event anotherEvent(wait, 10)
{
setEventTrigger(myEvent, inactive); //deactivate myEvent
}
...
// myEvent is defined after being referenced by anotherEvent,
// but it works, since we declared myEvent beforehand
event myEvent(wait, 20)
{
console("It all compiles, because I was declared beforehand!");
}
If myEvent was not declared before being referenced by anotherEvent then this example would not compile.
Triggers
In Warzone 2100 triggers are usually simple timers that repeatedly trigger execution of events, but triggers can also be callbacks (special events that occur in the game, like destruction of a building) that are listed and explained later.
Here are available trigger types:
Trigger type
Effect
wait, <time>
Run the event after delay <time>.
every, <time>
Run the event at every <time> interval.
<callback>
Run when callback occurs.
<bool exp>, <time>
Run the event if <bool exp> is true, checking every <time> interval.
init
Run the event when the script starts.
inactive
Do not run the event until a trigger is assigned to it.
NOTE: All time intervals are in 1/10 of a second.
For example every, 10 will trigger every second while wait, 50 will only activate once: 5 seconds after the game has started. If an event has inactive assigned as a trigger this event will never execute unless its trigger is reassigned by some other event with setEventTrigger(<event>, <trigger>) function.
NOTE: Complete function and callback listings are given below.
A few examples:
// 1. output text to game console every second
event everySecond(every, 10)
{
console("The game has started " + gameTime/10 + " seconds ago");
}
// 2. Code inside this event will never execute unless its event is reassigned later
event inactiveEvent(inactive)
{
console("Someone has just reactivated me!");
}
// 3. CALL_NEWDROID callback with parameters
event droidBuilt(CALL_NEWDROID, 5, ref newDroid, ref myFactory)
{
console("We got a new droid at coordinates " &
newDroid.x & "-" & newDroid.y);
}
In the last example droidBuilt event will be triggered everytime a factory belonging to player 5 produces a new droid. newDroid variable refers to the new droid that was just built and myFactory to the factory that build this droid. This example assumes that newDroid and myFactory were correctly defined in the variable declarations section. For more callbacks see Script function callbacks.
NOTE: ref keyword means that a pointer to the provided variable is passed to the interpreter, so that a callback can modify value of the variable.
It is possible to reuse a trigger for more than one event if a trigger is declared in the event and function declaration. Trigger declaration has following syntax:
trigger <trigger_name> (<trigger>);
Example:
trigger everySecond (every, 10); //trigger declaration
...
event eventOne(everySecond) // uses the trigger we declared above
{
...
}
event eventTwo(everySecond) // uses the trigger we declared above
{
...
}
In this example everySecond trigger is defined outside of an event. Such a trigger can be reused by its name. Note that trigger declaration ends with a semicolon.
Expressions
String expressions
Strings are put inside quotation marks: "some text inside quotation marks is a legal string".
Strings can be easily concatenated using the & operator.
For example: "String1" & "String2" will result in "String1String2".
Strings can be compared using == operator (case insensitive comparison) or strcmp() function.
Such data types as integers, booleans and floats are automatically converted to strings when it is required, so given the following variable declaration:
private float pi;
private int myInteger;
private string myString;
private bool myBool;
The following line is a valid string expression:
console("value of pi is " & pi & ", value of myInteger is " & myInteger & ",
value of myString is " & myString & ", value of myBool is " & myBool);
Numeric expressions
Numeric expressions are made up of int variables, numeric constants and functions that return int values, e. g.:
power * 32 - basePower
numDroids(player) + 5
The possible operators are: + - * /
Increment and decrement operators can only be applied to the integer variables outside of the expression context:
myInteger++;
myInteger--;
There are also a number of operators that compare numeric expressions to give a boolean
Operator
Meaning
<
Less than
>
Greater than
<=
Less than or equal
>=
Greater than or equal
==
Equal
!=
Not equal
Boolean expressions
Boolean expressions are made up of bool variables, the boolean constants TRUE and FALSE and game functions that return a boolean value e.g.:
not droidSeen and attackDroid
The possible operators are:
Operator
Meaning
bool1 and bool2
True if bool1 and bool2 are true
bool1 or bool2
True if at least one of bool1 and bool2 is true
not bool1
True becomes false and false becomes true
==
Can also be used with user defined type variables
!=
Can also be used with user defined type variables
Floating point expressions
Floating point expressions are very similar to integer expressions. There are some differences though: it is not possible to use increment/decrement operators with floating point variables. The integral and fractional parts of the float constant must be separated by a dot, even if fractional part is 0.
Examples:
myFloat = 1.0 + pi / 2.0 + 3.6;
Floating point expressions cannot be mixed with integer or boolean expressions. To use integers or booleans in floating point expressions they must be cast to FLOATs first.
For more information about casts refer to casts.
Assignment
The value of a variable or an expression can be assigned to another using the = character, e.g.:
currentDroid = foundDroid;
index = base + found * 4;
myString = "some text";
myFloat = 2.0 + pi / 2.0;
If statements
If statements are used to control which bits of code are executed. The simplest form is:
if (<bool exp>)
{
<code>
}
In this form if <bool exp> evaluates to true then the script code <code> is executed, otherwise the code is ignored.
Examples:
if (<bool exp>)
{
<code>
}
else
{
<other code>
}
if (<bool exp>)
{
<code>
}
else if (<other bool exp>)
{
<other code>
}
else
{
<yet another code>
}
While statements
While statements allow <code> to be executed while <bool exp> evaluates to TRUE:
while (<bool exp>)
{
<code>
}
Casts
Casts convert one data type into a different one. In Warzone 2100 casts are mostly used to convert float to int, int to float and bool to float. To perform a cast write the required data type in pare nothesis.
Examples:
myFloat = (float)myInteger + 2.3 + (float)500 + 500.0;
myInteger = 100 + numPlayers + (int)myFloat;
NOTE: Both (float)500 and 500.0 represent the same value. When converting FLOATs to INTs fractional part is discarded.
Custom functions
It is possible to define custom script functions to reuse certain functionality throughout the script.
Functions have following syntax:
function <return type> <function name> ([ <argument type> < argument name>, ... ])
{
<code>
return ... ;
}
Examples:
function void displayVictoryMessage(int winner)
{
console ("Player " & getPlayerName(winner) & " has won the game");
}
function float calculateMinimum (float f1, float f2)
{
if (f1 < f2)
{
return f1;
}
return f2;
}
Functions look almost identical to their C counterparts, except that the beginning of a function is marked with function keyword.
It is possible to declare functions like with events it is done in the event and function declaration section:
function void displayVictoryMessage(int winner);
function float calculateMinimum (float f1, float f2);
Declared this way it is possible to use a function before it is defined later in the script. To call a function simply provide its name with parameters in pare nothesis:
displayVictoryMessage(0);
...
console("Minimum of 2 and 2.1 is " & calculateMinimum(2.0, 2.1));
Like in C return <return expression>; or for void functions just return; returns execution to the caller.
Local variables
Local variables belong either to a function or event where they were declared and are not accessible outside of it. Local variables must be declared at the beginning of the function or event. Like public/private variables local variables of the same type can be declared on the same line separated by a comma.
Declaration of a local variable looks as follows:
local <variable type> <variable name> [, <variablename>, ...] ;
Example:
event myEvent(myTrigger)
{
local int count;
<code>
}
function void myFunction()
{
local DROID myDroid1, myDroid2;
local string myString;
<code>
}
Macros
The Warzone 2100 Scripting language supports nested macros (current max. depth is 10). Parametrized macros are not supported. Macros are defined as follows:
#define <macro name> <macro body>
Example:
#define pi 3.14
Example of a nested macro:
#define CURRENT_PLAYER 0
#define CURRENT_PLAYER_NAMe getPlayerName(CURRENT_PLAYER)
During the compilation process macro names are replaced with the actual code.
If any other text but "define" follows after # character then anything between # and end of the line is ignored by compiler making it possible to use #region and other tags in your favorite IDE.
NOTE: "#include" is reserved but not fully supported yet.
Data types
Apart from standard data types like string (string), integer (int), boolean (bool) and floating point (float) there are some Warzone 2100-specific data types available:
Data type
Meaning
INTMESSAGE
Simple. Name of a message as defined in Messages.txt, used mostly for campaign. In most cases it is easier to use a string instead.
BASEOBJ
Complex. Any of a DROID, FEATURE or STRUCTURE. It is a pointer to some droid/feature/structure on the map, can be NULLOBJECT if it was not assigned to a particular droid/feature/structure. You have access to the following variables:
baseobj.x
baseobj.y
baseobj.z
baseobj.id - unique ID number
baseobj.player - player ID
baseobj.type - one of OBJ_DROID, OBJ_STRUCTURE, OBJ_FEATURE
baseobj.health - %age number of body points left
baseobj.clusterID - the cluster the object is a member of
baseobj.target - target of the object (in case of a multi-turret object returns target of the default weapon)
DROID
Complex. Defined by the ID got from the world editor. It is a pointer to a particular droid on the map, can be NULLOBJECT when no droid is assigned to the DROID variable. You have access to following variables:
droid.x
droid.y
droid.z
droid.id - unique ID number
droid.player - player ID
droid.type - one of OBJ_DROID, OBJ_STRUCTURE, OBJ_FEATURE
droid.health - %age number of body points left
droid.clusterID - the cluster the object is a member of
droid.target - target of the object (in case of a multi-turret object returns target of the default weapon)
droid.order - current order of the droid
droid.orderx - target location of the droid order
droid.ordery - target location of the droid order
droid.action - current action of the droid
droid.body - the BODY of the droid
droid.propulsion - the PROPULSION of the droid
droid.weapon - the WEAPON of the droid DROIDID - (simple) literally just an Id of a droid
droid.selected - holds TRUE if droid is currently selected
droid.group - the GROUP droid belongs to
FEATURE
Complex. Defined by the ID got from the world editor. It is a pointer to a map decoration, like a tree, wrecked building, oil resource etc, can be NULLOBJECT. You have access to following variables:
feature.x
feature.y
feature.z
feature.id - unique ID number
feature.player - player ID
feature.type - one of OBJ_DROID, OBJ_STRUCTURE, OBJ_FEATURE
feature.health - %age number of body points left
feature.clusterID - the cluster the object is a member of
feature.target - target of the object (in case of a multi-turret object returns target of the default weapon)
FEATURESTAT
Simple. Type of a feature as defined in features.txt.
TEMPLATE
Simple. Name of a template as defined in templates.txt.
STRUCTURE
Complex. Defined by the ID got from the world editor. It is a pointer to a particular structure on the map, can be NULLOBJECT when no structure is assigned to the STRUCTURE variable. You have access to the foillowing variables:
structure.x
structure.y
structure.z
structure.id - unique ID number
structure.player - player ID
structure.type - one of OBJ_DROID, OBJ_STRUCTURE, OBJ_FEATURE
structure.health - %age number of body points left
structure.clusterID - the cluster the object is a member of
structure.target - target of the object (in case of a multi-turret object returns target of the default weapon)
structure.stat - the STRUCTURESTAT of the structure, defined in structures.txt
structure.stattype - structure type (likeREF_HQ etc.; refers to Script function constants)
STRUCTUREID
Simple. Literally just an ID of a struct.
STRUCTURESTAT
Simple. Type of a structure as defined in structures.txt.
BODY
Simple. Name of a body as defined in body.txt.
PROPULSION
Simple. Name of a propulsion as defined in propulsion.txt.
ECM
Simple. Name of an ECM as defined in ecm.txt.
SENSOR
Simple. Name of a sensor as defined in sensor.txt.
CONSTRUCT
Simple. Name of a construct as defined in construct.txt.
WEAPON
Simple. Name of a weapon as defined in weapons.txt.
REPAIR
Simple. Name of a repair type as defined in Repair.txt.
BRAIN
Simple. Name of a brain type as defined in Brain.txt.
SOUND
Simple. ID of sound used in playSound().
LEVEL
Simple. ID of a level as defined in GameDesc.lev.
RESEARCHSTAT
Simple. Name of a research topic as defined in research.txt.
GROUP
Complex. A group of droids. Do not confuse GROUP with in-game units' groups that can be accessed with CTRL-<number>, they have nothing in common. GROUP is an internal structure used to simplify unit management. You have access to following variables:
group.x - average x coord
group.y - average y coord
group.members - number of units in the group
group.health - average %age health of the units
group.type - type of the group, one of: GT_NORMAL, GT_COMMAND or GT_TRANSPORTER (refer to Script function constants)
group.commander - commander of the group, if type == GT_COMMAND or NULLOBJECT
NOTE: The functions objToDroid, objToStructure and objToFeature exist to convert a BASEOBJ to a droid, structure or feature if the base obj is of the right type.
NOTE: Transporters and commanders cannot be added to a GROUP.
With a complex object it is possible to access information specific to the instance of this object. Acomplex object is usually a pointer to a C structure in the code. For example a DROID is a complex object - its x, y, z can be queried whereas a DROIDID (a simple object - an integer) is just a placeholder for the numeric value of the ID.
Appendix A: Script functions
Standard functions
int random(range)
Return a random number between 0 and range - 1.
randomiseSeed()
Generate a new random seed for the random number generator.
int distBetweenTwoPoints(int x1, int y1, int x2, int y2)
Returns the distance between the two points given.
int max(int value1, int value2)
Returns maximum of two integer values.
int min(int value1, int value2)
Returns minimum of two integer values.
float fmax(float value1, float value2)
Returns maximum of two float values.
float fmin(float value1, float value2)
Returns minimum of two float values.
int modulo(int divident, int divisor)
Returns result of calculation (divident modulo divisor).
float toPow(float base, float exponent)
Returns floating point result of calculation base^exponent.
float exp(float exponent)
Exponential function. Returns the result of e^exponent.
float sqrt(float argument)
Square root function. Returns square root of the argument: √argument.
bool strcmp(string string1, string string2)
Returns TRUE if string1 and string2 are identical. Comparison is case-sensitive.
Type conversion
DROID objToDroid(BASEOBJ)
Convert a BASEOBJ to DROID when BASEOBJ.type == OBJ_DROID. Returns NULLOBJECT otherwise.
STRUCTURE objToStructure(BASEOBJ)
Convert a BASEOBJ to STRUCTURE when BASEOBJ.type == OBJ_STRUCTURE. Returns NULLOBJECT otherwise.
FEATURE objToFeature(BASEOBJ)
Convert a BASEOBJ to FEATURE when BASEOBJ.type == OBJ_FEATURE. Returns NULLOBJECT otherwise.
Objects
bool objectInRange(PLAYER, X, Y, RANGE)
This function checks for when an object belonging to a player is within range of a position. PLAYER is the id of the player whose unit is checked for in range. X, Y is the position to check from in world coords. RANGE is in world coords - 128 units = 1 tile.
bool objectInArea(PLAYER, X1, Y1, X2, Y2)
This function checks for when an object belonging to a player is in a square area. PLAYER is the id of the player whose droid is checked for in area. X1, Y1, X2, Y2 is the area to check in world coords. X1, Y1 should be smaller than X2, Y2.
centreView(OBJECT)
This function centres the view on the object supplied. OBJECT is any type of DROID, FEATURE, STRUCTURE.
int numObjectsInArea(PLAYER, X1, Y1, X2, Y2)
Return the number of player objects in an area.
bool losTwoObjects(BASEOBJ source, BASEOBJ target, bool wallsMatter)
Decides whether object source can see object target and you can specify whether walls matter or not. Note that whilst target can be anything, source needs to be something that can actually see - i. e. - have a sensor like a unit or structure. Returns TRUE or FALSE.
void forceDamageObject(BASEOBJ obj, int damage)
Sets obj to be damage percent damaged. obj must be a feature, droid or structure. damage ≥ 0 ⊥ damage ≤ 100.
void fireWeaponAtObj(WEAPON weap, BASEOBJ target)
Fire a single shot of the weapon weap at the object target.
BASEOBJECT skLocateEnemy(int pl)
Return a baseobject of interest belonging to player pl.
void skFireLassat (int pl, BASEOBJECT obj)
Fire lassat of player pl's at object obj.
int numEnemyWeapObjInRange(int lookingPlayer, int x, int y, int range, bool includeVTOLs, bool onlyFinishedStructs)
Return total number of enemy military structures and droids at location x, y and within range. Units belonging to lookingPlayer and his allies are ignored. If includeVTOLs is set to FALSE, then VTOLs are ignored. If onlyFinishedStructs is set to TRUE, then unfinished structures will be ignored.
int numFriendlyWeapObjInRange(int lookingPlayer, int x, int y, int range, bool includeVTOLs, bool onlyFinishedStructs)
Return total number of friendly military objects structures and droids at location x, y and within range. Units belonging to enemies of lookingPlayer are ignored. If includeVTOLs is set to FALSE, then VTOLs are ignored. If onlyFinishedStructs is set to TRUE, then unfinished structures will be ignored.
int numPlayerWeapObjInRange(int targetPlayer, int lookingPlayer, int x, int y, int range, bool includeVTOLs, bool onlyFinishedStructs)
Returns total number of targetPlayer's military structures and droids at location x, y and within range that are visible visible by lookingPlayer. If includeVTOLs is set to FALSE, then VTOLs are ignored. If onlyFinishedStructs is set to TRUE, then unfinished structures will be ignored.
int numEnemyObjInRange(int lookingPlayer, int, x, int y, int range, bool includeVTOLs, bool onlyFinishedStructs)
Returns total number of enemy objects (structures and units) at location x, y within range range that are visible to lookingPlayer. If includeVTOLs is set to FALSE, then VTOLs are ignored. If onlyFinishedStructs is set to TRUE, then unfinished structures will be ignored.
bool objHasWeapon(BASEOBJ object)
Returns TRUE if object has a weapon.
bool objectHasIndirectWeapon(BASEOBj object)
Returns TRUE if object has an indirect weapon.
int enemyWeapObjCostInRange(int lookingPlayer, int rangeX, int rangeY, int range, bool includeVtols, bool onlyFinishedStructs)
Returns total cost (in power) of enemy objects with a weapon in a certain area. If includeVTOLs is set to FALSE, then VTOLs are ignored. If onlyFinishedStructs is set to TRUE, then unfinished structures will be ignored.
int friendlyWeapObjCostInRange(int lookingPlayer, int rangeX, int rangeY, int range, bool includeVtols, bool onlyFinishedStructs)
Returns total cost (in power) of friendly objects with a weapon in a certain area. If includeVTOLs is set to FALSE, then VTOLs are ignored. If onlyFinishedStructs is set to TRUE, then unfinished structures will be ignored.
Structures
setStructureLimits(STRUCTURESTAT, LIMIT, PLAYER)
This sets a limit for a specific structure on how many can be built on a map. STRUCTURESTAT is defined by the name from Access. LIMIT is a number between 0 and 255. PLAYER is the id of the player.
setAllStructureLimits(LIMIT, PLAYER)
This sets a limit for all structures on how many can be built on a map. LIMIT is a number between 0 and 255. PLAYER is the id of the player.
bool buildingDestroyed(STRUCTUREID, PLAYER)
This function checks that a structure (given by the id) no longer exists for the player. STRUCTUREID is the id of the structure. Note that this is different to an object of type STRUCTURE. PLAYER is the id of the player whose list is checked for the building.
bool structureIdle(STRUCTURE)
This function checks whether the structure is doing anything. Returns TRUE if idle. STRUCTURE is a valid structure defined by ID.
bool structureBeingBuilt(STRUCTURESTAT, PLAYER)
This function checks that a structure of type STRUCTURESTAT is currently being built for the specified PLAYER. STRUCTURESTAT is defined by the name from Access. PLAYER is the id of the player who gets the structure.
bool structureBuilt(STRUCTURESTAT, PLAYER)
This function checks that a structure of type STRUCTURESTAT is currently built for the specified PLAYER. STRUCTURESTAT is defined by the name from Access. PLAYER is the id of the player who gets the structure.
bool structInArea(PLAYER, X1, Y1, X2, Y2)
This function checks for when a structure belonging to a player is in a square area. PLAYER is the id of the player whose droid is checked for in area. X1, Y1, X2, Y2 is the area to check in world coords. X1, Y1 should be smaller than X2, Y2.bool structInRange(PLAYER, X, Y, RANGE)This function checks for when a structure belonging to a player is within range of a position. PLAYER is the id of the player whose unit is checked for in range. X, Y is the position to check from in world coords. RANGE is in world coords - 128 units = 1 tile.setAssemblyPoint(X, Y, STRUCTURE)This sets the location of where new units assemble at for a specific factory. X, Y are the x and y in world coordinates. STRUCTURE is a valid structure defined by ID.STRUCTURE addStructure(STRUCTURESTAT, PLAYER, X, Y)Builds a structure belonging to PLAYER centred at (X, Y). The structure must be previously enabled via enableStructure(). The structure identifier is returned - this can be used in e.g. destroyStructure.destroyStructure(STRUCTURE)This removes the structure from the world. STRUCTURE is a structure defined by ID.STRUCTURE getStructure(STRUCTURESTAT, PLAYER)This function returns the first STRUCTURE based on the stat for the player it can find. To use it create a STRUCTURE variable and assign it to the result of the function call. For example:STRUCTURE myNewStructure;STRUCTURESTAT Factory;myNewStructure = getStructure(Factory, 0);This will look through the player 0 list of structures to find a Factory and return a variable of type STRUCTURE. You will then be able to access the x, y, and z. If a structure cannot be found than NULL is returned . It will be worth checking that the STRUCTURE does not equal NULL before using it. For example:if (myNewStructure == NULLOBJECT){ do something}void initEnumStruct(bool any, STRUCTURESTAT type, int targetPlayer, int lookingPlayer)STRUCTURE enumStruct()Enumerate through visible structures of given type of player targetPlayer that are visible to lookingPlayer. Returns NULLOBJECT when no more exist. If any is set to TRUE, then type is ignored and all structure types will be iterated.anyStructButWallsLeft(PLAYER)checks the specified player for any structures except walls - returns TRUE if some exist, FALSE if they have all been destroyed.anyFactoriesLeft(PLAYER)Returns true if player has a factory/cyborg factory/ vtol factory.STRUCTURE structureBuiltInRange(STRUCTURESTAT, X, Y, RANGE, PLAYER)Checks to see if a Structure has been built within a specified range of x, y. The first structure. to be found within this range will be returned. Check the result of the function for being NULLOBJECT before using. STRUCTURE is a return value (structure defined by ID). STRUCTURESTAT is defined by the name from Access. X, Y, RANGE are all in world coords. PLAYER is the id of the player whose structure list is searched.bool structButNoWallsInArea(PLAYER, X1, Y1, X2, Y2)See if there are any player structures excluding walls in an area.int numStructsInArea(PLAYER, X1, Y1, X2, Y2)Return the number of player structures in an area.int numStructsButNotWallsInArea(PLAYER, X1, Y1, X2, Y2)Return the number of player structures excluding walls in an area.int numStructsByTypeInArea(PLAYER, TYPE, X1, Y1, X2, Y2)Return the number of structures of a certain type in an area.bool pickStructLocation(STRUCTURESTAT, ref x, ref y, player);Returns true if structure of type structurestat can be built at x, y. If a structure can be built nearby then returns true and modifies x and y to the coords of acceptable location. Player trying to build uses this for the visibility.bool seenStructInArea(int player, int enemy, bool walls, int x1, int y1, int x2, int y2)Returns true if player has seen a structure belonging to enemy in area specified. Call with walls = true/false to include/exclude walls in the search. Similar to StructInArea.void killStructsInArea(int player, int buildingRef (like REF_WALL etc), int x1, int y1, int x2, int y2, bool bSeeEffect, bool bTakeFeatures).Blows up all the buildings of the specified reference within the specified area. If bSeeEffect is set, then you will see it blow up (provided you can see the building in question of course). If bTakeFeatures is set, then it will also kill features of type BUILDING. Returns 'nowt.bool testStructureModule(int playerNumber, ST_STRUCTURE structureToTest, int ref)Returns true if the structure in question has a module attached - presently the ref id is unused but could be later on. At the moment it returns true if the structure has _any_ number of modules attached. If the structure pointer that is sent in is NULL (i. e. - no structure is specified), then it will return TRUE if _any_ of the player's structures possess _any_ module. In all other cases, it will return FALSE.STRUCTURE takeOverSingleStructure(STRUCTURE structToTakeOver, int playerToGain)This replaces the existing structure (structToTakeOver) by a new one for the playerToGain. The new structure is passed back to the script. Test for NULLOBJECT BEFORE calling this function.int takeOverStructsInArea(int fromPlayer, int toPlayer, int x1, int y1, int x2, int y2)x1, y1, x2, y2 are in world units. checks for structures belonging to fromPlayer and if they are in the area they are given to the toPlayer. This will NOT WORK for the selectedPlayer on any Factory. The structure limits will be increased if necessary.void resetStructTargets()Reset the structure preferences.void setStructTarPref(int type)Set a preferred structure target type, repeated calls combine the effect.void setStructTarIgnore(int type)Set structure target ignore types.STRUCTURE structTargetInArea(int targetPlayer, int visibleToPlayer, int x1, int y1, int x2, int y2)Get a structure target in an area using the preferences. targetPlayer is the player to choose targets from, visibleToPlayer specifies the. player that has to be able to see the target or -1 for no visibility check.STRUCTURE structTargetOnMap(int targetPlayer, int visibleToPlayer)Get a structure target on the map using the preferences.bool isStructureAvailable(STRUCTURESTAT stat, int player)Returns true if structure is available to player, false otherwise.bool structureComplete(STRUCTURE struct)Returns true if the structure is completely built.int skGetFactoryCapacity(STRUCTURE str)Return the capacity of factory str.bool skDefenseLocation (ref int x, ref int y, STRUCTURESTAT defenceStat, STRUCTURESTAT wallstat, DROID unit, int player)Given a starting x and y, make unit unit belonging to player build either a defenceStat or a row of wallStat. Returns modified x and ys.int numEnemyWeapStructsInRange(int lookingPlayer, int x, int y, int range, bool onlyFinishedStructs)Return total number of enemy military structures at location x, y and within range. Units belonging to lookingPlayer and his allies are ignored. If includeVTOLs is set to FALSE, then VTOLs are ignored. If onlyFinishedStructs is set to TRUE, then unfinished structures will be ignored.int numFriendlyWeapStructsInRange(int lookingPlayer, int x, int y, int range, bool onlyFinishedStructs)Return total number of friendly military structures at location x, y and within range. Units belonging to enemies of lookingPlayer are ignored. If onlyFinishedStructs is set to TRUE, then unfinished structures will be ignored.int numPlayerWeapStructsInRange(int targetPlayer, int lookingPlayer, int x, int y, int range, bool onlyFinishedStructs)Returns total number of targetPlayer's military objects (either structures, droids or both) at location x, y and within range that are visible visible by lookingPlayer. If onlyFinishedStructs is set to TRUE, then unfinished structures will be ignored.int numAAinRange(int targetPlayer, int lookingPlayer, int x, int y, int range)Returns number of targetPlayer's AA defences at location x, y within range range that are visible to lookingPlayer.