(svn r9498) [NoAI] -Add: added regression for AITransactionMode() noai
authortruelight
Tue, 27 Mar 2007 10:22:39 +0000
branchnoai
changeset 9560 ff2dde050a4c
parent 9559 8fad57b884a7
child 9561 33b2f192bb34
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
-Fix: AITransActionMode() now substracts the costs he makes when executing, to keep the GetCosts in global space correct
-Fix: Reset NewVehicleID on building a vehicle
-Update: remove the need for a local variable in ai_sign.cpp
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
src/ai/api/ai_sign.cpp
src/ai/api/ai_transactionmode.cpp
src/ai/api/ai_vehicle.cpp
--- a/bin/ai/regression/regression.nut	Tue Mar 27 10:17:47 2007 +0000
+++ b/bin/ai/regression/regression.nut	Tue Mar 27 10:22:39 2007 +0000
@@ -322,8 +322,17 @@
 
 	local bank = company.GetBankBalance();
 
-	print("  BuildVehicle():       " + vehicle.BuildVehicle(33417, 153));
-	print("  IsValidVehicle(1024): " + vehicle.IsValidVehicle(1024));
+	{
+		local transaction = AITransactionMode();
+		print("  BuildVehicle():       " + vehicle.BuildVehicle(33417, 153));
+		print("  IsValidVehicle(1024): " + vehicle.IsValidVehicle(1024));
+
+		print("  --Transaction--");
+		print("    GetCosts():         " + transaction.GetCosts());
+		print("    Execute():          " + transaction.Execute());
+
+		print("  IsValidVehicle(1024): " + vehicle.IsValidVehicle(1024));
+	}
 	print("  CloneVehicle():       " + vehicle.CloneVehicle(33417, 1024, true));
 
 	local bank_after = company.GetBankBalance();
--- a/bin/ai/regression/regression.txt	Tue Mar 27 10:17:47 2007 +0000
+++ b/bin/ai/regression/regression.txt	Tue Mar 27 10:22:39 2007 +0000
@@ -1342,7 +1342,11 @@
     Reliability 0:      65535
     Reliability 50:     65535
     Reliability 100:    65535
-  BuildVehicle():       1024
+  BuildVehicle():       0
+  IsValidVehicle(1024): false
+  --Transaction--
+    GetCosts():         5945
+    Execute():          true
   IsValidVehicle(1024): true
   CloneVehicle():       1025
   --Accounting--
--- a/src/ai/api/ai_sign.cpp	Tue Mar 27 10:17:47 2007 +0000
+++ b/src/ai/api/ai_sign.cpp	Tue Mar 27 10:22:39 2007 +0000
@@ -52,14 +52,14 @@
 {
 	if (!::IsValidTile(location)) return INVALID_SIGN;
 
-	AIObject::SetNewSignID(INVALID_SIGN);
-	bool ret = this->DoCommand(location, 0, 0, CMD_PLACE_SIGN);
-	if (!ret) return INVALID_SIGN;
+	/* Reset the internal NewSignID in case we are in TestMode */
+	AIObject::SetNewSignID(0);
+
+	if (!this->DoCommand(location, 0, 0, CMD_PLACE_SIGN)) return INVALID_SIGN;
 
 	SignID new_sign_id = AIObject::GetNewSignID();
 	_cmd_text = text;
-	ret = this->DoCommand(0, new_sign_id, 0, CMD_RENAME_SIGN);
-	if (!ret) {
+	if (!this->DoCommand(0, new_sign_id, 0, CMD_RENAME_SIGN)) {
 		this->RemoveSign(new_sign_id);
 		return INVALID_SIGN;
 	}
--- a/src/ai/api/ai_transactionmode.cpp	Tue Mar 27 10:17:47 2007 +0000
+++ b/src/ai/api/ai_transactionmode.cpp	Tue Mar 27 10:22:39 2007 +0000
@@ -62,6 +62,11 @@
 	/* Make sure we are stopped */
 	this->Stop();
 
+	/* Remove the costs this transaction costs from the total costs, so any
+	 *  'accounting' running on the background will get the real costs for
+	 *  executing, and not the double value of both testing and executing */
+	this->IncreaseDoCommandCosts(-this->GetCosts());
+
 	/* Switch to a forced execute mode */
 	AIExecMode exec;
 
--- a/src/ai/api/ai_vehicle.cpp	Tue Mar 27 10:17:47 2007 +0000
+++ b/src/ai/api/ai_vehicle.cpp	Tue Mar 27 10:22:39 2007 +0000
@@ -43,6 +43,9 @@
 {
 	if (!this->IsValidEngine(engine_id)) return false;
 
+	/* Reset the internal NewVehicleID in case we are in TestMode */
+	AIObject::SetNewVehicleID(0);
+
 	bool ret;
 	switch (::GetEngine(engine_id)->type) {
 		case VEH_ROAD: ret = this->DoCommand(depot, engine_id, 0, CMD_BUILD_ROAD_VEH); break;
@@ -56,6 +59,9 @@
 {
 	if (!this->IsValidVehicle(vehicle_id)) return false;
 
+	/* Reset the internal NewVehicleID in case we are in TestMode */
+	AIObject::SetNewVehicleID(0);
+
 	bool ret;
 	switch (::GetVehicle(vehicle_id)->type) {
 		case VEH_ROAD: ret = this->DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE); break;