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

Classes | Macros
unittype.h File Reference
#include "upgrade_structs.h"
#include "unitsound.h"
#include "icons.h"
#include "color.h"
#include "missileconfig.h"
#include "vec2i.h"
#include <climits>
#include <vector>
#include <algorithm>
#include <map>

Go to the source code of this file.

Classes

class  ResourceInfo
 
class  CVariable
 
class  CDecoVar
 
class  CDecoVarBar
 
class  CDecoVarFrame
 
class  CDecoVarText
 
class  CDecoVarSpriteBar
 Sprite contains frame from full (left)to empty state (right). More...
 
class  CDecoVarStaticSprite
 use to show specific frame in a sprite. More...
 
class  CDecoVarAnimatedSprite
 use to show specific frame in a sprite. More...
 
class  CBuildRestriction
 
class  CBuildRestrictionAnd
 
class  CBuildRestrictionAddOn
 
class  CBuildRestrictionOnTop
 
class  CBuildRestrictionDistance
 
class  CBuildRestrictionHasUnit
 
class  CBuildRestrictionSurroundedBy
 
class  CUnitType
 
struct  CUnitType::_portrait_
 Icon to display for this unit. More...
 
struct  CUnitType::BoolFlags
 
class  CUnitTypeVar
 Orc wall. More...
 
struct  CUnitTypeVar::CKeys< SIZE >
 
struct  CUnitTypeVar::CKeys< SIZE >::DataKey
 
struct  CUnitTypeVar::CBoolKeys
 
struct  CUnitTypeVar::CVariableKeys
 

Macros

#define InfiniteRepairRange   INT_MAX
 Units repair range. More...
 
#define MouseActionNone   0
 Right click action. More...
 
#define MouseActionAttack   1
 
#define MouseActionMove   2
 
#define MouseActionHarvest   3
 
#define MouseActionSpellCast   5
 
#define MouseActionSail   6
 
#define CanTargetLand   1
 Which units can it attack. More...
 
#define CanTargetSea   2
 
#define CanTargetAir   4
 

unittype.h - The unit-types headerfile.

#define UnitSides   8
 
#define MaxAttackPos   5
 
enum  GroupSelectionMode { SELECTABLE_BY_RECTANGLE_ONLY = 0, NON_SELECTABLE_BY_RECTANGLE_ONLY, SELECT_ALL }
 
enum  {
  COWARD_INDEX = 0, BUILDING_INDEX, FLIP_INDEX, REVEALER_INDEX,
  LANDUNIT_INDEX, AIRUNIT_INDEX, SEAUNIT_INDEX, EXPLODEWHENKILLED_INDEX,
  VISIBLEUNDERFOG_INDEX, PERMANENTCLOAK_INDEX, DETECTCLOAK_INDEX, ATTACKFROMTRANSPORTER_INDEX,
  VANISHES_INDEX, GROUNDATTACK_INDEX, SHOREBUILDING_INDEX, CANATTACK_INDEX,
  BUILDEROUTSIDE_INDEX, BUILDERLOST_INDEX, CANHARVEST_INDEX, HARVESTER_INDEX,
  SELECTABLEBYRECTANGLE_INDEX, ISNOTSELECTABLE_INDEX, DECORATION_INDEX, INDESTRUCTIBLE_INDEX,
  TELEPORTER_INDEX, SHIELDPIERCE_INDEX, SAVECARGO_INDEX, NONSOLID_INDEX,
  WALL_INDEX, NORANDOMPLACING_INDEX, ORGANIC_INDEX, SIDEATTACK_INDEX,
  SKIRMISHER_INDEX, ALWAYSTHREAT_INDEX, ELEVATED_INDEX, NOFRIENDLYFIRE_INDEX,
  MAINFACILITY_INDEX, NBARALREADYDEFINED
}
 
enum  {
  HP_INDEX = 0, BUILD_INDEX, MANA_INDEX, TRANSPORT_INDEX,
  RESEARCH_INDEX, TRAINING_INDEX, UPGRADINGTO_INDEX, GIVERESOURCE_INDEX,
  CARRYRESOURCE_INDEX, XP_INDEX, KILL_INDEX, SUPPLY_INDEX,
  DEMAND_INDEX, ARMOR_INDEX, SIGHTRANGE_INDEX, ATTACKRANGE_INDEX,
  PIERCINGDAMAGE_INDEX, BASICDAMAGE_INDEX, POSX_INDEX, POSY_INDEX,
  POS_RIGHT_INDEX, POS_BOTTOM_INDEX, TARGETPOSX_INDEX, TARGETPOSY_INDEX,
  RADAR_INDEX, RADARJAMMER_INDEX, AUTOREPAIRRANGE_INDEX, BLOODLUST_INDEX,
  HASTE_INDEX, SLOW_INDEX, INVISIBLE_INDEX, UNHOLYARMOR_INDEX,
  SLOT_INDEX, SHIELD_INDEX, POINTS_INDEX, MAXHARVESTERS_INDEX,
  POISON_INDEX, SHIELDPERMEABILITY_INDEX, SHIELDPIERCING_INDEX, ISALIVE_INDEX,
  PLAYER_INDEX, PRIORITY_INDEX, NVARALREADYDEFINED
}
 
enum  UnitTypeType { UnitTypeLand, UnitTypeFly, UnitTypeNaval }
 
enum  DistanceTypeType {
  Equal, NotEqual, LessThan, LessThanEqual,
  GreaterThan, GreaterThanEqual
}
 
std::vector< CUnitType * > UnitTypes
 
CUnitTypeUnitTypeHumanWall
 All unit-types. More...
 
CUnitTypeUnitTypeOrcWall
 Human wall. More...
 
CUnitTypeVar UnitTypeVar
 
CUnitTypeUnitTypeByIdent (const std::string &ident)
 Update unit stats. More...
 
CUnitTypeCclGetUnitType (lua_State *l)
 
void UnitTypeCclRegister ()
 Access unit-type object. More...
 
void UpdateUnitStats (CUnitType &type, int reset_to_default)
 Register ccl features. More...
 
void UpdateStats (int reset_to_default)
 Update unit stats. More...
 
void SaveUnitTypes (CFile &file)
 Get unit-type by ident. More...
 
CUnitTypeNewUnitTypeSlot (const std::string &ident)
 Save the unit-type table. More...
 
void DrawUnitType (const CUnitType &type, CPlayerColorGraphic *sprite, int colorIndex, int frame, const PixelPos &screenPos)
 Draw the sprite frame of unit-type. More...
 
void InitUnitTypes (int reset_player_stats)
 
void LoadUnitTypeSprite (CUnitType &unittype)
 Init unit-type table. More...
 
void LoadUnitTypes ()
 Load the sprite for a unittype. More...
 
void CleanUnitTypes ()
 Load the unit-type data. More...
 
void DefineVariableField (lua_State *l, CVariable *var, int lua_index)
 Cleanup unit-type module. More...
 
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="")
 

Macro Definition Documentation

◆ CanTargetAir

#define CanTargetAir   4

◆ CanTargetLand

#define CanTargetLand   1

Which units can it attack.

◆ CanTargetSea

#define CanTargetSea   2

◆ InfiniteRepairRange

#define InfiniteRepairRange   INT_MAX

Units repair range.

◆ MaxAttackPos

#define MaxAttackPos   5

◆ MouseActionAttack

#define MouseActionAttack   1

◆ MouseActionHarvest

#define MouseActionHarvest   3

◆ MouseActionMove

#define MouseActionMove   2

◆ MouseActionNone

#define MouseActionNone   0

Right click action.

◆ MouseActionSail

#define MouseActionSail   6

◆ MouseActionSpellCast

#define MouseActionSpellCast   5

◆ UnitSides

#define UnitSides   8

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
COWARD_INDEX 
BUILDING_INDEX 

Unit will only attack if instructed.

FLIP_INDEX 
REVEALER_INDEX 
LANDUNIT_INDEX 

reveal the fog of war

AIRUNIT_INDEX 
SEAUNIT_INDEX 
EXPLODEWHENKILLED_INDEX 
VISIBLEUNDERFOG_INDEX 
PERMANENTCLOAK_INDEX 

Unit is visible under fog of war.

DETECTCLOAK_INDEX 

Is only visible by CloakDetectors.

ATTACKFROMTRANSPORTER_INDEX 

Can see Cloaked units.

VANISHES_INDEX 

Can attack from transporter.

GROUNDATTACK_INDEX 

Corpses & destroyed places.

SHOREBUILDING_INDEX 

Can do ground attack command.

CANATTACK_INDEX 

Building must be built on coast.

BUILDEROUTSIDE_INDEX 
BUILDERLOST_INDEX 

The builder stays outside during the construction.

CANHARVEST_INDEX 

The builder is lost after the construction.

HARVESTER_INDEX 

Resource can be harvested.

SELECTABLEBYRECTANGLE_INDEX 

Unit is a resource harvester.

ISNOTSELECTABLE_INDEX 

Selectable with mouse rectangle.

DECORATION_INDEX 
INDESTRUCTIBLE_INDEX 

Unit is a decoration (act as tile).

TELEPORTER_INDEX 

Unit is indestructible (take no damage).

SHIELDPIERCE_INDEX 

Can teleport other units.

SAVECARGO_INDEX 
NONSOLID_INDEX 

Unit unloads his passengers after death.

WALL_INDEX 

Unit can be entered by other units.

NORANDOMPLACING_INDEX 

Use special logic for Direction field.

ORGANIC_INDEX 

Don't use random frame rotation.

SIDEATTACK_INDEX 

Organic unit (used for death coil spell)

SKIRMISHER_INDEX 
ALWAYSTHREAT_INDEX 
ELEVATED_INDEX 

Unit always considered as threat for auto targeting algorihm, useful for unit without main attack ability, but which can cast spells (f.e. defiler in SC:BW)

NOFRIENDLYFIRE_INDEX 

Unit is elevated and can see over opaque tiles placed in the same ground level with the unit.

MAINFACILITY_INDEX 

Unit accepts friendly fire for splash attacks.

NBARALREADYDEFINED 

Unit is a main building (Town Hall f. ex.)

◆ anonymous enum

anonymous enum
Enumerator
HP_INDEX 
BUILD_INDEX 
MANA_INDEX 
TRANSPORT_INDEX 
RESEARCH_INDEX 
TRAINING_INDEX 
UPGRADINGTO_INDEX 
GIVERESOURCE_INDEX 
CARRYRESOURCE_INDEX 
XP_INDEX 
KILL_INDEX 
SUPPLY_INDEX 
DEMAND_INDEX 

Food supply.

ARMOR_INDEX 

Food demand.

SIGHTRANGE_INDEX 
ATTACKRANGE_INDEX 
PIERCINGDAMAGE_INDEX 
BASICDAMAGE_INDEX 
POSX_INDEX 
POSY_INDEX 
POS_RIGHT_INDEX 
POS_BOTTOM_INDEX 
TARGETPOSX_INDEX 
TARGETPOSY_INDEX 
RADAR_INDEX 
RADARJAMMER_INDEX 
AUTOREPAIRRANGE_INDEX 
BLOODLUST_INDEX 
HASTE_INDEX 
SLOW_INDEX 
INVISIBLE_INDEX 
UNHOLYARMOR_INDEX 
SLOT_INDEX 
SHIELD_INDEX 
POINTS_INDEX 
MAXHARVESTERS_INDEX 
POISON_INDEX 
SHIELDPERMEABILITY_INDEX 
SHIELDPIERCING_INDEX 
ISALIVE_INDEX 
PLAYER_INDEX 
PRIORITY_INDEX 
NVARALREADYDEFINED 

◆ DistanceTypeType

Enumerator
Equal 
NotEqual 
LessThan 
LessThanEqual 
GreaterThan 
GreaterThanEqual 

◆ GroupSelectionMode

Enumerator
SELECTABLE_BY_RECTANGLE_ONLY 
NON_SELECTABLE_BY_RECTANGLE_ONLY 
SELECT_ALL 

◆ UnitTypeType

Enumerator
UnitTypeLand 
UnitTypeFly 

Unit lives on land.

UnitTypeNaval 

Unit lives in air.

Unit lives on water

Function Documentation

◆ CclGetUnitType()

CUnitType* CclGetUnitType ( lua_State *  l)

Access unit-type object

Parameters
lLua state.

◆ CleanUnitTypes()

void CleanUnitTypes ( )

Load the unit-type data.

Cleanup the unit-type module.

◆ DefineVariableField()

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

Cleanup unit-type module.

Parse User Variables field.

Define the field of the UserDefined variables.

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

◆ DrawUnitType()

void DrawUnitType ( const CUnitType type,
CPlayerColorGraphic sprite,
int  colorIndex,
int  frame,
const PixelPos screenPos 
)

Draw the sprite frame of unit-type.

Allocate an empty unit-type slot

Draw unit-type on map.

Parameters
typeUnit-type pointer.
spriteSprite to use for drawing
playerPlayer number for color substitution.
frameAnimation frame of unit-type.
screenPosScreen pixel (top left) position to draw unit-type.
Todo:
Do screen position caculation in high level. Better way to handle in x mirrored sprites.

◆ InitUnitTypes()

void InitUnitTypes ( int  reset_player_stats)

Init unit types.

◆ LoadUnitTypes()

void LoadUnitTypes ( )

Load the sprite for a unittype.

Load the graphics for the unit-types.

◆ LoadUnitTypeSprite()

void LoadUnitTypeSprite ( CUnitType type)

Init unit-type table.

Loads the Sprite for a unit type

Parameters
typetype of unit to load

◆ NewUnitTypeSlot()

CUnitType* NewUnitTypeSlot ( const std::string &  ident)

Save the unit-type table.

Allocate an empty unit-type slot.

Parameters
identIdentifier to identify the slot (malloced by caller!).
Returns
New allocated (zeroed) unit-type pointer.

◆ SaveUnitTypes()

void SaveUnitTypes ( CFile file)

Get unit-type by ident.

Save state of the unit-type table to file.

Parameters
fileOutput file.

◆ 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"

◆ UnitTypeByIdent()

CUnitType * UnitTypeByIdent ( const std::string &  ident)

Update unit stats.

Find unit-type by identifier.

Parameters
identThe unit-type identifier.
Returns
Unit-type pointer.

◆ UnitTypeCclRegister()

void UnitTypeCclRegister ( )

Access unit-type object.

Register CCL features for unit-type.

◆ UpdateStats()

void UpdateStats ( int  reset)

Update unit stats.

Update the player stats for changed unit types.

Parameters
resetindicates wether default value should be set to each stat (level, upgrades)

◆ UpdateUnitStats()

void UpdateUnitStats ( CUnitType type,
int  reset_to_default 
)

Register ccl features.

◆ UpdateUnitVariables()

void UpdateUnitVariables ( CUnit unit)

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

Update unit variables which are not user defined.

Variable Documentation

◆ UnitTypeHumanWall

CUnitType* UnitTypeHumanWall

All unit-types.

Todo:
this hardcoded unit-types must be removed!!

Next unit type are used hardcoded in the source.

Todo:
find a way to make it configurable!

◆ UnitTypeOrcWall

CUnitType* UnitTypeOrcWall

Human wall.

◆ UnitTypes

std::vector<CUnitType *> UnitTypes

◆ UnitTypeVar

CUnitTypeVar UnitTypeVar
(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.