diff --git a/docs/idabot.rst b/docs/idabot.rst index 2a3b0c0d2f9c1339bb38c7ea32f358afc5f71ae9..f5f9004d66608c797e6938b94dbc56f209c43b11 100644 --- a/docs/idabot.rst +++ b/docs/idabot.rst @@ -59,6 +59,10 @@ IDABot Sends the string 'message' to the game chat + .. method:: IDABot.carry_vespene(self, unit) -> Boolean + + "Returns true if unit carries a vespene" + Attributes: .. autoattribute:: minerals diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index d92cbc72c6d48184facd6d8886cec382ee6c9683..227129e374ebdf5f28f36328dcfb7aa50546878b 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -66,24 +66,28 @@ PYBIND11_MODULE(library, m) // IDABot is a specialization of Agent py::class_<IDABot, PyIDABot, sc2::Agent>(m, "IDABot") - .def(py::init()) - .def("on_game_start", &IDABot::OnGameStart) - .def("on_step", &IDABot::OnStep) - .def("send_chat", &IDABot::SendChat, "Send a message to the game chat", "message"_a) - .def("get_all_units", &IDABot::GetAllUnits, "Returns a list of all units") - .def("get_my_units", &IDABot::GetMyUnits, "Returns a list of all units beloning to the player") - .def("get_player_race", &IDABot::GetPlayerRace) - .def_property_readonly("base_location_manager", &IDABot::Bases) - .def_property_readonly("tech_tree", &IDABot::GetTechTree) - .def_property_readonly("map_tools", &IDABot::Map) - .def_property_readonly("building_placer", &IDABot::GetBuildingPlacer) - .def_property_readonly("start_location", &IDABot::GetStartLocation, "CCPosition representing the start location") - .def_property_readonly("start_locations", &IDABot::GetStartLocations, "CCPosition representing the start locations") - .def_property_readonly("minerals", &IDABot::GetMinerals, "How much minerals we currently have") - .def_property_readonly("current_supply", &IDABot::GetCurrentSupply, "How much supply we are currently using") - .def_property_readonly("max_supply", &IDABot::GetMaxSupply, "How much supply we can currently use") - .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"); + .def(py::init()) + .def("on_game_start", &IDABot::OnGameStart) + .def("on_step", &IDABot::OnStep) + .def("send_chat", &IDABot::SendChat, "Send a message to the game chat", "message"_a) + .def("get_all_units", &IDABot::GetAllUnits, "Returns a list of all units") + .def("get_my_units", &IDABot::GetMyUnits, "Returns a list of all units beloning to the player") + .def("get_player_race", &IDABot::GetPlayerRace) + .def("carry_vespene", &IDABot::isCarryingVespene, "If unit carries a vespene") + .def("carry_mineral", &IDABot::isCarryingMineral, "If unit carries a mineral") + .def_property_readonly("base_location_manager", &IDABot::Bases) + .def_property_readonly("tech_tree", &IDABot::GetTechTree) + .def_property_readonly("map_tools", &IDABot::Map) + .def_property_readonly("building_placer", &IDABot::GetBuildingPlacer) + .def_property_readonly("start_location", &IDABot::GetStartLocation, "CCPosition representing the start location") + .def_property_readonly("start_locations", &IDABot::GetStartLocations, "CCPosition representing the start locations") + .def_property_readonly("minerals", &IDABot::GetMinerals, "How much minerals we currently have") + .def_property_readonly("current_supply", &IDABot::GetCurrentSupply, "How much supply we are currently using") + .def_property_readonly("max_supply", &IDABot::GetMaxSupply, "How much supply we can currently use") + .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 d0908f789cb42ab5675a0028889085a4918d79bd..f29a67e3c5d0d089970f14494dad5c343b0507ee 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -224,3 +224,19 @@ const TypeData & IDABot::Data(const MetaType & type) const { return m_techTree.getData(type); } + +/* + API extended summer 2020 +*/ + +bool IDABot::isCarryingVespene(Unit const unit) const +{ + const sc2::Unit * sc2unit = unit.getUnitPtr(); + return Observation()->IsUnitCarryVespene(*sc2unit); +} + +bool IDABot::isCarryingMineral(Unit const unit) const +{ + const sc2::Unit * sc2unit = unit.getUnitPtr(); + return Observation()->IsUnitCarryMineral(*sc2unit); +} diff --git a/src/IDABot.h b/src/IDABot.h index a1567ac9f75b75b6d5268cb3c4f3e372e8eac23e..8f10a681209e68e169c10409cf5a7635c75f37e4 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -59,6 +59,13 @@ public: const std::vector<Unit> GetUnits(const UnitType & type, int player = Players::Self) const; const std::vector<CCPosition> & GetStartLocations() const; + /* + API extended summer 2020 + + */ + bool isCarryingVespene(Unit const unit) const; + bool isCarryingMineral(Unit const unit) const; + // Not needed, just convenience functions const TypeData & Data(const UnitType & type) const; const TypeData & Data(const CCUpgrade & type) const;