changeset 16919:54eef81c6cb4 draft

(svn r21654) -Add: [NoAI] AITown::IsCity() so AIs can find out which towns grow faster than others (Lord Aro)
author yexo <yexo@openttd.org>
date Wed, 29 Dec 2010 12:19:33 +0000
parents ab6c96ab6f58
children c74988aa2403
files bin/ai/regression/regression.nut bin/ai/regression/regression.txt src/ai/api/ai_town.cpp src/ai/api/ai_town.hpp src/ai/api/ai_town.hpp.sq
diffstat 5 files changed, 45 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/bin/ai/regression/regression.nut
+++ b/bin/ai/regression/regression.nut
@@ -1477,6 +1477,7 @@
 		print("    GetLocation():   " + AITown.GetLocation(i));
 		print("    GetHouseCount(): " + AITown.GetHouseCount(i));
 		print("    GetRating():     " + AITown.GetRating(i, AICompany.COMPANY_SELF));
+		print("    IsCity():        " + AITown.IsCity(i));
 	}
 	print("  Valid Towns:       " + j);
 	print("  GetTownCount():    " + AITown.GetTownCount());
--- a/bin/ai/regression/regression.txt
+++ b/bin/ai/regression/regression.txt
@@ -7980,6 +7980,7 @@
     GetLocation():   15508
     GetHouseCount(): 30
     GetRating():     0
+    IsCity():        true
   Town 1
     IsValidTown():   true
     GetName():       Trenningville
@@ -7987,6 +7988,7 @@
     GetLocation():   46751
     GetHouseCount(): 17
     GetRating():     0
+    IsCity():        false
   Town 2
     IsValidTown():   true
     GetName():       Tonston
@@ -7994,6 +7996,7 @@
     GetLocation():   28365
     GetHouseCount(): 19
     GetRating():     0
+    IsCity():        false
   Town 3
     IsValidTown():   true
     GetName():       Tunford
@@ -8001,6 +8004,7 @@
     GetLocation():   41895
     GetHouseCount(): 11
     GetRating():     0
+    IsCity():        false
   Town 4
     IsValidTown():   true
     GetName():       Wruntown
@@ -8008,6 +8012,7 @@
     GetLocation():   41450
     GetHouseCount(): 18
     GetRating():     0
+    IsCity():        true
   Town 5
     IsValidTown():   true
     GetName():       Fratston
@@ -8015,6 +8020,7 @@
     GetLocation():   55007
     GetHouseCount(): 11
     GetRating():     0
+    IsCity():        false
   Town 6
     IsValidTown():   true
     GetName():       Muningville
@@ -8022,6 +8028,7 @@
     GetLocation():   38200
     GetHouseCount(): 28
     GetRating():     0
+    IsCity():        false
   Town 7
     IsValidTown():   true
     GetName():       Hutford
@@ -8029,6 +8036,7 @@
     GetLocation():   59234
     GetHouseCount(): 33
     GetRating():     0
+    IsCity():        false
   Town 8
     IsValidTown():   true
     GetName():       Satown
@@ -8036,6 +8044,7 @@
     GetLocation():   51267
     GetHouseCount(): 20
     GetRating():     0
+    IsCity():        true
   Town 9
     IsValidTown():   true
     GetName():       Frindinghattan
@@ -8043,6 +8052,7 @@
     GetLocation():   5825
     GetHouseCount(): 18
     GetRating():     0
+    IsCity():        false
   Town 10
     IsValidTown():   true
     GetName():       Nuntburg
@@ -8050,6 +8060,7 @@
     GetLocation():   6446
     GetHouseCount(): 26
     GetRating():     6
+    IsCity():        false
   Town 11
     IsValidTown():   true
     GetName():       Fort Frindston
@@ -8057,6 +8068,7 @@
     GetLocation():   14935
     GetHouseCount(): 13
     GetRating():     0
+    IsCity():        false
   Town 12
     IsValidTown():   true
     GetName():       Gintborough
@@ -8064,6 +8076,7 @@
     GetLocation():   32740
     GetHouseCount(): 28
     GetRating():     0
+    IsCity():        true
   Town 13
     IsValidTown():   true
     GetName():       Great Hinninghall
@@ -8071,6 +8084,7 @@
     GetLocation():   9595
     GetHouseCount(): 14
     GetRating():     0
+    IsCity():        false
   Town 14
     IsValidTown():   true
     GetName():       Prundinghall
@@ -8078,6 +8092,7 @@
     GetLocation():   51298
     GetHouseCount(): 18
     GetRating():     0
+    IsCity():        false
   Town 15
     IsValidTown():   true
     GetName():       Beningville
@@ -8085,6 +8100,7 @@
     GetLocation():   42338
     GetHouseCount(): 33
     GetRating():     6
+    IsCity():        false
   Town 16
     IsValidTown():   true
     GetName():       Kennville
@@ -8092,6 +8108,7 @@
     GetLocation():   17345
     GetHouseCount(): 33
     GetRating():     0
+    IsCity():        true
   Town 17
     IsValidTown():   true
     GetName():       Quarfingfield
@@ -8099,6 +8116,7 @@
     GetLocation():   24252
     GetHouseCount(): 13
     GetRating():     0
+    IsCity():        false
   Town 18
     IsValidTown():   true
     GetName():       Nefingbridge
@@ -8106,6 +8124,7 @@
     GetLocation():   10574
     GetHouseCount(): 13
     GetRating():     0
+    IsCity():        false
   Town 19
     IsValidTown():   true
     GetName():       Mendston
@@ -8113,6 +8132,7 @@
     GetLocation():   6511
     GetHouseCount(): 14
     GetRating():     0
+    IsCity():        false
   Town 20
     IsValidTown():   true
     GetName():       Chenfingbourne
@@ -8120,6 +8140,7 @@
     GetLocation():   22585
     GetHouseCount(): 15
     GetRating():     6
+    IsCity():        true
   Town 21
     IsValidTown():   true
     GetName():       Franinghead
@@ -8127,6 +8148,7 @@
     GetLocation():   9634
     GetHouseCount(): 27
     GetRating():     0
+    IsCity():        false
   Town 22
     IsValidTown():   true
     GetName():       Natborough
@@ -8134,6 +8156,7 @@
     GetLocation():   51891
     GetHouseCount(): 12
     GetRating():     0
+    IsCity():        false
   Town 23
     IsValidTown():   true
     GetName():       Larborough
@@ -8141,6 +8164,7 @@
     GetLocation():   59622
     GetHouseCount(): 27
     GetRating():     0
+    IsCity():        false
   Town 24
     IsValidTown():   true
     GetName():       Little Frutford
@@ -8148,6 +8172,7 @@
     GetLocation():   19596
     GetHouseCount(): 34
     GetRating():     4
+    IsCity():        true
   Town 25
     IsValidTown():   true
     GetName():       Grinnway
@@ -8155,6 +8180,7 @@
     GetLocation():   16433
     GetHouseCount(): 15
     GetRating():     0
+    IsCity():        false
   Town 26
     IsValidTown():   true
     GetName():       Beburg
@@ -8162,6 +8188,7 @@
     GetLocation():   39505
     GetHouseCount(): 18
     GetRating():     0
+    IsCity():        false
   Town 27
     IsValidTown():   true
     GetName():       Fudhattan
@@ -8169,6 +8196,7 @@
     GetLocation():   45525
     GetHouseCount(): 19
     GetRating():     0
+    IsCity():        false
   Valid Towns:       28
   GetTownCount():    28
 
--- a/src/ai/api/ai_town.cpp
+++ b/src/ai/api/ai_town.cpp
@@ -129,6 +129,13 @@
 	return ::HasBit(::Town::Get(town_id)->statues, _current_company);
 }
 
+/* static */ bool AITown::IsCity(TownID town_id)
+{
+	if (!IsValidTown(town_id)) return false;
+
+	return ::Town::Get(town_id)->larger_town;
+}
+
 /* static */ int AITown::GetRoadReworkDuration(TownID town_id)
 {
 	if (!IsValidTown(town_id)) return -1;
--- a/src/ai/api/ai_town.hpp
+++ b/src/ai/api/ai_town.hpp
@@ -227,6 +227,14 @@
 	static bool HasStatue(TownID town_id);
 
 	/**
+	 * Find out if the town is a city.
+	 * @param town_id The town to check.
+	 * @pre IsValidTown(town_id).
+	 * @return True if the town is a city.
+	 */
+	static bool IsCity(TownID town_id);
+
+	/**
 	 * Find out how long the town is undergoing road reconstructions.
 	 * @param town_id The town to check.
 	 * @pre IsValidTown(town_id).
--- a/src/ai/api/ai_town.hpp.sq
+++ b/src/ai/api/ai_town.hpp.sq
@@ -71,6 +71,7 @@
 	SQAITown.DefSQStaticMethod(engine, &AITown::GetDistanceSquareToTile,           "GetDistanceSquareToTile",           3, ".ii");
 	SQAITown.DefSQStaticMethod(engine, &AITown::IsWithinTownInfluence,             "IsWithinTownInfluence",             3, ".ii");
 	SQAITown.DefSQStaticMethod(engine, &AITown::HasStatue,                         "HasStatue",                         2, ".i");
+	SQAITown.DefSQStaticMethod(engine, &AITown::IsCity,                            "IsCity",                            2, ".i");
 	SQAITown.DefSQStaticMethod(engine, &AITown::GetRoadReworkDuration,             "GetRoadReworkDuration",             2, ".i");
 	SQAITown.DefSQStaticMethod(engine, &AITown::GetExclusiveRightsCompany,         "GetExclusiveRightsCompany",         2, ".i");
 	SQAITown.DefSQStaticMethod(engine, &AITown::GetExclusiveRightsDuration,        "GetExclusiveRightsDuration",        2, ".i");