(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.
This commit is contained in:
@@ -142,9 +142,9 @@ 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) 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 (GetIndustryIndex(tile_cur) == this->index) {
|
||||
/* MakeWaterKeepingClass() can also handle 'land' */
|
||||
@@ -163,7 +163,7 @@ Industry::~Industry()
|
||||
|
||||
if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
|
||||
/* 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);
|
||||
if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
|
||||
GetIndustryIndexOfField(tile_cur) == this->index) {
|
||||
@@ -509,7 +509,7 @@ static void TransportIndustryGoods(TileIndex tile)
|
||||
const IndustrySpec *indspec = GetIndustrySpec(i->type);
|
||||
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++) {
|
||||
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)
|
||||
{
|
||||
int x = i->width / 2 + Random() % 31 - 16;
|
||||
int y = i->height / 2 + Random() % 31 - 16;
|
||||
int x = i->location.w / 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);
|
||||
}
|
||||
@@ -1082,7 +1082,7 @@ static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
|
||||
*/
|
||||
static void ChopLumberMillTrees(Industry *i)
|
||||
{
|
||||
TileIndex tile = i->xy;
|
||||
TileIndex tile = i->location.tile;
|
||||
|
||||
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) {
|
||||
SndPlayTileFx(
|
||||
(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) {
|
||||
bool plant;
|
||||
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 {
|
||||
plant = Chance16(1, 8);
|
||||
}
|
||||
@@ -1128,7 +1128,7 @@ static void ProduceIndustryGoods(Industry *i)
|
||||
if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) {
|
||||
bool cut = ((i->counter & 0x1FF) == 0);
|
||||
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);
|
||||
@@ -1499,7 +1499,7 @@ static bool CheckIfFarEnoughFromIndustry(TileIndex tile, int type)
|
||||
|
||||
FOR_ALL_INDUSTRIES(i) {
|
||||
/* 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 */
|
||||
if (in_low_distance &&
|
||||
@@ -1541,8 +1541,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
|
||||
uint32 r;
|
||||
uint j;
|
||||
|
||||
i->xy = tile;
|
||||
i->width = i->height = 0;
|
||||
i->location = TileArea(tile, 1, 1);
|
||||
i->type = 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);
|
||||
|
||||
if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
|
||||
byte size;
|
||||
|
||||
size = it->ti.x;
|
||||
if (size > i->width) i->width = size;
|
||||
size = it->ti.y;
|
||||
if (size > i->height)i->height = size;
|
||||
i->location.Add(cur_tile);
|
||||
|
||||
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);
|
||||
|
||||
i->width++;
|
||||
i->height++;
|
||||
|
||||
if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
|
||||
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)) {
|
||||
uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
|
||||
0, GetReverseCargoTranslation(cargo, indspec->grf_prop.grffile),
|
||||
ind, ind->type, ind->xy);
|
||||
ind, ind->type, ind->location.tile);
|
||||
if (res == 0) continue;
|
||||
}
|
||||
*c_accepts = true;
|
||||
@@ -2066,7 +2057,7 @@ static int WhoCanServiceIndustry(Industry *ind)
|
||||
{
|
||||
/* Find all stations within reach of the industry */
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
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"
|
||||
suppress_message = HasBit(res, 7);
|
||||
/* Get the custom message if any */
|
||||
@@ -2343,7 +2334,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
|
||||
AddNewsItem(str,
|
||||
ns,
|
||||
closeit ? NR_TILE : NR_INDUSTRY,
|
||||
closeit ? i->xy + TileDiffXY(1, 1) : i->index);
|
||||
closeit ? i->location.tile + TileDiffXY(1, 1) : i->index);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user