From c1580e9573101a0cacb4b92ae08ddba37888d340 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hannes=20J=C3=A4mtner?= <hanja189@student.liu.se>
Date: Fri, 10 Jul 2020 14:06:49 +0200
Subject: [PATCH] Added vespene gas amount for geyser and updated
 Buildingplacer

---
 python-api-src/lib_unit.cpp | 1 +
 python-api-src/library.cpp  | 8 ++++----
 src/BuildingPlacer.cpp      | 8 +++++---
 src/IDABot.cpp              | 2 +-
 src/IDABot.h                | 2 +-
 src/Unit.cpp                | 6 ++++++
 src/Unit.h                  | 5 +++++
 7 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/python-api-src/lib_unit.cpp b/python-api-src/lib_unit.cpp
index 83b3166..efc4802 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("gas_left_in_refinery", &Unit::gasLeftInRefinery)
         .def("hold_position", &Unit::holdPosition)
         .def("patrol", py::overload_cast<const CCPosition &>(&Unit::patrol, py::const_))
         .def("stop_dance", &Unit::stopDance)
diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp
index a105330..2aa1198 100644
--- a/python-api-src/library.cpp
+++ b/python-api-src/library.cpp
@@ -73,9 +73,9 @@ 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")
-		.def("is_unit_carry_mineral", &IDABot::IsUnitCarryMineral, "If unit carries a mineral")
-		.def("debug_create_unit", &IDABot::DebugCreateUnit, "Create unit from debug mode")
+		.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")
 		.def("debug_fast_build", &IDABot::DebugFastBuild, "Set build time to 1 through debug mode")
@@ -93,7 +93,7 @@ PYBIND11_MODULE(library, m)
 		.def("debug_set_energy", &IDABot::DebugSetEnergy, "Set the energy on a unit through debug mode")
 		.def("debug_set_life", &IDABot::DebugSetLife, "Set the life on a unit through debug mode")
 		.def("debug_set_shield", &IDABot::DebugSetShields, "Set the shields on a unit through debug mode")
-		.def("get_enemy_base_location", &IDABot::GetEnemyBaseLocation, "Return the CCpostion of the enemy base")
+		.def("get_enemy_base_location", &IDABot::GetEnemyBaseLocations, "Return the CCpostion of the enemy base")
 		.def_property_readonly("base_location_manager", &IDABot::Bases)
 		.def_property_readonly("tech_tree", &IDABot::GetTechTree)
 		.def_property_readonly("map_tools", &IDABot::Map)
diff --git a/src/BuildingPlacer.cpp b/src/BuildingPlacer.cpp
index 4b048ed..008fb52 100644
--- a/src/BuildingPlacer.cpp
+++ b/src/BuildingPlacer.cpp
@@ -66,13 +66,13 @@ bool BuildingPlacer::canBuildHereWithSpace(int bx, int by, const UnitType & type
     // define the rectangle of the building spot
     int startx = bx - buildDist;
     int starty = by - buildDist;
-    int endx   = bx + width + buildDist;
-    int endy   = by + height + buildDist;
+    int endx   = bx + width + buildDist - 1;
+    int endy   = by + height + buildDist - 1;
 
     // TODO: recalculate start and end positions for addons
 
     // if this rectangle doesn't fit on the map we can't build here
-    if (startx < 0 || starty < 0 || endx > m_bot.Map().width() || endx < bx + width || endy > m_bot.Map().height())
+    if (startx < 0 || starty < 0 || endx > m_bot.Map().width() || endx < bx + width - 1 || endy > m_bot.Map().height() - 1)
     {
         return false;
     }
@@ -191,6 +191,7 @@ void BuildingPlacer::reserveTiles(int bx, int by, int width, int height)
 
 void BuildingPlacer::drawReservedTiles()
 {
+	// Why is there a return here? Should we not use the function? /Hannes J�mtner
     return;
     int rwidth = (int)m_reserveMap.size();
     int rheight = (int)m_reserveMap[0].size();
@@ -227,6 +228,7 @@ CCTilePosition BuildingPlacer::getRefineryPosition()
     double minGeyserDistanceFromHome = std::numeric_limits<double>::max();
     CCPosition homePosition = m_bot.GetStartLocation();
 
+
     for (auto & unit : m_bot.GetAllUnits())
     {
         if (!unit.getType().isGeyser())
diff --git a/src/IDABot.cpp b/src/IDABot.cpp
index ac3aa2a..4331f5e 100644
--- a/src/IDABot.cpp
+++ b/src/IDABot.cpp
@@ -334,7 +334,7 @@ void IDABot::DebugSetShields(float value, const Unit unit)
 
 // There is a bug in the latest SC2
 // This a function to get the enemy base instead of using build location manager
-const std::vector<Point2D> IDABot::GetEnemyBaseLocation()
+const std::vector<Point2D> IDABot::GetEnemyBaseLocations()
 {
 	return Observation()->GetGameInfo().enemy_start_locations;
 }
diff --git a/src/IDABot.h b/src/IDABot.h
index 026d8bb..01bb606 100644
--- a/src/IDABot.h
+++ b/src/IDABot.h
@@ -85,7 +85,7 @@ public:
 	void DebugSetEnergy(float value, const Unit unit);
 	void DebugSetLife(float value, const Unit unit);
 	void DebugSetShields(float value, const Unit unit);
-	const std::vector<Point2D> GetEnemyBaseLocation();
+	const std::vector<Point2D> GetEnemyBaseLocations();
 
 
     // Not needed, just convenience functions
diff --git a/src/Unit.cpp b/src/Unit.cpp
index 9cc165a..8d83331 100644
--- a/src/Unit.cpp
+++ b/src/Unit.cpp
@@ -439,3 +439,9 @@ bool Unit::isCarryingMinerals() const
     }
     return false;
 }
+
+int Unit::gasLeftInRefinery() const
+{
+	BOT_ASSERT(isValid(), "Unit is not valid");
+	return m_unit->vespene_contents;
+}
diff --git a/src/Unit.h b/src/Unit.h
index 58e7691..874c36f 100644
--- a/src/Unit.h
+++ b/src/Unit.h
@@ -60,6 +60,11 @@ public:
     void stopDance() const;
     float getFacing() const;
     float getRadius() const;
+	
+	/*
+		API extended summer 2020
+	*/
+	int gasLeftInRefinery() const;
 
 
     void stop           () const;
-- 
GitLab