Newer
Older
#include "UnitInformation.h"
UnitInformation::UnitInformation(const sc2::Unit * unit, IDAReplayObserver & replayObserver)
: m_replayObserver(&replayObserver), Unit(unit)
{
}
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
std::string UnitInformation::getType() const
{
return m_unit->unit_type.to_string();
}
bool UnitInformation::hasTarget() const
{
BOT_ASSERT(isValid(), "Unit is not valid");
if (getUnitPtr()->orders.size() > 0) {
if (getUnitPtr()->orders[0].target_unit_tag != NULL) {
CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
// IDABot finds the unit with this tag, and returns true if valid
return m_replayObserver->GetUnit(t_id).isValid();
}
}
return false;
}
UnitInformation UnitInformation::getTarget() const
{
BOT_ASSERT(isValid(), "Unit is not valid");
// if unit has order, check tag of target of first order
if (getUnitPtr()->orders.size() > 0) {
// t_id is set to the unit tag of the target
CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
//The tag is for somereason a null tag
if (t_id == sc2::NullTag) {
return *this;
}
// IDAReplayObserver finds the unit with this tag
return m_replayObserver->GetUnit(t_id);
}
UnitInformation this_unit = UnitInformation(m_unit, *m_replayObserver);
return this_unit;
}