6 #include "sc2_proto_interface.h" 11 #include <unordered_map> 12 #include <unordered_set> 18 class ObservationInterface;
33 target_unit_tag(NullTag),
212 typedef std::vector<const Unit*> Units;
213 typedef std::unordered_map<Tag, size_t> UnitIdxMap;
221 typedef std::vector<UnitDamage> UnitsDamaged;
225 Unit* CreateUnit(Tag tag);
226 Unit* GetUnit(Tag tag)
const;
227 Unit* GetExistingUnit(Tag tag)
const;
228 void MarkDead(Tag tag);
231 void ForEachExistingUnit(
const std::function<
void(
Unit& unit)>& functor)
const;
232 void ClearExisting();
233 bool UnitExists(Tag tag);
235 const Units& GetNewUnits()
const noexcept {
return units_newly_created_; };
236 const Units& GetUnitsEnteringVision()
const noexcept {
return units_entering_vision_; };
237 const Units& GetCompletedBuildings()
const noexcept {
return buildings_constructed_; };
238 const UnitsDamaged& GetDamagedUnits()
const noexcept {
return units_damaged_; };
239 const std::unordered_set<const Unit*>& GetIdledUnits()
const noexcept {
return units_idled_; };
241 void AddNewUnit(
const Unit* u) { units_newly_created_.push_back(u); };
242 void AddUnitEnteredVision(
const Unit* u) { units_entering_vision_.push_back(u); }
243 void AddCompletedBuilding(
const Unit* u) { buildings_constructed_.push_back(u); }
244 void AddUnitIdled(
const Unit* u) {
245 if (u->
alliance == Unit::Alliance::Self) units_idled_.insert(u);
247 void AddUnitDamaged(
const Unit* u,
float health,
float shield) { units_damaged_.push_back({u, health, shield}); }
250 void IncrementIndex();
252 static const size_t ENTRY_SIZE = 1000;
253 typedef std::pair<size_t, size_t> PoolIndex;
255 std::vector<std::vector<Unit> > unit_pool_;
256 PoolIndex available_index_;
257 std::unordered_map<Tag, Unit *> tag_to_unit_;
258 std::unordered_map<Tag, Unit *> tag_to_existing_unit_;
259 Units units_newly_created_;
260 Units units_entering_vision_;
261 Units buildings_constructed_;
262 UnitsDamaged units_damaged_;
263 std::unordered_set<const Unit*> units_idled_;
uint32_t last_seen_game_loop
The last time the unit was seen.
Definition: sc2_unit.h:198
bool is_on_screen
Visible and within the camera frustum.
Definition: sc2_unit.h:143
float energy_max
Max energy of the unit. Not set for snapshots.
Definition: sc2_unit.h:160
Tag tag
The tag of the unit in the transport.
Definition: sc2_unit.h:41
float health
The health of the unit in the transport.
Definition: sc2_unit.h:43
CloakState
Unit cloak state.
Definition: sc2_unit.h:98
Common data types, including points, rectangles and colors.
A unit. Could be a structure, a worker or a military unit.
Definition: sc2_unit.h:70
Alliance
Relationship to this player.
Definition: sc2_unit.h:86
std::vector< UnitOrder > orders
Orders on a unit. Only valid for this player's units.
Definition: sc2_unit.h:175
Definition: sc2_common.h:14
int owner
Which player owns a unit.
Definition: sc2_unit.h:121
bool is_blip
Detected by sensor tower.
Definition: sc2_unit.h:145
Definition: sc2_common.h:49
float radius
Radius of the unit.
Definition: sc2_unit.h:128
bool is_alive
Whether the unit is alive or not.
Definition: sc2_unit.h:196
Definition: sc2_action.h:9
float energy_max
The max possible energy of the unit in the transport.
Definition: sc2_unit.h:53
UnitTypeID unit_type
An identifier of the type of unit.
Definition: sc2_unit.h:119
std::vector< PassengerUnit > passengers
Passengers in this transport. Only valid for this player's units.
Definition: sc2_unit.h:179
CloakState cloak
If the unit is cloaked.
Definition: sc2_unit.h:133
A list of enums provided for your convenience.
float shield
The shield of the unit in the transport.
Definition: sc2_unit.h:47
float shield_max
The max possible shield of the unit in the transport.
Definition: sc2_unit.h:49
float health
Health of the unit. Not set for snapshots.
Definition: sc2_unit.h:150
float radar_range
Range of radar for units that are radar units.
Definition: sc2_unit.h:138
UnitTypeID unit_type
The type of unit in the transport.
Definition: sc2_unit.h:55
float facing
Direction the unit faces in radians (1 radian == 57.296 degrees)
Definition: sc2_unit.h:126
A passenger on a transport.
Definition: sc2_unit.h:39
float progress
Progress of the order.
Definition: sc2_unit.h:29
int ideal_harvesters
Number of harvesters that can be assigned to a town hall (e.g., Command Center). Only valid for this ...
Definition: sc2_unit.h:187
int cargo_space_taken
Number of cargo slots used in the transport. Only valid for this player's units.
Definition: sc2_unit.h:181
Tag target_unit_tag
Target unit of the order, if there is one.
Definition: sc2_unit.h:25
float energy
The energy of the unit in the transport.
Definition: sc2_unit.h:51
Definition: sc2_unit.h:223
float shield_max
Max shield of the unit. Not set for snapshots.
Definition: sc2_unit.h:156
Point3D pos
Position of the unit in the world.
Definition: sc2_unit.h:124
float build_progress
Gives progress under construction. Range: [0.0, 1.0]. 1.0 == finished.
Definition: sc2_unit.h:130
Tag add_on_tag
Add-on like a tech lab or reactor. Only valid for this player's units.
Definition: sc2_unit.h:177
float weapon_cooldown
Time remaining for a weapon on cooldown. Not set for snapshots.
Definition: sc2_unit.h:170
Types used in setting up a game.
float energy
Energy of the unit. Not set for snapshots.
Definition: sc2_unit.h:158
AbilityID ability_id
Ability ID that triggered the order.
Definition: sc2_unit.h:23
Point2D target_pos
Target position of the order, if there is one.
Definition: sc2_unit.h:27
An order that is active on a unit.
Definition: sc2_unit.h:21
Alliance alliance
Relationship of the unit to this player.
Definition: sc2_unit.h:114
int mineral_contents
Amount of minerals if the unit is a mineral field. Not set for snapshots.
Definition: sc2_unit.h:162
int32_t attack_upgrade_level
Level of weapon upgrades.
Definition: sc2_unit.h:201
std::vector< BuffID > buffs
Buffs on this unit. Only valid for this player's units.
Definition: sc2_unit.h:191
int32_t shield_upgrade_level
Level of shield upgrades.
Definition: sc2_unit.h:207
float shield
Shield of the unit. Not set for snapshots.
Definition: sc2_unit.h:154
int vespene_contents
Amount of vespene if the unit is a geyser. Not set for snapshots.
Definition: sc2_unit.h:164
float health_max
The max possible health of the unit in the transport.
Definition: sc2_unit.h:45
float health_max
Max health for the unit. Not set for snapshots.
Definition: sc2_unit.h:152
bool is_burrowed
If the unit is burrowed. Not set for snapshots.
Definition: sc2_unit.h:168
Tag engaged_target_tag
Target unit of a unit. Only valid for this player's units.
Definition: sc2_unit.h:189
bool is_flying
If the unit is flying. Not set for snapshots.
Definition: sc2_unit.h:166
int assigned_harvesters
Number of harvesters associated with a town hall (e.g., Command Center). Only valid for this player's...
Definition: sc2_unit.h:185
Definition: sc2_unit.h:215
float detect_range
Range of detector for detector units.
Definition: sc2_unit.h:136
bool is_powered
Whether the unit is powered by a pylon.
Definition: sc2_unit.h:193
int cargo_space_max
Number of cargo slots available for a transport. Only valid for this player's units.
Definition: sc2_unit.h:183
int32_t armor_upgrade_level
Level of armor upgrades.
Definition: sc2_unit.h:204
Tag tag
A unique identifier for the instance of a unit.
Definition: sc2_unit.h:117
bool is_selected
If the unit is in the current selection of the player.
Definition: sc2_unit.h:141
DisplayType display_type
If the unit is shown on screen or not.
Definition: sc2_unit.h:112
DisplayType
If the unit is shown on screen or not.
Definition: sc2_unit.h:73