Skip to content
Snippets Groups Projects
Commit deea9dde authored by Sopi (sofab194)'s avatar Sopi (sofab194)
Browse files

added has_target to unit

returns true if unit has target
parent ef7f04ae
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ void define_unit(py::module & m) ...@@ -27,6 +27,7 @@ void define_unit(py::module & m)
.def_property_readonly("is_training", &Unit::isTraining) .def_property_readonly("is_training", &Unit::isTraining)
.def_property_readonly("is_blip", &Unit::isBlip) .def_property_readonly("is_blip", &Unit::isBlip)
.def_property_readonly("target", &Unit::getTarget) .def_property_readonly("target", &Unit::getTarget)
.def_property_readonly("has_target", &Unit::hasTarget)
.def("stop", &Unit::stop) .def("stop", &Unit::stop)
.def("attack_unit", &Unit::attackUnit) .def("attack_unit", &Unit::attackUnit)
.def("attack_move", &Unit::attackMove) .def("attack_move", &Unit::attackMove)
......
...@@ -301,6 +301,7 @@ bool Unit::isConstructing(const UnitType & type) const ...@@ -301,6 +301,7 @@ bool Unit::isConstructing(const UnitType & type) const
Unit Unit::getTarget() const Unit Unit::getTarget() const
{ {
BOT_ASSERT(isValid(), "Unit is not valid"); BOT_ASSERT(isValid(), "Unit is not valid");
BOT_ASSERT(hasTarget(), "Unit has no target");
//if unit has order, check tag of target of first order //if unit has order, check tag of target of first order
if(getUnitPtr()->orders.size() > 0){ if(getUnitPtr()->orders.size() > 0){
...@@ -310,7 +311,24 @@ Unit Unit::getTarget() const ...@@ -310,7 +311,24 @@ Unit Unit::getTarget() const
return m_bot->GetUnit(t_id); return m_bot->GetUnit(t_id);
} }
return Unit(); //Unit* empty_unit = new Unit();
Unit this_unit = Unit(m_unit, *m_bot);
return this_unit;
}
bool Unit::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;
//let IDAbot find the unit with this tag
return m_bot->GetUnit(t_id).isValid();
}
}
return false;
} }
bool Unit::isBlip() const bool Unit::isBlip() const
......
...@@ -48,7 +48,8 @@ public: ...@@ -48,7 +48,8 @@ public:
bool isConstructing(const UnitType & type) const; bool isConstructing(const UnitType & type) const;
bool isBlip() const; bool isBlip() const;
Unit getTarget() const; bool hasTarget() const;
Unit getTarget() const;
void stop () const; void stop () const;
void attackUnit (const Unit & target) const; void attackUnit (const Unit & target) const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment