Skip to content
Snippets Groups Projects
Commit 7ea8c3ee authored by Rojikku98's avatar Rojikku98
Browse files

Some cleanup

parent e6b395c0
No related branches found
No related tags found
1 merge request!6Replays
...@@ -4,41 +4,41 @@ namespace py = pybind11; ...@@ -4,41 +4,41 @@ namespace py = pybind11;
void define_replay_unit(py::module & m) void define_replay_unit(py::module & m)
{ {
py::class_<UnitInformation>(m, "ReplayUnit") py::class_<ReplayUnit>(m, "ReplayUnit")
.def_property_readonly("id", &UnitInformation::getID) .def_property_readonly("id", &ReplayUnit::getID)
.def_property_readonly("unit_type", &UnitInformation::getType, "The id of the type") .def_property_readonly("unit_type", &ReplayUnit::getType, "The id of the type")
.def_property_readonly("unit_type_name", &UnitInformation::getTypeName, "The name of the type") .def_property_readonly("unit_type_name", &ReplayUnit::getTypeName, "The name of the type")
.def_property_readonly("position", &UnitInformation::getPosition, "The :class:`library.Point2D` of the unit") .def_property_readonly("position", &ReplayUnit::getPosition, "The :class:`library.Point2D` of the unit")
.def_property_readonly("tile_position", &UnitInformation::getTilePosition, "The :class:`library.Point2DI` of the unit") .def_property_readonly("tile_position", &ReplayUnit::getTilePosition, "The :class:`library.Point2DI` of the unit")
.def_property_readonly("hit_points", &UnitInformation::getHitPoints) .def_property_readonly("hit_points", &ReplayUnit::getHitPoints)
.def_property_readonly("shields", &UnitInformation::getShields) .def_property_readonly("shields", &ReplayUnit::getShields)
.def_property_readonly("energy", &UnitInformation::getEnergy) .def_property_readonly("energy", &ReplayUnit::getEnergy)
.def_property_readonly("player", &UnitInformation::getPlayer) .def_property_readonly("player", &ReplayUnit::getPlayer)
.def_property_readonly("build_percentage", &UnitInformation::getBuildPercentage) .def_property_readonly("build_percentage", &ReplayUnit::getBuildPercentage)
.def_property_readonly("weapon_cooldown", &UnitInformation::getWeaponCooldown) .def_property_readonly("weapon_cooldown", &ReplayUnit::getWeaponCooldown)
.def_property_readonly("is_completed", &UnitInformation::isCompleted) .def_property_readonly("is_completed", &ReplayUnit::isCompleted)
.def_property_readonly("is_being_constructed", &UnitInformation::isBeingConstructed) .def_property_readonly("is_being_constructed", &ReplayUnit::isBeingConstructed)
.def_property_readonly("is_cloaked", &UnitInformation::isCloaked) .def_property_readonly("is_cloaked", &ReplayUnit::isCloaked)
.def_property_readonly("is_flying", &UnitInformation::isFlying) .def_property_readonly("is_flying", &ReplayUnit::isFlying)
.def_property_readonly("buffs", &UnitInformation::buffs) .def_property_readonly("buffs", &ReplayUnit::buffs)
.def_property_readonly("is_alive", &UnitInformation::isAlive) .def_property_readonly("is_alive", &ReplayUnit::isAlive)
.def_property_readonly("is_powered", &UnitInformation::isPowered) .def_property_readonly("is_powered", &ReplayUnit::isPowered)
.def_property_readonly("is_idle", &UnitInformation::isIdle) .def_property_readonly("is_idle", &ReplayUnit::isIdle)
.def_property_readonly("is_burrowed", &UnitInformation::isBurrowed) .def_property_readonly("is_burrowed", &ReplayUnit::isBurrowed)
.def_property_readonly("is_valid", &UnitInformation::isValid) .def_property_readonly("is_valid", &ReplayUnit::isValid)
.def_property_readonly("is_training", &UnitInformation::isTraining) .def_property_readonly("is_training", &ReplayUnit::isTraining)
.def_property_readonly("is_blip", &UnitInformation::isBlip) .def_property_readonly("is_blip", &ReplayUnit::isBlip)
// Has target and target crashes if the target died in the same frame // Has target and target crashes if the target died in the same frame
//.def_property_readonly("target", &UnitInformation::getTarget) //.def_property_readonly("target", &ReplayUnit::getTarget)
//.def_property_readonly("has_target", &UnitInformation::hasTarget) //.def_property_readonly("has_target", &ReplayUnit::hasTarget)
.def_property_readonly("max_hit_points", &UnitInformation::getMaxHitPoints) .def_property_readonly("max_hit_points", &ReplayUnit::getMaxHitPoints)
.def_property_readonly("progress", &UnitInformation::getProgress) .def_property_readonly("progress", &ReplayUnit::getProgress)
.def_property_readonly("current_ability_id", &UnitInformation::getCurrentAbilityID, "The AbilityID of currently used ability") .def_property_readonly("current_ability_id", &ReplayUnit::getCurrentAbilityID, "The AbilityID of currently used ability")
.def_property_readonly("facing", &UnitInformation::getFacing) .def_property_readonly("facing", &ReplayUnit::getFacing)
.def_property_readonly("radius", &UnitInformation::getRadius) .def_property_readonly("radius", &ReplayUnit::getRadius)
.def_property_readonly("is_carrying_minerals", &UnitInformation::isCarryingMinerals) .def_property_readonly("is_carrying_minerals", &ReplayUnit::isCarryingMinerals)
.def("__hash__", [](const UnitInformation & unit) { return std::hash<const sc2::Unit *>{}(unit.getUnitPtr()); }) .def("__hash__", [](const ReplayUnit & unit) { return std::hash<const sc2::Unit *>{}(unit.getUnitPtr()); })
.def(py::self == py::self) .def(py::self == py::self)
.def("__repr__", [](const UnitInformation & unit) { return "<Unit of type: '" + unit.getTypeName() + "'>"; }) .def("__repr__", [](const ReplayUnit & unit) { return "<Unit of type: '" + unit.getTypeName() + "'>"; })
; ;
} }
...@@ -99,7 +99,6 @@ PYBIND11_MODULE(library, m) ...@@ -99,7 +99,6 @@ PYBIND11_MODULE(library, m)
.def("on_step", &IDAReplayObserver::OnStep) .def("on_step", &IDAReplayObserver::OnStep)
.def("on_game_end", &IDAReplayObserver::OnGameEnd) .def("on_game_end", &IDAReplayObserver::OnGameEnd)
.def("get_all_units", &IDAReplayObserver::GetAllUnits, "Returns a list of all units") .def("get_all_units", &IDAReplayObserver::GetAllUnits, "Returns a list of all units")
.def("on_unit_destroyed", &IDAReplayObserver::OnUnitInfomationDestroyed, "unit"_a)
; ;
py::class_<sc2::PlayerSetup>(m, "PlayerSetup"); py::class_<sc2::PlayerSetup>(m, "PlayerSetup");
......
...@@ -3,14 +3,11 @@ ...@@ -3,14 +3,11 @@
void IDAReplayObserver::setUnits() void IDAReplayObserver::setUnits()
{ {
m_allUnits.clear(); m_allUnits.clear();
for (auto & unit : Observation()->GetUnits()) for (auto & unit : Observation()->GetUnits())
{ {
m_allUnits.push_back(UnitInformation(unit, *this)); m_allUnits.push_back(ReplayUnit(unit, *this));
} }
} }
IDAReplayObserver::IDAReplayObserver(): IDAReplayObserver::IDAReplayObserver():
...@@ -20,10 +17,7 @@ IDAReplayObserver::IDAReplayObserver(): ...@@ -20,10 +17,7 @@ IDAReplayObserver::IDAReplayObserver():
void IDAReplayObserver::OnGameStart() void IDAReplayObserver::OnGameStart()
{ {
setUnits(); setUnits();
} }
void IDAReplayObserver::OnStep() void IDAReplayObserver::OnStep()
...@@ -37,21 +31,19 @@ void IDAReplayObserver::OnGameEnd() ...@@ -37,21 +31,19 @@ void IDAReplayObserver::OnGameEnd()
void IDAReplayObserver::OnUnitDestroyed(const sc2::Unit* unit) void IDAReplayObserver::OnUnitDestroyed(const sc2::Unit* unit)
{ {
UnitInformation unitInformation = UnitInformation(unit, *this); ReplayUnit unitInformation = ReplayUnit(unit, *this);
OnUnitInfomationDestroyed(&unitInformation); OnUnitInfomationDestroyed(&unitInformation);
} }
void IDAReplayObserver::OnUnitInfomationDestroyed(const ReplayUnit *)
{
}
UnitInformation IDAReplayObserver::GetUnit(const CCUnitID tag) const ReplayUnit IDAReplayObserver::GetUnit(const CCUnitID tag) const
{ {
std::cout << tag << std::endl; return ReplayUnit(Observation()->GetUnit(tag), *(IDAReplayObserver *)this);
if (tag == 0) {
std::cout << "TAG == 0" << std::endl;
}
UnitInformation(Observation()->GetUnit(tag), *(IDAReplayObserver *)this);
std::cout << "OK" << std::endl;
return UnitInformation(Observation()->GetUnit(tag), *(IDAReplayObserver *)this);
} }
...@@ -59,7 +51,7 @@ UnitInformation IDAReplayObserver::GetUnit(const CCUnitID tag) const ...@@ -59,7 +51,7 @@ UnitInformation IDAReplayObserver::GetUnit(const CCUnitID tag) const
const std::vector<UnitInformation>& IDAReplayObserver::GetAllUnits() const const std::vector<ReplayUnit>& IDAReplayObserver::GetAllUnits() const
{ {
return m_allUnits; return m_allUnits;
......
...@@ -4,33 +4,27 @@ ...@@ -4,33 +4,27 @@
#include <limits> #include <limits>
#include "Common.h" #include "Common.h"
#include "UnitInformation.h" #include "ReplayUnit.h"
class UnitInformation; class ReplayUnit;
class IDAReplayObserver : public sc2::ReplayObserver class IDAReplayObserver : public sc2::ReplayObserver
{ {
void setUnits(); void setUnits();
std::vector<UnitInformation> m_allUnits; std::vector<ReplayUnit> m_allUnits;
public: public:
IDAReplayObserver(); IDAReplayObserver();
void OnGameStart() override; void OnGameStart() override;
void OnStep() override; void OnStep() override;
void OnGameEnd() override; void OnGameEnd() override;
void OnUnitDestroyed(const sc2::Unit*) override; void OnUnitDestroyed(const sc2::Unit*) override;
virtual void OnUnitInfomationDestroyed(const UnitInformation*); void OnUnitInfomationDestroyed(const ReplayUnit*);
UnitInformation GetUnit(const CCUnitID tag) const;
ReplayUnit GetUnit(const CCUnitID tag) const;
const std::vector<UnitInformation> & GetAllUnits() const; const std::vector<ReplayUnit> & GetAllUnits() const;
}; };
#include "UnitInformation.h" #include "ReplayUnit.h"
UnitInformation::UnitInformation(const sc2::Unit * unit, IDAReplayObserver & replayObserver) ReplayUnit::ReplayUnit(const sc2::Unit * unit, IDAReplayObserver & replayObserver)
: m_replayObserver(&replayObserver), Unit(unit) : m_replayObserver(&replayObserver), Unit(unit)
{ {
} }
std::string UnitInformation::getType() const std::string ReplayUnit::getType() const
{ {
return m_unit->unit_type.to_string(); return m_unit->unit_type.to_string();
} }
std::string UnitInformation::getTypeName() const std::string ReplayUnit::getTypeName() const
{ {
return sc2::UnitTypeToName(m_unit->unit_type); return sc2::UnitTypeToName(m_unit->unit_type);
} }
bool UnitInformation::hasTarget() const bool ReplayUnit::hasTarget() const
{ {
BOT_ASSERT(isValid(), "Unit is not valid"); BOT_ASSERT(isValid(), "Unit is not valid");
std::cout << "HAS TARGET" << std::endl; std::cout << "HAS TARGET" << std::endl;
...@@ -43,7 +43,7 @@ bool UnitInformation::hasTarget() const ...@@ -43,7 +43,7 @@ bool UnitInformation::hasTarget() const
return false; return false;
} }
UnitInformation UnitInformation::getTarget() const ReplayUnit ReplayUnit::getTarget() const
{ {
BOT_ASSERT(isValid(), "Unit is not valid"); BOT_ASSERT(isValid(), "Unit is not valid");
...@@ -64,7 +64,7 @@ UnitInformation UnitInformation::getTarget() const ...@@ -64,7 +64,7 @@ UnitInformation UnitInformation::getTarget() const
return m_replayObserver->GetUnit(t_id); return m_replayObserver->GetUnit(t_id);
} }
UnitInformation this_unit = UnitInformation(m_unit, *m_replayObserver); ReplayUnit this_unit = ReplayUnit(m_unit, *m_replayObserver);
return this_unit; return this_unit;
} }
......
...@@ -4,18 +4,17 @@ ...@@ -4,18 +4,17 @@
class IDAReplayObserver; class IDAReplayObserver;
class UnitInformation: public Unit //! A Unit that have a replayobserver insted of an Agent,
class ReplayUnit: public Unit
{ {
mutable IDAReplayObserver * m_replayObserver; mutable IDAReplayObserver * m_replayObserver;
public: public:
UnitInformation(const sc2::Unit * unit, IDAReplayObserver & replayObserver); ReplayUnit(const sc2::Unit * unit, IDAReplayObserver & replayObserver);
std::string getType() const; std::string getType() const;
std::string getTypeName() const; std::string getTypeName() const;
bool hasTarget() const; bool hasTarget() const;
UnitInformation getTarget() const; ReplayUnit getTarget() const;
}; };
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment