_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

Classes
script_unit.cpp File Reference
#include "stratagus.h"
#include "unit.h"
#include "actions.h"
#include "animation.h"
#include "commands.h"
#include "construct.h"
#include "interface.h"
#include "map.h"
#include "netconnect.h"
#include "network.h"
#include "pathfinder.h"
#include "player.h"
#include "script.h"
#include "spells.h"
#include "trigger.h"
#include "unit_find.h"
#include "unit_manager.h"
#include "unittype.h"
#include "upgrade.h"

Classes

class  HasSameUnitTypeAs
 

Functions

script_unit.cpp - The unit ccl functions.
unsigned CclGetResourceByName (lua_State *l)
 Get resource by name. More...
 
static int CclSetTrainingQueue (lua_State *l)
 
static int CclSetBuildingCapture (lua_State *l)
 
static int CclSetRevealAttacker (lua_State *l)
 
static int CclResourcesMultiBuildersMultiplier (lua_State *l)
 
static CUnitCclGetUnit (lua_State *l)
 
CUnitCclGetUnitFromRef (lua_State *l)
 For saving lua state. More...
 
static void CclParseOrders (lua_State *l, CUnit &unit)
 
static int CclUnit (lua_State *l)
 
static int CclMoveUnit (lua_State *l)
 
static int CclRemoveUnit (lua_State *l)
 
static int CclCreateUnit (lua_State *l)
 
static int CclTransformUnit (lua_State *l)
 
static int CclDamageUnit (lua_State *l)
 
static int CclSetResourcesHeld (lua_State *l)
 
static int CclSetTeleportDestination (lua_State *l)
 
static int CclOrderUnit (lua_State *l)
 
static int CclKillUnit (lua_State *l)
 
static int CclKillUnitAt (lua_State *l)
 
static int CclGetUnits (lua_State *l)
 
static int CclGetUnitsAroundUnit (lua_State *l)
 
static int CclGetUnitBoolFlag (lua_State *l)
 
static int CclGetUnitVariable (lua_State *l)
 
static int CclSetUnitVariable (lua_State *l)
 
static int CclSlotUsage (lua_State *l)
 
static int CclSelectSingleUnit (lua_State *l)
 
static int CclFindNextResource (lua_State *l)
 
static int CclEnableSimplifiedAutoTargeting (lua_State *l)
 
void UnitCclRegister ()
 register CCL units features More...
 

Function Documentation

◆ CclCreateUnit()

static int CclCreateUnit ( lua_State *  l)
static

Description

Create a unit and place it on the map

Parameters
lLua state.
Returns
Returns the slot number of the made unit.

Example:

CreateUnit("unit-human-transport", 1, {94, 0})

◆ CclDamageUnit()

static int CclDamageUnit ( lua_State *  l)
static

Description

Damages unit, additionally using another unit as first's attacker

Parameters
lLua state.
Returns
Returns the slot number of the made unit.

Example:

– Make a grunt for player 5 grunt = CreateUnit("unit-grunt", 5, {58, 8}) – Damage the grunt with 15 points DamageUnit(-1,grunt,15)

◆ CclEnableSimplifiedAutoTargeting()

static int CclEnableSimplifiedAutoTargeting ( lua_State *  l)
static

Enable/disable simplified auto targeting

Parameters
lLua state.
Returns
0 for success, 1 for wrong type;

◆ CclFindNextResource()

static int CclFindNextResource ( lua_State *  l)
static

Find the next reachable resource unit that gives resource starting from a worker. Optional third argument is the range to search.

Parameters
lLua state.

Example:

peon = CreateUnit("unit-peon", 5, {58, 8}) goldmine = FindNextResource(peon, 0)

◆ CclGetResourceByName()

unsigned CclGetResourceByName ( lua_State *  l)

Get resource by name.

Get the resource ID from a SCM object.

Parameters
lLua state.
Returns
the resource id

◆ CclGetUnit()

static CUnit* CclGetUnit ( lua_State *  l)
static

Get a unit pointer

Parameters
lLua state.
Returns
The unit pointer

◆ CclGetUnitBoolFlag()

static int CclGetUnitBoolFlag ( lua_State *  l)
static

Get the value of the unit bool-flag.

Parameters
lLua state.
Returns
The value of the bool-flag of the unit.

◆ CclGetUnitFromRef()

CUnit* CclGetUnitFromRef ( lua_State *  l)

For saving lua state.

Get a unit pointer from ref string

Parameters
lLua state.
Returns
The unit pointer

◆ CclGetUnits()

static int CclGetUnits ( lua_State *  l)
static

Description

Get a player's units

Parameters
lLua state.
Returns
Array of units.

Example:

– Get units from player 0 units = GetUnits(0) for i, id_unit in ipairs(units) do print(id_unit) end

◆ CclGetUnitsAroundUnit()

static int CclGetUnitsAroundUnit ( lua_State *  l)
static

Description

Get a player's units in rectangle box specified with 2 coordinates

Parameters
lLua state.
Returns
Array of units.

Example:

circlePower = CreateUnit("unit-circle-of-power", 15, {59, 4}) – Get the units near the circle of power. unitsOnCircle = GetUnitsAroundUnit(circle,1,true)

◆ CclGetUnitVariable()

static int CclGetUnitVariable ( lua_State *  l)
static

Description

Get the value of the unit variable.

Parameters
lLua state.
Returns
The value of the variable of the unit.

Example:

– Make a grunt for player 5 grunt = CreateUnit("unit-grunt", 5, {58, 8}) – Take the name of the unit unit_name = GetUnitVariable(grunt,"Name") – Take the player number based on the unit player_type = GetUnitVariable(grunt,"PlayerType") – Take the value of the armor armor_value = GetUnitVariable(grunt,"Armor") – Show the message in the game. AddMessage(unit_name .. " " .. player_type .. " " .. armor_value)

◆ CclKillUnit()

static int CclKillUnit ( lua_State *  l)
static

Description

Kill a unit

Parameters
lLua state.
Returns
Returns true if a unit was killed.

Example:

– Kills an ogre controlled by player 3 KillUnit("unit-ogre", 3)

◆ CclKillUnitAt()

static int CclKillUnitAt ( lua_State *  l)
static

Description

Kill a unit at a location

Parameters
lLua state.
Returns
Returns the number of units killed.

Example:

– Kill 8 peasants controlled by player 7 from position {27,1} to {34,5} KillUnitAt("unit-peasant",7,8,{27,1},{34,5})

◆ CclMoveUnit()

static int CclMoveUnit ( lua_State *  l)
static

Move a unit on map.

Parameters
lLua state.
Returns
Returns the slot number of the made placed.

Example:

– Create the unit footman = CreateUnit("unit-footman", 0, {7, 4}) – Move the unit to position 20 (x) and 10 (y) MoveUnit(footman,{20,10})

◆ CclOrderUnit()

static int CclOrderUnit ( lua_State *  l)
static

Description

Order a unit

Parameters
lLua state.

OrderUnit(player, unit-type, start_loc, dest_loc, order)

Example:

– Move transport from position x=94,y=0 to x=80,y=9 OrderUnit(1,"unit-human-transport",{94,0},{80,9},"move")

◆ CclParseOrders()

static void CclParseOrders ( lua_State *  l,
CUnit unit 
)
static

Parse orders.

Parameters
lLua state.
unitUnit pointer which should get the orders.

◆ CclRemoveUnit()

static int CclRemoveUnit ( lua_State *  l)
static

Description

Remove unit from the map.

Parameters
lLua state.
Returns
Returns 1.

Example:

ogre = CreateUnit("unit-ogre", 0, {24, 89})
    AddTrigger(
            function() return (GameCycle > 150) end,
            function()
                    <strong>RemoveUnit</strong>(ogre)
                    return false end -- end of function
    )</code></div>

◆ CclResourcesMultiBuildersMultiplier()

static int CclResourcesMultiBuildersMultiplier ( lua_State *  l)
static

Set cost multiplier to RepairCost for buildings additional workers helping (0 = no additional cost)

Parameters
lLua state.

Example:

– No cost ResourcesMultiBuildersMultiplier(0) – Each builder helping will cost 1 resource ResourcesMultiBuildersMultiplier(1) – Each builder helping will cost 10 resource ResourcesMultiBuildersMultiplier(10)

◆ CclSelectSingleUnit()

static int CclSelectSingleUnit ( lua_State *  l)
static

Description

Select a single unit

Parameters
lLua state.
Returns
0, meaning the unit is selected.

Example:

– Make the hero unit Grom Hellscream for player 5 grom = CreateUnit("unit-beast-cry", 5, {58, 8}) – Select only the unit Grom Hellscream SelectSingleUnit(grom)

◆ CclSetBuildingCapture()

static int CclSetBuildingCapture ( lua_State *  l)
static

Set capture buildings

Parameters
lLua state.
Returns
The old state of the flag

Example:

SetBuildingCapture(true) SetBuildingCapture(false)

◆ CclSetResourcesHeld()

static int CclSetResourcesHeld ( lua_State *  l)
static

Set resources held by a unit

Parameters
lLua state.

◆ CclSetRevealAttacker()

static int CclSetRevealAttacker ( lua_State *  l)
static

Set reveal attacker

Parameters
lLua state.
Returns
The old state of the flag

Example:

SetRevealAttacker(true) SetRevealAttacker(false)

◆ CclSetTeleportDestination()

static int CclSetTeleportDestination ( lua_State *  l)
static

Set teleport deastination for teleporter unit

Parameters
lLua state.

◆ CclSetTrainingQueue()

static int CclSetTrainingQueue ( lua_State *  l)
static

Description

Set training queue

Parameters
lLua state.
Returns
The old state of the training queue

Example:

– Training queue available. Train multiple units. SetTrainingQueue(true) – Train one unit at a time. SetTrainingQueue(false)

◆ CclSetUnitVariable()

static int CclSetUnitVariable ( lua_State *  l)
static

Description

Set the value of the unit variable.

Parameters
lLua state.
Returns
The new value of the unit.

Example:

– Create a blacksmith for player 2 blacksmith = CreateUnit("unit-human-blacksmith", 2, {66, 71}) – Specify the amount of hit points to assign to the blacksmith SetUnitVariable(blacksmith,"HitPoints",344) – Set the blacksmiths color to the color of player 4 SetUnitVariable(blacksmith,"Color",4)

◆ CclSlotUsage()

static int CclSlotUsage ( lua_State *  l)
static

Get the usage of unit slots during load to allocate memory

Parameters
lLua state.

◆ CclTransformUnit()

static int CclTransformUnit ( lua_State *  l)
static

Description

'Upgrade' a unit in place to a unit of different type.

Parameters
lLua state.
Returns
Returns success.

Example:

– Make a peon for player 5 peon = CreateUnit("unit-peon", 5, {58, 9}) – The peon will be trasformed into a Grunt TransformUnit(peon,"unit-grunt")

◆ CclUnit()

static int CclUnit ( lua_State *  l)
static

Parse unit

Parameters
lLua state.
Todo:

Verify that vision table is always correct (transporter)

(PlaceUnit() and host-info).

Example:

footman = CreateUnit("unit-footman", 0, {0, 1}) – The unit will appear selected Unit(footman,{"selected"}) – The unit will be considered destroyed Unit(footman,{"destroyed"}) – The unit will be considered removed Unit(footman,{"removed"}) – The unit will be considered as a summoned unit Unit(footman,{"summoned",500}) – The unit will face on south Unit(footman,{"direction",0}) – The unit will be displayed with his 3rd frame Unit(footman,{"frame", 3}) – The footman will have a high sight Unit(footman,{"current-sight-range",9}) – Change the unit color to be the ones from player 1 Unit(footman,{"rescued-from",1})

◆ UnitCclRegister()

void UnitCclRegister ( )

register CCL units features

Register CCL features for unit.

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.