mirror of https://github.com/OpenTTD/OpenTTD
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
parent
c90819ff6d
commit
0c10006907
|
@ -46,11 +46,11 @@
|
||||||
case VEH_ROAD: {
|
case VEH_ROAD: {
|
||||||
uint total_length = 0;
|
uint total_length = 0;
|
||||||
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
|
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;
|
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;
|
default: return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,11 +86,11 @@
|
||||||
EnforcePrecondition(false, ::Vehicle::Get(source_vehicle_id)->type == VEH_TRAIN);
|
EnforcePrecondition(false, ::Vehicle::Get(source_vehicle_id)->type == VEH_TRAIN);
|
||||||
EnforcePrecondition(false, dest_vehicle_id == -1 || ::Vehicle::Get(dest_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);
|
while (source_wagon-- > 0) v = GetNextUnit(v);
|
||||||
const Train *w = NULL;
|
const Train *w = NULL;
|
||||||
if (dest_vehicle_id != -1) {
|
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);
|
while (dest_wagon-- > 0) w = GetNextUnit(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@
|
||||||
EnforcePrecondition(false, IsValidVehicle(vehicle_id) && wagon < GetNumWagons(vehicle_id));
|
EnforcePrecondition(false, IsValidVehicle(vehicle_id) && wagon < GetNumWagons(vehicle_id));
|
||||||
EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN);
|
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);
|
while (wagon-- > 0) v = GetNextUnit(v);
|
||||||
|
|
||||||
return AIObject::DoCommand(0, v->index, sell_attached_wagons ? 1 : 0, CMD_SELL_RAIL_WAGON);
|
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);
|
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||||
if (v->type == VEH_TRAIN) {
|
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;
|
return v->engine_type;
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@
|
||||||
|
|
||||||
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||||
if (v->type == VEH_TRAIN) {
|
if (v->type == VEH_TRAIN) {
|
||||||
while (wagon-- > 0) v = GetNextUnit((const Train *)v);
|
while (wagon-- > 0) v = GetNextUnit(::Train::From(v));
|
||||||
}
|
}
|
||||||
return v->age;
|
return v->age;
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@
|
||||||
if (!IsValidVehicle(vehicle_id)) return AIRoad::ROADTYPE_INVALID;
|
if (!IsValidVehicle(vehicle_id)) return AIRoad::ROADTYPE_INVALID;
|
||||||
if (GetVehicleType(vehicle_id) != VT_ROAD) 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)
|
/* static */ int32 AIVehicle::GetCapacity(VehicleID vehicle_id, CargoID cargo)
|
||||||
|
@ -412,8 +412,8 @@
|
||||||
|
|
||||||
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_ROAD: return RoadVehHasArticPart(v);
|
case VEH_ROAD: return ::RoadVehHasArticPart(v);
|
||||||
case VEH_TRAIN: return EngineHasArticPart(v);
|
case VEH_TRAIN: return ::EngineHasArticPart(v);
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
|
||||||
DrawSprite(v->GetImage(DIR_W), pal, x + 25, y + 10);
|
DrawSprite(v->GetImage(DIR_W), pal, x + 25, y + 10);
|
||||||
if (v->subtype == AIR_HELICOPTER) {
|
if (v->subtype == AIR_HELICOPTER) {
|
||||||
const Aircraft *a = (const Aircraft *)v;
|
const Aircraft *a = Aircraft::From(v);
|
||||||
SpriteID rotor_sprite = GetCustomRotorSprite(a, true);
|
SpriteID rotor_sprite = GetCustomRotorSprite(a, true);
|
||||||
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
|
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
|
||||||
DrawSprite(rotor_sprite, PAL_NONE, x + 25, y + 5);
|
DrawSprite(rotor_sprite, PAL_NONE, x + 25, y + 5);
|
||||||
|
|
|
@ -208,7 +208,7 @@ bool IsArticulatedVehicleCarryingDifferentCargos(const Vehicle *v, CargoID *carg
|
||||||
|
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
v = (EngineHasArticPart((const Train *)v) ? GetNextArticPart((const Train *)v) : NULL);
|
v = (EngineHasArticPart(Train::From(v)) ? GetNextArticPart(Train::From(v)) : NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
|
@ -256,7 +256,7 @@ void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
|
||||||
|
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
v = (EngineHasArticPart((const Train *)v) ? GetNextArticPart((const Train *)v) : NULL);
|
v = (EngineHasArticPart(Train::From(v)) ? GetNextArticPart(Train::From(v)) : NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
|
@ -305,7 +305,7 @@ void AddArticulatedParts(Vehicle *first, VehicleType type)
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
|
||||||
case VEH_TRAIN: {
|
case VEH_TRAIN: {
|
||||||
Train *front = (Train *)first;
|
Train *front = Train::From(first);
|
||||||
Train *t = new Train();
|
Train *t = new Train();
|
||||||
v->SetNext(t);
|
v->SetNext(t);
|
||||||
v = t;
|
v = t;
|
||||||
|
@ -328,7 +328,7 @@ void AddArticulatedParts(Vehicle *first, VehicleType type)
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VEH_ROAD: {
|
case VEH_ROAD: {
|
||||||
RoadVehicle *front = (RoadVehicle *)first;
|
RoadVehicle *front = RoadVehicle::From(first);
|
||||||
RoadVehicle *rv = new RoadVehicle();
|
RoadVehicle *rv = new RoadVehicle();
|
||||||
v->SetNext(rv);
|
v->SetNext(rv);
|
||||||
v = rv;
|
v = rv;
|
||||||
|
|
|
@ -92,18 +92,18 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
|
||||||
assert(!part_of_chain || new_head->IsPrimaryVehicle());
|
assert(!part_of_chain || new_head->IsPrimaryVehicle());
|
||||||
/* Loop through source parts */
|
/* Loop through source parts */
|
||||||
for (Vehicle *src = old_veh; src != NULL; src = src->Next()) {
|
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 */
|
/* Skip vehicles, which do not belong to old_veh */
|
||||||
src = GetLastEnginePart((Train *)src);
|
src = GetLastEnginePart(Train::From(src));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (src->cargo_type >= NUM_CARGO || src->cargo.Count() == 0) continue;
|
if (src->cargo_type >= NUM_CARGO || src->cargo.Count() == 0) continue;
|
||||||
|
|
||||||
/* Find free space in the new chain */
|
/* Find free space in the new chain */
|
||||||
for (Vehicle *dest = new_head; dest != NULL && src->cargo.Count() > 0; dest = dest->Next()) {
|
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 */
|
/* Skip vehicles, which do not belong to new_head */
|
||||||
dest = GetLastEnginePart((Train *)dest);
|
dest = GetLastEnginePart(Train::From(dest));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (dest->cargo_type != src->cargo_type) 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 */
|
/* 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 */
|
/* 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);
|
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) {
|
if (old_head->type == VEH_TRAIN) {
|
||||||
/* Store the length of the old vehicle chain, rounded up to whole tiles */
|
/* 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
|
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 **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
|
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 */
|
* Note: The replacement vehicles can only successfully build as long as the old vehicles are still in their chain */
|
||||||
int i;
|
int i;
|
||||||
Train *w;
|
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);
|
assert(i < num_units);
|
||||||
old_vehs[i] = w;
|
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. */
|
/* Note: When autoreplace has already failed here, old_vehs[] is not completely initialized. But it is also not needed. */
|
||||||
if (cost.Succeeded()) {
|
if (cost.Succeeded()) {
|
||||||
/* Separate the head, so we can start constructing the new chain */
|
/* 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));
|
if (second != NULL) cost.AddCost(MoveVehicle(second, NULL, DC_EXEC | DC_AUTOREPLACE, true));
|
||||||
|
|
||||||
assert(GetNextUnit(new_head) == NULL);
|
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 :) */
|
* Note: The vehicle attach callback is disabled here :) */
|
||||||
if ((flags & DC_EXEC) == 0) {
|
if ((flags & DC_EXEC) == 0) {
|
||||||
/* Separate the head, so we can reattach the old vehicles */
|
/* 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);
|
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--) {
|
for (int i = num_units - 1; i > 0; i--) {
|
||||||
CommandCost ret = MoveVehicle(old_vehs[i], old_head, DC_EXEC | DC_AUTOREPLACE, false);
|
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;
|
bool any_replacements = false;
|
||||||
while (w != NULL && !any_replacements) {
|
while (w != NULL && !any_replacements) {
|
||||||
any_replacements = (GetNewEngineType(w, c) != INVALID_ENGINE);
|
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) {
|
if (any_replacements) {
|
||||||
|
|
|
@ -272,7 +272,7 @@ struct DepotWindow : Window {
|
||||||
DrawTrainImage(v, x + 21, sprite_y, this->sel, this->hscroll.cap + 4, this->hscroll.pos);
|
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) */
|
/* 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
|
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;
|
break;
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ struct DepotWindow : Window {
|
||||||
hnum = 8;
|
hnum = 8;
|
||||||
for (uint num = 0; num < this->vehicle_list.Length(); num++) {
|
for (uint num = 0; num < this->vehicle_list.Length(); num++) {
|
||||||
const Vehicle *v = this->vehicle_list[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 */
|
/* 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);
|
SetVScrollCount(w, this->vehicle_list.Length() + this->wagon_list.Length() + 1);
|
||||||
|
@ -450,7 +450,7 @@ struct DepotWindow : Window {
|
||||||
x += skip;
|
x += skip;
|
||||||
|
|
||||||
/* find the vehicle in this row that was clicked */
|
/* 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 */
|
/* if an articulated part was selected, find its parent */
|
||||||
while (v != NULL && IsArticulatedPart(v)) v = v->Previous();
|
while (v != NULL && IsArticulatedPart(v)) v = v->Previous();
|
||||||
|
@ -514,11 +514,11 @@ struct DepotWindow : Window {
|
||||||
|
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN:
|
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;
|
break;
|
||||||
|
|
||||||
case VEH_ROAD:
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -313,9 +313,8 @@ static bool DisasterTick_Ufo(DisasterVehicle *v)
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
/* Target a vehicle */
|
/* Target a vehicle */
|
||||||
Vehicle *u_tmp = Vehicle::Get(v->dest_tile);
|
RoadVehicle *u = RoadVehicle::Get(v->dest_tile);
|
||||||
assert(u_tmp != NULL && u_tmp->type == VEH_ROAD && IsRoadVehFront(u_tmp));
|
assert(u != NULL && u->type == VEH_ROAD && IsRoadVehFront(u));
|
||||||
RoadVehicle *u = (RoadVehicle *)u_tmp;
|
|
||||||
|
|
||||||
uint dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos);
|
uint dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos);
|
||||||
|
|
||||||
|
|
|
@ -1314,7 +1314,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
|
||||||
/* update stats */
|
/* update stats */
|
||||||
int t;
|
int t;
|
||||||
switch (u->type) {
|
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;
|
case VEH_ROAD: t = u->max_speed / 2; break;
|
||||||
default: t = u->max_speed; break;
|
default: t = u->max_speed; break;
|
||||||
}
|
}
|
||||||
|
@ -1423,7 +1423,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN) {
|
if (v->type == VEH_TRAIN) {
|
||||||
/* Each platform tile is worth 2 rail vehicles. */
|
/* 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) {
|
if (overhang > 0) {
|
||||||
unloading_time <<= 1;
|
unloading_time <<= 1;
|
||||||
unloading_time += (overhang * unloading_time) / 8;
|
unloading_time += (overhang * unloading_time) / 8;
|
||||||
|
|
|
@ -434,9 +434,9 @@ static uint8 LiveryHelper(EngineID engine, const Vehicle *v)
|
||||||
if (!Company::IsValidID(_current_company)) return 0;
|
if (!Company::IsValidID(_current_company)) return 0;
|
||||||
l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, NULL);
|
l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, NULL);
|
||||||
} else if (v->type == VEH_TRAIN) {
|
} 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) {
|
} 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 {
|
} else {
|
||||||
l = GetEngineLivery(v->engine_type, v->owner, INVALID_ENGINE, v);
|
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));
|
memset(common_subtypes, 0, sizeof(common_subtypes));
|
||||||
|
|
||||||
for (u = v; u != NULL; u = u->Next()) {
|
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 */
|
/* Skip empty engines */
|
||||||
if (u->cargo_cap == 0) continue;
|
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
|
uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height
|
||||||
byte airporttype = ATP_TTDP_LARGE;
|
byte airporttype = ATP_TTDP_LARGE;
|
||||||
|
|
||||||
const Station *st = GetTargetAirportIfValid((Aircraft *)v);
|
const Station *st = GetTargetAirportIfValid(Aircraft::From(v));
|
||||||
|
|
||||||
if (st != NULL) {
|
if (st != NULL) {
|
||||||
switch (st->airport_type) {
|
switch (st->airport_type) {
|
||||||
|
@ -668,7 +668,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
||||||
uint16 modflags = 0;
|
uint16 modflags = 0;
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN) {
|
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;
|
const Train *u = IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON) ? t->First() : t;
|
||||||
RailType railtype = GetRailType(v->tile);
|
RailType railtype = GetRailType(v->tile);
|
||||||
bool powered = IsTrainEngine(v) || (IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON));
|
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 0x47: return GB(Engine::Get(v->engine_type)->internal_id, 8, 8);
|
||||||
case 0x48:
|
case 0x48:
|
||||||
if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum;
|
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 0x49: return v->day_counter;
|
||||||
case 0x4A: return v->breakdowns_since_last_service;
|
case 0x4A: return v->breakdowns_since_last_service;
|
||||||
|
@ -768,7 +768,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
||||||
/* Vehicle specific properties */
|
/* Vehicle specific properties */
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN: {
|
case VEH_TRAIN: {
|
||||||
Train *t = (Train *)v;
|
Train *t = Train::From(v);
|
||||||
switch (variable - 0x80) {
|
switch (variable - 0x80) {
|
||||||
case 0x62: return t->track;
|
case 0x62: return t->track;
|
||||||
case 0x66: return t->railtype;
|
case 0x66: return t->railtype;
|
||||||
|
@ -784,7 +784,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VEH_ROAD: {
|
case VEH_ROAD: {
|
||||||
RoadVehicle *rv = (RoadVehicle *)v;
|
RoadVehicle *rv = RoadVehicle::From(v);
|
||||||
switch (variable - 0x80) {
|
switch (variable - 0x80) {
|
||||||
case 0x62: return rv->state;
|
case 0x62: return rv->state;
|
||||||
case 0x64: return rv->blocked_ctr;
|
case 0x64: return rv->blocked_ctr;
|
||||||
|
@ -797,7 +797,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VEH_AIRCRAFT: {
|
case VEH_AIRCRAFT: {
|
||||||
Aircraft *a = (Aircraft *)v;
|
Aircraft *a = Aircraft::From(v);
|
||||||
switch (variable - 0x80) {
|
switch (variable - 0x80) {
|
||||||
case 0x62: return MapAircraftMovementState(a); // Current movement state
|
case 0x62: return MapAircraftMovementState(a); // Current movement state
|
||||||
case 0x63: return a->targetairport; // Airport to which the action refers
|
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
|
/* 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),
|
* 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 */
|
* 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;
|
if (group != NULL) return group;
|
||||||
} else if (v->type == VEH_ROAD) {
|
} 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;
|
if (group != NULL) return group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -952,7 +952,7 @@ SpriteID GetRotorOverrideSprite(EngineID engine, const Aircraft *v, bool info_vi
|
||||||
bool UsesWagonOverride(const Vehicle *v)
|
bool UsesWagonOverride(const Vehicle *v)
|
||||||
{
|
{
|
||||||
assert(v->type == VEH_TRAIN);
|
assert(v->type == VEH_TRAIN);
|
||||||
return ((const Train *)v)->tcache.cached_override != NULL;
|
return Train::From(v)->tcache.cached_override != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -425,7 +425,7 @@ static int32 NPFFindDepot(AyStar *as, OpenListNode *current)
|
||||||
/** Find any safe and free tile. */
|
/** Find any safe and free tile. */
|
||||||
static int32 NPFFindSafeTile(AyStar *as, OpenListNode *current)
|
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
|
return
|
||||||
IsSafeWaitingPosition(v, current->path.node.tile, current->path.node.direction, true, _settings_game.pf.forbid_90_deg) &&
|
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) {
|
if (as->user_target != NULL && ((NPFFindStationOrTileData*)as->user_target)->reserve_path && as->user_data[NPF_TYPE] == TRANSPORT_RAIL) {
|
||||||
/* Path reservation is requested. */
|
/* 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(¤t->path, v);
|
const PathNode *target = FindSafePosition(¤t->path, v);
|
||||||
ftd->node = target->node;
|
ftd->node = target->node;
|
||||||
|
|
|
@ -1119,7 +1119,7 @@ void StateGameLoop()
|
||||||
|
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_ROAD: {
|
case VEH_ROAD: {
|
||||||
RoadVehicle *rv = (RoadVehicle *)v;
|
RoadVehicle *rv = RoadVehicle::From(v);
|
||||||
RoadVehicleCache cache = rv->rcache;
|
RoadVehicleCache cache = rv->rcache;
|
||||||
RoadVehUpdateCache(rv);
|
RoadVehUpdateCache(rv);
|
||||||
|
|
||||||
|
@ -1130,7 +1130,7 @@ void StateGameLoop()
|
||||||
|
|
||||||
case VEH_TRAIN: {
|
case VEH_TRAIN: {
|
||||||
uint length = 0;
|
uint length = 0;
|
||||||
Train *t = (Train *)v;
|
Train *t = Train::From(v);
|
||||||
for (Vehicle *u = t; u != NULL; u = u->Next()) length++;
|
for (Vehicle *u = t; u != NULL; u = u->Next()) length++;
|
||||||
|
|
||||||
TrainCache *wagons = MallocT<TrainCache>(length);
|
TrainCache *wagons = MallocT<TrainCache>(length);
|
||||||
|
@ -1151,7 +1151,7 @@ void StateGameLoop()
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VEH_AIRCRAFT: {
|
case VEH_AIRCRAFT: {
|
||||||
Aircraft *a = (Aircraft *)v;
|
Aircraft *a = Aircraft::From(v);
|
||||||
AircraftCache cache = a->acache;
|
AircraftCache cache = a->acache;
|
||||||
UpdateAircraftCache(a);
|
UpdateAircraftCache(a);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "settings_type.h"
|
#include "settings_type.h"
|
||||||
#include "core/pool_func.hpp"
|
#include "core/pool_func.hpp"
|
||||||
#include "aircraft.h"
|
#include "aircraft.h"
|
||||||
|
#include "roadveh.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
@ -734,7 +735,7 @@ CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
v->cur_order_index = sel_ord;
|
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();
|
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_TRAIN: return st->train_tile;
|
||||||
case VEH_AIRCRAFT: return st->airport_tile;
|
case VEH_AIRCRAFT: return st->airport_tile;
|
||||||
case VEH_SHIP: return st->dock_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_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
|
||||||
|
|
||||||
if (v->type == VEH_AIRCRAFT) {
|
if (v->type == VEH_AIRCRAFT) {
|
||||||
Aircraft *a = (Aircraft *)v;
|
Aircraft *a = Aircraft::From(v);
|
||||||
if (a->state == FLYING && a->targetairport != destination) {
|
if (a->state == FLYING && a->targetairport != destination) {
|
||||||
/* The aircraft is now heading for a different hangar than the next in the orders */
|
/* The aircraft is now heading for a different hangar than the next in the orders */
|
||||||
extern void AircraftNextAirportPos_and_Order(Aircraft *a);
|
extern void AircraftNextAirportPos_and_Order(Aircraft *a);
|
||||||
|
@ -1734,13 +1735,13 @@ bool ProcessOrders(Vehicle *v)
|
||||||
if (v->type == VEH_AIRCRAFT) {
|
if (v->type == VEH_AIRCRAFT) {
|
||||||
/* Aircraft do something vastly different here, so handle separately */
|
/* Aircraft do something vastly different here, so handle separately */
|
||||||
extern void HandleMissingAircraftOrders(Aircraft *v);
|
extern void HandleMissingAircraftOrders(Aircraft *v);
|
||||||
HandleMissingAircraftOrders((Aircraft *)v);
|
HandleMissingAircraftOrders(Aircraft::From(v));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
v->current_order.Free();
|
v->current_order.Free();
|
||||||
v->dest_tile = 0;
|
v->dest_tile = 0;
|
||||||
if (v->type == VEH_ROAD) ClearSlot((RoadVehicle *)v);
|
if (v->type == VEH_ROAD) ClearSlot(RoadVehicle::From(v));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ static Vehicle *FindTrainOnTrackEnum(Vehicle *v, void *data)
|
||||||
|
|
||||||
if (v->type != VEH_TRAIN || (v->vehstatus & VS_CRASHED)) return NULL;
|
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))) {
|
if (HasBit((TrackBits)t->track, TrackdirToTrack(info->res.trackdir))) {
|
||||||
t = t->First();
|
t = t->First();
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data)
|
||||||
|
|
||||||
if (v->type != VEH_TRAIN) return NULL;
|
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;
|
if ((t->track != rail_bits) && !TracksOverlap(t->track | rail_bits)) return NULL;
|
||||||
|
|
||||||
_error_message = VehicleInTheWayErrMsg(v);
|
_error_message = VehicleInTheWayErrMsg(v);
|
||||||
|
@ -1235,7 +1235,7 @@ Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN && !IsArticulatedPart(v)) {
|
if (v->type == VEH_TRAIN && !IsArticulatedPart(v)) {
|
||||||
const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
|
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;
|
return NULL;
|
||||||
|
@ -2461,7 +2461,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
|
||||||
/* this routine applies only to trains in depot tiles */
|
/* this routine applies only to trains in depot tiles */
|
||||||
if (u->type != VEH_TRAIN || !IsRailDepotTile(tile)) return VETSB_CONTINUE;
|
if (u->type != VEH_TRAIN || !IsRailDepotTile(tile)) return VETSB_CONTINUE;
|
||||||
|
|
||||||
Train *v = (Train *)u;
|
Train *v = Train::From(u);
|
||||||
|
|
||||||
/* depot direction */
|
/* depot direction */
|
||||||
dir = GetRailDepotDirection(tile);
|
dir = GetRailDepotDirection(tile);
|
||||||
|
|
|
@ -1541,7 +1541,7 @@ static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int
|
||||||
case ROAD_TILE_DEPOT: {
|
case ROAD_TILE_DEPOT: {
|
||||||
if (v->type != VEH_ROAD) break;
|
if (v->type != VEH_ROAD) break;
|
||||||
|
|
||||||
RoadVehicle *rv = (RoadVehicle *)v;
|
RoadVehicle *rv = RoadVehicle::From(v);
|
||||||
if (rv->frame == RVC_DEPOT_STOP_FRAME &&
|
if (rv->frame == RVC_DEPOT_STOP_FRAME &&
|
||||||
_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == rv->state) {
|
_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == rv->state) {
|
||||||
rv->state = RVSB_IN_DEPOT;
|
rv->state = RVSB_IN_DEPOT;
|
||||||
|
|
|
@ -762,7 +762,7 @@ static RoadVehicle *RoadVehFindCloseTo(RoadVehicle *v, int x, int y, Direction d
|
||||||
|
|
||||||
if (++front->blocked_ctr > 1480) return NULL;
|
if (++front->blocked_ctr > 1480) return NULL;
|
||||||
|
|
||||||
return (RoadVehicle *)rvf.best;
|
return RoadVehicle::From(rvf.best);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RoadVehArrivesAt(const RoadVehicle *v, Station *st)
|
static void RoadVehArrivesAt(const RoadVehicle *v, Station *st)
|
||||||
|
|
|
@ -130,7 +130,7 @@ void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int c
|
||||||
int highlight_w = 0;
|
int highlight_w = 0;
|
||||||
|
|
||||||
for (int dx = 0; v != NULL && dx < max_length ; v = v->Next()) {
|
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) {
|
if (dx + width > 0 && dx <= max_length) {
|
||||||
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
|
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
|
||||||
|
|
|
@ -912,9 +912,9 @@ bool AfterLoadGame()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (v->type == VEH_TRAIN) {
|
if (v->type == VEH_TRAIN) {
|
||||||
((Train *)v)->track = TRACK_BIT_WORMHOLE;
|
Train::From(v)->track = TRACK_BIT_WORMHOLE;
|
||||||
} else {
|
} else {
|
||||||
((RoadVehicle *)v)->state = RVSB_WORMHOLE;
|
RoadVehicle::From(v)->state = RVSB_WORMHOLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ void FixOldVehicles()
|
||||||
|
|
||||||
/* We haven't used this bit for stations for ages */
|
/* We haven't used this bit for stations for ages */
|
||||||
if (v->type == VEH_ROAD) {
|
if (v->type == VEH_ROAD) {
|
||||||
RoadVehicle *rv = (RoadVehicle *)v;
|
RoadVehicle *rv = RoadVehicle::From(v);
|
||||||
if (rv->state != RVSB_IN_DEPOT && rv->state != RVSB_WORMHOLE) {
|
if (rv->state != RVSB_IN_DEPOT && rv->state != RVSB_WORMHOLE) {
|
||||||
ClrBit(rv->state, RVS_IS_STOPPING);
|
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;
|
if (v->spritenum / 2 >= lengthof(spriteset_rail)) return false;
|
||||||
v->spritenum = spriteset_rail[v->spritenum / 2]; // adjust railway sprite set offset
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -242,8 +242,8 @@ void AfterLoadVehicles(bool part_of_load)
|
||||||
|
|
||||||
if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
|
if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
|
||||||
v->first = NULL;
|
v->first = NULL;
|
||||||
if (v->type == VEH_TRAIN) ((Train *)v)->tcache.first_engine = INVALID_ENGINE;
|
if (v->type == VEH_TRAIN) Train::From(v)->tcache.first_engine = INVALID_ENGINE;
|
||||||
if (v->type == VEH_ROAD) ((RoadVehicle *)v)->rcache.first_engine = INVALID_ENGINE;
|
if (v->type == VEH_ROAD) RoadVehicle::From(v)->rcache.first_engine = INVALID_ENGINE;
|
||||||
|
|
||||||
v->cargo.InvalidateCache();
|
v->cargo.InvalidateCache();
|
||||||
}
|
}
|
||||||
|
@ -308,10 +308,10 @@ void AfterLoadVehicles(bool part_of_load)
|
||||||
assert(v->first != NULL);
|
assert(v->first != NULL);
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) {
|
if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) {
|
||||||
if (IsFrontEngine(v)) ((Train *)v)->tcache.last_speed = v->cur_speed; // update displayed train speed
|
if (IsFrontEngine(v)) Train::From(v)->tcache.last_speed = v->cur_speed; // update displayed train speed
|
||||||
TrainConsistChanged((Train *)v, false);
|
TrainConsistChanged(Train::From(v), false);
|
||||||
} else if (v->type == VEH_ROAD && IsRoadVehFront(v)) {
|
} 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) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_ROAD: {
|
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->roadtype = HasBit(EngInfo(v->First()->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
|
||||||
rv->compatible_roadtypes = RoadTypeToRoadTypes(rv->roadtype);
|
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 */
|
/* In the case of a helicopter we will update the rotor sprites */
|
||||||
if (v->subtype == AIR_HELICOPTER) {
|
if (v->subtype == AIR_HELICOPTER) {
|
||||||
Vehicle *rotor = shadow->Next();
|
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;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
|
|
|
@ -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 */
|
/** Check whether there is a train on rail, not in a depot */
|
||||||
static Vehicle *TrainOnTileEnum(Vehicle *v, void *)
|
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;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1488,7 +1488,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||||
|
|
||||||
static Vehicle *ClearRoadStopStatusEnum(Vehicle *v, void *)
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2617,7 +2617,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
|
||||||
|
|
||||||
int station_ahead;
|
int station_ahead;
|
||||||
int station_length;
|
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
|
/* Stop whenever that amount of station ahead + the distance from the
|
||||||
* begin of the platform to the stop location is longer than the length
|
* 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) {
|
} 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 (rv->state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)rv->state) && rv->frame == 0) {
|
||||||
if (IsRoadStop(tile) && IsRoadVehFront(v)) {
|
if (IsRoadStop(tile) && IsRoadVehFront(v)) {
|
||||||
/* Attempt to allocate a parking bay in a road stop */
|
/* Attempt to allocate a parking bay in a road stop */
|
||||||
|
|
|
@ -1725,7 +1725,7 @@ static Vehicle *TrainApproachingCrossingEnum(Vehicle *v, void *data)
|
||||||
|
|
||||||
TileIndex tile = *(TileIndex*)data;
|
TileIndex tile = *(TileIndex*)data;
|
||||||
|
|
||||||
if (TrainApproachingCrossingTile((Train *)v) != tile) return NULL;
|
if (TrainApproachingCrossingTile(Train::From(v)) != tile) return NULL;
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -1800,7 +1800,7 @@ static void AdvanceWagonsBeforeSwap(Train *v)
|
||||||
{
|
{
|
||||||
Train *base = v;
|
Train *base = v;
|
||||||
Train *first = base; // first vehicle to move
|
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);
|
uint length = CountVehiclesInChain(v);
|
||||||
|
|
||||||
while (length > 2) {
|
while (length > 2) {
|
||||||
|
@ -1849,7 +1849,7 @@ static void AdvanceWagonsAfterSwap(Train *v)
|
||||||
|
|
||||||
Train *base = v;
|
Train *base = v;
|
||||||
Train *first = base; // first vehicle to move
|
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);
|
uint length = CountVehiclesInChain(v);
|
||||||
|
|
||||||
/* we have to make sure all wagons that leave a depot because of train reversing are moved coorectly
|
/* 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();
|
Vehicle *coll = v->First();
|
||||||
|
|
||||||
/* can't collide with own wagons && can't crash in depot && the same height level */
|
/* 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 x_diff = v->x_pos - tcc->v->x_pos;
|
||||||
int y_diff = v->y_pos - tcc->v->y_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;
|
if (x_diff * x_diff + y_diff * y_diff > 25) return NULL;
|
||||||
|
|
||||||
/* crash both trains */
|
/* crash both trains */
|
||||||
tcc->num += TrainCrashed((Train *)tcc->v);
|
tcc->num += TrainCrashed(Train::From(tcc->v));
|
||||||
tcc->num += TrainCrashed((Train *)coll);
|
tcc->num += TrainCrashed(Train::From(coll));
|
||||||
|
|
||||||
/* Try to reserve all tiles directly under the crashed trains.
|
/* 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 */
|
* 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;
|
DiagDirection exitdir = *(DiagDirection *)data;
|
||||||
|
|
||||||
/* front engine of a train, not inside wormhole or depot, not crashed */
|
/* 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->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 *)v)->track) == exitdir) return v;
|
if (v->cur_speed <= 5 && TrainExitDir(v->direction, Train::From(v)->track) == exitdir) return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3942,11 +3942,11 @@ static Vehicle *CollectTrackbitsFromCrashedVehiclesEnum(Vehicle *v, void *data)
|
||||||
TrackBits *trackbits = (TrackBits *)data;
|
TrackBits *trackbits = (TrackBits *)data;
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN && (v->vehstatus & VS_CRASHED) != 0) {
|
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. */
|
/* Vehicle is inside a wormhole, v->track contains no useful value then. */
|
||||||
*trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(v->tile));
|
*trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(v->tile));
|
||||||
} else {
|
} else {
|
||||||
*trackbits |= ((Train *)v)->track;
|
*trackbits |= Train::From(v)->track;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int cou
|
||||||
_cur_dpi = &tmp_dpi;
|
_cur_dpi = &tmp_dpi;
|
||||||
|
|
||||||
do {
|
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 + width > 0) {
|
||||||
if (dx <= count) {
|
if (dx <= count) {
|
||||||
|
@ -236,7 +236,7 @@ void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_
|
||||||
do {
|
do {
|
||||||
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
|
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));
|
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();
|
u = u->Next();
|
||||||
} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
|
} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
|
||||||
|
|
||||||
|
|
|
@ -1385,7 +1385,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
DiagDirection vdir;
|
DiagDirection vdir;
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN) {
|
if (v->type == VEH_TRAIN) {
|
||||||
Train *t = (Train *)v;
|
Train *t = Train::From(v);
|
||||||
fc = (x & 0xF) + (y << 4);
|
fc = (x & 0xF) + (y << 4);
|
||||||
|
|
||||||
vdir = DirToDiagDir(t->direction);
|
vdir = DirToDiagDir(t->direction);
|
||||||
|
@ -1414,7 +1414,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VETSB_ENTERED_WORMHOLE;
|
||||||
}
|
}
|
||||||
} else if (v->type == VEH_ROAD) {
|
} else if (v->type == VEH_ROAD) {
|
||||||
RoadVehicle *rv = (RoadVehicle *)v;
|
RoadVehicle *rv = RoadVehicle::From(v);
|
||||||
fc = (x & 0xF) + (y << 4);
|
fc = (x & 0xF) + (y << 4);
|
||||||
vdir = DirToDiagDir(v->direction);
|
vdir = DirToDiagDir(v->direction);
|
||||||
|
|
||||||
|
@ -1464,18 +1464,18 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
}
|
}
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN: {
|
case VEH_TRAIN: {
|
||||||
Train *t = (Train *)v;
|
Train *t = Train::From(v);
|
||||||
t->track = TRACK_BIT_WORMHOLE;
|
t->track = TRACK_BIT_WORMHOLE;
|
||||||
ClrBit(t->flags, VRF_GOINGUP);
|
ClrBit(t->flags, VRF_GOINGUP);
|
||||||
ClrBit(t->flags, VRF_GOINGDOWN);
|
ClrBit(t->flags, VRF_GOINGDOWN);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
((RoadVehicle *)v)->state = RVSB_WORMHOLE;
|
RoadVehicle::From(v)->state = RVSB_WORMHOLE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
((Ship *)v)->state = TRACK_BIT_WORMHOLE;
|
Ship::From(v)->state = TRACK_BIT_WORMHOLE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
@ -1485,7 +1485,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
v->tile = tile;
|
v->tile = tile;
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN: {
|
case VEH_TRAIN: {
|
||||||
Train *t = (Train *)v;
|
Train *t = Train::From(v);
|
||||||
if (t->track == TRACK_BIT_WORMHOLE) {
|
if (t->track == TRACK_BIT_WORMHOLE) {
|
||||||
t->track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
|
t->track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VETSB_ENTERED_WORMHOLE;
|
||||||
|
@ -1493,7 +1493,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VEH_ROAD: {
|
case VEH_ROAD: {
|
||||||
RoadVehicle *rv = (RoadVehicle *)v;
|
RoadVehicle *rv = RoadVehicle::From(v);
|
||||||
if (rv->state == RVSB_WORMHOLE) {
|
if (rv->state == RVSB_WORMHOLE) {
|
||||||
rv->state = _road_exit_tunnel_state[dir];
|
rv->state = _road_exit_tunnel_state[dir];
|
||||||
rv->frame = 0;
|
rv->frame = 0;
|
||||||
|
@ -1502,7 +1502,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VEH_SHIP: {
|
case VEH_SHIP: {
|
||||||
Ship *ship = (Ship *)v;
|
Ship *ship = Ship::From(v);
|
||||||
if (ship->state == TRACK_BIT_WORMHOLE) {
|
if (ship->state == TRACK_BIT_WORMHOLE) {
|
||||||
ship->state = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
|
ship->state = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VETSB_ENTERED_WORMHOLE;
|
||||||
|
|
|
@ -524,9 +524,9 @@ void Vehicle::PreDestructor()
|
||||||
if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id);
|
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()) {
|
if (this->type == VEH_AIRCRAFT && this->IsPrimaryVehicle()) {
|
||||||
Aircraft *a = (Aircraft *)this;
|
Aircraft *a = Aircraft::From(this);
|
||||||
Station *st = GetTargetAirportIfValid(a);
|
Station *st = GetTargetAirportIfValid(a);
|
||||||
if (st != NULL) {
|
if (st != NULL) {
|
||||||
const AirportFTA *layout = st->Airport()->layout;
|
const AirportFTA *layout = st->Airport()->layout;
|
||||||
|
@ -984,8 +984,8 @@ void VehicleEnterDepot(Vehicle *v)
|
||||||
if (!IsFrontEngine(v)) v = v->First();
|
if (!IsFrontEngine(v)) v = v->First();
|
||||||
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
|
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
|
||||||
v->load_unload_time_rem = 0;
|
v->load_unload_time_rem = 0;
|
||||||
ClrBit(((Train *)v)->flags, VRF_TOGGLE_REVERSE);
|
ClrBit(Train::From(v)->flags, VRF_TOGGLE_REVERSE);
|
||||||
TrainConsistChanged((Train *)v, true);
|
TrainConsistChanged(Train::From(v), true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
|
@ -995,13 +995,13 @@ void VehicleEnterDepot(Vehicle *v)
|
||||||
|
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
InvalidateWindowClasses(WC_SHIPS_LIST);
|
InvalidateWindowClasses(WC_SHIPS_LIST);
|
||||||
static_cast<Ship*>(v)->state = TRACK_BIT_DEPOT;
|
Ship::From(v)->state = TRACK_BIT_DEPOT;
|
||||||
RecalcShipStuff(v);
|
RecalcShipStuff(v);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_AIRCRAFT:
|
case VEH_AIRCRAFT:
|
||||||
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
|
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
|
||||||
HandleAircraftEnterHangar((Aircraft *)v);
|
HandleAircraftEnterHangar(Aircraft::From(v));
|
||||||
break;
|
break;
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -1429,9 +1429,9 @@ SpriteID GetEnginePalette(EngineID engine_type, CompanyID company)
|
||||||
SpriteID GetVehiclePalette(const Vehicle *v)
|
SpriteID GetVehiclePalette(const Vehicle *v)
|
||||||
{
|
{
|
||||||
if (v->type == VEH_TRAIN) {
|
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) {
|
} 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);
|
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.
|
* might not be marked as wanting a reservation, e.g.
|
||||||
* when an overlength train gets turned around in a station. */
|
* 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) {
|
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_TRAIN && reverse) DoCommand(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
|
||||||
|
|
||||||
if (this->type == VEH_AIRCRAFT) {
|
if (this->type == VEH_AIRCRAFT) {
|
||||||
Aircraft *a = (Aircraft *)this;
|
Aircraft *a = Aircraft::From(this);
|
||||||
if (a->state == FLYING && a->targetairport != destination) {
|
if (a->state == FLYING && a->targetairport != destination) {
|
||||||
/* The aircraft is now heading for a different hangar than the next in the orders */
|
/* The aircraft is now heading for a different hangar than the next in the orders */
|
||||||
extern void AircraftNextAirportPos_and_Order(Aircraft *a);
|
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)
|
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);
|
return CanVehicleUseStation(v->engine_type, st);
|
||||||
}
|
}
|
||||||
|
|
|
@ -573,6 +573,28 @@ struct SpecializedVehicle : public Vehicle {
|
||||||
{
|
{
|
||||||
return IsValidID(index) ? Get(index) : NULL ;
|
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)
|
#define FOR_ALL_VEHICLES_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, vehicle_index, var, 0) if (var->type == name::EXPECTED_TYPE)
|
||||||
|
|
|
@ -67,7 +67,7 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||||
|
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN:
|
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;
|
break;
|
||||||
|
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
|
@ -75,7 +75,7 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_AIRCRAFT: {
|
case VEH_AIRCRAFT: {
|
||||||
Aircraft *a = (Aircraft *)v;
|
Aircraft *a = Aircraft::From(v);
|
||||||
/* cannot stop airplane when in flight, or when taking off / landing */
|
/* 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);
|
if (a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
|
||||||
} break;
|
} break;
|
||||||
|
@ -152,7 +152,7 @@ CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32
|
||||||
|
|
||||||
if (!vehicle_list_window) {
|
if (!vehicle_list_window) {
|
||||||
if (vehicle_type == VEH_TRAIN) {
|
if (vehicle_type == VEH_TRAIN) {
|
||||||
if (CheckTrainInDepot((const Train *)v, false) == -1) continue;
|
if (CheckTrainInDepot(Train::From(v), false) == -1) continue;
|
||||||
} else {
|
} else {
|
||||||
if (!(v->vehstatus & VS_HIDDEN)) continue;
|
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 (!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 */
|
/* check that we can allocate enough vehicles */
|
||||||
if (!(flags & DC_EXEC)) {
|
if (!(flags & DC_EXEC)) {
|
||||||
|
@ -381,8 +381,8 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
w = Vehicle::Get(_new_vehicle_id);
|
w = Vehicle::Get(_new_vehicle_id);
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN && HasBit(((Train *)v)->flags, VRF_REVERSE_DIRECTION)) {
|
if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) {
|
||||||
SetBit(((Train *)w)->flags, VRF_REVERSE_DIRECTION);
|
SetBit(Train::From(w)->flags, VRF_REVERSE_DIRECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN && !IsFrontEngine(v)) {
|
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
|
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) {
|
if ((flags & DC_EXEC) && v_front->type == VEH_TRAIN) {
|
||||||
/* for trains this needs to be the front engine due to the callback function */
|
/* 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)) {
|
if (w->type == VEH_TRAIN && EngineHasArticPart(w)) {
|
||||||
w = GetNextArticPart((Train *)w);
|
w = GetNextArticPart(Train::From(w));
|
||||||
} else if (w->type == VEH_ROAD && RoadVehHasArticPart(w)) {
|
} else if (w->type == VEH_ROAD && RoadVehHasArticPart(w)) {
|
||||||
w = w->Next();
|
w = w->Next();
|
||||||
} else {
|
} else {
|
||||||
|
@ -453,7 +453,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN && EngineHasArticPart(v)) {
|
if (v->type == VEH_TRAIN && EngineHasArticPart(v)) {
|
||||||
v = GetNextArticPart((Train *)v);
|
v = GetNextArticPart(Train::From(v));
|
||||||
} else if (v->type == VEH_ROAD && RoadVehHasArticPart(v)) {
|
} else if (v->type == VEH_ROAD && RoadVehHasArticPart(v)) {
|
||||||
v = v->Next();
|
v = v->Next();
|
||||||
} else {
|
} else {
|
||||||
|
@ -461,8 +461,8 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||||
}
|
}
|
||||||
} while (v != NULL);
|
} while (v != NULL);
|
||||||
|
|
||||||
if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = GetNextVehicle((Train *)w);
|
if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = GetNextVehicle(Train::From(w));
|
||||||
} 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) {
|
if (flags & DC_EXEC) {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -603,7 +603,7 @@ static int CDECL VehicleMaxSpeedSorter(const Vehicle * const *a, const Vehicle *
|
||||||
{
|
{
|
||||||
int r = 0;
|
int r = 0;
|
||||||
if ((*a)->type == VEH_TRAIN && (*b)->type == VEH_TRAIN) {
|
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 {
|
} else {
|
||||||
r = (*a)->max_speed - (*b)->max_speed;
|
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;
|
int r = 0;
|
||||||
switch ((*a)->type) {
|
switch ((*a)->type) {
|
||||||
case VEH_TRAIN:
|
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;
|
break;
|
||||||
|
|
||||||
case VEH_ROAD: {
|
case VEH_ROAD: {
|
||||||
const RoadVehicle *u;
|
const RoadVehicle *u;
|
||||||
for (u = (const RoadVehicle *)*a; 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 = (const RoadVehicle *)*b; 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;
|
} break;
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
@ -1471,10 +1471,10 @@ struct VehicleDetailsWindow : Window {
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
SetDParam(2, v->GetDisplayMaxSpeed());
|
SetDParam(2, v->GetDisplayMaxSpeed());
|
||||||
SetDParam(1, ((const Train *)v)->tcache.cached_power);
|
SetDParam(1, Train::From(v)->tcache.cached_power);
|
||||||
SetDParam(0, ((const Train *)v)->tcache.cached_weight);
|
SetDParam(0, Train::From(v)->tcache.cached_weight);
|
||||||
SetDParam(3, ((const Train *)v)->tcache.cached_max_te / 1000);
|
SetDParam(3, Train::From(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) ?
|
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_MAX_TE :
|
||||||
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED);
|
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED);
|
||||||
break;
|
break;
|
||||||
|
@ -1943,7 +1943,7 @@ struct VehicleViewWindow : Window {
|
||||||
} else if (v->vehstatus & VS_STOPPED) {
|
} else if (v->vehstatus & VS_STOPPED) {
|
||||||
if (v->type == VEH_TRAIN) {
|
if (v->type == VEH_TRAIN) {
|
||||||
if (v->cur_speed == 0) {
|
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;
|
str = STR_TRAIN_NO_POWER;
|
||||||
} else {
|
} else {
|
||||||
str = STR_VEHICLE_STATUS_STOPPED;
|
str = STR_VEHICLE_STATUS_STOPPED;
|
||||||
|
@ -1955,7 +1955,7 @@ struct VehicleViewWindow : Window {
|
||||||
} else { // no train
|
} else { // no train
|
||||||
str = STR_VEHICLE_STATUS_STOPPED;
|
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;
|
str = STR_TRAIN_STUCK;
|
||||||
} else { // vehicle is in a "normal" state, show current order
|
} else { // vehicle is in a "normal" state, show current order
|
||||||
switch (v->current_order.GetType()) {
|
switch (v->current_order.GetType()) {
|
||||||
|
|
|
@ -28,6 +28,8 @@ struct Train;
|
||||||
struct RoadVehicle;
|
struct RoadVehicle;
|
||||||
struct Ship;
|
struct Ship;
|
||||||
struct Aircraft;
|
struct Aircraft;
|
||||||
|
struct EffectVehicle;
|
||||||
|
struct DisasterVehicle;
|
||||||
|
|
||||||
struct BaseVehicle
|
struct BaseVehicle
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,7 +29,7 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
if (IsArticulatedPart(v) || IsRearDualheaded(v)) continue;
|
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 (wagons != NULL && IsFreeWagon(v->First())) {
|
||||||
if (individual_wagons || IsFreeWagon(v)) *wagons->Append() = v;
|
if (individual_wagons || IsFreeWagon(v)) *wagons->Append() = v;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -813,22 +813,22 @@ static void FloodVehicle(Vehicle *v)
|
||||||
/* FreeTrainTrackReservation() calls GetVehicleTrackdir() that doesn't like crashed vehicles.
|
/* 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) */
|
* In this case, v->direction matches v->u.rail.track, so we can do this (it wasn't crashed before) */
|
||||||
v->vehstatus &= ~VS_CRASHED;
|
v->vehstatus &= ~VS_CRASHED;
|
||||||
FreeTrainTrackReservation((Train *)v);
|
FreeTrainTrackReservation(Train::From(v));
|
||||||
v->vehstatus |= VS_CRASHED;
|
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);
|
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
if (IsRoadVehFront(v)) pass += 1; // driver
|
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);
|
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_AIRCRAFT:
|
case VEH_AIRCRAFT:
|
||||||
pass += 2; // driver
|
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);
|
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct CFollowTrackT
|
||||||
{
|
{
|
||||||
assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
|
assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
|
||||||
m_veh = v;
|
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)
|
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 TransportType TT() {return Ttr_type_;}
|
||||||
FORCEINLINE static bool IsWaterTT() {return TT() == TRANSPORT_WATER;}
|
FORCEINLINE static bool IsWaterTT() {return TT() == TRANSPORT_WATER;}
|
||||||
FORCEINLINE static bool IsRailTT() {return TT() == TRANSPORT_RAIL;}
|
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 IsRoadTT() {return TT() == TRANSPORT_ROAD;}
|
||||||
FORCEINLINE static bool Allow90degTurns() {return T90deg_turns_allowed_;}
|
FORCEINLINE static bool Allow90degTurns() {return T90deg_turns_allowed_;}
|
||||||
FORCEINLINE static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;}
|
FORCEINLINE static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;}
|
||||||
|
@ -106,7 +106,7 @@ struct CFollowTrackT
|
||||||
m_old_tile = old_tile;
|
m_old_tile = old_tile;
|
||||||
m_old_td = old_td;
|
m_old_td = old_td;
|
||||||
m_err = EC_NONE;
|
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
|
(IsTram() && GetSingleTramBit(m_old_tile) != INVALID_DIAGDIR)); // Disable the assertion for single tram bits
|
||||||
m_exitdir = TrackdirToExitdir(m_old_td);
|
m_exitdir = TrackdirToExitdir(m_old_td);
|
||||||
if (ForcedReverse()) return true;
|
if (ForcedReverse()) return true;
|
||||||
|
@ -207,7 +207,7 @@ protected:
|
||||||
if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
|
if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
|
||||||
m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
|
m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
|
||||||
} else {
|
} 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) {
|
if (IsTram() && m_new_td_bits == 0) {
|
||||||
/* GetTileTrackStatus() returns 0 for single tram bits.
|
/* GetTileTrackStatus() returns 0 for single tram bits.
|
||||||
|
|
|
@ -247,8 +247,8 @@ public:
|
||||||
const Vehicle *v = Yapf().GetVehicle();
|
const Vehicle *v = Yapf().GetVehicle();
|
||||||
assert(v != NULL);
|
assert(v != NULL);
|
||||||
assert(v->type == VEH_TRAIN);
|
assert(v->type == VEH_TRAIN);
|
||||||
assert(((const Train *)v)->tcache.cached_total_length != 0);
|
assert(Train::From(v)->tcache.cached_total_length != 0);
|
||||||
int missing_platform_length = (((const Train *)v)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length;
|
int missing_platform_length = (Train::From(v)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length;
|
||||||
if (missing_platform_length < 0) {
|
if (missing_platform_length < 0) {
|
||||||
/* apply penalty for longer platform than needed */
|
/* 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;
|
cost += Yapf().PfGetSettings().rail_longer_platform_penalty + Yapf().PfGetSettings().rail_longer_platform_per_tile_penalty * -missing_platform_length;
|
||||||
|
|
|
@ -13,8 +13,8 @@ protected:
|
||||||
public:
|
public:
|
||||||
void SetDestination(const Vehicle *v, bool override_rail_type = false)
|
void SetDestination(const Vehicle *v, bool override_rail_type = false)
|
||||||
{
|
{
|
||||||
m_compatible_railtypes = ((const Train *)v)->compatible_railtypes;
|
m_compatible_railtypes = Train::From(v)->compatible_railtypes;
|
||||||
if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(((const Train *)v)->railtype)->compatible_railtypes;
|
if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(Train::From(v)->railtype)->compatible_railtypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCompatibleRailType(RailType rt)
|
bool IsCompatibleRailType(RailType rt)
|
||||||
|
@ -91,8 +91,8 @@ public:
|
||||||
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
|
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
IsSafeWaitingPosition((const Train *)Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns()) &&
|
IsSafeWaitingPosition(Train::From(Yapf().GetVehicle()), tile, td, true, !TrackFollower::Allow90degTurns()) &&
|
||||||
IsWaitingPositionFree((const Train *)Yapf().GetVehicle(), tile, td, !TrackFollower::Allow90degTurns());
|
IsWaitingPositionFree(Train::From(Yapf().GetVehicle()), tile, td, !TrackFollower::Allow90degTurns());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
|
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
|
||||||
|
|
|
@ -54,7 +54,7 @@ private:
|
||||||
|
|
||||||
bool FindSafePositionProc(TileIndex tile, Trackdir td)
|
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 = tile;
|
||||||
m_res_dest_td = td;
|
m_res_dest_td = td;
|
||||||
return false; // Stop iterating segment
|
return false; // Stop iterating segment
|
||||||
|
@ -149,7 +149,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't bother if the target is reserved. */
|
/* 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) {
|
for (Node *node = m_res_node; node->m_parent != NULL; node = node->m_parent) {
|
||||||
node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack);
|
node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack);
|
||||||
|
@ -411,7 +411,7 @@ public:
|
||||||
if (target != NULL) target->tile = INVALID_TILE;
|
if (target != NULL) target->tile = INVALID_TILE;
|
||||||
|
|
||||||
/* set origin and destination nodes */
|
/* 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().SetOrigin(origin.tile, origin.trackdir, INVALID_TILE, INVALID_TRACKDIR, 1, true);
|
||||||
Yapf().SetDestination(v);
|
Yapf().SetDestination(v);
|
||||||
|
|
||||||
|
@ -536,9 +536,9 @@ Trackdir YapfChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection ent
|
||||||
|
|
||||||
bool YapfCheckReverseTrain(const Vehicle *vt)
|
bool YapfCheckReverseTrain(const Vehicle *vt)
|
||||||
{
|
{
|
||||||
const Train *v = (const Train *)vt;
|
const Train *v = Train::From(vt);
|
||||||
/* last wagon */
|
/* last wagon */
|
||||||
const Train *last_veh = (const Train *)GetLastVehicleInChain(v);
|
const Train *last_veh = Train::From(GetLastVehicleInChain(v));
|
||||||
|
|
||||||
/* get trackdirs of both ends */
|
/* get trackdirs of both ends */
|
||||||
Trackdir td = v->GetVehicleTrackdir();
|
Trackdir td = v->GetVehicleTrackdir();
|
||||||
|
@ -602,7 +602,7 @@ bool YapfFindNearestRailDepotTwoWay(const Vehicle *v, int max_distance, int reve
|
||||||
|
|
||||||
const Vehicle *last_veh = GetLastVehicleInChain(v);
|
const Vehicle *last_veh = GetLastVehicleInChain(v);
|
||||||
|
|
||||||
PBSTileInfo origin = FollowTrainReservation((const Train *)v);
|
PBSTileInfo origin = FollowTrainReservation(Train::From(v));
|
||||||
TileIndex last_tile = last_veh->tile;
|
TileIndex last_tile = last_veh->tile;
|
||||||
Trackdir td_rev = ReverseTrackdir(last_veh->GetVehicleTrackdir());
|
Trackdir td_rev = ReverseTrackdir(last_veh->GetVehicleTrackdir());
|
||||||
|
|
||||||
|
|
|
@ -299,13 +299,13 @@ public:
|
||||||
/* our source tile will be the next vehicle tile (should be the given one) */
|
/* our source tile will be the next vehicle tile (should be the given one) */
|
||||||
TileIndex src_tile = tile;
|
TileIndex src_tile = tile;
|
||||||
/* get available trackdirs on the start 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 */
|
/* select reachable trackdirs only */
|
||||||
src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
|
src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
|
||||||
|
|
||||||
/* get available trackdirs on the destination tile */
|
/* get available trackdirs on the destination tile */
|
||||||
TileIndex dest_tile = v->dest_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 */
|
/* set origin and destination nodes */
|
||||||
Yapf().SetOrigin(src_tile, src_trackdirs);
|
Yapf().SetOrigin(src_tile, src_trackdirs);
|
||||||
|
@ -349,7 +349,7 @@ public:
|
||||||
|
|
||||||
/* set destination tile, trackdir
|
/* set destination tile, trackdir
|
||||||
* get available trackdirs on the destination tile */
|
* 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);
|
Yapf().SetDestination(dst_tile, dst_td_bits);
|
||||||
|
|
||||||
/* if path not found - return distance = UINT_MAX */
|
/* if path not found - return distance = UINT_MAX */
|
||||||
|
@ -374,7 +374,7 @@ public:
|
||||||
/* set origin (tile, trackdir) */
|
/* set origin (tile, trackdir) */
|
||||||
TileIndex src_tile = v->tile;
|
TileIndex src_tile = v->tile;
|
||||||
Trackdir src_td = v->GetVehicleTrackdir();
|
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)
|
/* sometimes the roadveh is not on the road (it resides on non-existing track)
|
||||||
* how should we handle that situation? */
|
* how should we handle that situation? */
|
||||||
return false;
|
return false;
|
||||||
|
@ -471,7 +471,7 @@ Depot *YapfFindNearestRoadDepot(const Vehicle *v)
|
||||||
{
|
{
|
||||||
TileIndex tile = v->tile;
|
TileIndex tile = v->tile;
|
||||||
Trackdir trackdir = v->GetVehicleTrackdir();
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue