(svn r13211) [NoAI] -Codechange: replace a few hardcoded numbers by an API lookup in the WrightAI. noai
authorrubidium
Thu, 22 May 2008 10:23:34 +0000
branchnoai
changeset 10667 1bacf27342bd
parent 10653 c389705ba89f
child 10668 495789401303
(svn r13211) [NoAI] -Codechange: replace a few hardcoded numbers by an API lookup in the WrightAI.
bin/ai/wrightai/main.nut
--- a/bin/ai/wrightai/main.nut	Tue May 20 16:26:18 2008 +0000
+++ b/bin/ai/wrightai/main.nut	Thu May 22 10:23:34 2008 +0000
@@ -7,6 +7,7 @@
 	distance_of_route = {};
 	vehicle_to_depot = {};
 	delay_build_airport_route = 1000;
+	passenger_cargo_id = -1;
 
 	function Start();
 	function Stop();
@@ -15,6 +16,13 @@
 		this.towns_used = AIList();
 		this.route_1 = AIList();
 		this.route_2 = AIList();
+
+		local list = AICargoList();
+		for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+			if (AICargo.GetCargoLabel(i) == "PASS") {
+				this.passenger_cargo_id = i;
+			}
+		}
 	}
 }
 
@@ -108,7 +116,7 @@
 	engine_list.KeepBelowValue(balance < 300000 ? 50000 : (balance < 1000000 ? 300000 : 1000000));
 
 	engine_list.Valuate(AIEngine.GetCargoType)
-	engine_list.KeepValue(0); // passengers
+	engine_list.KeepValue(this.passenger_cargo_id);
 
 	engine_list.Valuate(AIEngine.GetCapacity)
 	engine_list.KeepTop(1);
@@ -178,7 +186,7 @@
 			list.KeepAboveValue(625);
 		}
 		/* Sort on acceptance, remove places that don't have acceptance */
-		list.Valuate(AITile.GetCargoAcceptance, 0, airport_x, airport_y, airport_rad);
+		list.Valuate(AITile.GetCargoAcceptance, this.passenger_cargo_id, airport_x, airport_y, airport_rad);
 		list.RemoveBelowValue(10);
 
 		/* Couldn't find a suitable place for this town, skip to the next */
@@ -246,7 +254,7 @@
 	if (!this.HasMoney(50000)) return;
 
 	list = AIStationList(AIStation.STATION_AIRPORT);
-	list.Valuate(AIStation.GetCargoWaiting, 0);
+	list.Valuate(AIStation.GetCargoWaiting, this.passenger_cargo_id);
 	list.KeepAboveValue(250);
 
 	for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
@@ -314,6 +322,11 @@
 
 function WrightAI::Start()
 {
+	if (this.passenger_cargo_id == -1) {
+		AILog.Error("WrightAI could not find the passenger cargo");
+		return;
+	}
+
 	/* Sleep 1 tick, as we can't execute anything in tick 0 */
 	Sleep(1);