10 #include "basetypes.h" 11 #include "buildtype.h" 20 #include <unordered_map> 109 containerIndices.fill((
size_t)invalidIndex);
113 return (unit.
flags & n) != 0;
117 return flag(tc::Unit::Flags::Attacking);
120 return flag(tc::Unit::Flags::Burrowed);
123 return flag(tc::Unit::Flags::Cloaked);
126 return flag(tc::Unit::Flags::Idle);
129 return flag(tc::Unit::Flags::Completed);
132 return flag(tc::Unit::Flags::Detected);
135 return flag(tc::Unit::Flags::Morphing);
138 return flag(tc::Unit::Flags::BeingGathered);
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;
153 return flag(tc::Unit::Flags::Powered);
156 return flag(tc::Unit::Flags::Lifted);
159 return flag(tc::Unit::Flags::CarryingMinerals);
162 return flag(tc::Unit::Flags::CarryingGas);
168 return flag(tc::Unit::Flags::Moving);
171 return flag(tc::Unit::Flags::Upgrading);
174 return flag(tc::Unit::Flags::Researching);
177 return flag(tc::Unit::Flags::Blind);
180 return flag(tc::Unit::Flags::BeingConstructed);
183 return flag(tc::Unit::Flags::Flying);
186 return flag(tc::Unit::Flags::Invincible);
189 return flag(tc::Unit::Flags::Irradiated);
192 return flag(tc::Unit::Flags::Plagued);
195 return flag(tc::Unit::Flags::UnderDarkSwarm);
198 return flag(tc::Unit::Flags::GatheringGas);
201 return flag(tc::Unit::Flags::GatheringMinerals);
207 return flag(tc::Unit::Flags::Constructing);
210 return flag(tc::Unit::Flags::Repairing);
213 return flag(tc::Unit::Flags::Stimmed);
216 return flag(tc::Unit::Flags::Ensnared);
219 return tc::BW::data::Acceleration[type->
unit] <= 1
232 double cdMultiplier()
const;
251 bool inRangeOf(
Unit const* source,
double frames = 0U)
const;
262 int destShield)
const;
268 auto air = dest->
flying();
303 Unit* getUnit(UnitId
id);
312 return allUnitsEver_;
320 return visibleUnits_;
328 return visibleBuildings_;
332 return resourceUnits_;
346 return myResourceDepots_;
355 return visibleEnemyUnits_;
360 return neutralUnits_;
370 return startedMorphingUnits_;
375 return completedOrMorphedUnits_;
389 return destroyUnits_;
395 const Units& mapHacked();
397 const std::unordered_map<const BuildType*, int>& inferredEnemyUnitTypes();
404 void updateGroups(
Unit* i);
407 inferMovePosition(
Position source,
bool flying,
int tileVisibiltyAge);
409 void inferUpdateNearbyUnits();
413 std::unordered_map<int, std::unordered_map<const BuildType*, double>>
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];
423 Units& myUnits_ = unitContainers_[6];
424 Units& myWorkers_ = unitContainers_[7];
425 Units& myBuildings_ = unitContainers_[8];
426 Units& myResourceDepots_ = unitContainers_[9];
428 Units& enemyUnits_ = unitContainers_[10];
429 Units& visibleEnemyUnits_ = unitContainers_[11];
431 Units& neutralUnits_ = unitContainers_[12];
450 Units& mapHackUnits_ = unitContainers_[15];
458 oss <<
"i (nullptr)";
461 oss <<
"i" << unit->
id <<
" (" << unit->
type->
name <<
")";
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
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
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'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
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'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've scouted the last location it was at, and we don'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