forked from yanntm/YoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitData.cpp
93 lines (80 loc) · 1.67 KB
/
UnitData.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "UnitData.h"
#include "Util.h"
UnitData::UnitData()
: m_mineralsLost(0)
, m_gasLost(0)
{
const int maxTypeID = 1024;
m_numDeadUnits = std::vector<int>(maxTypeID + 1, 0);
m_numUnits = std::vector<int>(maxTypeID + 1, 0);
}
void UnitData::updateUnit(const sc2::Unit * unit)
{
bool firstSeen = false;
const auto & it = m_unitMap.find(unit);
if (it == m_unitMap.end())
{
firstSeen = true;
m_unitMap[unit] = UnitInfo();
}
UnitInfo & ui = m_unitMap[unit];
ui.unit = unit;
ui.player = Util::GetPlayer(unit);
ui.lastPosition = unit->pos;
ui.lastHealth = unit->health;
ui.lastShields = unit->shield;
ui.tag = unit->tag;
ui.type = unit->unit_type;
ui.progress = unit->build_progress;
if (firstSeen)
{
m_numUnits[ui.type]++;
}
}
void UnitData::killUnit(const sc2::Unit * unit)
{
//_mineralsLost += unit->getType().mineralPrice();
//_gasLost += unit->getType().gasPrice();
m_numUnits[unit->unit_type]--;
m_numDeadUnits[unit->unit_type]++;
m_unitMap.erase(unit);
}
void UnitData::removeBadUnits()
{
for (auto iter = m_unitMap.begin(); iter != m_unitMap.end();)
{
if (badUnitInfo(iter->second))
{
m_numUnits[iter->second.type]--;
iter = m_unitMap.erase(iter);
}
else
{
iter++;
}
}
}
bool UnitData::badUnitInfo(const UnitInfo & ui) const
{
return false;
}
int UnitData::getGasLost() const
{
return m_gasLost;
}
int UnitData::getMineralsLost() const
{
return m_mineralsLost;
}
int UnitData::getNumUnits(sc2::UnitTypeID t) const
{
return m_numUnits[t];
}
int UnitData::getNumDeadUnits(sc2::UnitTypeID t) const
{
return m_numDeadUnits[t];
}
const std::map<const sc2::Unit *, UnitInfo> & UnitData::getUnitInfoMap() const
{
return m_unitMap;
}