--- a/bin/ai/regression/regression.nut Sun Mar 02 13:19:08 2008 +0000
+++ b/bin/ai/regression/regression.nut Mon Mar 03 16:15:24 2008 +0000
@@ -355,6 +355,14 @@
print(" GetLocation(): " + AIIndustry.GetLocation(i));
print(" GetProduction(): " + AIIndustry.GetProduction(i, 1));
print(" IsCargoAccepted(): " + AIIndustry.IsCargoAccepted(i, 1));
+
+ 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(" GetLastMonthTransported(): " + AIIndustry.GetLastMonthTransported(i, j));
+ }
+ }
}
print(" Valid Industries: " + j);
print(" GetIndustryCount(): " + AIIndustry.GetIndustryCount());
--- a/bin/ai/regression/regression.txt Sun Mar 02 13:19:08 2008 +0000
+++ b/bin/ai/regression/regression.txt Mon Mar 03 16:15:24 2008 +0000
@@ -4315,42 +4315,56 @@
GetLocation(): 45122
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 96
+ GetLastMonthTransported(): 0
Industry 2
IsValidIndustry(): true
GetName(): Fudinghattan Forest
GetLocation(): 41929
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 56
+ GetLastMonthTransported(): 0
Industry 3
IsValidIndustry(): true
GetName(): Benville Forest
GetLocation(): 44640
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 112
+ GetLastMonthTransported(): 0
Industry 4
IsValidIndustry(): true
GetName(): Netfingbridge Forest
GetLocation(): 8793
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 120
+ GetLastMonthTransported(): 0
Industry 5
IsValidIndustry(): true
GetName(): Hutfingford Forest
GetLocation(): 55429
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 112
+ GetLastMonthTransported(): 0
Industry 6
IsValidIndustry(): true
GetName(): Great Hinninghall Forest
GetLocation(): 6533
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 72
+ GetLastMonthTransported(): 0
Industry 7
IsValidIndustry(): true
GetName(): Tondston Forest
GetLocation(): 27609
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 152
+ GetLastMonthTransported(): 0
Industry 8
IsValidIndustry(): true
GetName(): Planfield Sawmill
@@ -4399,60 +4413,80 @@
GetLocation(): 51854
GetProduction(): 144
IsCargoAccepted(): false
+ GetLastMonthProduction(): 144
+ GetLastMonthTransported(): 0
Industry 16
IsValidIndustry(): true
GetName(): Kennville Coal Mine
GetLocation(): 11734
GetProduction(): 112
IsCargoAccepted(): false
+ GetLastMonthProduction(): 112
+ GetLastMonthTransported(): 0
Industry 17
IsValidIndustry(): true
GetName(): Great Hinninghall Coal Mine
GetLocation(): 13947
GetProduction(): 160
IsCargoAccepted(): false
+ GetLastMonthProduction(): 160
+ GetLastMonthTransported(): 0
Industry 18
IsValidIndustry(): true
GetName(): Little Fruford Coal Mine
GetLocation(): 23682
GetProduction(): 136
IsCargoAccepted(): false
+ GetLastMonthProduction(): 136
+ GetLastMonthTransported(): 0
Industry 19
IsValidIndustry(): true
GetName(): Hutfingford Coal Mine
GetLocation(): 57429
GetProduction(): 112
IsCargoAccepted(): false
+ GetLastMonthProduction(): 112
+ GetLastMonthTransported(): 0
Industry 20
IsValidIndustry(): true
GetName(): Mendingston Coal Mine
GetLocation(): 8562
GetProduction(): 136
IsCargoAccepted(): false
+ GetLastMonthProduction(): 136
+ GetLastMonthTransported(): 0
Industry 21
IsValidIndustry(): true
GetName(): Tondston Coal Mine
GetLocation(): 29147
GetProduction(): 104
IsCargoAccepted(): false
+ GetLastMonthProduction(): 104
+ GetLastMonthTransported(): 0
Industry 22
IsValidIndustry(): true
GetName(): Quartfingfield Coal Mine
GetLocation(): 27822
GetProduction(): 152
IsCargoAccepted(): false
+ GetLastMonthProduction(): 152
+ GetLastMonthTransported(): 0
Industry 23
IsValidIndustry(): true
GetName(): Muningville Coal Mine
GetLocation(): 43035
GetProduction(): 96
IsCargoAccepted(): false
+ GetLastMonthProduction(): 96
+ GetLastMonthTransported(): 0
Industry 24
IsValidIndustry(): true
GetName(): Grinnway Coal Mine
GetLocation(): 17943
GetProduction(): 72
IsCargoAccepted(): false
+ GetLastMonthProduction(): 72
+ GetLastMonthTransported(): 0
Industry 25
IsValidIndustry(): true
GetName(): Sadtown Power Station
@@ -4501,138 +4535,204 @@
GetLocation(): 14701
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 120
+ GetLastMonthTransported(): 0
Industry 33
IsValidIndustry(): true
GetName(): Nuntfingburg Oil Wells
GetLocation(): 5659
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 64
+ GetLastMonthTransported(): 0
Industry 34
IsValidIndustry(): true
GetName(): Benville Oil Wells
GetLocation(): 36728
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 96
+ GetLastMonthTransported(): 0
Industry 35
IsValidIndustry(): true
GetName(): Grinnway Oil Wells
GetLocation(): 14361
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 96
+ GetLastMonthTransported(): 0
Industry 36
IsValidIndustry(): true
GetName(): Muningville Oil Wells
GetLocation(): 36908
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 96
+ GetLastMonthTransported(): 0
Industry 37
IsValidIndustry(): true
GetName(): Tondston Oil Wells
GetLocation(): 34237
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 128
+ GetLastMonthTransported(): 0
Industry 38
IsValidIndustry(): true
GetName(): Fort Frindston Iron Ore Mine
GetLocation(): 17742
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 112
+ GetLastMonthTransported(): 0
Industry 39
IsValidIndustry(): true
GetName(): Tondston Iron Ore Mine
GetLocation(): 25545
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 40
+ GetLastMonthTransported(): 0
Industry 40
IsValidIndustry(): true
GetName(): Fudinghattan Iron Ore Mine
GetLocation(): 47838
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 72
+ GetLastMonthTransported(): 0
Industry 41
IsValidIndustry(): true
GetName(): Nuntfingburg Iron Ore Mine
GetLocation(): 8763
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 56
+ GetLastMonthTransported(): 0
Industry 42
IsValidIndustry(): true
GetName(): Lardborough Iron Ore Mine
GetLocation(): 60866
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 80
+ GetLastMonthTransported(): 0
Industry 43
IsValidIndustry(): true
GetName(): Tunford Iron Ore Mine
GetLocation(): 41155
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 96
+ GetLastMonthTransported(): 0
Industry 44
IsValidIndustry(): true
GetName(): Chentfingbourne Iron Ore Mine
GetLocation(): 19529
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 96
+ GetLastMonthTransported(): 0
Industry 45
IsValidIndustry(): true
GetName(): Naborough Farm
GetLocation(): 52931
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 80
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 80
+ GetLastMonthTransported(): 0
Industry 46
IsValidIndustry(): true
GetName(): Lardborough Farm
GetLocation(): 59604
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 80
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 56
+ GetLastMonthTransported(): 0
Industry 47
IsValidIndustry(): true
GetName(): Chentfingbourne Farm
GetLocation(): 24366
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 64
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 48
+ GetLastMonthTransported(): 0
Industry 48
IsValidIndustry(): true
GetName(): Wrundtown Farm
GetLocation(): 36847
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 88
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 104
+ GetLastMonthTransported(): 0
Industry 49
IsValidIndustry(): true
GetName(): Little Fruford Farm
GetLocation(): 28287
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 80
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 40
+ GetLastMonthTransported(): 0
Industry 50
IsValidIndustry(): true
GetName(): Hutfingford Farm
GetLocation(): 57432
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 112
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 88
+ GetLastMonthTransported(): 0
Industry 51
IsValidIndustry(): true
GetName(): Tondston Farm
GetLocation(): 23519
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 64
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 64
+ GetLastMonthTransported(): 0
Industry 52
IsValidIndustry(): true
GetName(): Nuntfingburg Farm
GetLocation(): 10773
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 104
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 72
+ GetLastMonthTransported(): 0
Industry 53
IsValidIndustry(): true
GetName(): Sadtown Farm
GetLocation(): 48206
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 96
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 64
+ GetLastMonthTransported(): 0
Industry 54
IsValidIndustry(): true
GetName(): Quartfingfield Farm
GetLocation(): 24005
GetProduction(): -1
IsCargoAccepted(): false
+ GetLastMonthProduction(): 80
+ GetLastMonthTransported(): 0
+ GetLastMonthProduction(): 96
+ GetLastMonthTransported(): 0
Industry 55
IsValidIndustry(): true
GetName(): Little Fruford Steel Mill
--- a/src/ai/api/ai_industry.cpp Sun Mar 02 13:19:08 2008 +0000
+++ b/src/ai/api/ai_industry.cpp Mon Mar 03 16:15:24 2008 +0000
@@ -68,3 +68,31 @@
if (!IsValidIndustry(industry_id)) return INVALID_TILE;
return ::GetIndustry(industry_id)->xy;
}
+
+/* static */ uint16 AIIndustry::GetLastMonthProduction(IndustryID industry_id, CargoID cargo_id)
+{
+ if (!IsValidIndustry(industry_id)) return false;
+ if (!AICargo::IsValidCargo(cargo_id)) return false;
+
+ const Industry *i = ::GetIndustry(industry_id);
+ const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
+
+ for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
+ if (indsp->produced_cargo[j] == cargo_id) return i->last_month_production[j];
+
+ return false;
+}
+
+/* static */ uint16 AIIndustry::GetLastMonthTransported(IndustryID industry_id, CargoID cargo_id)
+{
+ if (!IsValidIndustry(industry_id)) return false;
+ if (!AICargo::IsValidCargo(cargo_id)) return false;
+
+ const Industry *i = ::GetIndustry(industry_id);
+ const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
+
+ for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
+ if (indsp->produced_cargo[j] == cargo_id) return i->last_month_transported[j];
+
+ return false;
+}
--- a/src/ai/api/ai_industry.hpp Sun Mar 02 13:19:08 2008 +0000
+++ b/src/ai/api/ai_industry.hpp Mon Mar 03 16:15:24 2008 +0000
@@ -79,6 +79,27 @@
* @post return value is always valid with AIMap::IsValidTile().
*/
static TileIndex GetLocation(IndustryID industry_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.
+ * @pre industry_id has to be valid (use IsValidIndustry()).
+ * @pre cargo_id has to be valid (use IsValidCargo()).
+ * @return the last month's production of the given cargo for this industry.
+ */
+ static uint16 GetLastMonthProduction(IndustryID industry_id, CargoID cargo_id);
+
+ /**
+ * Get the total amount of cargo transported from an industry last month.
+ * @param industry_id the index of the industry.
+ * @param cargo_id the index of the cargo.
+ * @pre industry_id has to be valid (use IsValidIndustry()).
+ * @pre cargo_id has to be valid (use IsValidCargo()).
+ * @return the amount of given cargo transported from this industry last month.
+ */
+ static uint16 GetLastMonthTransported(IndustryID industry_id, CargoID cargo_id);
};
#endif /* AI_INDUSTRY_HPP */
--- a/src/ai/api/ai_industry.hpp.sq Sun Mar 02 13:19:08 2008 +0000
+++ b/src/ai/api/ai_industry.hpp.sq Mon Mar 03 16:15:24 2008 +0000
@@ -14,14 +14,16 @@
SQAIIndustry.PreRegister(engine);
SQAIIndustry.AddConstructor<void (AIIndustry::*)(), 1>(engine, "x");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetClassName, "GetClassName", 1, "x");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetMaxIndustryID, "GetMaxIndustryID", 1, "x");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryCount, "GetIndustryCount", 1, "x");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsValidIndustry, "IsValidIndustry", 2, "xi");
- 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::GetLocation, "GetLocation", 2, "xi");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetClassName, "GetClassName", 1, "x");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetMaxIndustryID, "GetMaxIndustryID", 1, "x");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryCount, "GetIndustryCount", 1, "x");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsValidIndustry, "IsValidIndustry", 2, "xi");
+ 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::GetLocation, "GetLocation", 2, "xi");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLastMonthProduction, "GetLastMonthProduction", 3, "xii");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLastMonthTransported, "GetLastMonthTransported", 3, "xii");
SQAIIndustry.PostRegister(engine);
}