From 0637111d76fe2eaafd3339312ba195c843fedd92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Bergstr=C3=B6m?= <davbe125@student.liu.se>
Date: Wed, 27 Jun 2018 15:29:27 +0200
Subject: [PATCH] Add BaseManager to Python-API

---
 python-api-src/lib_base_location.cpp | 25 +++++++++++++++++++++++++
 python-api-src/library.cpp           |  4 +++-
 python-api-src/library.h             |  5 ++++-
 3 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 python-api-src/lib_base_location.cpp

diff --git a/python-api-src/lib_base_location.cpp b/python-api-src/lib_base_location.cpp
new file mode 100644
index 0000000..4bbbd1c
--- /dev/null
+++ b/python-api-src/lib_base_location.cpp
@@ -0,0 +1,25 @@
+#include "library.h"
+
+namespace py = pybind11;
+
+void define_base_location(py::module & m)
+{
+    py::class_<BaseLocation>(m, "BaseLocation")
+        .def_property_readonly("geysers", &BaseLocation::getGeysers)
+        .def_property_readonly("minerals", &BaseLocation::getMinerals)
+        .def_property_readonly("start_location", &BaseLocation::isStartLocation)
+        .def_property_readonly("depot_position", &BaseLocation::getDepotPosition)
+        .def_property_readonly("position", &BaseLocation::getPosition)
+        .def("get_ground_distance", py::overload_cast<const CCPosition &>(&BaseLocation::getGroundDistance, py::const_))
+        .def("get_ground_distance", py::overload_cast<const CCTilePosition &>(&BaseLocation::getGroundDistance, py::const_))
+        .def("is_occupied_by_player", &BaseLocation::isOccupiedByPlayer)
+        .def("is_player_start_location", &BaseLocation::isPlayerStartLocation)
+        .def("contains_position", &BaseLocation::containsPosition);
+
+    py::class_<BaseLocationManager>(m, "BaseLocationManager")
+        .def_property_readonly("base_locations", &BaseLocationManager::getBaseLocations, py::return_value_policy::reference)
+        .def_property_readonly("starting_base_locations", &BaseLocationManager::getStartingBaseLocations, py::return_value_policy::reference)
+        .def("get_occupied_base_locations", &BaseLocationManager::getOccupiedBaseLocations, py::return_value_policy::reference)
+        .def("get_player_starting_base_locations", &BaseLocationManager::getPlayerStartingBaseLocation, py::return_value_policy::copy)
+        .def("get_next_expansion", &BaseLocationManager::getNextExpansion, py::return_value_policy::copy);
+}
\ No newline at end of file
diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp
index 50c2a4e..c5a4e4f 100644
--- a/python-api-src/library.cpp
+++ b/python-api-src/library.cpp
@@ -11,6 +11,7 @@ PYBIND11_MODULE(library, m)
     define_unittype(m);
     define_util(m);
     define_point(m);
+    define_base_location(m);
 
     py::class_<Coordinator>(m, "Coordinator")
         .def(py::init())
@@ -35,7 +36,8 @@ PYBIND11_MODULE(library, m)
         .def("OnStep", &IDABot::OnStep)
         .def("OnStep_UpdateIDABot", &IDABot::OnStep_UpdateIDABot)
         .def("GetAllUnits", &IDABot::GetAllUnits)
-        .def("GetMyUnits", &IDABot::GetMyUnits);
+        .def("GetMyUnits", &IDABot::GetMyUnits)
+        .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 b1da21a..a0dbadc 100644
--- a/python-api-src/library.h
+++ b/python-api-src/library.h
@@ -50,8 +50,11 @@ public:
     }
 };
 
+// The functions below are all defined in different .cpp files, in order 
+// to keep compilation snappy
 void define_typeenums(pybind11::module & m);
 void define_unit(pybind11::module & m);
 void define_unittype(pybind11::module &m);
 void define_util(pybind11::module &m);
-void define_point(pybind11::module &m);
\ No newline at end of file
+void define_point(pybind11::module &m);
+void define_base_location(pybind11::module & m);
\ No newline at end of file
-- 
GitLab