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

Classes
unit.h File Reference
#include "settings.h"
#include <vector>
#include "unittype.h"
#include "player.h"
#include "vec2i.h"

Go to the source code of this file.

Classes

class  CUnit
 The big unit structure. More...
 
class  CUnit::CUnitManagerData
 
struct  CUnit::_seen_stuff_
 Unit visibility counts. More...
 
struct  CUnit::_unit_anim_
 The counter while small ai can ignore non aggressive targets if searching attacker. More...
 
class  CPreference
 

unit.h - The unit headerfile.

#define PRIORITY_FACTOR   0x00080000
 
#define HEALTH_FACTOR   0x00000001
 
#define DISTANCE_FACTOR   0x00010000
 
#define INRANGE_FACTOR   0x00008000
 
#define INRANGE_BONUS   0x01000000
 
#define CANATTACK_BONUS   0x00080000
 
#define AIPRIORITY_BONUS   0x04000000
 
#define AT_ATTACKED_BY_FACTOR   0x40000000
 
#define AT_THREAT_FACTOR   0x20000000
 
#define AT_PRIORITY_OFFSET   15
 
#define AT_DISTANCE_OFFSET   7
 
#define AT_PRIORITY_MASK_HI   0xFFFF8000
 
#define AT_FARAWAY_REDUCE_OFFSET   14
 
#define NextDirection   32
 
#define UnitNotSeen   0x7fffffff
 
#define NoUnitP   (CUnit *)0
 
#define UnitNumber(unit)   ((unit).UnitManagerData.GetUnitId())
 
enum  _directions_ {
  LookingN = 0 * 32, LookingNE = 1 * 32, LookingE = 2 * 32, LookingSE = 3 * 32,
  LookingS = 4 * 32, LookingSW = 5 * 32, LookingW = 6 * 32, LookingNW = 7 * 32
}
 
typedef COrderCOrderPtr
 
CPreference Preference
 Lua handler count. More...
 
unsigned long ShowOrdersCount
 All sprite's infos. More...
 
unsigned long ShowNameDelay
 Show orders for some time. More...
 
unsigned long ShowNameTime
 Delay to show unit's name. More...
 
bool EnableTrainingQueue
 Show unit's name for some time. More...
 
bool EnableBuildingCapture
 Config: training queues enabled. More...
 
bool RevealAttacker
 Config: building capture enabled. More...
 
int ResourcesMultiBuildersMultiplier
 Config: reveal attacker enabled. More...
 
const CViewportCurrentViewport
 Config: spend resources for building with multiple workers. More...
 
void(* DrawSelection )(IntColor, int, int, int, int)
 Show unit's name for some time. More...
 
unsigned int MaxSelectable
 
std::vector< CUnit * > Selected
 How many units could be selected. More...
 
void(*)(IntColor, int, int, int, int) DrawSelectionEllipse (float factor)
 Draw ellipse around unit. More...
 
void SelectedUnitChanged ()
 Called whenever the selected unit was updated. More...
 
int MapDistanceBetweenTypes (const CUnitType &src, const Vec2i &pos1, const CUnitType &dst, const Vec2i &pos2)
 Returns the map distance between to unittype as locations. More...
 
void DrawUnitSelection (const CViewport &vp, const CUnit &unit)
 CurrentViewport. More...
 
void MarkUnitFieldFlags (const CUnit &unit)
 currently selected units More...
 
void UnmarkUnitFieldFlags (const CUnit &unit)
 Unmark the field with the FieldFlags. More...
 
void UpdateUnitSightRange (CUnit &unit)
 Update unit->CurrentSightRange. More...
 
CUnitMakeUnit (const CUnitType &type, CPlayer *player)
 Create a new unit. More...
 
CUnitMakeUnitAndPlace (const Vec2i &pos, const CUnitType &type, CPlayer *player)
 Create a new unit and place on map. More...
 
void FindNearestDrop (const CUnitType &type, const Vec2i &goalPos, Vec2i &resPos, int heading)
 Find the nearest position at which unit can be placed. More...
 
void UnitLost (CUnit &unit)
 Handle the loss of a unit (food,...) More...
 
void UnitClearOrders (CUnit &unit)
 Remove the Orders of a Unit. More...
 
void UpdateForNewUnit (const CUnit &unit, int upgrade)
 
void NearestOfUnit (const CUnit &unit, const Vec2i &pos, Vec2i *dpos)
 
CUnitGetFirstContainer (const CUnit &unit)
 
void UnitGoesUnderFog (CUnit &unit, const CPlayer &player)
 Call when an Unit goes under fog. More...
 
void UnitGoesOutOfFog (CUnit &unit, const CPlayer &player)
 Call when an Unit goes out of fog. More...
 
void UnitCountSeen (CUnit &unit)
 Does a recount for VisCount. More...
 
void RescueUnits ()
 Check for rescue each second. More...
 
int DirectionToHeading (const Vec2i &dir)
 Convert direction (dx,dy) to heading (0-255) More...
 
int DirectionToHeading (const PixelDiff &dir)
 Convert direction (dx,dy) to heading (0-255) More...
 
void CorrectWallDirections (CUnit &unit)
 Correct directions for placed wall. More...
 
void CorrectWallNeighBours (CUnit &unit)
 Correct the surrounding walls. More...
 
void UnitUpdateHeading (CUnit &unit)
 Update frame from heading. More...
 
void UnitHeadingFromDeltaXY (CUnit &unit, const Vec2i &delta)
 Heading and frame from delta direction. More...
 
void DropOutOnSide (CUnit &unit, int heading, const CUnit *container)
 
void DropOutNearest (CUnit &unit, const Vec2i &goalPos, const CUnit *container)
 
void DropOutAll (const CUnit &unit)
 Drop out all units in the unit. More...
 
CBuildRestrictionOnTopOnTopDetails (const CUnit &unit, const CUnitType *parent)
 Return the rule used to build this building. More...
 
CUnitCanBuildHere (const CUnit *unit, const CUnitType &type, const Vec2i &pos)
 
bool CanBuildOn (const Vec2i &pos, int mask)
 
CUnitCanBuildUnitType (const CUnit *unit, const CUnitType &type, const Vec2i &pos, int real)
 FIXME: more docu. More...
 
int ExtraDeathIndex (const char *death)
 Get the suitable animation frame depends of unit's damaged type. More...
 
CUnitUnitOnScreen (int x, int y)
 Get unit under cursor. More...
 
void LetUnitDie (CUnit &unit, bool suicide=false)
 Let a unit die. More...
 
void DestroyAllInside (CUnit &source)
 Destroy all units inside another unit. More...
 
int ThreatCalculate (const CUnit &unit, const CUnit &dest)
 Calculate some value to measure the unit's priority for AI. More...
 
int TargetPriorityCalculate (const CUnit *const attacker, const CUnit *const dest)
 
bool InReactRange (const CUnit &unit, const CUnit &target)
 Is target within reaction range of this unit? More...
 
bool InAttackRange (const CUnit &unit, const CUnit &target)
 Is target within attack range of this unit? More...
 
bool InAttackRange (const CUnit &unit, const Vec2i &tilePos)
 Is tile within attack range of this unit? More...
 
Vec2i GetRndPosInDirection (const Vec2i &srcPos, const CUnit &dirUnit, const bool dirFrom, const int minRange, const int devRadius, const int rangeDev=3)
 Return randomly selected position in direction (to/from) dirUnit from srcPos. More...
 
Vec2i GetRndPosInDirection (const Vec2i &srcPos, const Vec2i &dirPos, const bool dirFrom, const int minRange, const int devRadius, const int rangeDev=3)
 Return randomly selected position in direction (to/from) dirPos from srcPos. More...
 
void HitUnit (CUnit *attacker, CUnit &target, int damage, const Missile *missile=NULL)
 Hit unit with damage, if destroyed give attacker the points. More...
 
int ViewPointDistance (const Vec2i &pos)
 Calculate the distance from current view point to coordinate. More...
 
int ViewPointDistanceToUnit (const CUnit &dest)
 Calculate the distance from current view point to unit. More...
 
int CanTarget (const CUnitType &type, const CUnitType &dest)
 Can this unit-type attack the other (destination) More...
 
int CanTransport (const CUnit &transporter, const CUnit &unit)
 Can transporter transport the other unit. More...
 
std::string UnitReference (const CUnit &unit)
 Generate a unit reference, a printable unique string for unit. More...
 
std::string UnitReference (const CUnitPtr &unit)
 Generate a unit reference, a printable unique string for unit. More...
 
void SaveUnit (const CUnit &unit, CFile &file)
 save unit-structure More...
 
void InitUnits ()
 Initialize unit module. More...
 
void CleanUnits ()
 Clean unit module. More...
 
void DrawSelectionNone (IntColor, int, int, int, int)
 Draw nothing around unit. More...
 
void DrawSelectionCircle (IntColor, int, int, int, int)
 Draw circle around unit. More...
 
void DrawSelectionCircleWithTrans (IntColor, int, int, int, int)
 Draw circle filled with alpha around unit. More...
 
void DrawSelectionRectangle (IntColor, int, int, int, int)
 Draw rectangle around unit. More...
 
void DrawSelectionRectangleWithTrans (IntColor, int, int, int, int)
 Draw rectangle filled with alpha around unit. More...
 
void DrawSelectionCorners (IntColor, int, int, int, int)
 Draw corners around unit. More...
 
void DecorationCclRegister ()
 Register CCL decorations features. More...
 
void LoadDecorations ()
 Load the decorations (health,mana) of units. More...
 
void CleanDecorations ()
 Clean the decorations (health,mana) of units. More...
 
void DrawShadow (const CUnitType &type, int frame, const PixelPos &screenPos)
 Draw unit's shadow. More...
 
int FindAndSortUnits (const CViewport &vp, std::vector< CUnit * > &table)
 Draw all units visible on map in viewport. More...
 
void ShowOrder (const CUnit &unit)
 Show a unit's orders. More...
 
void SaveGroups (CFile &file)
 Save groups. More...
 
void CleanGroups ()
 Cleanup groups. More...
 
const std::vector< CUnit * > & GetUnitsOfGroup (int num)
 Get the array of units of a particular group. More...
 
void ClearGroup (int num)
 Remove all units from a group. More...
 
void AddToGroup (CUnit **units, unsigned int nunits, int num)
 Add the array of units to the group. More...
 
void SetGroup (CUnit **units, unsigned int nunits, int num)
 Set the contents of a particular group with an array of units. More...
 
void RemoveUnitFromGroups (CUnit &unit)
 Remove a unit from a group. More...
 
void GroupCclRegister ()
 Register CCL group features. More...
 
bool IsGroupTainted (int num)
 
bool IsOnlySelected (const CUnit &unit)
 Check if unit is the currently only selected. More...
 
void SaveSelection ()
 Save selection to restore after. More...
 
void RestoreSelection ()
 Restore selection. More...
 
void UnSelectAll ()
 Clear current selection. More...
 
void ChangeTeamSelectedUnits (CPlayer &player, const std::vector< CUnit * > &units)
 Changed TeamUnit Selection. More...
 
int SelectUnit (CUnit &unit)
 Add a unit to selection. More...
 
void SelectSingleUnit (CUnit &unit)
 Select one unit as selection. More...
 
void UnSelectUnit (CUnit &unit)
 Remove a unit from selection. More...
 
int ToggleSelectUnit (CUnit &unit)
 Add a unit to selected if not already selected, remove it otherwise. More...
 
int SelectUnitsByType (CUnit &base)
 Select units from the same type (if selectable by rectangle) More...
 
int ToggleUnitsByType (CUnit &base)
 Toggle units from the same type (if selectable by rectangle) More...
 
int SelectGroup (int group_number, GroupSelectionMode mode=SELECTABLE_BY_RECTANGLE_ONLY)
 Select the units belonging to a particular group. More...
 
int AddGroupFromUnitToSelection (CUnit &unit)
 Add the units from the same group as the one in parameter. More...
 
int SelectGroupFromUnit (CUnit &unit)
 Select the units from the same group as the one in parameter. More...
 
int SelectUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Select the units in the selection rectangle. More...
 
int SelectGroundUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Select ground units in the selection rectangle. More...
 
int SelectAirUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Select flying units in the selection rectangle. More...
 
int AddSelectedUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Add the units in the selection rectangle to the current selection. More...
 
int AddSelectedGroundUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Add ground units in the selection rectangle to the current selection. More...
 
int AddSelectedAirUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Add flying units in the selection rectangle to the current selection. More...
 
void SaveSelections (CFile &file)
 Save current selection state. More...
 
void CleanSelections ()
 Clean up selections. More...
 
void SelectionCclRegister ()
 Register CCL selection features. More...
 
void UnitCclRegister ()
 register CCL units features More...
 

Macro Definition Documentation

◆ AIPRIORITY_BONUS

#define AIPRIORITY_BONUS   0x04000000

◆ AT_ATTACKED_BY_FACTOR

#define AT_ATTACKED_BY_FACTOR   0x40000000

◆ AT_DISTANCE_OFFSET

#define AT_DISTANCE_OFFSET   7

◆ AT_FARAWAY_REDUCE_OFFSET

#define AT_FARAWAY_REDUCE_OFFSET   14

◆ AT_PRIORITY_MASK_HI

#define AT_PRIORITY_MASK_HI   0xFFFF8000

◆ AT_PRIORITY_OFFSET

#define AT_PRIORITY_OFFSET   15

◆ AT_THREAT_FACTOR

#define AT_THREAT_FACTOR   0x20000000

◆ CANATTACK_BONUS

#define CANATTACK_BONUS   0x00080000

◆ DISTANCE_FACTOR

#define DISTANCE_FACTOR   0x00010000

◆ HEALTH_FACTOR

#define HEALTH_FACTOR   0x00000001

◆ INRANGE_BONUS

#define INRANGE_BONUS   0x01000000

◆ INRANGE_FACTOR

#define INRANGE_FACTOR   0x00008000

◆ NextDirection

#define NextDirection   32

◆ NoUnitP

#define NoUnitP   (CUnit *)0

◆ PRIORITY_FACTOR

#define PRIORITY_FACTOR   0x00080000

◆ UnitNotSeen

#define UnitNotSeen   0x7fffffff

◆ UnitNumber

#define UnitNumber (   unit)    ((unit).UnitManagerData.GetUnitId())

Returns unit number (unique to this unit)

Typedef Documentation

◆ COrderPtr

typedef COrder* COrderPtr

Enumeration Type Documentation

◆ _directions_

Unit/Missile headings. N NW NE W E SW SE S

Enumerator
LookingN 
LookingNE 

Unit looking north.

LookingE 

Unit looking north east.

LookingSE 

Unit looking east.

LookingS 

Unit looking south east.

LookingSW 

Unit looking south.

LookingW 

Unit looking south west.

LookingNW 

Unit looking west.

Function Documentation

◆ AddGroupFromUnitToSelection()

int AddGroupFromUnitToSelection ( CUnit unit)

Add the units from the same group as the one in parameter.

Add units from group of a particular unit to selection.

Parameters
unitunit belonging to the group to be selected.
Returns
0 if the unit doesn't belong to a group, or the number of units in the group.

◆ AddSelectedAirUnitsInRectangle()

int AddSelectedAirUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Add flying units in the selection rectangle to the current selection.

Add the air units in the rectangle to the current selection

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ AddSelectedGroundUnitsInRectangle()

int AddSelectedGroundUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Add ground units in the selection rectangle to the current selection.

Add the ground units in the rectangle to the current selection

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ AddSelectedUnitsInRectangle()

int AddSelectedUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Add the units in the selection rectangle to the current selection.

Add the units in the rectangle to the current selection

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the total number of units selected.

◆ AddToGroup()

void AddToGroup ( CUnit **  units,
unsigned int  nunits,
int  num 
)

Add the array of units to the group.

Add units to group num contents from unit array "units"

Parameters
unitsArray of units to place into group.
nunitsNumber of units in array.
numGroup number for storage.

◆ CanBuildHere()

CUnit* CanBuildHere ( const CUnit unit,
const CUnitType type,
const Vec2i pos 
)
Todo:
more docu

Can build unit here. Hall too near to goldmine. Refinery or shipyard too near to oil patch.

Parameters
unitUnit doing the building
typeunit-type to be checked.
posMap position.
Returns
OnTop, parent unit, builder on true or 1 if unit==NULL, NULL false.

◆ CanBuildOn()

bool CanBuildOn ( const Vec2i pos,
int  mask 
)
Todo:
more docu

Can build on this point.

Parameters
postile map position.
maskterrain mask
Returns
true if we can build on this point.

◆ CanBuildUnitType()

CUnit* CanBuildUnitType ( const CUnit unit,
const CUnitType type,
const Vec2i pos,
int  real 
)

FIXME: more docu.

Can build unit-type at this point.

Parameters
unitWorker that want to build the building or NULL.
typeBuilding unit-type.
postile map position.
realReally build, or just placement
Returns
OnTop, parent unit, builder on true, NULL false.

◆ CanTarget()

int CanTarget ( const CUnitType source,
const CUnitType dest 
)

Can this unit-type attack the other (destination)

Can the source unit attack the destination unit?

Parameters
sourceUnit type pointer of the attacker.
destUnit type pointer of the target.
Returns
0 if attacker can't target the unit, else a positive number.

◆ CanTransport()

int CanTransport ( const CUnit transporter,
const CUnit unit 
)

Can transporter transport the other unit.

Can the transporter transport the other unit.

Parameters
transporterUnit which is the transporter.
unitUnit which wants to go in the transporter.
Returns
1 if transporter can transport unit, 0 else.

◆ ChangeTeamSelectedUnits()

void ChangeTeamSelectedUnits ( CPlayer player,
const std::vector< CUnit * > &  units 
)

Changed TeamUnit Selection.

Change A Unit Selection from my Team

Parameters
playerThe Player who is selecting the units
unitsThe Units to add/remove

◆ CleanDecorations()

void CleanDecorations ( )

Clean the decorations (health,mana) of units.

Clean decorations.

◆ CleanGroups()

void CleanGroups ( )

Cleanup groups.

Clean up group part.

◆ CleanSelections()

void CleanSelections ( )

Clean up selections.

Clean up the selection module.

◆ CleanUnits()

void CleanUnits ( )

Clean unit module.

Clean up unit module.

◆ ClearGroup()

void ClearGroup ( int  num)

Remove all units from a group.

Clear contents of group num

Parameters
numGroup number.

◆ CorrectWallDirections()

void CorrectWallDirections ( CUnit unit)

Correct directions for placed wall.

Correct direction for placed wall.

Parameters
unitThe wall unit.

◆ CorrectWallNeighBours()

void CorrectWallNeighBours ( CUnit unit)

Correct the surrounding walls.

Correct the surrounding walls.

Parameters
unitThe wall unit.

◆ DecorationCclRegister()

void DecorationCclRegister ( )

Register CCL decorations features.

Register CCL features for decorations.

◆ DestroyAllInside()

void DestroyAllInside ( CUnit source)

Destroy all units inside another unit.

Destroy all units inside unit.

Parameters
sourcecontainer.

◆ DirectionToHeading() [1/2]

int DirectionToHeading ( const PixelDiff delta)

Convert direction (dx,dy) to heading (0-255)

Convert direction to heading.

Parameters
deltaDelta.
Returns
Angle (0..255)

◆ DirectionToHeading() [2/2]

int DirectionToHeading ( const Vec2i delta)

Convert direction (dx,dy) to heading (0-255)

Convert direction to heading.

Parameters
deltaDelta.
Returns
Angle (0..255)

◆ DrawSelectionCircle()

void DrawSelectionCircle ( IntColor  color,
int  x1,
int  y1,
int  x2,
int  y2 
)

Draw circle around unit.

Show selected units with circle.

Parameters
colorColor to draw circle
x1,y1Coordinates of the top left corner.
x2,y2Coordinates of the bottom right corner.

◆ DrawSelectionCircleWithTrans()

void DrawSelectionCircleWithTrans ( IntColor  color,
int  x1,
int  y1,
int  x2,
int  y2 
)

Draw circle filled with alpha around unit.

Show selected units with circle.

Parameters
colorColor to draw and fill circle.
x1,y1Coordinates of the top left corner.
x2,y2Coordinates of the bottom right corner.

◆ DrawSelectionCorners()

void DrawSelectionCorners ( IntColor  color,
int  x1,
int  y1,
int  x2,
int  y2 
)

Draw corners around unit.

Draw selected corners around the unit.

Parameters
colorColor to draw corners.
x1,y1Coordinates of the top left corner.
x2,y2Coordinates of the bottom right corner.

◆ DrawSelectionNone()

void DrawSelectionNone ( IntColor  ,
int  ,
int  ,
int  ,
int   
)

Draw nothing around unit.

Don't show selected units.

Parameters
colorColor to draw, nothing in this case.
x1,y1Coordinates of the top left corner.
x2,y2Coordinates of the bottom right corner.

◆ DrawSelectionRectangle()

void DrawSelectionRectangle ( IntColor  color,
int  x1,
int  y1,
int  x2,
int  y2 
)

Draw rectangle around unit.

Draw selected rectangle around the unit.

Parameters
colorColor to draw rectangle.
x1,y1Coordinates of the top left corner.
x2,y2Coordinates of the bottom right corner.

◆ DrawSelectionRectangleWithTrans()

void DrawSelectionRectangleWithTrans ( IntColor  color,
int  x1,
int  y1,
int  x2,
int  y2 
)

Draw rectangle filled with alpha around unit.

Draw selected rectangle around the unit.

Parameters
colorColor to draw and fill rectangle.
x1,y1Coordinates of the top left corner.
x2,y2Coordinates of the bottom right corner.

◆ DrawShadow()

void DrawShadow ( const CUnitType type,
int  frame,
const PixelPos screenPos 
)

Draw unit's shadow.

Draw unit's shadow.

Parameters
typePointer to the unit type.
frameFrame number
screenPosScreen position of the unit.
Todo:
FIXME: combine new shadow code with old shadow code.

◆ DrawUnitSelection()

void DrawUnitSelection ( const CViewport vp,
const CUnit unit 
)

CurrentViewport.

CurrentViewport.

Show selection marker around a unit.

Parameters
unitPointer to unit.

◆ DropOutAll()

void DropOutAll ( const CUnit source)

Drop out all units in the unit.

Drop out all units inside unit.

Parameters
sourceAll units inside source are dropped out.

◆ DropOutNearest()

void DropOutNearest ( CUnit unit,
const Vec2i goalPos,
const CUnit container 
)
Todo:
more docu

Place a unit on the map nearest to goalPos.

Parameters
unitUnit to drop out.
goalPosGoal map tile position.
addxTile width of unit it's dropping out of.
addyTile height of unit it's dropping out of.

◆ DropOutOnSide()

void DropOutOnSide ( CUnit unit,
int  heading,
const CUnit container 
)
Todo:
more docu

Place a unit on the map to the side of a unit.

Parameters
unitUnit to drop out.
headingDirection in which the unit should appear.
containerUnit "containing" unit to drop (may be different of unit.Container).

◆ 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

◆ FindAndSortUnits()

int FindAndSortUnits ( const CViewport vp,
std::vector< CUnit * > &  table 
)

Draw all units visible on map in viewport.

Find all units to draw in viewport.

Parameters
vpViewport to be drawn.
tableTable of units to return in sorted order

◆ FindNearestDrop()

void FindNearestDrop ( const CUnitType type,
const Vec2i goalPos,
Vec2i resPos,
int  heading 
)

Find the nearest position at which unit can be placed.

Find the nearest position at which unit can be placed.

Parameters
typeType of the dropped unit.
goalPosGoal map tile position.
resPosHolds the nearest point.
headingpreferense side to drop out of.

◆ GetFirstContainer()

CUnit* GetFirstContainer ( const CUnit unit)

Return the unit not transported, by viewing the container recursively.

Parameters
unitunit from where look the first conatiner.
Returns
Container of container of ... of unit. It is not null.

◆ GetRndPosInDirection() [1/2]

Vec2i GetRndPosInDirection ( const Vec2i srcPos,
const CUnit dirUnit,
const bool  dirFrom,
const int  minRange,
const int  devRadius,
const int  rangeDev 
)

Return randomly selected position in direction (to/from) dirUnit from srcPos.

Returns end position of randomly generated vector form srcPos in direction to/from dirUnit

Parameters
srcPosVector origin
dirUnitPosition to determine vector direction
dirFromDirection of src-dir. True if "from" dirPos, false if "to" dirPos
minRangeMinimal range to new position
devRadiusDiviation radius
rangeDevRange deviation
Returns
Position

◆ GetRndPosInDirection() [2/2]

Vec2i GetRndPosInDirection ( const Vec2i srcPos,
const Vec2i dirPos,
const bool  dirFrom,
const int  minRange,
const int  devRadius,
const int  rangeDev 
)

Return randomly selected position in direction (to/from) dirPos from srcPos.

Returns end position of randomly generated vector form srcPos in direction to/from dirPos

Parameters
srcPosVector origin
dirPosPosition to determine vector direction
dirFromDirection of src-dir. True if "from" dirPos, false if "to" dirPos
minRangeMinimal range to new position
devRadiusDiviation radius
rangeDevRange deviation
Returns
Position

◆ GetUnitsOfGroup()

const std::vector<CUnit *>& GetUnitsOfGroup ( int  num)

Get the array of units of a particular group.

Return the units of group num

Parameters
numGroup number.
Returns
Returns an array of all units in the group.

◆ GroupCclRegister()

void GroupCclRegister ( )

Register CCL group features.

Register CCL features for groups.

◆ HitUnit()

void HitUnit ( CUnit attacker,
CUnit target,
int  damage,
const Missile missile 
)

Hit unit with damage, if destroyed give attacker the points.

Unit is hit by missile or other damage.

Parameters
attackerUnit that attacks.
targetUnit that is hit.
damageHow many damage to take.
missileWhich missile took the damage.

◆ InAttackRange() [1/2]

bool InAttackRange ( const CUnit unit,
const CUnit target 
)

Is target within attack range of this unit?

Returns true, if target is in attack range of the unit and there are no obstacles between them (when inside caves)

Parameters
unitUnit to check for.
targetChecked target.
Returns
True if in attack range, false otherwise.

◆ InAttackRange() [2/2]

bool InAttackRange ( const CUnit unit,
const Vec2i tilePos 
)

Is tile within attack range of this unit?

Returns true, if tile is in attack range of the unit and there are no obstacles between them (when inside caves)

Parameters
unitUnit to check for.
posChecked position.
Returns
True if in attack range, false otherwise.

◆ InitUnits()

void InitUnits ( )

Initialize unit module.

Initialize unit module.

◆ InReactRange()

bool InReactRange ( const CUnit unit,
const CUnit target 
)

Is target within reaction range of this unit?

Returns true, if target is in reaction range of the unit

Todo:
: Do we have to check range from unit.Container pos if unit is bunkered or in transport?
Parameters
unitUnit to check for.
targetChecked target.
Returns
True if within react range, false otherwise.

◆ IsGroupTainted()

bool IsGroupTainted ( int  num)

◆ IsOnlySelected()

bool IsOnlySelected ( const CUnit unit)

Check if unit is the currently only selected.

Check if unit is the currently only selected.

◆ LetUnitDie()

void LetUnitDie ( CUnit unit,
bool  suicide 
)

Let a unit die.

Let an unit die.

Parameters
unitUnit to be destroyed.

◆ LoadDecorations()

void LoadDecorations ( )

Load the decorations (health,mana) of units.

Load decoration.

◆ MakeUnit()

CUnit* MakeUnit ( const CUnitType type,
CPlayer player 
)

Create a new unit.

Create a new unit.

Parameters
typePointer to unit-type.
playerPointer to owning player.
Returns
Pointer to created unit.

◆ MakeUnitAndPlace()

CUnit* MakeUnitAndPlace ( const Vec2i pos,
const CUnitType type,
CPlayer player 
)

Create a new unit and place on map.

Create new unit and place on map.

Parameters
posmap tile position.
typePointer to unit-type.
playerPointer to owning player.
Returns
Pointer to created unit.

◆ MapDistanceBetweenTypes()

int MapDistanceBetweenTypes ( const CUnitType src,
const Vec2i pos1,
const CUnitType dst,
const Vec2i pos2 
)

Returns the map distance between to unittype as locations.

Returns the map distance between two points with unit type.

Parameters
srcsrc unittype
pos1map tile position of src (upperleft).
dstUnit type to take into account.
pos2map tile position of dst.
Returns
The distance between the types.

◆ MarkUnitFieldFlags()

void MarkUnitFieldFlags ( const CUnit unit)

currently selected units

Mark the field with the FieldFlags.

Mark the field with the FieldFlags.

Parameters
unitunit to mark.

◆ NearestOfUnit()

void NearestOfUnit ( const CUnit unit,
const Vec2i pos,
Vec2i dpos 
)
Todo:
more docu

Find nearest point of unit.

Parameters
unitPointer to unit.
postile map position.
dposOut: nearest point tile map position to (tx,ty).

◆ OnTopDetails()

CBuildRestrictionOnTop* OnTopDetails ( const CUnit unit,
const CUnitType parent 
)

Return the rule used to build this building.

Find the building restriction that gives me this unit built on top Allows you to define how the restriction is effecting the build

Parameters
unitthe unit that is "OnTop"
parentthe parent unit if known. (guess otherwise)
Returns
the BuildingRestrictionDetails

◆ RemoveUnitFromGroups()

void RemoveUnitFromGroups ( CUnit unit)

Remove a unit from a group.

Remove unit from its groups

Parameters
unitUnit to remove from group.

◆ RescueUnits()

void RescueUnits ( )

Check for rescue each second.

Rescue units.

Look through all rescueable players, if they could be rescued.

◆ RestoreSelection()

void RestoreSelection ( )

Restore selection.

Restore selection.

◆ SaveGroups()

void SaveGroups ( CFile file)

Save groups.

Save groups.

Save groups.

Parameters
fileOutput file.

◆ SaveSelection()

void SaveSelection ( )

Save selection to restore after.

Save selection to restore after.

◆ SaveSelections()

void SaveSelections ( CFile file)

Save current selection state.

Save current selection state.

Parameters
fileOutput file.

◆ SaveUnit()

void SaveUnit ( const CUnit unit,
CFile file 
)

save unit-structure

Save the state of a unit to file.

Parameters
unitUnit pointer to be saved.
fileOutput file.

◆ SelectAirUnitsInRectangle()

int SelectAirUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Select flying units in the selection rectangle.

Select own air units in a rectangle.

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ SelectedUnitChanged()

void SelectedUnitChanged ( )

Called whenever the selected unit was updated.

The selected unit has been altered.

◆ SelectGroundUnitsInRectangle()

int SelectGroundUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Select ground units in the selection rectangle.

Select own ground units in a rectangle.

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ SelectGroup()

int SelectGroup ( int  group_number,
GroupSelectionMode  mode 
)

Select the units belonging to a particular group.

Change selected units to units from group group_number Doesn't change the selection if the group has no unit.

Parameters
group_numbernumber of the group to be selected.
Returns
number of units in the group.

◆ SelectGroupFromUnit()

int SelectGroupFromUnit ( CUnit unit)

Select the units from the same group as the one in parameter.

Select units from group of a particular unit. Doesn't change the selection if the group has no unit, or the unit doesn't belong to any group.

Parameters
unitunit belonging to the group to be selected.
Returns
0 if the unit doesn't belong to a group, or the number of units in the group.

◆ SelectionCclRegister()

void SelectionCclRegister ( )

Register CCL selection features.

Register CCL features for selections.

◆ SelectSingleUnit()

void SelectSingleUnit ( CUnit unit)

Select one unit as selection.

Select a single unit, unselecting the previous ones

Parameters
unitPointer to unit to be selected.

◆ SelectUnit()

int SelectUnit ( CUnit unit)

Add a unit to selection.

Add a unit to the other selected units.

Parameters
unitPointer to unit to add.
Returns
true if added to selection, false otherwise (if Selected.size() == MaxSelectable or unit is already selected or unselectable)

◆ SelectUnitsByType()

int SelectUnitsByType ( CUnit base)

Select units from the same type (if selectable by rectangle)

Select units from a particular type and belonging to the local player.

The base is included in the selection and defines the type of the other units to be selected.

Parameters
baseSelect all units of same type.
Returns
Number of units found, 0 means selection unchanged

FIXME: 0 can't happen. Maybe when scripting will use it?

FIXME: should always select the nearest 9 units to the base!

◆ SelectUnitsInRectangle()

int SelectUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Select the units in the selection rectangle.

Select units in a rectangle. Proceed in order in none found:

  • select local player mobile units
  • select one local player static unit (random)
  • select one neutral unit (critter, mine...)
  • select one enemy unit (random)
Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ SetGroup()

void SetGroup ( CUnit **  units,
unsigned int  nunits,
int  num 
)

Set the contents of a particular group with an array of units.

Set group num contents to unit array "units"

Parameters
unitsArray of units to place into group.
nunitsNumber of units in array.
numGroup number for storage.

◆ ShowOrder()

void ShowOrder ( const CUnit unit)

Show a unit's orders.

Show the current order of a unit.

Parameters
unitPointer to the unit.

◆ TargetPriorityCalculate()

int TargetPriorityCalculate ( const CUnit *const  attacker,
const CUnit *const  dest 
)

Check if target attacks us (or has us as goal for any action)

Unit can attack back.

◆ ThreatCalculate()

int ThreatCalculate ( const CUnit unit,
const CUnit dest 
)

Calculate some value to measure the unit's priority for AI.

◆ ToggleSelectUnit()

int ToggleSelectUnit ( CUnit unit)

Add a unit to selected if not already selected, remove it otherwise.

Toggle the selection of a unit in a group of selected units

Parameters
unitPointer to unit to be toggled.
Returns
0 if unselected, 1 otherwise Toggle the selection of a unit in a group of selected units
Parameters
unitPointer to unit to be toggled.
Returns
0 if unselected, 1 otherwise

◆ ToggleUnitsByType()

int ToggleUnitsByType ( CUnit base)

Toggle units from the same type (if selectable by rectangle)

Toggle units from a particular type and belonging to the local player.

The base is included in the selection and defines the type of the other units to be selected.

Parameters
baseToggle all units of same type.
Returns
Number of units found, 0 means selection unchanged

FIXME: toggle not written FIXME: should always select the nearest 9 units to the base!

◆ UnitCclRegister()

void UnitCclRegister ( )

register CCL units features

Register CCL features for unit.

◆ UnitClearOrders()

void UnitClearOrders ( CUnit unit)

Remove the Orders of a Unit.

Removes all orders from a unit.

Parameters
unitThe unit that will have all its orders cleared

◆ UnitCountSeen()

void UnitCountSeen ( CUnit unit)

Does a recount for VisCount.

Recalculates a units visiblity count. This happens really often, Like every time a unit moves. It's really fast though, since we have per-tile counts.

Parameters
unitpointer to the unit to check if seen

◆ UnitGoesOutOfFog()

void UnitGoesOutOfFog ( CUnit unit,
const CPlayer player 
)

Call when an Unit goes out of fog.

This function should get called when a unit goes out of fog of war.

Parameters
unitThe unit that goes out of fog.
playerThe player the unit goes out of fog for.
Note
For units that are visible under fog (mostly buildings) we use reference counts, from the players that know about the building. When an building goes under fog it gets a refs increase, and when it shows up it gets a decrease. It must not get an decrease the first time it's seen, so we have to keep track of what player saw what units, with SeenByPlayer.

◆ UnitGoesUnderFog()

void UnitGoesUnderFog ( CUnit unit,
const CPlayer player 
)

Call when an Unit goes under fog.

This function should get called when a unit goes under fog of war.

Parameters
unitThe unit that goes under fog.
playerThe player the unit goes out of fog for.

◆ UnitHeadingFromDeltaXY()

void UnitHeadingFromDeltaXY ( CUnit unit,
const Vec2i delta 
)

Heading and frame from delta direction.

Change unit heading/frame from delta direction x, y.

Parameters
unitUnit for new direction looking.
deltamap tile delta direction.

◆ UnitLost()

void UnitLost ( CUnit unit)

Handle the loss of a unit (food,...)

Update information for lost units.

Parameters
unitPointer to unit.
Note
Also called by ChangeUnitOwner

◆ UnitOnScreen()

CUnit* UnitOnScreen ( int  x,
int  y 
)

Get unit under cursor.

Unit on map screen.

Select units on screen. (x, y are in pixels relative to map 0,0). Not GAMEPLAY safe, uses ReplayRevealMap

More units on same position. Cycle through units. First take highest unit.

Parameters
xX pixel position.
yY pixel position.
Returns
An unit on x, y position.

◆ UnitReference() [1/2]

std::string UnitReference ( const CUnit unit)

Generate a unit reference, a printable unique string for unit.

Generate a unit reference, a printable unique string for unit.

◆ UnitReference() [2/2]

std::string UnitReference ( const CUnitPtr unit)

Generate a unit reference, a printable unique string for unit.

Generate a unit reference, a printable unique string for unit.

◆ UnitUpdateHeading()

void UnitUpdateHeading ( CUnit unit)

Update frame from heading.

Update sprite frame for new heading.

◆ UnmarkUnitFieldFlags()

void UnmarkUnitFieldFlags ( const CUnit unit)

Unmark the field with the FieldFlags.

Mark the field with the FieldFlags.

Parameters
unitunit to mark.

◆ UnSelectAll()

void UnSelectAll ( )

Clear current selection.

Unselect all the units in the current selection

◆ UnSelectUnit()

void UnSelectUnit ( CUnit unit)

Remove a unit from selection.

Unselect unit

Parameters
unitPointer to unit to be unselected.

◆ UpdateForNewUnit()

void UpdateForNewUnit ( const CUnit unit,
int  upgrade 
)
Todo:
more docu

Update for new unit. Food and income ...

Parameters
unitNew unit pointer.
upgradeTrue unit was upgraded.

◆ UpdateUnitSightRange()

void UpdateUnitSightRange ( CUnit unit)

Update unit->CurrentSightRange.

Update the Unit Current sight range to good value and transported units inside.

Parameters
unitunit to update SightRange

◆ ViewPointDistance()

int ViewPointDistance ( const Vec2i pos)

Calculate the distance from current view point to coordinate.

Compute the distance from the view point to a given point.

Parameters
posmap tile position.
Todo:
FIXME: is it the correct place to put this function in?

◆ ViewPointDistanceToUnit()

int ViewPointDistanceToUnit ( const CUnit dest)

Calculate the distance from current view point to unit.

Compute the distance from the view point to a given unit.

Parameters
destDistance to this unit.
Todo:
FIXME: is it the correct place to put this function in?

Variable Documentation

◆ CurrentViewport

const CViewport* CurrentViewport

Config: spend resources for building with multiple workers.

◆ DrawSelection

void(* DrawSelection) (IntColor, int, int, int, int)

Show unit's name for some time.

Show that units are selected.

Parameters
colorFIXME
x1,y1Coordinates of the top left corner.
x2,y2Coordinates of the bottom right corner.

◆ DrawSelectionEllipse

void(*)(IntColor, int, int, int, int) DrawSelectionEllipse(float factor)

Draw ellipse around unit.

◆ EnableBuildingCapture

bool EnableBuildingCapture

Config: training queues enabled.

◆ EnableTrainingQueue

bool EnableTrainingQueue

Show unit's name for some time.

◆ MaxSelectable

unsigned int MaxSelectable

◆ Preference

CPreference Preference

Lua handler count.

◆ ResourcesMultiBuildersMultiplier

int ResourcesMultiBuildersMultiplier

Config: reveal attacker enabled.

◆ RevealAttacker

bool RevealAttacker

Config: building capture enabled.

Config: building capture enabled.

◆ Selected

std::vector<CUnit *> Selected

How many units could be selected.

How many units could be selected.

◆ ShowNameDelay

unsigned long ShowNameDelay

Show orders for some time.

◆ ShowNameTime

unsigned long ShowNameTime

Delay to show unit's name.

◆ ShowOrdersCount

unsigned long ShowOrdersCount

All sprite's infos.

Todo:
could be moved into the user interface ?
(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.