diff --git a/python-api-src/lib_building_placer.cpp b/python-api-src/lib_building_placer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7328973d8d5d09038e3cc10a42a09c424a19e782 --- /dev/null +++ b/python-api-src/lib_building_placer.cpp @@ -0,0 +1,14 @@ +#include "library.h" + +namespace py = pybind11; + +void define_building_placer(py::module & m) +{ + py::class_<BuildingPlacer>(m, "BuildingPlacer") + .def("can_build_here", &BuildingPlacer::canBuildHere, "x"_a, "y"_a, "unit_type"_a) + .def("can_build_here_with_spaces", &BuildingPlacer::canBuildHereWithSpace, "x"_a, "y"_a, "unit_type"_a, "build_distance"_a) + .def("get_build_location_near", &BuildingPlacer::getBuildLocationNear, "point2di"_a, "unit_type"_a, "build_distance"_a) + .def("reserve_tiles", &BuildingPlacer::reserveTiles, "x"_a, "y"_a, "width"_a, "height"_a) + .def("free_tiles", &BuildingPlacer::freeTiles, "x"_a, "y"_a, "width"_a, "height"_a) + .def("get_refinery_position", &BuildingPlacer::getRefineryPosition); +} \ No newline at end of file diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index ec324f9b7e62f026fb874ba414f93ad37899ccf7..1856427597945bdb4e1766a4be42be4fe31078b7 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -14,6 +14,7 @@ PYBIND11_MODULE(library, m) define_base_location(m); define_tech_tree(m); define_map_tools(m); + define_building_placer(m); py::class_<Coordinator>(m, "Coordinator") .def(py::init()) @@ -66,6 +67,7 @@ PYBIND11_MODULE(library, m) .def_property_readonly("base_location_manager", &IDABot::Bases) .def_property_readonly("tech_tree", &IDABot::TechTree) .def_property_readonly("map_tools", &IDABot::Map) + .def_property_readonly("building_placer", &IDABot::BuildingPlacer) .def_property_readonly("start_location", &IDABot::GetStartLocation) .def_property_readonly("minerals", &IDABot::GetMinerals) .def_property_readonly("current_supply", &IDABot::GetCurrentSupply) diff --git a/python-api-src/library.h b/python-api-src/library.h index f59ca94f0721525e027d83886a054341c4f40143..ebfbd65f30e20972e80719e1b7b7a98c2cbde081 100644 --- a/python-api-src/library.h +++ b/python-api-src/library.h @@ -7,6 +7,9 @@ #include <pybind11/stl.h> /* Automatic conversion from std::vector to Python lists */ #include <pybind11/operators.h> /* Convenient operator support */ +// Lets us use "x"_a instead of py::arg("x"), great. +using namespace pybind11::literals; + // Wrapper class since the initialization uses pure argc/argv and these cannot be wrapped into Python correctly class Coordinator : public sc2::Coordinator { @@ -59,4 +62,5 @@ void define_util(pybind11::module &m); void define_point(pybind11::module &m); void define_base_location(pybind11::module & m); void define_tech_tree(pybind11::module & m); -void define_map_tools(pybind11::module & m); \ No newline at end of file +void define_map_tools(pybind11::module & m); +void define_building_placer(pybind11::module & m); \ No newline at end of file diff --git a/src/IDABot.cpp b/src/IDABot.cpp index 07e9046a8b033ba805237e8657b4ca1e373e5684..4e6e8bce37572a3e1eb091ad8d5fc2409b104169 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -656,6 +656,11 @@ void IDABot::OnError(const std::vector<sc2::ClientError> & client_errors, const // This is called when the sc2api (Google's API) has an error. } +BuildingPlacer & IDABot::BuildingPlacer() +{ + return m_buildingPlacer; +} + const TypeData & IDABot::Data(const UnitType & type) const { return m_techTree.getData(type); diff --git a/src/IDABot.h b/src/IDABot.h index 1e43153c873305df3c40e4d8af00c4589514d45c..09ac90e252d8eb7800d83a93f3b715c08cc51886 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -124,6 +124,7 @@ public: const std::vector<Unit> & GetMyUnits() const; const std::vector<Unit> GetUnits(const UnitType & type, int player = Players::Self) const; const std::vector<CCPosition> & GetStartLocations() const; + BuildingPlacer & BuildingPlacer(); // Not needed, just convenience functions const TypeData & Data(const UnitType & type) const;