$treeview $search $mathjax
Stratagus  2.2.6
$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 "SDL.h"
#include "unittype.h"
#include "tile.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::COrder
struct  CUnit::_seen_stuff_
 Unit visibility counts. More...
struct  CUnit::_unit_anim_
 action counter More...
union  CUnit::_order_data_
 spells to auto cast More...
struct  CUnit::_order_data_::_order_move_
struct  CUnit::_order_data_::_order_built_
 ActionMove,... More...
struct  CUnit::_order_data_::_order_build_
 ActionBuilt,... More...
struct  CUnit::_order_data_::_order_resource_
 ActionBuild. More...
struct  CUnit::_order_data_::_order_resource_worker_
 Resource still. More...
struct  CUnit::_order_data_::_order_repair_
 Worker harvesting. More...
struct  CUnit::_order_data_::_order_research_
 Repairing unit. More...
struct  CUnit::_order_data_::_order_upgradeto_
 Research action. More...
struct  CUnit::_order_data_::_order_train_
 Upgrade to action. More...
class  CUnitPtr
class  CUnitDrawProxy
struct  CUnitTypeFinder
struct  CResourceFinder
struct  CResourceDepositFinder
class  CPreference

unit.h - The unit headerfile.

#define NextDirection   32
#define UnitNotSeen   0x7fffffff
#define NoUnitP   (CUnit *)0
#define InfiniteDistance   INT_MAX
#define FlushCommands   1
#define MAX_UNIT_SLOTS   65535
#define UnitNumber(unit)   ((unit).Slot)
#define NUM_GROUPS   10
#define IsOnlySelected(unit)   (NumSelected == 1 && Selected[0] == &(unit))
 Check if unit is the currently only selected.
enum  _unit_action_ {
  UnitActionNone, UnitActionStill, UnitActionStandGround, UnitActionFollow,
  UnitActionMove, UnitActionAttack, UnitActionAttackGround, UnitActionDie,
  UnitActionSpellCast, UnitActionTrain, UnitActionUpgradeTo, UnitActionResearch,
  UnitActionBuilt, UnitActionBoard, UnitActionUnload, UnitActionPatrol,
  UnitActionBuild, UnitActionRepair, UnitActionResource, UnitActionReturnGoods,
  UnitActionTransformInto
}
enum  UnitVoiceGroup {
  VoiceSelected, VoiceAcknowledging, VoiceReady, VoiceHelpMe,
  VoiceDying, VoiceWorkCompleted, VoiceBuilding, VoiceDocking,
  VoiceRepairing, VoiceHarvesting, VoiceAttack, VoiceExtraDying
}
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 unsigned short UnitRef
typedef enum _unit_action_ UnitAction
typedef CUnit::COrderCOrderPtr
CPreference Preference
 Lua handler count.
CUnitUnits [MAX_UNIT_SLOTS]
int NumUnits
 Units used.
unsigned long ShowOrdersCount
 Number of units used.
bool EnableTrainingQueue
 Show orders for some time.
bool EnableBuildingCapture
 Config: training queues enabled.
bool RevealAttacker
 Config: building capture enabled.
const CViewportCurrentViewport
 Config: reveal attacker enabled.
void(* DrawSelection )(Uint32, int, int, int, int)
 Show orders 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.
static int MapDistance (const Vec2i &pos1, const Vec2i &pos2)
int MapDistanceToType (const Vec2i &pos1, const CUnitType &type, const Vec2i &pos2)
 Returns the map distance between two points with unit-type.
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 (CUnitType &type, CPlayer *player)
 Create a new unit.
CUnitMakeUnitAndPlace (const Vec2i &pos, 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)
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 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 GetAnimationDamagedState (CUnit &unit, int anim)
 Get the suitable animation frame when unit is damaged.
CUnitUnitFindResource (const CUnit &unit, int x, int y, int range, int resource, bool check_usage=false, const CUnit *destu=NULL)
 Find resource.
CUnitUnitFindMiningArea (const CUnit &unit, int x, int y, int range, int resource)
CUnitFindDeposit (const CUnit &unit, int range, int resource)
 Find nearest deposit.
CUnitFindIdleWorker (const CPlayer &player, const CUnit *last)
 Find the next idle worker.
int FindTerrainType (int movemask, int resmask, int rvresult, int range, const CPlayer *player, const Vec2i &startPos, Vec2i *pos)
 Find the neareast piece of terrain with specific flags.
int FindWoodInSight (const CUnit &unit, Vec2i *pos)
 Find the nearest piece of wood in sight range.
CUnitUnitOnScreen (CUnit *unit, int x, int y)
void LetUnitDie (CUnit &unit)
 Let a unit die.
void DestroyAllInside (CUnit &source)
 Destory all units inside another unit.
void HitUnit (CUnit *attacker, CUnit &target, int damage)
 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.
void SaveOrder (const COrderPtr order, CFile *file)
 Save an order.
void SaveUnit (const CUnit &unit, CFile *file)
 save unit-structure
void SaveUnits (CFile *file)
 save all units
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, int x, int y)
 Draw unit's shadow.
int FindAndSortUnits (const CViewport *vp, CUnit *table[])
 Draw all units visible on map in viewport.
int FindAndSortUnits (const CViewport *vp, CUnitDrawProxy table[])
void ShowOrder (const CUnit &unit)
 Show a unit's orders.
int FindUnitsByType (const CUnitType &type, CUnit **table)
 Find all units of this type.
int FindPlayerUnitsByType (const CPlayer &, const CUnitType &, CUnit **)
 Find all units of this type of the player.
CUnitUnitOnMapTile (const Vec2i &pos, unsigned int type)
 Return any unit on that map tile.
CUnitTargetOnMap (const CUnit &unit, int x1, int y1, int x2, int y2)
 Return possible attack target on that map area.
CUnitResourceOnMap (const Vec2i &pos, int resource, bool mine_on_top=true)
 Return resource, if on map tile.
CUnitResourceDepositOnMap (const Vec2i &pos, int resource)
 Return resource deposit, if on map tile.
CUnitAttackUnitsInDistance (const CUnit &unit, int range)
 Find best enemy in numeric range to attack.
CUnitAttackUnitsInRange (const CUnit &unit)
 Find best enemy in attack range to attack.
CUnitAttackUnitsInReactRange (const CUnit &unit)
 Find best enemy in reaction range to attack.
CUnitAutoAttackUnitsInDistance (const CUnit &unit, int range, CUnitCache &autotargets)
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.
void GroupHelpMe (CUnit *attacker, CUnit &defender)
 ask group members for help
int IsGroupTainted (int num)
void SaveSelection ()
 Save selection to restore after.
void RestoreSelection ()
 Restore selection.
void UnSelectAll ()
 Clear current selection.
void ChangeSelectedUnits (CUnit **units, int num_units)
 Select group as selection.
void ChangeTeamSelectedUnits (CPlayer &player, CUnit **units, int adjust, int count)
 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 (int tx, int ty, int w, int h)
 Select the units in the selection rectangle.
int SelectGroundUnitsInRectangle (int tx, int ty, int w, int h)
 Select ground units in the selection rectangle.
int SelectAirUnitsInRectangle (int tx, int ty, int w, int h)
 Select flying units in the selection rectangle.
int AddSelectedUnitsInRectangle (int tx, int ty, int w, int h)
 Add the units in the selection rectangle to the current selection.
int AddSelectedGroundUnitsInRectangle (int tx, int ty, int w, int h)
 Add ground units in the selection rectangle to the current selection.
int AddSelectedAirUnitsInRectangle (int tx, int ty, int w, int h)
 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 CclParseOrder (lua_State *l, COrderPtr order)
 Parse order.
void UnitCclRegister ()
 register CCL units features

Defines

#define MAX_PATH_LENGTH   28
 stored path length

Define Documentation

#define FlushCommands   1

#define InfiniteDistance   INT_MAX

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

Check if unit is the currently only selected.

#define MAX_PATH_LENGTH   28

stored path length

#define MAX_UNIT_SLOTS   65535

#define NextDirection   32

#define NoUnitP   (CUnit *)0

#define NUM_GROUPS   10

How many groups supported

#define UnitNotSeen   0x7fffffff

#define UnitNumber ( unit   )     ((unit).Slot)

Returns unit number (unique to this unit)


Typedef Documentation

typedef enum _unit_action_ UnitAction

All possible unit actions.

Note:
Always change the table HandleActionTable
See also:
HandleActionTable

typedef unsigned short UnitRef

Unit references over network, or for memory saving.


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.

All possible unit actions.

Note:
Always change the table HandleActionTable
See also:
HandleActionTable
Enumerator:
UnitActionNone 
UnitActionStill  No valid action.
UnitActionStandGround  unit stand still, does nothing
UnitActionFollow  unit stands ground
UnitActionMove  unit follows units
UnitActionAttack  unit moves to position/unit
UnitActionAttackGround  unit attacks position/unit
UnitActionDie  unit attacks ground
UnitActionSpellCast  unit dies
UnitActionTrain  unit casts spell
UnitActionUpgradeTo  building is training
UnitActionResearch  building is upgrading itself
UnitActionBuilt  building is researching spell
UnitActionBoard  building is under construction
UnitActionUnload  unit entering transporter
UnitActionPatrol  unit leaving transporter
UnitActionBuild  unit paroling area
UnitActionRepair  unit builds building
UnitActionResource  unit repairing
UnitActionReturnGoods  unit harvesting resources
UnitActionTransformInto  unit returning any resource

unit transform into type.

Voice groups for a unit

Enumerator:
VoiceSelected 
VoiceAcknowledging  If selected.
VoiceReady  Acknowledge command.
VoiceHelpMe  Command completed.
VoiceDying  If attacked.
VoiceWorkCompleted  If killed.
VoiceBuilding  only worker, work completed
VoiceDocking  only for building under construction
VoiceRepairing  only for transport reaching coast
VoiceHarvesting  repairing
VoiceAttack  harvesting
VoiceExtraDying  Attack command.

extra deaths


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 ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

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

Add the air units in the rectangle to the current selection

Parameters:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
Returns:
the number of units found.

int AddSelectedGroundUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

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

Add the ground units in the rectangle to the current selection

Parameters:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
Returns:
the number of units found.

int AddSelectedUnitsInRectangle ( int  x0,
int  y0,
int  x1,
int  y1 
)

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

Add the units in the rectangle to the current selection

Parameters:
x0 X start of selection rectangle in tile coordinates
y0 Y start of selection rectangle in tile coordinates
x1 X start of selection rectangle in tile coordinates
y1 Y start of selection rectangle in tile coordinates
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* AttackUnitsInDistance ( const CUnit unit,
int  range 
)

Find best enemy in numeric range to attack.

Attack units in distance.

If the unit can attack must be handled by caller. Choose the best target, that can be attacked.

Parameters:
unit Find in distance for this unit.
range Distance range to look.
Returns:
Unit to be attacked.

CUnit* AttackUnitsInRange ( const CUnit unit  ) 

Find best enemy in attack range to attack.

Attack units in attack range.

Parameters:
unit Find unit in attack range for this unit.
Returns:
Pointer to unit which should be attacked.

CUnit* AttackUnitsInReactRange ( const CUnit unit  ) 

Find best enemy in reaction range to attack.

Attack units in reaction range.

Parameters:
unit Find unit in reaction range for this unit.
Returns:
Pointer to unit which should be attacked.

CUnit* AutoAttackUnitsInDistance ( const CUnit unit,
int  range,
CUnitCache autotargets 
)

AutoAttack units in distance.

If the unit can attack must be handled by caller. Choose the best target, that can be attacked.

Parameters:
unit Find in distance for this unit.
range Distance range to look.
autotargets Know enemy targets to chose in range.
Returns:
Unit to be attacked.

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 CclParseOrder ( lua_State *  l,
COrderPtr  order 
)

Parse order.

Parse order

Parameters:
l Lua state.
order OUT: resulting order.

void ChangeSelectedUnits ( CUnit **  units,
int  count 
)

Select group as selection.

Replace a group of selected units by an other group of units.

Parameters:
units Array of units to be selected.
count Number of units in array to be selected.

void ChangeTeamSelectedUnits ( CPlayer player,
CUnit **  units,
int  adjust,
int  count 
)

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
count the number of units to be adjusted

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 DecorationCclRegister (  ) 

Register CCL decorations features.

Register CCL features for decorations.

void DestroyAllInside ( CUnit source  ) 

Destory 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,
int  x,
int  y 
)

Draw unit's shadow.

Draw unit's shadow.

Parameters:
type Pointer to the unit type.
frame Frame number
x Screen X position of the unit.
y Screen Y 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 FindAndSortUnits ( const CViewport vp,
CUnitDrawProxy  table[] 
)

int FindAndSortUnits ( const CViewport vp,
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* FindDeposit ( const CUnit unit,
int  range,
int  resource 
)

Find nearest deposit.

Find deposit. This will find a deposit for a resource

Parameters:
unit The unit that wants to find a resource.
x Closest to x
y Closest to y
range Maximum distance to the deposit.
resource Resource to find deposit from.
Note:
This will return a reachable allied depot.
Returns:
NoUnitP or deposit unit

CUnit* FindIdleWorker ( const CPlayer player,
const CUnit last 
)

Find the next idle worker.

Find the next idle worker

Parameters:
player Player's units to search through
last Previous idle worker selected
Returns:
NoUnitP or next idle worker

int FindPlayerUnitsByType ( const CPlayer player,
const CUnitType type,
CUnit **  table 
)

Find all units of this type of the player.

Find all units of type.

Parameters:
player we're looking for the units of this player
type type of unit requested
table table in which we have to store the units
Returns:
Returns the number of units found.

int FindTerrainType ( int  movemask,
int  resmask,
int  rvresult,
int  range,
const CPlayer player,
const Vec2i startPos,
Vec2i pos 
)

Find the neareast piece of terrain with specific flags.

int FindUnitsByType ( const CUnitType type,
CUnit **  table 
)

Find all units of this type.

Find all units of type.

Parameters:
type type of unit requested
table table in which we have to store the units
Returns:
Returns the number of units found.

int FindWoodInSight ( const CUnit unit,
Vec2i pos 
)

Find the nearest piece of wood in sight range.

int GetAnimationDamagedState ( CUnit unit,
int  anim 
)

Get the suitable animation frame when unit is damaged.

Get the suitable animation frame when unit is damaged.

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 GroupHelpMe ( CUnit attacker,
CUnit defender 
)

ask group members for help

Called if a member of Group is Attacked

Parameters:
attacker Pointer to attacker unit.
defender Pointer to unit that is being attacked.

void HitUnit ( CUnit attacker,
CUnit target,
int  damage 
)

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.

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.

int 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 ( 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,
CUnitType type,
CPlayer player 
)

Create a new unit and place on map.

static int MapDistance ( const Vec2i pos1,
const Vec2i pos2 
) [inline, static]

Returns the map distance between two points.

Parameters:
pos1 map tile position.
pos2 map tile position.
Returns:
The distance between in tiles.
Returns the map distance between two points.

Parameters:
pos1 map pixel position.
pos2 map pixel position.
Returns:
The distance between in pixels.

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

Returns the map diestance between to unittype as locations.

int MapDistanceToType ( const Vec2i pos1,
const CUnitType type,
const Vec2i pos2 
)

Returns the map distance between two points with unit-type.

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.

CUnit* ResourceDepositOnMap ( const Vec2i pos,
int  resource 
)

Return resource deposit, if on map tile.

CUnit* ResourceOnMap ( const Vec2i pos,
int  resource,
bool  mine_on_top = true 
)

Return resource, if on map tile.

void RestoreSelection (  ) 

Restore selection.

Restore selection.

void SaveGroups ( CFile file  ) 

Save groups.

Save groups.

Parameters:
file Output file.

void SaveOrder ( const COrderPtr  order,
CFile file 
)

Save an order.

Save an order.

Parameters:
order Order who should be saved.
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.

void SaveUnits ( CFile file  ) 

save all units

Save state of units to file.

Parameters:
file Output file.

int SelectAirUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

Select flying units in the selection rectangle.

Select own air units in a rectangle.

Parameters:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
Returns:
the number of units found.

void SelectedUnitChanged (  ) 

Called whenever the selected unit was updated.

The selected unit has been altered.

int SelectGroundUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

Select ground units in the selection rectangle.

Select own ground units in a rectangle.

Parameters:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
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 ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

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:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
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.

CUnit* TargetOnMap ( const CUnit source,
int  x1,
int  y1,
int  x2,
int  y2 
)

Return possible attack target on that map area.

Choose target on map area.

Parameters:
source Unit which want to attack.
x1 X position on map, tile-based.
y1 Y position on map, tile-based.
x2 X position on map, tile-based.
y2 Y position on map, tile-based.
Returns:
Returns ideal target on map tile.

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

CUnit* UnitFindMiningArea ( const CUnit unit,
int  x,
int  y,
int  range,
int  resource 
)

Find Mining Area for Resource.

Parameters:
unit The unit that wants to find a resource.
x Closest to x
y Closest to y
range Maximum distance to the resource.
resource The resource id.
Note:
This will return an usable resource building that doesn't belong to the player or one of his allies.
Returns:
NoUnitP or resource unit

CUnit* UnitFindResource ( const CUnit unit,
int  x,
int  y,
int  range,
int  resource,
bool  check_usage,
const CUnit destu 
)

Find resource.

Find Resource.

Parameters:
unit The unit that wants to find a resource.
x Closest to x
y Closest to y
range Maximum distance to the resource.
resource The resource id.
Note:
This will return an usable resource building that doesn't belong to the player or one of his allies.
Returns:
NoUnitP or resource unit

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* UnitOnMapTile ( const Vec2i pos,
unsigned int  type 
)

Return any unit on that map tile.

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 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: reveal attacker enabled.

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

Show orders 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 orders for some time.

How many units selected.

teams currently selected units

int NumUnits

Units used.

Lua handler count.

Config: building capture enabled.

How many units could be selected.

unsigned long ShowOrdersCount

Number of units used.

Todo:
could be moved into the user interface ?

int TeamNumSelected[PlayerMax]

how many units selected

CUnit** TeamSelected[PlayerMax]

currently selected units

CUnit* Units[MAX_UNIT_SLOTS]

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