diff --git a/python-api-src/lib_unit.cpp b/python-api-src/lib_unit.cpp index e796c3012e9888b20af605a039c669ca283073b1..fd39b5d47cb03704926e0493c7f573c2e7d97873 100644 --- a/python-api-src/lib_unit.cpp +++ b/python-api-src/lib_unit.cpp @@ -26,6 +26,10 @@ void define_unit(py::module & m) .def_property_readonly("is_burrowed", &Unit::isBurrowed) .def_property_readonly("is_valid", &Unit::isValid) .def_property_readonly("is_training", &Unit::isTraining) + .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 935b58c10987e186929d577122dd572791011f7d..0946c514cea674458340ac6f0c6163c7176c4f2b 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") @@ -43,4 +44,4 @@ void define_unittype(py::module & m) // Not implemented in CommandCenter //.def("whatBuilds", &UnitType::whatBuilds); -} \ No newline at end of file +} diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 4ba7a80114fed03f05b7b19b90cad63a29486926..dd1bc0cfd0cd945da04754358c7214bfcd48b487 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -82,10 +82,12 @@ 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("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") - .def_property_readonly("gas", &IDABot::GetGas, "How much gas we currently have"); + .def_property_readonly("gas", &IDABot::GetGas, "How much gas we currently have") + .def_property_readonly("current_frame", &IDABot::GetCurrentFrame, "Which frame we are currently on"); py::class_<sc2::PlayerSetup>(m, "PlayerSetup"); diff --git a/src/Unit.cpp b/src/Unit.cpp index 5d5ec6c8850b9906531ba8aae091e46c1a4e94b6..b75c051fe0f44cbd945aa70210e4aa8f01db1e16 100644 --- a/src/Unit.cpp +++ b/src/Unit.cpp @@ -322,3 +322,51 @@ void Unit::ability(sc2::AbilityID ability, const Unit& target) const { m_bot->Actions()->UnitCommand(getUnitPtr(), ability, target.getUnitPtr(), false); } + +Unit Unit::getTarget() const +{ + 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(getUnitPtr()->orders.size() > 0){ + // t_id is set to the unit tag of the target + CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag; + // IDABot finds the unit with this tag + return m_bot->GetUnit(t_id); + } + + 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; + // IDABot finds the unit with this tag, and returns true if valid + return m_bot->GetUnit(t_id).isValid(); + } + } + + return false; +} + +bool Unit::isBlip() const +{ + BOT_ASSERT(isValid(), "Unit is not valid"); +#ifdef SC2API + return m_unit->is_blip; +#else + return m_unit->isBlip(); +#endif +} + +CCHealth Unit::getMaxHitPoints() const +{ + BOT_ASSERT(isValid(), "Unit is not valid"); + return m_unit->health_max; +} diff --git a/src/Unit.h b/src/Unit.h index 474428540635813596008cb9186a8db13b48c9f4..70c1aa8ed15bc72b6ba09caef68048237915c56e 100644 --- a/src/Unit.h +++ b/src/Unit.h @@ -48,6 +48,11 @@ public: bool isTraining() const; bool isConstructing(const UnitType & type) const; + bool isBlip() const; + bool hasTarget() const; + Unit getTarget() const; + CCHealth getMaxHitPoints() const; + void stop () const; void attackUnit (const Unit & target) const; void attackMove (const CCPosition & targetPosition) const; diff --git a/src/UnitType.cpp b/src/UnitType.cpp index b3478af36a9064436d90a89ddb3535312d3a87a7..2ace51fcb02044edfcb3c3209d94787526e3962b 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 b3458fa83d65b6ca3316b29db1327efcb765c4b1..6c8d04347c8ea5a8d9de52a851aa3c419ad0bbc9 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;