// AUTODOC generated file
//
// Note that a * means that a tag can be used more than once

// NOTE!!!    a # symbol indicates that something has not been implemented as yet!

//returns the turn count.
GetTurn()

//returns the tick in the current turn (in 30ths of a second)
GetTurnTick()

//end the battle setting the denoted side as the winner.  Will be ignored if the battle already has a winner...
EndBattle(winner)

//return the side id set for the mission, for the given side (0 or 1).  These are the value set using the side ID buttons in the editor
GetSideID(side)

//set the side id set for the mission, for the given side (0 or 1).  These are the values set using the side ID buttons in the editor
SetSideID(side, id)

//get a rand between and including the values of attrib[index] and attrib[index+1]
GetAttribRand(id, string, index)

//return the value of the give attrib for the give unit
GetAttrib(id, string)

//return the value of the give attrib at the index for the give unit (attrib[index])
GetAttribArray(id, string, index)

//return the base value of the give attrib for the give unit. If bit 16 is set (+65536) then id is assumed to be the type index of the unit type, allowing this to be used when no unit exists.
GetBaseAttrib(id, string)

//return the base value of the give attrib at the index for the give unit (attrib[index]). If bit 16 is set (+65536) then id is assumed to be the type index of the unit type, allowing this to be used when no unit exists.
GetBaseAttribArray(id, string, index)

//set the value of the give attrib for the give unit
SetAttrib(id, string, value)

//set the value of the give attrib at the index for the give unit (attrib[index])
SetAttribArray(id, string, index, value)

//create a new attrib (which will be available across all units) does nothing is attrib already exists.
AddAttrib(string)

//create a new attrib array (available across all units) does nothing is attrib already exists.
AddAttribArray(string)

//place the given attrib string into the first work string.  typeIndex is the index of the unit type. index is currently [0,7].
GetAttribString(typeIndex, index)

//return the value of the campaign var, if index is not provided 0 is used.  index must be [0, 7] unless a campaign array is used (var starts with a $) when index [0,255]
GetCampaignVar(tag, [index])

//set the value of the campaign var, if index is not provided 0 is used.  index must be [0, 7] unless a campaign array is used (var starts with a $) when index [0,255]
SetCampaignVar(tag, value, [index])

//return the value saved to a universal variable.  Returns 0 and creates if does not exist.This is accessible from any script.
GetUniversalVar(tag)

//set the value to a universal variable.  Created if doesn't exist  This is accessible from any script.
SetUniversalVar(tag, value)

//return the value saved to a universal variable array.  index [0,7]. Returns 0 and creates if does not exist.This is accessible from any script.
GetUniversalArray(tag, index)

//set the value to a universal variable. index [0,7]. Created if doesn't exist  This is accessible from any script.
SetUniversalArray(tag, index, value)

//returns 1 if in a deployment phase, 0 otherwise
IsDeploying()

//tells the game to skip the first player turn if the mission is set to have a deploy phase.  Obviously only useful to call on turn -1 or 0
SkipFirstPlayerTurn()

//tell the game to skip force selection.  Only useful in the PreStartBattle callback. flags can be combination of: 1 (prevent unfixed units from being removed on deployment)
SkipForceSelection([flags])

//tells the game not to show the onscreen start turn UI for this turn.  Only works when used in the StartTurn function
DisableStartTurn()

//return a value denoting whether the tile is valid.  1 means it is on the playable area, 0 means it is in the border, -1 means it is off the map entirely
IsValidTile(x,y)

//returns 1 if we are currently executing an AI turn in battle mode, 0 otherwise
IsAITurn()

//returns 1 if we are currently in hotseat mode
IsHotseat()

//return the side whose turn it currently is
GetCurrentSide()

//returns the side who is currently viewing the map (used for tile LOS etc, to show what should be seen)
GetShowSide()

//return the id of the currently selected unit.  Returns -1 if none
GetCurrentSelectedUnit()

//set the currently selected unit.  Use -1 for none.
SetCurrentSelectedUnit(id)

//add a unit to the map.  The string is the unit name.  If recycle is 1, attempt to reuse ids of removed or dead units.  If the tile is not clear the unit is not added.  Returns the id of the new unit, or -1 if there was a problem
AddUnit(x, y, side, typeString, [recycle])

//delete a unit from the side. NOTE: index is the position in the side list, it is NOT the unit ID as used by other functions. This will remove the unit entirely, unlike RemoveUnit etc. WARNING:CAN CHANGE THE IDs OF EXISTING UNITS, UPDATES SELECTED UNIT ID
DeleteUnit(side, index)

//Set a squad to route to the designated tile.  react denotes whether the move triggers reaction fire (0 - no reaction, 1 - normal reaction (default), 2 - object reaction only).
SetRoute(id, x, y, [react])

//Set a squad to route to the designated tile, but reverse there.  react denotes whether the move triggers reaction fire (0 - no reaction, 1 - normal reaction (default), 2 - object reaction only).
SetRouteReverse(id, x, y, [react])

//set a squad route, but factor in the threat map denoted by the threatIndex, currently [0,2]
SetRouteUsingThreat(id, x, y, threatIndex)

//Find the route length for the given squad.  -1 if cannot find a route.  showroute show it on the map.  ignoreunits 0(can't route), 1(try to avoid), 2(route as if not there) | 128 then treat all tiles as same cost
GetRouteCost(id, x, y, [showRoute], [ignoreUnits])

//return 1 if the unit can step to the tile x,y (which must be adjacent).  Basically is a shortest route 2 tiles in length.
CheckTileStep(id, x, y)

//return the cost of this tile for this unit.  Useful to find whether a unit can sit on a tile, for example.
GetTileCost(id, x, y)

//return the cost of this tile for this unit, based on side's LOS to the tile.  Useful for display when the objects on the tile may not be revealed.
GetTileCostFromLOS(id, x, y)

//Route cost for the squad.  -1 if cannot find route.  showroute show it on the map,use threat map denoted by the threatIndex, currently [0,2].  ignoreUnit 1=target, 2=all units
GetRouteCostUsingThreat(id, x, y, showRoute, ignoreUnit, threatIndex)

//get the X ordinate of the [index] entry into the route just generated by a call to GetRouteCost*
GetCheckRouteX(index)

//get the Y ordinate of the [index] entry into the route just generated by a call to GetRouteCost*
GetCheckRouteY(index)

//get the stored cost value of the [index] entry in the route array
GetCheckRouteCost(index)

//return the number of tiles in the route generated by a call to GetRouteCost*
GetCheckRouteLength()

//build a set of all the tiles touched by a line from the center of tile x0,y0 to tile x1,y1 into the CheckRoute array.
BuildTileLine(x0, y0, x1, y1)

//set a (single byte) mask used to prevent units with mask with matching bits from being included in routefinding calculations.
SetRouteMask(mask)

//set the (single byte) route mask on a unit
SetUnitRouteMask(id, mask)

//get the route mask on a unit
GetUnitRouteMask(id)

//tell a unit to move directly from its current tile to another tile, irrespective of any intervening units or terrain. Return 1 if success, otherwise 0. The unit claims destination tile immediately (fails if dest is occupied). USE WITH CAUTION.
MoveUnitDirect(id, x, y)

//set the number of ticks a blocked unit will wait for the target tile to become free before it stops.  Defaults to 60.  Should not be < 1.
SetStopDelayValue(value)

//return the x coordinate of next tile in the unit's current path or the current x if it is not moving
GetRouteNextX(id)

//return the y coordinate of next tile in the unit's current path or the current y if it is not moving
GetRouteNextY(id)

//return the unit side
GetUnitSide(id)

//returns 1 if the id unit is of type string (e.g. Sherman) as per the Name field in the squads file.  0 otherwise
IsUnitType(id, string)

//returns 1 if the unit is of the squad type string (e.g. INFANTRY) as defined in the terrain file.  If bit 16 is set (+65536) then id is assumed to be the type index of the unit type, allowing this to be used when no unit exists.
IsUnitSquadType(id, string)

//returns 1 if the unit is moving, 0 otherwise
IsUnitMoving(id)

//returns 1 if the unit is set as fixed in the editor
IsUnitFixed(id)

//returns the point cost of the given unit
GetUnitCost(id)

//puts the base asset filename for the unit in the workString requested, default 0. If bit 16 is set (+65536) then id is assumed to be the type index of the unit type, allowing this to be used when no unit exists.
GetUnitAssetFilename(id, [workString])

//place the base (stage 0) texture filename for the given unit type into the workstring requested (default 0). If ws1,2,3 are set they are indices to workstrings for texture stages 1,2,3 respectively. This is read directly from the file.  Returns 1 if successful, 0 otherwise.
GetUnitTextureFilename(typeString, [workString], [ws1], [ws2], [ws3])

//returns the unit type index.  This is the index of the unit type.  Can be used in other TypeIndex functions.
GetUnitTypeIndex(id)

//places the unit type string (e.g. Sherman) into workstring[0].  You can then use the String* functions to compare etc
GetUnitTypeString(typeIndex)

//places the unit squad type string as defined in the terrain file (e.g. INFANTRY) into workstring[0].  You can then use the String* functions to compare etc
GetUnitSquadTypeString(typeIndex)

//returns the cost of a unit type by index
GetUnitTypeCost(typeIndex)

//return the number of unit types
GetNumUnitTypes()

//get the face that the enemy is presenting to my position.  front,side,back = 0,1,2
GetFacingFrom(me_id, enemy_id)

//get the angle the enemy is presenting to my position, 0=looking straight at me, 180=I am directly behind them
GetAngleFrom(me, enemy)

//get the angle the enemy is presenting to the denoted tile, 0=looking straight at me, 180=I am directly behind them.  If leftright is !=0 then the result is signed (-ve for left)
GetAngleFromTile(x, y, enemy, [leftright])

//get the face that the enemy is presenting to my position.  front,side,back = 0,1,2
GetTurretFacingFrom(me_id, enemy_id)

//get the angle the enemy is presenting to my position, 0=looking straight at me, 180=I am directly behind them
GetTurretAngleFrom(me, enemy)

//get the angle the enemy is presenting to the denoted tile, 0=looking straight at me, 180=I am directly behind them
GetTurretAngleFromTile(x, y, enemy)

//return the unit's X coord
GetUnitX(id)

//return the unit's Y coord
GetUnitY(id)

//return the X coord of the specified man, in 100ths
GetManX(id, man)

//return the Y coord of the specified man, in 100ths
GetManY(id, man)

//return the X coord of the specified man's target position, in 100ths
GetManTargetX(id, man)

//return the Y coord of the specified man's target position, in 100ths
GetManTargetY(id, man)

//return the distance in 100ths between two points that are also in 100ths
GetPositionDistance(x1,y1,x2,y2)

//return how many men are in the unit
GetUnitMen(id)

//is this man dead?  0 = no, 1 = yes
GetUnitManDead(id, man)

//is the whole unit dead? 0 = no, 1 = yes
GetUnitDead(id)

//is the unit active (e.g. not dead, loaded, or removed from the map) 0 = no, 1 = yes
GetUnitActive(id)

//does this unit have LOS to the tile?  0 means no
GetUnitLOS(id, x, y)

//does this unit have LOS to the target?  0 means no
GetUnitLOSToUnit(id, target)

//return an id for the unit on a tile, -1 for none
GetUnitOnTile(x, y)

//tell our unit to turn and face the tile
SetUnitTurnToFace(id, x, y)

//flag this unit that enemies can react to what we just did
SetUnitForReaction(id)

//returns 1 if the unit has a turret, 0 otherwise
GetUnitTurret(id)

//returns the status of the unit, [-1, 2]
GetUnitStatus(id)

//sets the status of a unit.  Valid values are -1,0,1,2.  Changes the icon set used, and can be used to give extra abilities
SetUnitStatus(id, status)

//do an immediate switch for a unit to a given facing [0,359] If leaveMenInPlace!=0 then the actual men in the unit will not be changed by this command.
SetUnitFacing(id, angle, [leaveMenInPlace])

//do an turning switch for a unit to a given facing [0,359]
SetUnitFacingDesired(id, angle)

//return the unit facing angle
GetUnitFacing(id)

//return the unit's turret facing angle.
GetTurretFacing(id)

//call a unit script each tick until fn returns 0.  Can only be checking one fn at any time.  Must be defined in the unit script.  Can ONLY be used to call functions with up to 6 fixed params, one used forname.
SetUnitCheckFunction(id, function, [value, ...])

//show tracer fire, x,y are the end coords (in 100s), point is index of emitter 3d object, time is the duration in ticks, type is the visual type of the tracer
SetUnitTracer(me, man, x, y, point, time, type)

//set the unit to use a new texture.  A unit can only have a single texture on all its men.  If path is omitted or empty uses DATA/BATTLE/UNITTEXTURES (either local or main). index [0,3]. Empty filename means reset.
SetUnitTexture(me, filename [,path][,index])

//return 1 if the given texture exists, 0 otherwise.  The type on the filename is optional and success is returned if any valid texture file type exists. If path is omitted uses DATA/BATTLE/UNITTEXTURES (either local or main).
CheckTextureFile(filename [,path])

//set the shader style for the rendering on a unit. Use -1 to use the style defined in the model.
SetUnitShaderStyle(id, style)

//set the man count for a unit, ignoring any other settings.  Must be >=1 and <= max man count (currently 16), and must be less than the max mancount defined in the squads file. Use with care. Note: does not alter the ManCount attrib value.
SetUnitManCount(me, count)

//set the banner index for a unit.  A unit can have 2 banners (to allow for component-style banners). so index [0,1].  bannerIndex as defined in the BANNER.TXT file. zero for off. textureIndex -1 for full texture, [0,63] for 8x8 texture.
SetUnitBanner(me, index, bannerIndex, [textureIndex])

//set the animation for the given unit banner, for the current banner that is set. Uses the same anim naming conventions (and randomness) as units animations.  Use an empty string to disable animations.
SetUnitBannerAnim(me, index, animName)

//place the contents of the first UI string as a custom string for the unit.
SetUnitString(me)

//place the contents of the unit custom string into the first UI string.  Returns 0 if there is no custom string, 1 otherwise
GetUnitString(me)

//set the weather.  0 = none, 1 = rain.  2 = snow.
SetWeather(mode)

//get the weather.  0 = none, 1 = rain.  2 = snow.
GetWeather()

//get the number of minutes past midnight.
GetTimeOfDay()

//get the number of minutes per turn.
GetMinutesPerTurn()

//return the id of the unit if there is a clearable wreck on the tile, -1 if not
GetWreckOnTile(x,y)

//return 1 if there is a unit or a wreck that must be cleared before the specified unit can enter the tile, 0 otherwise
IsTileBlocked(id, x, y)

//move a unit instantly to this tile.  If there is a unit already there, it will be swapped with the current unit. If leaveMenInPlace!=0 then the actual men in the unit will not be moved by this command.
UnitDeploy(id, x, y, [leaveMenInPlace])

//if the unit script contains the function return the number of params, -1 otherwise
GetUnitFunction(id, functionName)

//call a function on a unit with params in the expected order, limited to functions with 6 params or less, returns the function result
CallUnitFunctionDirect(id, functionName, [value, ...])

//call a function on unit.  Assumed to have some/all of the params X, Y, UNIT, ME as per standard menu functions.
CallUnitFunction(id, functionName, x, y, me, unit)

//flag the men in the unit (as defined by the mask) as being dead.  Set the mask in holdAnim to denote whether men should die at the end of their current animation, even if it is not a DIE animation.
DestroyUnit(id, mask, [holdAnim])

//remove this unit from play.  Flags =0 just remove from tile, =1 immediate removal, =2 sink out of sight and remove. If flags bit 8 (+256) any dead men in the unit will continue to be displayed on map.
RemoveUnit(id, flags)

//resurrect the denoted men in a unit.  This will remove any dead bodies, will appear in place on the unit tile. WILL NOT work on dead units
ReviveUnit(id, mask)

//return the width of the map
GetMapWidth()

//return the height of the map
GetMapHeight()

//clear threat map index with the provided value [0,255]
ClearThreatMap(index, value)

//get the threat map value from map index at x,y
GetThreatMapValue(x, y, index)

//set the threat map value from map index at x,y.  Value must be [0,255]
SetThreatMapValue(x, y, index, value)

//load the toBeLoadedID unit onto the id unit.  NOTE:  Units can have more than 1 loaded unit
LoadUnit(id, toBeLoadedID)

//does the unit have another unit loaded onto it.  Returns the first unit found if more than one loaded, -1 if none found.
GetLoadedUnit(id)

//unload the unit that we are carrying onto the given tile,  returns 0 on success, -1 otherwise
UnloadUnit(id, x, y)

//return the unit id of any unit onto which the provided unit is loaded.  -1 if not loaded.
GetLoadedOn(id)

//get the terrain cover value for the given x,y
GetTerrainCoverValue(x, y, index)

//get the terrain cover value for the given x,y, based on side's LOS to the tile
GetTerrainCoverValueFromLOS(x, y, index, side)

//get the damage modifer for an edge (hedgerow or trench), in 100ths
GetEdgeCoverModifier(shooter, target)

//return 1 if the tile is a water tile, 0 otherwise
IsTileWater(x, y)

//return 1 if the tile currently has smoke, 0 otherwise
IsTileSmoke(x, y)

//set the los of a tile (not valid during StartTurn functions).  Values are:  0=hide, 1=show
SetTileLOS(x, y, side, los)

//return the LOS value of a tile (not valid during StartTurn functions).  0=hidden, 1=shown, 2 = cover
GetTileLOS(x,y,side)

//return the cover flag for a tile.  1 set means can be hidden in
GetTileCoverFlag(x,y)

//returns the best directional cover for the tile (% damage)
GetTileEdgeCover(x, y)

//damage a tile by the specified amount.  Tile damages ranges [0,255]
DamageTile(x, y, amount)

//return the damage on a given tile.  Tile damages ranges [0,255]
GetTileDamage(x, y)

//return the height of the center of a given tile, in 100ths.  So 0 would be ground level, 100 the top of a 1st level hill, etc
GetTileHeight(x,y)

//set the height of the given tile.  This is NOT in 100ths.  So 0 is ground, 1 is hill, 2 is twice as high, etc. Not for use during gameplay. If autoedge is 1, automatically update edging around tile
SetTileHeight(x, y, height, [autoedge])

//play an effect on these men in a unit, using the mask as per AddVizAnim
PlayEffect(id, mask, effect)

//return the distance between the two units
GetDistanceBetween(id, id)

//return the distance between two tiles
GetDistanceBetweenTiles(x1, y1, x2, y2)

//how far is the unit from the tile
GetDistanceFromUnit(id, x, y)

//play one of the defined sfxTypes for the the unit.  can optionally specify a bank to play from
PlayUnitUISFX(id, sfxType, [bank])

//play a world positioned sfx on the specified unit. can optionally specify a bank to play from. Returns a playback ID (or zero if did not play).
PlayUnitSFX(id, sfxType, [bank])

//play a sample at a specified position in the world (x,y are in 100ths). can optionally specify a bank to play from. Returns a playback ID (or zero if did not play).
PlaySFX(x, y, sfx, [bank])

//stop a playing sample using a playback ID.  Has no effect if the sample is over, or has been stopped by the system.
StopSFX(playbackID)

//play a screen shake for N ticks, the scale determines the amount of movement, in 100ths, so 100 is the default x1 value
Shake(ticks, scale)

//tell the game whether or not to show the cover ? markers.  1 = yes, 0 = no
ShowCoverMarkers(show)

//load lighting file(s) from DATA/BATTLE/LIGHTING (either local or main), name does not include .txt extension
SetLightingFile(lightFile, [twilightLightFile], [nightLightFile])

//show (visible = 1) or hide (visible = 0) an existing text marker
SetVisibilityTextMarker(id, visible)

//CREATE a text marker at the specified tile center.  id is user defined, must not be zero.  colour is a hex string
ShowTextMarker(id, x, y, string, fontid, colour, [unused])

//DESTROY the specified text marker
HideTextMarker(id)

//show anim at center of tile xy.  id is a user handle to allow for turning off etc-must NOT be zero. Use a negative id to loop the effect. sidemask=optional [0,1] only that side can see.  Set MinimapColourString to non-zero to show
ShowEffectMarker(id, x, y, animFile, effect, [showside], [MinimapColourString], [facing])

//remove an effect marker
HideEffectMarker(id)

//set effect marker on a projectile path from emitter on the given unit (man index in top 16 bits of emitterID). arc is initial angle in degrees. speed effects arc height. dest coords & height in 100ths. Helper script On_Impact when hits ground.
SetObjectProjectile(id, unitID, emitterID, ticks, arc, speed, destX, destY, [height])

//set the flag for turning on or off the force visible flag.  0 for off, anything else for on
SetForceVisible(id, value)

//set the flag for player control of a unit.  0 for off, anything else for on
SetCannotControl(id, value)

//returns 1 if the unit has been set to be uncontrollable, 0 otherwise
GetCannotControl(id)

//define which viz queue to use.  They both execute symultaneously.  Remember to set back to 0 when you are done.
UseVizQueue(queue)

//add a queued anim (string) to the unit, the mask is the men affected (1 == man 0, 2 == man 1, etc) neg mask means play until you tell it play something else
AddVizAnim(id, anim, mask)

//add a queued anim without a wait until the end (string) to the unit, the mask is the men affected (1 == man 0, 2 == man 1, etc.  neg mask means play until you play something else)
AddVizAnimNoWait(id, anim, mask)

//move the camera (if needed) to show this tile, optionally show for only side 0 or side 1
AddVizCam(x, y, [showSide])

//move the camera (if needed) to center the screen on this tile, optionally show for only side 0 or side 1
AddVizCamCenter(x, y, [showSide])

//move the camera (if needed) to point to this unit, optionally show for only side 0 or side 1
AddVizCamUnit(id, [showSide])

//insert a pause in the viz queue (and thus the game) of delay ticks
AddVizDelay(delay)

//add a display of text to the tile center, in the colour (colour is a string hex value).  alwaysShow means show even if tile is not visible to viewing side
AddVizText(x, y, text, colour, [alwaysShow])

//add a display of text to the coordinates in 100ths, in the colour (colour is a string hex value).  alwaysShow means show even if tile is not visible to viewing side. NOTE does not autodelay messages per tile as normal, to allow >1 on tile.
AddVizTextPrecise(x, y, text, colour, [alwaysShow])

//add a display of text to the unit, in the colour (colour is a string hex value).  alwaysShow means show even if tile is not visible to viewing side. $ as first char means literal string
AddVizUnitText(id, text, colour, [alwaysShow])

//on unit id, using the mask for men, play the file with the effect (-1 for none) and define the end time (1000ths of a sec, -1 for end of the anim).  animFile must be in the campaign or core ANIM dir.  Optionally, show for only one side (-1 for both).
AddVizUnitSpotAnim(id, mask, animFile, effect, endTime, [showSide])

//at x,y (+optional height)(in 100ths) play file with effect (-1=none) and define endtime (1000ths/sec, -1 end of anim, or (loopTicks<<16)|0x8000|endTicks to loop an animation). animFile in campaign or core ANIM dir. Optional show only one side (-1=all). facing angle to turn anim
AddVizSpotAnim(x, y, animFile, effect, endTime, [showSide], [facing], [height])

//turn the unit to face the specified tile. if nowait!=0 then it doesn't pause the main vizq, only the unit.
AddVizUnitTurnToFace(id, x, y, [noWait])

//turn the unit or the unit's turret (if it has one) to face the tile. if nowait!=0 then it doesn't pause the main vizq, only the unit.
AddVizUnitTurnToFire(id, x, y, [noWait])

//call a function from the vizQ.  Can ONLY be used to call functions with up to 11 fixed params, as one is used for the name.
AddVizFunctionCall(function, [value, ...])

//wait until the denoted unit has finished moving
AddVizWaitOnMove(id)

//do a call to the unit placement function (potentially calling the FORMATION_CALLBACK) and wait until all the men are in position and facing the correct way.
AddVizUnitFormation(id)

//do a call to the unit placement function (potentially calling the FORMATION_CALLBACK) and then immediately do the next viz entry.
AddVizUnitFormationNoWait(id)

//do a call to the unit placement function (potentially calling the FORMATION_CALLBACK), immediately apply facing and position, and then immediately do the next viz entry.
AddVizUnitFormationNoWaitNoAnim(id)

//wait until all the men in the denoted unit are at or reach their desired facing
AddVizWaitOnTurnAll(id)

//returns 1 if any viz queue has waiting items in it, 0 otherwise
IsVizWorking()

//immediately set the unit's anim without a wait (string) to the unit, the mask is the men affected (1 == man 0, 2 == man 1, etc.  neg mask means play until you play something else.  USE WITH CARE.  Prefer AddVizAnim.)
SetUnitAnim(id, anim, mask)

//Set the value of a global bonus base value
SetBonusBaseValue(name, side, value)

//Get the value of a global bonus base value
GetBonusBaseValue(name, side)

//Get the current value (taking into account player bonuses) of the global value.  If base is provided, we actually look for the string base+name as the global
GetBonusValue(name, side, [base])

//set the icon mask.  This is used when working out how to tag units.  Each of 8 bits add a different icon to the unit.  Sets the value, not OR.  Only used to pass the value back to the code.
SetIconMask(mask)

//set the icon mask.  Used by friendly units to show all the time, rather than to show actionable units for the current unit.  Uses same icon set.  ORs this value with the current value. byte 2 will be ORed to show always.
SetUnitIconMask(id, mask)

//turn off the bits in icon mask.  Used by friendly units to show all the time, rather than to show actionable units for the current unit.  Uses same icon set.  Turns off only the bits requested.
ResetUnitIconMask(id, mask)

//determine how/if unit icons are shown.  1 for on all the time, 0 for off all the time, -1 for default behaviour.  Defaults to -1.
SetUnitIconDisplayState(state)

//render the string to the screen. colourString is a hex value (as is borderColourString if used, 0 for not used). Returns the printed text height in the lower 16 bits and width in the upper 16 bits. Everything done in 1024x768 space. Negative width forces single line rendering.
RenderString(x, y, font, colourString, [borderColourString], [width], [height])

//flag an area of the screen as UI.  Means the UI won't treat the mouse as pointing to the map and will not show icons or options etc.  tooltip&1 then take current string & uses as tooltip.  bits 8-15 used as an id passed through.
BlockUIArea(x, y, width, height, [tooltip])

//render an image based on its filename (UI/TEXTURES base dir unless path is given, path is ignored if imageName is "UNITICONS0" or 1 (for each side).  Resets the image area. Neg width/height flips)
RenderImage(x, y, width, height, colourString, imageName, [path])

//Sets a restricted area to render from on the next call to RenderImage.  All values are in 1000ths, so to only draw the bottom half of the image you would use 0, 500, 1000, 500
SetImageArea(x, y, width, height)

//Forces the next call to RenderImage (or like functions) to rescale the rect to maintain the original aspect ratio
SetImageSquare()

//Set the current UI object which is being rendered to the texture and colour (colour is a hex string).  Do not use the file extension.
SetUITexture(filename, colour)

//set the current string as the tooltip which should be used by the UI for this control (if applicable) use in CHECK and/or UISETUP
SetUITooltip()

//set the colour the entire tooltip will be for the current control.
SetUITooltipColour(colourString)

//add some info to the tile tooltip which shows as the mouse is over the map.  Only really useful in the CHECK fn
AddTileTooltip()

//set the colour the entire tooltip will be.  Note if multiple functions attempt to use this in a single tick then the results will be whichever calls it last
SetTileTooltipColour(colourString)

//flags that this option can act as a single click if it is the only option, use in the CHECK fn
AllowUISingleClick()

//allows us to sort the order in which the onscreen order icons are shown.  Default priority for all icons is 0. Use in the CHECK fn.
SetIconPriority(priority)

//return the string which is the filename of the icon for the unit whose id is given
GetUnitIcon(id)

//return the string ID for the unit whose id is given
GetUnitStringID(id)

//render an image based on a unit id.  Resets the image area. Neg width/height flips.
RenderUnitIcon(id, x, y, width, height, [colourString])

//render a single icon from the UNITICONS image based on a unit id. Resets the image area. Neg width/height flips.
RenderFromUnitIcons(id, icon, x, y, width, height, [colourString])

//returns the X ordinate of the rect bounded by any prior drawing in the DrawScenarioUI functions
GetUIDisplayLeft()

//returns the Y ordinate of the rect bounded by any prior drawing in the DrawScenarioUI functions
GetUIDisplayRight()

//returns the right edge ordinate of the rect bounded by any prior drawing in the DrawScenarioUI functions
GetUIDisplayTop()

//returns the bottom edge ordinate of the rect bounded by any prior drawing in the DrawScenarioUI functions
GetUIDisplayBottom()

//remove the ability of the player to do things.  locked should be 1 to lock the UI, and 0 to unlock and return to normal
LockUI(locked)

//turn on tile display - this will show up tiles as per the movement when they have their tile display flag set.  Anything which causes a reset of the model, like movement or selecting a new unit, turns it off
ShowTileDisplay()

//turn off the tile display
HideTileDisplay()

//set a texture for a tile display flag value, max of 4 atm
SetTileDisplayTexture(index, texture)

//returns 0 if tile display mode is off, 1 if it is on
GetTileDisplay()

//clear all the tile display flags
ClearTileDisplayFlags()

//set the tile display flag for this tile.  -1 is off, any other value is the index of the texture you want to show [0,3] atm
SetTileDisplayFlag(x, y, value)

//return the X ordinate of the Nth AI point
GetAIPointX(id)

//return the Y ordinate of the Nth AI point
GetAIPointY(id)

//set the coordinate of the Nth AI point
SetAIPoint(id, x, y)

//return the value of an entry in the AI unit list (which determines the order in which the AI processes units)
GetAIUnitListEntry(index)

//set the value of an entry in the AI unit list. NOTE: the values should be the index of the unit NOT the unit ID
SetAIUnitListEntry(index, value)

//set how many entries are in the AI unit list.  Note dead or inactive (removed or mounted) units are ignored even if they are in the list
SetAIUnitListCount(count)

//how many passes through the AI units do we allow?  defaults to 1
SetAIPasses(passes)

//are all the units in the team at or as close as they can be to the destination.  0 for no, 1 for yes
CheckTeamDestination(side, team, x, y)

//return how many units were checked in the last call to CheckTeamDestination.  Dead etc units are not checked
GetCheckTeamTotal()

//return how many units were not at the destination in the last call to CheckTeamDestination.  Dead etc units are not checked
GetCheckTeamFailed()

//set the done value of the team
SetTeamDone(side, team, value)

//return the done value for the team
GetTeamDone(side, team)

//set the team destination: NOTE: this sets the value in the team, but DOES NOT force any movement-the AI script actually moves things (see wiki)
SetTeamDestination(side, team, x, y)

//return the X ordinate of the team destination.  Usually use -1 for none set
GetTeamDestinationX(side, team)

//return the Y ordinate of the team destination.  Usually use -1 for none set
GetTeamDestinationY(side, team)

//return the aggression value
GetTeamAggression(side, team)

//set the aggression value
SetTeamAggression(side, team, aggr)

//set the target of the team to be the unit index (use -1 unit index to flag no target)
SetTeamTarget(side, team, unit)

//returns the team targeted unit, or -1 for none
GetTeamTarget(side, team)

//return an average team position X
GetTeamX(side, team)

//return an average team position Y
GetTeamY(side, team)

//return the data from the team.  The index can be [0, MAX_TEAM_DATA-1].  0 is generally used to denote any AI point that the team will head for, but this is dealt with in the script
GetTeamData(side, team, index)

//set the team data
SetTeamData(side, team, index, value)

//return a team order. Full info on wiki. The index can be [0, MAX_TEAM_ORDERS-1], 6 current. Current AI script behaviour: byte 2 is new aggr, byte 0 is AI point unless bit 24 is set, in which case bytes0,1 are x,y
GetTeamOrder(side, team, index)

//set the team order value to the constructed order.  NOTE: zero value is no order, and order processing will stop.  If you need zero aggr and zero AI point, set bit 30.  0,0 coordinates mean only set aggression
SetTeamOrder(side, team, index, value)

//removes team order 0 and slides all other entries down
PopTeamOrder(side, team)

//make a list of the units closest to the any member of the team - there is only one list.  Returns the number of units on the list
MakeClosestUnitsToTeamList(side, team, [includeHidden])

//make a list of the units closest to the unit - there is only one list.  Returns the number of units on the list
MakeClosestUnitsToUnitList(id, [includeHidden])

//returns the smallest distance from the tile x,y to any unit in the defined team, or -1 if the team does not exist (or is all dead)
FindDistanceFromTeam(side, team, x, y)

//get the closest unit on the current closest unit list.  -1 if invalid in some way
GetClosestUnit(index)

//Set the destination of this unit.  Must be a valid tile
SetUnitDestination(id, x, y)

//clear out the unit destination (set to -1, -1)
ClearUnitDestination(id)

//return the X unit destination.  -1 for none set
GetUnitDestinationX(id)

//return the Y unit destination.  -1 for none set
GetUnitDestinationY(id)

//set a target for the unit.  -1 for none
SetUnitTarget(id, target_id)

//return the id of the target unit.  -1 for none
GetUnitTarget(id)

//return the team ID of the specificed unit
GetUnitTeam(id)

//set the team value of the specified unit.  team should be [0,7]
SetUnitTeam(id, team)

//returns the number of sides in the game (usually 2)
GetSideCount()

//returns the unit count for the side.  Includes ALL units including those that are dead or inactive.
GetUnitCount(side)

//returns 0 if a unit is dead/hidden/inactive (loaded, etc).  1 otherwise
IsUnitValid(id)

//return the unit id of the Nth unit in a side
GetUnitID(side, index)

//set a route to a dest, but the actual route set is the route which costs <= cost AP.  Always ignores anything on the target tile. set bit 24 of cost to route through units. 25 only team. After minMove steps, path may be truncated due to threat.
SetRouteWithCostWithThreat(id, x, y, cost, threatMapIndex, [reverse], [minMove])

//set a route to a destination, but the actual route set is the route which costs up to the cost value in AP.  Always ignores anything on the target tile.set bit 24 of cost to route through units. 25 only our team
SetRouteWithCost(id, x, y, cost, [reverse])

// Call bonus function on all bonuses assigned to side.  The function is called from a bonus script.  Returns function return value.  If the function is not in the mission, returns -999.  If the fn does not take a param it will be ignored
CallBonusFunction(functionName, side, x, y, unit)

//sets the briefing screen to show to the player, same parameters as ShowUIScreen below. Only valid when called in a scenario BRIEFING_CALLBACK(side) function
SetBriefingScreen(screenName, animName, textTag, [imageTags])

//show the briefing screen (if set up).
ShowBriefing()

//Hides the custom UI if state is 0, otherwise shows it
ShowCustomUI(state)

//returns the ID of a given pairing of set/tile.  -1 means the tile doesn't exist.  These are the internal folder/tile names, not the displayed localised names.  NOTE: this will not be a constant as game data and custom data changes, so don't rely on it.
GetTileID(set, name)

//place a tile in its layer, replacing anything else there.   Rotation is [0,3].  If autoedge is 1, automatically update edging around tile
PlaceTile(x, y, id, rotation, [autoedge])

//return the id of the tile on the tile at the layer.  Returns -1 if nothing there.
GetTileOnTile(layer, x, y)

//remove the denoted tile if it is on the tile.  You cannot remove the layer 0 (non-overlay) tile.  If autoedge is 1, automatically update edging around tile
RemoveTile(x, y, id, [autoedge])

//returns the difficulty mode.  0 for normal, 1 for easy, 2 for fun
GetDiffMode()

//returns 0 or 1 indicating which coop team is currently active, -1 if it is not a coop game or if the AI is active
GetCoopTeam()

//add the object at x,y (in 100ths) to the map.  Returns an id for use with other object functions - not constant across game runs. Returns -1 if not valid object
PlaceObject(x, y, objectSet, objectName)

//return the id of the Nth object on the given tile - not constant across game runs.  Returns -1 if no object at that index, so when you run out of objects.
GetTileObject(x, y, index)

//return the id of the Nth object on the map of the described type.  If objectSet is an empty string then any object matching the objectName will be returned.  Returns -1 if no more are found.  Not case sensitive
GetObjectFromName(objectSet, objectName, index)

//returns 1 if the object is part of the set provided, 0 otherwise.  Not case sensitive.
IsObjectSet(id, setName)

//returns 1 if the object is the type named, 0 otherwise.  Not case sensitive.
IsObjectName(id, objectName)

//set the data in an object, index must be [0,3].
SetObjectData(id, index, value)

//get the data in an object, index must be [0,3].
GetObjectData(id, index)

//change the position of an existing object (in 100ths)
SetObjectPosition(id, x, y)

//change the rotation of an existing object, in 100ths of radians
SetObjectRotation(id, rotation)

//change the scale of an existing object, scale is in 100ths
SetObjectScale(id, scale)

//return the X position of an existing object in 100ths
GetObjectPositionX(id)

//return the Y position of an existing object in 100ths
GetObjectPositionY(id)

//return the rotation of an existing object, in 100ths of radians
GetObjectRotation(id)

//return the scale of an existing object, scale is in 100ths
GetObjectScale(id)

//play an animation on the object. If animName is empty stops animations. flags bit0=loop
ObjectPlayAnimation(id, animName, flags)

//delete the object denoted by the id
DeleteObject(id)

//return the data held by tiles.  index 0 is used in carryover mechanics.  index must be [0,3].  All entries are unsigned bytes [0,255]
GetTileData(x, y, index)

//set the data held by tiles.  index 0 is used in carryover mechanics.  index must be [0,3].  value is an unsigned byte so [0,255]
SetTileData(x, y, index, value)

//return the number of carried over units for the given side from the given mission (first mission is index 0, etc)
GetCarryoverCount(missionIndex, side)

//return a new unit created from the carryover data for the index'th entry in the carryover data.  returns -1 if the unit cannot be created.
AddCarryoverUnit(x, y, missionIndex, side, index)

//return a type index from the carryover data for the index'th entry in the carryover data.  You can then use the GetUnitTypeString/SquadType to investigate.
GetCarryoverUnitTypeIndex(missionIndex, side, index)

//Set the location of the nth man in the unit relative to the center of the tile.  offset is [0, 32], angle is [0, 359].  Only relevant in FORMATION_CALLBACK
SetFormationRow(n, offset, angle)

//Set the location of the nth man in the unit relative to the center of the tile, using offsets when facing 0.  Only relevant in FORMATION_CALLBACK
SetFormationRowXY(n, x, y)

//set the facing of the nth man in the unit. Facing is relative to the unit facing. Use -1 (or zero) to just have the man face in the default direction of the unit as a whole.  Only relevant in FORMATION_CALLBACK
SetFormationFacing(n, facing)

//Generate mapping for current formation points to get the mapping values to indexth WorkArray.  This defines which living man was sent to a given formation point.  Note only for live men, so not a direct mapping to man index. Only valid in FORMATION_CALLBACK
GetFormationMapping(index)

//Set the north direction for the compass [0, 359]
SetCompassNorth(angle)

//returns 1 if the game is currently evaluating or executing a reaction shot, 0 otherwise.
IsReaction()

//turn faster movement of AI units on or off. Use if AI units are being moved out of normal sequence. 0 turns off, any other value turns on.
SetAIFastMove(allow)

//enable/disable unit movement interuption if they uncover a new unit or cover tile.  0 means no stopping, non-zero means stop during movement.  Defaults to on.
SetStopOnNew(stop)

//If it exists, call a function from the current scenario script.  Returns 0 or the return value of the called function.  Can ONLY be used to call functions with up to 7 fixed params, as one is used for the name.
TryToCallScenarioFunction(function, [value, ...])

//adds an order to call a fn in the scenario script. params must in the correct order for the function call. String params are NOT supported, only numeric values.
AddCustomOrder(function, [param,...])

//adds an order to call a fn in a given script. params must in the correct order for the function call. String params are NOT supported, only numeric values.
AddCustomOrderInScript(scriptId, function, [param,...])

//try to call the function on all known plugins
CallPluginFunction(function, [value, ...])

//returns the winning side or -1 if the battle has not ended
GetWinner()

//returns the number of casualties on a side
GetCasualties(side)

//returns the number of casualties on a side of a given type (e.g. "Sherman") as per the Name field in the squads file
GetCasualtiesByType(side, type)

//returns the number of casualties on a side of a given type  (e.g. "INFANTRY") as defined in the terrain file
GetCasualtiesBySquadType(side, squadtype)

//enter the AI placement mode.  point must be [0,7] currently.  Marker can be 0 (use the default AI marker) or the ID of a user marker already on the map
PlaceAIPoint(point, marker)

//returns 1 if running in the editor, 0 otherwise.  Useful mainly in plugins as normal script functionality is off in the editor.
InEditor()

//close this plugin.  Can only be used within a plugin script
ClosePlugin()

//return the last unit placed or clicked, or -1 for invalid
GetEditorLastUnit()

//create a scenario file for the current editor scenario. The file is the headerSource followed by the contents of the templateFilename file. If overwrite !=0 then will overwrite any existing file, otherwise not. Returns -1 (failed), 0 (exists), 1 success. See wiki for more details.
WriteScenarioFile(templateFilename, headerSource, overwrite)

//returns 1 if the current mission has already been completed by the player, otherwise 0. No MP use.
HasCompletedCurrentMission()

//returns 1 if the player has completed all missions in the current campaign, otherwise 0. No MP use.
HasCompletedCampaign()

//returns 1 if the player has completed the indicated mission, otherwise 0. No MP use.
HasCompletedMission(index)

//start a battle.  No params means start currently set up Skirmish battle. scenario is the name of the mission (as per the CAMPAIGN.TXT chunks).  Only useful from custom campaign UI.  For first mission of a carryover campaign, set isFirstCarryover to 1 (or 2 to skip the dialog).
StartBattle([scenario], [isFirstCarryover])

//use the current UI string as an additional string to display in the name of the autosave for the current campaign.  So, e.g. set to the name of the current mission.
SetAutosaveString()

//places the scenario name for the currently running scenario into the first work string.  Behaviour if called outside a battle is undefined.
GetScenarioName()

//call IMMEDIATELY before StartBattle to start the battle in hotseat mode.  Note that this state is reset when StartBattle is called.
AllowHotseat()

//switch to a given campaign.  Searches in local campaigns, then in campaigns.  Also accepts a full path using / as seperator.  If called with no params, starts the default skirmish campaign.
StartCampaign(campaignName)

//return the number of campaigns available currently (takes any campaign filtering into account, only useful on or after the campaign selection screen
GetCampaignCount()

//first work string gets pathname for given campaign, the first UI string gets IDS_CAMPAIGN_NAME and the 2nd IDS_CAMPAIGN_TEXT. Places the base campaign name into the 2nd work string (stripped of path). Return value is flags bit0=locked campaign, bit1=is core campaign, bit2=is carryover, bits 16-23 are DLC index if applicable
GetCampaignEntry(index)

//return the number of scenarios in the current campaign, or in the campaign at the provided path if passed in.
GetBattleCount([campaignPath])

//set the first work string with the scenario name for the given battle, and the first UI string with IDS_SCENARIO_<name> if it exists.  If campaignPath is set use it, otherwise the current campaign.
GetBattleEntry(index, [campaignPath])

//reset the campaign screen to its 'campaign list' state.  Useful only when completely replacing the campaign screen, needed when returning to the campaign screen from battle.
ResetCampaignScreen()

//delete a user campaign.  The filename is expected to include the CAMPAIGNS or MULTIPLAYER path element depending upon where the campaign is.  E.g. MULTIPLAYER/MYCAMPAIGN.  NOTE: it is good practice to prompt the user to confirm deletion.
DeleteUserCampaign(filename)

//returns 1 if the current campaign is a carryover campaign, zero otherwise.
IsCarryover()

//return the unit count for the given side.  This is unit in the map data, and can only be used in the PreStartBattle function.  Does NOT count loaded units.
GetMapUnitCount(side)

//returns and id for the n'th map unit from the given side.  index starts at zero.
GetMapUnit(side, index)

//return the x ordinate of the map unit with the given id
GetMapUnitX(id)

//return the y ordinate of the map unit with the given id
GetMapUnitY(id)

//returns -1 if the map unit has no loaded unit, otherwise the unit type index
GetMapUnitLoadedTypeIndex(id)

//load a unit of type on the specified transport
SetMapUnitLoaded(id, type)

//returns the unit type index.  See GetUnitTypeString etc.
GetMapUnitTypeIndex(id)

//return the facing of the given map unit.
GetMapUnitFacing(id)

//set the facing of the given map unit.
SetMapUnitFacing(id)

//return the status of the given map unit
GetMapUnitStatus(id)

//set the status of the given map unit
SetMapUnitStatus(id, status)

//return the team of the given map unit
GetMapUnitTeam(id)

//set the map unit team
SetMapUnitTeam(id, team)

//returns 1 if the given map unit is Fixed, otherwise returns 0
IsMapUnitFixed(id)

//set a map unit as being fixed, if the fixed parameter is !=0, otherwise reset it.
SetMapUnitFixed(id, fixed)

//returns 1 if the given map unit is to be carried over, otherwise returns 0
IsMapUnitCarryover(id)

//sets a map unit as carryover if carryover is !=0 otherwise resets.
SetMapUnitCarryover(id, carryover)

//remove the n'th map unit for the given side.  This INVALIDATES all map unit ids and so you cannot rely on any previously retrieved ids being correct.
RemoveMapUnit(side, index)

//add a unit to the given side.  type should be the type string for the unit. returns the id of the map unit, or -1 if there is an error.
AddMapUnit(side, x, y, type, facing)

//place a tile from the specified style and group in its layer, replacing anything else there.  If autoedge is 1, automatically update edging around tile
PlaceTileByType(x, y, style, group, [autoedge])

//place an object from the specified style and group. x and y are in 100ths. If an alternateStyle is specified, it will be used if the primary style does not contain an appropriate object
PlaceObjectByType(x, y, style, group, [alternateStyle])

//place an object from the specified style with the specified name. x and y are in 100ths. If an alternateStyle is specified, it will be used if the primary style does not contain an appropriate object
PlaceObjectByStyle(x, y, style, name, [alternateStyle])

//set the map style by name
SetMapStyle(style)

//place the current map style string into the first work string.
GetMapStyle()

//returns the number of map styles, styles are set in work strings (see GetWorkString)
GetMapStyles()

//turn on or off LOS updates. For performance reasons, it may be beneficial to disable LOS updates while making a batch of map changes, but it must be turned back on afterwards
EnableLOSUpdates(enable)

//toggle damage texture for object
SetObjectDamage(id, damaged)

//fill work string 0 with the name of a squad of a given type, side, and costs that also meets numAttribs criteria specified in work arrays 0 (attrib), 1 (value), and 2 (comparison type: -1: <, 0: ==, 1: >, 2: !=, 3 <abs(),99 to 102 special date comp)
FindRandomSquad(side, squadType, minCost, maxCost, numAttribs)

//grant the named bonus to the side
AddBonus(side, bonusName)

//0: none, 1: first side only, 2: both sides
SetDeploymentType(type)

//return the deployment type.
GetDeploymentType(type)

//render a texture to the defined tile. the optional uv params must be in 10000ths. Useful in DRAW_UNIT_TILE_CALLBACK.
DrawUITile(textureFileName, x, y, [startu], [startv], [endu], [endv], [colourString])

//returns the current value of the transient flags item.  This is an item which is NOT saved as part of save or MP games and is set to zero at the start of all battles, whether new or loaded.
GetTransientFlag()

//set the value of the transient flags item.  This is an item which is NOT saved as part of save or MP games and is set to zero at the start of all battles, whether new or loaded.
SetTransientFlag(value)

//returns 1 if the unit would have LOS between the provided tiles, zero otherwise
GetUnitLOSAtTile(id, startx, starty, endx, endy)

//set the flag on the denoted unit which tells the system whether it should be shown when using the 'show next unordered unit' shortcut.
SetHasBeenOrdered(id)

//reset the has been ordered flag for the given unit
ResetHasBeenOrdered(id)

//returns 0 if the has been ordered flag is not set, 1 if the flag is set
GetHasBeenOrdered(id)

//returns the state of the global invalidate all flag.  This is 0 or 1.  Use this (with Set) to prevent global updates from happening when using functions which otherwise would force a (slow) global update.
GetUpdateAllFlag()

//sets the global invalidate flag.  Must be 0 or 1.  Setting this to 1 will force a full global update internally in the code.  Use this with caution, and ideally paired with the GetUpdateAllFlag call to prevent undefined behaviour.
SetUpdateAllFlag(update)

//turns off or on the automatic disabling of the tile display each tick when in the AI turn or replays are running.  set state to 0 for disabling auto-off, 1 for enabling (default)
SetAutoOffTileDisplay(state)

//set the camera to instantly point to the given tile, centering it on the screen
SetCameraPosition(x, y)

//set the camera to instantly point to the given point (defined in 100ths), centering it on the screen
SetCameraPositionPrecise(x, y)

//set how many minutes are incremented each turn, for time of day
SetMinutesPerTurn(value)

//returns 1 if the current game is multiplayer, 0 otherwise
IsMultiplayer()

//returns 1 if the current game is MP and is a tournament game.
IsTournament()

//replace the initial state for MP replay with the current state.  This clears all saved MP orders.  USE WITH CARE.
SetInitialMPState()

//returns 1 if we are currently in a state prior to loading the game state when loading, allowing you to avoid executing script code during this state if you are relying on data from the incoming state.
IsInLoadingPhase()

//returns 1 if we are currently in the replay phase of a MP game. USE WITH CARE: should only be used to affect non-model logic (e.g. UI display) to avoid incorrect replay playback.
IsInReplayPhase()

//returns 1 if we are waiting to send the MP turn to the other player.  At this stage we will be at the initial turn start state, so standard logic may fail.
IsInSendTurnPhase()

//reset the skirmish manager state to the default
SkirmishReset()

//set the map type [0,255]
SkirmishSetType(type)

//set the size [0,4] for presets, or to 99 if you want to set the specific sizes using width and height.
SkirmishSetMapSize(size, [width, height])

//set the style
SkirmishSetStyle(style)

//set the fortification value [0,100]
SkirmishSetFortifications(fortifications)

//set openness value [0,100]
SkirmishSetOpen(open)

//set damage value [0,100]
SkirmishSetDamage(damage)

//set the scenario type value
SkirmishSetScenarioType(type)

//set the force size preset [0,8], or set size to 99 and use side0/1 to set the seperate force sizes.  Note that the force size limits in skirmish UI are still [0,4].
SkirmishSetForceSize(size, [side0, side1])

//set to 0 for no force selection, 1 for all force selection, 2 for mixed
SkirmishSetForceSelection(selection)

//set the turn limit.  Limited to 1000.
SkirmishSetTurnLimit(limit)

//set to 0 for off, nonzero for on
SkirmishSetReinforcements(state)

//set the skirmish date value
SkirmishSetDate(month, year)

//set army lists for use for each side, uses strings which are the chunk names from the armylist file.
SkirmishSetArmyLists(list0, list1)

//set a mask value which denotes which (if any) DLC is required by the skirmish.  Bitfield, DLC 0 is bit 0, DLC 1 bit 1.  Bit 31 is reserved.
SkirmishSetRequired(mask)

//returns a value denoting the kind of skirmish battle in progress. 0 means not skirmish, 1 means skirmish, 2 means skirmish started from a custom campaign (via StartBattle)
GetSkirmishState()

//sets the first 4 values in the first work array with the current skirmish points values (fixed0, fixed1, select0, select1)
GetSkirmishPoints()

//return the type index of a unit based on it's string.  Returns -1 if not found.
GetUnitTypeIndexFromString(name)

//return the string index (ID field from squads file) of a unit based on it's string.  Returns -1 if invalid unit type.
GetUnitStringIndexFromString(name)

//return the string index (ID field from squads file) of a unit based on it's index.  Returns -1 if invalid unit type.
GetUnitStringIndexFromTypeIndex(index)

//return the index of the madeby entry in the current sides file
GetUnitMadebyFromIndex(index)

//place the name of the side in the first work string and return 1.  Returns zero if not a valid index based on the sides file.
GetSideEntry(index)

//init a force control with the give name from the system array. count is the number of entries. System array should hold count entries of the form 8f:8u:16type for fixed/unfixed/unittype. See wiki for more details.
InitForceControl(objectName, count, points)

//fills the first work array with an array containing all the currently chosen units.  Returns the array count.  Entries of the same for as InitForceControl, but unfixed value contains unfixed units chosen.  See wiki for more details.
GetForceControlState(objectName)

//returns the unit type of the currently selected unit for the force control.  -1 if none.
GetForceControlSelection(objectName)

//set the tooltip shown when mousing over the button for the denoted unit type on the force control screen, using the first unicode system string.  Note this only has an effect after the control has been Init'ed.
SetForceControlTooltip(objectName, unitType)

//determine if the force control always shows points. state 0 for no, 1 for yes always show.
SetForceControlAlwaysShowPoints(objectName, state)

//set the selected state of a given unit on tile x,y on the deployment map.  If select is 0 then the unit is unselected, otherwise selected. Note can fail if unit is fixed or not enough points.
SetForceControlSelected(objectName, x, y, select)

//returns 0 if the unit on x,y is unselected, 1 if selected, 2 if fixed, (-1 if no unit is on the tile)
GetForceControlSelected(objectName, x, y)

//set the zoom level for the camera in battle
SetZoom(zoom)

//set the type that the campaign screen filters against, causing it to only show campaigns with the appropriate TYPE value in CAMPAIGNS.TXT (missing tag defaults to zero)
SetCampaignScreenFilter(value)

//retrieves the string from the named object inside the internal campaign screen display into the UI string, if possible
GetCampaignScreenString(objectName)

//tell the system to use a listbox object as the output target for any Log commands.
SetDebugUIObject(objectName)

//get the Nth editor data value from a unit, index currently must be [0,7]
GetEditorData(id, index)

//set the Nth editor data value for a unit, index currently must be [0,7]
SetEditorData(id, index, value)

//if state is 0 then automatic viewing of AI moves is disabled, otherwise it is enabled (default).  Note this resets at the start of each turn.
SetShowAIMoves(state)

//set tesselation (values can be 1,2,or4) and smoothing (same units as the tweak, so in 1000ths) default is 2000.  Rebuilds the map height texture each time it is called.
SetMapTerrainSmoothing(tesselation, smoothing)

//return the points value for the the given side.  NOTE: this actually returns the points available after all fixed units have been purchased.
GetForcePoints(side)

//returns 1 if there are new user content downloads available, 0 otherwise
AreNewDownloads()

//returns 1 if the player owns the given DLC.
OwnsDLC(dlcIndex)

//shows the purchase process for the given DLC.
ShowDLCPurchase(dlcIndex)

//attempt to claim an achievement based on its string id.  Currently supports only Steam achivements.  No effect on non-Steam versions.
ClaimCheevo(id)

//take the textures from the denoted unit and apply them to the mesh shown in the 3D UI object
SetUIObject3DFromUnit(objectName, id)

//set the 4 unit colours on the minimap. Alpha is ignored on all other than coopInvalid which should include it. Zero values cause the default to be used.
SetMinimapColours(side0, side1, selectedUnit, coopInvalid)

//force a minimap refresh if units have been modified.
UpdateMinimap()

//if a mod is selected, place the name of the current mod into the first UI string and return its index, otherwise return -1.  Always returns -1 in multiplayer.
GetCurrentMod()

//close the game and attempt to launch the Empire companion app.
LaunchEmpires()

//returns a value denoting the status of any companion version that is available. -1 means none.
GetEmpiresStatus()

//places the bytes of the first UI string into the given script char array.  This is a pure store, no conversion is done and the resulting char array will not be usable as a string.  The char array must be 2x the size of the required unicode chars (including terminator)
StoreUIString(charArray)

//fetches the bytes from a script char array into the first UI string, or the UI string denoted by the optional index.  If append is != 0 then appends to the existing string.
FetchUIString(charArray, [index], [append])

//replace the given unit with a new unit of the given type.  The unitid will remain the same.  The man count will be set to that of the original unit, as will positions.  Returns -1 if there is a failure.
ReplaceUnit(unitid, typestring)

//do a pass over the men in a unit, causing them to try and play either WAIT or the provided animation.  This can be used to force a call to any custom animation callback in case men have moved in their formation positions. Only applies to alive men.
ResetUnitAnimations(unitID, [animName])

//render the minimap atop the given UI object.
SetUIMinimapTarget(objectName)

//set the value for the UI minimap rendering mode
SetMinimapMode(mode)

//return a random number [min, max] i.e. with a min value of min and a max value of max inclusive.  MUST be multiplayer safe.
Rand(min, max)

//returns the current random seed
GetRandSeed()

//sets the current random seed. USE WITH CAUTION, especially in MP.
SetRandSeed(seed)

//return a random number [min, max] i.e. with a min value of min and a max value of max inclusive.  Can be used for non-multiplayer/visual only tasks which are not multiplayer safe
FXRand(min, max)

//sets the seed for the FX rand calculations.
SetFXRandSeed(seed)

//take a value [0,100] and scale using Sine.  Use to make random values clump around 100 more and be less likely to be 0
SinScale(value)

//Output a string to the debug stream, for debugging.  Can have up to 4 values which will also be logged.
Log(string, [value, value, value, value])

//output a string to the debug log error.log.  Defaults to only writing the string if DebugMode is on, unless always is non-zero
DebugLog(string, [always])

//otuput a string to the output stream visible in the debugger.
OutputDebug(string)

//returns 1 if debug mode is on, otherwise 0
IsDebugMode()

//returns the min of the 2 values
Min(a, b)

//returns the max of the 2 values
Max(a, b)

//return the binary NOT of the provided value.  E.g. (binary) 000110 will return 111001.
Not(a)

//return the absolute value of the param
Abs(a)

//set every byte in the given variable to zero
ZeroVar(variableName)

//set every byte in the given variable (or element) to zero.  Takes the actual variable.
Zero(variable)

//sort the array by the elementName entry (which must be an integer or a char array).  If direction included, 0 is ascending (the default), 1 is descending.
Sort(elementName, array, count, [direction])

//clear out the work array to the specified value.  There are 4 arrays, array 0 is used if none is specified. The work array is a set of 256 ints which can be used as a scratchpad.  Note that all scripts share the same array, so beware of side effects.
ClearArray(value, [array])

//get a value from the specified work array
GetArray(index, [array])

//set a value in the work array
SetArray(index, value, [array])

//perform a sort on one or more arrays using the first count entries.  Sorts the array in ascending order.  If other array indexes are included, keeps them in the same order as the sortArray
SortArray(count, sortArray, [array...])

//IGNORES CASE. returns 1 if the two strings are the same, otherwise 0
StringCompare(string1, string2)

//CASE SENSITIVE.  returns 1 if the two strings are the same, otherwise 0
StringCompareExact(string1, string2)

//IGNORES CASE.  returns 1 if the first count characters of the string are the same, otherwise 0
StringCompareLeft(string1, string2, count)

//make a string of the count characters of the provided string, starting at the start character.  BASE 0 (first character start is 0). index is the working string where the string is placed.
StringSub(string, start, count, [index])

//returns the length in characters of the string
GetStringLength(string)

//return the integer value of the string.  If the string has no valid numeric conversion, 0 is returned.  Input is assumed to be in base 10 (decimal) if no base is provided.
StringToInt(string, [base])

//returns the index of the first array item containing and element called elementName which is the search string.  elementName is a string entry, array is the variable array itself, if isSorted is != 0 the array is assumed to already be sorted in ascending order by elementName
FindStringInArray(string, elementName, array, [isSorted])

//returns the index of the first array item containing and element called elementName which equals the search value.  elementName is the name of the struct element as a string, array is the variable array itself, if isSorted is != 0 the array is assumed to already be sorted in ascending order by elementName
FindInArray(value, elementName, array, [isSorted])

//return the value of the value stored in the options file.  index [0,31] Can be used for global flags to define behaviour.
GetOptionValue(index)

//set the value into the options file.  index [0,31]
SetOptionValue(index, value)

//get the value of one of the entries in the options file.
GetOption(string)

//set the value of one of the entries in the options file.  Will still be limited by the options limits.
SetOption(string, value)

//play a specific UI sample. can optionally specify a bank to play from
PlayUISFX(sfx, [bank])

//begin a new UI string construction, index must be [0,15] to use one of the 16 different UI strings, zero is used if no index provided
StartString([index])

//add the string defined by the string id to the current UI string construct
PrintString(stringID, [index])

//add the string defined by the string id to the current UI string construct (e.g. IDS_STRING0 would be accesed by (IDS_STRING, 0)
PrintStringIndexed(stringID, stringIndex, [index])

//print the contents of string into the UI string construct (mainly for spacing, newlines etc)
PrintStringLiteral(string, [index])

//print the value into the UI construct string
PrintInt(value, [index])

//returns the UI string height in the requested font
GetStringHeight(font, [index])

//copy one UI string to another by index
CopyString(sourceIndex, destIndex)

//version of printf for the UI strings into string 0. Max 9 variable params. %d (or %x) is number, %s assumes string is string identifier, %i expects 2 params the string identifier and an index, %u is index of another UI string, %w is index of a working string. Implied StartString.
Print(formatString, [...])

//same as Print other than takes an index to the UI string to print to.
PrintTo(index, formatString, [...])

//same as Print other than take an index to the UI string AND also adds the printed string to the end of the existing UI string, whatever it may be.
PrintCat(index, formatString, [...])

//append one UI string to another by index (destination is 0 if unspecified)
PrintStringToString(sourceIndex, [destIndex])

//IGNORES CASE. returns 1 if the two UI strings are the same, otherwise 0
CompareUIString(index1, index2)

//CASE SENSITIVE.  returns 1 if the two UI strings are the same, otherwise 0
CompareUIStringExact(index1, index2)

//IGNORES CASE.  returns 1 if the first count characters of the UI strings are the same, otherwise 0
CompareUIStringLeft(index1, index2, count)

//IGNORES CASE.  Returns 1 if the index1 string contains the index2 string
CompareUIStringString(index1, index2)

//returns the length of a UI string, zero is used if no index provided
GetUIStringLength([index])

//begin a new work string construction.  This is for building filenames etc.  Up to 16 strings, uses 0 if no index
StartWorkString([index])

//print a literal to the work string
PrintWorkStringLiteral(string, [index])

//print an integer to the work string
PrintWorkStringInt(value, [index])

//return the work string to any function which takes a string argument
GetWorkString([index])

//version of printf for the work strings into string 0. %d is number, %s is for strings, %#F is for fixed point where # is the number of digits to shift (default 2). Implied StartWorkString.
PrintWork(formatString, [...])

//copy one work string to another by index
CopyWorkString(sourceIndex, destIndex)

//print into a string variable. Is overflow safe (destination will not be overflowed if too many chars are written, but will be cut off). %#F is for fixed point where # is the number of digits to shift (default 2).
sprintf(destination, formatString, [...])

//copy string into another string variable. Is overflow safe (destination will not be overflowed if too many chars are written, but will be cut off)
strcpy(destination, source)

//append source to destination. Is overflow safe (destination will not be overflowed if too many chars are written, but will be cut off)
strcat(destination, source)

//returns 1 if the key is down, 0 if not.  Valid values are 0 (shift), 1 (control)
IsModKeyDown(keyID)

//returns 1 if the UI object with the objectName has the provided id.  Use in the handler function to see which object has been actioned
IsUIObject(id, objectName)

//sets the UI object to have the system string (from StartString etc) as its string property (if relevant)
SetUIObjectString(objectName)

//gets the UI object string in UI string 0 (if relevant)
GetUIObjectString(objectName)

//sets the UI object to have the system string (from StartString etc) as its tooltip property (if relevant)
SetUIObjectTooltip(objectName)

//enable or disable the UI object, disable if state = 0, otherwise enable
SetUIObjectEnabled(objectName, state)

//return 1 if the object is enabled, 0 otherwise
GetUIObjectEnabled(objectName)

//hide or reveal the object.  Hidden if state = 0, shown otherwise
SetUIObjectVisible(objectName, state)

//set the texture of the provided object, if possible.  If no path, comes from UI\TEXTURES (campaign or core)
SetUIObjectTexture(objectName, textureName, [path])

//return 1 if the object is visible, zero otherwise
GetUIObjectVisible(objectName)

//cause a UI object to 'bounce' in size
SetUIObjectBounce(objectName)

//set the text colour of a UI object, if applicable
SetUIObjectTextColour(objectName, colour, [borderColour])

//get the text colour of a UI object as an ARGB int, if applicable
GetUIObjectTextColour(objectName)

//set the image colour of a UI object, if applicable
SetUIObjectImageColour(objectName, colour)

//get the image colour of a UI object as an ARGB int, if applicable
GetUIObjectImageColour(objectName)

//show a tip using the current UI string.  The string is made up of two parts, title and body text, seperated by a # symbol.  e.g. tip title#this is the tip text
ShowSystemTip()

//show an arrow pointing to the object. x,y start pt in 1024x768.  all vars in 1000ths, extent [0,1000] to animate
ArrowUIObject(objectName, x, y, colourString, borderString, size, flare, curve, extent)

//within the given screen object, select the object with the specified groupIndex value from the given group, deselecting all others
SetUIGroupSelection(screen, group, groupIndex)

//return the groupIndex of the selected object of the given group within the specified screen object
GetUIGroupSelection(screen, group)

//clear a listbox UI object and reset its selection. numberOfItems pre-allocates space for that many items, speeding up large list filling.
ClearUIListbox(objectName, [numberOfItems])

//add an item to a listbox using the current string. colour is a string hex value, tooltipIndex is the index of the string containing the tooltip (-1 if none). data is a user data item passed as DATA to the script fn (note, stored unsigned).
AddUIListboxItem(objectName, [colour], [tooltipIndex], [data], [icon], [sortData])

//get the index of the currently selected item for a listbox, returns -1 if none
GetUIListboxItem(objectName)

//return 1 if the specified item is selected, zero otherwise
IsUIListboxItemSelected(object, index)

//returns the number of items in a listbox
GetUIListboxCount(object)

//sets whether the list is a multiselection list.
SetUIListboxMultiSelect(object, multiselect)

//sets whether the list is a hotkey enabled multiselection list.
SetUIListboxHotkeyMultiSelect(object, hotkey)

//set the tooltip of the UI list box item at the index with the UI string
SetUIListboxItemTooltip(objectName, index)

//set the index of the currently selected item for a listbox, use -1 for none selected, if add != 0 and the list is multiselectable, add to the current selection, if value is specified, 0 will remove the selection from the index
SetUIListboxItem(objectName, index, [add], [value])

//move the UI listbox to show the given item index.  Scrolls unless immediate is non-zero, in which case it instantly changes the view
ShowUIListboxItem(objectName, index, [immediate])

//return the data value passed in when an item was created.
GetUIListboxItemData(objectName, itemIndex)

//return the text from the list entry into the first UI string.
GetUIListboxItemText(objectName, itemIndex)

//sort existing items in the listbox. direction: 0 ascending (default), 1 descending. sortBy: 0 sort by item display string (default), 1 sort by item data, 2 sort by item sortData, 3 sort by item sortData then by display string
SortUIListbox(objectName, [direction], [sortBy])

//set a listbox to be a tab (\t) delimited table. Table headers (also tab delimited) are read from UI string 0. Can be used to change headers on an existing table.
SetUIListboxTable(objectName)

// update the contents of a listbox item, using the first UI string
UpdateUIListboxItem(objectName, itemIndex, [colour], [tooltipIndex], [data], [icon], [sortData])

//Trigger an object as if it has been actioned.  event denotes which 'mouse event' has occurred in case it matters to the receiving object.  0 for LMB, 1 for RMB.
TriggerUIObject(objectName, event)

//trigger a UI custom command.  These are numeric values which vary on a per-flavour basis.
TriggerUICommand(command)

//move the named UI object to the x,y position (in 1024x768 coordinates)
PlaceUIObject(objectName, x, y)

//place the name of the UI object described by the id into the first working string and return 1.  If the object does not exist, returns 0.
GetUIObjectName(id)

//set the user data of the denoted object
SetUIObjectUserData(objectName, data)

//return the user data of the denoted object
GetUIObjectUserData(objectName)

//cause a call to the UI_OBJ_EVENT function on all active UI screens. objectName should be the name of a UI object, passed to UI_OBJ_EVENT as an id.  The other values are passed through.
UIEvent(objectName, event, data)

//show the UI object screen, setting up with text of the form textTag_objName for each object.  Image tags are 1 or more obj:file pairs seperated by a $
ShowUIScreen(screenName, animName, textTag, [imageTags])

//show a UI object screen.  The userdata value on the screen is set to the value passed in data
ShowUIDialog(screenName, data)

//hide a UI screen which is showing
HideUIScreen(screenName)

//disable all UI screens (you should follow this with some enabled UI screens!)
DisableUIAll()

//returns 1 if the screen is active, 0 otherwise.
IsUIScreenActive(screenName)

//Set the size of the named UI object. flags: bit0=keep the central position of the UI object, bit1=maintain aspect ratio.
SetUIObjectSize(objectName, width, height, [flags])

//return any value set via UI files for the given UI object.  index must be [0,7].
GetUIObjectValue(objectName, index)

//move named UI object gradually to the x,y position (in 1024x768 coordinates).
SetUIObjectMove(objectName, x, y, speed)

//returns 1 if any UI objects are still moving from the use of the SetUIObjectMove command
IsUIObjectMoving()

//if filename starts with # then defaults to standard unit loading paths.
UIObject3DLoad(objectName, filename, [texturePath])

//automatically set the zoom and camera origin to the size of the currently loaded object
UIObject3DAuto(objectName)

//set the origin position and vertical angle of the camera.  Optionally change the zoom. xyz are in 100ths
SetUIObject3DCamera(objectName, x,y,z,angle,[zoom])

//set the options for the view.  0 for off, nonzero for on.
SetUIObject3DOptions(objectName, allowZoom, allowHorizontalRotate, allowVerticalRotate)

//set the rotation angle for the 3D view
SetUIObject3DRotation(objectName, angle)

//set the zoom for the given 3D view
SetUIObject3DZoom(objectName, zoom)

//get the zoom for the given 3D view
GetUIObject3DZoom(objectName)

//play an animation, which must be set up in the standard text file. If index then it will play a specific anim (if it exists) otherwise random. Loops if loop is != 0, defaults on
SetUIObject3DAnim(objectName, animName, [loop, index])

//set the per-axis tilts for the model, in 100ths of degrees. Note the rotations are applied in xyz order.
SetUIObject3DTilt(objectName, x, y ,z)

//set the lighting direction xyz (a vector in 100ths) and the light colour and ambient colour for the control.
SetUIObject3DLighting(objectName, x, y, z, colour, ambient)

//set the 4 shader values for register 30 (random uvs etc), in 100ths.
SetUIObject3DShaderValues(objectName, a, b, c ,d)

//set a button to be visibly selected
SetUIButtonSelected(objectName, isSelected)

//returns 1 if the button is selected, 0 otherwise
GetUIButtonSelected(objectName)

//get the x coordinate (out of 1024, approximated) of the UI object, if relative != 0 the coordinate is relative to its parent
GetUIObjectX(objectName, [relative])

//get the y coordinate (out of 768, approximated) of the UI object, if relative != 0 the coordinate is relative to its parent
GetUIObjectY(objectName, [relative])

//get the width (out of 1024, approximated) of the UI object
GetUIObjectWidth(objectName)

//get the height (out of 768, approximated) of the UI object
GetUIObjectHeight(objectName)

//places the contents of the edit box into the first UI string.
GetUIEditbox(objectName)

//takes the contents of the UI editbox and converts them to a string.  If there are any non-numeric characters in the string, then the return value is invalidValue.  Skips leading and trailing whitespace.
GetUIEditboxToInt(objectName, invalidValue)

//render the string to the screen. colourString is a hex value (as is borderColourString if used, 0 for not used). Returns the text height in the lower 16 bits and the width in the upper 16 bits. alignment is "RIGHT" or "CENTER"
DrawString(x, y, font, colourString, [borderColourString], [width], [height], [alignment])

//render an image based on its filename (UI/TEXTURES base dir unless path is given. Negative width/height flips. Use keepSquare = 1 to preserve aspect ratio of the image)
DrawImage(x, y, width, height, colourString, imageName, [keepSquare], [path])

//play the animation on the denoted UI screen (the objectName must be the root object of the screen).
PlayUIAnimation(objectName, animationName)

//returns 1 if the UI object exists, 0 otherwise.
DoesUIObjectExist(objectName)

//set the current tab of a UITab object
SetUITabIndex(objectName, index)

//set the checked state of a checkbox. Zero for unchecked, non-zero for checked.
SetUICheckbox(objectName, state)

//get the checked state of a checkbox. Zero for unchecked, 1 for checked.
GetUICheckbox(objectName)

//set the progress [0, 100] state of a progress bar.
SetUIProgress(objectName, progressPct)

//return the position of the given progress UI control [0,100]
GetUIProgress(objectName)

//add or update data to a BARCHART or PIECHART UI object, category name is taken from UI string 0, for a BARCHART multiple values can be given to show multiple bars in a category, returns index of data
SetUIChartData(objectName, value, [valueN], ...)

//set the colour for the bar within a category in a BARCHART by index and takes the description of the bar from UI string 0 OR sets the colour of a slice in a PIECHART by index
SetUIChartColours(objectName, index, colour)

//sets an arbitrary maximum value for the chart's bars to be sized to. If this is set the bars will be sized in relation to this value instead of their maximum.
SetUIChartScaleChartToValue(objectName, maxValue)

//sets the axis lines to be drawn. On by default, on is any non zero parameter passed, off 0.
SetUIChartShowAxisLines(objectName, showAxisLines)

//sets the data strings to be drawn. On by default, on is any non zero parameter passed, off 0.
SetUIChartShowDataStrings(objectName, showDataStrings)

//adds spacing between bars. On by default, on is any non zero parameter passed, off 0.
SetUIChartSpaceBarsOut(objectName, spaceBarsOut)

//set the title, horizontal label, and vertical label (when applicable) for a chart
SetUIChartLabels(objectName, titleStringTag, [horizLabelStringTag], [vertLabelStringTag])

//sort existing data in a BARCHART or PIECHART UI by category. direction: 0 ascending (default), 1 descending. numeric: 0 sort category names alphabetically (default), 1 treat category names as numbers (ie "2" < "10")
SortUIChartData(objectName, [direction], [numeric])

//clear data from a BARCHART or PIECHART UI object
ClearUIChartData(objectName)

//set scrollable text to scroll immediately to the top (scrollTo 0) or bottom (scrollTo 1)
SetUITextScroll(objectName, scrollTo)

//tell the given object to request UI focus
SetUIFocus(objectName)

//set the font that a given UI object will use. Font is index in the font list. CURRENTLY ONLY WORKS FOR TEXT OBJECTS AND BUTTONS.
SetUIObjectFont(objectName, font)

//returns 1 if this update is an animation update (30fps), zero otherwise.
GetAnimUpdate()

//return the width of the screen in pixels.
GetScreenWidth()

//return the height of the screen in pixels.
GetScreenHeight()

//get the actual x coordinate of the UI object, if relative != 0 the coordinate is relative to its parent
GetUIObjectXDirect(objectName, [relative])

//get the actual y coordinate of the UI object, if relative != 0 the coordinate is relative to its parent
GetUIObjectYDirect(objectName, [relative])

//get the actual width of the UI object
GetUIObjectWidthDirect(objectName)

//get the actual height of the UI object
GetUIObjectHeightDirect(objectName)

//directly set the screen coordinates of a UI object (not scaled from 1024x768)
SetUIObjectRectDirect(objectName, x, y, width, height)

//render an image based on its filename (UI/TEXTURES base dir unless path is given). Negative width/height.
DrawImageDirect(x, y, width, height, colourString, imageName, [path])

//render the string to the screen. colourString is a hex value (as is borderColourString if used, 0 for not used). Returns the text height in the lower 16 bits and the width in the upper 16 bits. alignment is "RIGHT" or "CENTER"
DrawStringDirect(x, y, font, colourString, [borderColourString], [width], [height], [alignment])

//creates a string of the form IDS_<tagBody>_<number> finding the first empty slot in the string table, and fills it with the contents of the first UI string. If fullTag!=0 then uses the tagBody as is.
AddUserString(tagBody, [fullTag])

//remove the denoted user string from the temporary store.  Has no effect if the string has already been written out to the file.
RemoveUserString(tag)

//flush out any user strings to the TEXT9.TXT file.  NOTE: this is done automatically at map save and editor exit. flushToMain !=0 means work on TEXT9.TXT in the main DATA/TEXT folder (should not be used in release scripts).
FlushUserStrings([flushToMain])

//returns the highest N for which a string exists with the form IDS_<tagBody>_<N>, up to a max of 100000. Returns -1 if none exist.
GetHighestStringIndex(tagBody)

//return 1 if the string exists, 0 otherwise
DoesStringExist(tag)

//get the denoted string into the first UI string if it exists.  Empty otherwise
GetString(tag)

//take the UI string from an editbox object and update it if it has changed (or is new).  Return 1 if a change has been made, zero otherwise.
UpdateUserStringFromUI(objectName, tag)

//returns 1 if the denoted global exists, 0 otherwise.  The script name must be the filename of the script, path is not required.
CheckScriptGlobal(scriptName, globalName)

//return the value of a global from a known script.  The script name must be the filename of the script, path is not required.  If either the script or global cannot be found, zero is returned. Does not autocreate if missing.
GetScriptGlobal(scriptName, globalName)

//set the value of a global from a known script.  The script name is filename of the script, path is not required.  If the script or global not found, zero is returned, otherwise 1.  The return value can be ignored as desired.  Does not autocreate if missing.
SetScriptGlobal(scriptName, globalName, value)

//get the ID of the current script
GetCurrentScriptID()

//call a fn in a given script. params must in the correct order for the function call.
CallFunctionInScript(scriptId, function, [param,...])

//open a parser file for reading. Prefix with a # to force reading from the CORE game folder. Otherwise reads from the current campaign. Assumes a .TXT extension. Returns 0 if fails, otherwise a fileID which is used when reading data from the file. You MUST close the file when you are done.
FromFileOpen(filename)

//close the given parser file.
FromFileClose(fileID)

//returns 1 if the given chunk is present in the file. Returns 0 if the chunk is not present
FromFileFindChunk(fileID, chunk)

//returns 1 if the given tag is present in the chunk in the file. chunk ="" means global chunk. Returns 0 if the tag is not present
FromFileFindTag(fileID, chunk, tag)

//read and return a signed integer value from the denoted parser file. If chunk is an empty string uses the global chunk.  Always returns 0 if the tag does not exist.
FromFileGetValue(fileID, chunk, tag)

//read a string from the given tag. If chunk is an empty string uses the global chunk. The string is placed in the 1st working string, or in the zero-based workingString[index] if included. Returns 1 if the tag exists, zero if not
FromFileGetString(fileID, chunk, tag, [index])

//reads in a number of numeric data elements from a tag.  E.g. TAG 1 2 3 4.  These are placed in the first work array. If chunk is an empty string uses the global chunk.  count is the max number to be read.  The function returns the actual number of data elements read.
FromFileGetData(fileID, chunk, tag, count)

//returns the number of chunks in the file, not including the global chunk
FromFileChunkCount(fileID)

//copies the name of the chunk into the 1st working string, or in the zero-based workingString[index] if included. Returns 1 if successful
FromFileChunkName(fileID, index, [stringIndex])

//search for a tagged string in the chunk where the start of the string matches the given searchString, and place the remainder of the string into workstring[index].  Return 1 if successful.
FromFileFindString(fileID, chunk, tag, search, [index])

//create a text file you can write to in your own local folder, you should not include the .TXT ending (it will be added automatically).  Only a single file can be open for writing at any one time.  Returns 1 if the file is opened successfully, zero otherwise.
WriteFileOpen(filename)

//write out the string to the currently open write file.  Note that only characters [32,127] are valid.  A linefeed will be added to the end of the line.  Max 255 characters are allowed.
WriteFileWriteLine(string)

//close the currently opened write file.  You must ensure you close any open files after you have finished writing to them.
WriteFileClose()

//read from parserfile into a structure. .txt extension not needed. Tries local campaign file, then game folder using same path. Reads chunks in order and entries into var members with same names.  All values are treated as non-array ints.  Returns 0 file not found, otherwise 1.
FromFileToVariable(filename, variableName)

//read from a CSV file into a structure does not assume extension. Tries local campaign file, then game folder using path. Row 1 is comments, Reads element name from row 2, then all other rows are read into destination elements. Variable must be array of structures. ret is -1 on fail, otherwise # of lines read
FromCSVToVariable(filename, variableName)

//returns the current value of the internal millisecond timer. Use for profiling script timing.  Has 28 bits of accuracy and can wrap around.
GetTimingCount()

//returns the owner id of the given region [0,255]
RegionMapGetOwner(objectName, region)

//set the owner [0,255] of the given region [0,255]. Needs RegionMapUpdate to show changes onscreen.
RegionMapSetOwner(objectName, region, owner)

//set the tooltip for the given region [0,255] to the current UI string
RegionMapSetTooltip(objectName, region)

//return the currently selected region
RegionMapGetSelected(objectName)

//set the currently selected region on the map. Needs RegionMapUpdate to show changes onscreen.
RegionMapSetSelected(objectName, region)

//update the onscreen representation of the region map after altering its data
RegionMapUpdate(objectName)

//return the X ordinate of the onscreen center point for the region (as defined in the .DAT file) in 1024x768
RegionMapGetX(objectName, region)

//return the Y ordinate of the onscreen center point for the region (as defined in the .DAT file) in 1024x768
RegionMapGetY(objectName, region)

//return the data as set in the .DAT file or by script.  index can be [0,3]
RegionMapGetData(objectName, region, index)

//return the data as set in BYTEDATA the .DAT file.  index can be [0,15].  Values are [0,255].
RegionMapGetByteData(objectName, region, index)

//set the data for the given region.  index can be [0,3]
RegionMapSetData(objectName, region, index, value)

//returns the region of the map the mouse is currently pointing to, or -1 if the mouse is not over the control
RegionMapGetMouseRegion(objectName)

//set up a variable edit control with the structure you want to edit. The customFilename points to a file which allows setup of custom entry positioning/fonts and other details. See wiki.
VariableEditSetStruct(objectName, structName, [customFilename])

//fill the edit control with the values from the given variable.  Requires the variable name string, not the variable itself.
VariableEditSetVariable(objectName, variableName)

//use the edit control to set the values of a given variable.  Requires the variable name string, not the variable itself.
VariableEditGetVariable(objectName, variableName)

//save the contents of a variable (passed by string name, not variable itself) to a file. Prefix filename with a # to force save to CORE, otherwise saves to the current campaign folder. Empty filename will use a global data file in the user folder, see wiki.
SaveVariableData(variableName, filename)

//load the contents of a variable (passed by string name, not variable itself) from a file.  Only data which matches the naming etc of the destination will be loaded. Prefix filename with a # to force load from CORE, otherwise loads from the current campaign folder. Empty filename will use a global data file in the user folder, see wiki.
LoadVariableData(variableName, filename)

//save the contents of a variable (passed by string name, not variable itself) to a file as binary data. Prefix filename with a # to force save to CORE, otherwise saves to the current campaign folder. WARNING: no layout or type data is saved.
SaveVariableAsBinary(variableName, filename)

//load into a var (string name, not var itself) as binary data. size is read size into var, count is num of reads, offset is initial offset into file, step amount to step after each read. # filename pref force load from CORE, other loads from campaign.
LoadVariableAsBinary(variableName, filename, size, count, offset, step)

//read a parser file to the named var (must be an array of structs). Only int values currently supported. Numbered chunks (base 0) are read to the corresponding array element in the named array. Each value is read to corresponding item in the structure.  See wiki for details.
LoadVariableFromParserFile(variableName, filename)

//set a music file to be loaded and used. Looks in local then core files. A ? as filename means leave the existing music entry.
SetMusicFile(filename)

//switch to the denoted music track.  Must be [0,5] currently as per the MUSIC.TXT file order. If force is non-zero then the track will be restarted even if already playing (e.g. if you have changed the music files).
SwitchMusic(track [,force])

//show a confirm popup using UI string 0, and callback the given function with the result (see wiki for details) empty string for no callback. flags denote the buttons to show, zero for off, 1 for on, for OK and Cancel buttons for bits 0 and 1 respectively
ShowConfirm(callbackFunction, [flags])

//return the currently set volume. type 0=music, 1=sfx.  Volume values [0,127]
GetVolume(type)

//set the volume. type 0=music, 1=sfx.  Volume values [0,127]
SetVolume(type, volume)

//set the gamma value, if possible.  gamma is in 1000ths.
SetGamma(gamma)

//returns 1 if the current setup allows for gamma adjustment (e.g. driver support, or because gamma requires fullscreen).
AllowsGamma()

