From d5c2af868656cc89a814e3e5cf342c2169681967 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hannes=20J=C3=A4mtner?= <hanja189@student.liu.se>
Date: Mon, 20 Jul 2020 19:12:58 +0200
Subject: [PATCH] Checked files for up to date and updated docs

---
 docs/helpers.rst                       |  3 ++
 docs/idabot.rst                        | 40 +++++++++++++-------------
 docs/types.rst                         |  4 +++
 docs/unit.rst                          | 18 ++++++------
 python-api-src/lib_building_placer.cpp |  8 +++---
 src/BuildingPlacer.cpp                 | 10 +++++++
 src/UnitType.cpp                       |  4 ++-
 7 files changed, 53 insertions(+), 34 deletions(-)

diff --git a/docs/helpers.rst b/docs/helpers.rst
index b77c57285..79e8e40a6 100644
--- a/docs/helpers.rst
+++ b/docs/helpers.rst
@@ -62,6 +62,9 @@ BaseLocation
    .. autoattribute:: geysers
 
    .. automethod:: get_ground_distance
+      
+      This function uses BFS and moves in a vertical and horizontal position. Because of this,
+      the distance might overshoot compared to calculating it with Pythagoras' theorem.
 
    .. automethod:: is_occupied_by_player
 
diff --git a/docs/idabot.rst b/docs/idabot.rst
index a2c4d935a..714ed3cc3 100644
--- a/docs/idabot.rst
+++ b/docs/idabot.rst
@@ -61,11 +61,11 @@ IDABot
 
    .. method:: IDABot.has_creep(self, Point2D) -> Boolean
 
-      Returns if the position has a creep.
+      Returns if the position has a creep
 
    .. method:: IDABot.move_camera(self, Point2DI)
 
-      Move the camera to the position.
+      Move the camera to the position
 
    Attributes:
 
@@ -88,63 +88,63 @@ The debug-methods are a great tool for speeding up the process.
    .. method:: IDABot.debug_create_unit(self, UnitTypeID, Point2D, Player Constant, Int)
 
       This method creates the nr (INT) of units on the position of the Point2D, the unit 
-      belongs to the Player Constant.
+      belongs to the Player Constant
 
    .. method:: IDABot.debug_kill_unit(self, Unit)
 
-      Kills the unit.
+      Kills the unit
 
    .. method:: IDABot.debug_show_map(self)
 
-      Make the entire map visible.
+      Make the entire map visible
 
    .. method:: IDABot.debug_fast_build(self)
 
-      Set the build time in game to 1.
+      Set the build time in game to 1
   
    .. method:: IDABot.debug_enemy_control(self)
 
-      Gives the player full control over the enemy.
+      Gives the player full control over the enemy
 
    .. method:: IDABot.debug_fast_build(self)
 
-      Set the build time in game to 1.
+      Set the build time in game to 1
 
    .. method:: IDABot.debug_ignore_food(self)
 
-      Ignore food in game.
+      Ignore food in game
 
    .. method:: IDABot.debug_ignore_resource_cost(self)
 
-      Ignore the resource cost in game. Everything cost 0 resources.
+      Ignore the resource cost in game. Everything cost 0 resources
 
    .. method:: IDABot.debug_give_all_resources(self)
 
-      Set the mineral and vespene gas to 5000.
+      Set the mineral and vespene gas to 5000
    
    .. method:: IDABot.debug_god_mode(self)
 
-      Give yourself god mode in the game.
+      Give yourself god mode in the game
 
    .. method:: IDABot.debug_ignore_mineral(self)
 
-      Ignore the mineral cost in the game.
+      Ignore the mineral cost in the game
 
    .. method:: IDABot.debug_no_cooldowns(self)
 
-      Deactivate cooldowns (Basically setting them to 0).
+      Deactivate cooldowns (Basically setting them to 0)
 
    .. method:: IDABot.debug_give_all_tech(self)
 
-      Give yourself all tech.
+      Give yourself all tech
 
    .. method:: IDABot.debug_give_all_upgrades(self)
 
-      Give yourself all upgrades.
+      Give yourself all upgrades
 
    .. method:: IDABot.debug_set_score(self, Float)
 
-      Set the player score in game.
+      Set the player score in game
 
    .. method:: IDABot.debug_end_game(self, Boolean)
 
@@ -153,13 +153,13 @@ The debug-methods are a great tool for speeding up the process.
 
    .. method:: IDABot.debug_set_energy(self, Float, Unit)
 
-      Set the amount (Float) of energy to the unit.
+      Set the amount (Float) of energy to the unit
 
    .. method:: IDABot.debug_set_life(self, Float, Unit)
 
-      Set the amount (Float) of life to the unit.
+      Set the amount (Float) of life to the unit
 
    .. method:: IDABot.debug_set_shields(self, Float, Unit)
 
-      Set the amount (Float) of shield to the unit.
+      Set the amount (Float) of shield to the unit
 
diff --git a/docs/types.rst b/docs/types.rst
index 6e3903cad..dd9986f59 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -9,6 +9,10 @@ For a full list of all abilities and upgrades, see :class:`library.ABILITY_ID`
 , :class:`library.UPGRADE_ID` and :class:`library.EFFECT_ID` respectively. Note that these does not have any
 wrapper classes for them.
 
+If any of the ID's doesn't respond with the game. Before contacting the labassistent, check the game version
+and the compatibility through Liquipedia. Some ID's might be left after a patch and is not available in
+the game anymore.
+
 UnitType
 --------
 
diff --git a/docs/unit.rst b/docs/unit.rst
index 28fd1a45a..e8c09acfa 100644
--- a/docs/unit.rst
+++ b/docs/unit.rst
@@ -36,7 +36,7 @@ Unit
    .. autoattribute:: is_alive 
    .. autoattribute:: is_blip
 
-      Returns true if unit is a "blip" - a ping on the map.
+      Returns true if unit is a "blip" - a ping on the map
 
    .. autoattribute:: is_being_constructed 
       
@@ -56,7 +56,7 @@ Unit
    .. attribute:: Unit.player 
 
       Returns the constant corresponding to player which this unit belongs to.
-      See :ref:`playerconstants` for more information.
+      See :ref:`playerconstants` for more information
 
    .. autoattribute:: position 
    .. autoattribute:: current_ability_id
@@ -83,30 +83,30 @@ Unit
 
    .. attribute:: Unit.target
 
-      Returns target if unit has one, otherwise will fail the assertion (make sure not to call this unless certain that the unit has a target!).
+      Returns target if unit has one, otherwise will fail the assertion (make sure not to call this unless certain that the unit has a target!)
 
    .. autoattribute:: gas_left_in_refinery
 
       This is used on the geyser.	
-      Returns the amount of gas left in refinery.
+      Returns the amount of gas left in refinery
 
    .. autoattribute:: minerals_left_in_mineralfield
 
-      Returns the amount of minerals left in mineralfield.
+      Returns the amount of minerals left in mineralfield
 
    .. autoattribute:: owner
 
-      Returns the Player ID, the owner of the unit.
+      Returns the Player ID, the owner of the unit
 
    Methods:
 
    .. automethod:: ability
 
-      Call an ability directly, different abilities has different targets. Some target the unit itself (no argument), target a point (Point2D as argument) and some target a Unit (instance of Unit as argument).
+      Call an ability directly, different abilities has different targets. Some target the unit itself (no argument), target a point (Point2D as argument) and some target a Unit (instance of Unit as argument)
 
    .. method:: Unit.is_constructing(self, unit_type: library.UnitType)
 
-      Returns true if the unit is currently constructing another unit of type `unit_type`. Note that `unit_type` needs to be an instance of :class:`library.UnitType`.
+      Returns true if the unit is currently constructing another unit of type `unit_type`. Note that `unit_type` needs to be an instance of :class:`library.UnitType`
 
    .. automethod:: stop
    .. automethod:: attack_unit
@@ -124,7 +124,7 @@ Unit
    .. automethod:: morph
    .. method:: Unit.has_target
 
-      Returns True if the target has a valid target and False otherwise.
+      Returns True if the target has a valid target and False otherwise
 
    .. automethod:: hold_position
    .. automethod:: stop_dance
diff --git a/python-api-src/lib_building_placer.cpp b/python-api-src/lib_building_placer.cpp
index b925c749a..f2aed9730 100644
--- a/python-api-src/lib_building_placer.cpp
+++ b/python-api-src/lib_building_placer.cpp
@@ -6,8 +6,8 @@ void define_building_placer(py::module & m)
 {
     py::class_<BuildingPlacer>(m, "BuildingPlacer")
         .def("can_build_here", &BuildingPlacer::canBuildHere, "x"_a, "y"_a, "unit_type"_a)
-        .def("can_build_here_with_spaces", &BuildingPlacer::canBuildHereWithSpace, "x"_a, "y"_a, "unit_type"_a, "build_distance"_a)
-        .def("get_build_location_near", &BuildingPlacer::getBuildLocationNear, "point2di"_a, "unit_type"_a, "build_distance"_a = 2, "search_count"_a = 1000)
-        .def("reserve_tiles", &BuildingPlacer::reserveTiles, "x"_a, "y"_a, "width"_a, "height"_a)
-        .def("free_tiles", &BuildingPlacer::freeTiles, "x"_a, "y"_a, "width"_a, "height"_a);
+        .def("can_build_here_with_spaces", &BuildingPlacer::canBuildHereWithSpace, "Creates a square with the help of x, y, distance_to_building and the size of the unit_type. Good approach if we later gonna make a addon to the building.", "x"_a, "y"_a, "unit_type"_a, "distance_to_building"_a)
+        .def("get_build_location_near", &BuildingPlacer::getBuildLocationNear, "The search_count is how many building we should check (nearby buildings, instead of i < size, we can switch size to search_count). distance_to_building is the distance to the closest building.", "point2di"_a, "unit_type"_a, "distance_to_building"_a = 2, "search_count"_a = 1000)
+        .def("reserve_tiles", &BuildingPlacer::reserveTiles, "It's possible to reserve tiles, which makes it impossible to build at the position given by x and y.", "x"_a, "y"_a, "width"_a, "height"_a)
+        .def("free_tiles", &BuildingPlacer::freeTiles,"Free the tile (x, y) from reservation", "x"_a, "y"_a, "width"_a, "height"_a);
 }
\ No newline at end of file
diff --git a/src/BuildingPlacer.cpp b/src/BuildingPlacer.cpp
index 988ceca16..bc94e5f92 100644
--- a/src/BuildingPlacer.cpp
+++ b/src/BuildingPlacer.cpp
@@ -233,6 +233,9 @@ CCTilePosition BuildingPlacer::getRefineryPosition()
 
     for (auto & unit : m_bot.GetAllUnits())
     {
+		UnitType & refinery = Util::GetRefinery(m_bot.GetPlayerRace(Players::Self), m_bot);
+
+
         if (!unit.getType().isGeyser())
         {
             continue;
@@ -240,6 +243,13 @@ CCTilePosition BuildingPlacer::getRefineryPosition()
 
         CCPosition geyserPos(unit.getPosition());
 
+
+		// can't build a refinery on top of another
+		if (!m_bot.Map().canBuildTypeAtPosition((int)geyserPos.x, (int)geyserPos.y, refinery))
+		{
+			continue;
+		}
+
         // check to see if it's next to one of our depots
         bool nearDepot = false;
         for (auto & unit : m_bot.UnitInfo().getUnits(Players::Self))
diff --git a/src/UnitType.cpp b/src/UnitType.cpp
index 9fcad4336..33013aa37 100644
--- a/src/UnitType.cpp
+++ b/src/UnitType.cpp
@@ -164,6 +164,8 @@ bool UnitType::isMineral() const
         case sc2::UNIT_TYPEID::NEUTRAL_MINERALFIELD750      : return true;
         case sc2::UNIT_TYPEID::NEUTRAL_RICHMINERALFIELD     : return true;
         case sc2::UNIT_TYPEID::NEUTRAL_RICHMINERALFIELD750  : return true;
+		case sc2::UNIT_TYPEID::NEUTRAL_LABMINERALFIELD		: return true;
+		case sc2::UNIT_TYPEID::NEUTRAL_LABMINERALFIELD750	: return true;
         default: return false;
     }
 #else
@@ -366,7 +368,7 @@ bool UnitType::isMorphedBuilding() const
     }
 #else
     return  m_type == BWAPI::UnitTypes::Zerg_Sunken_Colony ||
-            m_type == BWAPI::UnitTypes::Zerg_Spore_Colony ||
+            m_type == BWAPI::UnitTypes::Zerg_Spore_Colony ||w
             m_type == BWAPI::UnitTypes::Zerg_Lair ||
             m_type == BWAPI::UnitTypes::Zerg_Hive ||
             m_type == BWAPI::UnitTypes::Zerg_Greater_Spire;
-- 
GitLab