(svn r14807) -Codechange: use INVALID_TILE instead of 0 to mark invalid depots, industries, towns and waypoints

pull/155/head
smatz 16 years ago
parent 7a2adef859
commit b00e510140

@ -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));

@ -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()

@ -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)

@ -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;

@ -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:

@ -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 {

@ -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)

@ -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;

@ -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;
}

@ -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();

@ -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);
}

@ -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 {

@ -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: {

@ -460,7 +460,7 @@ Waypoint::~Waypoint()
RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
RedrawWaypointSign(this);
this->xy = 0;
this->xy = INVALID_TILE;
}
/**

@ -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)

Loading…
Cancel
Save