summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-06-06 16:54:22 +0000
committersmatz <smatz@openttd.org>2009-06-06 16:54:22 +0000
commit0c10006907b7d149f91d277a0c28a79b40eaa4c0 (patch)
treedc8cb6a7a9315a10688af00187db94be8911acef /src/vehicle.cpp
parentc90819ff6d8d49ac25aa9194bdf04e8dfd7149ea (diff)
downloadopenttd-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/vehicle.cpp')
-rw-r--r--src/vehicle.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 92248b95c..8a1b649a6 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -524,9 +524,9 @@ void Vehicle::PreDestructor()
if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id);
}
- if (this->type == VEH_ROAD) ClearSlot((RoadVehicle *)this);
+ if (this->type == VEH_ROAD) ClearSlot(RoadVehicle::From(this));
if (this->type == VEH_AIRCRAFT && this->IsPrimaryVehicle()) {
- Aircraft *a = (Aircraft *)this;
+ Aircraft *a = Aircraft::From(this);
Station *st = GetTargetAirportIfValid(a);
if (st != NULL) {
const AirportFTA *layout = st->Airport()->layout;
@@ -984,8 +984,8 @@ void VehicleEnterDepot(Vehicle *v)
if (!IsFrontEngine(v)) v = v->First();
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
v->load_unload_time_rem = 0;
- ClrBit(((Train *)v)->flags, VRF_TOGGLE_REVERSE);
- TrainConsistChanged((Train *)v, true);
+ ClrBit(Train::From(v)->flags, VRF_TOGGLE_REVERSE);
+ TrainConsistChanged(Train::From(v), true);
break;
case VEH_ROAD:
@@ -995,13 +995,13 @@ void VehicleEnterDepot(Vehicle *v)
case VEH_SHIP:
InvalidateWindowClasses(WC_SHIPS_LIST);
- static_cast<Ship*>(v)->state = TRACK_BIT_DEPOT;
+ Ship::From(v)->state = TRACK_BIT_DEPOT;
RecalcShipStuff(v);
break;
case VEH_AIRCRAFT:
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
- HandleAircraftEnterHangar((Aircraft *)v);
+ HandleAircraftEnterHangar(Aircraft::From(v));
break;
default: NOT_REACHED();
}
@@ -1429,9 +1429,9 @@ SpriteID GetEnginePalette(EngineID engine_type, CompanyID company)
SpriteID GetVehiclePalette(const Vehicle *v)
{
if (v->type == VEH_TRAIN) {
- return GetEngineColourMap(v->engine_type, v->owner, ((const Train *)v)->tcache.first_engine, v);
+ return GetEngineColourMap(v->engine_type, v->owner, Train::From(v)->tcache.first_engine, v);
} else if (v->type == VEH_ROAD) {
- return GetEngineColourMap(v->engine_type, v->owner, ((const RoadVehicle *)v)->rcache.first_engine, v);
+ return GetEngineColourMap(v->engine_type, v->owner, RoadVehicle::From(v)->rcache.first_engine, v);
}
return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v);
@@ -1493,7 +1493,7 @@ void Vehicle::LeaveStation()
* might not be marked as wanting a reservation, e.g.
* when an overlength train gets turned around in a station. */
if (UpdateSignalsOnSegment(this->tile, TrackdirToExitdir(this->GetVehicleTrackdir()), this->owner) == SIGSEG_PBS || _settings_game.pf.reserve_paths) {
- TryPathReserve((Train *)this, true, true);
+ TryPathReserve(Train::From(this), true, true);
}
}
}
@@ -1577,7 +1577,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
if (this->type == VEH_TRAIN && reverse) DoCommand(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
if (this->type == VEH_AIRCRAFT) {
- Aircraft *a = (Aircraft *)this;
+ Aircraft *a = Aircraft::From(this);
if (a->state == FLYING && a->targetairport != destination) {
/* The aircraft is now heading for a different hangar than the next in the orders */
extern void AircraftNextAirportPos_and_Order(Aircraft *a);
@@ -1747,7 +1747,7 @@ bool CanVehicleUseStation(EngineID engine_type, const Station *st)
*/
bool CanVehicleUseStation(const Vehicle *v, const Station *st)
{
- if (v->type == VEH_ROAD) return st->GetPrimaryRoadStop((const RoadVehicle *)v) != NULL;
+ if (v->type == VEH_ROAD) return st->GetPrimaryRoadStop(RoadVehicle::From(v)) != NULL;
return CanVehicleUseStation(v->engine_type, st);
}