_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
The big unit structure. More...
#include <unit.h>
Classes | |
struct | _seen_stuff_ |
Unit visibility counts. More... | |
struct | _unit_anim_ |
The counter while small ai can ignore non aggressive targets if searching attacker. More... | |
class | CUnitManagerData |
Public Member Functions | |
CUnit () | |
COrder * | CurrentOrder () const |
bool | IsAgressive () const |
bool | IsInvisibile (const CPlayer &player) const |
bool | IsAliveOnMap () const |
bool | IsVisibleAsGoal (const CPlayer &player) const |
bool | IsVisibleOnMap (const CPlayer &player) const |
int | MapDistanceTo (const CUnit &dst) const |
bool | CanMove () const |
unit.cpp - The units. | |
~CUnit () | |
void | Init () |
unsigned int | CurrentAction () const |
bool | IsIdle () const |
void | ClearAction () |
void | RefsIncrease () |
Increase a unit's reference count. More... | |
void | RefsDecrease () |
Decrease a unit's reference count. More... | |
void | Init (const CUnitType &type) |
Initialize unit structure with default values. More... | |
void | AssignToPlayer (CPlayer &player) |
Assign unit to player. More... | |
void | Place (const Vec2i &pos) |
Place a unit on map. More... | |
void | MoveToXY (const Vec2i &pos) |
Move unit to tile(pos). (Do special stuff : vision, cachelist, pathfinding) More... | |
void | AddInContainer (CUnit &host) |
Add a unit inside a container. Only deal with list stuff. More... | |
void | ChangeOwner (CPlayer &newplayer) |
Change owner of unit. More... | |
void | Remove (CUnit *host) |
Remove unit from map/groups/... More... | |
void | AssignWorkerToMine (CUnit &mine) |
void | DeAssignWorkerFromMine (CUnit &mine) |
void | Release (bool final=false) |
Release a unit. More... | |
bool | RestoreOrder () |
bool | CanStoreOrder (COrder *order) |
bool | IsVisible (const CPlayer &player) const |
Returns true, if unit is directly seen by an allied unit. More... | |
bool | IsAlive () const |
bool | IsVisibleOnMinimap () const |
Returns true if unit is visible on minimap. Only for ThisPlayer. More... | |
bool | IsVisibleInViewport (const CViewport &vp) const |
Returns true if unit is visible in a viewport. Only for ThisPlayer. More... | |
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 | IsTeamed (const CPlayer &player) const |
bool | IsTeamed (const CUnit &unit) const |
bool | IsUnusable (bool ignore_built_state=false) const |
int | MapDistanceTo (const Vec2i &pos) const |
int | GetDrawLevel () const |
bool | IsAttackRanged (CUnit *goal, const Vec2i &goalPos) |
PixelPos | GetMapPixelPosTopLeft () const |
PixelPos | GetMapPixelPosCenter () const |
unit_draw.cpp - The draw routines for units. | |
void | Draw (const CViewport &vp) const |
Draw a single unit. More... | |
map_radar.cpp - The map radar handling. | |
bool | IsVisibleOnRadar (const CPlayer &pradar) const |
Public Attributes | |
unsigned int | Refs |
unsigned int | ReleaseCycle |
Reference counter. More... | |
CUnitManagerData | UnitManagerData |
When this unit could be recycled. More... | |
size_t | PlayerSlot |
int | InsideCount |
index in Player->Units More... | |
int | BoardCount |
Number of units inside. More... | |
CUnit * | UnitInside |
Number of units transported inside. More... | |
CUnit * | Container |
Pointer to one of the units inside. More... | |
CUnit * | NextContained |
Pointer to the unit containing it (or 0) More... | |
CUnit * | PrevContained |
Next unit in the container. More... | |
CUnit * | NextWorker |
Previous unit in the container. More... | |
struct { | |
CUnit * Workers | |
int Assigned | |
pointer to first assigned worker to this resource. More... | |
int Active | |
how many units are assigned to harvesting from the resource. More... | |
} | Resource |
Vec2i | tilePos |
Resource still. More... | |
unsigned int | Offset |
Map position X. More... | |
const CUnitType * | Type |
Map position as flat index offset (x + y * w) More... | |
CPlayer * | Player |
Pointer to unit-type (peon,...) More... | |
const CUnitStats * | Stats |
Owner of this unit. More... | |
int | CurrentSightRange |
Current unit stats. More... | |
PathFinderData * | pathFinderData |
Unit's Current Sight Range. More... | |
int | Frame |
int | Colors |
Image frame: <0 is mirrored. More... | |
bool | IndividualUpgrades [UpgradeMax] |
custom colors More... | |
signed char | IX |
individual upgrades which the unit has More... | |
signed char | IY |
X image displacement to map position. More... | |
unsigned char | Direction |
Y image displacement to map position. More... | |
unsigned char | CurrentResource |
int | ResourcesHeld |
unsigned char | DamagedType |
Resources Held by a unit. More... | |
unsigned long | Attacked |
Index of damage type of unit which damaged this unit. More... | |
unsigned long | Summoned |
gamecycle unit was last attacked More... | |
unsigned | Blink: 3 |
GameCycle unit was summoned using spells. More... | |
unsigned | Moving: 1 |
Let selection rectangle blink. More... | |
unsigned | ReCast: 1 |
The unit is moving. More... | |
unsigned | AutoRepair: 1 |
Recast again next cycle. More... | |
unsigned | Burning: 1 |
True if unit tries to repair on still action. More... | |
unsigned | Destroyed: 1 |
unit is burning More... | |
unsigned | Removed: 1 |
unit is destroyed pending reference More... | |
unsigned | Selected: 1 |
unit is removed (not on map) More... | |
unsigned | Constructed: 1 |
unit is selected More... | |
unsigned | Active: 1 |
Unit is in construction. More... | |
unsigned | Boarded: 1 |
Unit is active for AI. More... | |
unsigned | CacheLock: 1 |
Unit is on board a transporter. More... | |
unsigned | Waiting: 1 |
Unit is on lock by unitcache operations. More... | |
unsigned | MineLow: 1 |
Unit is waiting and playing its still animation. More... | |
unsigned | TeamSelected |
This mine got a notification about its resources being low. More... | |
CPlayer * | RescuedFrom |
unit is selected by a team member. More... | |
int | VisCount [PlayerMax] |
NULL if the unit was not rescued. More... | |
struct CUnit::_seen_stuff_ | Seen |
CVariable * | Variable |
unsigned long | TTL |
array of User Defined variables. More... | |
unsigned int | GroupId |
time to live More... | |
unsigned int | LastGroup |
unit belongs to this group id More... | |
unsigned int | Wait |
unit belongs to this last group More... | |
int | Threshold |
action counter More... | |
int | UnderAttack |
The counter while ai unit couldn't change target. More... | |
struct CUnit::_unit_anim_ | Anim |
struct CUnit::_unit_anim_ | WaitBackup |
std::vector< COrder * > | Orders |
COrder * | SavedOrder |
orders to process More... | |
COrder * | NewOrder |
order to continue after current More... | |
COrder * | CriticalOrder |
order for new trained units More... | |
char * | AutoCastSpell |
order to do as possible in breakable animation. More... | |
int * | SpellCoolDownTimers |
spells to auto cast More... | |
CUnit * | Goal |
how much time unit need to wait before spell will be ready More... | |
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:
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 *).
CUnit::UnitSlot
This is the index 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.
The index 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[].
Pointer to the unit containing it, or NULL 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).
Pointer to the last unit added inside. Order doesn't really matter. All units inside are kept in a circular linked list. This is NULL if there are no units inside. Multiple levels of inclusion are allowed, though not very useful right now
CUnit::NextContained, CUnit::PrevContained
The next and previous element in the curent container. Bogus values allowed for units not contained.
The number of units inside the container.
The number of units transported inside the container. This does not include for instance stuff like harvesters returning cargo.
The tile map coordinates of the unit. 0,0 is the upper left on the map.
Pointer to the unit-type (::UnitType). The unit-type contains all information 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.
Pointer to the owner of this unit (::Player). An unit could only be owned by one player.
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, ...)
Current sight range of a unit, this changes when a unit enters a transporter or building or exits one of these.
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.
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).
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.
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.
Last cycle the unit was attacked. 0 means never.
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.
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.
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.
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.
Number of the group to that the unit belongs. This is the main group showed on map, a unit can belong to many groups.
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.
The unit is forced too wait for that many cycles. Be careful, 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
Pointer to the original owner of a unit. It will be NULL if the unit was not rescued.
Contains all orders of the unit. Slot 0 is always used.
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.
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.
Generic goal pointer. Used by teleporters to point to circle of power.
|
inline |
CUnit::~CUnit | ( | ) |
Add a unit inside a container. Only deal with list stuff.
Add unit to a container. It only updates linked list stuff.
host | Pointer to container. |
Assign unit to player.
Assigns a unit to a player, adjusting buildings, food and totals
player | player which have the unit. |
|
inline |
Test if unit can move. For the moment only check for move animation.
bool CUnit::CanStoreOrder | ( | COrder * | order | ) |
Check if we can store this order
Change owner of unit.
Change the unit's owner
newplayer | New owning player. |
void CUnit::ClearAction | ( | ) |
unsigned int CUnit::CurrentAction | ( | ) | const |
|
inline |
Draw a single unit.
Units on map: Draw unit on map.
TODO: change ThisPlayer to currently rendered player/players #RenderTargets
int CUnit::GetDrawLevel | ( | ) | const |
PixelPos CUnit::GetMapPixelPosCenter | ( | ) | const |
PixelPos CUnit::GetMapPixelPosTopLeft | ( | ) | const |
void CUnit::Init | ( | ) |
Initialize unit structure with default values.
Initialize the unit slot with default values.
type | Unit-type |
|
inline |
bool CUnit::IsAlive | ( | ) | const |
Returns true if unit is alive. Another unit can interact only with alive map units.
|
inline |
Returns true if unit is alive and on the map. Another unit can interact only with alive map units.
bool CUnit::IsAllied | ( | const CPlayer & | player | ) | const |
Check if the player is an ally
player | Player to check |
bool CUnit::IsAllied | ( | const CUnit & | unit | ) | const |
Check if the unit is an ally
x | Unit to check |
Check if the unit attacking its goal will result in a ranged attack
bool CUnit::IsEnemy | ( | const CPlayer & | player | ) | const |
Check if the player is an enemy
player | Player to check |
bool CUnit::IsEnemy | ( | const CUnit & | unit | ) | const |
Check if the unit is an enemy
unit | Unit to check |
bool CUnit::IsIdle | ( | ) | const |
|
inline |
bool CUnit::IsTeamed | ( | const CPlayer & | player | ) | const |
Check if the player is on the same team
x | Player to check |
bool CUnit::IsTeamed | ( | const CUnit & | unit | ) | const |
Check if the unit is on the same team
x | Unit to check |
bool CUnit::IsUnusable | ( | bool | ignore_built_state = false | ) | const |
Check if the unit is unusable (for attacking...)
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.
player | The player to check. |
|
inline |
Returns true, if unit is visible as an action goal for a player on the map.
player | Player to check for. |
bool CUnit::IsVisibleInViewport | ( | const CViewport & | vp | ) | const |
Returns true if unit is visible in a viewport. Only for ThisPlayer.
Returns true, if unit is visible in viewport.
vp | Viewport pointer. |
|
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
player | Player to check for. |
bool CUnit::IsVisibleOnMinimap | ( | ) | const |
Returns true if unit is visible on minimap. Only for ThisPlayer.
Returns true, if unit is shown on minimap.
bool CUnit::IsVisibleOnRadar | ( | const CPlayer & | pradar | ) | const |
|
inline |
Returns the map distance between this unit and dst units.
dst | Distance to this unit. |
int CUnit::MapDistanceTo | ( | const Vec2i & | pos | ) | const |
Returns the map distance to unit.
pos | map tile position. |
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).
pos | map tile position. |
Place a unit on map.
Place unit on map.
pos | map tile position. |
void CUnit::RefsDecrease | ( | ) |
Decrease a unit's reference count.
Decrease a unit's reference count.
void CUnit::RefsIncrease | ( | ) |
Increase a unit's reference count.
Increase a unit's reference count.
void CUnit::Release | ( | bool | final = false | ) |
Release a unit.
Release an unit.
The unit is only released, if all references are dropped.
Remove unit from map/groups/...
Remove unit from map.
Update selection. Update panels. Update map.
host | Pointer to housing unit. |
bool CUnit::RestoreOrder | ( | ) |
Restore the saved order
int CUnit::Active |
how many units are assigned to harvesting from the resource.
unsigned CUnit::Active |
Unit is in construction.
struct CUnit::_unit_anim_ CUnit::Anim |
int CUnit::Assigned |
pointer to first assigned worker to this resource.
unsigned long CUnit::Attacked |
Index of damage type of unit which damaged this unit.
char* CUnit::AutoCastSpell |
order to do as possible in breakable animation.
unsigned CUnit::AutoRepair |
Recast again next cycle.
unsigned CUnit::Blink |
GameCycle unit was summoned using spells.
int CUnit::BoardCount |
Number of units inside.
unsigned CUnit::Boarded |
Unit is active for AI.
unsigned CUnit::Burning |
True if unit tries to repair on still action.
unsigned CUnit::CacheLock |
Unit is on board a transporter.
int CUnit::Colors |
Image frame: <0 is mirrored.
unsigned CUnit::Constructed |
unit is selected
CUnit* CUnit::Container |
Pointer to one of the units inside.
COrder* CUnit::CriticalOrder |
order for new trained units
unsigned char CUnit::CurrentResource |
int CUnit::CurrentSightRange |
Current unit stats.
unsigned char CUnit::DamagedType |
Resources Held by a unit.
unsigned CUnit::Destroyed |
unit is burning
unsigned char CUnit::Direction |
Y image displacement to map position.
int CUnit::Frame |
CUnit* CUnit::Goal |
how much time unit need to wait before spell will be ready
unsigned int CUnit::GroupId |
time to live
bool CUnit::IndividualUpgrades[UpgradeMax] |
custom colors
int CUnit::InsideCount |
index in Player->Units
signed char CUnit::IX |
individual upgrades which the unit has
signed char CUnit::IY |
X image displacement to map position.
unsigned int CUnit::LastGroup |
unit belongs to this group id
unsigned CUnit::MineLow |
Unit is waiting and playing its still animation.
unsigned CUnit::Moving |
Let selection rectangle blink.
COrder* CUnit::NewOrder |
order to continue after current
CUnit* CUnit::NextContained |
Pointer to the unit containing it (or 0)
CUnit* CUnit::NextWorker |
Previous unit in the container.
unsigned int CUnit::Offset |
Map position X.
std::vector<COrder *> CUnit::Orders |
PathFinderData* CUnit::pathFinderData |
Unit's Current Sight Range.
CPlayer* CUnit::Player |
Pointer to unit-type (peon,...)
size_t CUnit::PlayerSlot |
CUnit* CUnit::PrevContained |
Next unit in the container.
unsigned CUnit::ReCast |
The unit is moving.
unsigned int CUnit::Refs |
unsigned int CUnit::ReleaseCycle |
Reference counter.
unsigned CUnit::Removed |
unit is destroyed pending reference
CPlayer* CUnit::RescuedFrom |
unit is selected by a team member.
struct { ... } CUnit::Resource |
int CUnit::ResourcesHeld |
COrder* CUnit::SavedOrder |
orders to process
struct CUnit::_seen_stuff_ CUnit::Seen |
unsigned CUnit::Selected |
unit is removed (not on map)
int* CUnit::SpellCoolDownTimers |
spells to auto cast
const CUnitStats* CUnit::Stats |
Owner of this unit.
unsigned long CUnit::Summoned |
gamecycle unit was last attacked
unsigned CUnit::TeamSelected |
This mine got a notification about its resources being low.
int CUnit::Threshold |
action counter
Vec2i CUnit::tilePos |
Resource still.
unsigned long CUnit::TTL |
array of User Defined variables.
const CUnitType* CUnit::Type |
Map position as flat index offset (x + y * w)
int CUnit::UnderAttack |
The counter while ai unit couldn't change target.
CUnit* CUnit::UnitInside |
Number of units transported inside.
CUnitManagerData CUnit::UnitManagerData |
When this unit could be recycled.
CVariable* CUnit::Variable |
int CUnit::VisCount[PlayerMax] |
NULL if the unit was not rescued.
The original owner of a rescued unit.
unsigned int CUnit::Wait |
unit belongs to this last group
struct CUnit::_unit_anim_ CUnit::WaitBackup |
unsigned CUnit::Waiting |
Unit is on lock by unitcache operations.
CUnit* CUnit::Workers |