Newer
Older
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "MetaType.h"
#include "Util.h"
#include "IDABot.h"
MetaType::MetaType()
: m_bot (nullptr)
, m_type (MetaTypes::None)
, m_name ("MetaType")
, m_unitType ()
, m_upgrade ()
{
}
#ifdef SC2API
MetaType::MetaType(const std::string & name, IDABot & bot)
: MetaType()
{
m_bot = ⊥
m_name = name;
m_unitType = UnitType::GetUnitTypeFromName(m_name, bot);
if (m_unitType.isValid())
{
m_type = MetaTypes::Unit;
return;
}
for (const sc2::UpgradeData & data : bot.Observation()->GetUpgradeData())
{
if (name == data.name)
{
m_upgrade = data.upgrade_id;
m_type = MetaTypes::Upgrade;
return;
}
}
BOT_ASSERT(false, "Could not find MetaType with name: %s", name.c_str());
}
#else
MetaType::MetaType(const std::string & name, IDABot & bot)
: MetaType()
{
m_bot = ⊥
std::string inputName(name);
std::replace(inputName.begin(), inputName.end(), '_', ' ');
for (const BWAPI::UnitType & unitType : BWAPI::UnitTypes::allUnitTypes())
{
// check to see if the names match exactly
std::string typeName = unitType.getName();
std::replace(typeName.begin(), typeName.end(), '_', ' ');
if (typeName == inputName)
{
*this = MetaType(UnitType(unitType, bot), bot);
return;
}
// check to see if the names match without the race prefix
const std::string & raceName = unitType.getRace().getName();
if ((typeName.length() > raceName.length()) && (typeName.compare(raceName.length() + 1, typeName.length(), inputName) == 0))
{
*this = MetaType(UnitType(unitType, bot), bot);
return;
}
}
for (const BWAPI::TechType & techType : BWAPI::TechTypes::allTechTypes())
{
std::string typeName = techType.getName();
std::replace(typeName.begin(), typeName.end(), '_', ' ');
if (typeName == inputName)
{
*this = MetaType(techType, bot);
return;
}
}
for (const BWAPI::UpgradeType & upgradeType : BWAPI::UpgradeTypes::allUpgradeTypes())
{
std::string typeName = upgradeType.getName();
std::replace(typeName.begin(), typeName.end(), '_', ' ');
if (typeName == inputName)
{
*this = MetaType(upgradeType, bot);
return;
}
}
BOT_ASSERT(false, "Could not find MetaType with name: %s", name.c_str());
}
MetaType::MetaType(const BWAPI::TechType & t, IDABot & bot)
: m_tech(t)
, m_type(MetaTypes::Tech)
, m_race(t.getRace())
, m_name(t.getName())
, m_bot(&bot)
{
}
#endif
MetaType::MetaType(const UnitType & unitType, IDABot & bot)
{
m_bot = ⊥
m_type = MetaTypes::Unit;
m_unitType = unitType;
m_race = unitType.getRace();
m_name = unitType.getName();
}
MetaType::MetaType(const CCUpgrade & upgradeType, IDABot & bot)
{
m_bot = ⊥
m_type = MetaTypes::Upgrade;
m_upgrade = upgradeType;
#ifdef SC2API
m_race = m_bot->GetPlayerRace(Players::Self);
m_name = sc2::UpgradeIDToName(upgradeType);
#else
m_race = upgradeType.getRace();
m_name = upgradeType.getName();
#endif
}
bool MetaType::isBuilding() const
{
return isUnit() && getUnitType().isBuilding();
}
const size_t & MetaType::getMetaType() const
{
return m_type;
}
bool MetaType::isUnit() const
{
return m_type == MetaTypes::Unit;
}
bool MetaType::isUpgrade() const
{
return m_type == MetaTypes::Upgrade;
}
bool MetaType::isTech() const
{
return m_type == MetaTypes::Tech;
}
const CCRace & MetaType::getRace() const
{
return m_race;
}
const UnitType & MetaType::getUnitType() const
{
return m_unitType;
}
const CCUpgrade & MetaType::getUpgrade() const
{
return m_upgrade;
}
const std::string & MetaType::getName() const
{
return m_name;
}
#ifndef SC2API
const BWAPI::TechType & MetaType::getTechType() const
{
return m_tech;
}
#endif