TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
unitsinfo.h
1 /*
2  * Copyright (c) 2017-present, Facebook, Inc.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #pragma once
9 
10 #include "basetypes.h"
11 #include "buildtype.h"
12 #include "cherrypi.h"
13 
14 #include <algorithm>
15 #include <array>
16 #include <cstdint>
17 #include <functional>
18 #include <list>
19 #include <random>
20 #include <unordered_map>
21 #include <utility>
22 #include <vector>
23 
24 namespace cherrypi {
25 
26 class State;
27 
28 typedef int32_t UnitId;
29 
30 /**
31  * Represents a unit in the game.
32  *
33  * Unit objects have game lifetime. Thus, you can hold pointers to them.
34  */
35 struct Unit {
36  UnitId id = -1;
37  int x = 0;
38  int y = 0;
40  /// This unit is currently visible. If this field is set, all other fields
41  /// are up-to-date, otherwise everything is from when we last saw it.
42  bool visible = false;
43  /// We've seen this unit die.
44  bool dead = false;
45  /// If the unit is not visible, but we've scouted the last location it was at,
46  /// and we don't have a better clue about where it is, then this is set to
47  /// true. The unit might still be in the game, or it might be dead.
48  bool gone = false; // todo
53  bool isMine = false;
54  bool isEnemy = false;
55  bool isNeutral = false;
56  const BuildType* type = nullptr;
58  /// X coordinate of the *walktile* the build location (top left corner) of the
59  /// unit
60  int buildX = 0;
61  /// Y coordinate of the *walktile* the build location (top left corner) of the
62  /// unit
63  int buildY = 0;
64  const BuildType* constructingType = nullptr;
65  const BuildType* upgradingType = nullptr;
66  const BuildType* researchingType = nullptr;
69  Unit* associatedUnit = nullptr;
70  int associatedCount = 0;
71  Unit* addon = nullptr;
72  int sightRange = 0;
73  Unit* attackingTarget = nullptr;
74  int lastAttacked = 0;
75  double topSpeed = 0;
76  bool hasCollision = true;
78  std::unordered_set<Unit*> inferNearbyUnitsToMove;
79 
80  /// A copy of the torchcraft unit data.
81  tc::Unit unit = {};
82 
83  /// The last UPC that was used to send a TC command involving this unit
85  /// Bitwise combination of last UPC command and all its sources.
86  uint32_t lastUpcCommands = Command::None;
87  /// Commands with a probility higher than this will be considered for
88  /// lastUpcCommands.
89  static float constexpr kLastUpcCommandThreshold = 0.5f;
90 
91  // Both the below are guaranteed to be sorted by distance from me
92  // All enemy units who are within range to attack you in the next second
93  std::vector<Unit*> threateningEnemies;
94  // All units that are attacking you
95  std::vector<Unit*> beingAttackedByEnemies;
96  // these helpers can be used for efficiency when computing moves
97  // All units in sight range
98  std::vector<Unit*> unitsInSightRange;
99  // All buildings in sight range
100  std::vector<Unit*> obstaclesInSightRange;
101  // All enemies/allied units in sight range, without buildings
102  std::vector<Unit*> enemyUnitsInSightRange;
103  std::vector<Unit*> allyUnitsInSightRange;
104 
105  std::array<size_t, 16> containerIndices;
106  static const size_t invalidIndex = (size_t)-1;
107 
108  Unit() {
109  containerIndices.fill((size_t)invalidIndex);
110  }
111 
112  bool flag(tc::Unit::Flags n) const {
113  return (unit.flags & n) != 0;
114  }
115 
116  bool attacking() const {
117  return flag(tc::Unit::Flags::Attacking);
118  }
119  bool burrowed() const {
120  return flag(tc::Unit::Flags::Burrowed);
121  }
122  bool cloaked() const {
123  return flag(tc::Unit::Flags::Cloaked);
124  }
125  bool idle() const {
126  return flag(tc::Unit::Flags::Idle);
127  }
128  bool completed() const {
129  return flag(tc::Unit::Flags::Completed);
130  }
131  bool detected() const {
132  return flag(tc::Unit::Flags::Detected);
133  }
134  bool morphing() const {
135  return flag(tc::Unit::Flags::Morphing);
136  }
137  bool beingGathered() const {
138  return flag(tc::Unit::Flags::BeingGathered);
139  }
140  bool active() const {
141  if (dead) {
142  return false;
143  }
144  auto constexpr flip = tc::Unit::Flags::Powered | tc::Unit::Flags::Completed;
145  auto constexpr mask = tc::Unit::Flags::BeingConstructed |
146  tc::Unit::Flags::Completed | tc::Unit::Flags::Loaded |
147  tc::Unit::Flags::LockedDown | tc::Unit::Flags::Maelstrommed |
148  tc::Unit::Flags::Powered | tc::Unit::Flags::Stasised |
149  tc::Unit::Flags::Stuck;
150  return ((unit.flags ^ flip) & mask) == 0;
151  }
152  bool powered() const {
153  return flag(tc::Unit::Flags::Powered);
154  }
155  bool lifted() const {
156  return flag(tc::Unit::Flags::Lifted);
157  }
158  bool carryingMinerals() const {
159  return flag(tc::Unit::Flags::CarryingMinerals);
160  }
161  bool carryingGas() const {
162  return flag(tc::Unit::Flags::CarryingGas);
163  }
164  bool carryingResources() const {
165  return carryingMinerals() || carryingGas();
166  }
167  bool moving() const {
168  return flag(tc::Unit::Flags::Moving);
169  }
170  bool upgrading() const {
171  return flag(tc::Unit::Flags::Upgrading);
172  }
173  bool researching() const {
174  return flag(tc::Unit::Flags::Researching);
175  }
176  bool blind() const {
177  return flag(tc::Unit::Flags::Blind);
178  }
179  bool beingConstructed() const {
180  return flag(tc::Unit::Flags::BeingConstructed);
181  }
182  bool flying() const {
183  return flag(tc::Unit::Flags::Flying);
184  }
185  bool invincible() const {
186  return flag(tc::Unit::Flags::Invincible);
187  }
188  bool irradiated() const {
189  return flag(tc::Unit::Flags::Irradiated);
190  }
191  bool plagued() const {
192  return flag(tc::Unit::Flags::Plagued);
193  }
194  bool underDarkSwarm() const {
195  return flag(tc::Unit::Flags::UnderDarkSwarm);
196  }
197  bool gatheringGas() const {
198  return flag(tc::Unit::Flags::GatheringGas);
199  }
200  bool gatheringMinerals() const {
201  return flag(tc::Unit::Flags::GatheringMinerals);
202  }
203  bool gathering() const {
204  return gatheringGas() || gatheringMinerals();
205  }
206  bool constructing() const {
207  return flag(tc::Unit::Flags::Constructing);
208  }
209  bool repairing() const {
210  return flag(tc::Unit::Flags::Repairing);
211  }
212  bool stimmed() const {
213  return flag(tc::Unit::Flags::Stimmed);
214  }
215  bool ensnared() const {
216  return flag(tc::Unit::Flags::Ensnared);
217  }
218  double atTopSpeed() const {
219  return tc::BW::data::Acceleration[type->unit] <= 1
220  ? true
221  : unit.velocityX * unit.velocityX + unit.velocityY * unit.velocityY >
222  0.90 * topSpeed * topSpeed;
223  }
224 
225  bool canKite(Unit const* dest) const;
226  inline bool canAttack(Unit const* dest) const {
227  return dest->detected() && !dest->invincible() &&
228  (dest->flying() ? type->hasAirWeapon : type->hasGroundWeapon);
229  }
230 
231  private:
232  double cdMultiplier() const;
233 
234  public:
235  double cd() const;
236  double maxCdAir() const;
237  double maxCdGround() const;
238  Vec2 velocity() const;
239  Vec2 pxVelocity() const;
240  double pxTopSpeed() const;
241  double maxCdAgainst(Unit const* target) const;
242  double rangeAgainst(Unit const* target) const;
243  double pxRangeAgainst(Unit const* target) const;
244 
245  Position pos() const {
246  return Position(x, y);
247  }
248  Vec2 posf() const;
249 
250  // In range of source, assuming source has had [frames] to move towards us
251  bool inRangeOf(Unit const* source, double frames = 0U) const;
252 
253  /// Compute HP and shield damage to dest when attacking now.
254  void computeDamageTo(Unit const* dest, int* hpDamage, int* shieldDamage)
255  const;
256  /// Compute HP and shield damage to dest when attacking now and dest has
257  /// `destShield` shield points left.
258  void computeDamageTo(
259  Unit const* dest,
260  int* hpDamage,
261  int* shieldDamage,
262  int destShield) const;
263 
264  // Computes number of hits to kill target (effective health points)
265  double computeEHP(Unit const* dest) const;
266 
267  inline double computeHPDamage(Unit const* dest, double dmg) const {
268  auto air = dest->flying();
269  auto dmgType = air ? unit.airDmgType : unit.groundDmgType;
270  auto numAttacks = air ? type->numAirAttacks : type->numGroundAttacks;
271  return damageMultiplier(dmgType, dest->unit.size) * dmg -
272  numAttacks * dest->unit.armor;
273  }
274  inline double computeHPDamage(Unit const* dest) const {
275  return computeHPDamage(dest, dest->flying() ? unit.airATK : unit.groundATK);
276  }
277  inline double computeShieldDamage(Unit const* dest, double dmg) const {
278  auto numAttacks =
279  dest->flying() ? type->numAirAttacks : type->numGroundAttacks;
280  return dmg - numAttacks * dest->unit.shieldArmor;
281  }
282  inline double computeShieldDamage(Unit const* dest) const {
283  return computeShieldDamage(
284  dest, dest->flying() ? unit.airATK : unit.groundATK);
285  }
286  Position getMovingTarget() const;
287  double damageMultiplier(Unit const* dest) const;
288  double damageMultiplier(int damageType, int unitSize) const;
289 };
290 
291 /**
292  * Updates and organizes information about all the units in the game.
293  */
294 class UnitsInfo {
295  public:
296  typedef std::vector<Unit*> Units;
297 
298  UnitsInfo(State* state_);
299  ~UnitsInfo();
300  UnitsInfo(UnitsInfo const&) = delete;
301  UnitsInfo& operator=(UnitsInfo const&) = delete;
302 
303  Unit* getUnit(UnitId id);
304 
305  /// Our units of a particular type (does not include dead units).
306  const Units& myUnitsOfType(const BuildType* type);
307  /// Our completed units of a particular type (does not include dead units).
308  const Units& myCompletedUnitsOfType(const BuildType* type);
309 
310  /// All units we've ever seen
311  const Units& allUnitsEver() {
312  return allUnitsEver_;
313  }
314  /// All units that are not dead. This includes gone units.
315  const Units& liveUnits() {
316  return liveUnits_;
317  }
318  /// All units that are currently visible.
319  const Units& visibleUnits() {
320  return visibleUnits_;
321  }
322  /// All units that are currently not visible.
323  const Units& hiddenUnits() {
324  return hiddenUnits_;
325  }
326  /// All buildings that are currently visible.
327  const Units& visibleBuildings() {
328  return visibleBuildings_;
329  }
330  /// All resources (mineral fields, gas geysers + refineries)
331  const Units& resourceUnits() {
332  return resourceUnits_;
333  }
334 
335  /// All our (live) units
336  const Units& myUnits() {
337  return myUnits_;
338  }
339  const Units& myWorkers() {
340  return myWorkers_;
341  }
342  const Units& myBuildings() {
343  return myBuildings_;
344  }
345  const Units& myResourceDepots() {
346  return myResourceDepots_;
347  }
348 
349  /// All enemy units that are not dead (includes gone units).
350  const Units& enemyUnits() {
351  return enemyUnits_;
352  }
353  /// All enemy units that we can see right now.
354  const Units& visibleEnemyUnits() {
355  return visibleEnemyUnits_;
356  }
357 
358  /// All neutral units that are not dead
359  const Units& neutralUnits() {
360  return neutralUnits_;
361  }
362 
363  /// All units that were discovered since the previous update/step.
364  const Units& getNewUnits() {
365  return newUnits_;
366  }
367  /// All units that has started morphing to a different unit type (was
368  /// not morphing last update/step).
369  const Units& getStartedMorphingUnits() {
370  return startedMorphingUnits_;
371  }
372  /// All units that finished being built or finished morphing since the
373  /// previous update/step.
374  const Units& getCompletedOrMorphedUnits() {
375  return completedOrMorphedUnits_;
376  }
377  /// All units that went from hidden to visible since the previous
378  /// update/step.
379  const Units& getShowUnits() {
380  return showUnits_;
381  }
382  /// All units that went from visible to hidden since the previous
383  /// update/step.
384  const Units& getHideUnits() {
385  return hideUnits_;
386  }
387  /// All units that died since the previous update/step.
388  const Units& getDestroyUnits() {
389  return destroyUnits_;
390  }
391 
392  /// Parse the units directly from the tcstate, this is only reasonable
393  /// when we have mapHack on. Keep in mind not all things that we precompute,
394  /// like beingAttackedByEnemies, etc, are filled out in the mapHacked units.
395  const Units& mapHacked();
396 
397  const std::unordered_map<const BuildType*, int>& inferredEnemyUnitTypes();
398 
399  void update();
400 
401  protected:
402  State* state_ = nullptr;
403  void updateUnit(Unit*, const tc::Unit&, tc::State*, bool maphack = false);
404  void updateGroups(Unit* i);
405  size_t inferPositionsUnitAtIndex(Position pos);
406  Position
407  inferMovePosition(Position source, bool flying, int tileVisibiltyAge);
408  void inferMoveUnit(Unit* u, Position newPos);
409  void inferUpdateNearbyUnits();
410 
411  std::array<Units, 16> unitContainers_;
412  std::unordered_map<UnitId, Unit> unitsMap_;
413  std::unordered_map<int, std::unordered_map<const BuildType*, double>>
415 
416  Units& allUnitsEver_ = unitContainers_[0];
417  Units& liveUnits_ = unitContainers_[1];
418  Units& visibleUnits_ = unitContainers_[2];
419  Units& hiddenUnits_ = unitContainers_[3];
420  Units& visibleBuildings_ = unitContainers_[4];
421  Units& resourceUnits_ = unitContainers_[5];
422 
423  Units& myUnits_ = unitContainers_[6];
424  Units& myWorkers_ = unitContainers_[7];
425  Units& myBuildings_ = unitContainers_[8];
426  Units& myResourceDepots_ = unitContainers_[9];
427 
428  Units& enemyUnits_ = unitContainers_[10];
429  Units& visibleEnemyUnits_ = unitContainers_[11];
430 
431  Units& neutralUnits_ = unitContainers_[12];
432 
433  std::unordered_map<int, Units> myUnitsOfType_;
434  std::unordered_map<int, Units> myCompletedUnitsOfType_;
435 
436  Units newUnits_;
439  Units showUnits_;
440  Units hideUnits_;
442  std::unordered_map<const BuildType*, int> memoizedEnemyUnitTypes_;
443 
444  std::vector<uint8_t> inferPositionsUnitAt;
446 
447  std::minstd_rand rngEngine;
448 
449  std::unordered_map<UnitId, Unit> mapHackUnitsMap_;
450  Units& mapHackUnits_ = unitContainers_[15];
451 };
452 
453 } // namespace cherrypi
454 
455 namespace std {
456 inline ostream& operator<<(ostream& oss, cherrypi::Unit const* unit) {
457  if (!unit) {
458  oss << "i (nullptr)";
459  } else {
460  // Log units with 'i' prefix so that we'll be able to use 'u' for UPC tuples
461  oss << "i" << unit->id << " (" << unit->type->name << ")";
462  }
463  return oss;
464 }
465 } // namespace std
std::unordered_map< UnitId, Unit > unitsMap_
Definition: unitsinfo.h:412
bool ensnared() const
Definition: unitsinfo.h:215
Game state.
Definition: state.h:42
int FrameNum
Definition: basetypes.h:22
Unit * attackingTarget
Definition: unitsinfo.h:73
bool beingGathered() const
Definition: unitsinfo.h:137
bool carryingGas() const
Definition: unitsinfo.h:161
std::unordered_map< UnitId, Unit > mapHackUnitsMap_
Definition: unitsinfo.h:449
double pxTopSpeed() const
Definition: unitsinfo.cpp:127
int numAirAttacks
Definition: buildtype.h:91
int32_t groundDmgType
Definition: frame.h:91
bool upgrading() const
Definition: unitsinfo.h:170
const Units & liveUnits()
All units that are not dead. This includes gone units.
Definition: unitsinfo.h:315
bool plagued() const
Definition: unitsinfo.h:191
std::vector< uint8_t > inferPositionsUnitAt
Definition: unitsinfo.h:444
int buildY
Y coordinate of the walktile the build location (top left corner) of the unit.
Definition: unitsinfo.h:63
Unit * associatedUnit
Definition: unitsinfo.h:69
int32_t airDmgType
Definition: frame.h:91
double rangeAgainst(Unit const *target) const
Definition: unitsinfo.cpp:135
std::vector< Unit * > obstaclesInSightRange
Definition: unitsinfo.h:100
Represents and holds information about buildable types (units, upgrades, techs).
Definition: buildtype.h:36
static float constexpr kLastUpcCommandThreshold
Commands with a probility higher than this will be considered for lastUpcCommands.
Definition: unitsinfo.h:89
const Units & resourceUnits()
All resources (mineral fields, gas geysers + refineries)
Definition: unitsinfo.h:331
double cd() const
Definition: unitsinfo.cpp:82
std::vector< Unit * > allyUnitsInSightRange
Definition: unitsinfo.h:103
bool hasGroundWeapon
Definition: buildtype.h:90
bool flag(tc::Unit::Flags n) const
Definition: unitsinfo.h:112
double computeShieldDamage(Unit const *dest) const
Definition: unitsinfo.h:282
bool flying() const
Definition: unitsinfo.h:182
bool cloaked() const
Definition: unitsinfo.h:122
STL namespace.
bool isNeutral
Definition: unitsinfo.h:55
bool canKite(Unit const *dest) const
Definition: unitsinfo.cpp:63
Unit()
Definition: unitsinfo.h:108
int numGroundAttacks
Definition: buildtype.h:92
const Units & neutralUnits()
All neutral units that are not dead.
Definition: unitsinfo.h:359
std::vector< Unit * > enemyUnitsInSightRange
Definition: unitsinfo.h:102
FrameNum busyUntil
Definition: unitsinfo.h:57
bool lifted() const
Definition: unitsinfo.h:155
bool carryingResources() const
Definition: unitsinfo.h:164
Units showUnits_
Definition: unitsinfo.h:439
double computeHPDamage(Unit const *dest, double dmg) const
Definition: unitsinfo.h:267
bool invincible() const
Definition: unitsinfo.h:185
std::unordered_map< int, Units > myCompletedUnitsOfType_
Definition: unitsinfo.h:434
double topSpeed
Definition: unitsinfo.h:75
bool completed() const
Definition: unitsinfo.h:128
bool visible
This unit is currently visible.
Definition: unitsinfo.h:42
int32_t UnitId
Definition: unitsinfo.h:26
std::string name
Definition: buildtype.h:44
const Units & myResourceDepots()
Definition: unitsinfo.h:345
bool hasAirWeapon
Definition: buildtype.h:89
FrameNum lastLarvaSpawn
Definition: unitsinfo.h:52
Definition: frame.h:81
int32_t airATK
Definition: frame.h:90
const Units & hiddenUnits()
All units that are currently not visible.
Definition: unitsinfo.h:323
UnitId id
Definition: unitsinfo.h:36
const Units & myWorkers()
Definition: unitsinfo.h:339
double maxCdGround() const
Definition: unitsinfo.cpp:115
UpcId lastUpcId
The last UPC that was used to send a TC command involving this unit.
Definition: unitsinfo.h:84
const Units & myUnits()
All our (live) units.
Definition: unitsinfo.h:336
std::unordered_map< const BuildType *, int > memoizedEnemyUnitTypes_
Definition: unitsinfo.h:442
Represents a unit in the game.
Definition: unitsinfo.h:35
int remainingBuildTrainTime
Definition: unitsinfo.h:67
bool idle() const
Definition: unitsinfo.h:125
Updates and organizes information about all the units in the game.
Definition: unitsinfo.h:294
const Units & allUnitsEver()
All units we&#39;ve ever seen.
Definition: unitsinfo.h:311
std::array< size_t, 16 > containerIndices
Definition: unitsinfo.h:105
double maxCdAir() const
Definition: unitsinfo.cpp:111
bool carryingMinerals() const
Definition: unitsinfo.h:158
Position getMovingTarget() const
Definition: unitsinfo.cpp:208
const Units & visibleBuildings()
All buildings that are currently visible.
Definition: unitsinfo.h:327
const Units & getCompletedOrMorphedUnits()
All units that finished being built or finished morphing since the previous update/step.
Definition: unitsinfo.h:374
bool isEnemy
Definition: unitsinfo.h:54
bool underDarkSwarm() const
Definition: unitsinfo.h:194
const Units & getShowUnits()
All units that went from hidden to visible since the previous update/step.
Definition: unitsinfo.h:379
std::vector< Unit * > threateningEnemies
Definition: unitsinfo.h:93
double damageMultiplier(Unit const *dest) const
Definition: unitsinfo.cpp:55
bool hasCollision
Definition: unitsinfo.h:76
std::unordered_map< int, Units > myUnitsOfType_
Definition: unitsinfo.h:433
Definition: state.h:43
bool powered() const
Definition: unitsinfo.h:152
const Units & visibleEnemyUnits()
All enemy units that we can see right now.
Definition: unitsinfo.h:354
std::unordered_set< Unit * > inferNearbyUnitsToMove
Definition: unitsinfo.h:78
bool blind() const
Definition: unitsinfo.h:176
const BuildType * researchingType
Definition: unitsinfo.h:66
bool beingConstructed() const
Definition: unitsinfo.h:179
int32_t size
Definition: frame.h:87
tc::Unit unit
A copy of the torchcraft unit data.
Definition: unitsinfo.h:81
double pxRangeAgainst(Unit const *target) const
Definition: unitsinfo.cpp:139
const Units & myBuildings()
Definition: unitsinfo.h:342
Units destroyUnits_
Definition: unitsinfo.h:441
Flags
Definition: frame.h:108
std::minstd_rand rngEngine
Definition: unitsinfo.h:447
PlayerId playerId
Definition: unitsinfo.h:39
int lastAttacked
Definition: unitsinfo.h:74
Vec2 posf() const
Definition: unitsinfo.cpp:143
const Units & getHideUnits()
All units that went from visible to hidden since the previous update/step.
Definition: unitsinfo.h:384
Units newUnits_
Definition: unitsinfo.h:436
bool researching() const
Definition: unitsinfo.h:173
const Units & enemyUnits()
All enemy units that are not dead (includes gone units).
Definition: unitsinfo.h:350
Position lastSeenPos
Definition: unitsinfo.h:77
int32_t shieldArmor
Definition: frame.h:87
std::array< Units, 16 > unitContainers_
Definition: unitsinfo.h:411
bool active() const
Definition: unitsinfo.h:140
double computeEHP(Unit const *dest) const
Definition: unitsinfo.cpp:190
uint32_t lastUpcCommands
Bitwise combination of last UPC command and all its sources.
Definition: unitsinfo.h:86
bool moving() const
Definition: unitsinfo.h:167
bool isMine
Definition: unitsinfo.h:53
double computeShieldDamage(Unit const *dest, double dmg) const
Definition: unitsinfo.h:277
int PlayerId
Definition: basetypes.h:21
const Units & getDestroyUnits()
All units that died since the previous update/step.
Definition: unitsinfo.h:388
bool canAttack(Unit const *dest) const
Definition: unitsinfo.h:226
int32_t armor
Definition: frame.h:87
int sightRange
Definition: unitsinfo.h:72
Position pos() const
Definition: unitsinfo.h:245
bool burrowed() const
Definition: unitsinfo.h:119
Vec2 pxVelocity() const
Definition: unitsinfo.cpp:123
int unit
Definition: buildtype.h:37
bool gatheringGas() const
Definition: unitsinfo.h:197
bool gatheringMinerals() const
Definition: unitsinfo.h:200
const Units & visibleUnits()
All units that are currently visible.
Definition: unitsinfo.h:319
bool detected() const
Definition: unitsinfo.h:131
Units startedMorphingUnits_
Definition: unitsinfo.h:437
bool dead
We&#39;ve seen this unit die.
Definition: unitsinfo.h:44
Main namespace for bot-related code.
Definition: areainfo.cpp:17
FrameNum goneFrame
Definition: unitsinfo.h:51
double maxCdAgainst(Unit const *target) const
Definition: unitsinfo.cpp:131
bool morphing() const
Definition: unitsinfo.h:134
const BuildType * type
Definition: unitsinfo.h:56
int associatedCount
Definition: unitsinfo.h:70
bool gathering() const
Definition: unitsinfo.h:203
int remainingUpgradeResearchTime
Definition: unitsinfo.h:68
bool constructing() const
Definition: unitsinfo.h:206
FrameNum lastInferUpdateNearbyUnits
Definition: unitsinfo.h:445
const BuildType * upgradingType
Definition: unitsinfo.h:65
static const size_t invalidIndex
Definition: unitsinfo.h:106
bool gone
If the unit is not visible, but we&#39;ve scouted the last location it was at, and we don&#39;t have a better...
Definition: unitsinfo.h:48
Vec2 velocity() const
Definition: unitsinfo.cpp:119
int x
Definition: unitsinfo.h:37
std::vector< Unit * > unitsInSightRange
Definition: unitsinfo.h:98
int UpcId
Definition: basetypes.h:23
double velocityX
Definition: frame.h:97
bool inRangeOf(Unit const *source, double frames=0U) const
Definition: unitsinfo.cpp:149
std::vector< Unit * > Units
Definition: unitsinfo.h:296
void computeDamageTo(Unit const *dest, int *hpDamage, int *shieldDamage) const
Compute HP and shield damage to dest when attacking now.
Definition: unitsinfo.cpp:184
Unit * addon
Definition: unitsinfo.h:71
FrameNum firstSeen
Definition: unitsinfo.h:49
double computeHPDamage(Unit const *dest) const
Definition: unitsinfo.h:274
uint64_t flags
Definition: frame.h:85
bool stimmed() const
Definition: unitsinfo.h:212
FrameNum lastSeen
Definition: unitsinfo.h:50
std::unordered_map< int, std::unordered_map< const BuildType *, double > > speedMap_
Definition: unitsinfo.h:414
const Units & getNewUnits()
All units that were discovered since the previous update/step.
Definition: unitsinfo.h:364
std::vector< Unit * > beingAttackedByEnemies
Definition: unitsinfo.h:95
int32_t groundATK
Definition: frame.h:90
int y
Definition: unitsinfo.h:38
bool repairing() const
Definition: unitsinfo.h:209
bool irradiated() const
Definition: unitsinfo.h:188
Units hideUnits_
Definition: unitsinfo.h:440
const BuildType * constructingType
Definition: unitsinfo.h:64
double velocityY
Definition: frame.h:97
bool attacking() const
Definition: unitsinfo.h:116
int buildX
X coordinate of the walktile the build location (top left corner) of the unit.
Definition: unitsinfo.h:60
Vec2T< int > Position
Definition: basetypes.h:178
double atTopSpeed() const
Definition: unitsinfo.h:218
const Units & getStartedMorphingUnits()
All units that has started morphing to a different unit type (was not morphing last update/step)...
Definition: unitsinfo.h:369
UpcId constexpr kInvalidUpcId
Definition: basetypes.h:25
Units completedOrMorphedUnits_
Definition: unitsinfo.h:438