1
0
Fork 0

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

release/0.7
smatz 2009-01-03 16:06:58 +00:00
parent 21308de6cb
commit 254e19da91
15 changed files with 42 additions and 32 deletions

View File

@ -797,7 +797,7 @@ struct BuildVehicleWindow : Window {
EngineID rename_engine; EngineID rename_engine;
GUIEngineList eng_list; 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; this->vehicle_type = type;
int vlh = GetVehicleListHeight(this->vehicle_type); int vlh = GetVehicleListHeight(this->vehicle_type);
@ -810,7 +810,7 @@ struct BuildVehicleWindow : Window {
this->resize.width = this->width; this->resize.width = this->width;
this->resize.height = this->height; 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->sel_engine = INVALID_ENGINE;
this->regenerate_list = false; this->regenerate_list = false;
@ -821,15 +821,15 @@ struct BuildVehicleWindow : Window {
switch (type) { switch (type) {
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_TRAIN: case VEH_TRAIN:
this->filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile); this->filter.railtype = (tile == INVALID_TILE) ? RAILTYPE_END : GetRailType(tile);
break; break;
case VEH_ROAD: 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: case VEH_SHIP:
break; break;
case VEH_AIRCRAFT: case VEH_AIRCRAFT:
this->filter.flags = this->filter.flags =
tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags; tile == INVALID_TILE ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
break; break;
} }
this->SetupWindowStrings(type); this->SetupWindowStrings(type);
@ -1194,10 +1194,10 @@ static const WindowDesc _build_vehicle_desc = {
void ShowBuildVehicleWindow(TileIndex tile, VehicleType type) void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
{ {
/* We want to be able to open both Available Train as Available Ships, /* 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 * As it always is a low value, it won't collide with any real tile
* number. */ * number. */
uint num = (tile == 0) ? (int)type : tile; uint num = (tile == INVALID_TILE) ? (int)type : tile;
assert(IsCompanyBuildableVehicleType(type)); assert(IsCompanyBuildableVehicleType(type));

View File

@ -43,7 +43,7 @@ Depot::~Depot()
/* Delete the depot-window */ /* Delete the depot-window */
DeleteWindowById(WC_VEHICLE_DEPOT, this->xy); DeleteWindowById(WC_VEHICLE_DEPOT, this->xy);
this->xy = 0; this->xy = INVALID_TILE;
} }
void InitializeDepots() void InitializeDepots()

View File

@ -16,10 +16,10 @@ struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> {
TileIndex xy; TileIndex xy;
TownID town_index; TownID town_index;
Depot(TileIndex xy = 0) : xy(xy) {} Depot(TileIndex xy = INVALID_TILE) : xy(xy) {}
~Depot(); ~Depot();
inline bool IsValid() const { return this->xy != 0; } inline bool IsValid() const { return this->xy != INVALID_TILE; }
}; };
static inline bool IsValidDepotID(DepotID index) static inline bool IsValidDepotID(DepotID index)

View File

@ -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) { if (cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) {
xy = GetTown(s->from)->xy; xy = GetTown(s->from)->xy;
} else { } else {
xy = (GetIndustry(s->from))->xy; xy = GetIndustry(s->from)->xy;
} }
if (DistanceMax(xy, from->xy) > 9) continue; if (DistanceMax(xy, from->xy) > 9) continue;

View File

@ -535,7 +535,7 @@ public:
case GRP_WIDGET_AVAILABLE_VEHICLES: case GRP_WIDGET_AVAILABLE_VEHICLES:
ShowBuildVehicleWindow(0, this->vehicle_type); ShowBuildVehicleWindow(INVALID_TILE, this->vehicle_type);
break; break;
case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN: case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN:

View File

@ -132,10 +132,10 @@ struct Industry : PoolItem<Industry, IndustryID, &_Industry_pool> {
PersistentStorage psa; ///< Persistent storage for NewGRF industries. PersistentStorage psa; ///< Persistent storage for NewGRF industries.
Industry(TileIndex tile = 0) : xy(tile) {} Industry(TileIndex tile = INVALID_TILE) : xy(tile) {}
~Industry(); ~Industry();
inline bool IsValid() const { return this->xy != 0; } inline bool IsValid() const { return this->xy != INVALID_TILE; }
}; };
struct IndustryTileTable { struct IndustryTileTable {

View File

@ -140,7 +140,7 @@ Industry::~Industry()
/* Industry can also be destroyed when not fully initialized. /* Industry can also be destroyed when not fully initialized.
* This means that we do not have to clear tiles either. */ * This means that we do not have to clear tiles either. */
if (this->width == 0) { if (this->width == 0) {
this->xy = 0; this->xy = INVALID_TILE;
return; return;
} }
@ -174,7 +174,7 @@ Industry::~Industry()
DeleteSubsidyWithIndustry(this->index); DeleteSubsidyWithIndustry(this->index);
DeleteWindowById(WC_INDUSTRY_VIEW, this->index); DeleteWindowById(WC_INDUSTRY_VIEW, this->index);
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0); InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0);
this->xy = 0; this->xy = INVALID_TILE;
} }
static void IndustryDrawSugarMine(const TileInfo *ti) static void IndustryDrawSugarMine(const TileInfo *ti)

View File

@ -490,7 +490,12 @@ static const OldChunks town_chunk[] = {
}; };
static bool LoadOldTown(LoadgameState *ls, int num) 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; static uint16 _old_order;
@ -545,10 +550,13 @@ static const OldChunks depot_chunk[] = {
static bool LoadOldDepot(LoadgameState *ls, int num) 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); GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index);
} else {
d->xy = INVALID_TILE;
} }
return true; return true;
@ -732,9 +740,11 @@ static bool LoadOldIndustry(LoadgameState *ls, int num)
Industry *i = new (num) Industry(); Industry *i = new (num) Industry();
if (!LoadChunk(ls, i, industry_chunk)) return false; if (!LoadChunk(ls, i, industry_chunk)) return false;
if (i->IsValid()) { if (i->xy != 0) {
i->town = GetTown(REMAP_TOWN_IDX(_old_town_index)); i->town = GetTown(REMAP_TOWN_IDX(_old_town_index));
IncIndustryTypeCount(i->type); IncIndustryTypeCount(i->type);
} else {
i->xy = INVALID_TILE;
} }
return true; return true;

View File

@ -838,7 +838,7 @@ public:
if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) { if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
const Order *ord = GetVehicleOrder(this->vehicle, sel); const Order *ord = GetVehicleOrder(this->vehicle, sel);
TileIndex xy = 0; TileIndex xy = INVALID_TILE;
switch (ord->GetType()) { switch (ord->GetType()) {
case OT_GOTO_STATION: xy = GetStation(ord->GetDestination())->xy ; break; case OT_GOTO_STATION: xy = GetStation(ord->GetDestination())->xy ; break;
@ -851,7 +851,7 @@ public:
break; break;
} }
if (xy != 0) ScrollMainWindowToTile(xy); if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
return; return;
} }

View File

@ -179,12 +179,12 @@ struct Town : PoolItem<Town, TownID, &_Town_pool> {
/** /**
* Creates a new town * Creates a new town
*/ */
Town(TileIndex tile = 0); Town(TileIndex tile = INVALID_TILE);
/** Destroy the town */ /** Destroy the town */
~Town(); ~Town();
inline bool IsValid() const { return this->xy != 0; } inline bool IsValid() const { return this->xy != INVALID_TILE; }
void InitializeLayout(); void InitializeLayout();

View File

@ -65,7 +65,7 @@ DEFINE_OLD_POOL_GENERIC(Town, Town)
Town::Town(TileIndex tile) Town::Town(TileIndex tile)
{ {
if (tile != 0) _total_towns++; if (tile != INVALID_TILE) _total_towns++;
this->xy = tile; this->xy = tile;
} }
@ -115,7 +115,7 @@ Town::~Town()
MarkWholeScreenDirty(); MarkWholeScreenDirty();
this->xy = 0; this->xy = INVALID_TILE;
UpdateNearestTownForRoadTiles(false); UpdateNearestTownForRoadTiles(false);
} }

View File

@ -554,7 +554,7 @@ public:
while (i < this->towns.Length()) { while (i < this->towns.Length()) {
const Town *t = this->towns[i]; const Town *t = this->towns[i];
assert(t->xy); assert(t->xy != INVALID_TILE);
SetDParam(0, t->index); SetDParam(0, t->index);
SetDParam(1, t->population); SetDParam(1, t->population);
@ -601,7 +601,7 @@ public:
if (id_v >= this->towns.Length()) return; // click out of town bounds if (id_v >= this->towns.Length()) return; // click out of town bounds
const Town *t = this->towns[id_v]; const Town *t = this->towns[id_v];
assert(t->xy); assert(t->xy != INVALID_TILE);
if (_ctrl_pressed) { if (_ctrl_pressed) {
ShowExtraViewPortWindow(t->xy); ShowExtraViewPortWindow(t->xy);
} else { } else {

View File

@ -1037,7 +1037,7 @@ struct VehicleListWindow : public BaseVehicleListWindow {
} break; } break;
case VLW_WIDGET_AVAILABLE_VEHICLES: case VLW_WIDGET_AVAILABLE_VEHICLES:
ShowBuildVehicleWindow(0, this->vehicle_type); ShowBuildVehicleWindow(INVALID_TILE, this->vehicle_type);
break; break;
case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN: { case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN: {

View File

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

View File

@ -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. 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(); ~Waypoint();
inline bool IsValid() const { return this->xy != 0; } inline bool IsValid() const { return this->xy != INVALID_TILE; }
}; };
static inline bool IsValidWaypointID(WaypointID index) static inline bool IsValidWaypointID(WaypointID index)