From f8ec4bd0971362da7b95987f5c47b3d1ed4e08de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hannes=20J=C3=A4mtner?= <hanja189@student.liu.se>
Date: Mon, 13 Jul 2020 09:35:50 +0200
Subject: [PATCH] Refactor and moved function from IDABot to unit

---
 python-api-src/lib_unit.cpp |  1 +
 python-api-src/library.cpp  |  2 --
 src/BuildingPlacer.cpp      |  2 ++
 src/IDABot.cpp              | 12 ------------
 src/IDABot.h                |  2 --
 src/Unit.cpp                | 14 ++++++++++++++
 src/Unit.h                  |  1 +
 7 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/python-api-src/lib_unit.cpp b/python-api-src/lib_unit.cpp
index dbb4c017a..f7ba369c1 100644
--- a/python-api-src/lib_unit.cpp
+++ b/python-api-src/lib_unit.cpp
@@ -35,6 +35,7 @@ void define_unit(py::module & m)
         .def_property_readonly("facing", &Unit::getFacing)
         .def_property_readonly("radius", &Unit::getRadius)
         .def_property_readonly("is_carrying_minerals", &Unit::isCarryingMinerals)
+		.def_property_readonly("is_carrying_gas", &Unit::isCarryingGas)
 		.def_property_readonly("gas_left_in_refinery", &Unit::gasLeftInGeyser)
 		.def_property_readonly("minerals_left_in_mineralfield", &Unit::mineralsLeftInMineralfield)
 		.def_property_readonly("owner", &Unit::getOwner)
diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp
index 832d9f534..1c59abb89 100644
--- a/python-api-src/library.cpp
+++ b/python-api-src/library.cpp
@@ -73,8 +73,6 @@ PYBIND11_MODULE(library, m)
 		.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("is_unit_carry_vespene", &IDABot::IsUnitCarryVespene, "If unit carries a vespene", "unit"_a)
-		.def("is_unit_carry_mineral", &IDABot::IsUnitCarryMineral, "If unit carries a mineral", "unit"_a)
 		.def("debug_create_unit", &IDABot::DebugCreateUnit, "unit_type"_a, "p"_a, "player_id"_a = 1, "count"_a = 1)
 		.def("debug_kill_unit", &IDABot::DebugKillUnit, "Kill unit from debug mode")
 		.def("debug_show_map", &IDABot::DebugShowMap, "Show the entire map through debug mode")
diff --git a/src/BuildingPlacer.cpp b/src/BuildingPlacer.cpp
index 008fb521e..988ceca16 100644
--- a/src/BuildingPlacer.cpp
+++ b/src/BuildingPlacer.cpp
@@ -95,6 +95,8 @@ bool BuildingPlacer::canBuildHereWithSpace(int bx, int by, const UnitType & type
     return true;
 }
 
+// BuildDist is the distance from the position where the building is gonna be placed.
+
 CCTilePosition BuildingPlacer::getBuildLocationNear(const CCTilePosition & p, const UnitType & t, int buildDist, size_t search_count) const
 {
     //Timer t;
diff --git a/src/IDABot.cpp b/src/IDABot.cpp
index 2e4ae3908..dc70bd380 100644
--- a/src/IDABot.cpp
+++ b/src/IDABot.cpp
@@ -230,18 +230,6 @@ const TypeData & IDABot::Data(const MetaType & type) const
 	API extended summer 2020
 */
 
-bool IDABot::IsUnitCarryVespene(Unit const unit) const
-{
-	const sc2::Unit * sc2unit = unit.getUnitPtr();
-	return Observation()->IsUnitCarryVespene(*sc2unit);
-}
-
-bool IDABot::IsUnitCarryMineral(Unit const unit) const
-{
-	const sc2::Unit * sc2unit = unit.getUnitPtr();
-	return Observation()->IsUnitCarryMineral(*sc2unit);
-}
-
 void IDABot::DebugCreateUnit(UnitTypeID unit_type, const CCPosition& p, uint32_t player_id, uint32_t count) 
 {
 	Debug()->DebugCreateUnit(unit_type, p, player_id, count);
diff --git a/src/IDABot.h b/src/IDABot.h
index 7fba6b34f..b55508444 100644
--- a/src/IDABot.h
+++ b/src/IDABot.h
@@ -66,8 +66,6 @@ public:
 	/*
 		API extended summer 2020
 	*/
-	bool IsUnitCarryVespene(Unit const unit) const;
-	bool IsUnitCarryMineral(Unit const unit) const;
 	void DebugCreateUnit(UnitTypeID unit_type, const CCPosition& p, uint32_t player_id = 1, uint32_t count = 1);
 	void DebugKillUnit(const Unit unit);
 	void DebugShowMap();
diff --git a/src/Unit.cpp b/src/Unit.cpp
index 04d80c681..ff4c26f2e 100644
--- a/src/Unit.cpp
+++ b/src/Unit.cpp
@@ -426,6 +426,8 @@ void Unit::stopDance() const
 	m_bot->Actions()->UnitCommand(m_unit, sc2::ABILITY_ID::STOP_DANCE);
 }
 
+/*
+// Implementation by Dawid Abucewicz
 bool Unit::isCarryingMinerals() const
 {
     BOT_ASSERT(isValid(), "Unit is not valid");
@@ -439,6 +441,7 @@ bool Unit::isCarryingMinerals() const
     }
     return false;
 }
+*/
 
 int Unit::gasLeftInGeyser() const
 {
@@ -457,3 +460,14 @@ int Unit::getOwner() const
 	BOT_ASSERT(isValid(), "Unit is not valid");
 	return m_unit->owner;
 }
+
+// Implemented with Blizzard SC2 API
+bool Unit::isCarryingGas() const
+{
+	return m_bot->Observation()->IsUnitCarryVespene(*m_unit);
+}
+
+bool Unit::isCarryingMinerals() const
+{
+	return m_bot->Observation()->IsUnitCarryMineral(*m_unit);
+}
\ No newline at end of file
diff --git a/src/Unit.h b/src/Unit.h
index 2275b2ca5..a996e372f 100644
--- a/src/Unit.h
+++ b/src/Unit.h
@@ -67,6 +67,7 @@ public:
 	int gasLeftInGeyser() const;
 	int mineralsLeftInMineralfield() const;
 	int getOwner() const;
+	bool isCarryingGas() const;
 
 
     void stop           () const;
-- 
GitLab