From 14ab444bb4243411a1f9cff3c1f1d731246cee99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hannes=20J=C3=A4mtner?= <hanja189@student.liu.se>
Date: Thu, 23 Jul 2020 09:08:35 +0200
Subject: [PATCH] Changed structure of functions and added functions instead of
 techtree

---
 docs/helpers.rst                |  3 +++
 docs/idabot.rst                 | 16 ++++++++++++++++
 python-api-src/lib_unittype.cpp |  3 +++
 python-api-src/library.cpp      |  7 +++++++
 src/IDABot.cpp                  | 33 ++++++++++++++++++++++++++++++---
 src/IDABot.h                    |  6 ++++++
 src/Unit.cpp                    |  4 ++--
 src/UnitType.cpp                | 17 ++++++++++++++++-
 src/UnitType.h                  |  6 +++++-
 9 files changed, 88 insertions(+), 7 deletions(-)

diff --git a/docs/helpers.rst b/docs/helpers.rst
index 79e8e40..7f57cd0 100644
--- a/docs/helpers.rst
+++ b/docs/helpers.rst
@@ -89,6 +89,9 @@ TechTree
    this can be found under the folder data in this link_.
    A recent file is included in the `template repository`_.
 
+   Instead of using TechTree, it's possible to use the functions in UnitType for
+   structure, etc. In IDABot there is functions for getting data about upgrades.	
+
    .. method:: get_data(argument) -> library.TypeData
 
       Argument is either an instance of the class :class:`library.UnitType` or
diff --git a/docs/idabot.rst b/docs/idabot.rst
index 714ed3c..076123f 100644
--- a/docs/idabot.rst
+++ b/docs/idabot.rst
@@ -67,6 +67,22 @@ IDABot
 
       Move the camera to the position
 
+   .. method:: IDABot.ability_for_upgrade(self, UpgradeID)
+
+      Ability that researches this upgrade
+
+   .. method:: IDABot.upgrade_mineral_cost(self, UpgradeID)
+
+      Mineral cost of researching the upgrade
+
+   .. method:: IDABot.upgrade_gas_cost(self, UpgradeID)
+
+      Vespene/gas cost of researching the upgrade
+
+   .. method:: IDABot.upgrade_research_time(self, UpgradeID)
+
+      Time in GameLoops to research this upgrade
+
    Attributes:
 
    .. autoattribute:: minerals
diff --git a/python-api-src/lib_unittype.cpp b/python-api-src/lib_unittype.cpp
index a5dcc01..723f5e1 100644
--- a/python-api-src/lib_unittype.cpp
+++ b/python-api-src/lib_unittype.cpp
@@ -40,6 +40,9 @@ void define_unittype(py::module & m)
         .def_property_readonly("is_egg", &UnitType::isEgg)
         .def_property_readonly("is_queen", &UnitType::isQueen)
         .def_property_readonly("is_tank", &UnitType::isTank)
+		.def_property_readonly("get_equivalent_units", &UnitType::getEquivalentUnits)
+		.def_property_readonly("required_attached", &UnitType::requiredAttached)
+		.def_property_readonly("build_time", &UnitType::getBuildTime)
         .def("__hash__", [](const UnitType & unit_type) { return std::hash<CCUnitID>{}(unit_type.getAPIUnitType()); })
         .def(py::self == py::self)
         .def("__repr__", [](const UnitType & unit_type) { return "<UnitType: '" + unit_type.getName() + "'>"; });
diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp
index 7278c8a..77728c6 100644
--- a/python-api-src/library.cpp
+++ b/python-api-src/library.cpp
@@ -99,6 +99,10 @@ PYBIND11_MODULE(library, m)
 		.def("get_enemy_base_location", &IDABot::GetEnemyBaseLocations, "Return the CCpostion of the enemy base")
 		.def("move_camera", &IDABot::CameraMove, "Move the camera to p postion", "p"_a)
 		.def("has_creep", &IDABot::HasCreep, "Returns true if there is creep at position p", "p"_a)
+		.def("ability_for_upgrade", &IDABot::abilityForUpgrade, "Ability that researches this upgrade", "upgrade"_a)
+		.def("upgrade_mineral_cost", &IDABot::UpgradeMineralCost, "Mineral cost of researching the upgrade", "upgrade"_a)
+		.def("upgrade_gas_cost", &IDABot::UpgradeGasCost, "Vespene/gas cost of researching the upgrade", "upgrade"_a)
+		.def("upgrade_research_time", &IDABot::UpgradeResearchTime, "Time in GameLoops to research this upgrade", "upgrade"_a)
 		.def_property_readonly("base_location_manager", &IDABot::Bases)
 		.def_property_readonly("tech_tree", &IDABot::GetTechTree)
 		.def_property_readonly("map_tools", &IDABot::Map)
@@ -111,6 +115,9 @@ PYBIND11_MODULE(library, m)
 		.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 dc0cb36..b6330b5 100644
--- a/src/IDABot.cpp
+++ b/src/IDABot.cpp
@@ -320,7 +320,7 @@ void IDABot::DebugSetShields(float value, const Unit unit)
 	Debug()->DebugSetShields(value, unit.getUnitPtr());
 }
 
-// There is a bug in the latest SC2
+// There is a bug in the latest SC2 (if using Blizzard API with game >=4.10)
 // This a function to get the enemy base instead of using build location manager
 // Switched over to other API where this is solved
 // Leaving function incase of it breaking
@@ -329,10 +329,37 @@ const std::vector<Point2D> IDABot::GetEnemyBaseLocations()
 	return Observation()->GetGameInfo().enemy_start_locations;
 }
 
-bool IDABot::HasCreep(Point2D p) const {
+bool IDABot::HasCreep(Point2D p) const 
+{
 	return Observation()->HasCreep(p);
 }
 
-void IDABot::CameraMove(Point2DI p) {
+void IDABot::CameraMove(Point2DI p) 
+{
 	ActionsFeatureLayer()->CameraMove(p);
+}
+
+const char* IDABot::abilityForUpgrade(sc2::UpgradeID upgrade_id) const
+{
+	return sc2::AbilityTypeToName(Observation()->GetUpgradeData()[upgrade_id].ability_id);
+}
+
+uint32_t IDABot::UpgradeMineralCost(sc2::UpgradeID upgrade_id) const
+{
+	return Observation()->GetUpgradeData()[upgrade_id].mineral_cost;
+}
+
+uint32_t IDABot::UpgradeGasCost(sc2::UpgradeID upgrade_id) const
+{
+	return Observation()->GetUpgradeData()[upgrade_id].vespene_cost;
+}
+
+float IDABot::UpgradeResearchTime(sc2::UpgradeID upgrade_id) const
+{
+	return Observation()->GetUpgradeData()[upgrade_id].research_time;
+}
+
+float IDABot::RadiusEffect(sc2::EffectID effect_id) const
+{
+	return Observation()->GetEffectData()[effect_id].radius;
 }
\ No newline at end of file
diff --git a/src/IDABot.h b/src/IDABot.h
index b555084..4186904 100644
--- a/src/IDABot.h
+++ b/src/IDABot.h
@@ -87,6 +87,12 @@ public:
 	const std::vector<Point2D> GetEnemyBaseLocations();
 	bool HasCreep(Point2D p) const;
 	void CameraMove(Point2DI p);
+	const char* abilityForUpgrade(sc2::UpgradeID upgrade_id) const;
+	uint32_t UpgradeMineralCost(sc2::UpgradeID upgrade_id) const;
+	uint32_t UpgradeGasCost(sc2::UpgradeID upgrade_id) const;
+	float UpgradeResearchTime(sc2::UpgradeID upgrade_id) const;
+	float RadiusEffect(sc2::EffectID effect_id) const;
+
 
 
     // Not needed, just convenience functions
diff --git a/src/Unit.cpp b/src/Unit.cpp
index 12a5ac1..0fa7550 100644
--- a/src/Unit.cpp
+++ b/src/Unit.cpp
@@ -464,10 +464,10 @@ int Unit::getOwner() const
 // Implemented with Blizzard SC2 API
 bool Unit::isCarryingGas() const
 {
-	return m_bot->Observation()->IsUnitCarryVespene(*m_unit);
+	return sc2::IsCarryingVespene(*m_unit);
 }
 
 bool Unit::isCarryingMinerals() const
 {
-	return m_bot->Observation()->IsUnitCarryMineral(*m_unit);
+	return sc2::IsCarryingMinerals(*m_unit);
 }
\ No newline at end of file
diff --git a/src/UnitType.cpp b/src/UnitType.cpp
index 33013aa..cf69835 100644
--- a/src/UnitType.cpp
+++ b/src/UnitType.cpp
@@ -385,7 +385,22 @@ int UnitType::getSightRange() const
     return m_bot->Observation()->GetUnitTypeData()[m_type].sight_range;
 }
 
-sc2::UnitTypeID UnitType::getRequiredStructure() const
+UnitTypeID UnitType::getRequiredStructure() const
 {
     return m_bot->Observation()->GetUnitTypeData()[m_type].tech_requirement;
 }
+
+std::vector<sc2::UnitTypeID> UnitType::getEquivalentUnits() const
+{
+	return m_bot->Observation()->GetUnitTypeData()[m_type].tech_alias;
+}
+
+bool UnitType::requiredAttached() const
+{
+	return m_bot->Observation()->GetUnitTypeData()[m_type].require_attached;
+}
+
+float UnitType::getBuildTime() const
+{
+	return m_bot->Observation()->GetUnitTypeData()[m_type].build_time;
+}
\ No newline at end of file
diff --git a/src/UnitType.h b/src/UnitType.h
index 72ea028..7f3bbbe 100644
--- a/src/UnitType.h
+++ b/src/UnitType.h
@@ -2,6 +2,7 @@
 
 #include "Common.h"
 
+
 class IDABot;
 
 class UnitType
@@ -25,7 +26,7 @@ public:
 	
     int getMovementSpeed() const;
     int getSightRange() const;
-    sc2::UnitTypeID getRequiredStructure() const;
+	sc2::UnitTypeID getRequiredStructure() const;
     
     bool isValid() const;
     bool isBuilding() const;
@@ -50,6 +51,9 @@ public:
     int gasPrice() const;
 
     const std::vector<UnitType> & whatBuilds() const;
+	std::vector<sc2::UnitTypeID> getEquivalentUnits() const;
+	bool requiredAttached() const;
+	float getBuildTime() const;
 
     static UnitType GetUnitTypeFromName(const std::string & name, IDABot & bot);
 
-- 
GitLab