diff --git a/docs/helpers.rst b/docs/helpers.rst index 79e8e40a605b6c808f3de431015df570cc2201cd..7f57cd07c373eae8dd1d0fcfa4b6b3ee92101b5b 100644 --- a/docs/helpers.rst +++ b/docs/helpers.rst @@ -89,6 +89,9 @@ TechTree this can be found under the folder data in this link_. A recent file is included in the `template repository`_. + Instead of using TechTree, it's possible to use the functions in UnitType for + structure, etc. In IDABot there is functions for getting data about upgrades. + .. method:: get_data(argument) -> library.TypeData Argument is either an instance of the class :class:`library.UnitType` or diff --git a/docs/idabot.rst b/docs/idabot.rst index 714ed3cc33420599666992c423dfeb994e77d609..076123fcc4c464f2424a66db31c1f2c7727482be 100644 --- a/docs/idabot.rst +++ b/docs/idabot.rst @@ -67,6 +67,22 @@ IDABot Move the camera to the position + .. method:: IDABot.ability_for_upgrade(self, UpgradeID) + + Ability that researches this upgrade + + .. method:: IDABot.upgrade_mineral_cost(self, UpgradeID) + + Mineral cost of researching the upgrade + + .. method:: IDABot.upgrade_gas_cost(self, UpgradeID) + + Vespene/gas cost of researching the upgrade + + .. method:: IDABot.upgrade_research_time(self, UpgradeID) + + Time in GameLoops to research this upgrade + Attributes: .. autoattribute:: minerals diff --git a/python-api-src/lib_unittype.cpp b/python-api-src/lib_unittype.cpp index a5dcc01544e89c9ff41d95e27ab9193a7ee0837a..723f5e1f170076ff82ea437b25c77a14bf593ffd 100644 --- a/python-api-src/lib_unittype.cpp +++ b/python-api-src/lib_unittype.cpp @@ -40,6 +40,9 @@ void define_unittype(py::module & m) .def_property_readonly("is_egg", &UnitType::isEgg) .def_property_readonly("is_queen", &UnitType::isQueen) .def_property_readonly("is_tank", &UnitType::isTank) + .def_property_readonly("get_equivalent_units", &UnitType::getEquivalentUnits) + .def_property_readonly("required_attached", &UnitType::requiredAttached) + .def_property_readonly("build_time", &UnitType::getBuildTime) .def("__hash__", [](const UnitType & unit_type) { return std::hash<CCUnitID>{}(unit_type.getAPIUnitType()); }) .def(py::self == py::self) .def("__repr__", [](const UnitType & unit_type) { return "<UnitType: '" + unit_type.getName() + "'>"; }); diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 7278c8a6bd573454873609082421ef98eed3ed7e..77728c644fcac6dfe48038615c29cd19a48d5ead 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -99,6 +99,10 @@ PYBIND11_MODULE(library, m) .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("ability_for_upgrade", &IDABot::abilityForUpgrade, "Ability that researches this upgrade", "upgrade"_a) + .def("upgrade_mineral_cost", &IDABot::UpgradeMineralCost, "Mineral cost of researching the upgrade", "upgrade"_a) + .def("upgrade_gas_cost", &IDABot::UpgradeGasCost, "Vespene/gas cost of researching the upgrade", "upgrade"_a) + .def("upgrade_research_time", &IDABot::UpgradeResearchTime, "Time in GameLoops to research this upgrade", "upgrade"_a) .def_property_readonly("base_location_manager", &IDABot::Bases) .def_property_readonly("tech_tree", &IDABot::GetTechTree) .def_property_readonly("map_tools", &IDABot::Map) @@ -111,6 +115,9 @@ PYBIND11_MODULE(library, m) .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"); + + + // API extended summer 2020 py::class_<sc2::PlayerSetup>(m, "PlayerSetup"); diff --git a/src/IDABot.cpp b/src/IDABot.cpp index dc0cb3601e037ac495a32e29381ed98ae202d5a9..b6330b538b182b7b24efd52266f05af68b53083c 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -320,7 +320,7 @@ void IDABot::DebugSetShields(float value, const Unit unit) Debug()->DebugSetShields(value, unit.getUnitPtr()); } -// There is a bug in the latest SC2 +// There is a bug in the latest SC2 (if using Blizzard API with game >=4.10) // This a function to get the enemy base instead of using build location manager // Switched over to other API where this is solved // Leaving function incase of it breaking @@ -329,10 +329,37 @@ const std::vector<Point2D> IDABot::GetEnemyBaseLocations() return Observation()->GetGameInfo().enemy_start_locations; } -bool IDABot::HasCreep(Point2D p) const { +bool IDABot::HasCreep(Point2D p) const +{ return Observation()->HasCreep(p); } -void IDABot::CameraMove(Point2DI p) { +void IDABot::CameraMove(Point2DI p) +{ ActionsFeatureLayer()->CameraMove(p); +} + +const char* IDABot::abilityForUpgrade(sc2::UpgradeID upgrade_id) const +{ + return sc2::AbilityTypeToName(Observation()->GetUpgradeData()[upgrade_id].ability_id); +} + +uint32_t IDABot::UpgradeMineralCost(sc2::UpgradeID upgrade_id) const +{ + return Observation()->GetUpgradeData()[upgrade_id].mineral_cost; +} + +uint32_t IDABot::UpgradeGasCost(sc2::UpgradeID upgrade_id) const +{ + return Observation()->GetUpgradeData()[upgrade_id].vespene_cost; +} + +float IDABot::UpgradeResearchTime(sc2::UpgradeID upgrade_id) const +{ + return Observation()->GetUpgradeData()[upgrade_id].research_time; +} + +float IDABot::RadiusEffect(sc2::EffectID effect_id) const +{ + return Observation()->GetEffectData()[effect_id].radius; } \ No newline at end of file diff --git a/src/IDABot.h b/src/IDABot.h index b55508444e3f3f42079ece999fa1bf6de2bdf698..4186904a17081faf4bd6ec3f09166700bb026cba 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -87,6 +87,12 @@ public: const std::vector<Point2D> GetEnemyBaseLocations(); bool HasCreep(Point2D p) const; void CameraMove(Point2DI p); + const char* abilityForUpgrade(sc2::UpgradeID upgrade_id) const; + uint32_t UpgradeMineralCost(sc2::UpgradeID upgrade_id) const; + uint32_t UpgradeGasCost(sc2::UpgradeID upgrade_id) const; + float UpgradeResearchTime(sc2::UpgradeID upgrade_id) const; + float RadiusEffect(sc2::EffectID effect_id) const; + // Not needed, just convenience functions diff --git a/src/Unit.cpp b/src/Unit.cpp index 12a5ac1a0f373c981112385294359a6b4164da3e..0fa7550dd9c0de89af813376bd17448ef10197f2 100644 --- a/src/Unit.cpp +++ b/src/Unit.cpp @@ -464,10 +464,10 @@ int Unit::getOwner() const // Implemented with Blizzard SC2 API bool Unit::isCarryingGas() const { - return m_bot->Observation()->IsUnitCarryVespene(*m_unit); + return sc2::IsCarryingVespene(*m_unit); } bool Unit::isCarryingMinerals() const { - return m_bot->Observation()->IsUnitCarryMineral(*m_unit); + return sc2::IsCarryingMinerals(*m_unit); } \ No newline at end of file diff --git a/src/UnitType.cpp b/src/UnitType.cpp index 33013aa3711b603401cb75c1bebf1fb12667c4d6..cf6983564ce0952afe032e97e9671a6d76ef618e 100644 --- a/src/UnitType.cpp +++ b/src/UnitType.cpp @@ -385,7 +385,22 @@ int UnitType::getSightRange() const return m_bot->Observation()->GetUnitTypeData()[m_type].sight_range; } -sc2::UnitTypeID UnitType::getRequiredStructure() const +UnitTypeID UnitType::getRequiredStructure() const { return m_bot->Observation()->GetUnitTypeData()[m_type].tech_requirement; } + +std::vector<sc2::UnitTypeID> UnitType::getEquivalentUnits() const +{ + return m_bot->Observation()->GetUnitTypeData()[m_type].tech_alias; +} + +bool UnitType::requiredAttached() const +{ + return m_bot->Observation()->GetUnitTypeData()[m_type].require_attached; +} + +float UnitType::getBuildTime() const +{ + return m_bot->Observation()->GetUnitTypeData()[m_type].build_time; +} \ No newline at end of file diff --git a/src/UnitType.h b/src/UnitType.h index 72ea02820e92dca208e52e3b72cb0dd087962474..7f3bbbe530ffc6859f7ceb8cff1c691af42afb31 100644 --- a/src/UnitType.h +++ b/src/UnitType.h @@ -2,6 +2,7 @@ #include "Common.h" + class IDABot; class UnitType @@ -25,7 +26,7 @@ public: int getMovementSpeed() const; int getSightRange() const; - sc2::UnitTypeID getRequiredStructure() const; + sc2::UnitTypeID getRequiredStructure() const; bool isValid() const; bool isBuilding() const; @@ -50,6 +51,9 @@ public: int gasPrice() const; const std::vector<UnitType> & whatBuilds() const; + std::vector<sc2::UnitTypeID> getEquivalentUnits() const; + bool requiredAttached() const; + float getBuildTime() const; static UnitType GetUnitTypeFromName(const std::string & name, IDABot & bot);