src/ai/api/ai_vehicle.cpp
branchnoai
changeset 9711 c8b427215c9d
parent 9709 196a08fbfeb6
child 9723 eee46cb39750
--- a/src/ai/api/ai_vehicle.cpp	Fri Oct 19 09:36:27 2007 +0000
+++ b/src/ai/api/ai_vehicle.cpp	Fri Oct 19 11:32:20 2007 +0000
@@ -3,6 +3,7 @@
 /** @file ai_vehicle.cpp handles the functions of the AIVehicle class */
 
 #include "ai_vehicle.hpp"
+#include "ai_engine.hpp"
 #include "ai_cargo.hpp"
 #include "ai_order.hpp"
 #include "../../command.h"
@@ -14,97 +15,14 @@
 #include "../../strings.h"
 #include "table/strings.h"
 
-/* static */ bool AIVehicle::IsValidEngine(EngineID engine_id)
-{
-	return ::IsEngineIndex(engine_id); // TODO: implement 'can I build this engine check'
-}
-
 /* static */ bool AIVehicle::IsValidVehicle(VehicleID vehicle_id)
 {
 	return ::IsValidVehicleID(vehicle_id) && ::GetVehicle(vehicle_id)->owner == _current_player && GetVehicle(vehicle_id)->IsPrimaryVehicle();
 }
 
-EngineID AIVehicle::FindBestVehicle(CargoID cargo, uint8 min_reliability, AIVehicle::VehicleType veh_type, uint max_cost)
-{
-	if (!AICargo::IsValidCargo(cargo) || min_reliability > 100) return INVALID_ENGINE;
-
-	EngineID best_engine = INVALID_ENGINE;
-	EngineID engine_id;
-	uint best_cargo = 0;
-	uint best_speed = 0;
-
-	FOR_ALL_ENGINEIDS_OF_TYPE(engine_id, veh_type) {
-		/* Is the vehicle available for this player */
-		if (IsEngineBuildable(engine_id, veh_type, _current_player) &&
-				GetEngine(engine_id)->reliability * 100 >= min_reliability << 16) {
-			uint cspeed, ccargo;
-			/* Can this vehicle handle the cargo requested? */
-			switch (veh_type) {
-				case VEHICLE_ROAD: {
-					const RoadVehicleInfo *vi = RoadVehInfo(engine_id);
-					if (vi->cargo_type != cargo && !CanRefitTo(engine_id, cargo)) continue;
-					if ((_price.roadveh_base >> 3) * vi->base_cost >> 5 > max_cost) continue;
-					ccargo = vi->capacity;
-					cspeed = vi->max_speed;
-				} break;
-
-				case VEHICLE_RAIL: {
-					const RailVehicleInfo *vi = RailVehInfo(engine_id);
-					if (vi->cargo_type != cargo && !CanRefitTo(engine_id, cargo)) continue;
-					if ((_price.build_railvehicle >> 3) * vi->base_cost >> 5 > max_cost) continue;
-					ccargo = vi->capacity;
-					cspeed = vi->max_speed;
-				} break;
-
-				case VEHICLE_WATER: {
-					const ShipVehicleInfo *vi = ShipVehInfo(engine_id);
-					if (vi->cargo_type != cargo && !CanRefitTo(engine_id, cargo)) continue;
-					if ((_price.ship_base >> 3) * vi->base_cost >> 5 > max_cost) continue;
-					ccargo = vi->capacity;
-					cspeed = vi->max_speed;
-				} break;
-
-				case VEHICLE_AIR: {
-					const AircraftVehicleInfo *vi = AircraftVehInfo(engine_id);
-					if (CT_PASSENGERS != cargo && CT_MAIL != cargo && !CanRefitTo(engine_id, cargo)) continue;
-					if ((_price.aircraft_base >> 3) * vi->base_cost >> 5 > max_cost) continue;
-					ccargo = vi->passenger_capacity;
-					cspeed = vi->max_speed;
-				} break;
-
-				default: NOT_REACHED();
-			}
-
-			/* Sort on speed, than on cargo, than on order of engine-array */
-			if (best_speed > cspeed) continue;
-			if (best_cargo > ccargo) continue;
-			best_engine = engine_id;
-			best_speed = cspeed;
-			best_cargo = ccargo;
-		}
-	}
-
-	return best_engine;
-}
-
-EngineID AIVehicle::FindBestRoadVehicle(CargoID cargo, uint8 min_reliability, uint max_cost)
-{
-	return this->FindBestVehicle(cargo, min_reliability, VEHICLE_ROAD, max_cost);
-}
-
-EngineID AIVehicle::FindBestAirVehicle(CargoID cargo, uint8 min_reliability, uint max_cost)
-{
-	return this->FindBestVehicle(cargo, min_reliability, VEHICLE_AIR, max_cost);
-}
-
-EngineID AIVehicle::FindBestWaterVehicle(CargoID cargo, uint8 min_reliability, uint max_cost)
-{
-	return this->FindBestVehicle(cargo, min_reliability, VEHICLE_WATER, max_cost);
-}
-
 VehicleID AIVehicle::BuildVehicle(TileIndex depot, EngineID engine_id)
 {
-	if (!this->IsValidEngine(engine_id)) return false;
+	if (!AIEngine::IsValidEngine(engine_id)) return false;
 
 	/* Reset the internal NewVehicleID in case we are in TestMode */
 	AIObject::SetNewVehicleID(0);