From 3f99ff86310a367a461a12d0ebe96c757f6aaa47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20J=C3=A4mtner?= <hanja189@student.liu.se> Date: Fri, 10 Jul 2020 15:49:15 +0200 Subject: [PATCH] Added the functions for unit and IDABot --- python-api-src/lib_unit.cpp | 4 +++- python-api-src/library.cpp | 2 ++ src/IDABot.cpp | 7 +++++++ src/IDABot.h | 3 +++ src/Unit.cpp | 14 +++++++++++++- src/Unit.h | 4 +++- 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/python-api-src/lib_unit.cpp b/python-api-src/lib_unit.cpp index efc4802da..dbb4c017a 100644 --- a/python-api-src/lib_unit.cpp +++ b/python-api-src/lib_unit.cpp @@ -35,7 +35,9 @@ void define_unit(py::module & m) .def_property_readonly("facing", &Unit::getFacing) .def_property_readonly("radius", &Unit::getRadius) .def_property_readonly("is_carrying_minerals", &Unit::isCarryingMinerals) - .def_property_readonly("gas_left_in_refinery", &Unit::gasLeftInRefinery) + .def_property_readonly("gas_left_in_refinery", &Unit::gasLeftInGeyser) + .def_property_readonly("minerals_left_in_mineralfield", &Unit::mineralsLeftInMineralfield) + .def_property_readonly("owner", &Unit::getOwner) .def("hold_position", &Unit::holdPosition) .def("patrol", py::overload_cast<const CCPosition &>(&Unit::patrol, py::const_)) .def("stop_dance", &Unit::stopDance) diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 2aa1198cb..832d9f534 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -94,6 +94,8 @@ PYBIND11_MODULE(library, m) .def("debug_set_life", &IDABot::DebugSetLife, "Set the life on a unit through debug mode") .def("debug_set_shield", &IDABot::DebugSetShields, "Set the shields on a unit through debug mode") .def("get_enemy_base_location", &IDABot::GetEnemyBaseLocations, "Return the CCpostion of the enemy base") + .def("move_camera", &IDABot::CameraMove, "Move the camera to p postion", "p"_a) + .def("has_creep", &IDABot::HasCreep, "Returns true if there is creep at position p", "p"_a) .def_property_readonly("base_location_manager", &IDABot::Bases) .def_property_readonly("tech_tree", &IDABot::GetTechTree) .def_property_readonly("map_tools", &IDABot::Map) diff --git a/src/IDABot.cpp b/src/IDABot.cpp index 4331f5e84..2e4ae3908 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -339,3 +339,10 @@ const std::vector<Point2D> IDABot::GetEnemyBaseLocations() return Observation()->GetGameInfo().enemy_start_locations; } +bool IDABot::HasCreep(Point2D p) const { + return Observation()->HasCreep(p); +} + +void IDABot::CameraMove(Point2DI p) { + ActionsFeatureLayer()->CameraMove(p); +} \ No newline at end of file diff --git a/src/IDABot.h b/src/IDABot.h index 01bb6062f..7fba6b34f 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -16,6 +16,7 @@ using sc2::UnitTypeID; using sc2::Point2D; +using sc2::Point2DI; class IDABot : public sc2::Agent { @@ -86,6 +87,8 @@ public: void DebugSetLife(float value, const Unit unit); void DebugSetShields(float value, const Unit unit); const std::vector<Point2D> GetEnemyBaseLocations(); + bool HasCreep(Point2D p) const; + void CameraMove(Point2DI p); // Not needed, just convenience functions diff --git a/src/Unit.cpp b/src/Unit.cpp index 8d833317e..04d80c681 100644 --- a/src/Unit.cpp +++ b/src/Unit.cpp @@ -440,8 +440,20 @@ bool Unit::isCarryingMinerals() const return false; } -int Unit::gasLeftInRefinery() const +int Unit::gasLeftInGeyser() const { BOT_ASSERT(isValid(), "Unit is not valid"); return m_unit->vespene_contents; } + +int Unit::mineralsLeftInMineralfield() const +{ + BOT_ASSERT(isValid(), "Unit is not valid"); + return m_unit->mineral_contents; +} + +int Unit::getOwner() const +{ + BOT_ASSERT(isValid(), "Unit is not valid"); + return m_unit->owner; +} diff --git a/src/Unit.h b/src/Unit.h index 874c36f2f..2275b2ca5 100644 --- a/src/Unit.h +++ b/src/Unit.h @@ -64,7 +64,9 @@ public: /* API extended summer 2020 */ - int gasLeftInRefinery() const; + int gasLeftInGeyser() const; + int mineralsLeftInMineralfield() const; + int getOwner() const; void stop () const; -- GitLab