(svn r13407) [NoAI] -Add: added AICompany::IsMine() to ease up owner-checks (no, not the ones to cash in money) noai
authortruebrain
Sat, 07 Jun 2008 23:30:41 +0000
branchnoai
changeset 10856 c7b29152d594
parent 10855 90904faa1890
child 10859 4c14a8041c0a
(svn r13407) [NoAI] -Add: added AICompany::IsMine() to ease up owner-checks (no, not the ones to cash in money)
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
src/ai/api/ai_company.cpp
src/ai/api/ai_company.hpp
src/ai/api/ai_company.hpp.sq
--- a/bin/ai/regression/regression.nut	Sat Jun 07 23:08:42 2008 +0000
+++ b/bin/ai/regression/regression.nut	Sat Jun 07 23:30:41 2008 +0000
@@ -793,6 +793,7 @@
 		print("    GetText():       " + AISign.GetText(i));
 		print("    GetLocation():   " + AISign.GetLocation(i));
 		print("    GetOwner():      " + AISign.GetOwner(i));
+		print("    IsMine():        " + AICompany.IsMine(AISign.GetOwner(i)));
 	}
 	print("  Valid Signs:       " + j);
 }
--- a/bin/ai/regression/regression.txt	Sat Jun 07 23:08:42 2008 +0000
+++ b/bin/ai/regression/regression.txt	Sat Jun 07 23:30:41 2008 +0000
@@ -5785,26 +5785,31 @@
     GetText():       (null : 0x00000000)
     GetLocation():   -1
     GetOwner():      -1
+    IsMine():        false
   Sign 0
     IsValidSign():   true
     GetText():       Some Sign
     GetLocation():   33410
     GetOwner():      1
+    IsMine():        true
   Sign 1
     IsValidSign():   false
     GetText():       (null : 0x00000000)
     GetLocation():   -1
     GetOwner():      -1
+    IsMine():        false
   Sign 2
     IsValidSign():   false
     GetText():       (null : 0x00000000)
     GetLocation():   -1
     GetOwner():      -1
+    IsMine():        false
   Sign 3
     IsValidSign():   false
     GetText():       (null : 0x00000000)
     GetLocation():   -1
     GetOwner():      -1
+    IsMine():        false
   Valid Signs:       1
 
 --Station--
--- a/src/ai/api/ai_company.cpp	Sat Jun 07 23:08:42 2008 +0000
+++ b/src/ai/api/ai_company.cpp	Sat Jun 07 23:30:41 2008 +0000
@@ -23,6 +23,11 @@
 	return (::IsValidPlayer((PlayerID)company) && ::GetPlayer((PlayerID)company)->is_active) ? company : INVALID_COMPANY;
 }
 
+/* static */ bool AICompany::IsMine(AICompany::CompanyID company)
+{
+	return ResolveCompanyID(company) == ResolveCompanyID(MY_COMPANY);
+}
+
 /* static */ bool AICompany::SetCompanyName(const char *name)
 {
 	EnforcePrecondition(false, !::StrEmpty(name));
--- a/src/ai/api/ai_company.hpp	Sat Jun 07 23:08:42 2008 +0000
+++ b/src/ai/api/ai_company.hpp	Sat Jun 07 23:30:41 2008 +0000
@@ -33,6 +33,13 @@
 	static CompanyID ResolveCompanyID(CompanyID company);
 
 	/**
+	 * Check if a CompanyID is your CompanyID, to ease up checks.
+	 * @param company The company index to check.
+	 * @return True if and only if this company is your CompanyID.
+	 */
+	static bool IsMine(CompanyID company);
+
+	/**
 	 * Set the name of your company.
 	 * @param name The new name of the company.
 	 * @pre 'name' must have at least one character.
--- a/src/ai/api/ai_company.hpp.sq	Sat Jun 07 23:08:42 2008 +0000
+++ b/src/ai/api/ai_company.hpp.sq	Sat Jun 07 23:30:41 2008 +0000
@@ -21,13 +21,14 @@
 	SQAICompany.PreRegister(engine);
 	SQAICompany.AddConstructor<void (AICompany::*)(), 1>(engine, "x");
 
+	SQAICompany.DefSQConst(engine, AICompany::INVALID_COMPANY, "INVALID_COMPANY");
 	SQAICompany.DefSQConst(engine, AICompany::FIRST_COMPANY,   "FIRST_COMPANY");
 	SQAICompany.DefSQConst(engine, AICompany::LAST_COMPANY,    "LAST_COMPANY");
 	SQAICompany.DefSQConst(engine, AICompany::MY_COMPANY,      "MY_COMPANY");
-	SQAICompany.DefSQConst(engine, AICompany::INVALID_COMPANY, "INVALID_COMPANY");
 
 	SQAICompany.DefSQStaticMethod(engine, &AICompany::GetClassName,         "GetClassName",         1, "x");
 	SQAICompany.DefSQStaticMethod(engine, &AICompany::ResolveCompanyID,     "ResolveCompanyID",     2, "xi");
+	SQAICompany.DefSQStaticMethod(engine, &AICompany::IsMine,               "IsMine",               2, "xi");
 	SQAICompany.DefSQStaticMethod(engine, &AICompany::SetCompanyName,       "SetCompanyName",       2, "xs");
 	SQAICompany.DefSQStaticMethod(engine, &AICompany::GetCompanyName,       "GetCompanyName",       2, "xi");
 	SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentName,     "SetPresidentName",     2, "xs");