diff options
author | smatz <smatz@openttd.org> | 2009-01-03 16:06:58 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-01-03 16:06:58 +0000 |
commit | b00e510140b4983d58f580fdca87368b1edb436a (patch) | |
tree | cfe8a97df4f219709152bb304eee65541e9ab8db /src | |
parent | 7a2adef8594cb54b5ec00466117c7608d3619150 (diff) | |
download | openttd-b00e510140b4983d58f580fdca87368b1edb436a.tar.xz |
(svn r14807) -Codechange: use INVALID_TILE instead of 0 to mark invalid depots, industries, towns and waypoints
Diffstat (limited to 'src')
-rw-r--r-- | src/build_vehicle_gui.cpp | 14 | ||||
-rw-r--r-- | src/depot.cpp | 2 | ||||
-rw-r--r-- | src/depot_base.h | 4 | ||||
-rw-r--r-- | src/economy.cpp | 2 | ||||
-rw-r--r-- | src/group_gui.cpp | 2 | ||||
-rw-r--r-- | src/industry.h | 4 | ||||
-rw-r--r-- | src/industry_cmd.cpp | 4 | ||||
-rw-r--r-- | src/oldloader.cpp | 18 | ||||
-rw-r--r-- | src/order_gui.cpp | 4 | ||||
-rw-r--r-- | src/town.h | 4 | ||||
-rw-r--r-- | src/town_cmd.cpp | 4 | ||||
-rw-r--r-- | src/town_gui.cpp | 4 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 2 | ||||
-rw-r--r-- | src/waypoint.cpp | 2 | ||||
-rw-r--r-- | src/waypoint.h | 4 |
15 files changed, 42 insertions, 32 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 6ce2334df..7cfcc6aec 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -797,7 +797,7 @@ struct BuildVehicleWindow : Window { EngineID rename_engine; GUIEngineList eng_list; - BuildVehicleWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc, tile == 0 ? (int)type : tile) + BuildVehicleWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc, tile == INVALID_TILE ? (int)type : tile) { this->vehicle_type = type; int vlh = GetVehicleListHeight(this->vehicle_type); @@ -810,7 +810,7 @@ struct BuildVehicleWindow : Window { this->resize.width = this->width; this->resize.height = this->height; - this->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_company; + this->caption_color = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company; this->sel_engine = INVALID_ENGINE; this->regenerate_list = false; @@ -821,15 +821,15 @@ struct BuildVehicleWindow : Window { switch (type) { default: NOT_REACHED(); case VEH_TRAIN: - this->filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile); + this->filter.railtype = (tile == INVALID_TILE) ? RAILTYPE_END : GetRailType(tile); break; case VEH_ROAD: - this->filter.roadtypes = (tile == 0) ? ROADTYPES_ALL : GetRoadTypes(tile); + this->filter.roadtypes = (tile == INVALID_TILE) ? ROADTYPES_ALL : GetRoadTypes(tile); case VEH_SHIP: break; case VEH_AIRCRAFT: this->filter.flags = - tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags; + tile == INVALID_TILE ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags; break; } this->SetupWindowStrings(type); @@ -1194,10 +1194,10 @@ static const WindowDesc _build_vehicle_desc = { void ShowBuildVehicleWindow(TileIndex tile, VehicleType type) { /* We want to be able to open both Available Train as Available Ships, - * so if tile == 0 (Available XXX Window), use 'type' as unique number. + * so if tile == INVALID_TILE (Available XXX Window), use 'type' as unique number. * As it always is a low value, it won't collide with any real tile * number. */ - uint num = (tile == 0) ? (int)type : tile; + uint num = (tile == INVALID_TILE) ? (int)type : tile; assert(IsCompanyBuildableVehicleType(type)); diff --git a/src/depot.cpp b/src/depot.cpp index 8b9abe06a..005f067b1 100644 --- a/src/depot.cpp +++ b/src/depot.cpp @@ -43,7 +43,7 @@ Depot::~Depot() /* Delete the depot-window */ DeleteWindowById(WC_VEHICLE_DEPOT, this->xy); - this->xy = 0; + this->xy = INVALID_TILE; } void InitializeDepots() diff --git a/src/depot_base.h b/src/depot_base.h index 35d35e392..53877485d 100644 --- a/src/depot_base.h +++ b/src/depot_base.h @@ -16,10 +16,10 @@ struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> { TileIndex xy; TownID town_index; - Depot(TileIndex xy = 0) : xy(xy) {} + Depot(TileIndex xy = INVALID_TILE) : xy(xy) {} ~Depot(); - inline bool IsValid() const { return this->xy != 0; } + inline bool IsValid() const { return this->xy != INVALID_TILE; } }; static inline bool IsValidDepotID(DepotID index) diff --git a/src/economy.cpp b/src/economy.cpp index 6b8162608..a6fbb55f2 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1313,7 +1313,7 @@ static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type) if (cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) { xy = GetTown(s->from)->xy; } else { - xy = (GetIndustry(s->from))->xy; + xy = GetIndustry(s->from)->xy; } if (DistanceMax(xy, from->xy) > 9) continue; diff --git a/src/group_gui.cpp b/src/group_gui.cpp index e15a2f629..a59b7830c 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -535,7 +535,7 @@ public: case GRP_WIDGET_AVAILABLE_VEHICLES: - ShowBuildVehicleWindow(0, this->vehicle_type); + ShowBuildVehicleWindow(INVALID_TILE, this->vehicle_type); break; case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN: diff --git a/src/industry.h b/src/industry.h index e750c6ab0..f154823a2 100644 --- a/src/industry.h +++ b/src/industry.h @@ -132,10 +132,10 @@ struct Industry : PoolItem<Industry, IndustryID, &_Industry_pool> { PersistentStorage psa; ///< Persistent storage for NewGRF industries. - Industry(TileIndex tile = 0) : xy(tile) {} + Industry(TileIndex tile = INVALID_TILE) : xy(tile) {} ~Industry(); - inline bool IsValid() const { return this->xy != 0; } + inline bool IsValid() const { return this->xy != INVALID_TILE; } }; struct IndustryTileTable { diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 413a3aa81..d13cf5132 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -140,7 +140,7 @@ Industry::~Industry() /* Industry can also be destroyed when not fully initialized. * This means that we do not have to clear tiles either. */ if (this->width == 0) { - this->xy = 0; + this->xy = INVALID_TILE; return; } @@ -174,7 +174,7 @@ Industry::~Industry() DeleteSubsidyWithIndustry(this->index); DeleteWindowById(WC_INDUSTRY_VIEW, this->index); InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0); - this->xy = 0; + this->xy = INVALID_TILE; } static void IndustryDrawSugarMine(const TileInfo *ti) diff --git a/src/oldloader.cpp b/src/oldloader.cpp index a94824978..cb55afc50 100644 --- a/src/oldloader.cpp +++ b/src/oldloader.cpp @@ -490,7 +490,12 @@ static const OldChunks town_chunk[] = { }; static bool LoadOldTown(LoadgameState *ls, int num) { - return LoadChunk(ls, new (num) Town(), town_chunk); + Town *t = new (num) Town(); + if (!LoadChunk(ls, t, town_chunk)) return false; + + if (t->xy == 0) t->xy = INVALID_TILE; + + return true; } static uint16 _old_order; @@ -545,10 +550,13 @@ static const OldChunks depot_chunk[] = { static bool LoadOldDepot(LoadgameState *ls, int num) { - if (!LoadChunk(ls, new (num) Depot(), depot_chunk)) return false; + Depot *d = new (num) Depot(); + if (!LoadChunk(ls, d, depot_chunk)) return false; - if (IsValidDepotID(num)) { + if (d->xy != 0) { GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index); + } else { + d->xy = INVALID_TILE; } return true; @@ -732,9 +740,11 @@ static bool LoadOldIndustry(LoadgameState *ls, int num) Industry *i = new (num) Industry(); if (!LoadChunk(ls, i, industry_chunk)) return false; - if (i->IsValid()) { + if (i->xy != 0) { i->town = GetTown(REMAP_TOWN_IDX(_old_town_index)); IncIndustryTypeCount(i->type); + } else { + i->xy = INVALID_TILE; } return true; diff --git a/src/order_gui.cpp b/src/order_gui.cpp index a3a69d8a1..3f70a8c28 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -838,7 +838,7 @@ public: if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) { const Order *ord = GetVehicleOrder(this->vehicle, sel); - TileIndex xy = 0; + TileIndex xy = INVALID_TILE; switch (ord->GetType()) { case OT_GOTO_STATION: xy = GetStation(ord->GetDestination())->xy ; break; @@ -851,7 +851,7 @@ public: break; } - if (xy != 0) ScrollMainWindowToTile(xy); + if (xy != INVALID_TILE) ScrollMainWindowToTile(xy); return; } diff --git a/src/town.h b/src/town.h index f7f584b86..0e2b2221b 100644 --- a/src/town.h +++ b/src/town.h @@ -179,12 +179,12 @@ struct Town : PoolItem<Town, TownID, &_Town_pool> { /** * Creates a new town */ - Town(TileIndex tile = 0); + Town(TileIndex tile = INVALID_TILE); /** Destroy the town */ ~Town(); - inline bool IsValid() const { return this->xy != 0; } + inline bool IsValid() const { return this->xy != INVALID_TILE; } void InitializeLayout(); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index e37e331c1..ec318f488 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -65,7 +65,7 @@ DEFINE_OLD_POOL_GENERIC(Town, Town) Town::Town(TileIndex tile) { - if (tile != 0) _total_towns++; + if (tile != INVALID_TILE) _total_towns++; this->xy = tile; } @@ -115,7 +115,7 @@ Town::~Town() MarkWholeScreenDirty(); - this->xy = 0; + this->xy = INVALID_TILE; UpdateNearestTownForRoadTiles(false); } diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 4803e3bf2..c76556170 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -554,7 +554,7 @@ public: while (i < this->towns.Length()) { const Town *t = this->towns[i]; - assert(t->xy); + assert(t->xy != INVALID_TILE); SetDParam(0, t->index); SetDParam(1, t->population); @@ -601,7 +601,7 @@ public: if (id_v >= this->towns.Length()) return; // click out of town bounds const Town *t = this->towns[id_v]; - assert(t->xy); + assert(t->xy != INVALID_TILE); if (_ctrl_pressed) { ShowExtraViewPortWindow(t->xy); } else { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 6f5df3e62..a9133e611 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1037,7 +1037,7 @@ struct VehicleListWindow : public BaseVehicleListWindow { } break; case VLW_WIDGET_AVAILABLE_VEHICLES: - ShowBuildVehicleWindow(0, this->vehicle_type); + ShowBuildVehicleWindow(INVALID_TILE, this->vehicle_type); break; case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN: { diff --git a/src/waypoint.cpp b/src/waypoint.cpp index a08e543c3..81d7d9563 100644 --- a/src/waypoint.cpp +++ b/src/waypoint.cpp @@ -460,7 +460,7 @@ Waypoint::~Waypoint() RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index); RedrawWaypointSign(this); - this->xy = 0; + this->xy = INVALID_TILE; } /** diff --git a/src/waypoint.h b/src/waypoint.h index a4afbba43..8b07bdbac 100644 --- a/src/waypoint.h +++ b/src/waypoint.h @@ -33,10 +33,10 @@ struct Waypoint : PoolItem<Waypoint, WaypointID, &_Waypoint_pool> { byte deleted; ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted. - Waypoint(TileIndex tile = 0); + Waypoint(TileIndex tile = INVALID_TILE); ~Waypoint(); - inline bool IsValid() const { return this->xy != 0; } + inline bool IsValid() const { return this->xy != INVALID_TILE; } }; static inline bool IsValidWaypointID(WaypointID index) |