summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-05-26 22:45:48 +0000
committersmatz <smatz@openttd.org>2009-05-26 22:45:48 +0000
commit5a463c8347fe1e68ab31dda1425e9060d52bfbd6 (patch)
tree55f5c9de8dcbda6268d003b29af59650594ce27a
parent7ee882d03f4c41d8659ed82fd5be0d0efbae0a0c (diff)
downloadopenttd-5a463c8347fe1e68ab31dda1425e9060d52bfbd6.tar.xz
(svn r16442) -Codechange: use new Vehicle accessors at more places
-rw-r--r--src/aircraft_cmd.cpp15
-rw-r--r--src/disaster_cmd.cpp12
-rw-r--r--src/effectvehicle_base.h2
-rw-r--r--src/road_cmd.cpp19
-rw-r--r--src/roadveh_cmd.cpp12
-rw-r--r--src/saveload/afterload.cpp27
-rw-r--r--src/saveload/vehicle_sl.cpp84
-rw-r--r--src/settings.cpp7
-rw-r--r--src/ship.h2
-rw-r--r--src/ship_cmd.cpp12
-rw-r--r--src/smallmap_gui.cpp15
-rw-r--r--src/station_cmd.cpp16
-rw-r--r--src/train_cmd.cpp38
-rw-r--r--src/train_gui.cpp11
-rw-r--r--src/vehicle_base.h6
-rw-r--r--src/waypoint_cmd.cpp6
16 files changed, 129 insertions, 155 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 7bf6a79e0..025d6f777 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -440,10 +440,9 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
*/
CommandCost CmdSellAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL) return CMD_ERROR;
+ Aircraft *v = Aircraft::GetIfValid(p1);
- if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
+ if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_AIRCRAFT_MUST_BE_STOPPED);
if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
@@ -493,11 +492,9 @@ CommandCost CmdSendAircraftToHangar(TileIndex tile, DoCommandFlag flags, uint32
return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
}
- Vehicle *v = Vehicle::GetIfValid(p1);
+ Aircraft *v = Aircraft::GetIfValid(p1);
if (v == NULL) return CMD_ERROR;
- if (v->type != VEH_AIRCRAFT) return CMD_ERROR;
-
return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK));
}
@@ -516,10 +513,8 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
{
byte new_subtype = GB(p2, 8, 8);
- Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL) return CMD_ERROR;
-
- if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
+ Aircraft *v = Aircraft::GetIfValid(p1);
+ if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_AIRCRAFT_MUST_BE_STOPPED);
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE);
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 96735f199..3cc62d057 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -300,9 +300,9 @@ static bool DisasterTick_Ufo(DisasterVehicle *v)
}
v->current_order.SetDestination(1);
- Vehicle *u;
- FOR_ALL_VEHICLES(u) {
- if (u->type == VEH_ROAD && IsRoadVehFront(u)) {
+ RoadVehicle *u;
+ FOR_ALL_ROADVEHICLES(u) {
+ if (IsRoadVehFront(u)) {
v->dest_tile = u->index;
v->age = 0;
return true;
@@ -938,10 +938,10 @@ void StartupDisasters()
*/
void ReleaseDisastersTargetingIndustry(IndustryID i)
{
- Vehicle *v;
- FOR_ALL_VEHICLES(v) {
+ DisasterVehicle *v;
+ FOR_ALL_DISASTERVEHICLES(v) {
/* primary disaster vehicles that have chosen target */
- if (v->type == VEH_DISASTER && (v->subtype == ST_AIRPLANE || v->subtype == ST_HELICOPTER)) {
+ if (v->subtype == ST_AIRPLANE || v->subtype == ST_HELICOPTER) {
/* if it has chosen target, and it is this industry (yes, dest_tile is IndustryID here), set order to "leaving map peacefully" */
if (v->current_order.GetDestination() > 0 && v->dest_tile == i) v->current_order.SetDestination(3);
}
diff --git a/src/effectvehicle_base.h b/src/effectvehicle_base.h
index 2f2926a86..dd79370af 100644
--- a/src/effectvehicle_base.h
+++ b/src/effectvehicle_base.h
@@ -37,4 +37,6 @@ struct EffectVehicle : public SpecializedVehicle<EffectVehicle, VEH_EFFECT> {
bool Tick();
};
+#define FOR_ALL_EFFECTVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(EffectVehicle, var)
+
#endif /* EFFECTVEHICLE_BASE_H */
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 231abebe8..680b8d000 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -37,11 +37,9 @@
*/
bool RoadVehiclesAreBuilt()
{
- const Vehicle *v;
+ const RoadVehicle *rv;
+ FOR_ALL_ROADVEHICLES(rv) return true;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_ROAD) return true;
- }
return false;
}
@@ -274,9 +272,9 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
if (HasRoadWorks(tile)) {
/* flooding tile with road works, don't forget to remove the effect vehicle too */
assert(_current_company == OWNER_WATER);
- Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_EFFECT && TileVirtXY(v->x_pos, v->y_pos) == tile) {
+ EffectVehicle *v;
+ FOR_ALL_EFFECTVEHICLES(v) {
+ if (TileVirtXY(v->x_pos, v->y_pos) == tile) {
delete v;
}
}
@@ -1540,13 +1538,6 @@ static const byte _roadveh_enter_depot_dir[4] = {
static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
{
switch (GetRoadTileType(tile)) {
- case ROAD_TILE_CROSSING:
- if (v->type == VEH_TRAIN) {
- /* it should be barred */
- assert(IsCrossingBarred(tile));
- }
- break;
-
case ROAD_TILE_DEPOT: {
if (v->type != VEH_ROAD) break;
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index e78b69275..959fdfffb 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -312,8 +312,8 @@ bool RoadVehicle::IsStoppedInDepot() const
*/
CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL || v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR;
+ RoadVehicle *v = RoadVehicle::GetIfValid(p1);
+ if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
@@ -418,8 +418,8 @@ CommandCost CmdSendRoadVehToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1
return SendAllVehiclesToDepot(VEH_ROAD, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
}
- Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL || v->type != VEH_ROAD) return CMD_ERROR;
+ RoadVehicle *v = RoadVehicle::GetIfValid(p1);
+ if (v == NULL) return CMD_ERROR;
return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK));
}
@@ -1991,9 +1991,9 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
uint16 capacity = CALLBACK_FAILED;
uint total_capacity = 0;
- Vehicle *v = Vehicle::GetIfValid(p1);
+ RoadVehicle *v = RoadVehicle::GetIfValid(p1);
- if (v == NULL || v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR;
+ if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_ROAD_MUST_BE_STOPPED_INSIDE_DEPOT);
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE);
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index c4f9b9c81..36dca96bc 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -314,9 +314,9 @@ static void FixOwnerOfRailTrack(TileIndex t)
assert(!Company::IsValidID(GetTileOwner(t)) && (IsLevelCrossingTile(t) || IsPlainRailTile(t)));
/* remove leftover rail piece from crossing (from very old savegames) */
- Vehicle *v = NULL, *w;
- FOR_ALL_VEHICLES(w) {
- if (w->type == VEH_TRAIN && w->tile == t) {
+ Train *v = NULL, *w;
+ FOR_ALL_TRAINS(w) {
+ if (w->tile == t) {
v = w;
break;
}
@@ -1286,10 +1286,10 @@ bool AfterLoadGame()
}
if (CheckSavegameVersion(50)) {
- Vehicle *v;
+ Aircraft *v;
/* Aircraft units changed from 8 mph to 1 km/h */
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_AIRCRAFT && v->subtype <= AIR_AIRCRAFT) {
+ FOR_ALL_AIRCRAFT(v) {
+ if (v->subtype <= AIR_AIRCRAFT) {
const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
v->cur_speed *= 129;
v->cur_speed /= 10;
@@ -1624,10 +1624,9 @@ bool AfterLoadGame()
if (CheckSavegameVersion(62)) {
/* Remove all trams from savegames without tram support.
* There would be trams without tram track under causing crashes sooner or later. */
- Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_ROAD && v->First() == v &&
- HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) {
+ RoadVehicle *v;
+ FOR_ALL_ROADVEHICLES(v) {
+ if (v->First() == v && HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) {
if (_switch_mode_errorstr == INVALID_STRING_ID || _switch_mode_errorstr == STR_NEWGRF_COMPATIBLE_LOAD_WARNING) {
_switch_mode_errorstr = STR_LOADGAME_REMOVED_TRAMS;
}
@@ -1735,11 +1734,11 @@ bool AfterLoadGame()
}
if (CheckSavegameVersion(104)) {
- Vehicle *v;
- FOR_ALL_VEHICLES(v) {
+ Aircraft *a;
+ FOR_ALL_AIRCRAFT(a) {
/* Set engine_type of shadow and rotor */
- if (v->type == VEH_AIRCRAFT && !IsNormalAircraft(v)) {
- v->engine_type = v->First()->engine_type;
+ if (!IsNormalAircraft(a)) {
+ a->engine_type = a->First()->engine_type;
}
}
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index 65c1347d0..ae3b539e9 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -100,55 +100,49 @@ void ConnectMultiheadedTrains()
*/
void ConvertOldMultiheadToNew()
{
- Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_TRAIN) {
- SetBit(v->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop
- }
- }
-
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_TRAIN) {
- if (HasBit(v->subtype, 7) && ((v->subtype & ~0x80) == 0 || (v->subtype & ~0x80) == 4)) {
- for (Vehicle *u = v; u != NULL; u = u->Next()) {
- const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
-
- ClrBit(u->subtype, 7);
- switch (u->subtype) {
- case 0: // TS_Front_Engine
- if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u);
- SetFrontEngine(u);
- SetTrainEngine(u);
- break;
-
- case 1: // TS_Artic_Part
- u->subtype = 0;
- SetArticulatedPart(u);
- break;
+ Train *t;
+ FOR_ALL_TRAINS(t) SetBit(t->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop
+
+ FOR_ALL_TRAINS(t) {
+ if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
+ for (Vehicle *u = t; u != NULL; u = u->Next()) {
+ const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
+
+ ClrBit(u->subtype, 7);
+ switch (u->subtype) {
+ case 0: // TS_Front_Engine
+ if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u);
+ SetFrontEngine(u);
+ SetTrainEngine(u);
+ break;
- case 2: // TS_Not_First
- u->subtype = 0;
- if (rvi->railveh_type == RAILVEH_WAGON) {
- /* normal wagon */
- SetTrainWagon(u);
- break;
- }
- if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
- /* rear end of a multiheaded engine */
- SetMultiheaded(u);
- break;
- }
- if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u);
- SetTrainEngine(u);
- break;
+ case 1: // TS_Artic_Part
+ u->subtype = 0;
+ SetArticulatedPart(u);
+ break;
- case 4: // TS_Free_Car
- u->subtype = 0;
+ case 2: // TS_Not_First
+ u->subtype = 0;
+ if (rvi->railveh_type == RAILVEH_WAGON) {
+ /* normal wagon */
SetTrainWagon(u);
- SetFreeWagon(u);
break;
- default: NOT_REACHED();
- }
+ }
+ if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
+ /* rear end of a multiheaded engine */
+ SetMultiheaded(u);
+ break;
+ }
+ if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u);
+ SetTrainEngine(u);
+ break;
+
+ case 4: // TS_Free_Car
+ u->subtype = 0;
+ SetTrainWagon(u);
+ SetFreeWagon(u);
+ break;
+ default: NOT_REACHED();
}
}
}
diff --git a/src/settings.cpp b/src/settings.cpp
index fac9a0dfb..ad0ac1de3 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -57,6 +57,7 @@
#include "ai/ai_config.hpp"
#include "newgrf.h"
#include "engine_base.h"
+#include "ship.h"
#include "void_map.h"
#include "station_base.h"
@@ -878,9 +879,9 @@ static bool CheckFreeformEdges(int32 p1)
{
if (_game_mode == GM_MENU) return true;
if (p1 != 0) {
- Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_SHIP && (TileX(v->tile) == 0 || TileY(v->tile) == 0)) {
+ Ship *s;
+ FOR_ALL_SHIPS(s) {
+ if (TileX(s->tile) == 0 || TileY(s->tile) == 0) {
ShowErrorMessage(INVALID_STRING_ID, STR_CONFIG_SETTING_EDGES_NOT_EMPTY, 0, 0);
return false;
}
diff --git a/src/ship.h b/src/ship.h
index 67f1a8748..99a4f94aa 100644
--- a/src/ship.h
+++ b/src/ship.h
@@ -49,4 +49,6 @@ struct Ship: public SpecializedVehicle<Ship, VEH_SHIP> {
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
};
+#define FOR_ALL_SHIPS(var) FOR_ALL_VEHICLES_OF_TYPE(Ship, var)
+
#endif /* SHIP_H */
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index c2c5a72cd..1ed7a0480 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -838,8 +838,8 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
*/
CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL || v->type != VEH_SHIP || !CheckOwnership(v->owner)) return CMD_ERROR;
+ Ship *v = Ship::GetIfValid(p1);
+ if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
@@ -884,8 +884,8 @@ CommandCost CmdSendShipToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
return SendAllVehiclesToDepot(VEH_SHIP, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
}
- Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL || v->type != VEH_SHIP) return CMD_ERROR;
+ Ship *v = Ship::GetIfValid(p1);
+ if (v == NULL) return CMD_ERROR;
return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK));
}
@@ -908,9 +908,9 @@ CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
byte new_subtype = GB(p2, 8, 8);
uint16 capacity = CALLBACK_FAILED;
- Vehicle *v = Vehicle::GetIfValid(p1);
+ Ship *v = Ship::GetIfValid(p1);
- if (v == NULL || v->type != VEH_SHIP || !CheckOwnership(v->owner)) return CMD_ERROR;
+ if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT);
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE);
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 1e397eb31..1692ee467 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -20,6 +20,7 @@
#include "vehicle_base.h"
#include "sound_func.h"
#include "window_func.h"
+#include "effectvehicle_base.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -739,13 +740,9 @@ public:
/* draw vehicles? */
if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) {
- Vehicle *v;
- bool skip;
- byte colour;
-
- FOR_ALL_VEHICLES(v) {
- if (v->type != VEH_EFFECT &&
- (v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0) {
+ EffectVehicle *v;
+ FOR_ALL_EFFECTVEHICLES(v) {
+ if ((v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0) {
/* Remap into flat coordinates. */
Point pt = RemapCoords(
v->x_pos / TILE_SIZE - this->scroll_x / TILE_SIZE, // divide each one separately because (a-b)/c != a/c-b/c in integer world
@@ -759,7 +756,7 @@ public:
if (!IsInsideMM(y, 0, dpi->height)) continue;
/* Default is to draw both pixels. */
- skip = false;
+ bool skip = false;
/* Offset X coordinate */
x -= this->subscroll + 3 + dpi->left;
@@ -776,7 +773,7 @@ public:
}
/* Calculate pointer to pixel and the colour */
- colour = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colours[v->type] : 0xF;
+ byte colour = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colours[v->type] : 0xF;
/* And draw either one or two pixels depending on clipping */
blitter->SetPixel(dpi->dst_ptr, x, y, colour);
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 85fdde83f..296353f75 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1547,11 +1547,9 @@ static CommandCost RemoveRoadStop(Station *st, DoCommandFlag flags, TileIndex ti
delete cur_stop;
/* Make sure no vehicle is going to the old roadstop */
- Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_ROAD &&
- v->First() == v &&
- v->current_order.IsType(OT_GOTO_STATION) &&
+ RoadVehicle *v;
+ FOR_ALL_ROADVEHICLES(v) {
+ if (v->First() == v && v->current_order.IsType(OT_GOTO_STATION) &&
v->dest_tile == tile) {
v->dest_tile = v->GetOrderStationLocation(st->index);
}
@@ -1964,11 +1962,9 @@ static CommandCost RemoveAirport(Station *st, DoCommandFlag flags)
CommandCost cost(EXPENSES_CONSTRUCTION, w * h * _price.remove_airport);
- const Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
-
- const Aircraft *a = (const Aircraft *)v;
+ const Aircraft *a;
+ FOR_ALL_AIRCRAFT(a) {
+ if (!IsNormalAircraft(a)) continue;
if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR;
}
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index f8a3a923e..d0d09a2ff 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -185,11 +185,11 @@ static void RailVehicleLengthChanged(const Train *u)
/** Checks if lengths of all rail vehicles are valid. If not, shows an error message. */
void CheckTrainsLengths()
{
- const Vehicle *v;
+ const Train *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_TRAIN && v->First() == v && !(v->vehstatus & VS_CRASHED)) {
- for (const Train *u = (const Train *)v, *w = (const Train *)v->Next(); w != NULL; u = w, w = w->Next()) {
+ FOR_ALL_TRAINS(v) {
+ if (v->First() == v && !(v->vehstatus & VS_CRASHED)) {
+ for (const Train *u = v, *w = v->Next(); w != NULL; u = w, w = w->Next()) {
if (u->track != TRACK_BIT_DEPOT) {
if ((w->track != TRACK_BIT_DEPOT &&
max(abs(u->x_pos - w->x_pos), abs(u->y_pos - w->y_pos)) != u->tcache.cached_veh_length) ||
@@ -654,11 +654,11 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF
if (flags & DC_EXEC) {
Vehicle *u = NULL;
- Vehicle *w;
- FOR_ALL_VEHICLES(w) {
+ Train *w;
+ FOR_ALL_TRAINS(w) {
/* do not connect new wagon with crashed/flooded consists */
- if (w->type == VEH_TRAIN && w->tile == tile &&
- IsFreeWagon(w) && w->engine_type == engine &&
+ if (w->tile == tile && IsFreeWagon(w) &&
+ w->engine_type == engine &&
!HASBITS(w->vehstatus, VS_CRASHED)) {
u = GetLastVehicleInChain(w);
break;
@@ -732,12 +732,10 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF
/** Move all free vehicles in the depot to the train */
static void NormalizeTrainVehInDepot(const Train *u)
{
- const Vehicle *v;
-
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_TRAIN && IsFreeWagon(v) &&
- v->tile == u->tile &&
- ((const Train *)v)->track == TRACK_BIT_DEPOT) {
+ const Train *v;
+ FOR_ALL_TRAINS(v) {
+ if (IsFreeWagon(v) && v->tile == u->tile &&
+ v->track == TRACK_BIT_DEPOT) {
if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC,
CMD_MOVE_RAIL_VEHICLE)))
break;
@@ -2236,8 +2234,8 @@ CommandCost CmdSendTrainToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1,
return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
}
- Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL || v->type != VEH_TRAIN) return CMD_ERROR;
+ Train *v = Train::GetIfValid(p1);
+ if (v == NULL) return CMD_ERROR;
return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK));
}
@@ -3567,10 +3565,10 @@ static Vehicle *FindTrainCollideEnum(Vehicle *v, void *data)
/* 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 */
- const Vehicle *u;
- FOR_ALL_VEHICLES(u) {
- if (u->type == VEH_TRAIN && HASBITS(u->vehstatus, VS_CRASHED) && (((const Train *)u)->track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) {
- TrackBits trackbits = ((const Train *)u)->track;
+ const Train *u;
+ FOR_ALL_TRAINS(u) {
+ if (HASBITS(u->vehstatus, VS_CRASHED) && (u->track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) {
+ TrackBits trackbits = u->track;
if ((trackbits & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) {
/* Vehicle is inside a wormhole, v->track contains no useful value then. */
trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(u->tile));
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index bf16234f2..b0a2ca30a 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -24,13 +24,12 @@ void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
/* find a locomotive in the depot. */
const Vehicle *found = NULL;
- const Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_TRAIN && IsFrontEngine(v) &&
- v->tile == tile &&
- ((const Train *)v)->track == TRACK_BIT_DEPOT) {
+ const Train *t;
+ FOR_ALL_TRAINS(t) {
+ if (IsFrontEngine(t) && t->tile == tile &&
+ t->track == TRACK_BIT_DEPOT) {
if (found != NULL) return; // must be exactly one.
- found = v;
+ found = t;
}
}
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 368835b66..eef514d03 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -491,6 +491,9 @@ public:
}
};
+#define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start)
+#define FOR_ALL_VEHICLES(var) FOR_ALL_VEHICLES_FROM(var, 0)
+
/**
* Class defining several overloaded accessors so we don't
* have to cast vehicle types that often
@@ -572,8 +575,7 @@ struct DisasterVehicle : public SpecializedVehicle<DisasterVehicle, VEH_DISASTER
bool Tick();
};
-#define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start)
-#define FOR_ALL_VEHICLES(var) FOR_ALL_VEHICLES_FROM(var, 0)
+#define FOR_ALL_DISASTERVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(DisasterVehicle, var)
/** Generates sequence of free UnitID numbers */
struct FreeUnitIDGenerator {
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index bac5417c3..f2443f69c 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -185,10 +185,8 @@ CommandCost CmdBuildTrainWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1
/* First we update the destination for all vehicles that
* have the old waypoint in their orders. */
Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_TRAIN &&
- v->First() == v &&
- v->current_order.IsType(OT_GOTO_WAYPOINT) &&
+ FOR_ALL_TRAINS(v) {
+ if (v->First() == v && v->current_order.IsType(OT_GOTO_WAYPOINT) &&
v->dest_tile == wp->xy) {
v->dest_tile = tile;
}