From 534b89cfca08a35d5a425681df2f227f954994a5 Mon Sep 17 00:00:00 2001
From: David Warnquist <davwa458@student.liu.se>
Date: Tue, 2 Jul 2024 16:42:36 +0200
Subject: [PATCH] Updated segfault guards and added concussionshell alias

---
 python-api-src/lib_sc2_typeenums.cpp |  1 +
 src/UnitType.cpp                     | 52 ++++++++++++++--------------
 2 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/python-api-src/lib_sc2_typeenums.cpp b/python-api-src/lib_sc2_typeenums.cpp
index eeb8338dd..091ffb704 100644
--- a/python-api-src/lib_sc2_typeenums.cpp
+++ b/python-api-src/lib_sc2_typeenums.cpp
@@ -3382,6 +3382,7 @@ void define_typeenums(py::module & m)
 		.value("PSIDISRUPTOR", sc2::UPGRADE_ID::PSIDISRUPTOR)
 		.value("PSIONICAMPLIFIERS", sc2::UPGRADE_ID::PSIONICAMPLIFIERS)
 		.value("PSISTORMTECH", sc2::UPGRADE_ID::PSISTORMTECH)
+		.value("CONCUSSIONSHELLS", sc2::UPGRADE_ID::PUNISHERGRENADES)
 		.value("PUNISHERGRENADES", sc2::UPGRADE_ID::PUNISHERGRENADES)
 		.value("RAPIDDEPLOYMENT", sc2::UPGRADE_ID::RAPIDDEPLOYMENT)
 		.value("RAVAGERRANGE", sc2::UPGRADE_ID::RAVAGERRANGE)
diff --git a/src/UnitType.cpp b/src/UnitType.cpp
index 688ccb4c7..6572513b2 100644
--- a/src/UnitType.cpp
+++ b/src/UnitType.cpp
@@ -73,7 +73,7 @@ CCRace UnitType::getRace() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
+        std::cout << "Failed to get race, try with game running!" << std::endl;
         return CCRace::Random;
     }
     return UTData[m_type].race;
@@ -234,7 +234,7 @@ bool UnitType::canAttackGound() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
+        std::cout << "Failed canAttackGround, try with game running!" << std::endl;
         return false;
     }
 	auto & weapons = UTData[m_type].weapons;
@@ -265,7 +265,7 @@ bool UnitType::canAttackAir() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
+        std::cout << "Failed canAttackAir, try with game running!" << std::endl;
         return false;
     }
 	auto & weapons = UTData[m_type].weapons;
@@ -295,7 +295,7 @@ CCPositionType UnitType::getAttackRange() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
+        std::cout << "Failed getAttackRange, try with game running!" << std::endl;
         return 0.0f;
     }
     auto & weapons = UTData[m_type].weapons;
@@ -327,7 +327,7 @@ float UnitType::getAttackDamage() const
 	auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
+        std::cout << "Failed getAttackDamage, try with game running!" << std::endl;
         return 0.0f;
     }
     auto & weapons = UTData[m_type].weapons;
@@ -362,8 +362,8 @@ int UnitType::tileWidth() const
         auto UTData = m_client->Observation()->GetAbilityData();
         if (UTData.empty()) // Check to hopefully avoid segfaults
         {
-            BOT_ASSERT(false, "Failed, try with game running!");
-            return -1;
+            std::cout << "Failed tileWidth, try with game running!" << std::endl;
+            return 0;
         }
 
 		else if (m_bot != nullptr)
@@ -393,8 +393,8 @@ int UnitType::tileHeight() const
         auto UTData = m_client->Observation()->GetAbilityData();
         if (UTData.empty()) // Check to hopefully avoid segfaults
         {
-            BOT_ASSERT(false, "Failed, try with game running!");
-            return -1;
+            std::cout << "Failed tileHeight, try with game running!" << std::endl;
+            return 0;
         }
 
 		else if (m_bot != nullptr)
@@ -464,8 +464,8 @@ int UnitType::supplyProvided() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
-        return -1;
+        std::cout << "Failed supplyProvided, try with game running!" << std::endl;
+        return 0;
     }
 
     return (int)UTData[m_type].food_provided;
@@ -480,8 +480,8 @@ int UnitType::supplyRequired() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
-        return -1;
+        std::cout << "Failed supplyRequired, try with game running!" << std::endl;
+        return 0;
     }
 
     return (int)UTData[m_type].food_required;
@@ -496,8 +496,8 @@ int UnitType::mineralPrice() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
-        return -1;
+        std::cout << "Failed mineralPrice, try with game running!" << std::endl;
+        return 0;
     }
     return (int)UTData[m_type].mineral_cost;
 #else
@@ -511,8 +511,8 @@ int UnitType::gasPrice() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
-        return -1;
+        std::cout << "Failed gasPrice, try with game running!" << std::endl;
+        return 0;
     }
     return (int)UTData[m_type].vespene_cost;
 #else
@@ -609,8 +609,8 @@ int UnitType::getMovementSpeed() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
-        return -1;
+        std::cout << "Failed getMovementSpeed, try with game running!" << std::endl;
+        return 0;
     }
     return UTData[m_type].movement_speed;
 }
@@ -620,8 +620,8 @@ int UnitType::getSightRange() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
-        return -1;
+        std::cout << "Failed getSightRange, try with game running!" << std::endl;
+        return 0;
     }
     return UTData[m_type].sight_range;
 }
@@ -631,7 +631,7 @@ UnitTypeID UnitType::getRequiredStructure() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
+        std::cout << "Failed getRequiredStructure, try with game running!" << std::endl;
         return UnitTypeID();
     }
     return UTData[m_type].tech_requirement;
@@ -642,7 +642,7 @@ std::vector<sc2::UnitTypeID> UnitType::getEquivalentUnits() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
+        std::cout << "Failed getEquivalentUnits, try with game running!" << std::endl;
         return std::vector<sc2::UnitTypeID>();
     }
     return UTData[m_type].tech_alias;
@@ -653,7 +653,7 @@ bool UnitType::requiredAttached() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
+        std::cout << "Failed requiredAttached, try with game running!" << std::endl;
         return false;
     }
     return UTData[m_type].require_attached;
@@ -664,8 +664,8 @@ float UnitType::getBuildTime() const
     auto UTData = m_client->Observation()->GetUnitTypeData();
     if (UTData.empty()) // Check to hopefully avoid segfaults
     {
-        BOT_ASSERT(false, "Failed, try with game running!");
-        return -1;
+        std::cout << "Failed getBuildTime, try with game running!" << std::endl;
+        return 0.0f;
     }
     return UTData[m_type].build_time;
 }
\ No newline at end of file
-- 
GitLab