Programming robots
Starting with release 011, server admins will be able to program their own robots in addition to designing their own levels. Robots will be coded in Lua, and will will have a number of special functions available to them.
Robot coding is still fluid, and everything is subject to change, but here is a list of commands being implemented for the next alpha release (see forums for the URL):
Contents
getZoneCenterXY( x, y ) - Return point representing center of zone containing point x,y
getGatewayFromZoneToZone( a, b ) - Return point representing fastest way from zone a to zone b. If zones a & b are not neighbors, returns nil
getZoneCount() - Return number of zones
getCurrentZone() - Return current zone that robot is in
getAngle() - Return angle robot is currently facing
getPosXY() - Return x, y of robot
setAngle(ang) - Set robot's angle
setAngleXY(x, y) - Point robot at point x,y
getAngleXY(x, y) - Return angle to point x, y
hasLosXY(x, y) - Return whether or not robot can see point x, y
hasFlag() - Return whether or not robot currently has the flag
getWeapon() - Return currently selected weapon (returns WeaponInfo)
Example:
weap = bot:getWeapon() bot:logprint( weap:getName().." has a range of "..weap:getRange() )
Navigation
findObjects(ObjectType)
getWaypoint(x, y)
Ship control
setThrustAng(angle)
setThrustXY(x, y)
fire()
setWeapon(weapon number)
globalMsg(msg) - Send a message to all players
teamMsg(msg) - Send a message to players on the same team
logprint(msg) - Print msg to game logfile
GameItems
The Lua object structure follows that used by Bitfighter. The GameItems group conisists of RepairItems, Asteroids, ResourceItems, and TestItems. These all share similar properties, and have similar methods. All of these implement the getLoc, getVel, and getRad methods for querying location, velocity, and radius respectively. Some items have additional methods that apply only to them. See below for details on these additional methods.
TestItems
Category: GameItem
getLoc() - Center of testItem (returns point)
getRad() - Radius of testItem (returns number)
getVel() - Speed of testItem (returns point)
Example:
ti = bot:findTestItem() -- Function likely to change vel = it:getVel()
Asteroids
Category: GameItem
getSize() - Index of current asteroid size (0 = initial size, 1 = next smaller, 2 = ...) (returns int)
getSizeCount() - Number of indexes of size we can have (returns int)
getLoc() - Center of asteroid (returns point)
getRad() - Radius of asteroid (returns number)
getVel() - Speed of asteroid (returns point)
Example:
asteroid = bot:findAsteroid() -- Function likely to change target = asteroid:getLoc()
ResourceItems
Category: GameItem
getLoc() - Center of ResourceItem (returns point)
getRad() - Radius of ResourceItem (returns number)
getVel() - Speed of ResourceItem (returns point)
Example:
ri = bot:ResourceItem() -- Function likely to change vel = ri:getVel()
RepairItems
Category: GameItem
getLoc() - Center of RepairItem (returns point)
getRad() - Radius of RepairItem (returns number)
getVel() - Speed of RepairItem (returns point, usually 0,0)
isVis() - Is repair item currently visible? (returns boolean)
Example:
ri = bot:findRepairItem() -- Function likely to change vel = ri:getVel()
Weapon Information
All the WeaponInfo data will remain constant throughout the game. Therefore, if you need some information about a weapon, it might make sense to retrieve it in the bot's header and store it in a local variable rather than instantiating a new WeaponInfo object during every loop of the robot's getMove() method.
Example:
weap = bot:getWeapon() -- Get robot's currently selected weapon bot:logprint( weap:getName().." has a range of "..weap:getRange() )
weap = WeaponInfo( WeaponTurret ) -- Get info about those infernal turrets bot:logprint( weap:getName().." shoots with a speed of "..weap:WeaponTurret()..". Yikes!" )
getName() - Name of weapon ("Phaser", "Triple", etc.) (returns string)
getID() - ID of module (WeaponPhaser, WeaponTriple, etc.) (returns integer)
getRange() - Get range of weapon (units) (returns integer)
getFireDelay() - Delay between shots in ms (returns integer)
getMinEnergy() - Minimum energy needed to use (returns integer)
getEnergyDrain() - Amount of energy weapon consumes (returns integer)
getProjVel() - Speed of projectile (units/sec) (returns integer)
getProjLife() - Time projectile will live (ms) (returns integer, -1 == live forever)
getDamage() - Damage projectile does (0-1, where 1 = total destruction) (returns float)
getCanDamageSelf() - Will weapon damage self? (returns boolean)
getCanDamageTeammate() - Will weapon damage teammates? (returns boolean)
Valid weapon constants are:
WeaponPhaser
WeaponBounce
WeaponTriple
WeaponBurst
WeaponMine
WeaponSpyBug
WeaponTurret
Module Information
Example:
mod = ModuleInfo( ModuleBoost ) bot:logprint( "This is a lame example!" )
getName() - Name of module ("Shield", "Turbo", etc.) (returns string)
getID() - ID of module (ModuleShield, ModuleBoost, etc.) (returns integer)
Valid module constants are:
ModuleShield
ModuleBoost
ModuleSensor
ModuleRepair
ModuleEngineer (may not work at this time)
ModuleCloak
Game Information
You can get information about the current game with the GameInfo object. You only need get this object once, then you can use it as often as you like. It will always reflect the latest data.
Example:
game = GameInfo() -- Create the GameInfo object levelname = game:getLevelName()
Methods available:
getGameType()
getFlagCount()
getWinningScore()
getGameTimeTotal()
getGameTimeRemaining()
getLeadingScore()
getLeadingTeam()
getLevelName()
getGridSize()
getIsTeamGame()
getEventScore(ScoringEvent)
Valid GameType constants are:
BitmatchGame
CTFGame
HTFGame
NexusGame
RabbitGame
RetrieveGame
SoccerGame
ZoneControlGame
Valid ScoringEvent constants are:
KillEnemy
KillSelf
KillTeammate
KillEnemyTurret
KillOwnTurret
CaptureFlag
CaptureZone
UncaptureZone
HoldFlagInZone
RemoveFlagFromEnemyZone
RabbitHoldsFlag
RabbitKilled
RabbitKills
ReturnFlagsToNexus
ReturnFlagToZone
LostFlag
ReturnTeamFlag
ScoreGoalEnemyTeam
ScoreGoalHostileTeam
ScoreGoalOwnTeam
Misc
Some constants available in game:
Game Objects
ShipType
BarrierType
MoveableType
BulletType
ItemType
ResourceItemType
EngineeredType
ForceFieldType
LoadoutZoneType
MineType
TestItemType
FlagType
TurretTargetType
SlipZoneType
HeatSeekerType
SpyBugType
NexusType
BotNavMeshZoneType
RobotType
TeleportType
GoalZoneType
AsteroidType