From 570f99b3fe918fab2b4703551ff3d599fdb30ee6 Mon Sep 17 00:00:00 2001
From: Sofia Abaied <sofab194@student.liu.se>
Date: Mon, 12 Nov 2018 15:59:24 +0100
Subject: [PATCH] Added isBlip() and getTarget() to Unit

---
 src/Unit.cpp | 27 ++++++++++++++++++++++++++-
 src/Unit.h   |  3 +++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/Unit.cpp b/src/Unit.cpp
index a189959..9b30f7b 100644
--- a/src/Unit.cpp
+++ b/src/Unit.cpp
@@ -296,4 +296,29 @@ bool Unit::isConstructing(const UnitType & type) const
 {
 	sc2::AbilityID buildAbility = m_bot->Data(type).buildAbility;
 	return (getUnitPtr()->orders.size() > 0) && (getUnitPtr()->orders[0].ability_id == buildAbility);
-}
\ No newline at end of file
+}
+
+Unit Unit::getTarget() const
+{
+        BOT_ASSERT(isValid(), "Unit is not valid");
+
+        //if unit has order, check tag of target of first order
+        if(getUnitPtr()->orders.size() > 0){
+          //pray that this value can be declared as CCUnitID
+	  CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
+          //let IDAbot find the unit with this tag
+          return m_bot->GetUnit(t_id);
+	}
+
+	return;
+}
+
+bool Unit::isBlip() const
+{
+	BOT_ASSERT(isValid(), "Unit is not valid");
+#ifdef SC2API
+	return m_unit->is_blip;
+#else
+	return m_unit->isBlip();
+#endif
+}
diff --git a/src/Unit.h b/src/Unit.h
index 5770bd8..fdfa940 100644
--- a/src/Unit.h
+++ b/src/Unit.h
@@ -47,6 +47,9 @@ public:
     bool isTraining() const;
     bool isConstructing(const UnitType & type) const;
 
+    bool isBlip() const;
+    Unit getTarget() const;
+
     void stop           () const;
     void attackUnit     (const Unit & target) const;
     void attackMove     (const CCPosition & targetPosition) const;
-- 
GitLab