From d4ae9862751333d3e1ac22156c9abdc71c5ce0ae Mon Sep 17 00:00:00 2001 From: sofab194 <sofab194@student.liu.se> Date: Tue, 27 Nov 2018 16:55:43 +0100 Subject: [PATCH] Added access to unit movement speed and max health --- python-api-src/lib_unit.cpp | 1 + python-api-src/lib_unittype.cpp | 1 + python-api-src/library.cpp | 2 +- src/Unit.cpp | 6 ++++++ src/Unit.h | 1 + src/UnitType.cpp | 5 +++++ src/UnitType.h | 2 ++ 7 files changed, 17 insertions(+), 1 deletion(-) diff --git a/python-api-src/lib_unit.cpp b/python-api-src/lib_unit.cpp index 0462c8d..5102648 100644 --- a/python-api-src/lib_unit.cpp +++ b/python-api-src/lib_unit.cpp @@ -28,6 +28,7 @@ void define_unit(py::module & m) .def_property_readonly("is_blip", &Unit::isBlip) .def_property_readonly("target", &Unit::getTarget) .def_property_readonly("has_target", &Unit::hasTarget) + .def_property_readonly("max_hit_points", &Unit::getMaxHitPoints) .def("stop", &Unit::stop) .def("attack_unit", &Unit::attackUnit) .def("attack_move", &Unit::attackMove) diff --git a/python-api-src/lib_unittype.cpp b/python-api-src/lib_unittype.cpp index 935b58c..35313de 100644 --- a/python-api-src/lib_unittype.cpp +++ b/python-api-src/lib_unittype.cpp @@ -10,6 +10,7 @@ void define_unittype(py::module & m) .def_property_readonly("unit_typeid", [](UnitType & unit_type) { return static_cast<sc2::UNIT_TYPEID>(unit_type.getAPIUnitType()); }) .def_property_readonly("name", &UnitType::getName) .def_property_readonly("race", &UnitType::getRace) + .def_property_readonly("movement_speed", &UnitType::getMovementSpeed) .def_property_readonly("is_valid", &UnitType::isValid) .def_property_readonly("is_building", &UnitType::isBuilding) .def_property_readonly("is_combat_unit", &UnitType::isCombatUnit, "The unit is not any of the following: worker, supply provider, building, larva, egg") diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 7d88337..721ad62 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -75,7 +75,7 @@ PYBIND11_MODULE(library, m) .def_property_readonly("map_tools", &IDABot::Map) .def_property_readonly("building_placer", &IDABot::GetBuildingPlacer) .def_property_readonly("start_location", &IDABot::GetStartLocation, "CCPosition representing the start location") - .def_property_readonly("start_locations", &IDABot::GetStartLocations, "CCPosition representing the start locations") + .def_property_readonly("start_locations", &IDABot::GetStartLocations, "CCPosition representing the start locations") .def_property_readonly("minerals", &IDABot::GetMinerals, "How much minerals we currently have") .def_property_readonly("current_supply", &IDABot::GetCurrentSupply, "How much supply we are currently using") .def_property_readonly("max_supply", &IDABot::GetMaxSupply, "How much supply we can currently use") diff --git a/src/Unit.cpp b/src/Unit.cpp index 4c62902..15277c8 100644 --- a/src/Unit.cpp +++ b/src/Unit.cpp @@ -339,3 +339,9 @@ bool Unit::isBlip() const return m_unit->isBlip(); #endif } + +CCHealth Unit::getMaxHitPoints() const +{ + BOT_ASSERT(isValid(), "Unit is not valid"); + return m_unit->health_max; +} \ No newline at end of file diff --git a/src/Unit.h b/src/Unit.h index 0872d7b..f9c51a7 100644 --- a/src/Unit.h +++ b/src/Unit.h @@ -50,6 +50,7 @@ public: bool isBlip() const; bool hasTarget() const; Unit getTarget() const; + CCHealth getMaxHitPoints() const; void stop () const; void attackUnit (const Unit & target) const; diff --git a/src/UnitType.cpp b/src/UnitType.cpp index b3478af..2ace51f 100644 --- a/src/UnitType.cpp +++ b/src/UnitType.cpp @@ -372,3 +372,8 @@ bool UnitType::isMorphedBuilding() const m_type == BWAPI::UnitTypes::Zerg_Greater_Spire; #endif } + +int UnitType::getMovementSpeed() const +{ + return m_bot->Observation()->GetUnitTypeData()[m_type].movement_speed; +} diff --git a/src/UnitType.h b/src/UnitType.h index b3458fa..8f9d975 100644 --- a/src/UnitType.h +++ b/src/UnitType.h @@ -22,6 +22,8 @@ public: std::string getName() const; CCRace getRace() const; + + int getMovementSpeed() const; bool isValid() const; bool isBuilding() const; -- GitLab