summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/default/default.cpp10
-rw-r--r--src/aircraft_cmd.cpp25
-rw-r--r--src/disaster_cmd.cpp2
-rw-r--r--src/oldloader.cpp4
-rw-r--r--src/openttd.cpp10
-rw-r--r--src/order_cmd.cpp10
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/station.cpp21
-rw-r--r--src/station_base.h10
-rw-r--r--src/station_cmd.cpp32
-rw-r--r--src/station_gui.cpp2
-rw-r--r--src/train_cmd.cpp2
12 files changed, 70 insertions, 60 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index 8e5f4a069..5f7f5a59b 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -3689,11 +3689,11 @@ static void AiStateRemoveStation(Company *c)
// Go through all stations and delete those that aren't in use
FOR_ALL_STATIONS(st) {
if (st->owner == _current_company && !in_use[st->index] &&
- ( (st->bus_stops != NULL && (tile = st->bus_stops->xy) != 0) ||
- (st->truck_stops != NULL && (tile = st->truck_stops->xy) != 0) ||
- (tile = st->train_tile) != 0 ||
- (tile = st->dock_tile) != 0 ||
- (tile = st->airport_tile) != 0)) {
+ ( (st->bus_stops != NULL && (tile = st->bus_stops->xy) != INVALID_TILE) ||
+ (st->truck_stops != NULL && (tile = st->truck_stops->xy) != INVALID_TILE) ||
+ (tile = st->train_tile) != INVALID_TILE ||
+ (tile = st->dock_tile) != INVALID_TILE ||
+ (tile = st->airport_tile) != INVALID_TILE)) {
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
}
}
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 85d96b42c..8d0f911af 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -632,7 +632,7 @@ static void CheckIfAircraftNeedsService(Vehicle *v)
const Station *st = GetStation(v->current_order.GetDestination());
/* only goto depot if the target airport has terminals (eg. it is airport) */
- if (st->IsValid() && st->airport_tile != 0 && st->Airport()->terminals != NULL) {
+ if (st->IsValid() && st->airport_tile != INVALID_TILE && st->Airport()->terminals != NULL) {
// printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index);
// v->u.air.targetairport = st->index;
v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE);
@@ -946,8 +946,8 @@ static byte AircraftGetEntryPoint(const Vehicle *v, const AirportFTAClass *apc)
if (IsValidStationID(v->u.air.targetairport)) {
const Station *st = GetStation(v->u.air.targetairport);
- /* Make sure we don't go to 0,0 if the airport has been removed. */
- tile = (st->airport_tile != 0) ? st->airport_tile : st->xy;
+ /* Make sure we don't go to INVALID_TILE if the airport has been removed. */
+ tile = (st->airport_tile != INVALID_TILE) ? st->airport_tile : st->xy;
}
int delta_x = v->x_pos - TileX(tile) * TILE_SIZE;
@@ -977,17 +977,16 @@ static bool AircraftController(Vehicle *v)
/* NULL if station is invalid */
const Station *st = IsValidStationID(v->u.air.targetairport) ? GetStation(v->u.air.targetairport) : NULL;
- /* 0 if there is no station */
- TileIndex tile = 0;
+ /* INVALID_TILE if there is no station */
+ TileIndex tile = INVALID_TILE;
if (st != NULL) {
- tile = st->airport_tile;
- if (tile == 0) tile = st->xy;
+ tile = (st->airport_tile != INVALID_TILE) ? st->airport_tile : st->xy;
}
/* DUMMY if there is no station or no airport */
- const AirportFTAClass *afc = tile == 0 ? GetAirport(AT_DUMMY) : st->Airport();
+ const AirportFTAClass *afc = tile == INVALID_TILE ? GetAirport(AT_DUMMY) : st->Airport();
- /* prevent going to 0,0 if airport is deleted. */
- if (st == NULL || st->airport_tile == 0) {
+ /* prevent going to INVALID_TILE if airport is deleted. */
+ if (st == NULL || st->airport_tile == INVALID_TILE) {
/* Jump into our "holding pattern" state machine if possible */
if (v->u.air.pos >= afc->nofelements) {
v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, afc);
@@ -1156,7 +1155,7 @@ static bool AircraftController(Vehicle *v)
if ((amd->flag & AMED_HOLD) && (z > 150)) z--;
if (amd->flag & AMED_LAND) {
- if (st->airport_tile == 0) {
+ if (st->airport_tile == INVALID_TILE) {
/* Airport has been removed, abort the landing procedure */
v->u.air.state = FLYING;
UpdateAircraftCache(v);
@@ -1666,7 +1665,7 @@ static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *apc)
/* runway busy or not allowed to use this airstation, circle */
if (apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES) &&
- st->airport_tile != 0 &&
+ st->airport_tile != INVALID_TILE &&
(st->owner == OWNER_NONE || st->owner == v->owner)) {
// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41},
// if it is an airplane, look for LANDING, for helicopter HELILANDING
@@ -2107,7 +2106,7 @@ Station *GetTargetAirportIfValid(const Vehicle *v)
Station *st = GetStation(sid);
- return st->airport_tile == 0 ? NULL : st;
+ return st->airport_tile == INVALID_TILE ? NULL : st;
}
/** need to be called to load aircraft from old version */
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 678fc7de4..36c365d11 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -771,7 +771,7 @@ static void Disaster_Zeppeliner_Init()
x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
FOR_ALL_STATIONS(st) {
- if (st->airport_tile != 0 &&
+ if (st->airport_tile != INVALID_TILE &&
st->airport_type <= 1 &&
IsHumanCompany(st->owner)) {
x = (TileX(st->airport_tile) + 2) * TILE_SIZE;
diff --git a/src/oldloader.cpp b/src/oldloader.cpp
index 942b4eb0a..2e072b76d 100644
--- a/src/oldloader.cpp
+++ b/src/oldloader.cpp
@@ -685,9 +685,11 @@ static bool LoadOldStation(LoadgameState *ls, int num)
if (!LoadChunk(ls, st, station_chunk))
return false;
- if (st->IsValid()) {
+ if (st->xy != 0) {
st->town = GetTown(REMAP_TOWN_IDX(_old_town_index));
st->string_id = RemapOldStringID(_old_string_id);
+ } else {
+ st->xy = INVALID_TILE;
}
return true;
diff --git a/src/openttd.cpp b/src/openttd.cpp
index a487262ed..3cbe953b3 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1409,6 +1409,16 @@ bool AfterLoadGame()
/* From this point the old names array is cleared. */
ResetOldNames();
+ /* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */
+ if (CheckSavegameVersion(105)) {
+ Station *st;
+ FOR_ALL_STATIONS(st) {
+ if (st->airport_tile == 0) st->airport_tile = INVALID_TILE;
+ if (st->dock_tile == 0) st->dock_tile = INVALID_TILE;
+ if (st->train_tile == 0) st->train_tile = INVALID_TILE;
+ }
+ }
+
/* convert road side to my format. */
if (_settings_game.vehicle.road_side) _settings_game.vehicle.road_side = 1;
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index f0806f607..e53630092 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -1377,13 +1377,13 @@ static TileIndex GetStationTileForVehicle(const Vehicle* v, const Station* st)
switch (v->type) {
default: NOT_REACHED();
case VEH_TRAIN: return st->train_tile;
- case VEH_AIRCRAFT: return CanAircraftUseStation(v->engine_type, st) ? st->airport_tile : 0;
+ case VEH_AIRCRAFT: return CanAircraftUseStation(v->engine_type, st) ? st->airport_tile : INVALID_TILE;
case VEH_SHIP: return st->dock_tile;
case VEH_ROAD:
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
- return (st->bus_stops != NULL) ? st->bus_stops->xy : 0;
+ return (st->bus_stops != NULL) ? st->bus_stops->xy : INVALID_TILE;
} else {
- return (st->truck_stops != NULL) ? st->truck_stops->xy : 0;
+ return (st->truck_stops != NULL) ? st->truck_stops->xy : INVALID_TILE;
}
}
}
@@ -1430,7 +1430,7 @@ void CheckOrders(const Vehicle* v)
TileIndex required_tile = GetStationTileForVehicle(v, st);
n_st++;
- if (required_tile == 0) problem_type = 3;
+ if (required_tile == INVALID_TILE) problem_type = 3;
}
}
@@ -1763,7 +1763,7 @@ bool ProcessOrders(Vehicle *v)
/* If it is unchanged, keep it. */
if (order->Equals(v->current_order) && (v->type == VEH_AIRCRAFT || v->dest_tile != 0) &&
- (v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || GetStation(order->GetDestination())->dock_tile != 0)) {
+ (v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || GetStation(order->GetDestination())->dock_tile != INVALID_TILE)) {
return false;
}
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index bb3b8f83d..b93433514 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -237,7 +237,7 @@ TileIndex Ship::GetOrderStationLocation(StationID station)
if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
const Station *st = GetStation(station);
- if (st->dock_tile != 0) {
+ if (st->dock_tile != INVALID_TILE) {
return TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile)));
} else {
this->cur_order_index++;
diff --git a/src/station.cpp b/src/station.cpp
index 371a8fc43..4bb65b0d8 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -42,7 +42,7 @@ Station::Station(TileIndex tile)
DEBUG(station, cDebugCtorLevel, "I+%3d", index);
xy = tile;
- airport_tile = dock_tile = train_tile = 0;
+ airport_tile = dock_tile = train_tile = INVALID_TILE;
bus_stops = truck_stops = NULL;
had_vehicle_of_type = 0;
time_since_load = 255;
@@ -97,7 +97,7 @@ Station::~Station()
/* Remove all news items */
DeleteStationNews(this->index);
- xy = 0;
+ xy = INVALID_TILE;
for (CargoID c = 0; c < NUM_CARGO; c++) {
goods[c].cargo.Truncate(0);
@@ -161,8 +161,7 @@ void Station::MarkTilesDirty(bool cargo_change) const
TileIndex tile = train_tile;
int w, h;
- /* XXX No station is recorded as 0, not INVALID_TILE... */
- if (tile == 0) return;
+ if (tile == INVALID_TILE) return;
/* cargo_change is set if we're refreshing the tiles due to cargo moving
* around. */
@@ -255,13 +254,13 @@ uint Station::GetCatchmentRadius() const
uint ret = CA_NONE;
if (_settings_game.station.modified_catchment) {
- if (this->bus_stops != NULL) ret = max<uint>(ret, CA_BUS);
- if (this->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK);
- if (this->train_tile != 0) ret = max<uint>(ret, CA_TRAIN);
- if (this->dock_tile != 0) ret = max<uint>(ret, CA_DOCK);
- if (this->airport_tile != 0) ret = max<uint>(ret, this->Airport()->catchment);
+ if (this->bus_stops != NULL) ret = max<uint>(ret, CA_BUS);
+ if (this->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK);
+ if (this->train_tile != INVALID_TILE) ret = max<uint>(ret, CA_TRAIN);
+ if (this->dock_tile != INVALID_TILE) ret = max<uint>(ret, CA_DOCK);
+ if (this->airport_tile != INVALID_TILE) ret = max<uint>(ret, this->Airport()->catchment);
} else {
- if (this->bus_stops != NULL || this->truck_stops != NULL || this->train_tile != 0 || this->dock_tile != 0 || this->airport_tile != 0) {
+ if (this->bus_stops != NULL || this->truck_stops != NULL || this->train_tile != INVALID_TILE || this->dock_tile != INVALID_TILE || this->airport_tile != INVALID_TILE) {
ret = CA_UNMODIFIED;
}
}
@@ -469,7 +468,7 @@ RoadStop::~RoadStop()
DEBUG(ms, cDebugCtorLevel , "I- at %d[0x%x]", xy, xy);
- xy = 0;
+ xy = INVALID_TILE;
}
/** Checks whether there is a free bay in this road stop */
diff --git a/src/station_base.h b/src/station_base.h
index 2943c10f8..2859096da 100644
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -58,14 +58,14 @@ struct RoadStop : PoolItem<RoadStop, RoadStopID, &_RoadStop_pool> {
byte num_vehicles; ///< Number of vehicles currently slotted to this stop
struct RoadStop *next; ///< Next stop of the given type at this station
- RoadStop(TileIndex tile = 0);
+ RoadStop(TileIndex tile = INVALID_TILE);
virtual ~RoadStop();
/**
* Determines whether a road stop exists
* @return true if and only is the road stop exists
*/
- inline bool IsValid() const { return this->xy != 0; }
+ inline bool IsValid() const { return this->xy != INVALID_TILE; }
/* For accessing status */
bool HasFreeBay() const;
@@ -120,7 +120,7 @@ public:
const AirportFTAClass *Airport() const
{
- if (airport_tile == 0) return GetAirport(AT_DUMMY);
+ if (airport_tile == INVALID_TILE) return GetAirport(AT_DUMMY);
return GetAirport(airport_type);
}
@@ -171,7 +171,7 @@ public:
static const int cDebugCtorLevel = 5;
- Station(TileIndex tile = 0);
+ Station(TileIndex tile = INVALID_TILE);
virtual ~Station();
void AddFacility(byte new_facility_bit, TileIndex facil_xy);
@@ -198,7 +198,7 @@ public:
* Determines whether a station exists
* @return true if and only is the station exists
*/
- inline bool IsValid() const { return this->xy != 0; }
+ inline bool IsValid() const { return this->xy != INVALID_TILE; }
uint GetCatchmentRadius() const;
};
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index b39fa40c7..d43e89283 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -573,19 +573,19 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
uint old_acc = GetAcceptanceMask(st);
/* Put all the tiles that span an area in the table. */
- if (st->train_tile != 0) {
+ if (st->train_tile != INVALID_TILE) {
MergePoint(&rect, st->train_tile);
MergePoint(&rect, st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1));
}
- if (st->airport_tile != 0) {
+ if (st->airport_tile != INVALID_TILE) {
const AirportFTAClass *afc = st->Airport();
MergePoint(&rect, st->airport_tile);
MergePoint(&rect, st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1));
}
- if (st->dock_tile != 0) {
+ if (st->dock_tile != INVALID_TILE) {
MergePoint(&rect, st->dock_tile);
if (IsDockTile(st->dock_tile)) {
MergePoint(&rect, st->dock_tile + TileOffsByDiagDir(GetDockDirection(st->dock_tile)));
@@ -986,7 +986,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1,
if (st->owner != _current_company)
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
- if (st->train_tile != 0) {
+ if (st->train_tile != INVALID_TILE) {
/* check if we want to expanding an already existing station? */
if (_is_old_ai_company || !_settings_game.station.join_stations)
return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD);
@@ -1177,7 +1177,7 @@ restart:
}
}
} else {
- tile = 0;
+ tile = INVALID_TILE;
}
st->trainst_w = w;
@@ -1281,7 +1281,7 @@ CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1
}
/* if we deleted the whole station, delete the train facility. */
- if (st->train_tile == 0) {
+ if (st->train_tile == INVALID_TILE) {
st->facilities &= ~FACIL_TRAIN;
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
UpdateStationVirtCoordDirty(st);
@@ -1348,7 +1348,7 @@ static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, uint32 fla
if (flags & DC_EXEC) {
st->rect.AfterRemoveRect(st, st->train_tile, st->trainst_w, st->trainst_h);
- st->train_tile = 0;
+ st->train_tile = INVALID_TILE;
st->trainst_w = st->trainst_h = 0;
st->facilities &= ~FACIL_TRAIN;
@@ -1803,7 +1803,7 @@ void UpdateAirportsNoise()
FOR_ALL_TOWNS(t) t->noise_reached = 0;
FOR_ALL_STATIONS(st) {
- if (st->airport_tile != 0) {
+ if (st->airport_tile != INVALID_TILE) {
st->town->noise_reached += GetAirportNoiseLevelForTown(GetAirport(st->airport_type), st->town->xy, st->airport_tile);
}
}
@@ -1881,7 +1881,7 @@ CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST)) return CMD_ERROR;
- if (st->airport_tile != 0) {
+ if (st->airport_tile != INVALID_TILE) {
return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT);
}
} else {
@@ -1991,7 +1991,7 @@ static CommandCost RemoveAirport(Station *st, uint32 flags)
st->rect.AfterRemoveRect(st, tile, w, h);
- st->airport_tile = 0;
+ st->airport_tile = INVALID_TILE;
st->facilities &= ~FACIL_AIRPORT;
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
@@ -2087,7 +2087,7 @@ static CommandCost RemoveBuoy(Station *st, uint32 flags)
if (!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
if (flags & DC_EXEC) {
- st->dock_tile = 0;
+ st->dock_tile = INVALID_TILE;
/* Buoys are marked in the Station struct by this flag. Yes, it is this
* braindead.. */
st->facilities &= ~FACIL_DOCK;
@@ -2178,7 +2178,7 @@ CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
_dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST)) return CMD_ERROR;
- if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK);
+ if (st->dock_tile != INVALID_TILE) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK);
} else {
/* allocate and initialize new station */
/* allocate and initialize new station */
@@ -2234,7 +2234,7 @@ static CommandCost RemoveDock(Station *st, uint32 flags)
MarkTileDirtyByTile(tile2);
- st->dock_tile = 0;
+ st->dock_tile = INVALID_TILE;
st->facilities &= ~FACIL_DOCK;
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
@@ -3050,7 +3050,7 @@ void BuildOilRig(TileIndex tile)
st->truck_stops = NULL;
st->airport_tile = tile;
st->dock_tile = tile;
- st->train_tile = 0;
+ st->train_tile = INVALID_TILE;
st->had_vehicle_of_type = 0;
st->time_since_load = 255;
st->time_since_unload = 255;
@@ -3080,8 +3080,8 @@ void DeleteOilRig(TileIndex tile)
MakeWaterKeepingClass(tile, OWNER_NONE);
MarkTileDirtyByTile(tile);
- st->dock_tile = 0;
- st->airport_tile = 0;
+ st->dock_tile = INVALID_TILE;
+ st->airport_tile = INVALID_TILE;
st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK);
st->airport_flags = 0;
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index da5cc5773..537de777b 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -338,7 +338,7 @@ public:
const Station *st = this->stations[i];
int x;
- assert(st->xy != 0);
+ assert(st->xy != INVALID_TILE);
/* Do not do the complex check HasStationInUse here, it may be even false
* when the order had been removed and the station list hasn't been removed yet */
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 80ead8107..50f50b137 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -4447,7 +4447,7 @@ void Train::OnNewDay()
/* update destination */
if (this->current_order.IsType(OT_GOTO_STATION)) {
TileIndex tile = GetStation(this->current_order.GetDestination())->train_tile;
- if (tile != 0) this->dest_tile = tile;
+ if (tile != INVALID_TILE) this->dest_tile = tile;
}
if (this->running_ticks != 0) {