From bde90cffe3712af18df112a18045b92d6679b530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bergstr=C3=B6m?= <davbe125@student.liu.se> Date: Thu, 28 Jun 2018 17:07:35 +0200 Subject: [PATCH] Make TechTree available to Python --- python-api-src/lib_tech_tree.cpp | 29 +++++++++++++++++++++++++++++ python-api-src/library.cpp | 2 ++ python-api-src/library.h | 3 ++- src/IDABot.cpp | 5 +++++ src/IDABot.h | 1 + 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 python-api-src/lib_tech_tree.cpp diff --git a/python-api-src/lib_tech_tree.cpp b/python-api-src/lib_tech_tree.cpp new file mode 100644 index 000000000..9df5b8e70 --- /dev/null +++ b/python-api-src/lib_tech_tree.cpp @@ -0,0 +1,29 @@ +#include "library.h" + +namespace py = pybind11; + +void define_tech_tree(py::module & m) +{ + py::class_<TypeData>(m, "TypeData") + .def_readonly("race", &TypeData::race) + .def_readonly("mineral_cost", &TypeData::mineralCost, "mineral cost of the item") + .def_readonly("gas_cost", &TypeData::gasCost, "gas cost of the item") + .def_readonly("supply_cost", &TypeData::supplyCost, "supply cost of the item") + .def_readonly("build_time", &TypeData::buildTime, "build time of the item") + .def_readonly("is_unit", &TypeData::isUnit) + .def_readonly("is_building", &TypeData::isBuilding) + .def_readonly("is_worker", &TypeData::isWorker) + .def_readonly("is_refinery", &TypeData::isRefinery) + .def_readonly("is_supply_provider", &TypeData::isSupplyProvider) + .def_readonly("is_resource_depot", &TypeData::isResourceDepot) + .def_readonly("is_addon", &TypeData::isAddon) + .def_readonly("build_ability", &TypeData::buildAbility, "the ability that creates this item") + .def_readonly("warp_ability", &TypeData::warpAbility, "the ability that creates this item via warp-in") + .def_readonly("what_builds", &TypeData::whatBuilds, "any of these units can build the item") + .def_readonly("required_units", &TypeData::requiredUnits, "owning ONE of these is required to make") + .def_readonly("required_upgrades", &TypeData::requiredUpgrades, "having ALL of these is required to make"); + + py::class_<TechTree>(m, "TechTree") + .def("get_data", py::overload_cast<const UnitType &>(&TechTree::getData, py::const_)) + .def("get_data", py::overload_cast<const CCUpgrade &>(&TechTree::getData, py::const_)); +} \ No newline at end of file diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 5d7c749f4..bed54094d 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -12,6 +12,7 @@ PYBIND11_MODULE(library, m) define_util(m); define_point(m); define_base_location(m); + define_tech_tree(m); py::class_<Coordinator>(m, "Coordinator") .def(py::init()) @@ -58,6 +59,7 @@ PYBIND11_MODULE(library, m) .def("OnStep_UpdateIDABot", &IDABot::OnStep_UpdateIDABot) .def("get_all_units", &IDABot::GetAllUnits) .def("get_my_units", &IDABot::GetMyUnits) + .def_property_readonly("tech_tree", &IDABot::TechTree) .def_property_readonly("base_manager", &IDABot::Bases); py::class_<sc2::PlayerSetup>(m, "PlayerSetup"); diff --git a/python-api-src/library.h b/python-api-src/library.h index a0dbadc2e..0bdb906e3 100644 --- a/python-api-src/library.h +++ b/python-api-src/library.h @@ -57,4 +57,5 @@ void define_unit(pybind11::module & m); void define_unittype(pybind11::module &m); void define_util(pybind11::module &m); void define_point(pybind11::module &m); -void define_base_location(pybind11::module & m); \ No newline at end of file +void define_base_location(pybind11::module & m); +void define_tech_tree(pybind11::module & m); \ No newline at end of file diff --git a/src/IDABot.cpp b/src/IDABot.cpp index ecd43432f..8b2faf56f 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -587,6 +587,11 @@ int IDABot::GetCurrentFrame() const return (int)Observation()->GetGameLoop(); } +const TechTree & IDABot::TechTree() const +{ + return m_techTree; +} + WorkerManager & IDABot::Workers() { return m_workers; diff --git a/src/IDABot.h b/src/IDABot.h index 902134d9c..519fbe754 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -109,6 +109,7 @@ public: /* API for students */ + const TechTree & TechTree() const; WorkerManager & Workers(); const BaseLocationManager & Bases() const; const MapTools & Map() const; -- GitLab