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

src/include/unit.h File Reference

#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 ai unit couldn't change target. More...
class  CPreference

unit.h - The unit headerfile.

#define PRIORITY_FACTOR   0x00001000
#define HEALTH_FACTOR   0x00000001
#define DISTANCE_FACTOR   0x00010000
#define INRANGE_FACTOR   0x00001000
#define INRANGE_BONUS   0x00100000
#define CANATTACK_BONUS   0x00010000
#define AIPRIORITY_BONUS   0x01000000
#define NextDirection   32
#define UnitNotSeen   0x7fffffff
#define NoUnitP   (CUnit *)0
#define UnitNumber(unit)   ((unit).UnitManagerData.GetUnitId())
#define IsOnlySelected(unit)   (NumSelected == 1 && Selected[0] == &(unit))
 Check if unit is the currently only selected.
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.
unsigned long ShowOrdersCount
 All sprite's infos.
unsigned long ShowNameDelay
 Show orders for some time.
unsigned long ShowNameTime
 Delay to show unit's name.
bool EnableTrainingQueue
 Show unit's name for some time.
bool EnableBuildingCapture
 Config: training queues enabled.
bool RevealAttacker
 Config: building capture enabled.
int ResourcesMultiBuildersMultiplier
 Config: reveal attacker enabled.
const CViewportCurrentViewport
 Config: spend resources for building with multiple workers.
void(* DrawSelection )(Uint32, int, int, int, int)
 Show unit's name for some time.
int MaxSelectable
 How many units selected.
CUnit ** Selected
 How many units could be selected.
CUnit ** TeamSelected [PlayerMax]
 currently selected units
int NumSelected
 teams currently selected units
int TeamNumSelected [PlayerMax]
 how many units selected
void SelectedUnitChanged ()
 Called whenever the selected unit was updated.
int MapDistanceBetweenTypes (const CUnitType &src, const Vec2i &pos1, const CUnitType &dst, const Vec2i &pos2)
 Returns the map diestance between to unittype as locations.
void DrawUnitSelection (const CViewport &vp, const CUnit &unit)
 CurrentViewport.
void MarkUnitFieldFlags (const CUnit &unit)
 Number of Units a team member has selected.
void UnmarkUnitFieldFlags (const CUnit &unit)
 Unmark the field with the FieldFlags.
void UpdateUnitSightRange (CUnit &unit)
 Update unit->CurrentSightRange.
CUnitMakeUnit (const CUnitType &type, CPlayer *player)
 Create a new unit.
CUnitMakeUnitAndPlace (const Vec2i &pos, const CUnitType &type, CPlayer *player)
 Create a new unit and place on map.
void UnitLost (CUnit &unit)
 Handle the loss of a unit (food,...).
void UnitClearOrders (CUnit &unit)
 Remove the Orders of a Unit.
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.
void UnitGoesOutOfFog (CUnit &unit, const CPlayer &player)
 Call when an Unit goes out of fog.
void UnitsOnTileMarkSeen (const CPlayer &player, int x, int y, int p)
 Marks a unit as seen.
void UnitsOnTileMarkSeen (const CPlayer &player, unsigned int index, int p)
void UnitsOnTileUnmarkSeen (const CPlayer &player, int x, int y, int p)
 Unmarks a unit as seen.
void UnitsOnTileUnmarkSeen (const CPlayer &player, unsigned int index, int p)
void UnitCountSeen (CUnit &unit)
 Does a recount for VisCount.
void RescueUnits ()
 Check for rescue each second.
int DirectionToHeading (const Vec2i &dir)
 Convert direction (dx,dy) to heading (0-255).
void CorrectWallDirections (CUnit &unit)
 Correct directions for placed wall.
void CorrectWallNeighBours (CUnit &unit)
 Correct the surrounding walls.
void UnitUpdateHeading (CUnit &unit)
 Update frame from heading.
void UnitHeadingFromDeltaXY (CUnit &unit, const Vec2i &delta)
 Heading and frame from delta direction.
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.
CBuildRestrictionOnTopOnTopDetails (const CUnit &unit, const CUnitType *parent)
 Return the rule used to build this building.
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.
int ExtraDeathIndex (const char *death)
 Get the suitable animation frame depends of unit's damaged type.
CUnitUnitOnScreen (CUnit *unit, int x, int y)
void LetUnitDie (CUnit &unit)
 Let a unit die.
void DestroyAllInside (CUnit &source)
 Destroy all units inside another unit.
int ThreatCalculate (const CUnit &unit, const CUnit &dest)
 Calculate some value to measure the unit's priority for AI.
void HitUnit (CUnit *attacker, CUnit &target, int damage, const Missile *missile=NULL)
 Hit unit with damage, if destroyed give attacker the points.
int ViewPointDistance (const Vec2i &pos)
 Calculate the distance from current view point to coordinate.
int ViewPointDistanceToUnit (const CUnit &dest)
 Calculate the distance from current view point to unit.
int CanTarget (const CUnitType *type, const CUnitType *dest)
 Can this unit-type attack the other (destination).
int CanTransport (const CUnit &transporter, const CUnit &unit)
 Can transporter transport the other unit.
std::string UnitReference (const CUnit &unit)
 Generate a unit reference, a printable unique string for unit.
std::string UnitReference (const CUnitPtr &unit)
 Generate a unit reference, a printable unique string for unit.
void SaveUnit (const CUnit &unit, CFile &file)
 save unit-structure
void InitUnits ()
 Initialize unit module.
void CleanUnits ()
 Clean unit module.
void DrawSelectionNone (Uint32, int, int, int, int)
 Draw nothing around unit.
void DrawSelectionCircle (Uint32, int, int, int, int)
 Draw circle around unit.
void DrawSelectionCircleWithTrans (Uint32, int, int, int, int)
 Draw circle filled with alpha around unit.
void DrawSelectionRectangle (Uint32, int, int, int, int)
 Draw rectangle around unit.
void DrawSelectionRectangleWithTrans (Uint32, int, int, int, int)
 Draw rectangle filled with alpha around unit.
void DrawSelectionCorners (Uint32, int, int, int, int)
 Draw corners around unit.
void DecorationCclRegister ()
 Register CCL decorations features.
void LoadDecorations ()
 Load the decorations (health,mana) of units.
void CleanDecorations ()
 Clean the decorations (health,mana) of units.
void DrawShadow (const CUnitType &type, int frame, const PixelPos &screenPos)
 Draw unit's shadow.
int FindAndSortUnits (const CViewport &vp, std::vector< CUnit * > &table)
 Draw all units visible on map in viewport.
void ShowOrder (const CUnit &unit)
 Show a unit's orders.
void InitGroups ()
 Initialize data structures for groups.
void SaveGroups (CFile &file)
 Save groups.
void CleanGroups ()
 Cleanup groups.
int GetNumberUnitsOfGroup (int num, GroupSelectionMode mode=SELECTABLE_BY_RECTANGLE_ONLY)
 Get the number of units in a particular group.
CUnit ** GetUnitsOfGroup (int num)
 Get the array of units of a particular group.
void ClearGroup (int num)
 Remove all units from a group.
void AddToGroup (CUnit **units, int nunits, int num)
 Add the array of units to the group.
void SetGroup (CUnit **units, int nunits, int num)
 Set the contents of a particular group with an array of units.
void RemoveUnitFromGroups (CUnit &unit)
 Remove a unit from a group.
void GroupCclRegister ()
 Register CCL group features.
bool IsGroupTainted (int num)
void SaveSelection ()
 Save selection to restore after.
void RestoreSelection ()
 Restore selection.
void UnSelectAll ()
 Clear current selection.
void ChangeTeamSelectedUnits (CPlayer &player, const std::vector< CUnit * > &units, int adjust)
 Changed TeamUnit Selection.
int SelectUnit (CUnit &unit)
 Add a unit to selection.
void SelectSingleUnit (CUnit &unit)
 Select one unit as selection.
void UnSelectUnit (CUnit &unit)
 Remove a unit from selection.
int ToggleSelectUnit (CUnit &unit)
 Add a unit to selected if not already selected, remove it otherwise.
int SelectUnitsByType (CUnit &base)
 Select units from the same type (if selectable by rectangle).
int ToggleUnitsByType (CUnit &base)
 Toggle units from the same type (if selectable by rectangle).
int SelectGroup (int group_number, GroupSelectionMode mode=SELECTABLE_BY_RECTANGLE_ONLY)
 Select the units belonging to a particular group.
int AddGroupFromUnitToSelection (CUnit &unit)
 Add the units from the same group as the one in parameter.
int SelectGroupFromUnit (CUnit &unit)
 Select the units from the same group as the one in parameter.
int SelectUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Select the units in the selection rectangle.
int SelectGroundUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Select ground units in the selection rectangle.
int SelectAirUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Select flying units in the selection rectangle.
int AddSelectedUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Add the units in the selection rectangle to the current selection.
int AddSelectedGroundUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Add ground units in the selection rectangle to the current selection.
int AddSelectedAirUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Add flying units in the selection rectangle to the current selection.
void InitSelections ()
 Init selections.
void SaveSelections (CFile &file)
 Save current selection state.
void CleanSelections ()
 Clean up selections.
void SelectionCclRegister ()
 Register CCL selection features.
void UnitCclRegister ()
 register CCL units features

Define Documentation

#define AIPRIORITY_BONUS   0x01000000

#define CANATTACK_BONUS   0x00010000

#define DISTANCE_FACTOR   0x00010000

#define HEALTH_FACTOR   0x00000001

#define INRANGE_BONUS   0x00100000

#define INRANGE_FACTOR   0x00001000

#define IsOnlySelected ( unit   )     (NumSelected == 1 && Selected[0] == &(unit))

Check if unit is the currently only selected.

#define NextDirection   32

#define NoUnitP   (CUnit *)0

#define PRIORITY_FACTOR   0x00001000

#define UnitNotSeen   0x7fffffff

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

Returns unit number (unique to this unit)


Typedef Documentation

typedef COrder* COrderPtr


Enumeration Type Documentation

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

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:
unit unit 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.

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,start of selection rectangle
corner_bottomright end of selection rectangle
Returns:
the number of units found.

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,start of selection rectangle
corner_bottomright end of selection rectangle
Returns:
the number of units found.

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,start of selection rectangle
corner_bottomright end of selection rectangle
Returns:
the _total_ number of units selected.

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

Add the array of units to the group.

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

Parameters:
units Array of units to place into group.
nunits Number of units in array.
num Group number for storage.

CUnit* CanBuildHere ( const CUnit unit,
const CUnitType type,
const Vec2i pos 
)

Todo:
more docu

bool CanBuildOn ( const Vec2i pos,
int  mask 
)

Todo:
more docu

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

FIXME: more docu.

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:
source Unit type pointer of the attacker.
dest Unit type pointer of the target.
Returns:
0 if attacker can't target the unit, else a positive number.

int CanTransport ( const CUnit transporter,
const CUnit unit 
)

Can transporter transport the other unit.

Can the transporter transport the other unit.

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

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

Changed TeamUnit Selection.

Change A Unit Selection from my Team

Parameters:
player The Player who is selecting the units
units The Units to add/remove
adjust 0 = reset, 1 = remove units, 2 = add units

void CleanDecorations (  ) 

Clean the decorations (health,mana) of units.

Clean decorations.

void CleanGroups (  ) 

Cleanup groups.

Clean up group part.

void CleanSelections (  ) 

Clean up selections.

Clean up the selection module.

void CleanUnits (  ) 

Clean unit module.

Clean up unit module.

void ClearGroup ( int  num  ) 

Remove all units from a group.

Clear contents of group num

Parameters:
num Group number.

void CorrectWallDirections ( CUnit unit  ) 

Correct directions for placed wall.

Correct direction for placed wall.

Parameters:
unit The wall unit.

void CorrectWallNeighBours ( CUnit unit  ) 

Correct the surrounding walls.

Correct the surrounding walls.

Parameters:
unit The wall unit.

void DecorationCclRegister (  ) 

Register CCL decorations features.

Register CCL features for decorations.

void DestroyAllInside ( CUnit source  ) 

Destroy all units inside another unit.

Destroy all units inside unit.

Parameters:
source container.

int DirectionToHeading ( const Vec2i delta  ) 

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

Convert direction to heading.

Parameters:
delta Delta.
Returns:
Angle (0..255)

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

Draw circle around unit.

Show selected units with circle.

Parameters:
color Color to draw circle
x1,y1 Coordinates of the top left corner.
x2,y2 Coordinates of the bottom right corner.

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

Draw circle filled with alpha around unit.

Show selected units with circle.

Parameters:
color Color to draw and fill circle.
x1,y1 Coordinates of the top left corner.
x2,y2 Coordinates of the bottom right corner.

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

Draw corners around unit.

Draw selected corners around the unit.

Parameters:
color Color to draw corners.
x1,y1 Coordinates of the top left corner.
x2,y2 Coordinates of the bottom right corner.

void DrawSelectionNone ( Uint32  ,
int  ,
int  ,
int  ,
int   
)

Draw nothing around unit.

Don't show selected units.

Parameters:
color Color to draw, nothing in this case.
x1,y1 Coordinates of the top left corner.
x2,y2 Coordinates of the bottom right corner.

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

Draw rectangle around unit.

Draw selected rectangle around the unit.

Parameters:
color Color to draw rectangle.
x1,y1 Coordinates of the top left corner.
x2,y2 Coordinates of the bottom right corner.

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

Draw rectangle filled with alpha around unit.

Draw selected rectangle around the unit.

Parameters:
color Color to draw and fill rectangle.
x1,y1 Coordinates of the top left corner.
x2,y2 Coordinates of the bottom right corner.

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

Draw unit's shadow.

Draw unit's shadow.

Parameters:
type Pointer to the unit type.
frame Frame number
screenPos Screen position of the unit.
Todo:
FIXME: combine new shadow code with old shadow code.

void DrawUnitSelection ( const CViewport vp,
const CUnit unit 
)

CurrentViewport.

CurrentViewport.

Show selection marker around a unit.

Parameters:
unit Pointer to unit.

void DropOutAll ( const CUnit source  ) 

Drop out all units in the unit.

Drop out all units inside unit.

Parameters:
source All units inside source are dropped out.

void DropOutNearest ( CUnit unit,
const Vec2i goalPos,
const CUnit container 
)

Todo:
more docu

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:
unit Unit to drop out.
heading Direction in which the unit should appear.
container Unit "containing" unit to drop (may be different of unit.Container).

int ExtraDeathIndex ( const char *  death  ) 

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

Find the index of a extra death type

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:
vp Viewport to be drawn.
table Table of units to return in sorted order

CUnit* GetFirstContainer ( const CUnit unit  ) 

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

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

int GetNumberUnitsOfGroup ( int  num,
GroupSelectionMode  mode 
)

Get the number of units in a particular group.

Return the number of units of group num

Parameters:
num Group number.
Returns:
Returns the number of units in the group.

CUnit** GetUnitsOfGroup ( int  num  ) 

Get the array of units of a particular group.

Return the units of group num

Parameters:
num Group number.
Returns:
Returns an array of all units in the group.

void GroupCclRegister (  ) 

Register CCL group features.

Register CCL features for groups.

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:
attacker Unit that attacks.
target Unit that is hit.
damage How many damage to take.
missile Which missile took the damage.

void InitGroups (  ) 

Initialize data structures for groups.

Initialize data structures for groups.

Initialize group part.

Todo:
Not needed with the new unit code!

void InitSelections (  ) 

Init selections.

Initialize the selection module.

void InitUnits (  ) 

Initialize unit module.

Initialize unit module.

bool IsGroupTainted ( int  num  ) 

void LetUnitDie ( CUnit unit  ) 

Let a unit die.

Let an unit die.

Parameters:
unit Unit to be destroyed.

void LoadDecorations (  ) 

Load the decorations (health,mana) of units.

Load decoration.

CUnit* MakeUnit ( const CUnitType type,
CPlayer player 
)

Create a new unit.

Create a new unit.

Parameters:
type Pointer to unit-type.
player Pointer to owning player.
Returns:
Pointer to created unit.

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

Create a new unit and place on map.

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

Returns the map diestance between to unittype as locations.

void MarkUnitFieldFlags ( const CUnit unit  ) 

Number of Units a team member has selected.

Mark the field with the FieldFlags.

Mark the field with the FieldFlags.

Parameters:
unit unit to mark.

void NearestOfUnit ( const CUnit unit,
const Vec2i pos,
Vec2i dpos 
)

Todo:
more docu

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:
unit the unit that is "OnTop"
parent the parent unit if known. (guess otherwise)
Returns:
the BuildingRestrictionDetails

void RemoveUnitFromGroups ( CUnit unit  ) 

Remove a unit from a group.

Remove unit from its groups

Parameters:
unit Unit to remove from group.

void RescueUnits (  ) 

Check for rescue each second.

Rescue units.

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

void RestoreSelection (  ) 

Restore selection.

Restore selection.

void SaveGroups ( CFile file  ) 

Save groups.

Save groups.

Parameters:
file Output file.

void SaveSelection (  ) 

Save selection to restore after.

Save selection to restore after.

Save selection to restore after.

void SaveSelections ( CFile file  ) 

Save current selection state.

Save current selection state.

Parameters:
file Output file.

void SaveUnit ( const CUnit unit,
CFile file 
)

save unit-structure

Save the state of a unit to file.

Parameters:
unit Unit pointer to be saved.
file Output file.

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,start of selection rectangle
corner_bottomright end of selection rectangle
Returns:
the number of units found.

void SelectedUnitChanged (  ) 

Called whenever the selected unit was updated.

The selected unit has been altered.

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,start of selection rectangle
corner_bottomright end of selection rectangle
Returns:
the number of units found.

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_number number of the group to be selected.
Returns:
number of units in the group.

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:
unit unit 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.

void SelectionCclRegister (  ) 

Register CCL selection features.

Register CCL features for selections.

void SelectSingleUnit ( CUnit unit  ) 

Select one unit as selection.

Select a single unit, unselecting the previous ones

Parameters:
unit Pointer to unit to be selected.

int SelectUnit ( CUnit unit  ) 

Add a unit to selection.

Add a unit to the other selected units.

Parameters:
unit Pointer to unit to add.
Returns:
true if added to selection, false otherwise (if NumSelected == MaxSelectable or unit is already selected or unselectable)

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:
base Select 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!

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,start of selection rectangle
corner_bottomright end of selection rectangle
Returns:
the number of units found.

void SetGroup ( CUnit **  units,
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:
units Array of units to place into group.
nunits Number of units in array.
num Group number for storage.

void ShowOrder ( const CUnit unit  ) 

Show a unit's orders.

Show the current order of a unit.

Parameters:
unit Pointer to the unit.

int ThreatCalculate ( const CUnit unit,
const CUnit dest 
)

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

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:
unit Pointer to unit to be toggled.
Returns:
0 if unselected, 1 otherwise

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:
base Toggle 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!

void UnitCclRegister (  ) 

register CCL units features

Register CCL features for unit.

void UnitClearOrders ( CUnit unit  ) 

Remove the Orders of a Unit.

Removes all orders from a unit.

Parameters:
unit The unit that will have all its orders cleared

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:
unit pointer to the unit to check if seen

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:
unit The unit that goes out of fog.
player The 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.

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:
unit The unit that goes under fog.
player The player the unit goes out of fog for.

void UnitHeadingFromDeltaXY ( CUnit unit,
const Vec2i delta 
)

Heading and frame from delta direction.

void UnitLost ( CUnit unit  ) 

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

Update information for lost units.

Parameters:
unit Pointer to unit.
Note:
Also called by ChangeUnitOwner

CUnit* UnitOnScreen ( CUnit ounit,
int  x,
int  y 
)

Todo:
more docu
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. ounit is the old one. First take highest unit.

Parameters:
ounit Old selected unit.
x X pixel position.
y Y pixel position.
Returns:
An unit on x, y position.

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.

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.

void UnitsOnTileMarkSeen ( const CPlayer player,
const unsigned int  index,
int  cloak 
)

Mark all units on a tile as now visible.

Parameters:
player The player this is for.
x x location to check
y y location to check
cloak If we mark cloaked units too.

void UnitsOnTileMarkSeen ( const CPlayer player,
int  x,
int  y,
int  p 
)

Marks a unit as seen.

void UnitsOnTileUnmarkSeen ( const CPlayer player,
const unsigned int  index,
int  cloak 
)

This function unmarks units on x, y as seen. It uses a reference count.

Parameters:
player The player to mark for.
x x location to check if building is on, and mark as seen
y y location to check if building is on, and mark as seen
cloak If this is for cloaked units.

void UnitsOnTileUnmarkSeen ( const CPlayer player,
int  x,
int  y,
int  p 
)

Unmarks a unit as seen.

void UnitUpdateHeading ( CUnit unit  ) 

Update frame from heading.

Update sprite frame for new heading.

void UnmarkUnitFieldFlags ( const CUnit unit  ) 

Unmark the field with the FieldFlags.

Mark the field with the FieldFlags.

Parameters:
unit unit to mark.

void UnSelectAll (  ) 

Clear current selection.

Unselect all the units in the current selection

void UnSelectUnit ( CUnit unit  ) 

Remove a unit from selection.

Unselect unit

Parameters:
unit Pointer to unit to be unselected.

void UpdateForNewUnit ( const CUnit unit,
int  upgrade 
)

Todo:
more docu
Update for new unit. Food and income ...

Parameters:
unit New unit pointer.
upgrade True unit was upgraded.

void UpdateUnitSightRange ( CUnit unit  ) 

Update unit->CurrentSightRange.

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

Parameters:
unit unit to update SightRange

int ViewPointDistance ( const Vec2i pos  ) 

Calculate the distance from current view point to coordinate.

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:
dest Distance to this unit.
Todo:
FIXME: is it the correct place to put this function in?


Variable Documentation

Config: spend resources for building with multiple workers.

void(* DrawSelection)(Uint32, int, int, int, int)

Show unit's name for some time.

Show that units are selected.

Parameters:
color FIXME
x1,y1 Coordinates of the top left corner.
x2,y2 Coordinates of the bottom right corner.

Config: training queues enabled.

Show unit's name for some time.

How many units selected.

teams currently selected units

Lua handler count.

Config: reveal attacker enabled.

Config: building capture enabled.

How many units could be selected.

unsigned long ShowNameDelay

Show orders for some time.

unsigned long ShowNameTime

Delay to show unit's name.

unsigned long ShowOrdersCount

All sprite's infos.

Todo:
could be moved into the user interface ?

int TeamNumSelected[PlayerMax]

how many units selected

CUnit** TeamSelected[PlayerMax]

currently selected units

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