-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathUnitData.h
73 lines (58 loc) · 1.64 KB
/
UnitData.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "Common.h"
#include "Util.h"
#include "Unit.h"
#include "UnitType.h"
struct UnitInfo
{
// we need to store all of this data because if the unit is not visible, we
// can't reference it from the unit pointer
CCUnitID id;
CCHealth lastHealth;
CCHealth lastShields;
CCPlayer player;
Unit unit;
CCPosition lastPosition;
UnitType type;
float progress;
UnitInfo()
: id(0)
, lastHealth(0)
, player(-1)
, lastPosition(0, 0)
, progress(1.0)
{
}
bool operator == (const Unit & unit) const
{
return id == unit.getID();
}
bool operator == (const UnitInfo & rhs) const
{
return (id == rhs.id);
}
bool operator < (const UnitInfo & rhs) const
{
return (id < rhs.id);
}
};
typedef std::vector<UnitInfo> UnitInfoVector;
class UnitData
{
std::map<Unit, UnitInfo> m_unitMap;
std::map<UnitType, int> m_numDeadUnits;
std::map<UnitType, int> m_numUnits;
int m_mineralsLost;
int m_gasLost;
bool badUnitInfo(const UnitInfo & ui) const;
public:
UnitData();
void updateUnit(const Unit & unit);
void killUnit(const Unit & unit);
void removeBadUnits();
int getGasLost() const;
int getMineralsLost() const;
int getNumUnits(const UnitType & t) const;
int getNumDeadUnits(const UnitType & t) const;
const std::map<Unit, UnitInfo> & getUnitInfoMap() const;
};