Skip to content
Snippets Groups Projects
Commit 907971dd authored by Edvin Bergström's avatar Edvin Bergström
Browse files

Fixed target

parent cbe8af94
No related branches found
Tags 1.4
1 merge request!6Replays
......@@ -28,9 +28,8 @@ void define_replay_unit(py::module & m)
.def_property_readonly("is_valid", &ReplayUnit::isValid)
.def_property_readonly("is_training", &ReplayUnit::isTraining)
.def_property_readonly("is_blip", &ReplayUnit::isBlip)
// Has target and target crashes if the target died in the same frame
//.def_property_readonly("target", &ReplayUnit::getTarget)
//.def_property_readonly("has_target", &ReplayUnit::hasTarget)
.def_property_readonly("target", &ReplayUnit::getTarget)
.def_property_readonly("has_target", &ReplayUnit::hasTarget)
.def_property_readonly("max_hit_points", &ReplayUnit::getMaxHitPoints)
.def_property_readonly("progress", &ReplayUnit::getProgress)
.def_property_readonly("current_ability_id", &ReplayUnit::getCurrentAbilityID, "The AbilityID of currently used ability")
......
......@@ -6,9 +6,12 @@
void IDAReplayObserver::setUnits()
{
m_allUnits.clear();
m_allUnitsID.clear();
for (auto & unit : Observation()->GetUnits())
{
m_allUnits.push_back(ReplayUnit(unit, *this));
ReplayUnit replayUnit = ReplayUnit(unit, *this);
m_allUnits.push_back(replayUnit);
m_allUnitsID.insert(replayUnit.getID());
}
}
......@@ -45,7 +48,6 @@ void IDAReplayObserver::OnReplayUnitDestroyed(const ReplayUnit *)
void IDAReplayObserver::OnUnitCreated(const sc2::Unit * unit)
{
ReplayUnit unitInformation = ReplayUnit(unit, *this);
std::cout << "OnUnitCreated" << std::endl;
OnReplayUnitCreated(&unitInformation);
}
......@@ -56,7 +58,6 @@ void IDAReplayObserver::OnReplayUnitCreated(const ReplayUnit *)
void IDAReplayObserver::OnBuildingConstructionComplete(const sc2::Unit *unit)
{
ReplayUnit unitInformation = ReplayUnit(unit, *this);
std::cout << "OnBuildingConstructionComplete" << std::endl;
OnReplayUnitCreated(&unitInformation);
}
......@@ -64,8 +65,16 @@ void IDAReplayObserver::OnBuildingConstructionComplete(const sc2::Unit *unit)
ReplayUnit IDAReplayObserver::GetUnit(const CCUnitID tag) const
{
return ReplayUnit(Observation()->GetUnit(tag), *(IDAReplayObserver *)this);
{
return ReplayUnit(Observation()->GetUnit(tag), *(IDAReplayObserver *)this);
}
bool IDAReplayObserver::UnitExists(const CCUnitID tag) const
{
return m_allUnitsID.find(tag) != m_allUnitsID.end();
}
......
......@@ -12,6 +12,7 @@ class IDAReplayObserver : public sc2::ReplayObserver
{
void setUnits();
std::vector<ReplayUnit> m_allUnits;
std::set<CCUnitID> m_allUnitsID;
public:
IDAReplayObserver();
......@@ -26,6 +27,7 @@ public:
void OnBuildingConstructionComplete(const sc2::Unit*);
ReplayUnit GetUnit(const CCUnitID tag) const;
bool UnitExists(const CCUnitID tag) const;
const std::vector<ReplayUnit> & GetAllUnits() const;
CCRace GetPlayerRace(int player);
......
......@@ -22,23 +22,16 @@ ReplayUnit::ReplayUnit(const sc2::Unit * unit, IDAReplayObserver & replayObserve
bool ReplayUnit::hasTarget() const
{
BOT_ASSERT(isValid(), "Unit is not valid");
std::cout << "HAS TARGET" << std::endl;
if (getUnitPtr()->orders.size() > 0) {
if (getUnitPtr()->orders[0].target_unit_tag != NULL) {
CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
//The tag is for somereason a null tag
if (t_id == sc2::NullTag) {
return false;
// IDAReplayObserver checks if the unit with this tag still exists
if (m_replayObserver->UnitExists(t_id)){
// IDAReplayObserver finds the unit with this tag, and returns true if valid
return m_replayObserver->GetUnit(t_id).isValid();
}
std::cout << "1MID HAS TARGET" << std::endl;
std::cout << "2MID HAS TARGET" << std::endl;
std::cout << "valid" << m_replayObserver->GetUnit(t_id).getType() << std::endl;
std::cout << "AFTER" << std::endl;
// IDABot finds the unit with this tag, and returns true if valid
return m_replayObserver->GetUnit(t_id).isValid();
}
}
std::cout << "END HAS TARGET" << std::endl;
return false;
}
......@@ -52,18 +45,12 @@ ReplayUnit ReplayUnit::getTarget() const
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) {
std::cout << "nullTAG" << std::endl;
std::cout << "type " << sc2::UnitTypeToName(m_unit->unit_type) <<"pos " << getPosition().x << " x y "<< getPosition().y << ", id " << getID() << "player " << getPlayer() << std::endl;
std::cout << getUnitPtr()->orders.size() << std::endl;
return *this;
// Checks if the tag is a null tag or the unit have been removed
if (t_id != sc2::NullTag && m_replayObserver->UnitExists(t_id)){
// IDAReplayObserver finds the unit with this tag
return m_replayObserver->GetUnit(t_id);
}
// IDAReplayObserver finds the unit with this tag
return m_replayObserver->GetUnit(t_id);
}
ReplayUnit this_unit = ReplayUnit(m_unit, *m_replayObserver);
return this_unit;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment