$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

CUnit Class Reference

The big unit structure. More...

#include <unit.h>

List of all members.


Public Member Functions

 CUnit ()
void Init ()
COrderCreateOrder ()
 Generic/Teleporter goal pointer.
COrderCurrentOrder () const
UnitAction CurrentAction () const
bool IsIdle () const
void ClearAction ()
int GetReactRange () const
bool IsAgressive () const
bool IsInvisibile (const CPlayer &player) const
bool IsAlive () const
bool IsAliveOnMap () const
bool IsVisibleAsGoal (const CPlayer &player) const
bool IsVisibleOnMap (const CPlayer &player) const
int MapDistanceTo (const CUnit &dst) const
int MapDistanceTo (int x, int y) const
bool CanMove () const
int GetDrawLevel () const
unit.cpp - The units.
void RefsIncrease ()
 Increase a unit's reference count.
void RefsDecrease ()
 Decrease a unit's reference count.
void Init (CUnitType &type)
 Initialize unit structure with default values.
void AssignToPlayer (CPlayer *player)
 Assign unit to player.
void Place (const Vec2i &pos)
 Place a unit on map.
void MoveToXY (const Vec2i &pos)
 Move unit to tile(pos). (Do special stuff : vision, cachelist, pathfinding).
void AddInContainer (CUnit &host)
 Add a unit inside a container. Only deal with list stuff.
void ChangeOwner (CPlayer &newplayer)
 Change owner of unit.
void Remove (CUnit *host)
 Remove unit from map/groups/...
void AssignWorkerToMine (CUnit &mine)
void DeAssignWorkerFromMine (CUnit &mine)
void Release (bool final=false)
 Release a unit.
bool RestoreOrder ()
bool StoreOrder ()
bool IsVisible (const CPlayer &player) const
 Returns true, if unit is directly seen by an allied unit.
bool IsVisibleOnMinimap () const
 Returns true if unit is visible on minimap. Only for ThisPlayer.
bool IsVisibleInViewport (const CViewport *vp) const
 Returns true if unit is visible in an viewport. Only for ThisPlayer.
bool IsVisibleOnScreen () const
 Returns true, if unit is visible on current map view (any viewport).
void GetMapArea (int *sx, int *sy, int *ex, int *ey) const
bool IsEnemy (const CPlayer &player) const
bool IsEnemy (const CUnit &unit) const
bool IsAllied (const CPlayer &player) const
bool IsAllied (const CUnit &unit) const
bool IsSharedVision (const CPlayer &player) const
bool IsSharedVision (const CUnit &unit) const
bool IsBothSharedVision (const CPlayer &player) const
bool IsBothSharedVision (const CUnit &unit) const
bool IsTeamed (const CPlayer &player) const
bool IsTeamed (const CUnit &unit) const
bool IsUnusable (bool ignore_built_state=false) const
unit_draw.cpp - The draw routines for units.
void Draw (const CViewport *vp) const
 Draw a single unit.
map_radar.cpp - The map radar handling.
bool IsVisibleOnRadar (const CPlayer &pradar) const

Public Attributes

unsigned int Refs
int Slot
 Reference counter.
CUnit ** UnitSlot
 Assigned slot number.
CUnit ** PlayerSlot
 Slot pointer of Units.
CUnitNext
 Slot pointer of Player->Units.
int InsideCount
 Generic link pointer (on map).
int BoardCount
 Number of units inside.
CUnitUnitInside
 Number of units transported inside.
CUnitContainer
 Pointer to one of the units inside.
CUnitNextContained
 Pointer to the unit containing it (or 0).
CUnitPrevContained
 Next unit in the container.
CUnitNextWorker
 Previous unit in the container.
Vec2i tilePos
unsigned int Offset
 Map position X.
CUnitTypeType
 Map position as flat index offset (x + y * w).
CPlayerPlayer
 Pointer to unit-type (peon,...).
CUnitStatsStats
 Owner of this unit.
int CurrentSightRange
 Current unit stats.
int Frame
 Unit's Current Sight Range.
CUnitColorsColors
 Image frame: <0 is mirrored.
signed char IX
 Player colors.
signed char IY
 X image displacement to map position.
unsigned char Direction
 Y image displacement to map position.
unsigned char CurrentResource
int ResourcesHeld
unsigned char DamagedType
 Resources Held by a unit.
unsigned long Attacked
 Index of damage type of unit which damaged this unit.
unsigned SubAction: 8
 gamecycle unit was last attacked
unsigned State: 8
 sub-action of unit
unsigned Blink: 3
 action state
unsigned Moving: 1
 Let selection rectangle blink.
unsigned ReCast: 1
 The unit is moving.
unsigned AutoRepair: 1
 Recast again next cycle.
unsigned Burning: 1
 True if unit tries to repair on still action.
unsigned Destroyed: 1
 unit is burning
unsigned Removed: 1
 unit is destroyed pending reference
unsigned Selected: 1
 unit is removed (not on map)
unsigned Constructed: 1
 unit is selected
unsigned Active: 1
 Unit is in construction.
unsigned Boarded: 1
 Unit is active for AI.
unsigned CacheLock: 1
 Unit is on board a transporter.
unsigned GuardLock: 1
 Unit is on lock by unitcache operations.
unsigned Rs: 8
 Unit is on lock by guard operations.
unsigned TeamSelected
CPlayerRescuedFrom
 unit is selected by a team member.
int VisCount [PlayerMax]
 NULL if the unit was not rescued.
struct CUnit::_seen_stuff_ Seen
 Unit visibility counts.
CVariableVariable
unsigned long TTL
 array of User Defined variables.
int GroupId
 time to live
int LastGroup
 unit belongs to this group id
unsigned int Wait
 unit belongs to this last group
struct CUnit::_unit_anim_ Anim
 action counter
char OrderCount
char OrderFlush
 how many orders in queue
std::vector< COrder * > Orders
 cancel current order, take next
COrder SavedOrder
 orders to process
COrder NewOrder
 order to continue after current
COrder CriticalOrder
 order for new trained units
char * AutoCastSpell
 order to do as possible in breakable animation.
union CUnit::_order_data_ Data
 spells to auto cast
CUnitGoal
 Storage room for different commands.

Classes

union  _order_data_
 spells to auto cast More...
struct  _seen_stuff_
 Unit visibility counts. More...
struct  _unit_anim_
 action counter More...
class  COrder

Detailed Description

The big unit structure.

#include "unit.h"

Everything belonging to a unit. FIXME: rearrange for less memory.

This class contains all information about a unit in game. A unit could be anything: a man, a vehicle, a ship, or a building. Currently only a tile, a unit, or a missile could be placed on the map.

The unit structure members:

CUnit::Refs

The reference counter of the unit. If the pointer to the unit is stored the counter must be incremented and if this reference is destroyed the counter must be decremented. Alternative it would be possible to implement a garbage collector for this.

CUnit::Slot

This is the unique slot number. It is not possible that two units have the same slot number at the same time. The slot numbers are reused. This field could be accessed by the macro UnitNumber(Unit *). Maximal 65535 (=MAX_UNIT_SLOTS) simultaneous units are supported.

CUnit::UnitSlot

This is the pointer into Units[], where the unit pointer is stored. Units[] is a table of all units currently active in game. This pointer is only needed to speed up, the remove of the unit pointer from Units[], it didn't must be searched in the table.

CUnit::PlayerSlot

A pointer into Player::Units[], where the unit pointer is stored. Player::Units[] is a table of all units currently belonging to a player. This pointer is only needed to speed up, the remove of the unit pointer from Player::Units[].

CUnit::Next

A generic link pointer. This member is currently used, if an unit is on the map, to link all units on the same map field together. This also links corpses and stuff. Also, this is used in memory management to link unused units.

CUnit::Container

Pointer to the unit containing it, or NoUnitP if the unit is free. This points to the transporter for units on board, or to the building for peasants inside(when they are mining).

CUnit::UnitInside

Pointer to the last unit added inside. Order doesn't really matter. All units inside are kept in a circular linked list. This is NoUnitP if there are no units inside. Multiple levels of inclusion are allowed, though not very usefull right now

CUnit::NextContained, CUnit::PrevContained

The next and previous element in the curent container. Bogus values allowed for units not contained.

CUnit::InsideCount

The number of units inside the container.

CUnit::BoardCount

The number of units transported inside the container. This does not include for instance stuff like harvesters returning cargo.

CUnit::tilePos

The tile map coordinates of the unit. 0,0 is the upper left on the map. To convert the map coordinates into pixels, they must be multiplicated with the PixelTileSize.x and PixelTileSize.y. To get the pixel coordinates of a unit, calculate CUnit::X*PixelTileSize.x+CUnitIX , CUnit::Y*PixelTileSize.y+CUnitIY.

CUnit::Type

Pointer to the unit-type (UnitType). The unit-type contains all informations that all units of the same type shares. (Animations, Name, Stats, ...)

CUnit::SeenType Pointer to the unit-type that this unit was, when last seen. Currently only used by buildings.

CUnit::Player

Pointer to the owner of this unit (Player). An unit could only be owned by one player.

CUnit::Stats

Pointer to the current status (UnitStats) of a unit. The units of the same player and the same type could share the same stats. The status contains all values which could be different for each player. This f.e. the upgradeable abilities of an unit. (CUnit::Stats::SightRange, CUnit::Stats::Armor, CUnit::Stats::HitPoints, ...)

CUnit::CurrentSightRange

Current sight range of a unit, this changes when a unit enters a transporter or building or exits one of these.

CUnit::Colors

Player colors of the unit. Contains the hardware dependent pixel values for the player colors (palette index #208-#211). Setup from the global palette. This is a pointer.

Note:
Index #208-#211 are various SHADES of the team color (#208 is brightest shade, #211 is darkest shade) .... these numbers are NOT red=#208, blue=#209, etc
CUnit::IX CUnit::IY

Coordinate displacement in pixels or coordinates inside a tile. Currently only !=0, if the unit is moving from one tile to another (0-32 and for ships/flyers 0-64).

CUnit::Frame

Current graphic image of the animation sequence. The high bit (128) is used to flip this image horizontal (x direction). This also limits the number of different frames/image to 126.

CUnit::SeenFrame

Graphic image (see CUnit::Frame) what the player on this computer has last seen. If UnitNotSeen the player haven't seen this unit yet.

CUnit::Direction

Contains the binary angle (0-255) in which the direction the unit looks. 0, 32, 64, 128, 160, 192, 224, 256 corresponds to 0�, 45�, 90�, 135�, 180�, 225�, 270�, 315�, 360� or north, north-east, east, south-east, south, south-west, west, north-west, north. Currently only 8 directions are used, this is more for the future.

CUnit::Attacked

Last cycle the unit was attacked. 0 means never.

CUnit::Burning

If Burning is non-zero, the unit is burning.

CUnit::VisCount[PlayerMax]

Used to keep track of visible units on the map, it counts the Number of seen tiles for each player. This is only modified in UnitsMarkSeen and UnitsUnmarkSeen, from fow. We keep track of visilibty for each player, and combine with Shared vision ONLY when querying and such.

CUnit::SeenByPlayer

This is a bitmask of 1 and 0 values. SeenByPlayer & (1<<p) is 0 If p never saw the unit and 1 if it did. This is important for keeping track of dead units under fog. We only keep track of units that are visible under fog with this.

CUnit::Destroyed

Todo:
docu. If you need more informations, please send me an email or write it self.
CUnit::Removed

This flag means the unit is not active on map. This flag have workers set if they are inside a building, units that are on board of a transporter.

CUnit::Selected

Unit is selected. (So you can give it orders)

CUnit::Constructed Set when a building is under construction, and still using the generic building animation.

CUnit::SeenConstructed Last seen state of construction. Used to draw correct building frame. See CUnit::Constructed for more information.

CUnit::SeenState The Seen State of the building. 01 The building in being built when last seen. 10 The building was been upgraded when last seen.

CUnit::Boarded

This is 1 if the unit is on board a transporter.

CUnit::XP

Number of XP of the unit.

CUnit::Kills

How many units have been killed by the unit.

CUnit::GroupId

Number of the group to that the unit belongs. This is the main group showed on map, a unit can belong to many groups.

CUnit::LastGroup

Automatic group number, to reselect the same units. When the user selects more than one unit all units is given the next same number. (Used for ALT-CLICK)

CUnit::Value

This values hold the amount of resources in a resource or in in a harvester.

Todo:
continue documentation
CUnit::SubAction

This is an action private variable, it is zero on the first entry of an action. Must be set to zero, if an action finishes. It should only be used inside of actions.

CUnit::Wait

The unit is forced too wait for that many cycles. Be carefull, setting this to 0 will lock the unit.

CUnit::State

Animation state, currently position in the animation script. 0 if an animation has just started, it should only be changed inside of actions.

CUnit::Reset

Todo:
continue documentation
CUnit::Blink

CUnit::Moving

CUnit::RescuedFrom

Pointer to the original owner of a unit. It will be NULL if the unit was not rescued.

CUnit::OrderCount

The number of the orders unit to process. An unit has atleast one order. CUnit::OrderCount should be a number at least 1. The orders are in CUnit::Orders[].

CUnit::OrderFlush

A flag, which tells the unit to stop with the current order and immediately start with the next order.

CUnit::TotalOrders

The number of Orders allocated for this unit to use. Default is 4, but is dynamically updated if more orders are given.

CUnit::Orders

Contains all orders of the unit. Slot 0 is always used.

CUnit::SavedOrder

This order is executed, if the current order is finished. This is used for attacking units, to return to the old place or for patrolling units to return to patrol after killing some enemies. Any new order given to the unit, clears this saved order.

CUnit::NewOrder

This field is only used by buildings and this order is assigned to any by this building new trained unit. This is can be used to set the exit or gathering point of a building.

CUnit::Data

Todo:
continue documentation
CUnit::Goal

Generic goal pointer. Used by teleporters to point to circle of power.

Todo:
continue documentation

Constructor & Destructor Documentation

CUnit::CUnit (  )  [inline]


Member Function Documentation

void CUnit::Init (  )  [inline]

COrder* CUnit::CreateOrder (  )  [inline]

Generic/Teleporter goal pointer.

COrder* CUnit::CurrentOrder (  )  const [inline]

UnitAction CUnit::CurrentAction (  )  const [inline]

bool CUnit::IsIdle (  )  const [inline]

void CUnit::ClearAction (  )  [inline]

int CUnit::GetReactRange (  )  const [inline]

void CUnit::RefsIncrease (  ) 

Increase a unit's reference count.

Increase a unit's reference count.

void CUnit::RefsDecrease (  ) 

Decrease a unit's reference count.

Decrease a unit's reference count.

void CUnit::Init ( CUnitType type  ) 

Initialize unit structure with default values.

Initialize the unit slot with default values.

Parameters:
type Unit-type

void CUnit::AssignToPlayer ( CPlayer player  ) 

Assign unit to player.

Assigns a unit to a player, adjusting buildings, food and totals

Parameters:
player player which have the unit.

void CUnit::Draw ( const CViewport vp  )  const

Draw a single unit.

Units on map: Draw unit on map.

void CUnit::Place ( const Vec2i pos  ) 

Place a unit on map.

Place unit on map.

Parameters:
pos map tile position.

void CUnit::MoveToXY ( const Vec2i pos  ) 

Move unit to tile(pos). (Do special stuff : vision, cachelist, pathfinding).

Move a unit (with units inside) to tile (pos). (Do stuff with vision, cachelist and pathfinding).

Parameters:
pos map tile position.

void CUnit::AddInContainer ( CUnit host  ) 

Add a unit inside a container. Only deal with list stuff.

Add unit to a container. It only updates linked list stuff.

Parameters:
host Pointer to container.

void CUnit::ChangeOwner ( CPlayer newplayer  ) 

Change owner of unit.

Change the unit's owner

Parameters:
newplayer New owning player.

void CUnit::Remove ( CUnit host  ) 

Remove unit from map/groups/...

Remove unit from map.

Update selection. Update panels. Update map.

Parameters:
host Pointer to housing unit.

void CUnit::AssignWorkerToMine ( CUnit mine  ) 

void CUnit::DeAssignWorkerFromMine ( CUnit mine  ) 

void CUnit::Release ( bool  final = false  ) 

Release a unit.

Release an unit.

The unit is only released, if all references are dropped.

bool CUnit::RestoreOrder (  ) 

Restore the saved order

Returns:
True if the saved order was restored

bool CUnit::StoreOrder (  ) 

Store the Current order

Returns:
True if the current order was saved

bool CUnit::IsAgressive (  )  const [inline]

bool CUnit::IsVisible ( const CPlayer player  )  const

Returns true, if unit is directly seen by an allied unit.

Returns true, if the unit is visible. It check the Viscount of the player and everyone who shares vision with him.

Note:
This understands shared vision, and should be used all around.
Parameters:
player The player to check.

bool CUnit::IsInvisibile ( const CPlayer player  )  const [inline]

bool CUnit::IsAlive (  )  const [inline]

Returns true if unit is alive. Another unit can interact only with alive map units.

Returns:
True if alive, false otherwise.

bool CUnit::IsAliveOnMap (  )  const [inline]

Returns true if unit is alive and on the map. Another unit can interact only with alive map units.

Returns:
True if alive, false otherwise.

bool CUnit::IsVisibleAsGoal ( const CPlayer player  )  const [inline]

Returns true, if unit is visible as an action goal for a player on the map.

Parameters:
player Player to check for.
Returns:
True if visible, false otherwise.

bool CUnit::IsVisibleOnMap ( const CPlayer player  )  const [inline]

Returns true, if unit is visible for this player on the map. The unit has to be out of fog of war and alive

Parameters:
player Player to check for.
Returns:
True if visible, false otherwise.

bool CUnit::IsVisibleOnMinimap (  )  const

Returns true if unit is visible on minimap. Only for ThisPlayer.

Returns true, if unit is shown on minimap.

Warning:
This is for ThisPlayer only.
Todo:
radar support
Returns:
True if visible, false otherwise.

bool CUnit::IsVisibleOnRadar ( const CPlayer pradar  )  const

bool CUnit::IsVisibleInViewport ( const CViewport vp  )  const

Returns true if unit is visible in an viewport. Only for ThisPlayer.

Returns true, if unit is visible in viewport.

Warning:
This is only true for ThisPlayer
Parameters:
vp Viewport pointer.
Returns:
True if visible, false otherwise.

bool CUnit::IsVisibleOnScreen (  )  const

Returns true, if unit is visible on current map view (any viewport).

Returns true, if unit is visible on current map view (any viewport).

Returns:
True if visible, false otherwise.

void CUnit::GetMapArea ( int *  sx,
int *  sy,
int *  ex,
int *  ey 
) const

Todo:
more docu
Get area of map tiles covered by unit, including its displacement.

Parameters:
sx Out: Top left X tile map postion.
sy Out: Top left Y tile map postion.
ex Out: Bottom right X tile map postion.
ey Out: Bottom right Y tile map postion.
Returns:
sx,sy,ex,ey defining area in Map

bool CUnit::IsEnemy ( const CPlayer player  )  const

Check if the player is an enemy

Parameters:
x Player to check

bool CUnit::IsEnemy ( const CUnit unit  )  const

Check if the unit is an enemy

Parameters:
x Unit to check

bool CUnit::IsAllied ( const CPlayer player  )  const

Check if the player is an ally

Parameters:
x Player to check

bool CUnit::IsAllied ( const CUnit unit  )  const

Check if the unit is an ally

Parameters:
x Unit to check

bool CUnit::IsSharedVision ( const CPlayer player  )  const

Check if unit shares vision with the player

Parameters:
x Player to check

bool CUnit::IsSharedVision ( const CUnit unit  )  const

Check if the unit shares vision with the unit

Parameters:
x Unit to check

bool CUnit::IsBothSharedVision ( const CPlayer player  )  const

Check if both players share vision

Parameters:
x Player to check

bool CUnit::IsBothSharedVision ( const CUnit unit  )  const

Check if both units share vision

Parameters:
x Unit to check

bool CUnit::IsTeamed ( const CPlayer player  )  const

Check if the player is on the same team

Parameters:
x Player to check

bool CUnit::IsTeamed ( const CUnit unit  )  const

Check if the unit is on the same team

Parameters:
x Unit to check

bool CUnit::IsUnusable ( bool  ignore_built_state = false  )  const

Check if the unit is unusable (for attacking...)

Todo:
look if correct used (UnitActionBuilt is no problem if attacked)?

int CUnit::MapDistanceTo ( const CUnit dst  )  const [inline]

Returns the map distance between this unit and dst units.

Parameters:
dst Distance to this unit.
Returns:
The distance between in tiles.

int CUnit::MapDistanceTo ( int  x,
int  y 
) const [inline]

Returns the map distance to unit.

Parameters:
x X map tile position.
y Y map tile position.
dest Distance to this unit.
Returns:
The distance between in tiles.

bool CUnit::CanMove (  )  const [inline]

Test if unit can move. For the moment only check for move animation.

Returns:
0 if unit cannot move.

int CUnit::GetDrawLevel (  )  const [inline]


Member Data Documentation

unsigned int CUnit::Refs

Reference counter.

Assigned slot number.

Slot pointer of Units.

Slot pointer of Player->Units.

Generic link pointer (on map).

Number of units inside.

Number of units transported inside.

Pointer to one of the units inside.

Pointer to the unit containing it (or 0).

Next unit in the container.

Previous unit in the container.

unsigned int CUnit::Offset

Map position X.

Map position as flat index offset (x + y * w).

Pointer to unit-type (peon,...).

Owner of this unit.

Current unit stats.

Unit's Current Sight Range.

Image frame: <0 is mirrored.

signed char CUnit::IX

Player colors.

signed char CUnit::IY

X image displacement to map position.

unsigned char CUnit::Direction

Y image displacement to map position.

unsigned char CUnit::CurrentResource

unsigned char CUnit::DamagedType

Resources Held by a unit.

unsigned long CUnit::Attacked

Index of damage type of unit which damaged this unit.

unsigned CUnit::SubAction

gamecycle unit was last attacked

unsigned CUnit::State

sub-action of unit

unsigned CUnit::Blink

action state

unsigned CUnit::Moving

Let selection rectangle blink.

unsigned CUnit::ReCast

The unit is moving.

Recast again next cycle.

unsigned CUnit::Burning

True if unit tries to repair on still action.

unsigned CUnit::Destroyed

unit is burning

unsigned CUnit::Removed

unit is destroyed pending reference

unsigned CUnit::Selected

unit is removed (not on map)

unit is selected

unsigned CUnit::Active

Unit is in construction.

unsigned CUnit::Boarded

Unit is active for AI.

unsigned CUnit::CacheLock

Unit is on board a transporter.

unsigned CUnit::GuardLock

Unit is on lock by unitcache operations.

unsigned CUnit::Rs

Unit is on lock by guard operations.

set to random 1..100 when MakeUnit() used for fancy buildings

unit is selected by a team member.

int CUnit::VisCount[PlayerMax]

NULL if the unit was not rescued.

The original owner of a rescued unit.

Unit visibility counts.

unsigned long CUnit::TTL

array of User Defined variables.

time to live

unit belongs to this group id

unsigned int CUnit::Wait

unit belongs to this last group

action counter

how many orders in queue

std::vector<COrder *> CUnit::Orders

cancel current order, take next

orders to process

order to continue after current

order for new trained units

order to do as possible in breakable animation.

spells to auto cast

Storage room for different commands.


The documentation for this class was generated from the following files:
(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.