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

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
unit.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 1998-2015 by Lutz Sammer, Jimmy Salmon and Andrettin
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29 
30 #ifndef __UNIT_H__
31 #define __UNIT_H__
32 
34 
35 /*----------------------------------------------------------------------------
36 -- Includes
37 ----------------------------------------------------------------------------*/
38 
39 #include <vector>
40 
41 #ifndef __UNITTYPE_H__
42 #include "unittype.h"
43 #endif
44 
45 #ifndef __PLAYER_H__
46 #include "player.h"
47 #endif
48 
49 #include "vec2i.h"
50 
51 /*----------------------------------------------------------------------------
52 -- Declarations
53 ----------------------------------------------------------------------------*/
54 
55 class CAnimation;
57 class CConstructionFrame;
58 class CFile;
59 class Missile;
60 class CMapField;
61 class COrder;
62 class CPlayer;
63 class CUnit;
64 class CUnitColors;
65 class CUnitPtr;
66 class CUnitStats;
67 class CUnitType;
68 class CUpgrade;
69 class CVariable;
70 class CViewport;
71 class PathFinderData;
72 class SpellType;
73 struct lua_State;
74 
75 typedef COrder *COrderPtr;
76 
77 /*
78 ** Configuration of the small (unit) AI.
79 */
80 #define PRIORITY_FACTOR 0x00080000
81 #define HEALTH_FACTOR 0x00000001
82 #define DISTANCE_FACTOR 0x00010000
83 #define INRANGE_FACTOR 0x00008000
84 #define INRANGE_BONUS 0x01000000
85 #define CANATTACK_BONUS 0x00080000
86 #define AIPRIORITY_BONUS 0x04000000
87 
88 
90 extern void SelectedUnitChanged();
91 
93 extern int MapDistanceBetweenTypes(const CUnitType &src, const Vec2i &pos1,
94  const CUnitType &dst, const Vec2i &pos2);
95 
105  LookingN = 0 * 32,
106  LookingNE = 1 * 32,
107  LookingE = 2 * 32,
108  LookingSE = 3 * 32,
109  LookingS = 4 * 32,
110  LookingSW = 5 * 32,
111  LookingW = 6 * 32,
112  LookingNW = 7 * 32
113 };
114 
115 #define NextDirection 32
116 #define UnitNotSeen 0x7fffffff
117 
118 class CUnit
120 {
121 public:
122  CUnit() : tilePos(-1, -1), pathFinderData(NULL), SavedOrder(NULL), NewOrder(NULL), CriticalOrder(NULL) { Init(); }
123 
124  void Init();
125 
126  COrder *CurrentOrder() const { return Orders[0]; }
127 
128  unsigned int CurrentAction() const;
129 
130  bool IsIdle() const;
131 
132  void ClearAction();
133 
135  void RefsIncrease();
137  void RefsDecrease();
138 
140  void Init(const CUnitType &type);
142  void AssignToPlayer(CPlayer &player);
143 
145  void Draw(const CViewport &vp) const;
147  void Place(const Vec2i &pos);
148 
150  void MoveToXY(const Vec2i &pos);
152  void AddInContainer(CUnit &host);
154  void ChangeOwner(CPlayer &newplayer);
155 
157  void Remove(CUnit *host);
158 
159  void AssignWorkerToMine(CUnit &mine);
160  void DeAssignWorkerFromMine(CUnit &mine);
161 
163  void Release(bool final = false);
164 
165  bool RestoreOrder();
166  bool CanStoreOrder(COrder *order);
167 
168  // Cowards and invisible units don't attack unless ordered.
169  bool IsAgressive() const
170  {
171  return (Type->BoolFlag[CANATTACK_INDEX].value && !Type->BoolFlag[COWARD_INDEX].value
172  && Variable[INVISIBLE_INDEX].Value == 0);
173  }
174 
176  bool IsVisible(const CPlayer &player) const;
177 
178  inline bool IsInvisibile(const CPlayer &player) const
179  {
180  return (&player != Player && !!Variable[INVISIBLE_INDEX].Value
181  && !player.IsBothSharedVision(*Player));
182  }
183 
190  bool IsAlive() const;
191 
198  inline bool IsAliveOnMap() const
199  {
200  return !Removed && IsAlive();
201  }
202 
210  inline bool IsVisibleAsGoal(const CPlayer &player) const
211  {
212  // Invisibility
213  if (IsInvisibile(player)) {
214  return false;
215  }
216  // Don't attack revealers
217  if (this->Type->BoolFlag[REVEALER_INDEX].value) {
218  return false;
219  }
220  if ((player.Type == PlayerComputer && !this->Type->BoolFlag[PERMANENTCLOAK_INDEX].value)
221  || IsVisible(player) || IsVisibleOnRadar(player)) {
222  return IsAliveOnMap();
223  } else {
224  return Type->BoolFlag[VISIBLEUNDERFOG_INDEX].value
225  && (Seen.ByPlayer & (1 << player.Index))
226  && !(Seen.Destroyed & (1 << player.Index));
227  }
228  }
229 
238  inline bool IsVisibleOnMap(const CPlayer &player) const
239  {
240  return IsAliveOnMap() && !IsInvisibile(player) && IsVisible(player);
241  }
242 
244  bool IsVisibleOnMinimap() const;
245 
246  // Returns true if unit is visible under radar (By player, or by shared vision)
247  bool IsVisibleOnRadar(const CPlayer &pradar) const;
248 
250  bool IsVisibleInViewport(const CViewport &vp) const;
251 
252  bool IsEnemy(const CPlayer &player) const;
253  bool IsEnemy(const CUnit &unit) const;
254  bool IsAllied(const CPlayer &player) const;
255  bool IsAllied(const CUnit &unit) const;
256  bool IsSharedVision(const CPlayer &player) const;
257  bool IsSharedVision(const CUnit &unit) const;
258  bool IsBothSharedVision(const CPlayer &player) const;
259  bool IsBothSharedVision(const CUnit &unit) const;
260  bool IsTeamed(const CPlayer &player) const;
261  bool IsTeamed(const CUnit &unit) const;
262 
263  bool IsUnusable(bool ignore_built_state = false) const;
264 
272  int MapDistanceTo(const CUnit &dst) const
273  {
274  return MapDistanceBetweenTypes(*Type, tilePos, *dst.Type, dst.tilePos);
275  }
276 
277  int MapDistanceTo(const Vec2i &pos) const;
278 
285  bool CanMove() const { return Type->CanMove(); }
286 
287  int GetDrawLevel() const;
288 
289  bool IsAttackRanged(CUnit *goal, const Vec2i &goalPos);
290 
293 
294 public:
296  {
297  friend class CUnitManager;
298  public:
299  CUnitManagerData() : slot(-1), unitSlot(-1) {}
300 
301  int GetUnitId() const { return slot; }
302  private:
303  int slot;
304  int unitSlot;
305  };
306 public:
307  // @note int is faster than shorts
308  unsigned int Refs;
309  unsigned int ReleaseCycle;
311  size_t PlayerSlot;
312 
319 
320  CUnit *NextWorker; //pointer to next assigned worker to "Goal" resource.
321  struct {
323  int Assigned;
324  int Active;
325  } Resource;
326 
328 
329  unsigned int Offset;
330 
331  const CUnitType *Type;
333  const CUnitStats *Stats;
335 
336  // Pathfinding stuff:
338 
339  // DISPLAY:
340  int Frame;
343 
344  signed char IX;
345  signed char IY;
346  unsigned char Direction; //: 8; /// angle (0-255) unit looking
347  unsigned char CurrentResource;
349 
350  unsigned char DamagedType;
351  unsigned long Attacked;
352  unsigned Blink : 3;
353  unsigned Moving : 1;
354  unsigned ReCast : 1;
355  unsigned AutoRepair : 1;
356 
357  unsigned Burning : 1;
358  unsigned Destroyed : 1;
359  unsigned Removed : 1;
360  unsigned Selected : 1;
361 
362  unsigned Constructed : 1;
363  unsigned Active : 1;
364  unsigned Boarded : 1;
365  unsigned CacheLock : 1;
366 
367  unsigned Summoned : 1;
368  unsigned Waiting : 1;
369  unsigned MineLow : 1;
370 
371  unsigned TeamSelected;
373  /* Seen stuff. */
376  struct _seen_stuff_ {
377  _seen_stuff_() : CFrame(NULL), Type(NULL), tilePos(-1, -1) {}
379  int Frame;
380  const CUnitType *Type;
382  signed char IX;
383  signed char IY;
384  unsigned Constructed : 1;
385  unsigned State : 3;
386 unsigned Destroyed : PlayerMax;
387 unsigned ByPlayer : PlayerMax;
388  } Seen;
389 
391 
392  unsigned long TTL;
393 
394  unsigned int GroupId;
395  unsigned int LastGroup;
396 
397  unsigned int Wait;
398  int Threshold;
399 
400  struct _unit_anim_ {
401  const CAnimation *Anim;
403  int Wait;
405  } Anim, WaitBackup;
406 
407 
408  std::vector<COrder *> Orders;
412 
415 
417 };
418 
419 #define NoUnitP (CUnit *)0
420 
421 
424 #define UnitNumber(unit) ((unit).UnitManagerData.GetUnitId())
425 
430 {
431 public:
433  ShowAttackRange(false), ShowMessages(true), BigScreen(false),
434  PauseOnLeave(true), AiExplores(true), GrayscaleIcons(false),
435  IconsShift(false), StereoSound(true), MineNotifications(false),
436  DeselectInMine(false), NoStatusLineTooltips(false),
437  IconFrameG(NULL), PressedIconFrameG(NULL),
439 
440  bool ShowSightRange;
444  bool BigScreen;
446  bool AiExplores;
448  bool IconsShift;
449  bool StereoSound;
453 
458 
459  std::string SF2Soundfont;
460 
463 };
464 
465 extern CPreference Preference;
466 
467 /*----------------------------------------------------------------------------
468 -- Variables
469 ----------------------------------------------------------------------------*/
470 
471 // in unit_draw.c
473 extern unsigned long ShowOrdersCount;
474 extern unsigned long ShowNameDelay;
475 extern unsigned long ShowNameTime;
476 extern bool EnableTrainingQueue;
477 extern bool EnableBuildingCapture;
478 extern bool RevealAttacker;
480 extern const CViewport *CurrentViewport;
481 extern void DrawUnitSelection(const CViewport &vp, const CUnit &unit);
482 extern void (*DrawSelection)(IntColor, int, int, int, int);
483 
484 extern unsigned int MaxSelectable;
485 extern std::vector<CUnit *> Selected;
486 
487 /*----------------------------------------------------------------------------
488 -- Functions
489 ----------------------------------------------------------------------------*/
490 
492 void MarkUnitFieldFlags(const CUnit &unit);
494 void UnmarkUnitFieldFlags(const CUnit &unit);
496 void UpdateUnitSightRange(CUnit &unit);
498 extern CUnit *MakeUnit(const CUnitType &type, CPlayer *player);
500 extern CUnit *MakeUnitAndPlace(const Vec2i &pos, const CUnitType &type, CPlayer *player);
502 void FindNearestDrop(const CUnitType &type, const Vec2i &goalPos, Vec2i &resPos, int heading);
504 extern void UnitLost(CUnit &unit);
506 extern void UnitClearOrders(CUnit &unit);
508 extern void UpdateForNewUnit(const CUnit &unit, int upgrade);
510 extern void NearestOfUnit(const CUnit &unit, const Vec2i &pos, Vec2i *dpos);
511 
512 extern CUnit *GetFirstContainer(const CUnit &unit);
513 
515 extern void UnitGoesUnderFog(CUnit &unit, const CPlayer &player);
517 extern void UnitGoesOutOfFog(CUnit &unit, const CPlayer &player);
518 
520 extern void UnitCountSeen(CUnit &unit);
521 
523 extern void RescueUnits();
524 
526 extern int DirectionToHeading(const Vec2i &dir);
528 extern int DirectionToHeading(const PixelDiff &dir);
529 
531 extern void CorrectWallDirections(CUnit &unit);
533 extern void CorrectWallNeighBours(CUnit &unit);
534 
536 extern void UnitUpdateHeading(CUnit &unit);
538 extern void UnitHeadingFromDeltaXY(CUnit &unit, const Vec2i &delta);
539 
540 
542 extern void DropOutOnSide(CUnit &unit, int heading, const CUnit *container);
544 extern void DropOutNearest(CUnit &unit, const Vec2i &goalPos, const CUnit *container);
545 
547 extern void DropOutAll(const CUnit &unit);
548 
550 extern CBuildRestrictionOnTop *OnTopDetails(const CUnit &unit, const CUnitType *parent);
552 extern CUnit *CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i &pos);
554 extern bool CanBuildOn(const Vec2i &pos, int mask);
556 extern CUnit *CanBuildUnitType(const CUnit *unit, const CUnitType &type, const Vec2i &pos, int real);
558 extern int ExtraDeathIndex(const char *death);
559 
561 extern CUnit *UnitOnScreen(int x, int y);
562 
564 extern void LetUnitDie(CUnit &unit, bool suicide = false);
566 extern void DestroyAllInside(CUnit &source);
568 extern int ThreatCalculate(const CUnit &unit, const CUnit &dest);
570 extern void HitUnit(CUnit *attacker, CUnit &target, int damage, const Missile *missile = NULL);
571 
573 extern int ViewPointDistance(const Vec2i &pos);
575 extern int ViewPointDistanceToUnit(const CUnit &dest);
576 
578 extern int CanTarget(const CUnitType &type, const CUnitType &dest);
580 extern int CanTransport(const CUnit &transporter, const CUnit &unit);
581 
583 extern std::string UnitReference(const CUnit &unit);
585 extern std::string UnitReference(const CUnitPtr &unit);
586 
588 extern void SaveUnit(const CUnit &unit, CFile &file);
589 
591 extern void InitUnits();
593 extern void CleanUnits();
594 
595 // in unit_draw.c
596 //--------------------
598 extern void DrawSelectionNone(IntColor, int, int, int, int);
600 extern void DrawSelectionCircle(IntColor, int, int, int, int);
602 extern void DrawSelectionCircleWithTrans(IntColor, int, int, int, int);
604 extern void DrawSelectionRectangle(IntColor, int, int, int, int);
606 extern void DrawSelectionRectangleWithTrans(IntColor, int, int, int, int);
608 extern void DrawSelectionCorners(IntColor, int, int, int, int);
609 
611 extern void DecorationCclRegister();
613 extern void LoadDecorations();
615 extern void CleanDecorations();
616 
618 extern void DrawShadow(const CUnitType &type, int frame, const PixelPos &screenPos);
620 extern int FindAndSortUnits(const CViewport &vp, std::vector<CUnit *> &table);
621 
623 extern void ShowOrder(const CUnit &unit);
624 
625 // in groups.c
626 
628 extern void SaveGroups(CFile &file);
630 extern void CleanGroups();
632 extern const std::vector<CUnit *> &GetUnitsOfGroup(int num);
633 
635 extern void ClearGroup(int num);
637 extern void AddToGroup(CUnit **units, unsigned int nunits, int num);
639 extern void SetGroup(CUnit **units, unsigned int nunits, int num);
641 extern void RemoveUnitFromGroups(CUnit &unit);
643 extern void GroupCclRegister();
644 extern bool IsGroupTainted(int num);
645 
646 // in selection.c
647 
649 extern bool IsOnlySelected(const CUnit &unit);
650 
652 extern void SaveSelection();
654 extern void RestoreSelection();
656 extern void UnSelectAll();
658 extern void ChangeTeamSelectedUnits(CPlayer &player, const std::vector<CUnit *> &units);
660 extern int SelectUnit(CUnit &unit);
662 extern void SelectSingleUnit(CUnit &unit);
664 extern void UnSelectUnit(CUnit &unit);
666 extern int ToggleSelectUnit(CUnit &unit);
668 extern int SelectUnitsByType(CUnit &base);
670 extern int ToggleUnitsByType(CUnit &base);
672 extern int SelectGroup(int group_number, GroupSelectionMode mode = SELECTABLE_BY_RECTANGLE_ONLY);
674 extern int AddGroupFromUnitToSelection(CUnit &unit);
676 extern int SelectGroupFromUnit(CUnit &unit);
678 extern int SelectUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright);
680 extern int SelectGroundUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright);
682 extern int SelectAirUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright);
684 extern int AddSelectedUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright);
686 extern int AddSelectedGroundUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright);
688 extern int AddSelectedAirUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright);
689 
691 extern void SaveSelections(CFile &file);
693 extern void CleanSelections();
695 extern void SelectionCclRegister();
696 
697 // in ccl_unit.c
698 
700 extern void UnitCclRegister();
701 
703 
704 #endif // !__UNIT_H__
Definition: unittype.h:144
int Type
name of non computer
Definition: player.h:85
int MapDistanceBetweenTypes(const CUnitType &src, const Vec2i &pos1, const CUnitType &dst, const Vec2i &pos2)
Returns the map distance between to unittype as locations.
Definition: unit.cpp:2890
int FindAndSortUnits(const CViewport &vp, std::vector< CUnit * > &table)
Draw all units visible on map in viewport.
Definition: unit_draw.cpp:936
int Value
Maximum for the variable. (Assume min is 0.)
Definition: unittype.h:134
CUnit * Goal
how much time unit need to wait before spell will be ready
Definition: unit.h:416
int SelectUnitsByType(CUnit &base)
Select units from the same type (if selectable by rectangle)
Definition: selection.cpp:339
bool GrayscaleIcons
If true, AI sends explorers to search for resources (almost useless thing)
Definition: unit.h:447
void RescueUnits()
Check for rescue each second.
Definition: unit.cpp:1899
void Init()
Definition: unit.cpp:402
unsigned long ShowNameTime
Delay to show unit's name.
Definition: unit_draw.cpp:100
Construction frame.
Definition: construct.h:112
Unit looking west.
Definition: unit.h:112
COrder * CriticalOrder
order for new trained units
Definition: unit.h:411
size_t PlayerSlot
Definition: unit.h:311
void FindNearestDrop(const CUnitType &type, const Vec2i &goalPos, Vec2i &resPos, int heading)
Find the nearest position at which unit can be placed.
Definition: unit.cpp:1142
void MoveToXY(const Vec2i &pos)
Move unit to tile(pos). (Do special stuff : vision, cachelist, pathfinding)
Definition: unit.cpp:1063
void UnmarkUnitFieldFlags(const CUnit &unit)
Unmark the field with the FieldFlags.
Definition: unit.cpp:963
int ShowNameDelay
How many second show orders of unit on map.
Definition: unit.h:455
int GetUnitId() const
Definition: unit.h:301
Definition: unit.h:295
CUnit * MakeUnitAndPlace(const Vec2i &pos, const CUnitType &type, CPlayer *player)
Create a new unit and place on map.
Definition: unit.cpp:1124
void UnitLost(CUnit &unit)
Handle the loss of a unit (food,...)
Definition: unit.cpp:1253
Definition: unittype.h:391
void DropOutOnSide(CUnit &unit, int heading, const CUnit *container)
Definition: unit.cpp:2074
bool EnableBuildingCapture
Config: training queues enabled.
Definition: unit.cpp:356
unsigned long Attacked
Index of damage type of unit which damaged this unit.
Definition: unit.h:351
Missile on the map.
Definition: missile.h:413
const CViewport * CurrentViewport
Config: spend resources for building with multiple workers.
Definition: unit_draw.cpp:121
bool ShowMessages
Show attack range.
Definition: unit.h:443
unsigned Summoned
Unit is on lock by unitcache operations.
Definition: unit.h:367
Definition: unittype.h:118
unsigned int CurrentAction() const
Definition: unit.cpp:542
bool RestoreOrder()
Definition: unit.cpp:647
void DrawShadow(const CUnitType &type, int frame, const PixelPos &screenPos)
Draw unit's shadow.
Definition: unit_draw.cpp:579
unsigned Selected
unit is removed (not on map)
Definition: unit.h:360
void ChangeTeamSelectedUnits(CPlayer &player, const std::vector< CUnit * > &units)
Changed TeamUnit Selection.
Definition: selection.cpp:181
unsigned MineLow
Unit is waiting and playing its still animation.
Definition: unit.h:369
Definition: unittype.h:141
struct CUnit::_seen_stuff_ Seen
CUnit * NextContained
Pointer to the unit containing it (or 0)
Definition: unit.h:317
const CUnitStats * Stats
Owner of this unit.
Definition: unit.h:333
_directions_
Definition: unit.h:104
void RestoreSelection()
Restore selection.
Definition: selection.cpp:88
void MarkUnitFieldFlags(const CUnit &unit)
currently selected units
Definition: unit.cpp:919
bool IsBothSharedVision(const CPlayer &player) const
Definition: player.cpp:1432
COrder * NewOrder
order to continue after current
Definition: unit.h:410
bool CanStoreOrder(COrder *order)
Definition: unit.cpp:677
CUnit * UnitInside
Number of units transported inside.
Definition: unit.h:315
int Threshold
action counter
Definition: unit.h:398
Unit looking north.
Definition: unit.h:106
unsigned CacheLock
Unit is on board a transporter.
Definition: unit.h:365
void DrawUnitSelection(const CViewport &vp, const CUnit &unit)
CurrentViewport.
Definition: unit_draw.cpp:130
int ResourcesHeld
Definition: unit.h:348
Definition: actions.h:93
unsigned Waiting
Unit is summoned using spells.
Definition: unit.h:368
void SaveSelection()
Save selection to restore after.
Definition: selection.cpp:77
unsigned Moving
Let selection rectangle blink.
Definition: unit.h:353
unsigned long ShowOrdersCount
All sprite's infos.
Definition: unit_draw.cpp:97
int AddSelectedAirUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
Add flying units in the selection rectangle to the current selection.
Definition: selection.cpp:1010
void AssignWorkerToMine(CUnit &mine)
Definition: unit.cpp:1813
int Frame
Definition: unit.h:340
void ClearGroup(int num)
Remove all units from a group.
Definition: groups.cpp:172
const CAnimation * Anim
Definition: unit.h:401
Definition: color.h:62
bool PauseOnLeave
If true, shows the big screen(without panels)
Definition: unit.h:445
unsigned Burning
True if unit tries to repair on still action.
Definition: unit.h:357
Unit looking east.
Definition: unit.h:108
unsigned int ReleaseCycle
Reference counter.
Definition: unit.h:309
void SelectedUnitChanged()
Called whenever the selected unit was updated.
Definition: script_ui.cpp:1126
Definition: animation.h:93
void RefsIncrease()
Increase a unit's reference count.
Definition: unit.cpp:376
Building must be built on coast.
Definition: unittype.h:156
CVariable * Variable
Definition: unit.h:390
unsigned char CurrentResource
Definition: unit.h:347
bool IsVisibleOnMap(const CPlayer &player) const
Definition: unit.h:238
std::vector< BoolFlags > BoolFlag
Definition: unittype.h:598
void AssignToPlayer(CPlayer &player)
Assign unit to player.
Definition: unit.cpp:695
The big unit structure.
Definition: unit.h:119
int ViewPointDistanceToUnit(const CUnit &dest)
Calculate the distance from current view point to unit.
Definition: unit.cpp:2931
#define PlayerMax
Definition: stratagus.h:157
unsigned int Offset
Map position X.
Definition: unit.h:329
Unit looking south east.
Definition: unit.h:109
unsigned Constructed
seen Y image displacement to map position
Definition: unit.h:384
struct CUnit::_unit_anim_ WaitBackup
CUnit * Workers
Definition: unit.h:322
void LoadDecorations()
Load the decorations (health,mana) of units.
Definition: unit_draw.cpp:344
int SelectUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
Select the units in the selection rectangle.
Definition: selection.cpp:704
void DrawSelectionRectangleWithTrans(IntColor, int, int, int, int)
Draw rectangle filled with alpha around unit.
Definition: unit_draw.cpp:230
unused slot
Definition: player.h:311
const std::vector< CUnit * > & GetUnitsOfGroup(int num)
Get the array of units of a particular group.
Definition: groups.cpp:161
void SaveSelections(CFile &file)
Save current selection state.
Definition: selection.cpp:1076
void Remove(CUnit *host)
Remove unit from map/groups/...
Definition: unit.cpp:1203
void Release(bool final=false)
Release a unit.
Definition: unit.cpp:485
COrder * SavedOrder
orders to process
Definition: unit.h:409
void DropOutAll(const CUnit &unit)
Drop out all units in the unit.
Definition: unit.cpp:2237
std::vector< CUnit * > Selected
How many units could be selected.
Definition: selection.cpp:57
signed char IY
X image displacement to map position.
Definition: unit.h:345
void SetGroup(CUnit **units, unsigned int nunits, int num)
Set the contents of a particular group with an array of units.
Definition: groups.cpp:215
The counter while ai unit couldn't change target.
Definition: unit.h:400
void DrawSelectionCorners(IntColor, int, int, int, int)
Draw corners around unit.
Definition: unit_draw.cpp:244
signed char IX
Last unit->tilePos Seen.
Definition: unit.h:382
bool RevealAttacker
Config: building capture enabled.
Definition: unit.cpp:357
void DeAssignWorkerFromMine(CUnit &mine)
Definition: unit.cpp:1834
CUnitManagerData UnitManagerData
When this unit could be recycled.
Definition: unit.h:310
const CAnimation * CurrAnim
Anim.
Definition: unit.h:402
std::string SF2Soundfont
Autosave the game every X minutes; autosave is disabled if the value is 0.
Definition: unit.h:459
bool IsIdle() const
Definition: unit.cpp:557
CPreference()
Definition: unit.h:432
int Wait
CurrAnim.
Definition: unit.h:403
Unit is visible under fog of war.
Definition: unittype.h:150
void CorrectWallDirections(CUnit &unit)
Correct directions for placed wall.
Definition: unit.cpp:1434
int ExtraDeathIndex(const char *death)
Get the suitable animation frame depends of unit's damaged type.
Definition: script_unittype.cpp:209
void DropOutNearest(CUnit &unit, const Vec2i &goalPos, const CUnit *container)
Definition: unit.cpp:2159
void UnSelectAll()
Clear current selection.
Definition: selection.cpp:106
signed char IY
Seen X image displacement to map position.
Definition: unit.h:383
COrder * CurrentOrder() const
Definition: unit.h:126
char * AutoCastSpell
order to do as possible in breakable animation.
Definition: unit.h:413
bool IsInvisibile(const CPlayer &player) const
Definition: unit.h:178
unsigned int MaxSelectable
Definition: selection.cpp:55
void DrawSelectionRectangle(IntColor, int, int, int, int)
Draw rectangle around unit.
Definition: unit_draw.cpp:218
Vec2i tilePos
Pointer to last seen unit-type.
Definition: unit.h:381
bool BigScreen
Show messages.
Definition: unit.h:444
bool ShowAttackRange
Show reaction range.
Definition: unit.h:442
bool IsBothSharedVision(const CPlayer &player) const
Definition: unit.cpp:3080
Definition: unit.h:429
int BoardCount
Number of units inside.
Definition: unit.h:314
bool IsAttackRanged(CUnit *goal, const Vec2i &goalPos)
Definition: unit.cpp:3127
Definition: video.h:64
bool IsUnusable(bool ignore_built_state=false) const
Definition: unit.cpp:3119
Definition: viewport.h:63
unsigned int GroupId
time to live
Definition: unit.h:394
bool IsSharedVision(const CPlayer &player) const
Definition: unit.cpp:3060
void UnitUpdateHeading(CUnit &unit)
Update frame from heading.
Definition: unit.cpp:2022
Definition: unittype.h:467
Definition: iolib.h:101
bool ShowReactionRange
Show sight range.
Definition: unit.h:441
int SelectGroundUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
Select ground units in the selection rectangle.
Definition: selection.cpp:841
void Place(const Vec2i &pos)
Place a unit on map.
Definition: unit.cpp:1085
void(* DrawSelection)(IntColor, int, int, int, int)
Show unit's name for some time.
Definition: unit_draw.cpp:112
unsigned Boarded
Unit is active for AI.
Definition: unit.h:364
std::vector< COrder * > Orders
Definition: unit.h:408
int AddSelectedGroundUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
Add ground units in the selection rectangle to the current selection.
Definition: selection.cpp:940
bool NoStatusLineTooltips
Deselect peasants in mines.
Definition: unit.h:452
Definition: unittype.h:207
CUnitManagerData()
Definition: unit.h:299
Unit looking south.
Definition: unit.h:110
void SelectionCclRegister()
Register CCL selection features.
Definition: selection.cpp:1146
void ChangeOwner(CPlayer &newplayer)
Change owner of unit.
Definition: unit.cpp:1732
struct CUnit::_unit_anim_ Anim
#define UpgradeMax
Definition: stratagus.h:159
void CleanDecorations()
Clean the decorations (health,mana) of units.
Definition: unit_draw.cpp:357
int GetDrawLevel() const
Definition: unit.cpp:567
Definition: unittype.h:81
Definition: pathfinder.h:115
void CleanSelections()
Clean up selections.
Definition: selection.cpp:1092
CPlayer * RescuedFrom
unit is selected by a team member.
Definition: unit.h:372
bool IsAlive() const
Definition: unit.cpp:562
CUnit * PrevContained
Next unit in the container.
Definition: unit.h:318
bool IsVisibleOnMinimap() const
Returns true if unit is visible on minimap. Only for ThisPlayer.
Definition: unit.cpp:1663
Vec2i tilePos
Resource still.
Definition: unit.h:327
int Index
Definition: player.h:82
bool IsAllied(const CPlayer &player) const
Definition: unit.cpp:3040
int AutosaveMinutes
How many cycles need to show unit's name popup.
Definition: unit.h:457
void UpdateUnitSightRange(CUnit &unit)
Update unit->CurrentSightRange.
Definition: unit.cpp:890
void SelectSingleUnit(CUnit &unit)
Select one unit as selection.
Definition: selection.cpp:247
void ClearAction()
Definition: unit.cpp:547
bool EnableTrainingQueue
Show unit's name for some time.
Definition: unit.cpp:355
unsigned int Refs
Definition: unit.h:308
bool IsTeamed(const CPlayer &player) const
Definition: unit.cpp:3100
GroupSelectionMode
Definition: unittype.h:80
int * SpellCoolDownTimers
spells to auto cast
Definition: unit.h:414
Definition: unit_manager.h:50
unsigned long ShowNameDelay
Show orders for some time.
Definition: unit_draw.cpp:99
unsigned ByPlayer
Unit seen destroyed or not.
Definition: unit.h:387
int Frame
Seen construction frame.
Definition: unit.h:379
Unit looking south west.
Definition: unit.h:111
unsigned int Wait
unit belongs to this last group
Definition: unit.h:397
bool IconsShift
Use grayscaled icons for unavailable units, upgrades, etc.
Definition: unit.h:448
int CanTransport(const CUnit &transporter, const CUnit &unit)
Can transporter transport the other unit.
Definition: unit.cpp:2981
int ShowNameTime
How many cycles need to wait until unit's name popup will appear.
Definition: unit.h:456
void UnSelectUnit(CUnit &unit)
Remove a unit from selection.
Definition: selection.cpp:259
void GroupCclRegister()
Register CCL group features.
Definition: groups.cpp:271
CUnit * UnitOnScreen(int x, int y)
Get unit under cursor.
Definition: unit.cpp:2265
const CConstructionFrame * CFrame
Definition: unit.h:378
void UpdateForNewUnit(const CUnit &unit, int upgrade)
Definition: unit.cpp:1363
CUnit * CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i &pos)
Definition: build.cpp:391
PathFinderData * pathFinderData
Unit's Current Sight Range.
Definition: unit.h:337
CBuildRestrictionOnTop * OnTopDetails(const CUnit &unit, const CUnitType *parent)
Return the rule used to build this building.
Definition: build.cpp:60
unsigned int LastGroup
unit belongs to this group id
Definition: unit.h:395
int ToggleSelectUnit(CUnit &unit)
Add a unit to selected if not already selected, remove it otherwise.
Definition: selection.cpp:310
unsigned Destroyed
Unit seen build/upgrade state.
Definition: unit.h:386
bool CanMove() const
Definition: unittype.cpp:624
unsigned Removed
unit is destroyed pending reference
Definition: unit.h:359
void ShowOrder(const CUnit &unit)
Show a unit's orders.
Definition: unit_draw.cpp:614
void SaveUnit(const CUnit &unit, CFile &file)
save unit-structure
Definition: unit_save.cpp:124
PixelPos GetMapPixelPosTopLeft() const
Definition: unit.cpp:2302
CPreference Preference
Lua handler count.
Definition: script_ui.cpp:66
Definition: unitptr.h:41
CUnit * CanBuildUnitType(const CUnit *unit, const CUnitType &type, const Vec2i &pos, int real)
FIXME: more docu.
Definition: build.cpp:493
int MapDistanceTo(const CUnit &dst) const
Definition: unit.h:272
int Assigned
pointer to first assigned worker to this resource.
Definition: unit.h:323
void NearestOfUnit(const CUnit &unit, const Vec2i &pos, Vec2i *dpos)
Definition: unit.cpp:1392
bool AiExplores
If true, game pauses when cursor is gone.
Definition: unit.h:446
unsigned AutoRepair
Recast again next cycle.
Definition: unit.h:355
void SaveGroups(CFile &file)
Save groups.
Definition: groups.cpp:124
Diplomacy states for CommandDiplomacy.
Definition: player.h:79
unsigned Destroyed
unit is burning
Definition: unit.h:358
unsigned State
Unit seen construction.
Definition: unit.h:385
signed char IX
individual upgrades which the unit has
Definition: unit.h:344
CUnit * NextWorker
Previous unit in the container.
Definition: unit.h:320
void UnitClearOrders(CUnit &unit)
Remove the Orders of a Unit.
Definition: unit.cpp:1348
void DestroyAllInside(CUnit &source)
Destroy all units inside another unit.
Definition: unit.cpp:2423
unsigned char Direction
Y image displacement to map position.
Definition: unit.h:346
CGraphic * IconFrameG
Path to SF2 soundfont.
Definition: unit.h:461
int SelectGroupFromUnit(CUnit &unit)
Select the units from the same group as the one in parameter.
Definition: selection.cpp:585
void UnitHeadingFromDeltaXY(CUnit &unit, const Vec2i &delta)
Heading and frame from delta direction.
Definition: unit.cpp:2057
CPlayer * Player
Pointer to unit-type (peon,...)
Definition: unit.h:332
bool IsVisibleOnRadar(const CPlayer &pradar) const
Definition: map_radar.cpp:80
CGraphic * PressedIconFrameG
Definition: unit.h:462
unsigned ReCast
The unit is moving.
Definition: unit.h:354
void CleanUnits()
Clean unit module.
Definition: unit.cpp:3173
unsigned Constructed
unit is selected
Definition: unit.h:362
void DrawSelectionCircle(IntColor, int, int, int, int)
Draw circle around unit.
Definition: unit_draw.cpp:190
int InsideCount
index in Player->Units
Definition: unit.h:313
int Unbreakable
Wait.
Definition: unit.h:404
void UnitCclRegister()
register CCL units features
Definition: script_unit.cpp:1265
struct CUnit::@37 Resource
CUnit * Container
Pointer to one of the units inside.
Definition: unit.h:316
const CUnitType * Type
last seen frame/stage of buildings
Definition: unit.h:380
bool IsVisible(const CPlayer &player) const
Returns true, if unit is directly seen by an allied unit.
Definition: unit.cpp:1640
int AddGroupFromUnitToSelection(CUnit &unit)
Add the units from the same group as the one in parameter.
Definition: selection.cpp:549
unsigned long TTL
array of User Defined variables.
Definition: unit.h:392
void AddInContainer(CUnit &host)
Add a unit inside a container. Only deal with list stuff.
Definition: unit.cpp:993
int VisCount[PlayerMax]
NULL if the unit was not rescued.
Definition: unit.h:375
CUnit * MakeUnit(const CUnitType &type, CPlayer *player)
Create a new unit.
Definition: unit.cpp:748
void InitUnits()
Initialize unit module.
Definition: unit.cpp:3163
PixelPos GetMapPixelPosCenter() const
Definition: unit.cpp:2308
CUnit * GetFirstContainer(const CUnit &unit)
Definition: unit.cpp:810
void DecorationCclRegister()
Register CCL decorations features.
Definition: unit_draw.cpp:333
void UnitCountSeen(CUnit &unit)
Does a recount for VisCount.
Definition: unit.cpp:1564
int DirectionToHeading(const Vec2i &dir)
Convert direction (dx,dy) to heading (0-255)
Definition: unit.cpp:1986
bool StereoSound
Shift icons slightly when you press on them.
Definition: unit.h:449
int CanTarget(const CUnitType &type, const CUnitType &dest)
Can this unit-type attack the other (destination)
Definition: unit.cpp:2948
CUnitColors * Colors
Image frame: <0 is mirrored.
Definition: unit.h:341
void CleanGroups()
Cleanup groups.
Definition: groups.cpp:141
bool IsVisibleInViewport(const CViewport &vp) const
Returns true if unit is visible in a viewport. Only for ThisPlayer.
Definition: unit.cpp:1687
Unit visibility counts.
Definition: unit.h:376
void HitUnit(CUnit *attacker, CUnit &target, int damage, const Missile *missile=NULL)
Hit unit with damage, if destroyed give attacker the points.
Definition: unit.cpp:2730
bool IsOnlySelected(const CUnit &unit)
Check if unit is the currently only selected.
Definition: selection.cpp:69
int ThreatCalculate(const CUnit &unit, const CUnit &dest)
Calculate some value to measure the unit's priority for AI.
Definition: unit.cpp:2444
Definition: upgrade_structs.h:154
bool IsAliveOnMap() const
Definition: unit.h:198
int ToggleUnitsByType(CUnit &base)
Toggle units from the same type (if selectable by rectangle)
Definition: selection.cpp:431
void DrawSelectionNone(IntColor, int, int, int, int)
Draw nothing around unit.
Definition: unit_draw.cpp:179
COrder * COrderPtr
Definition: unit.h:73
Definition: vec2i.h:36
unsigned Blink
gamecycle unit was last attacked
Definition: unit.h:352
Definition: upgrade_structs.h:129
_seen_stuff_()
Definition: unit.h:377
uint32_t IntColor
Definition: color.h:74
Describes a field of the map.
Definition: tile.h:186
int ShowOrders
Don't show messages on status line.
Definition: unit.h:454
Unit looking north east.
Definition: unit.h:107
const CUnitType * Type
Map position as flat index offset (x + y * w)
Definition: unit.h:331
void UnitGoesOutOfFog(CUnit &unit, const CPlayer &player)
Call when an Unit goes out of fog.
Definition: unit.cpp:1543
bool DeselectInMine
Show mine is running low/depleted messages.
Definition: unit.h:451
void UnitGoesUnderFog(CUnit &unit, const CPlayer &player)
Call when an Unit goes under fog.
Definition: unit.cpp:1502
int CurrentSightRange
Current unit stats.
Definition: unit.h:334
std::string UnitReference(const CUnit &unit)
Generate a unit reference, a printable unique string for unit.
Definition: unit_save.cpp:61
bool IsVisibleAsGoal(const CPlayer &player) const
Definition: unit.h:210
int Active
how many units are assigned to harvesting from the resource.
Definition: unit.h:324
int SelectAirUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
Select flying units in the selection rectangle.
Definition: selection.cpp:891
int ResourcesMultiBuildersMultiplier
Config: reveal attacker enabled.
Definition: unit.cpp:358
bool MineNotifications
Enables/disables stereo sound effects.
Definition: unit.h:450
void RemoveUnitFromGroups(CUnit &unit)
Remove a unit from a group.
Definition: groups.cpp:228
bool IsEnemy(const CPlayer &player) const
Definition: unit.cpp:3020
void CorrectWallNeighBours(CUnit &unit)
Correct the surrounding walls.
Definition: unit.cpp:1474
void RefsDecrease()
Decrease a unit's reference count.
Definition: unit.cpp:387
int SelectUnit(CUnit &unit)
Add a unit to selection.
Definition: selection.cpp:210
bool IndividualUpgrades[UpgradeMax]
Player colors.
Definition: unit.h:342
int SelectGroup(int group_number, GroupSelectionMode mode=SELECTABLE_BY_RECTANGLE_ONLY)
Select the units belonging to a particular group.
Definition: selection.cpp:515
bool ShowSightRange
Definition: unit.h:438
Definition: unittype.h:149
Definition: unit.h:105
bool CanBuildOn(const Vec2i &pos, int mask)
Definition: build.cpp:477
bool IsGroupTainted(int num)
Definition: groups.cpp:148
void DrawSelectionCircleWithTrans(IntColor, int, int, int, int)
Draw circle filled with alpha around unit.
Definition: unit_draw.cpp:203
void LetUnitDie(CUnit &unit, bool suicide=false)
Let a unit die.
Definition: unit.cpp:2318
bool CanMove() const
Definition: unit.h:285
void Draw(const CViewport &vp) const
Draw a single unit.
Definition: unit_draw.cpp:788
int ViewPointDistance(const Vec2i &pos)
Calculate the distance from current view point to coordinate.
Definition: unit.cpp:2915
CUnit()
Definition: unit.h:122
unsigned TeamSelected
This mine got a notification about its resources being low.
Definition: unit.h:371
void AddToGroup(CUnit **units, unsigned int nunits, int num)
Add the array of units to the group.
Definition: groups.cpp:192
bool IsAgressive() const
Definition: unit.h:169
Definition: spells.h:205
int AddSelectedUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
Add the units in the selection rectangle to the current selection.
Definition: selection.cpp:783
unsigned char DamagedType
Resources Held by a unit.
Definition: unit.h:350
(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.