summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_vehicle.cpp20
-rw-r--r--src/aircraft_gui.cpp2
-rw-r--r--src/articulated_vehicles.cpp8
-rw-r--r--src/autoreplace_cmd.cpp26
-rw-r--r--src/depot_gui.cpp10
-rw-r--r--src/disaster_cmd.cpp5
-rw-r--r--src/economy.cpp4
-rw-r--r--src/newgrf_engine.cpp24
-rw-r--r--src/npf.cpp4
-rw-r--r--src/openttd.cpp6
-rw-r--r--src/order_cmd.cpp11
-rw-r--r--src/pbs.cpp2
-rw-r--r--src/rail_cmd.cpp6
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/roadveh_gui.cpp2
-rw-r--r--src/saveload/afterload.cpp4
-rw-r--r--src/saveload/oldloader_sl.cpp4
-rw-r--r--src/saveload/vehicle_sl.cpp16
-rw-r--r--src/signal.cpp2
-rw-r--r--src/station_cmd.cpp6
-rw-r--r--src/train_cmd.cpp20
-rw-r--r--src/train_gui.cpp4
-rw-r--r--src/tunnelbridge_cmd.cpp16
-rw-r--r--src/vehicle.cpp22
-rw-r--r--src/vehicle_base.h22
-rw-r--r--src/vehicle_cmd.cpp22
-rw-r--r--src/vehicle_gui.cpp20
-rw-r--r--src/vehicle_type.h2
-rw-r--r--src/vehiclelist.cpp2
-rw-r--r--src/water_cmd.cpp8
-rw-r--r--src/yapf/follow_track.hpp8
-rw-r--r--src/yapf/yapf_costrail.hpp4
-rw-r--r--src/yapf/yapf_destrail.hpp8
-rw-r--r--src/yapf/yapf_rail.cpp12
-rw-r--r--src/yapf/yapf_road.cpp10
36 files changed, 185 insertions, 161 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();
}
}
diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp
index f2c0bf771..ccc04490b 100644
--- a/src/aircraft_gui.cpp
+++ b/src/aircraft_gui.cpp
@@ -67,7 +67,7 @@ void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
DrawSprite(v->GetImage(DIR_W), pal, x + 25, y + 10);
if (v->subtype == AIR_HELICOPTER) {
- const Aircraft *a = (const Aircraft *)v;
+ const Aircraft *a = Aircraft::From(v);
SpriteID rotor_sprite = GetCustomRotorSprite(a, true);
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
DrawSprite(rotor_sprite, PAL_NONE, x + 25, y + 5);
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index 1c3ef6cdc..15b4121d4 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -208,7 +208,7 @@ bool IsArticulatedVehicleCarryingDifferentCargos(const Vehicle *v, CargoID *carg
switch (v->type) {
case VEH_TRAIN:
- v = (EngineHasArticPart((const Train *)v) ? GetNextArticPart((const Train *)v) : NULL);
+ v = (EngineHasArticPart(Train::From(v)) ? GetNextArticPart(Train::From(v)) : NULL);
break;
case VEH_ROAD:
@@ -256,7 +256,7 @@ void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
switch (v->type) {
case VEH_TRAIN:
- v = (EngineHasArticPart((const Train *)v) ? GetNextArticPart((const Train *)v) : NULL);
+ v = (EngineHasArticPart(Train::From(v)) ? GetNextArticPart(Train::From(v)) : NULL);
break;
case VEH_ROAD:
@@ -305,7 +305,7 @@ void AddArticulatedParts(Vehicle *first, VehicleType type)
default: NOT_REACHED();
case VEH_TRAIN: {
- Train *front = (Train *)first;
+ Train *front = Train::From(first);
Train *t = new Train();
v->SetNext(t);
v = t;
@@ -328,7 +328,7 @@ void AddArticulatedParts(Vehicle *first, VehicleType type)
} break;
case VEH_ROAD: {
- RoadVehicle *front = (RoadVehicle *)first;
+ RoadVehicle *front = RoadVehicle::From(first);
RoadVehicle *rv = new RoadVehicle();
v->SetNext(rv);
v = rv;
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 948286d69..183284dac 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -92,18 +92,18 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
assert(!part_of_chain || new_head->IsPrimaryVehicle());
/* Loop through source parts */
for (Vehicle *src = old_veh; src != NULL; src = src->Next()) {
- if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != ((Train *)old_veh)->other_multiheaded_part && !IsArticulatedPart(src)) {
+ if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != Train::From(old_veh)->other_multiheaded_part && !IsArticulatedPart(src)) {
/* Skip vehicles, which do not belong to old_veh */
- src = GetLastEnginePart((Train *)src);
+ src = GetLastEnginePart(Train::From(src));
continue;
}
if (src->cargo_type >= NUM_CARGO || src->cargo.Count() == 0) continue;
/* Find free space in the new chain */
for (Vehicle *dest = new_head; dest != NULL && src->cargo.Count() > 0; dest = dest->Next()) {
- if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != ((Train *)new_head)->other_multiheaded_part && !IsArticulatedPart(dest)) {
+ if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != Train::From(new_head)->other_multiheaded_part && !IsArticulatedPart(dest)) {
/* Skip vehicles, which do not belong to new_head */
- dest = GetLastEnginePart((Train *)dest);
+ dest = GetLastEnginePart(Train::From(dest));
continue;
}
if (dest->cargo_type != src->cargo_type) continue;
@@ -116,7 +116,7 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
}
/* Update train weight etc., the old vehicle will be sold anyway */
- if (part_of_chain && new_head->type == VEH_TRAIN) TrainConsistChanged((Train *)new_head, true);
+ if (part_of_chain && new_head->type == VEH_TRAIN) TrainConsistChanged(Train::From(new_head), true);
}
/**
@@ -269,7 +269,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
}
/* Try to reverse the vehicle, but do not care if it fails as the new type might not be reversible */
- if (new_veh->type == VEH_TRAIN && HasBit(((Train *)old_veh)->flags, VRF_REVERSE_DIRECTION)) {
+ if (new_veh->type == VEH_TRAIN && HasBit(Train::From(old_veh)->flags, VRF_REVERSE_DIRECTION)) {
DoCommand(0, new_veh->index, true, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
}
@@ -403,10 +403,10 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
if (old_head->type == VEH_TRAIN) {
/* Store the length of the old vehicle chain, rounded up to whole tiles */
- uint16 old_total_length = (((Train *)old_head)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE * TILE_SIZE;
+ uint16 old_total_length = (Train::From(old_head)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE * TILE_SIZE;
int num_units = 0; ///< Number of units in the chain
- for (Train *w = (Train *)old_head; w != NULL; w = GetNextUnit(w)) num_units++;
+ for (Train *w = Train::From(old_head); w != NULL; w = GetNextUnit(w)) num_units++;
Train **old_vehs = CallocT<Train *>(num_units); ///< Will store vehicles of the old chain in their order
Train **new_vehs = CallocT<Train *>(num_units); ///< New vehicles corresponding to old_vehs or NULL if no replacement
@@ -416,7 +416,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
* Note: The replacement vehicles can only successfully build as long as the old vehicles are still in their chain */
int i;
Train *w;
- for (w = (Train *)old_head, i = 0; w != NULL; w = GetNextUnit(w), i++) {
+ for (w = Train::From(old_head), i = 0; w != NULL; w = GetNextUnit(w), i++) {
assert(i < num_units);
old_vehs[i] = w;
@@ -432,7 +432,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
/* Note: When autoreplace has already failed here, old_vehs[] is not completely initialized. But it is also not needed. */
if (cost.Succeeded()) {
/* Separate the head, so we can start constructing the new chain */
- Train *second = GetNextUnit((Train *)old_head);
+ Train *second = GetNextUnit(Train::From(old_head));
if (second != NULL) cost.AddCost(MoveVehicle(second, NULL, DC_EXEC | DC_AUTOREPLACE, true));
assert(GetNextUnit(new_head) == NULL);
@@ -538,10 +538,10 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
* Note: The vehicle attach callback is disabled here :) */
if ((flags & DC_EXEC) == 0) {
/* Separate the head, so we can reattach the old vehicles */
- Train *second = GetNextUnit((Train *)old_head);
+ Train *second = GetNextUnit(Train::From(old_head));
if (second != NULL) MoveVehicle(second, NULL, DC_EXEC | DC_AUTOREPLACE, true);
- assert(GetNextUnit((Train *)old_head) == NULL);
+ assert(GetNextUnit(Train::From(old_head)) == NULL);
for (int i = num_units - 1; i > 0; i--) {
CommandCost ret = MoveVehicle(old_vehs[i], old_head, DC_EXEC | DC_AUTOREPLACE, false);
@@ -632,7 +632,7 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1
bool any_replacements = false;
while (w != NULL && !any_replacements) {
any_replacements = (GetNewEngineType(w, c) != INVALID_ENGINE);
- w = (!free_wagon && w->type == VEH_TRAIN ? GetNextUnit((Train *)w) : NULL);
+ w = (!free_wagon && w->type == VEH_TRAIN ? GetNextUnit(Train::From(w)) : NULL);
}
if (any_replacements) {
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 06fab5c8f..ed415d6c9 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -272,7 +272,7 @@ struct DepotWindow : Window {
DrawTrainImage(v, x + 21, sprite_y, this->sel, this->hscroll.cap + 4, this->hscroll.pos);
/* Number of wagons relative to a standard length wagon (rounded up) */
- SetDParam(0, (((const Train *)v)->tcache.cached_total_length + 7) / 8);
+ SetDParam(0, (Train::From(v)->tcache.cached_total_length + 7) / 8);
DrawString(this->widget[DEPOT_WIDGET_MATRIX].left, this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING, SA_RIGHT); // Draw the counter
break;
@@ -328,7 +328,7 @@ struct DepotWindow : Window {
hnum = 8;
for (uint num = 0; num < this->vehicle_list.Length(); num++) {
const Vehicle *v = this->vehicle_list[num];
- hnum = max(hnum, ((const Train *)v)->tcache.cached_total_length);
+ hnum = max(hnum, Train::From(v)->tcache.cached_total_length);
}
/* Always have 1 empty row, so people can change the setting of the train */
SetVScrollCount(w, this->vehicle_list.Length() + this->wagon_list.Length() + 1);
@@ -450,7 +450,7 @@ struct DepotWindow : Window {
x += skip;
/* find the vehicle in this row that was clicked */
- while (v != NULL && (x -= ((const Train *)v)->tcache.cached_veh_length) >= 0) v = v->Next();
+ while (v != NULL && (x -= Train::From(v)->tcache.cached_veh_length) >= 0) v = v->Next();
/* if an articulated part was selected, find its parent */
while (v != NULL && IsArticulatedPart(v)) v = v->Previous();
@@ -514,11 +514,11 @@ struct DepotWindow : Window {
switch (v->type) {
case VEH_TRAIN:
- _cursor.short_vehicle_offset = 16 - ((const Train *)v)->tcache.cached_veh_length * 2;
+ _cursor.short_vehicle_offset = 16 - Train::From(v)->tcache.cached_veh_length * 2;
break;
case VEH_ROAD:
- _cursor.short_vehicle_offset = 16 - ((const RoadVehicle *)v)->rcache.cached_veh_length * 2;
+ _cursor.short_vehicle_offset = 16 - RoadVehicle::From(v)->rcache.cached_veh_length * 2;
break;
default:
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index a32ee6b80..bee1db1a7 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -313,9 +313,8 @@ static bool DisasterTick_Ufo(DisasterVehicle *v)
return false;
} else {
/* Target a vehicle */
- Vehicle *u_tmp = Vehicle::Get(v->dest_tile);
- assert(u_tmp != NULL && u_tmp->type == VEH_ROAD && IsRoadVehFront(u_tmp));
- RoadVehicle *u = (RoadVehicle *)u_tmp;
+ RoadVehicle *u = RoadVehicle::Get(v->dest_tile);
+ assert(u != NULL && u->type == VEH_ROAD && IsRoadVehFront(u));
uint dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos);
diff --git a/src/economy.cpp b/src/economy.cpp
index b7ce214e6..dd925a380 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1314,7 +1314,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
/* update stats */
int t;
switch (u->type) {
- case VEH_TRAIN: t = ((Train *)u)->tcache.cached_max_speed; break;
+ case VEH_TRAIN: t = Train::From(u)->tcache.cached_max_speed; break;
case VEH_ROAD: t = u->max_speed / 2; break;
default: t = u->max_speed; break;
}
@@ -1423,7 +1423,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
if (v->type == VEH_TRAIN) {
/* Each platform tile is worth 2 rail vehicles. */
- int overhang = ((Train *)v)->tcache.cached_total_length - st->GetPlatformLength(v->tile) * TILE_SIZE;
+ int overhang = Train::From(v)->tcache.cached_total_length - st->GetPlatformLength(v->tile) * TILE_SIZE;
if (overhang > 0) {
unloading_time <<= 1;
unloading_time += (overhang * unloading_time) / 8;
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 9d8f25639..1637aef46 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -434,9 +434,9 @@ static uint8 LiveryHelper(EngineID engine, const Vehicle *v)
if (!Company::IsValidID(_current_company)) return 0;
l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, NULL);
} else if (v->type == VEH_TRAIN) {
- l = GetEngineLivery(v->engine_type, v->owner, ((const Train *)v)->tcache.first_engine, v);
+ l = GetEngineLivery(v->engine_type, v->owner, Train::From(v)->tcache.first_engine, v);
} else if (v->type == VEH_ROAD) {
- l = GetEngineLivery(v->engine_type, v->owner, ((const RoadVehicle *)v)->rcache.first_engine, v);
+ l = GetEngineLivery(v->engine_type, v->owner, RoadVehicle::From(v)->rcache.first_engine, v);
} else {
l = GetEngineLivery(v->engine_type, v->owner, INVALID_ENGINE, v);
}
@@ -534,7 +534,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
memset(common_subtypes, 0, sizeof(common_subtypes));
for (u = v; u != NULL; u = u->Next()) {
- if (v->type == VEH_TRAIN) user_def_data |= ((const Train *)u)->tcache.user_def_data;
+ if (v->type == VEH_TRAIN) user_def_data |= Train::From(u)->tcache.user_def_data;
/* Skip empty engines */
if (u->cargo_cap == 0) continue;
@@ -590,7 +590,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height
byte airporttype = ATP_TTDP_LARGE;
- const Station *st = GetTargetAirportIfValid((Aircraft *)v);
+ const Station *st = GetTargetAirportIfValid(Aircraft::From(v));
if (st != NULL) {
switch (st->airport_type) {
@@ -668,7 +668,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
uint16 modflags = 0;
if (v->type == VEH_TRAIN) {
- const Train *t = (const Train *)v;
+ const Train *t = Train::From(v);
const Train *u = IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON) ? t->First() : t;
RailType railtype = GetRailType(v->tile);
bool powered = IsTrainEngine(v) || (IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON));
@@ -736,7 +736,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
case 0x47: return GB(Engine::Get(v->engine_type)->internal_id, 8, 8);
case 0x48:
if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum;
- return HasBit(((Train *)v)->flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD;
+ return HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD;
case 0x49: return v->day_counter;
case 0x4A: return v->breakdowns_since_last_service;
@@ -768,7 +768,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
/* Vehicle specific properties */
switch (v->type) {
case VEH_TRAIN: {
- Train *t = (Train *)v;
+ Train *t = Train::From(v);
switch (variable - 0x80) {
case 0x62: return t->track;
case 0x66: return t->railtype;
@@ -784,7 +784,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
} break;
case VEH_ROAD: {
- RoadVehicle *rv = (RoadVehicle *)v;
+ RoadVehicle *rv = RoadVehicle::From(v);
switch (variable - 0x80) {
case 0x62: return rv->state;
case 0x64: return rv->blocked_ctr;
@@ -797,7 +797,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
} break;
case VEH_AIRCRAFT: {
- Aircraft *a = (Aircraft *)v;
+ Aircraft *a = Aircraft::From(v);
switch (variable - 0x80) {
case 0x62: return MapAircraftMovementState(a); // Current movement state
case 0x63: return a->targetairport; // Airport to which the action refers
@@ -886,10 +886,10 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *
/* We always use cached value, except for callbacks because the override spriteset
* to use may be different than the one cached. It happens for callback 0x15 (refit engine),
* as v->cargo_type is temporary changed to the new type */
- group = use_cache ? ((const Train *)v)->tcache.cached_override : GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, ((const Train *)v)->tcache.first_engine);
+ group = use_cache ? Train::From(v)->tcache.cached_override : GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, Train::From(v)->tcache.first_engine);
if (group != NULL) return group;
} else if (v->type == VEH_ROAD) {
- group = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, ((const RoadVehicle *)v)->rcache.first_engine);
+ group = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, RoadVehicle::From(v)->rcache.first_engine);
if (group != NULL) return group;
}
}
@@ -952,7 +952,7 @@ SpriteID GetRotorOverrideSprite(EngineID engine, const Aircraft *v, bool info_vi
bool UsesWagonOverride(const Vehicle *v)
{
assert(v->type == VEH_TRAIN);
- return ((const Train *)v)->tcache.cached_override != NULL;
+ return Train::From(v)->tcache.cached_override != NULL;
}
/**
diff --git a/src/npf.cpp b/src/npf.cpp
index dbd9875ed..e4a9473cf 100644
--- a/src/npf.cpp
+++ b/src/npf.cpp
@@ -425,7 +425,7 @@ static int32 NPFFindDepot(AyStar *as, OpenListNode *current)
/** Find any safe and free tile. */
static int32 NPFFindSafeTile(AyStar *as, OpenListNode *current)
{
- const Train *v = (const Train *)((NPFFindStationOrTileData*)as->user_target)->v;
+ const Train *v = Train::From(((NPFFindStationOrTileData *)as->user_target)->v);
return
IsSafeWaitingPosition(v, current->path.node.tile, current->path.node.direction, true, _settings_game.pf.forbid_90_deg) &&
@@ -506,7 +506,7 @@ static void NPFSaveTargetData(AyStar *as, OpenListNode *current)
if (as->user_target != NULL && ((NPFFindStationOrTileData*)as->user_target)->reserve_path && as->user_data[NPF_TYPE] == TRANSPORT_RAIL) {
/* Path reservation is requested. */
- const Train *v = (const Train *)((NPFFindStationOrTileData*)as->user_target)->v;
+ const Train *v = Train::From(((NPFFindStationOrTileData *)as->user_target)->v);
const PathNode *target = FindSafePosition(&current->path, v);
ftd->node = target->node;
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 3504bb76d..50efa4f8c 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1119,7 +1119,7 @@ void StateGameLoop()
switch (v->type) {
case VEH_ROAD: {
- RoadVehicle *rv = (RoadVehicle *)v;
+ RoadVehicle *rv = RoadVehicle::From(v);
RoadVehicleCache cache = rv->rcache;
RoadVehUpdateCache(rv);
@@ -1130,7 +1130,7 @@ void StateGameLoop()
case VEH_TRAIN: {
uint length = 0;
- Train *t = (Train *)v;
+ Train *t = Train::From(v);
for (Vehicle *u = t; u != NULL; u = u->Next()) length++;
TrainCache *wagons = MallocT<TrainCache>(length);
@@ -1151,7 +1151,7 @@ void StateGameLoop()
} break;
case VEH_AIRCRAFT: {
- Aircraft *a = (Aircraft *)v;
+ Aircraft *a = Aircraft::From(v);
AircraftCache cache = a->acache;
UpdateAircraftCache(a);
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 37e993d41..48e2f6fd5 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -21,6 +21,7 @@
#include "settings_type.h"
#include "core/pool_func.hpp"
#include "aircraft.h"
+#include "roadveh.h"
#include "table/strings.h"
@@ -734,7 +735,7 @@ CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (flags & DC_EXEC) {
v->cur_order_index = sel_ord;
- if (v->type == VEH_ROAD) ClearSlot((RoadVehicle *)v);
+ if (v->type == VEH_ROAD) ClearSlot(RoadVehicle::From(v));
if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
@@ -1360,7 +1361,7 @@ static TileIndex GetStationTileForVehicle(const Vehicle *v, const Station *st)
case VEH_TRAIN: return st->train_tile;
case VEH_AIRCRAFT: return st->airport_tile;
case VEH_SHIP: return st->dock_tile;
- case VEH_ROAD: return st->GetPrimaryRoadStop((RoadVehicle *)v)->xy;
+ case VEH_ROAD: return st->GetPrimaryRoadStop(RoadVehicle::From(v))->xy;
}
}
@@ -1615,7 +1616,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
if (v->type == VEH_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
if (v->type == VEH_AIRCRAFT) {
- Aircraft *a = (Aircraft *)v;
+ Aircraft *a = Aircraft::From(v);
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);
@@ -1734,13 +1735,13 @@ bool ProcessOrders(Vehicle *v)
if (v->type == VEH_AIRCRAFT) {
/* Aircraft do something vastly different here, so handle separately */
extern void HandleMissingAircraftOrders(Aircraft *v);
- HandleMissingAircraftOrders((Aircraft *)v);
+ HandleMissingAircraftOrders(Aircraft::From(v));
return false;
}
v->current_order.Free();
v->dest_tile = 0;
- if (v->type == VEH_ROAD) ClearSlot((RoadVehicle *)v);
+ if (v->type == VEH_ROAD) ClearSlot(RoadVehicle::From(v));
return false;
}
diff --git a/src/pbs.cpp b/src/pbs.cpp
index 0554b2ecc..f4898e0e2 100644
--- a/src/pbs.cpp
+++ b/src/pbs.cpp
@@ -235,7 +235,7 @@ static Vehicle *FindTrainOnTrackEnum(Vehicle *v, void *data)
if (v->type != VEH_TRAIN || (v->vehstatus & VS_CRASHED)) return NULL;
- Train *t = (Train *)v;
+ Train *t = Train::From(v);
if (HasBit((TrackBits)t->track, TrackdirToTrack(info->res.trackdir))) {
t = t->First();
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index a17dbb6c6..64be2e900 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -92,7 +92,7 @@ Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data)
if (v->type != VEH_TRAIN) return NULL;
- Train *t = (Train *)v;
+ Train *t = Train::From(v);
if ((t->track != rail_bits) && !TracksOverlap(t->track | rail_bits)) return NULL;
_error_message = VehicleInTheWayErrMsg(v);
@@ -1235,7 +1235,7 @@ Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
if (v->type == VEH_TRAIN && !IsArticulatedPart(v)) {
const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
- if (GetVehicleProperty(v, 0x0B, rvi->power) != 0) TrainPowerChanged((Train *)v->First());
+ if (GetVehicleProperty(v, 0x0B, rvi->power) != 0) TrainPowerChanged(Train::From(v)->First());
}
return NULL;
@@ -2461,7 +2461,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
/* this routine applies only to trains in depot tiles */
if (u->type != VEH_TRAIN || !IsRailDepotTile(tile)) return VETSB_CONTINUE;
- Train *v = (Train *)u;
+ Train *v = Train::From(u);
/* depot direction */
dir = GetRailDepotDirection(tile);
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index dddc609c0..3023cd222 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -1541,7 +1541,7 @@ static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int
case ROAD_TILE_DEPOT: {
if (v->type != VEH_ROAD) break;
- RoadVehicle *rv = (RoadVehicle *)v;
+ RoadVehicle *rv = RoadVehicle::From(v);
if (rv->frame == RVC_DEPOT_STOP_FRAME &&
_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == rv->state) {
rv->state = RVSB_IN_DEPOT;
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 8943b44d6..832237c06 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -762,7 +762,7 @@ static RoadVehicle *RoadVehFindCloseTo(RoadVehicle *v, int x, int y, Direction d
if (++front->blocked_ctr > 1480) return NULL;
- return (RoadVehicle *)rvf.best;
+ return RoadVehicle::From(rvf.best);
}
static void RoadVehArrivesAt(const RoadVehicle *v, Station *st)
diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp
index 09ebd1fc9..19f6cec82 100644
--- a/src/roadveh_gui.cpp
+++ b/src/roadveh_gui.cpp
@@ -130,7 +130,7 @@ void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int c
int highlight_w = 0;
for (int dx = 0; v != NULL && dx < max_length ; v = v->Next()) {
- int width = ((const RoadVehicle *)v)->rcache.cached_veh_length;
+ int width = RoadVehicle::From(v)->rcache.cached_veh_length;
if (dx + width > 0 && dx <= max_length) {
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 911e687dd..9ec6b231a 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -912,9 +912,9 @@ bool AfterLoadGame()
continue;
}
if (v->type == VEH_TRAIN) {
- ((Train *)v)->track = TRACK_BIT_WORMHOLE;
+ Train::From(v)->track = TRACK_BIT_WORMHOLE;
} else {
- ((RoadVehicle *)v)->state = RVSB_WORMHOLE;
+ RoadVehicle::From(v)->state = RVSB_WORMHOLE;
}
}
}
diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp
index 18815c737..b3358813c 100644
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -177,7 +177,7 @@ void FixOldVehicles()
/* We haven't used this bit for stations for ages */
if (v->type == VEH_ROAD) {
- RoadVehicle *rv = (RoadVehicle *)v;
+ RoadVehicle *rv = RoadVehicle::From(v);
if (rv->state != RVSB_IN_DEPOT && rv->state != RVSB_WORMHOLE) {
ClrBit(rv->state, RVS_IS_STOPPING);
}
@@ -1316,7 +1316,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
};
if (v->spritenum / 2 >= lengthof(spriteset_rail)) return false;
v->spritenum = spriteset_rail[v->spritenum / 2]; // adjust railway sprite set offset
- ((Train *)v)->railtype = type == 0x25 ? 1 : 0; // monorail / rail
+ Train::From(v)->railtype = type == 0x25 ? 1 : 0; // monorail / rail
break;
}
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index 9c2610384..415ba76b9 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -242,8 +242,8 @@ void AfterLoadVehicles(bool part_of_load)
if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
v->first = NULL;
- if (v->type == VEH_TRAIN) ((Train *)v)->tcache.first_engine = INVALID_ENGINE;
- if (v->type == VEH_ROAD) ((RoadVehicle *)v)->rcache.first_engine = INVALID_ENGINE;
+ if (v->type == VEH_TRAIN) Train::From(v)->tcache.first_engine = INVALID_ENGINE;
+ if (v->type == VEH_ROAD) RoadVehicle::From(v)->rcache.first_engine = INVALID_ENGINE;
v->cargo.InvalidateCache();
}
@@ -308,10 +308,10 @@ void AfterLoadVehicles(bool part_of_load)
assert(v->first != NULL);
if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) {
- if (IsFrontEngine(v)) ((Train *)v)->tcache.last_speed = v->cur_speed; // update displayed train speed
- TrainConsistChanged((Train *)v, false);
+ if (IsFrontEngine(v)) Train::From(v)->tcache.last_speed = v->cur_speed; // update displayed train speed
+ TrainConsistChanged(Train::From(v), false);
} else if (v->type == VEH_ROAD && IsRoadVehFront(v)) {
- RoadVehUpdateCache((RoadVehicle *)v);
+ RoadVehUpdateCache(RoadVehicle::From(v));
}
}
@@ -335,7 +335,7 @@ void AfterLoadVehicles(bool part_of_load)
FOR_ALL_VEHICLES(v) {
switch (v->type) {
case VEH_ROAD: {
- RoadVehicle *rv = (RoadVehicle *)v;
+ RoadVehicle *rv = RoadVehicle::From(v);
rv->roadtype = HasBit(EngInfo(v->First()->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
rv->compatible_roadtypes = RoadTypeToRoadTypes(rv->roadtype);
}
@@ -356,10 +356,10 @@ void AfterLoadVehicles(bool part_of_load)
/* In the case of a helicopter we will update the rotor sprites */
if (v->subtype == AIR_HELICOPTER) {
Vehicle *rotor = shadow->Next();
- rotor->cur_image = GetRotorImage((Aircraft *)v);
+ rotor->cur_image = GetRotorImage(Aircraft::From(v));
}
- UpdateAircraftCache((Aircraft *)v);
+ UpdateAircraftCache(Aircraft::From(v));
}
break;
default: break;
diff --git a/src/signal.cpp b/src/signal.cpp
index b7df907e6..187227b40 100644
--- a/src/signal.cpp
+++ b/src/signal.cpp
@@ -184,7 +184,7 @@ static SmallSet<DiagDirection, SIG_GLOB_SIZE> _globset("_globset"); ///< set of
/** Check whether there is a train on rail, not in a depot */
static Vehicle *TrainOnTileEnum(Vehicle *v, void *)
{
- if (v->type != VEH_TRAIN || ((Train *)v)->track == TRACK_BIT_DEPOT) return NULL;
+ if (v->type != VEH_TRAIN || Train::From(v)->track == TRACK_BIT_DEPOT) return NULL;
return v;
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index a4f9df11a..0c4ee2de4 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1488,7 +1488,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
static Vehicle *ClearRoadStopStatusEnum(Vehicle *v, void *)
{
- if (v->type == VEH_ROAD) ((RoadVehicle *)v)->state &= RVSB_ROAD_STOP_TRACKDIR_MASK;
+ if (v->type == VEH_ROAD) RoadVehicle::From(v)->state &= RVSB_ROAD_STOP_TRACKDIR_MASK;
return NULL;
}
@@ -2617,7 +2617,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
int station_ahead;
int station_length;
- int stop = GetTrainStopLocation(station_id, tile, (Train *)v, &station_ahead, &station_length);
+ int stop = GetTrainStopLocation(station_id, tile, Train::From(v), &station_ahead, &station_length);
/* Stop whenever that amount of station ahead + the distance from the
* begin of the platform to the stop location is longer than the length
@@ -2645,7 +2645,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
}
}
} else if (v->type == VEH_ROAD) {
- RoadVehicle *rv = (RoadVehicle *)v;
+ RoadVehicle *rv = RoadVehicle::From(v);
if (rv->state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)rv->state) && rv->frame == 0) {
if (IsRoadStop(tile) && IsRoadVehFront(v)) {
/* Attempt to allocate a parking bay in a road stop */
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 7a377098c..505e2b3cf 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1725,7 +1725,7 @@ static Vehicle *TrainApproachingCrossingEnum(Vehicle *v, void *data)
TileIndex tile = *(TileIndex*)data;
- if (TrainApproachingCrossingTile((Train *)v) != tile) return NULL;
+ if (TrainApproachingCrossingTile(Train::From(v)) != tile) return NULL;
return v;
}
@@ -1800,7 +1800,7 @@ static void AdvanceWagonsBeforeSwap(Train *v)
{
Train *base = v;
Train *first = base; // first vehicle to move
- Train *last = (Train *)GetLastVehicleInChain(v); // last vehicle to move
+ Train *last = Train::From(GetLastVehicleInChain(v)); // last vehicle to move
uint length = CountVehiclesInChain(v);
while (length > 2) {
@@ -1849,7 +1849,7 @@ static void AdvanceWagonsAfterSwap(Train *v)
Train *base = v;
Train *first = base; // first vehicle to move
- Train *last = (Train *)GetLastVehicleInChain(v); // last vehicle to move
+ Train *last = Train::From(GetLastVehicleInChain(v)); // last vehicle to move
uint length = CountVehiclesInChain(v);
/* we have to make sure all wagons that leave a depot because of train reversing are moved coorectly
@@ -3559,7 +3559,7 @@ static Vehicle *FindTrainCollideEnum(Vehicle *v, void *data)
Vehicle *coll = v->First();
/* can't collide with own wagons && can't crash in depot && the same height level */
- if (coll != tcc->v && ((Train *)v)->track != TRACK_BIT_DEPOT && abs(v->z_pos - tcc->v->z_pos) < 6) {
+ if (coll != tcc->v && Train::From(v)->track != TRACK_BIT_DEPOT && abs(v->z_pos - tcc->v->z_pos) < 6) {
int x_diff = v->x_pos - tcc->v->x_pos;
int y_diff = v->y_pos - tcc->v->y_pos;
@@ -3567,8 +3567,8 @@ static Vehicle *FindTrainCollideEnum(Vehicle *v, void *data)
if (x_diff * x_diff + y_diff * y_diff > 25) return NULL;
/* crash both trains */
- tcc->num += TrainCrashed((Train *)tcc->v);
- tcc->num += TrainCrashed((Train *)coll);
+ tcc->num += TrainCrashed(Train::From(tcc->v));
+ tcc->num += TrainCrashed(Train::From(coll));
/* Try to reserve all tiles directly under the crashed trains.
* As there might be more than two trains involved, we have to do that for all vehicles */
@@ -3632,8 +3632,8 @@ static Vehicle *CheckVehicleAtSignal(Vehicle *v, void *data)
DiagDirection exitdir = *(DiagDirection *)data;
/* front engine of a train, not inside wormhole or depot, not crashed */
- if (v->type == VEH_TRAIN && IsFrontEngine(v) && (((Train *)v)->track & TRACK_BIT_MASK) != 0 && !(v->vehstatus & VS_CRASHED)) {
- if (v->cur_speed <= 5 && TrainExitDir(v->direction, ((Train *)v)->track) == exitdir) return v;
+ if (v->type == VEH_TRAIN && IsFrontEngine(v) && (Train::From(v)->track & TRACK_BIT_MASK) && !(v->vehstatus & VS_CRASHED)) {
+ if (v->cur_speed <= 5 && TrainExitDir(v->direction, Train::From(v)->track) == exitdir) return v;
}
return NULL;
@@ -3942,11 +3942,11 @@ static Vehicle *CollectTrackbitsFromCrashedVehiclesEnum(Vehicle *v, void *data)
TrackBits *trackbits = (TrackBits *)data;
if (v->type == VEH_TRAIN && (v->vehstatus & VS_CRASHED) != 0) {
- if ((((Train *)v)->track & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) {
+ if ((Train::From(v)->track & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) {
/* Vehicle is inside a wormhole, v->track contains no useful value then. */
*trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(v->tile));
} else {
- *trackbits |= ((Train *)v)->track;
+ *trackbits |= Train::From(v)->track;
}
}
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index 8dc526c56..2ef9e786c 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -80,7 +80,7 @@ void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int cou
_cur_dpi = &tmp_dpi;
do {
- int width = ((const Train *)v)->tcache.cached_veh_length;
+ int width = Train::From(v)->tcache.cached_veh_length;
if (dx + width > 0) {
if (dx <= count) {
@@ -236,7 +236,7 @@ void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_
do {
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
DrawSprite(u->GetImage(DIR_W), pal, x + WagonLengthToPixels(4 + dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
- dx += ((const Train *)u)->tcache.cached_veh_length;
+ dx += Train::From(u)->tcache.cached_veh_length;
u = u->Next();
} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index d883c650b..5d769053f 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -1385,7 +1385,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
DiagDirection vdir;
if (v->type == VEH_TRAIN) {
- Train *t = (Train *)v;
+ Train *t = Train::From(v);
fc = (x & 0xF) + (y << 4);
vdir = DirToDiagDir(t->direction);
@@ -1414,7 +1414,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
return VETSB_ENTERED_WORMHOLE;
}
} else if (v->type == VEH_ROAD) {
- RoadVehicle *rv = (RoadVehicle *)v;
+ RoadVehicle *rv = RoadVehicle::From(v);
fc = (x & 0xF) + (y << 4);
vdir = DirToDiagDir(v->direction);
@@ -1464,18 +1464,18 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
}
switch (v->type) {
case VEH_TRAIN: {
- Train *t = (Train *)v;
+ Train *t = Train::From(v);
t->track = TRACK_BIT_WORMHOLE;
ClrBit(t->flags, VRF_GOINGUP);
ClrBit(t->flags, VRF_GOINGDOWN);
} break;
case VEH_ROAD:
- ((RoadVehicle *)v)->state = RVSB_WORMHOLE;
+ RoadVehicle::From(v)->state = RVSB_WORMHOLE;
break;
case VEH_SHIP:
- ((Ship *)v)->state = TRACK_BIT_WORMHOLE;
+ Ship::From(v)->state = TRACK_BIT_WORMHOLE;
break;
default: NOT_REACHED();
@@ -1485,7 +1485,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
v->tile = tile;
switch (v->type) {
case VEH_TRAIN: {
- Train *t = (Train *)v;
+ Train *t = Train::From(v);
if (t->track == TRACK_BIT_WORMHOLE) {
t->track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
return VETSB_ENTERED_WORMHOLE;
@@ -1493,7 +1493,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
} break;
case VEH_ROAD: {
- RoadVehicle *rv = (RoadVehicle *)v;
+ RoadVehicle *rv = RoadVehicle::From(v);
if (rv->state == RVSB_WORMHOLE) {
rv->state = _road_exit_tunnel_state[dir];
rv->frame = 0;
@@ -1502,7 +1502,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
} break;
case VEH_SHIP: {
- Ship *ship = (Ship *)v;
+ Ship *ship = Ship::From(v);
if (ship->state == TRACK_BIT_WORMHOLE) {
ship->state = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
return VETSB_ENTERED_WORMHOLE;
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);
}
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index b6bcbb4b6..b5e7a16f5 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -573,6 +573,28 @@ struct SpecializedVehicle : public Vehicle {
{
return IsValidID(index) ? Get(index) : NULL ;
}
+
+ /**
+ * Converts a Vehicle to SpecializedVehicle with type checking.
+ * @param v Vehicle pointer
+ * @return pointer to SpecializedVehicle
+ */
+ static FORCEINLINE T *From(Vehicle *v)
+ {
+ assert(v->type == Type);
+ return (T *)v;
+ }
+
+ /**
+ * Converts a const Vehicle to const SpecializedVehicle with type checking.
+ * @param v Vehicle pointer
+ * @return pointer to SpecializedVehicle
+ */
+ static FORCEINLINE const T *From(const Vehicle *v)
+ {
+ assert(v->type == Type);
+ return (const T *)v;
+ }
};
#define FOR_ALL_VEHICLES_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, vehicle_index, var, 0) if (var->type == name::EXPECTED_TYPE)
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index d1e5b4df3..a7ff57e53 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -67,7 +67,7 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
switch (v->type) {
case VEH_TRAIN:
- if ((v->vehstatus & VS_STOPPED) && ((Train *)v)->tcache.cached_power == 0) return_cmd_error(STR_TRAIN_START_NO_CATENARY);
+ if ((v->vehstatus & VS_STOPPED) && Train::From(v)->tcache.cached_power == 0) return_cmd_error(STR_TRAIN_START_NO_CATENARY);
break;
case VEH_SHIP:
@@ -75,7 +75,7 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
break;
case VEH_AIRCRAFT: {
- Aircraft *a = (Aircraft *)v;
+ Aircraft *a = Aircraft::From(v);
/* cannot stop airplane when in flight, or when taking off / landing */
if (a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
} break;
@@ -152,7 +152,7 @@ CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32
if (!vehicle_list_window) {
if (vehicle_type == VEH_TRAIN) {
- if (CheckTrainInDepot((const Train *)v, false) == -1) continue;
+ if (CheckTrainInDepot(Train::From(v), false) == -1) continue;
} else {
if (!(v->vehstatus & VS_HIDDEN)) continue;
}
@@ -349,7 +349,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (!CheckOwnership(v->owner)) return CMD_ERROR;
- if (v->type == VEH_TRAIN && (!IsFrontEngine(v) || ((Train *)v)->crash_anim_pos >= 4400)) return CMD_ERROR;
+ if (v->type == VEH_TRAIN && (!IsFrontEngine(v) || Train::From(v)->crash_anim_pos >= 4400)) return CMD_ERROR;
/* check that we can allocate enough vehicles */
if (!(flags & DC_EXEC)) {
@@ -381,8 +381,8 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (flags & DC_EXEC) {
w = Vehicle::Get(_new_vehicle_id);
- if (v->type == VEH_TRAIN && HasBit(((Train *)v)->flags, VRF_REVERSE_DIRECTION)) {
- SetBit(((Train *)w)->flags, VRF_REVERSE_DIRECTION);
+ if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) {
+ SetBit(Train::From(w)->flags, VRF_REVERSE_DIRECTION);
}
if (v->type == VEH_TRAIN && !IsFrontEngine(v)) {
@@ -403,7 +403,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop
}
- } while (v->type == VEH_TRAIN && (v = GetNextVehicle((Train *)v)) != NULL);
+ } while (v->type == VEH_TRAIN && (v = GetNextVehicle(Train::From(v))) != NULL);
if ((flags & DC_EXEC) && v_front->type == VEH_TRAIN) {
/* for trains this needs to be the front engine due to the callback function */
@@ -437,7 +437,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
if (w->type == VEH_TRAIN && EngineHasArticPart(w)) {
- w = GetNextArticPart((Train *)w);
+ w = GetNextArticPart(Train::From(w));
} else if (w->type == VEH_ROAD && RoadVehHasArticPart(w)) {
w = w->Next();
} else {
@@ -453,7 +453,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
if (v->type == VEH_TRAIN && EngineHasArticPart(v)) {
- v = GetNextArticPart((Train *)v);
+ v = GetNextArticPart(Train::From(v));
} else if (v->type == VEH_ROAD && RoadVehHasArticPart(v)) {
v = v->Next();
} else {
@@ -461,8 +461,8 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
} while (v != NULL);
- if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = GetNextVehicle((Train *)w);
- } while (v->type == VEH_TRAIN && (v = GetNextVehicle((Train *)v)) != NULL);
+ if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = GetNextVehicle(Train::From(w));
+ } while (v->type == VEH_TRAIN && (v = GetNextVehicle(Train::From(v))) != NULL);
if (flags & DC_EXEC) {
/*
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 3f6e67a1e..b2e5f1cd2 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -603,7 +603,7 @@ static int CDECL VehicleMaxSpeedSorter(const Vehicle * const *a, const Vehicle *
{
int r = 0;
if ((*a)->type == VEH_TRAIN && (*b)->type == VEH_TRAIN) {
- r = ((const Train *)(*a))->tcache.cached_max_speed - ((const Train *)(*b))->tcache.cached_max_speed;
+ r = Train::From(*a)->tcache.cached_max_speed - Train::From(*b)->tcache.cached_max_speed;
} else {
r = (*a)->max_speed - (*b)->max_speed;
}
@@ -636,13 +636,13 @@ static int CDECL VehicleLengthSorter(const Vehicle * const *a, const Vehicle * c
int r = 0;
switch ((*a)->type) {
case VEH_TRAIN:
- r = ((const Train *)(*a))->tcache.cached_total_length - ((const Train *)(*b))->tcache.cached_total_length;
+ r = Train::From(*a)->tcache.cached_total_length - Train::From(*b)->tcache.cached_total_length;
break;
case VEH_ROAD: {
const RoadVehicle *u;
- for (u = (const RoadVehicle *)*a; u != NULL; u = u->Next()) r += u->rcache.cached_veh_length;
- for (u = (const RoadVehicle *)*b; u != NULL; u = u->Next()) r -= u->rcache.cached_veh_length;
+ for (u = RoadVehicle::From(*a); u != NULL; u = u->Next()) r += u->rcache.cached_veh_length;
+ for (u = RoadVehicle::From(*b); u != NULL; u = u->Next()) r -= u->rcache.cached_veh_length;
} break;
default: NOT_REACHED();
@@ -1471,10 +1471,10 @@ struct VehicleDetailsWindow : Window {
switch (v->type) {
case VEH_TRAIN:
SetDParam(2, v->GetDisplayMaxSpeed());
- SetDParam(1, ((const Train *)v)->tcache.cached_power);
- SetDParam(0, ((const Train *)v)->tcache.cached_weight);
- SetDParam(3, ((const Train *)v)->tcache.cached_max_te / 1000);
- DrawString(2, this->width - 2, 25, (_settings_game.vehicle.train_acceleration_model != TAM_ORIGINAL && ((const Train *)v)->railtype != RAILTYPE_MAGLEV) ?
+ SetDParam(1, Train::From(v)->tcache.cached_power);
+ SetDParam(0, Train::From(v)->tcache.cached_weight);
+ SetDParam(3, Train::From(v)->tcache.cached_max_te / 1000);
+ DrawString(2, this->width - 2, 25, (_settings_game.vehicle.train_acceleration_model != TAM_ORIGINAL && Train::From(v)->railtype != RAILTYPE_MAGLEV) ?
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE :
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED);
break;
@@ -1943,7 +1943,7 @@ struct VehicleViewWindow : Window {
} else if (v->vehstatus & VS_STOPPED) {
if (v->type == VEH_TRAIN) {
if (v->cur_speed == 0) {
- if (((const Train *)v)->tcache.cached_power == 0) {
+ if (Train::From(v)->tcache.cached_power == 0) {
str = STR_TRAIN_NO_POWER;
} else {
str = STR_VEHICLE_STATUS_STOPPED;
@@ -1955,7 +1955,7 @@ struct VehicleViewWindow : Window {
} else { // no train
str = STR_VEHICLE_STATUS_STOPPED;
}
- } else if (v->type == VEH_TRAIN && HasBit(((const Train *)v)->flags, VRF_TRAIN_STUCK)) {
+ } else if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_TRAIN_STUCK)) {
str = STR_TRAIN_STUCK;
} else { // vehicle is in a "normal" state, show current order
switch (v->current_order.GetType()) {
diff --git a/src/vehicle_type.h b/src/vehicle_type.h
index c642cfcf5..b008e1d87 100644
--- a/src/vehicle_type.h
+++ b/src/vehicle_type.h
@@ -28,6 +28,8 @@ struct Train;
struct RoadVehicle;
struct Ship;
struct Aircraft;
+struct EffectVehicle;
+struct DisasterVehicle;
struct BaseVehicle
{
diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp
index 14d291254..25e66ec90 100644
--- a/src/vehiclelist.cpp
+++ b/src/vehiclelist.cpp
@@ -29,7 +29,7 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine
switch (type) {
case VEH_TRAIN:
if (IsArticulatedPart(v) || IsRearDualheaded(v)) continue;
- if (((const Train *)v)->track != TRACK_BIT_DEPOT) continue;
+ if (Train::From(v)->track != TRACK_BIT_DEPOT) continue;
if (wagons != NULL && IsFreeWagon(v->First())) {
if (individual_wagons || IsFreeWagon(v)) *wagons->Append() = v;
continue;
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index a37fc27ec..17aadffce 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -813,22 +813,22 @@ static void FloodVehicle(Vehicle *v)
/* FreeTrainTrackReservation() calls GetVehicleTrackdir() that doesn't like crashed vehicles.
* In this case, v->direction matches v->u.rail.track, so we can do this (it wasn't crashed before) */
v->vehstatus &= ~VS_CRASHED;
- FreeTrainTrackReservation((Train *)v);
+ FreeTrainTrackReservation(Train::From(v));
v->vehstatus |= VS_CRASHED;
}
- ((Train *)v)->crash_anim_pos = 4000; // max 4440, disappear pretty fast
+ Train::From(v)->crash_anim_pos = 4000; // max 4440, disappear pretty fast
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
break;
case VEH_ROAD:
if (IsRoadVehFront(v)) pass += 1; // driver
- ((RoadVehicle *)v)->crashed_ctr = 2000; // max 2220, disappear pretty fast
+ RoadVehicle::From(v)->crashed_ctr = 2000; // max 2220, disappear pretty fast
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
break;
case VEH_AIRCRAFT:
pass += 2; // driver
- ((Aircraft *)v)->crashed_counter = 9000; // max 10000, disappear pretty fast
+ Aircraft::From(v)->crashed_counter = 9000; // max 10000, disappear pretty fast
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
break;
}
diff --git a/src/yapf/follow_track.hpp b/src/yapf/follow_track.hpp
index d169733a7..3a55a3adc 100644
--- a/src/yapf/follow_track.hpp
+++ b/src/yapf/follow_track.hpp
@@ -55,7 +55,7 @@ struct CFollowTrackT
{
assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
m_veh = v;
- Init(v != NULL ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? ((const Train *)v)->compatible_railtypes : railtype_override, pPerf);
+ Init(v != NULL ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override, pPerf);
}
FORCEINLINE void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf)
@@ -76,7 +76,7 @@ struct CFollowTrackT
FORCEINLINE static TransportType TT() {return Ttr_type_;}
FORCEINLINE static bool IsWaterTT() {return TT() == TRANSPORT_WATER;}
FORCEINLINE static bool IsRailTT() {return TT() == TRANSPORT_RAIL;}
- FORCEINLINE bool IsTram() {return IsRoadTT() && HasBit(((const RoadVehicle *)m_veh)->compatible_roadtypes, ROADTYPE_TRAM);}
+ FORCEINLINE bool IsTram() {return IsRoadTT() && HasBit(RoadVehicle::From(m_veh)->compatible_roadtypes, ROADTYPE_TRAM);}
FORCEINLINE static bool IsRoadTT() {return TT() == TRANSPORT_ROAD;}
FORCEINLINE static bool Allow90degTurns() {return T90deg_turns_allowed_;}
FORCEINLINE static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;}
@@ -106,7 +106,7 @@ struct CFollowTrackT
m_old_tile = old_tile;
m_old_td = old_td;
m_err = EC_NONE;
- assert(((TrackStatusToTrackdirBits(GetTileTrackStatus(m_old_tile, TT(), IsRoadTT() && m_veh != NULL ? ((const RoadVehicle *)m_veh)->compatible_roadtypes : 0)) & TrackdirToTrackdirBits(m_old_td)) != 0) ||
+ assert(((TrackStatusToTrackdirBits(GetTileTrackStatus(m_old_tile, TT(), IsRoadTT() && m_veh != NULL ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0)) & TrackdirToTrackdirBits(m_old_td)) != 0) ||
(IsTram() && GetSingleTramBit(m_old_tile) != INVALID_DIAGDIR)); // Disable the assertion for single tram bits
m_exitdir = TrackdirToExitdir(m_old_td);
if (ForcedReverse()) return true;
@@ -207,7 +207,7 @@ protected:
if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
} else {
- m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), IsRoadTT() && m_veh != NULL ? ((const RoadVehicle *)m_veh)->compatible_roadtypes : 0));
+ m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), IsRoadTT() && m_veh != NULL ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0));
if (IsTram() && m_new_td_bits == 0) {
/* GetTileTrackStatus() returns 0 for single tram bits.
diff --git a/src/yapf/yapf_costrail.hpp b/src/yapf/yapf_costrail.hpp
index 9504beced..00c824b1a 100644
--- a/src/yapf/yapf_costrail.hpp
+++ b/src/yapf/yapf_costrail.hpp
@@ -247,8 +247,8 @@ public:
const Vehicle *v = Yapf().GetVehicle();
assert(v != NULL);
assert(v->type == VEH_TRAIN);
- assert(((const Train *)v)->tcache.cached_total_length != 0);
- int missing_platform_length = (((const Train *)v)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length;
+ assert(Train::From(v)->tcache.cached_total_length != 0);
+ int missing_platform_length = (Train::From(v)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length;
if (missing_platform_length < 0) {
/* apply penalty for longer platform than needed */
cost += Yapf().PfGetSettings().rail_longer_platform_penalty + Yapf().PfGetSettings().rail_longer_platform_per_tile_penalty * -missing_platform_length;
diff --git a/src/yapf/yapf_destrail.hpp b/src/yapf/yapf_destrail.hpp
index 498cc5975..08b1da070 100644
--- a/src/yapf/yapf_destrail.hpp
+++ b/src/yapf/yapf_destrail.hpp
@@ -13,8 +13,8 @@ protected:
public:
void SetDestination(const Vehicle *v, bool override_rail_type = false)
{
- m_compatible_railtypes = ((const Train *)v)->compatible_railtypes;
- if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(((const Train *)v)->railtype)->compatible_railtypes;
+ m_compatible_railtypes = Train::From(v)->compatible_railtypes;
+ if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(Train::From(v)->railtype)->compatible_railtypes;
}
bool IsCompatibleRailType(RailType rt)
@@ -91,8 +91,8 @@ public:
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
{
return
- IsSafeWaitingPosition((const Train *)Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns()) &&
- IsWaitingPositionFree((const Train *)Yapf().GetVehicle(), tile, td, !TrackFollower::Allow90degTurns());
+ IsSafeWaitingPosition(Train::From(Yapf().GetVehicle()), tile, td, true, !TrackFollower::Allow90degTurns()) &&
+ IsWaitingPositionFree(Train::From(Yapf().GetVehicle()), tile, td, !TrackFollower::Allow90degTurns());
}
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
diff --git a/src/yapf/yapf_rail.cpp b/src/yapf/yapf_rail.cpp
index 71e272038..13c064eb8 100644
--- a/src/yapf/yapf_rail.cpp
+++ b/src/yapf/yapf_rail.cpp
@@ -54,7 +54,7 @@ private:
bool FindSafePositionProc(TileIndex tile, Trackdir td)
{
- if (IsSafeWaitingPosition((const Train *)Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns())) {
+ if (IsSafeWaitingPosition(Train::From(Yapf().GetVehicle()), tile, td, true, !TrackFollower::Allow90degTurns())) {
m_res_dest = tile;
m_res_dest_td = td;
return false; // Stop iterating segment
@@ -149,7 +149,7 @@ public:
}
/* Don't bother if the target is reserved. */
- if (!IsWaitingPositionFree((const Train *)Yapf().GetVehicle(), m_res_dest, m_res_dest_td)) return false;
+ if (!IsWaitingPositionFree(Train::From(Yapf().GetVehicle()), m_res_dest, m_res_dest_td)) return false;
for (Node *node = m_res_node; node->m_parent != NULL; node = node->m_parent) {
node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack);
@@ -411,7 +411,7 @@ public:
if (target != NULL) target->tile = INVALID_TILE;
/* set origin and destination nodes */
- PBSTileInfo origin = FollowTrainReservation((const Train *)v);
+ PBSTileInfo origin = FollowTrainReservation(Train::From(v));
Yapf().SetOrigin(origin.tile, origin.trackdir, INVALID_TILE, INVALID_TRACKDIR, 1, true);
Yapf().SetDestination(v);
@@ -536,9 +536,9 @@ Trackdir YapfChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection ent
bool YapfCheckReverseTrain(const Vehicle *vt)
{
- const Train *v = (const Train *)vt;
+ const Train *v = Train::From(vt);
/* last wagon */
- const Train *last_veh = (const Train *)GetLastVehicleInChain(v);
+ const Train *last_veh = Train::From(GetLastVehicleInChain(v));
/* get trackdirs of both ends */
Trackdir td = v->GetVehicleTrackdir();
@@ -602,7 +602,7 @@ bool YapfFindNearestRailDepotTwoWay(const Vehicle *v, int max_distance, int reve
const Vehicle *last_veh = GetLastVehicleInChain(v);
- PBSTileInfo origin = FollowTrainReservation((const Train *)v);
+ PBSTileInfo origin = FollowTrainReservation(Train::From(v));
TileIndex last_tile = last_veh->tile;
Trackdir td_rev = ReverseTrackdir(last_veh->GetVehicleTrackdir());
diff --git a/src/yapf/yapf_road.cpp b/src/yapf/yapf_road.cpp
index ce627b1f0..c14b5b484 100644
--- a/src/yapf/yapf_road.cpp
+++ b/src/yapf/yapf_road.cpp
@@ -299,13 +299,13 @@ public:
/* our source tile will be the next vehicle tile (should be the given one) */
TileIndex src_tile = tile;
/* get available trackdirs on the start tile */
- TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes));
+ TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes));
/* select reachable trackdirs only */
src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
/* get available trackdirs on the destination tile */
TileIndex dest_tile = v->dest_tile;
- TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes));
+ TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes));
/* set origin and destination nodes */
Yapf().SetOrigin(src_tile, src_trackdirs);
@@ -349,7 +349,7 @@ public:
/* set destination tile, trackdir
* get available trackdirs on the destination tile */
- TrackdirBits dst_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes));
+ TrackdirBits dst_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes));
Yapf().SetDestination(dst_tile, dst_td_bits);
/* if path not found - return distance = UINT_MAX */
@@ -374,7 +374,7 @@ public:
/* set origin (tile, trackdir) */
TileIndex src_tile = v->tile;
Trackdir src_td = v->GetVehicleTrackdir();
- if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
+ if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
/* sometimes the roadveh is not on the road (it resides on non-existing track)
* how should we handle that situation? */
return false;
@@ -471,7 +471,7 @@ Depot *YapfFindNearestRoadDepot(const Vehicle *v)
{
TileIndex tile = v->tile;
Trackdir trackdir = v->GetVehicleTrackdir();
- if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
+ if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
return NULL;
}