(svn r13723) [NoAI] -Add: added AIIndustry::GetStockpiledCargo() (Yexo) noai
authortruebrain
Fri, 18 Jul 2008 00:15:14 +0000
branchnoai
changeset 11165 a725845fcc01
parent 11164 67338721eb26
child 11166 17960948c3af
(svn r13723) [NoAI] -Add: added AIIndustry::GetStockpiledCargo() (Yexo)
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
src/ai/api/ai_industry.cpp
src/ai/api/ai_industry.hpp
src/ai/api/ai_industry.hpp.sq
--- a/bin/ai/regression/regression.nut	Thu Jul 17 23:45:52 2008 +0000
+++ b/bin/ai/regression/regression.nut	Fri Jul 18 00:15:14 2008 +0000
@@ -604,8 +604,9 @@
 		local cargo_list = AICargoList();
 		for (local j = cargo_list.Begin(); cargo_list.HasNext(); j = cargo_list.Next()) {
 			if (AIIndustry.GetProduction(i, j) > 0) {
-				print("	   GetLastMonthProduction(): " + AIIndustry.GetLastMonthProduction(i, j));
+				print("	   GetLastMonthProduction():  " + AIIndustry.GetLastMonthProduction(i, j));
 				print("	   GetLastMonthTransported(): " + AIIndustry.GetLastMonthTransported(i, j));
+				print("	   GetStockpiledCargo():      " + AIIndustry.GetStockpiledCargo(i, j));
 			}
 		}
 	}
--- a/bin/ai/regression/regression.txt	Thu Jul 17 23:45:52 2008 +0000
+++ b/bin/ai/regression/regression.txt	Fri Jul 18 00:15:14 2008 +0000
@@ -4956,56 +4956,63 @@
     GetLocation():     45122
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 96
+	   GetLastMonthProduction():  96
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      12
   Industry 2
     IsValidIndustry(): true
     GetName():         Fudinghattan Forest
     GetLocation():     41929
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 56
+	   GetLastMonthProduction():  56
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      28
   Industry 3
     IsValidIndustry(): true
     GetName():         Benville Forest
     GetLocation():     44640
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 112
+	   GetLastMonthProduction():  112
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      14
   Industry 4
     IsValidIndustry(): true
     GetName():         Netfingbridge Forest
     GetLocation():     8793
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 120
+	   GetLastMonthProduction():  120
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      15
   Industry 5
     IsValidIndustry(): true
     GetName():         Hutfingford Forest
     GetLocation():     55429
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 112
+	   GetLastMonthProduction():  112
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      14
   Industry 6
     IsValidIndustry(): true
     GetName():         Great Hinninghall Forest
     GetLocation():     6533
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 72
+	   GetLastMonthProduction():  72
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 7
     IsValidIndustry(): true
     GetName():         Tondston Forest
     GetLocation():     27609
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 152
+	   GetLastMonthProduction():  152
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 8
     IsValidIndustry(): true
     GetName():         Planfield Sawmill
@@ -5054,80 +5061,90 @@
     GetLocation():     51854
     GetProduction():   144
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 144
+	   GetLastMonthProduction():  144
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 16
     IsValidIndustry(): true
     GetName():         Kennville Coal Mine
     GetLocation():     11734
     GetProduction():   112
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 112
+	   GetLastMonthProduction():  112
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 17
     IsValidIndustry(): true
     GetName():         Great Hinninghall Coal Mine
     GetLocation():     13947
     GetProduction():   160
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 160
+	   GetLastMonthProduction():  160
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 18
     IsValidIndustry(): true
     GetName():         Little Fruford Coal Mine
     GetLocation():     23682
     GetProduction():   136
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 136
+	   GetLastMonthProduction():  136
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 19
     IsValidIndustry(): true
     GetName():         Hutfingford Coal Mine
     GetLocation():     57429
     GetProduction():   112
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 112
+	   GetLastMonthProduction():  112
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 20
     IsValidIndustry(): true
     GetName():         Mendingston Coal Mine
     GetLocation():     8562
     GetProduction():   136
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 136
+	   GetLastMonthProduction():  136
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 21
     IsValidIndustry(): true
     GetName():         Tondston Coal Mine
     GetLocation():     29147
     GetProduction():   104
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 104
+	   GetLastMonthProduction():  104
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 22
     IsValidIndustry(): true
     GetName():         Quartfingfield Coal Mine
     GetLocation():     27822
     GetProduction():   152
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 152
+	   GetLastMonthProduction():  152
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 23
     IsValidIndustry(): true
     GetName():         Muningville Coal Mine
     GetLocation():     43035
     GetProduction():   96
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 96
+	   GetLastMonthProduction():  96
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 24
     IsValidIndustry(): true
     GetName():         Grinnway Coal Mine
     GetLocation():     17943
     GetProduction():   72
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 72
+	   GetLastMonthProduction():  72
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 25
     IsValidIndustry(): true
     GetName():         Sadtown Power Station
@@ -5176,204 +5193,237 @@
     GetLocation():     14701
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 120
+	   GetLastMonthProduction():  120
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 33
     IsValidIndustry(): true
     GetName():         Nuntfingburg Oil Wells
     GetLocation():     5659
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 64
+	   GetLastMonthProduction():  64
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 34
     IsValidIndustry(): true
     GetName():         Benville Oil Wells
     GetLocation():     36728
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 96
+	   GetLastMonthProduction():  96
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 35
     IsValidIndustry(): true
     GetName():         Grinnway Oil Wells
     GetLocation():     14361
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 96
+	   GetLastMonthProduction():  96
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 36
     IsValidIndustry(): true
     GetName():         Muningville Oil Wells
     GetLocation():     36908
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 96
+	   GetLastMonthProduction():  96
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 37
     IsValidIndustry(): true
     GetName():         Tondston Oil Wells
     GetLocation():     34237
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 128
+	   GetLastMonthProduction():  128
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      16
   Industry 38
     IsValidIndustry(): true
     GetName():         Fort Frindston Iron Ore Mine
     GetLocation():     17742
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 112
+	   GetLastMonthProduction():  112
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 39
     IsValidIndustry(): true
     GetName():         Tondston Iron Ore Mine
     GetLocation():     25545
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 40
+	   GetLastMonthProduction():  40
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 40
     IsValidIndustry(): true
     GetName():         Fudinghattan Iron Ore Mine
     GetLocation():     47838
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 72
+	   GetLastMonthProduction():  72
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 41
     IsValidIndustry(): true
     GetName():         Nuntfingburg Iron Ore Mine
     GetLocation():     8763
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 56
+	   GetLastMonthProduction():  56
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 42
     IsValidIndustry(): true
     GetName():         Lardborough Iron Ore Mine
     GetLocation():     60866
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 80
+	   GetLastMonthProduction():  80
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 43
     IsValidIndustry(): true
     GetName():         Tunford Iron Ore Mine
     GetLocation():     41155
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 96
+	   GetLastMonthProduction():  96
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 44
     IsValidIndustry(): true
     GetName():         Chentfingbourne Iron Ore Mine
     GetLocation():     19529
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 96
+	   GetLastMonthProduction():  96
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 45
     IsValidIndustry(): true
     GetName():         Naborough Farm
     GetLocation():     52931
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 80
+	   GetLastMonthProduction():  80
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 80
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  80
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 46
     IsValidIndustry(): true
     GetName():         Lardborough Farm
     GetLocation():     59604
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 80
+	   GetLastMonthProduction():  80
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 56
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  56
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 47
     IsValidIndustry(): true
     GetName():         Chentfingbourne Farm
     GetLocation():     24366
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 64
+	   GetLastMonthProduction():  64
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 48
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  48
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 48
     IsValidIndustry(): true
     GetName():         Wrundtown Farm
     GetLocation():     36847
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 88
+	   GetLastMonthProduction():  88
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 104
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  104
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 49
     IsValidIndustry(): true
     GetName():         Little Fruford Farm
     GetLocation():     28287
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 80
+	   GetLastMonthProduction():  80
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 40
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  40
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 50
     IsValidIndustry(): true
     GetName():         Hutfingford Farm
     GetLocation():     57432
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 112
+	   GetLastMonthProduction():  112
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 88
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  88
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 51
     IsValidIndustry(): true
     GetName():         Tondston Farm
     GetLocation():     23519
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 64
+	   GetLastMonthProduction():  64
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 64
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  64
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 52
     IsValidIndustry(): true
     GetName():         Nuntfingburg Farm
     GetLocation():     10773
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 104
+	   GetLastMonthProduction():  104
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 72
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  72
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 53
     IsValidIndustry(): true
     GetName():         Sadtown Farm
     GetLocation():     48206
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 96
+	   GetLastMonthProduction():  96
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 64
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  64
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 54
     IsValidIndustry(): true
     GetName():         Quartfingfield Farm
     GetLocation():     24005
     GetProduction():   -1
     IsCargoAccepted(): false
-	   GetLastMonthProduction(): 80
+	   GetLastMonthProduction():  80
 	   GetLastMonthTransported(): 0
-	   GetLastMonthProduction(): 96
+	   GetStockpiledCargo():      0
+	   GetLastMonthProduction():  96
 	   GetLastMonthTransported(): 0
+	   GetStockpiledCargo():      0
   Industry 55
     IsValidIndustry(): true
     GetName():         Little Fruford Steel Mill
--- a/src/ai/api/ai_industry.cpp	Thu Jul 17 23:45:52 2008 +0000
+++ b/src/ai/api/ai_industry.cpp	Fri Jul 18 00:15:14 2008 +0000
@@ -67,6 +67,22 @@
 	return false;
 }
 
+/* static */ int32 AIIndustry::GetStockpiledCargo(IndustryID industry_id, CargoID cargo_id)
+{
+	if (!IsValidIndustry(industry_id)) return -1;
+	if (!AICargo::IsValidCargo(cargo_id)) return -1;
+
+	Industry *ind = ::GetIndustry(industry_id);
+	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
+		CargoID cargo_id = ind->produced_cargo[i];
+		if (cargo_id == cargo_id) {
+			return ind->produced_cargo_waiting[i];
+		}
+	}
+
+	return -1;
+}
+
 /* static */ int32 AIIndustry::GetLastMonthProduction(IndustryID industry_id, CargoID cargo_id)
 {
 	if (!IsValidIndustry(industry_id)) return -1;
--- a/src/ai/api/ai_industry.hpp	Thu Jul 17 23:45:52 2008 +0000
+++ b/src/ai/api/ai_industry.hpp	Fri Jul 18 00:15:14 2008 +0000
@@ -67,6 +67,16 @@
 	static bool IsCargoAccepted(IndustryID industry_id, CargoID cargo_id);
 
 	/**
+	 * Get the amount of cargo stockpiled for processing.
+	 * @param industry_id The index of the industry.
+	 * @param cargo_id The index of the cargo.
+	 * @pre IsValidIndustry(industry_id).
+	 * @pre AICargo::IsValidCargo(cargo_id).
+	 * @return The amount of cargo that is waiting for processing.
+	 */
+	static int32 GetStockpiledCargo(IndustryID industry_id, CargoID cargo_id);
+
+	/**
 	 * Get the total last month's production of the given cargo at an industry.
 	 * @param industry_id The index of the industry.
 	 * @param cargo_id The index of the cargo.
--- a/src/ai/api/ai_industry.hpp.sq	Thu Jul 17 23:45:52 2008 +0000
+++ b/src/ai/api/ai_industry.hpp.sq	Fri Jul 18 00:15:14 2008 +0000
@@ -24,6 +24,7 @@
 	SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetName,                    "GetName",                    2, "xi");
 	SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetProduction,              "GetProduction",              3, "xii");
 	SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsCargoAccepted,            "IsCargoAccepted",            3, "xii");
+	SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetStockpiledCargo,         "GetStockpiledCargo",         3, "xii");
 	SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLastMonthProduction,     "GetLastMonthProduction",     3, "xii");
 	SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLastMonthTransported,    "GetLastMonthTransported",    3, "xii");
 	SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLocation,                "GetLocation",                2, "xi");