(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth. noai
authorrubidium
Mon, 07 Apr 2008 18:29:12 +0000
branchnoai
changeset 10087 0cb23b9abbf7
parent 10086 6497ef78f031
child 10088 922c6e6a8d3e
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
src/ai/api/ai_vehicle.cpp
--- a/src/ai/api/ai_vehicle.cpp	Mon Apr 07 18:24:45 2008 +0000
+++ b/src/ai/api/ai_vehicle.cpp	Mon Apr 07 18:29:12 2008 +0000
@@ -9,6 +9,7 @@
 #include "../../depot.h"
 #include "../../player_func.h"
 #include "../../aircraft.h"
+#include "../../string_func.h"
 #include "../../strings_func.h"
 #include "../../core/alloc_func.hpp"
 #include "../../command_type.h"
@@ -22,7 +23,7 @@
 
 /* static */ VehicleID AIVehicle::BuildVehicle(TileIndex depot, EngineID engine_id)
 {
-	if (!AIEngine::IsValidEngine(engine_id)) return false;
+	EnforcePrecondition(false, AIEngine::IsValidEngine(engine_id));
 
 	/* Reset the internal NewVehicleID in case we are in TestMode */
 	AIObject::SetNewVehicleID(0);
@@ -41,7 +42,7 @@
 
 /* static */ VehicleID AIVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders)
 {
-	if (!IsValidVehicle(vehicle_id)) return false;
+	EnforcePrecondition(false, IsValidVehicle(vehicle_id));
 
 	/* Reset the internal NewVehicleID in case we are in TestMode */
 	AIObject::SetNewVehicleID(0);
@@ -52,7 +53,7 @@
 
 /* static */ bool AIVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo)
 {
-	if (!IsValidVehicle(vehicle_id) || !AICargo::IsValidCargo(cargo)) return false;
+	EnforcePrecondition(false, IsValidVehicle(vehicle_id) && AICargo::IsValidCargo(cargo));
 
 	switch (::GetVehicle(vehicle_id)->type) {
 		case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, cargo, CMD_REFIT_ROAD_VEH);
@@ -66,7 +67,7 @@
 
 /* static */ bool AIVehicle::SellVehicle(VehicleID vehicle_id)
 {
-	if (!IsValidVehicle(vehicle_id)) return false;
+	EnforcePrecondition(false, IsValidVehicle(vehicle_id));
 
 	switch (::GetVehicle(vehicle_id)->type) {
 		case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SELL_ROAD_VEH);
@@ -79,7 +80,7 @@
 
 /* static */ bool AIVehicle::SendVehicleToDepot(VehicleID vehicle_id)
 {
-	if (!IsValidVehicle(vehicle_id)) return false;
+	EnforcePrecondition(false, IsValidVehicle(vehicle_id));
 
 	switch (::GetVehicle(vehicle_id)->type) {
 		case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SEND_ROADVEH_TO_DEPOT);
@@ -104,7 +105,7 @@
 
 /* static */ bool AIVehicle::StartStopVehicle(VehicleID vehicle_id)
 {
-	if (!IsValidVehicle(vehicle_id)) return false;
+	EnforcePrecondition(false, IsValidVehicle(vehicle_id));
 
 	switch (::GetVehicle(vehicle_id)->type) {
 		case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, 0, CMD_START_STOP_ROADVEH);
@@ -117,15 +118,15 @@
 
 /* static */ bool AIVehicle::SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id)
 {
-	if (!AIOrder::IsValidVehicleOrder(vehicle_id, order_id)) return false;
+	EnforcePrecondition(false, AIOrder::IsValidVehicleOrder(vehicle_id, order_id));
 
 	return AIObject::DoCommand(0, vehicle_id, order_id, CMD_SKIP_TO_ORDER);
 }
 
 /* static */ bool AIVehicle::SetName(VehicleID vehicle_id, const char *name)
 {
-	if (!IsValidVehicle(vehicle_id)) return false;
-	if (name == NULL) return false;
+	EnforcePrecondition(false, IsValidVehicle(vehicle_id));
+	EnforcePrecondition(false, !StrEmpty(name));
 
 	_cmd_text = name;
 	return AIObject::DoCommand(0, vehicle_id, 0, CMD_NAME_VEHICLE);