From 4fce66f8f8fa5acf492a99d53b2dfc2d4011aaff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hannes=20J=C3=A4mtner?= <hanja189@student.liu.se>
Date: Wed, 8 Jul 2020 16:28:48 +0200
Subject: [PATCH] carry now exist in IDABot

---
 docs/idabot.rst            |  4 ++++
 python-api-src/library.cpp | 40 +++++++++++++++++++++-----------------
 src/IDABot.cpp             | 16 +++++++++++++++
 src/IDABot.h               |  7 +++++++
 4 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/docs/idabot.rst b/docs/idabot.rst
index 2a3b0c0d2..f5f9004d6 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 d92cbc72c..227129e37 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 d0908f789..f29a67e3c 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 a1567ac9f..8f10a6812 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;
-- 
GitLab