From 7f5eb81c01d81af9b6d6c6aba790dc8a36a9be91 Mon Sep 17 00:00:00 2001 From: Rojikku98 <be.edvin@gmail.com> Date: Thu, 17 Mar 2022 09:59:15 +0100 Subject: [PATCH] Added on_game_end and asve replay --- python-api-src/library.cpp | 2 ++ python-api-src/library.h | 9 +++++++++ src/IDABot.cpp | 4 ++++ src/IDABot.h | 2 ++ 4 files changed, 17 insertions(+) diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 4850443..7b26f47 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -83,6 +83,7 @@ PYBIND11_MODULE(library, m) .def(py::init()) .def("on_game_start", &IDABot::OnGameStart) .def("on_step", &IDABot::OnStep) + .def("on_game_end", &IDABot::OnGameEnd) .def("send_chat", &IDABot::SendChat, "Sends the string 'message' to the game chat", "message"_a) .def("get_all_units", &IDABot::GetAllUnits, "Returns a list of all visible units, including minerals and geysers") .def("get_my_units", &IDABot::GetMyUnits, "Returns a list of all your units") @@ -113,6 +114,7 @@ PYBIND11_MODULE(library, m) .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("effect_radius", &IDABot::RadiusEffect, "Size of the circle the effect impacts", "effect"_a) + .def("save_replay", &IDABot::SaveReplay, "Saves the game as a replay", "path"_a) .def_property_readonly("base_location_manager", &IDABot::Bases, "An instance of the class :class:`library.BaseLocationManager`") .def_property_readonly("tech_tree", &IDABot::GetTechTree, "An instance of the class :class:`library.TechTree`") .def_property_readonly("map_tools", &IDABot::Map, "An instance of the class :class:`library.MapTools`") diff --git a/python-api-src/library.h b/python-api-src/library.h index 3f9114d..9fb76f3 100644 --- a/python-api-src/library.h +++ b/python-api-src/library.h @@ -60,6 +60,15 @@ public: OnStep ); } + void OnGameEnd() override + { + PYBIND11_OVERLOAD_NAME( + void, + IDABot, + "on_game_end", + OnGameEnd + ); + } }; diff --git a/src/IDABot.cpp b/src/IDABot.cpp index b89e541..6b55eb5 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -403,4 +403,8 @@ const sc2::GameResult IDABot::GetPlayerResults() const { } std::cout << "The player can not be found" << std::endl; return sc2::GameResult::Undecided; +} + +bool IDABot::SaveReplay(const std::string& path) { + return this->Control()->SaveReplay(path); } \ No newline at end of file diff --git a/src/IDABot.h b/src/IDABot.h index 009be41..7df2a52 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -97,6 +97,8 @@ public: const sc2::GameResult GetPlayerResults() const; + bool SaveReplay(const std::string & path); + // Not needed, just convenience functions -- GitLab