1
0
Fork 0

(svn r18717) -Codechange: use TileArea in industry instead of three separate variables. Also make use of TileArea functions for determining the 'width' and 'height' of an industry.

release/1.0
rubidium 2010-01-04 18:21:07 +00:00
parent 71f2789270
commit 87466a4ed0
14 changed files with 71 additions and 81 deletions

View File

@ -115,7 +115,7 @@
{ {
if (!IsValidIndustry(industry_id)) return INVALID_TILE; if (!IsValidIndustry(industry_id)) return INVALID_TILE;
return ::Industry::Get(industry_id)->xy; return ::Industry::Get(industry_id)->location.tile;
} }
/* static */ int32 AIIndustry::GetAmountOfStationsAround(IndustryID industry_id) /* static */ int32 AIIndustry::GetAmountOfStationsAround(IndustryID industry_id)
@ -124,7 +124,7 @@
Industry *ind = ::Industry::Get(industry_id); Industry *ind = ::Industry::Get(industry_id);
StationList stations; StationList stations;
::FindStationsAroundTiles(TileArea(ind->xy, ind->width, ind->height), &stations); ::FindStationsAroundTiles(ind->location, &stations);
return (int32)stations.Length(); return (int32)stations.Length();
} }
@ -162,7 +162,7 @@
if (!HasHeliport(industry_id)) return INVALID_TILE; if (!HasHeliport(industry_id)) return INVALID_TILE;
const Industry *ind = ::Industry::Get(industry_id); const Industry *ind = ::Industry::Get(industry_id);
TILE_LOOP(tile_cur, ind->width, ind->height, ind->xy) { TILE_LOOP(tile_cur, ind->location.w, ind->location.h, ind->location.tile) {
if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
return tile_cur; return tile_cur;
} }
@ -184,7 +184,7 @@
if (!HasDock(industry_id)) return INVALID_TILE; if (!HasDock(industry_id)) return INVALID_TILE;
const Industry *ind = ::Industry::Get(industry_id); const Industry *ind = ::Industry::Get(industry_id);
TILE_LOOP(tile_cur, ind->width, ind->height, ind->xy) { TILE_LOOP(tile_cur, ind->location.w, ind->location.h, ind->location.tile) {
if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
return tile_cur; return tile_cur;
} }

View File

@ -86,7 +86,7 @@ AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_i
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED; if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;
TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) { TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h+ radius * 2, i->location.tile - ::TileDiffXY(radius, radius)) {
if (!::IsValidTile(cur_tile)) continue; if (!::IsValidTile(cur_tile)) continue;
/* Exclude all tiles that belong to this industry */ /* Exclude all tiles that belong to this industry */
if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue; if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue;
@ -123,7 +123,7 @@ AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_i
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED; if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;
TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) { TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h+ radius * 2, i->location.tile - ::TileDiffXY(radius, radius)) {
if (!::IsValidTile(cur_tile)) continue; if (!::IsValidTile(cur_tile)) continue;
/* Exclude all tiles that belong to this industry */ /* Exclude all tiles that belong to this industry */
if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue; if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue;

View File

@ -401,8 +401,8 @@ static bool DisasterTick_Aircraft(DisasterVehicle *v, uint16 image_override, boo
if (v->current_order.GetDestination() == 2) { if (v->current_order.GetDestination() == 2) {
if (GB(v->tick_counter, 0, 2) == 0) { if (GB(v->tick_counter, 0, 2) == 0) {
Industry *i = Industry::Get(v->dest_tile); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid Industry *i = Industry::Get(v->dest_tile); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid
int x = TileX(i->xy) * TILE_SIZE; int x = TileX(i->location.tile) * TILE_SIZE;
int y = TileY(i->xy) * TILE_SIZE; int y = TileY(i->location.tile) * TILE_SIZE;
uint32 r = Random(); uint32 r = Random();
CreateEffectVehicleAbove( CreateEffectVehicleAbove(
@ -423,7 +423,7 @@ static bool DisasterTick_Aircraft(DisasterVehicle *v, uint16 image_override, boo
SetDParam(0, i->town->index); SetDParam(0, i->town->index);
AddIndustryNewsItem(news_message, NS_ACCIDENT, i->index); // delete the news, when the industry closes AddIndustryNewsItem(news_message, NS_ACCIDENT, i->index); // delete the news, when the industry closes
SndPlayTileFx(SND_12_EXPLOSION, i->xy); SndPlayTileFx(SND_12_EXPLOSION, i->location.tile);
} }
} else if (v->current_order.GetDestination() == 0) { } else if (v->current_order.GetDestination() == 0) {
int x = v->x_pos - (15 * TILE_SIZE); int x = v->x_pos - (15 * TILE_SIZE);
@ -742,7 +742,7 @@ static void Disaster_Airplane_Init()
/* Start from the bottom (south side) of the map */ /* Start from the bottom (south side) of the map */
int x = (MapSizeX() + 9) * TILE_SIZE - 1; int x = (MapSizeX() + 9) * TILE_SIZE - 1;
int y = TileY(found->xy) * TILE_SIZE + 37; int y = TileY(found->location.tile) * TILE_SIZE + 37;
InitializeDisasterVehicle(v, x, y, 135, DIR_NE, ST_AIRPLANE); InitializeDisasterVehicle(v, x, y, 135, DIR_NE, ST_AIRPLANE);
@ -772,7 +772,7 @@ static void Disaster_Helicopter_Init()
DisasterVehicle *v = new DisasterVehicle(); DisasterVehicle *v = new DisasterVehicle();
int x = -16 * TILE_SIZE; int x = -16 * TILE_SIZE;
int y = TileY(found->xy) * TILE_SIZE + 37; int y = TileY(found->location.tile) * TILE_SIZE + 37;
InitializeDisasterVehicle(v, x, y, 135, DIR_SW, ST_HELICOPTER); InitializeDisasterVehicle(v, x, y, 135, DIR_SW, ST_HELICOPTER);
@ -861,10 +861,10 @@ static void Disaster_CoalMine_Init()
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) { if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) {
SetDParam(0, i->town->index); SetDParam(0, i->town->index);
AddNewsItem(STR_NEWS_DISASTER_COAL_MINE_SUBSIDENCE, AddNewsItem(STR_NEWS_DISASTER_COAL_MINE_SUBSIDENCE,
NS_ACCIDENT, NR_TILE, i->xy + TileDiffXY(1, 1)); // keep the news, even when the mine closes NS_ACCIDENT, NR_TILE, i->location.tile + TileDiffXY(1, 1)); // keep the news, even when the mine closes
{ {
TileIndex tile = i->xy; TileIndex tile = i->location.tile;
TileIndexDiff step = TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2)); TileIndexDiff step = TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2));
for (uint n = 0; n < 30; n++) { for (uint n = 0; n < 30; n++) {

View File

@ -896,7 +896,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
/* Check if industry temporarily refuses acceptance */ /* Check if industry temporarily refuses acceptance */
if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) { if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) {
uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile), ind, ind->type, ind->xy); uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile), ind, ind->type, ind->location.tile);
if (res == 0) continue; if (res == 0) continue;
} }

View File

@ -22,6 +22,7 @@
#include "tile_type.h" #include "tile_type.h"
#include "subsidy_type.h" #include "subsidy_type.h"
#include "industry_map.h" #include "industry_map.h"
#include "tilearea_type.h"
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool; typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
@ -33,9 +34,7 @@ extern IndustryPool _industry_pool;
struct Industry : IndustryPool::PoolItem<&_industry_pool> { struct Industry : IndustryPool::PoolItem<&_industry_pool> {
typedef PersistentStorageArray<uint32, 16> PersistentStorage; typedef PersistentStorageArray<uint32, 16> PersistentStorage;
TileIndex xy; ///< coordinates of the primary tile the industry is built one TileArea location; ///< Location of the industry
byte width;
byte height;
const Town *town; ///< Nearest town const Town *town; ///< Nearest town
CargoID produced_cargo[2]; ///< 2 production cargo slots CargoID produced_cargo[2]; ///< 2 production cargo slots
uint16 produced_cargo_waiting[2]; ///< amount of cargo produced per cargo uint16 produced_cargo_waiting[2]; ///< amount of cargo produced per cargo
@ -69,7 +68,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
PersistentStorage psa; ///< Persistent storage for NewGRF industries. PersistentStorage psa; ///< Persistent storage for NewGRF industries.
Industry(TileIndex tile = INVALID_TILE) : xy(tile) {} Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
~Industry(); ~Industry();
/** /**

View File

@ -142,9 +142,9 @@ 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) return; if (this->location.w == 0) return;
TILE_LOOP(tile_cur, this->width, this->height, this->xy) { TILE_LOOP(tile_cur, this->location.w, this->location.h, this->location.tile) {
if (IsTileType(tile_cur, MP_INDUSTRY)) { if (IsTileType(tile_cur, MP_INDUSTRY)) {
if (GetIndustryIndex(tile_cur) == this->index) { if (GetIndustryIndex(tile_cur) == this->index) {
/* MakeWaterKeepingClass() can also handle 'land' */ /* MakeWaterKeepingClass() can also handle 'land' */
@ -163,7 +163,7 @@ Industry::~Industry()
if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) { if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
/* Remove the farmland and convert it to regular tiles over time. */ /* Remove the farmland and convert it to regular tiles over time. */
TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiffXY(21, 21)) { TILE_LOOP(tile_cur, 42, 42, this->location.tile - TileDiffXY(21, 21)) {
tile_cur = TILE_MASK(tile_cur); tile_cur = TILE_MASK(tile_cur);
if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) && if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
GetIndustryIndexOfField(tile_cur) == this->index) { GetIndustryIndexOfField(tile_cur) == this->index) {
@ -509,7 +509,7 @@ static void TransportIndustryGoods(TileIndex tile)
const IndustrySpec *indspec = GetIndustrySpec(i->type); const IndustrySpec *indspec = GetIndustrySpec(i->type);
bool moved_cargo = false; bool moved_cargo = false;
StationFinder stations(TileArea(i->xy, i->width, i->height)); StationFinder stations(i->location);
for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) { for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
uint cw = min(i->produced_cargo_waiting[j], 255); uint cw = min(i->produced_cargo_waiting[j], 255);
@ -1043,10 +1043,10 @@ static void PlantFarmField(TileIndex tile, IndustryID industry)
void PlantRandomFarmField(const Industry *i) void PlantRandomFarmField(const Industry *i)
{ {
int x = i->width / 2 + Random() % 31 - 16; int x = i->location.w / 2 + Random() % 31 - 16;
int y = i->height / 2 + Random() % 31 - 16; int y = i->location.h / 2 + Random() % 31 - 16;
TileIndex tile = TileAddWrap(i->xy, x, y); TileIndex tile = TileAddWrap(i->location.tile, x, y);
if (tile != INVALID_TILE) PlantFarmField(tile, i->index); if (tile != INVALID_TILE) PlantFarmField(tile, i->index);
} }
@ -1082,7 +1082,7 @@ static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
*/ */
static void ChopLumberMillTrees(Industry *i) static void ChopLumberMillTrees(Industry *i)
{ {
TileIndex tile = i->xy; TileIndex tile = i->location.tile;
if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed
@ -1101,7 +1101,7 @@ static void ProduceIndustryGoods(Industry *i)
if (Chance16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) { if (Chance16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) {
SndPlayTileFx( SndPlayTileFx(
(SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]), (SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]),
i->xy); i->location.tile);
} }
} }
@ -1118,7 +1118,7 @@ static void ProduceIndustryGoods(Industry *i)
if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) { if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
bool plant; bool plant;
if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) { if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) {
plant = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->xy) != 0); plant = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->location.tile) != 0);
} else { } else {
plant = Chance16(1, 8); plant = Chance16(1, 8);
} }
@ -1128,7 +1128,7 @@ static void ProduceIndustryGoods(Industry *i)
if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) { if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) {
bool cut = ((i->counter & 0x1FF) == 0); bool cut = ((i->counter & 0x1FF) == 0);
if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) { if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) {
cut = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, 0, 1, i, i->type, i->xy) != 0); cut = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, 0, 1, i, i->type, i->location.tile) != 0);
} }
if (cut) ChopLumberMillTrees(i); if (cut) ChopLumberMillTrees(i);
@ -1499,7 +1499,7 @@ static bool CheckIfFarEnoughFromIndustry(TileIndex tile, int type)
FOR_ALL_INDUSTRIES(i) { FOR_ALL_INDUSTRIES(i) {
/* Within 14 tiles from another industry is considered close */ /* Within 14 tiles from another industry is considered close */
bool in_low_distance = DistanceMax(tile, i->xy) <= 14; bool in_low_distance = DistanceMax(tile, i->location.tile) <= 14;
/* check if an industry that accepts the same goods is nearby */ /* check if an industry that accepts the same goods is nearby */
if (in_low_distance && if (in_low_distance &&
@ -1541,8 +1541,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
uint32 r; uint32 r;
uint j; uint j;
i->xy = tile; i->location = TileArea(tile, 1, 1);
i->width = i->height = 0;
i->type = type; i->type = type;
IncIndustryTypeCount(type); IncIndustryTypeCount(type);
@ -1629,12 +1628,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
if (it->gfx != GFX_WATERTILE_SPECIALCHECK) { if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
byte size; i->location.Add(cur_tile);
size = it->ti.x;
if (size > i->width) i->width = size;
size = it->ti.y;
if (size > i->height)i->height = size;
WaterClass wc = (IsWaterTile(cur_tile) ? GetWaterClass(cur_tile) : WATER_CLASS_INVALID); WaterClass wc = (IsWaterTile(cur_tile) ? GetWaterClass(cur_tile) : WATER_CLASS_INVALID);
@ -1654,9 +1648,6 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
} }
} while ((++it)->ti.x != -0x80); } while ((++it)->ti.x != -0x80);
i->width++;
i->height++;
if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) { if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
for (j = 0; j != 50; j++) PlantRandomFarmField(i); for (j = 0; j != 50; j++) PlantRandomFarmField(i);
} }
@ -2031,7 +2022,7 @@ static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accept
if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) { if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) {
uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
0, GetReverseCargoTranslation(cargo, indspec->grf_prop.grffile), 0, GetReverseCargoTranslation(cargo, indspec->grf_prop.grffile),
ind, ind->type, ind->xy); ind, ind->type, ind->location.tile);
if (res == 0) continue; if (res == 0) continue;
} }
*c_accepts = true; *c_accepts = true;
@ -2066,7 +2057,7 @@ static int WhoCanServiceIndustry(Industry *ind)
{ {
/* Find all stations within reach of the industry */ /* Find all stations within reach of the industry */
StationList stations; StationList stations;
FindStationsAroundTiles(TileArea(ind->xy, ind->width, ind->height), &stations); FindStationsAroundTiles(ind->location, &stations);
if (stations.Length() == 0) return 0; // No stations found at all => nobody services if (stations.Length() == 0) return 0; // No stations found at all => nobody services
@ -2168,7 +2159,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
bool callback_enabled = HasBit(indspec->callback_mask, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE); bool callback_enabled = HasBit(indspec->callback_mask, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE);
if (callback_enabled) { if (callback_enabled) {
uint16 res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->xy); uint16 res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->location.tile);
if (res != CALLBACK_FAILED) { // failed callback means "do nothing" if (res != CALLBACK_FAILED) { // failed callback means "do nothing"
suppress_message = HasBit(res, 7); suppress_message = HasBit(res, 7);
/* Get the custom message if any */ /* Get the custom message if any */
@ -2343,7 +2334,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
AddNewsItem(str, AddNewsItem(str,
ns, ns,
closeit ? NR_TILE : NR_INDUSTRY, closeit ? NR_TILE : NR_INDUSTRY,
closeit ? i->xy + TileDiffXY(1, 1) : i->index); closeit ? i->location.tile + TileDiffXY(1, 1) : i->index);
} }
} }

View File

@ -63,7 +63,7 @@ static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind,
{ {
suffix[0] = '\0'; suffix[0] = '\0';
if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) { if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) {
uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, (cst != CST_FUND) ? ind->xy : INVALID_TILE); uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, (cst != CST_FUND) ? ind->location.tile : INVALID_TILE);
if (GB(callback, 0, 8) != 0xFF) { if (GB(callback, 0, 8) != 0xFF) {
PrepareTextRefStackUsage(6); PrepareTextRefStackUsage(6);
GetString(suffix, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), suffix_last); GetString(suffix, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), suffix_last);
@ -580,7 +580,7 @@ public:
this->InitNested(desc, window_number); this->InitNested(desc, window_number);
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(IVW_VIEWPORT); NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(IVW_VIEWPORT);
nvp->InitializeViewport(this, Industry::Get(window_number)->xy + TileDiffXY(1, 1), ZOOM_LVL_INDUSTRY); nvp->InitializeViewport(this, Industry::Get(window_number)->location.tile + TileDiffXY(1, 1), ZOOM_LVL_INDUSTRY);
} }
virtual void OnPaint() virtual void OnPaint()
@ -674,7 +674,7 @@ public:
/* Get the extra message for the GUI */ /* Get the extra message for the GUI */
if (HasBit(ind->callback_mask, CBM_IND_WINDOW_MORE_TEXT)) { if (HasBit(ind->callback_mask, CBM_IND_WINDOW_MORE_TEXT)) {
uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->xy); uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->location.tile);
if (callback_res != CALLBACK_FAILED) { if (callback_res != CALLBACK_FAILED) {
StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res); StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
if (message != STR_NULL && message != STR_UNDEFINED) { if (message != STR_NULL && message != STR_UNDEFINED) {
@ -747,9 +747,9 @@ public:
case IVW_GOTO: case IVW_GOTO:
i = Industry::Get(this->window_number); i = Industry::Get(this->window_number);
if (_ctrl_pressed) { if (_ctrl_pressed) {
ShowExtraViewPortWindow(i->xy + TileDiffXY(1, 1)); ShowExtraViewPortWindow(i->location.tile + TileDiffXY(1, 1));
} else { } else {
ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1)); ScrollMainWindowToTile(i->location.tile + TileDiffXY(1, 1));
} }
break; break;
} }
@ -1124,9 +1124,9 @@ public:
p = y + this->vscroll.GetPosition(); p = y + this->vscroll.GetPosition();
if (p < this->industries.Length()) { if (p < this->industries.Length()) {
if (_ctrl_pressed) { if (_ctrl_pressed) {
ShowExtraViewPortWindow(this->industries[p]->xy); ShowExtraViewPortWindow(this->industries[p]->location.tile);
} else { } else {
ScrollMainWindowToTile(this->industries[p]->xy); ScrollMainWindowToTile(this->industries[p]->location.tile);
} }
} }
} break; } break;

View File

@ -92,7 +92,7 @@ static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Indust
FOR_ALL_INDUSTRIES(i) { FOR_ALL_INDUSTRIES(i) {
if (i->type != type || i == current) continue; if (i->type != type || i == current) continue;
best_dist = min(best_dist, DistanceManhattan(tile, i->xy)); best_dist = min(best_dist, DistanceManhattan(tile, i->location.tile));
} }
return best_dist; return best_dist;
@ -132,7 +132,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
if (layout_filter == 0) { if (layout_filter == 0) {
/* If the filter is 0, it could be because none was specified as well as being really a 0. /* If the filter is 0, it could be because none was specified as well as being really a 0.
* In either case, just do the regular var67 */ * In either case, just do the regular var67 */
closest_dist = GetClosestIndustry(current->xy, ind_index, current); closest_dist = GetClosestIndustry(current->location.tile, ind_index, current);
count = GetIndustryTypeCount(ind_index); count = GetIndustryTypeCount(ind_index);
} else { } else {
/* Count only those who match the same industry type and layout filter /* Count only those who match the same industry type and layout filter
@ -140,7 +140,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
const Industry *i; const Industry *i;
FOR_ALL_INDUSTRIES(i) { FOR_ALL_INDUSTRIES(i) {
if (i->type == ind_index && i != current && i->selected_layout == layout_filter) { if (i->type == ind_index && i != current && i->selected_layout == layout_filter) {
closest_dist = min(closest_dist, DistanceManhattan(current->xy, i->xy)); closest_dist = min(closest_dist, DistanceManhattan(current->location.tile, i->location.tile));
count++; count++;
} }
} }
@ -235,7 +235,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
case 0x46: return industry->construction_date; // Date when built - long format - (in days) case 0x46: return industry->construction_date; // Date when built - long format - (in days)
/* Get industry ID at offset param */ /* Get industry ID at offset param */
case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), industry); case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->location.tile), industry);
/* Get random tile bits at offset param */ /* Get random tile bits at offset param */
case 0x61: case 0x61:
@ -269,15 +269,15 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
case 0x7C: return industry->psa.Get(parameter); case 0x7C: return industry->psa.Get(parameter);
/* Industry structure access*/ /* Industry structure access*/
case 0x80: return industry->xy; case 0x80: return industry->location.tile;
case 0x81: return GB(industry->xy, 8, 8); case 0x81: return GB(industry->location.tile, 8, 8);
/* Pointer to the town the industry is associated with */ /* Pointer to the town the industry is associated with */
case 0x82: return industry->town->index; case 0x82: return industry->town->index;
case 0x83: case 0x83:
case 0x84: case 0x84:
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
case 0x86: return industry->width; case 0x86: return industry->location.w;
case 0x87: return industry->height;// xy dimensions case 0x87: return industry->location.h;// xy dimensions
case 0x88: case 0x88:
case 0x89: return industry->produced_cargo[variable - 0x88]; case 0x89: return industry->produced_cargo[variable - 0x88];
@ -455,8 +455,8 @@ bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspe
Industry ind; Industry ind;
ind.index = INVALID_INDUSTRY; ind.index = INVALID_INDUSTRY;
ind.xy = tile; ind.location.tile = tile;
ind.width = 0; ind.location.w = 0;
ind.type = type; ind.type = type;
ind.selected_layout = itspec_index; ind.selected_layout = itspec_index;
ind.town = ClosestTownFromTile(tile, UINT_MAX); ind.town = ClosestTownFromTile(tile, UINT_MAX);
@ -516,7 +516,7 @@ void IndustryProductionCallback(Industry *ind, int reason)
{ {
const IndustrySpec *spec = GetIndustrySpec(ind->type); const IndustrySpec *spec = GetIndustrySpec(ind->type);
ResolverObject object; ResolverObject object;
NewIndustryResolver(&object, ind->xy, ind, ind->type); NewIndustryResolver(&object, ind->location.tile, ind, ind->type);
if ((spec->behaviour & INDUSTRYBEH_PRODCALLBACK_RANDOM) != 0) object.callback_param1 = Random(); if ((spec->behaviour & INDUSTRYBEH_PRODCALLBACK_RANDOM) != 0) object.callback_param1 = Random();
int multiplier = 1; int multiplier = 1;
if ((spec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) multiplier = ind->prod_level; if ((spec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) multiplier = ind->prod_level;

View File

@ -86,7 +86,7 @@ static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variabl
case 0x42: return GetTownRadiusGroup(ClosestTownFromTile(tile, UINT_MAX), tile); case 0x42: return GetTownRadiusGroup(ClosestTownFromTile(tile, UINT_MAX), tile);
/* Relative position */ /* Relative position */
case 0x43: return GetRelativePosition(tile, inds->xy); case 0x43: return GetRelativePosition(tile, inds->location.tile);
/* Animation frame. Like house variable 46 but can contain anything 0..FF. */ /* Animation frame. Like house variable 46 but can contain anything 0..FF. */
case 0x44: return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryAnimationState(tile) : 0; case 0x44: return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryAnimationState(tile) : 0;
@ -271,8 +271,8 @@ bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile,
{ {
Industry ind; Industry ind;
ind.index = INVALID_INDUSTRY; ind.index = INVALID_INDUSTRY;
ind.xy = ind_base_tile; ind.location.tile = ind_base_tile;
ind.width = 0; ind.location.w = 0;
ind.type = type; ind.type = type;
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile); uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile);
@ -396,7 +396,7 @@ bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigge
{ {
bool ret = true; bool ret = true;
uint32 random = Random(); uint32 random = Random();
TILE_LOOP(tile, ind->width, ind->height, ind->xy) { TILE_LOOP(tile, ind->location.w, ind->location.h, ind->location.tile) {
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) {
if (StartStopIndustryTileAnimation(tile, iat, random)) { if (StartStopIndustryTileAnimation(tile, iat, random)) {
SB(random, 0, 16, Random()); SB(random, 0, 16, Random());
@ -441,7 +441,7 @@ void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger) void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
{ {
TILE_LOOP(tile, ind->width, ind->height, ind->xy) { TILE_LOOP(tile, ind->location.w, ind->location.h, ind->location.tile) {
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) {
DoTriggerIndustryTile(tile, trigger, ind); DoTriggerIndustryTile(tile, trigger, ind);
} }

View File

@ -63,7 +63,7 @@ static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
switch (reftype) { switch (reftype) {
case NR_TILE: return (TileIndex)ref; case NR_TILE: return (TileIndex)ref;
case NR_STATION: return Station::Get((StationID)ref)->xy; case NR_STATION: return Station::Get((StationID)ref)->xy;
case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->xy + TileDiffXY(1, 1); case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
case NR_TOWN: return Town::Get((TownID)ref)->xy; case NR_TOWN: return Town::Get((TownID)ref)->xy;
default: return INVALID_TILE; default: return INVALID_TILE;
} }

View File

@ -17,10 +17,10 @@
#include "saveload.h" #include "saveload.h"
static const SaveLoad _industry_desc[] = { static const SaveLoad _industry_desc[] = {
SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), SLE_CONDVAR(Industry, location.tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, SL_MAX_VERSION), SLE_CONDVAR(Industry, location.tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_VAR(Industry, width, SLE_UINT8), SLE_VAR(Industry, location.w, SLE_UINT8),
SLE_VAR(Industry, height, SLE_UINT8), SLE_VAR(Industry, location.h, SLE_UINT8),
SLE_REF(Industry, town, REF_TOWN), SLE_REF(Industry, town, REF_TOWN),
SLE_CONDNULL( 2, 0, 60), ///< used to be industry's produced_cargo SLE_CONDNULL( 2, 0, 60), ///< used to be industry's produced_cargo
SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 2, 78, SL_MAX_VERSION), SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 2, 78, SL_MAX_VERSION),

View File

@ -776,10 +776,10 @@ static bool LoadOldStation(LoadgameState *ls, int num)
} }
static const OldChunks industry_chunk[] = { static const OldChunks industry_chunk[] = {
OCL_SVAR( OC_TILE, Industry, xy ), OCL_SVAR( OC_TILE, Industry, location.tile ),
OCL_VAR ( OC_UINT32, 1, &_old_town_index ), OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
OCL_SVAR( OC_UINT8, Industry, width ), OCL_SVAR( OC_UINT8, Industry, location.w ),
OCL_SVAR( OC_UINT8, Industry, height ), OCL_SVAR( OC_UINT8, Industry, location.h ),
OCL_NULL( 2 ), ///< used to be industry's produced_cargo OCL_NULL( 2 ), ///< used to be industry's produced_cargo
OCL_SVAR( OC_TTD | OC_UINT16, Industry, produced_cargo_waiting[0] ), OCL_SVAR( OC_TTD | OC_UINT16, Industry, produced_cargo_waiting[0] ),
@ -825,7 +825,7 @@ 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->xy != 0) { if (i->location.tile != 0) {
i->town = Town::Get(RemapTownIndex(_old_town_index)); i->town = Town::Get(RemapTownIndex(_old_town_index));
if (_savegame_type == SGT_TTO) { if (_savegame_type == SGT_TTO) {

View File

@ -236,7 +236,7 @@ static Subsidy *FindSubsidyCargoRoute()
/* Only want big towns */ /* Only want big towns */
if (t->population < SUBSIDY_CARGO_MIN_POPULATION) return NULL; if (t->population < SUBSIDY_CARGO_MIN_POPULATION) return NULL;
if (DistanceManhattan(i->xy, t->xy) > SUBSIDY_MAX_DISTANCE) return NULL; if (DistanceManhattan(i->location.tile, t->xy) > SUBSIDY_MAX_DISTANCE) return NULL;
dst = t->index; dst = t->index;
} else { } else {
@ -252,7 +252,7 @@ static Subsidy *FindSubsidyCargoRoute()
return NULL; return NULL;
} }
if (DistanceManhattan(i->xy, i2->xy) > SUBSIDY_MAX_DISTANCE) return NULL; if (DistanceManhattan(i->location.tile, i2->location.tile) > SUBSIDY_MAX_DISTANCE) return NULL;
dst = i2->index; dst = i2->index;
} }

View File

@ -83,7 +83,7 @@ struct SubsidyListWindow : Window {
/* determine src coordinate for subsidy and try to scroll to it */ /* determine src coordinate for subsidy and try to scroll to it */
TileIndex xy; TileIndex xy;
switch (s->src_type) { switch (s->src_type) {
case ST_INDUSTRY: xy = Industry::Get(s->src)->xy; break; case ST_INDUSTRY: xy = Industry::Get(s->src)->location.tile; break;
case ST_TOWN: xy = Town::Get(s->src)->xy; break; case ST_TOWN: xy = Town::Get(s->src)->xy; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
@ -93,7 +93,7 @@ struct SubsidyListWindow : Window {
/* otherwise determine dst coordinate for subsidy and scroll to it */ /* otherwise determine dst coordinate for subsidy and scroll to it */
switch (s->dst_type) { switch (s->dst_type) {
case ST_INDUSTRY: xy = Industry::Get(s->dst)->xy; break; case ST_INDUSTRY: xy = Industry::Get(s->dst)->location.tile; break;
case ST_TOWN: xy = Town::Get(s->dst)->xy; break; case ST_TOWN: xy = Town::Get(s->dst)->xy; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }