(svn r16442) -Codechange: use new Vehicle accessors at more places

This commit is contained in:
smatz 2009-05-26 22:45:48 +00:00
parent 7ee882d03f
commit 5a463c8347
16 changed files with 127 additions and 153 deletions

View File

@ -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) CommandCost CmdSellAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{ {
Vehicle *v = Vehicle::GetIfValid(p1); Aircraft *v = Aircraft::GetIfValid(p1);
if (v == NULL) return CMD_ERROR;
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 (!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); 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); 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 == NULL) return CMD_ERROR;
if (v->type != VEH_AIRCRAFT) return CMD_ERROR;
return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); 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); byte new_subtype = GB(p2, 8, 8);
Vehicle *v = Vehicle::GetIfValid(p1); Aircraft *v = Aircraft::GetIfValid(p1);
if (v == NULL) return CMD_ERROR; if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_AIRCRAFT_MUST_BE_STOPPED); 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); if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE);

View File

@ -300,9 +300,9 @@ static bool DisasterTick_Ufo(DisasterVehicle *v)
} }
v->current_order.SetDestination(1); v->current_order.SetDestination(1);
Vehicle *u; RoadVehicle *u;
FOR_ALL_VEHICLES(u) { FOR_ALL_ROADVEHICLES(u) {
if (u->type == VEH_ROAD && IsRoadVehFront(u)) { if (IsRoadVehFront(u)) {
v->dest_tile = u->index; v->dest_tile = u->index;
v->age = 0; v->age = 0;
return true; return true;
@ -938,10 +938,10 @@ void StartupDisasters()
*/ */
void ReleaseDisastersTargetingIndustry(IndustryID i) void ReleaseDisastersTargetingIndustry(IndustryID i)
{ {
Vehicle *v; DisasterVehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_DISASTERVEHICLES(v) {
/* primary disaster vehicles that have chosen target */ /* 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 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); if (v->current_order.GetDestination() > 0 && v->dest_tile == i) v->current_order.SetDestination(3);
} }

View File

@ -37,4 +37,6 @@ struct EffectVehicle : public SpecializedVehicle<EffectVehicle, VEH_EFFECT> {
bool Tick(); bool Tick();
}; };
#define FOR_ALL_EFFECTVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(EffectVehicle, var)
#endif /* EFFECTVEHICLE_BASE_H */ #endif /* EFFECTVEHICLE_BASE_H */

View File

@ -37,11 +37,9 @@
*/ */
bool RoadVehiclesAreBuilt() 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; return false;
} }
@ -274,9 +272,9 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
if (HasRoadWorks(tile)) { if (HasRoadWorks(tile)) {
/* flooding tile with road works, don't forget to remove the effect vehicle too */ /* flooding tile with road works, don't forget to remove the effect vehicle too */
assert(_current_company == OWNER_WATER); assert(_current_company == OWNER_WATER);
Vehicle *v; EffectVehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_EFFECTVEHICLES(v) {
if (v->type == VEH_EFFECT && TileVirtXY(v->x_pos, v->y_pos) == tile) { if (TileVirtXY(v->x_pos, v->y_pos) == tile) {
delete v; 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) static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
{ {
switch (GetRoadTileType(tile)) { switch (GetRoadTileType(tile)) {
case ROAD_TILE_CROSSING:
if (v->type == VEH_TRAIN) {
/* it should be barred */
assert(IsCrossingBarred(tile));
}
break;
case ROAD_TILE_DEPOT: { case ROAD_TILE_DEPOT: {
if (v->type != VEH_ROAD) break; if (v->type != VEH_ROAD) break;

View File

@ -312,8 +312,8 @@ bool RoadVehicle::IsStoppedInDepot() const
*/ */
CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{ {
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 (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE); 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); return SendAllVehiclesToDepot(VEH_ROAD, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
} }
Vehicle *v = Vehicle::GetIfValid(p1); RoadVehicle *v = RoadVehicle::GetIfValid(p1);
if (v == NULL || v->type != VEH_ROAD) return CMD_ERROR; if (v == NULL) return CMD_ERROR;
return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); 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; uint16 capacity = CALLBACK_FAILED;
uint total_capacity = 0; 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->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); if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE);

View File

@ -314,9 +314,9 @@ static void FixOwnerOfRailTrack(TileIndex t)
assert(!Company::IsValidID(GetTileOwner(t)) && (IsLevelCrossingTile(t) || IsPlainRailTile(t))); assert(!Company::IsValidID(GetTileOwner(t)) && (IsLevelCrossingTile(t) || IsPlainRailTile(t)));
/* remove leftover rail piece from crossing (from very old savegames) */ /* remove leftover rail piece from crossing (from very old savegames) */
Vehicle *v = NULL, *w; Train *v = NULL, *w;
FOR_ALL_VEHICLES(w) { FOR_ALL_TRAINS(w) {
if (w->type == VEH_TRAIN && w->tile == t) { if (w->tile == t) {
v = w; v = w;
break; break;
} }
@ -1286,10 +1286,10 @@ bool AfterLoadGame()
} }
if (CheckSavegameVersion(50)) { if (CheckSavegameVersion(50)) {
Vehicle *v; Aircraft *v;
/* Aircraft units changed from 8 mph to 1 km/h */ /* Aircraft units changed from 8 mph to 1 km/h */
FOR_ALL_VEHICLES(v) { FOR_ALL_AIRCRAFT(v) {
if (v->type == VEH_AIRCRAFT && v->subtype <= AIR_AIRCRAFT) { if (v->subtype <= AIR_AIRCRAFT) {
const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type); const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
v->cur_speed *= 129; v->cur_speed *= 129;
v->cur_speed /= 10; v->cur_speed /= 10;
@ -1624,10 +1624,9 @@ bool AfterLoadGame()
if (CheckSavegameVersion(62)) { if (CheckSavegameVersion(62)) {
/* Remove all trams from savegames without tram support. /* Remove all trams from savegames without tram support.
* There would be trams without tram track under causing crashes sooner or later. */ * There would be trams without tram track under causing crashes sooner or later. */
Vehicle *v; RoadVehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_ROADVEHICLES(v) {
if (v->type == VEH_ROAD && v->First() == v && if (v->First() == v && HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) {
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) { if (_switch_mode_errorstr == INVALID_STRING_ID || _switch_mode_errorstr == STR_NEWGRF_COMPATIBLE_LOAD_WARNING) {
_switch_mode_errorstr = STR_LOADGAME_REMOVED_TRAMS; _switch_mode_errorstr = STR_LOADGAME_REMOVED_TRAMS;
} }
@ -1735,11 +1734,11 @@ bool AfterLoadGame()
} }
if (CheckSavegameVersion(104)) { if (CheckSavegameVersion(104)) {
Vehicle *v; Aircraft *a;
FOR_ALL_VEHICLES(v) { FOR_ALL_AIRCRAFT(a) {
/* Set engine_type of shadow and rotor */ /* Set engine_type of shadow and rotor */
if (v->type == VEH_AIRCRAFT && !IsNormalAircraft(v)) { if (!IsNormalAircraft(a)) {
v->engine_type = v->First()->engine_type; a->engine_type = a->First()->engine_type;
} }
} }

View File

@ -100,55 +100,49 @@ void ConnectMultiheadedTrains()
*/ */
void ConvertOldMultiheadToNew() void ConvertOldMultiheadToNew()
{ {
Vehicle *v; Train *t;
FOR_ALL_VEHICLES(v) { FOR_ALL_TRAINS(t) SetBit(t->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop
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) { FOR_ALL_TRAINS(t) {
if (v->type == VEH_TRAIN) { if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
if (HasBit(v->subtype, 7) && ((v->subtype & ~0x80) == 0 || (v->subtype & ~0x80) == 4)) { for (Vehicle *u = t; u != NULL; u = u->Next()) {
for (Vehicle *u = v; u != NULL; u = u->Next()) { const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
ClrBit(u->subtype, 7); ClrBit(u->subtype, 7);
switch (u->subtype) { switch (u->subtype) {
case 0: // TS_Front_Engine case 0: // TS_Front_Engine
if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u); if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u);
SetFrontEngine(u); SetFrontEngine(u);
SetTrainEngine(u); SetTrainEngine(u);
break; break;
case 1: // TS_Artic_Part case 1: // TS_Artic_Part
u->subtype = 0; u->subtype = 0;
SetArticulatedPart(u); SetArticulatedPart(u);
break; break;
case 2: // TS_Not_First case 2: // TS_Not_First
u->subtype = 0; u->subtype = 0;
if (rvi->railveh_type == RAILVEH_WAGON) { if (rvi->railveh_type == RAILVEH_WAGON) {
/* normal 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 4: // TS_Free_Car
u->subtype = 0;
SetTrainWagon(u); SetTrainWagon(u);
SetFreeWagon(u);
break; 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();
} }
} }
} }

View File

@ -57,6 +57,7 @@
#include "ai/ai_config.hpp" #include "ai/ai_config.hpp"
#include "newgrf.h" #include "newgrf.h"
#include "engine_base.h" #include "engine_base.h"
#include "ship.h"
#include "void_map.h" #include "void_map.h"
#include "station_base.h" #include "station_base.h"
@ -878,9 +879,9 @@ static bool CheckFreeformEdges(int32 p1)
{ {
if (_game_mode == GM_MENU) return true; if (_game_mode == GM_MENU) return true;
if (p1 != 0) { if (p1 != 0) {
Vehicle *v; Ship *s;
FOR_ALL_VEHICLES(v) { FOR_ALL_SHIPS(s) {
if (v->type == VEH_SHIP && (TileX(v->tile) == 0 || TileY(v->tile) == 0)) { if (TileX(s->tile) == 0 || TileY(s->tile) == 0) {
ShowErrorMessage(INVALID_STRING_ID, STR_CONFIG_SETTING_EDGES_NOT_EMPTY, 0, 0); ShowErrorMessage(INVALID_STRING_ID, STR_CONFIG_SETTING_EDGES_NOT_EMPTY, 0, 0);
return false; return false;
} }

View File

@ -49,4 +49,6 @@ struct Ship: public SpecializedVehicle<Ship, VEH_SHIP> {
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
}; };
#define FOR_ALL_SHIPS(var) FOR_ALL_VEHICLES_OF_TYPE(Ship, var)
#endif /* SHIP_H */ #endif /* SHIP_H */

View File

@ -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) CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{ {
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 (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE); 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); return SendAllVehiclesToDepot(VEH_SHIP, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
} }
Vehicle *v = Vehicle::GetIfValid(p1); Ship *v = Ship::GetIfValid(p1);
if (v == NULL || v->type != VEH_SHIP) return CMD_ERROR; if (v == NULL) return CMD_ERROR;
return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); 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); byte new_subtype = GB(p2, 8, 8);
uint16 capacity = CALLBACK_FAILED; 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->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); if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE);

View File

@ -20,6 +20,7 @@
#include "vehicle_base.h" #include "vehicle_base.h"
#include "sound_func.h" #include "sound_func.h"
#include "window_func.h" #include "window_func.h"
#include "effectvehicle_base.h"
#include "table/strings.h" #include "table/strings.h"
#include "table/sprites.h" #include "table/sprites.h"
@ -739,13 +740,9 @@ public:
/* draw vehicles? */ /* draw vehicles? */
if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) { if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) {
Vehicle *v; EffectVehicle *v;
bool skip; FOR_ALL_EFFECTVEHICLES(v) {
byte colour; if ((v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0) {
FOR_ALL_VEHICLES(v) {
if (v->type != VEH_EFFECT &&
(v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0) {
/* Remap into flat coordinates. */ /* Remap into flat coordinates. */
Point pt = RemapCoords( 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 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; if (!IsInsideMM(y, 0, dpi->height)) continue;
/* Default is to draw both pixels. */ /* Default is to draw both pixels. */
skip = false; bool skip = false;
/* Offset X coordinate */ /* Offset X coordinate */
x -= this->subscroll + 3 + dpi->left; x -= this->subscroll + 3 + dpi->left;
@ -776,7 +773,7 @@ public:
} }
/* Calculate pointer to pixel and the colour */ /* 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 */ /* And draw either one or two pixels depending on clipping */
blitter->SetPixel(dpi->dst_ptr, x, y, colour); blitter->SetPixel(dpi->dst_ptr, x, y, colour);

View File

@ -1547,11 +1547,9 @@ static CommandCost RemoveRoadStop(Station *st, DoCommandFlag flags, TileIndex ti
delete cur_stop; delete cur_stop;
/* Make sure no vehicle is going to the old roadstop */ /* Make sure no vehicle is going to the old roadstop */
Vehicle *v; RoadVehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_ROADVEHICLES(v) {
if (v->type == VEH_ROAD && if (v->First() == v && v->current_order.IsType(OT_GOTO_STATION) &&
v->First() == v &&
v->current_order.IsType(OT_GOTO_STATION) &&
v->dest_tile == tile) { v->dest_tile == tile) {
v->dest_tile = v->GetOrderStationLocation(st->index); 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); CommandCost cost(EXPENSES_CONSTRUCTION, w * h * _price.remove_airport);
const Vehicle *v; const Aircraft *a;
FOR_ALL_VEHICLES(v) { FOR_ALL_AIRCRAFT(a) {
if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue; if (!IsNormalAircraft(a)) continue;
const Aircraft *a = (const Aircraft *)v;
if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR; if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR;
} }

View File

@ -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. */ /** Checks if lengths of all rail vehicles are valid. If not, shows an error message. */
void CheckTrainsLengths() void CheckTrainsLengths()
{ {
const Vehicle *v; const Train *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_TRAINS(v) {
if (v->type == VEH_TRAIN && v->First() == v && !(v->vehstatus & VS_CRASHED)) { if (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 (const Train *u = v, *w = v->Next(); w != NULL; u = w, w = w->Next()) {
if (u->track != TRACK_BIT_DEPOT) { if (u->track != TRACK_BIT_DEPOT) {
if ((w->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) || 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) { if (flags & DC_EXEC) {
Vehicle *u = NULL; Vehicle *u = NULL;
Vehicle *w; Train *w;
FOR_ALL_VEHICLES(w) { FOR_ALL_TRAINS(w) {
/* do not connect new wagon with crashed/flooded consists */ /* do not connect new wagon with crashed/flooded consists */
if (w->type == VEH_TRAIN && w->tile == tile && if (w->tile == tile && IsFreeWagon(w) &&
IsFreeWagon(w) && w->engine_type == engine && w->engine_type == engine &&
!HASBITS(w->vehstatus, VS_CRASHED)) { !HASBITS(w->vehstatus, VS_CRASHED)) {
u = GetLastVehicleInChain(w); u = GetLastVehicleInChain(w);
break; break;
@ -732,12 +732,10 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF
/** Move all free vehicles in the depot to the train */ /** Move all free vehicles in the depot to the train */
static void NormalizeTrainVehInDepot(const Train *u) static void NormalizeTrainVehInDepot(const Train *u)
{ {
const Vehicle *v; const Train *v;
FOR_ALL_TRAINS(v) {
FOR_ALL_VEHICLES(v) { if (IsFreeWagon(v) && v->tile == u->tile &&
if (v->type == VEH_TRAIN && IsFreeWagon(v) && v->track == TRACK_BIT_DEPOT) {
v->tile == u->tile &&
((const Train *)v)->track == TRACK_BIT_DEPOT) {
if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC, if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC,
CMD_MOVE_RAIL_VEHICLE))) CMD_MOVE_RAIL_VEHICLE)))
break; 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); return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
} }
Vehicle *v = Vehicle::GetIfValid(p1); Train *v = Train::GetIfValid(p1);
if (v == NULL || v->type != VEH_TRAIN) return CMD_ERROR; if (v == NULL) return CMD_ERROR;
return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); 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. /* 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 */
const Vehicle *u; const Train *u;
FOR_ALL_VEHICLES(u) { FOR_ALL_TRAINS(u) {
if (u->type == VEH_TRAIN && HASBITS(u->vehstatus, VS_CRASHED) && (((const Train *)u)->track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) { if (HASBITS(u->vehstatus, VS_CRASHED) && (u->track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) {
TrackBits trackbits = ((const Train *)u)->track; TrackBits trackbits = u->track;
if ((trackbits & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) { if ((trackbits & 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(u->tile)); trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(u->tile));

View File

@ -24,13 +24,12 @@ void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
/* find a locomotive in the depot. */ /* find a locomotive in the depot. */
const Vehicle *found = NULL; const Vehicle *found = NULL;
const Vehicle *v; const Train *t;
FOR_ALL_VEHICLES(v) { FOR_ALL_TRAINS(t) {
if (v->type == VEH_TRAIN && IsFrontEngine(v) && if (IsFrontEngine(t) && t->tile == tile &&
v->tile == tile && t->track == TRACK_BIT_DEPOT) {
((const Train *)v)->track == TRACK_BIT_DEPOT) {
if (found != NULL) return; // must be exactly one. if (found != NULL) return; // must be exactly one.
found = v; found = t;
} }
} }

View File

@ -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 * Class defining several overloaded accessors so we don't
* have to cast vehicle types that often * have to cast vehicle types that often
@ -572,8 +575,7 @@ struct DisasterVehicle : public SpecializedVehicle<DisasterVehicle, VEH_DISASTER
bool Tick(); bool Tick();
}; };
#define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start) #define FOR_ALL_DISASTERVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(DisasterVehicle, var)
#define FOR_ALL_VEHICLES(var) FOR_ALL_VEHICLES_FROM(var, 0)
/** Generates sequence of free UnitID numbers */ /** Generates sequence of free UnitID numbers */
struct FreeUnitIDGenerator { struct FreeUnitIDGenerator {

View File

@ -185,10 +185,8 @@ CommandCost CmdBuildTrainWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1
/* First we update the destination for all vehicles that /* First we update the destination for all vehicles that
* have the old waypoint in their orders. */ * have the old waypoint in their orders. */
Vehicle *v; Vehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_TRAINS(v) {
if (v->type == VEH_TRAIN && if (v->First() == v && v->current_order.IsType(OT_GOTO_WAYPOINT) &&
v->First() == v &&
v->current_order.IsType(OT_GOTO_WAYPOINT) &&
v->dest_tile == wp->xy) { v->dest_tile == wp->xy) {
v->dest_tile = tile; v->dest_tile = tile;
} }