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

script_unittype.cpp File Reference
#include "stratagus.h"
#include "unittype.h"
#include "actions.h"
#include "animation.h"
#include "construct.h"
#include "editor.h"
#include "font.h"
#include "luacallback.h"
#include "map.h"
#include "player.h"
#include "script.h"
#include "sound.h"
#include "spells.h"
#include "ui.h"
#include "unit.h"
#include "unitsound.h"
#include "unit_manager.h"
#include "video.h"

script_unittype.cpp - The unit-type ccl functions.

CUnitTypeVar UnitTypeVar
 
static const char COWARD_KEY [] = "Coward"
 Variables for UnitType and unit. More...
 
static const char BUILDING_KEY [] = "Building"
 
static const char FLIP_KEY [] = "Flip"
 
static const char REVEALER_KEY [] = "Revealer"
 
static const char LANDUNIT_KEY [] = "LandUnit"
 
static const char AIRUNIT_KEY [] = "AirUnit"
 
static const char SEAUNIT_KEY [] = "SeaUnit"
 
static const char EXPLODEWHENKILLED_KEY [] = "ExplodeWhenKilled"
 
static const char VISIBLEUNDERFOG_KEY [] = "VisibleUnderFog"
 
static const char PERMANENTCLOAK_KEY [] = "PermanentCloak"
 
static const char DETECTCLOAK_KEY [] = "DetectCloak"
 
static const char ATTACKFROMTRANSPORTER_KEY [] = "AttackFromTransporter"
 
static const char VANISHES_KEY [] = "Vanishes"
 
static const char GROUNDATTACK_KEY [] = "GroundAttack"
 
static const char SHOREBUILDING_KEY [] = "ShoreBuilding"
 
static const char CANATTACK_KEY [] = "CanAttack"
 
static const char BUILDEROUTSIDE_KEY [] = "BuilderOutside"
 
static const char BUILDERLOST_KEY [] = "BuilderLost"
 
static const char CANHARVEST_KEY [] = "CanHarvest"
 
static const char HARVESTER_KEY [] = "Harvester"
 
static const char SELECTABLEBYRECTANGLE_KEY [] = "SelectableByRectangle"
 
static const char ISNOTSELECTABLE_KEY [] = "IsNotSelectable"
 
static const char DECORATION_KEY [] = "Decoration"
 
static const char INDESTRUCTIBLE_KEY [] = "Indestructible"
 
static const char TELEPORTER_KEY [] = "Teleporter"
 
static const char SHIELDPIERCE_KEY [] = "ShieldPiercing"
 
static const char SAVECARGO_KEY [] = "SaveCargo"
 
static const char NONSOLID_KEY [] = "NonSolid"
 
static const char WALL_KEY [] = "Wall"
 
static const char NORANDOMPLACING_KEY [] = "NoRandomPlacing"
 
static const char ORGANIC_KEY [] = "organic"
 
static const char SIDEATTACK_KEY [] = "SideAttack"
 
static const char SKIRMISHER_KEY [] = "Skirmisher"
 
static const char ALWAYSTHREAT_KEY [] = "AlwaysThreat"
 
static const char ELEVATED_KEY [] = "Elevated"
 
static const char NOFRIENDLYFIRE_KEY [] = "NoFriendlyFire"
 
static const char MAINFACILITY_KEY [] = "MainFacility"
 
static const char HITPOINTS_KEY [] = "HitPoints"
 
static const char BUILD_KEY [] = "Build"
 
static const char MANA_KEY [] = "Mana"
 
static const char TRANSPORT_KEY [] = "Transport"
 
static const char RESEARCH_KEY [] = "Research"
 
static const char TRAINING_KEY [] = "Training"
 
static const char UPGRADETO_KEY [] = "UpgradeTo"
 
static const char GIVERESOURCE_KEY [] = "GiveResource"
 
static const char CARRYRESOURCE_KEY [] = "CarryResource"
 
static const char XP_KEY [] = "Xp"
 
static const char KILL_KEY [] = "Kill"
 
static const char SUPPLY_KEY [] = "Supply"
 
static const char DEMAND_KEY [] = "Demand"
 
static const char ARMOR_KEY [] = "Armor"
 
static const char SIGHTRANGE_KEY [] = "SightRange"
 
static const char ATTACKRANGE_KEY [] = "AttackRange"
 
static const char PIERCINGDAMAGE_KEY [] = "PiercingDamage"
 
static const char BASICDAMAGE_KEY [] = "BasicDamage"
 
static const char POSX_KEY [] = "PosX"
 
static const char POSY_KEY [] = "PosY"
 
static const char POS_RIGHT_KEY [] = "PosRight"
 
static const char POS_BOTTOM_KEY [] = "PosBottom"
 
static const char TARGETPOSX_KEY [] = "TargetPosX"
 
static const char TARGETPOSY_KEY [] = "TargetPosY"
 
static const char RADARRANGE_KEY [] = "RadarRange"
 
static const char RADARJAMMERRANGE_KEY [] = "RadarJammerRange"
 
static const char AUTOREPAIRRANGE_KEY [] = "AutoRepairRange"
 
static const char BLOODLUST_KEY [] = "Bloodlust"
 
static const char HASTE_KEY [] = "Haste"
 
static const char SLOW_KEY [] = "Slow"
 
static const char INVISIBLE_KEY [] = "Invisible"
 
static const char UNHOLYARMOR_KEY [] = "UnholyArmor"
 
static const char SLOT_KEY [] = "Slot"
 
static const char SHIELD_KEY [] = "ShieldPoints"
 
static const char POINTS_KEY [] = "Points"
 
static const char MAXHARVESTERS_KEY [] = "MaxHarvesters"
 
static const char POISON_KEY [] = "Poison"
 
static const char SHIELDPERMEABILITY_KEY [] = "ShieldPermeability"
 
static const char SHIELDPIERCING_KEY [] = "ShieldPiercing"
 
static const char ISALIVE_KEY [] = "IsAlive"
 
static const char PLAYER_KEY [] = "Player"
 
static const char PRIORITY_KEY [] = "Priority"
 
static const std::string shadowMarker = std::string("MARKER")
 
int GetSpriteIndex (const char *SpriteName)
 
unsigned CclGetResourceByName (lua_State *l)
 Get resource by name. More...
 
int ExtraDeathIndex (const char *death)
 Get the suitable animation frame depends of unit's damaged type. More...
 
static void ParseBuildingRules (lua_State *l, std::vector< CBuildRestriction * > &blist)
 
static void UpdateDefaultBoolFlags (CUnitType &type)
 
static int CclDefineUnitType (lua_State *l)
 
static int CclCopyUnitType (lua_State *l)
 
static int CclDefineUnitStats (lua_State *l)
 
CUnitTypeCclGetUnitType (lua_State *l)
 
static int CclUnitType (lua_State *l)
 
static int CclUnitTypeArray (lua_State *l)
 
static int CclGetUnitTypeIdent (lua_State *l)
 
static int CclGetUnitTypeName (lua_State *l)
 
static int CclSetUnitTypeName (lua_State *l)
 
static int CclGetUnitTypeData (lua_State *l)
 
void DefineVariableField (lua_State *l, CVariable *var, int lua_index)
 Cleanup unit-type module. More...
 
static int CclDefineVariables (lua_State *l)
 
static int CclDefineBoolFlags (lua_State *l)
 
static int CclDefineDecorations (lua_State *l)
 
static int CclDefineExtraDeathTypes (lua_State *l)
 
static int CclDefinePaletteSwap (lua_State *l)
 
void UpdateUnitVariables (CUnit &unit)
 Update custom Variables with other variable (like Hp, ...) More...
 
void SetMapStat (std::string ident, std::string variable_key, int value, std::string variable_type)
 
void SetMapSound (std::string ident, std::string sound, std::string sound_type, std::string sound_subtype)
 
void UnitTypeCclRegister ()
 Access unit-type object. More...
 

Function Documentation

◆ CclCopyUnitType()

static int CclCopyUnitType ( lua_State *  l)
static

Description

Copy a unit type.

Parameters
lLua state.

Example:

CopyUnitType("unit-peasant", "unit-peasant-copy")

◆ CclDefineBoolFlags()

static int CclDefineBoolFlags ( lua_State *  l)
static

Define boolean flag.

Parameters
lLua state.

◆ CclDefineDecorations()

static int CclDefineDecorations ( lua_State *  l)
static

Define Decorations for user variables

Parameters
lLua state.
Todo:

modify Assert with luastate with User Error.

continue to add configuration.

◆ CclDefineExtraDeathTypes()

static int CclDefineExtraDeathTypes ( lua_State *  l)
static

Define default extra death types.

Parameters
lLua state.

◆ CclDefinePaletteSwap()

static int CclDefinePaletteSwap ( lua_State *  l)
static

◆ CclDefineUnitStats()

static int CclDefineUnitStats ( lua_State *  l)
static

Description

Parse unit-stats.

Parameters
lLua state.

Example:

DefineUnitStats("unit-berserker", 2, { "HitPoints", {Value = 55, Max = 55, Increase = 0, Enable = true}, "AttackRange", {Value = 5, Max = 6, Increase = 0, Enable = true}, "SightRange", {Value = 7, Max = 7, Increase = 0, Enable = true}, })

◆ CclDefineUnitType()

static int CclDefineUnitType ( lua_State *  l)
static

Description

Parse unit-type.

Parameters
lLua state.

Example:

DefineUnitType("unit-silvermoon-archer", { Name = _("Silvermoon Archer"), Image = {"file", "human/units/elven_archer.png", "size", {72, 72}}, Animations = "animations-archer", Icon = "icon-archer", Costs = {"time", 70, "gold", 500, "wood", 50}, Speed = 10, HitPoints = 45, DrawLevel = 40, TileSize = {1, 1}, BoxSize = {33, 33}, SightRange = 6, ComputerReactionRange = 7, PersonReactionRange = 6, BasicDamage = 4, PiercingDamage = 6, Missile = "missile-arrow", MaxAttackRange = 4, Priority = 75, Points = 60, Demand = 1, Corpse = "unit-human-dead-body", Type = "land", RightMouseAction = "attack", CanAttack = true, CanTargetLand = true, CanTargetSea = true, CanTargetAir = true, LandUnit = true, organic = true, SelectableByRectangle = true, Sounds = { "selected", "archer-selected", "acknowledge", "archer-acknowledge", "ready", "archer-ready", "help", "basic human voices help 1", "dead", "basic human voices dead"} } )

◆ CclDefineVariables()

static int CclDefineVariables ( lua_State *  l)
static

Define user variables.

Parameters
lLua state.

◆ 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

◆ CclGetUnitType()

CUnitType* CclGetUnitType ( lua_State *  l)

Access unit-type object

Parameters
lLua state.

◆ CclGetUnitTypeData()

static int CclGetUnitTypeData ( lua_State *  l)
static

Description

Get unit type data.

Parameters
lLua state.

Example:

– Get the amount of supply from Human Farms supply = GetUnitTypeData("unit-farm","Supply") print(supply)

◆ CclGetUnitTypeIdent()

static int CclGetUnitTypeIdent ( lua_State *  l)
static

Get the ident of the unit-type structure.

Parameters
lLua state.
Returns
The identifier of the unit-type.

◆ CclGetUnitTypeName()

static int CclGetUnitTypeName ( lua_State *  l)
static

Description

Get the name of the unit-type structure.

Parameters
lLua state.
Returns
The name of the unit-type.

Example:

name = GetUnitTypeName("unit-knight") print(name)

◆ CclSetUnitTypeName()

static int CclSetUnitTypeName ( lua_State *  l)
static

Description

Set the name of the unit-type structure.

Parameters
lLua state.
Returns
The name of the unit-type.

Example:

SetUnitTypeName("unit-beast-cry","Doomhammer")

◆ CclUnitType()

static int CclUnitType ( lua_State *  l)
static

Get unit-type structure.

Parameters
lLua state.
Returns
Unit-type structure.

◆ CclUnitTypeArray()

static int CclUnitTypeArray ( lua_State *  l)
static

Get all unit-type structures.

Parameters
lLua state.
Returns
An array of all unit-type structures.

◆ DefineVariableField()

void DefineVariableField ( lua_State *  l,
CVariable var,
int  lua_index 
)

Cleanup unit-type module.

Define the field of the UserDefined variables.

Parameters
lLua state.
varVariable to set.
lua_indexIndex of the table where are the infos

◆ ExtraDeathIndex()

int ExtraDeathIndex ( const char *  death)

Get the suitable animation frame depends of unit's damaged type.

Find the index of a extra death type

◆ GetSpriteIndex()

int GetSpriteIndex ( const char *  SpriteName)

Return the index of the sprite named SpriteName.

Parameters
SpriteNameName of the sprite.
Returns
Index of the sprite. -1 if not found.

◆ ParseBuildingRules()

static void ParseBuildingRules ( lua_State *  l,
std::vector< CBuildRestriction * > &  blist 
)
static

Parse BuildingRules

Parameters
lLua state.
blistBuildingRestriction to fill in

◆ SetMapSound()

void SetMapSound ( std::string  ident,
std::string  sound,
std::string  sound_type,
std::string  sound_subtype 
)

Set the map sound for a unit type

Parameters
identUnit type ident
sound_typeType of the sound
soundThe sound to be set for that type

◆ SetMapStat()

void SetMapStat ( std::string  ident,
std::string  variable_key,
int  value,
std::string  variable_type 
)

Set the map default stat for a unit type

Parameters
identUnit type ident
variable_keyKey of the desired variable
valueValue to set to
variable_typeType to be modified (i.e. "Value", "Max", etc.); alternatively, resource type if variable_key equals "Costs"

◆ UnitTypeCclRegister()

void UnitTypeCclRegister ( )

Access unit-type object.

Register CCL features for unit-type.

◆ UpdateDefaultBoolFlags()

static void UpdateDefaultBoolFlags ( CUnitType type)
static

◆ UpdateUnitVariables()

void UpdateUnitVariables ( CUnit unit)

Update custom Variables with other variable (like Hp, ...)

Update unit variables which are not user defined.

Variable Documentation

◆ AIRUNIT_KEY

const char AIRUNIT_KEY[] = "AirUnit"
static

◆ ALWAYSTHREAT_KEY

const char ALWAYSTHREAT_KEY[] = "AlwaysThreat"
static

◆ ARMOR_KEY

const char ARMOR_KEY[] = "Armor"
static

◆ ATTACKFROMTRANSPORTER_KEY

const char ATTACKFROMTRANSPORTER_KEY[] = "AttackFromTransporter"
static

◆ ATTACKRANGE_KEY

const char ATTACKRANGE_KEY[] = "AttackRange"
static

◆ AUTOREPAIRRANGE_KEY

const char AUTOREPAIRRANGE_KEY[] = "AutoRepairRange"
static

◆ BASICDAMAGE_KEY

const char BASICDAMAGE_KEY[] = "BasicDamage"
static

◆ BLOODLUST_KEY

const char BLOODLUST_KEY[] = "Bloodlust"
static

◆ BUILD_KEY

const char BUILD_KEY[] = "Build"
static

◆ BUILDERLOST_KEY

const char BUILDERLOST_KEY[] = "BuilderLost"
static

◆ BUILDEROUTSIDE_KEY

const char BUILDEROUTSIDE_KEY[] = "BuilderOutside"
static

◆ BUILDING_KEY

const char BUILDING_KEY[] = "Building"
static

◆ CANATTACK_KEY

const char CANATTACK_KEY[] = "CanAttack"
static

◆ CANHARVEST_KEY

const char CANHARVEST_KEY[] = "CanHarvest"
static

◆ CARRYRESOURCE_KEY

const char CARRYRESOURCE_KEY[] = "CarryResource"
static

◆ COWARD_KEY

const char COWARD_KEY[] = "Coward"
static

Variables for UnitType and unit.

◆ DECORATION_KEY

const char DECORATION_KEY[] = "Decoration"
static

◆ DEMAND_KEY

const char DEMAND_KEY[] = "Demand"
static

◆ DETECTCLOAK_KEY

const char DETECTCLOAK_KEY[] = "DetectCloak"
static

◆ ELEVATED_KEY

const char ELEVATED_KEY[] = "Elevated"
static

◆ EXPLODEWHENKILLED_KEY

const char EXPLODEWHENKILLED_KEY[] = "ExplodeWhenKilled"
static

◆ FLIP_KEY

const char FLIP_KEY[] = "Flip"
static

◆ GIVERESOURCE_KEY

const char GIVERESOURCE_KEY[] = "GiveResource"
static

◆ GROUNDATTACK_KEY

const char GROUNDATTACK_KEY[] = "GroundAttack"
static

◆ HARVESTER_KEY

const char HARVESTER_KEY[] = "Harvester"
static

◆ HASTE_KEY

const char HASTE_KEY[] = "Haste"
static

◆ HITPOINTS_KEY

const char HITPOINTS_KEY[] = "HitPoints"
static

◆ INDESTRUCTIBLE_KEY

const char INDESTRUCTIBLE_KEY[] = "Indestructible"
static

◆ INVISIBLE_KEY

const char INVISIBLE_KEY[] = "Invisible"
static

◆ ISALIVE_KEY

const char ISALIVE_KEY[] = "IsAlive"
static

◆ ISNOTSELECTABLE_KEY

const char ISNOTSELECTABLE_KEY[] = "IsNotSelectable"
static

◆ KILL_KEY

const char KILL_KEY[] = "Kill"
static

◆ LANDUNIT_KEY

const char LANDUNIT_KEY[] = "LandUnit"
static

◆ MAINFACILITY_KEY

const char MAINFACILITY_KEY[] = "MainFacility"
static

◆ MANA_KEY

const char MANA_KEY[] = "Mana"
static

◆ MAXHARVESTERS_KEY

const char MAXHARVESTERS_KEY[] = "MaxHarvesters"
static

◆ NOFRIENDLYFIRE_KEY

const char NOFRIENDLYFIRE_KEY[] = "NoFriendlyFire"
static

◆ NONSOLID_KEY

const char NONSOLID_KEY[] = "NonSolid"
static

◆ NORANDOMPLACING_KEY

const char NORANDOMPLACING_KEY[] = "NoRandomPlacing"
static

◆ ORGANIC_KEY

const char ORGANIC_KEY[] = "organic"
static

◆ PERMANENTCLOAK_KEY

const char PERMANENTCLOAK_KEY[] = "PermanentCloak"
static

◆ PIERCINGDAMAGE_KEY

const char PIERCINGDAMAGE_KEY[] = "PiercingDamage"
static

◆ PLAYER_KEY

const char PLAYER_KEY[] = "Player"
static

◆ POINTS_KEY

const char POINTS_KEY[] = "Points"
static

◆ POISON_KEY

const char POISON_KEY[] = "Poison"
static

◆ POS_BOTTOM_KEY

const char POS_BOTTOM_KEY[] = "PosBottom"
static

◆ POS_RIGHT_KEY

const char POS_RIGHT_KEY[] = "PosRight"
static

◆ POSX_KEY

const char POSX_KEY[] = "PosX"
static

◆ POSY_KEY

const char POSY_KEY[] = "PosY"
static

◆ PRIORITY_KEY

const char PRIORITY_KEY[] = "Priority"
static

◆ RADARJAMMERRANGE_KEY

const char RADARJAMMERRANGE_KEY[] = "RadarJammerRange"
static

◆ RADARRANGE_KEY

const char RADARRANGE_KEY[] = "RadarRange"
static

◆ RESEARCH_KEY

const char RESEARCH_KEY[] = "Research"
static

◆ REVEALER_KEY

const char REVEALER_KEY[] = "Revealer"
static

◆ SAVECARGO_KEY

const char SAVECARGO_KEY[] = "SaveCargo"
static

◆ SEAUNIT_KEY

const char SEAUNIT_KEY[] = "SeaUnit"
static

◆ SELECTABLEBYRECTANGLE_KEY

const char SELECTABLEBYRECTANGLE_KEY[] = "SelectableByRectangle"
static

◆ shadowMarker

const std::string shadowMarker = std::string("MARKER")
static

◆ SHIELD_KEY

const char SHIELD_KEY[] = "ShieldPoints"
static

◆ SHIELDPERMEABILITY_KEY

const char SHIELDPERMEABILITY_KEY[] = "ShieldPermeability"
static

◆ SHIELDPIERCE_KEY

const char SHIELDPIERCE_KEY[] = "ShieldPiercing"
static

◆ SHIELDPIERCING_KEY

const char SHIELDPIERCING_KEY[] = "ShieldPiercing"
static

◆ SHOREBUILDING_KEY

const char SHOREBUILDING_KEY[] = "ShoreBuilding"
static

◆ SIDEATTACK_KEY

const char SIDEATTACK_KEY[] = "SideAttack"
static

◆ SIGHTRANGE_KEY

const char SIGHTRANGE_KEY[] = "SightRange"
static

◆ SKIRMISHER_KEY

const char SKIRMISHER_KEY[] = "Skirmisher"
static

◆ SLOT_KEY

const char SLOT_KEY[] = "Slot"
static

◆ SLOW_KEY

const char SLOW_KEY[] = "Slow"
static

◆ SUPPLY_KEY

const char SUPPLY_KEY[] = "Supply"
static

◆ TARGETPOSX_KEY

const char TARGETPOSX_KEY[] = "TargetPosX"
static

◆ TARGETPOSY_KEY

const char TARGETPOSY_KEY[] = "TargetPosY"
static

◆ TELEPORTER_KEY

const char TELEPORTER_KEY[] = "Teleporter"
static

◆ TRAINING_KEY

const char TRAINING_KEY[] = "Training"
static

◆ TRANSPORT_KEY

const char TRANSPORT_KEY[] = "Transport"
static

◆ UNHOLYARMOR_KEY

const char UNHOLYARMOR_KEY[] = "UnholyArmor"
static

◆ UnitTypeVar

CUnitTypeVar UnitTypeVar

◆ UPGRADETO_KEY

const char UPGRADETO_KEY[] = "UpgradeTo"
static

◆ VANISHES_KEY

const char VANISHES_KEY[] = "Vanishes"
static

◆ VISIBLEUNDERFOG_KEY

const char VISIBLEUNDERFOG_KEY[] = "VisibleUnderFog"
static

◆ WALL_KEY

const char WALL_KEY[] = "Wall"
static

◆ XP_KEY

const char XP_KEY[] = "Xp"
static
(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.