diff options
author | smatz <smatz@openttd.org> | 2009-06-06 16:54:22 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-06-06 16:54:22 +0000 |
commit | 0c10006907b7d149f91d277a0c28a79b40eaa4c0 (patch) | |
tree | dc8cb6a7a9315a10688af00187db94be8911acef /src/ai | |
parent | c90819ff6d8d49ac25aa9194bdf04e8dfd7149ea (diff) | |
download | openttd-0c10006907b7d149f91d277a0c28a79b40eaa4c0.tar.xz |
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/api/ai_vehicle.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp index a905d42c6..b1e4e0ad7 100644 --- a/src/ai/api/ai_vehicle.cpp +++ b/src/ai/api/ai_vehicle.cpp @@ -46,11 +46,11 @@ 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; } } @@ -86,11 +86,11 @@ 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); } @@ -137,7 +137,7 @@ 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); @@ -244,7 +244,7 @@ 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; } @@ -282,7 +282,7 @@ 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; } @@ -369,7 +369,7 @@ 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) @@ -412,8 +412,8 @@ 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(); } } |