File diff r12108:f8d8164485bd → r12109:90df01928018
src/ai/api/ai_vehicle.cpp
Show inline comments
 
@@ -43,17 +43,17 @@
 

	
 
	const Vehicle *v = ::Vehicle::Get(vehicle_id);
 
	switch (v->type) {
 
		case VEH_ROAD: {
 
			uint total_length = 0;
 
			for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 
				total_length += ((const RoadVehicle *)u)->rcache.cached_veh_length;
 
				total_length += ::RoadVehicle::From(u)->rcache.cached_veh_length;
 
			}
 
			return total_length;
 
		}
 
		case VEH_TRAIN: return ((const Train *)v)->tcache.cached_total_length;
 
		case VEH_TRAIN: return ::Train::From(v)->tcache.cached_total_length;
 
		default: return -1;
 
	}
 
}
 

	
 
/* static */ VehicleID AIVehicle::BuildVehicle(TileIndex depot, EngineID engine_id)
 
{
 
@@ -83,17 +83,17 @@
 
{
 
	EnforcePrecondition(false, IsValidVehicle(source_vehicle_id) && source_wagon < GetNumWagons(source_vehicle_id));
 
	EnforcePrecondition(false, dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)));
 
	EnforcePrecondition(false, ::Vehicle::Get(source_vehicle_id)->type == VEH_TRAIN);
 
	EnforcePrecondition(false, dest_vehicle_id == -1 || ::Vehicle::Get(dest_vehicle_id)->type == VEH_TRAIN);
 

	
 
	const Train *v = (const Train *)::Vehicle::Get(source_vehicle_id);
 
	const Train *v = ::Train::Get(source_vehicle_id);
 
	while (source_wagon-- > 0) v = GetNextUnit(v);
 
	const Train *w = NULL;
 
	if (dest_vehicle_id != -1) {
 
		w = (const Train *)::Vehicle::Get(dest_vehicle_id);
 
		w = ::Train::Get(dest_vehicle_id);
 
		while (dest_wagon-- > 0) w = GetNextUnit(w);
 
	}
 

	
 
	return AIObject::DoCommand(0, v->index | ((w == NULL ? INVALID_VEHICLE : w->index) << 16), move_attached_wagons ? 1 : 0, CMD_MOVE_RAIL_VEHICLE);
 
}
 

	
 
@@ -134,13 +134,13 @@
 

	
 
/* static */ bool AIVehicle::_SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons)
 
{
 
	EnforcePrecondition(false, IsValidVehicle(vehicle_id) && wagon < GetNumWagons(vehicle_id));
 
	EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN);
 

	
 
	const Train *v = (const Train *)::Vehicle::Get(vehicle_id);
 
	const Train *v = ::Train::Get(vehicle_id);
 
	while (wagon-- > 0) v = GetNextUnit(v);
 

	
 
	return AIObject::DoCommand(0, v->index, sell_attached_wagons ? 1 : 0, CMD_SELL_RAIL_WAGON);
 
}
 

	
 
/* static */ bool AIVehicle::SellWagon(VehicleID vehicle_id, int wagon)
 
@@ -241,13 +241,13 @@
 
{
 
	if (!IsValidVehicle(vehicle_id)) return INVALID_ENGINE;
 
	if (wagon >= GetNumWagons(vehicle_id)) return INVALID_ENGINE;
 

	
 
	const Vehicle *v = ::Vehicle::Get(vehicle_id);
 
	if (v->type == VEH_TRAIN) {
 
		while (wagon-- > 0) v = GetNextUnit((const Train *)v);
 
		while (wagon-- > 0) v = GetNextUnit(::Train::From(v));
 
	}
 
	return v->engine_type;
 
}
 

	
 
/* static */ int32 AIVehicle::GetUnitNumber(VehicleID vehicle_id)
 
{
 
@@ -279,13 +279,13 @@
 
{
 
	if (!IsValidVehicle(vehicle_id)) return -1;
 
	if (wagon >= GetNumWagons(vehicle_id)) return -1;
 

	
 
	const Vehicle *v = ::Vehicle::Get(vehicle_id);
 
	if (v->type == VEH_TRAIN) {
 
		while (wagon-- > 0) v = GetNextUnit((const Train *)v);
 
		while (wagon-- > 0) v = GetNextUnit(::Train::From(v));
 
	}
 
	return v->age;
 
}
 

	
 
/* static */ int32 AIVehicle::GetMaxAge(VehicleID vehicle_id)
 
{
 
@@ -366,13 +366,13 @@
 

	
 
/* static */ AIRoad::RoadType AIVehicle::GetRoadType(VehicleID vehicle_id)
 
{
 
	if (!IsValidVehicle(vehicle_id)) return AIRoad::ROADTYPE_INVALID;
 
	if (GetVehicleType(vehicle_id) != VT_ROAD) return AIRoad::ROADTYPE_INVALID;
 

	
 
	return (AIRoad::RoadType)((RoadVehicle*)::Vehicle::Get(vehicle_id))->roadtype;
 
	return (AIRoad::RoadType)(::RoadVehicle::Get(vehicle_id))->roadtype;
 
}
 

	
 
/* static */ int32 AIVehicle::GetCapacity(VehicleID vehicle_id, CargoID cargo)
 
{
 
	if (!IsValidVehicle(vehicle_id)) return -1;
 
	if (!AICargo::IsValidCargo(cargo)) return -1;
 
@@ -409,14 +409,14 @@
 
{
 
	if (!IsValidVehicle(vehicle_id)) return false;
 
	if (GetVehicleType(vehicle_id) != VT_ROAD && GetVehicleType(vehicle_id) != VT_RAIL) return false;
 

	
 
	const Vehicle *v = ::Vehicle::Get(vehicle_id);
 
	switch (v->type) {
 
		case VEH_ROAD: return RoadVehHasArticPart(v);
 
		case VEH_TRAIN: return EngineHasArticPart(v);
 
		case VEH_ROAD: return ::RoadVehHasArticPart(v);
 
		case VEH_TRAIN: return ::EngineHasArticPart(v);
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/* static */ bool AIVehicle::HasSharedOrders(VehicleID vehicle_id)
 
{