Fix: do not hide parameter by local variable with the same name

pull/332/head
rubidium42 3 years ago committed by rubidium42
parent eaa3df1e8e
commit b791ffc6de

@ -16,14 +16,14 @@
#include <utility> #include <utility>
template <typename SetPixelT> template <typename SetPixelT>
void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, int screen_height, int width, int dash, SetPixelT set_pixel) void Blitter::DrawLineGeneric(int x1, int y1, int x2, int y2, int screen_width, int screen_height, int width, int dash, SetPixelT set_pixel)
{ {
int dy; int dy;
int dx; int dx;
int stepx; int stepx;
int stepy; int stepy;
dy = (y2 - y) * 2; dy = (y2 - y1) * 2;
if (dy < 0) { if (dy < 0) {
dy = -dy; dy = -dy;
stepy = -1; stepy = -1;
@ -31,7 +31,7 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
stepy = 1; stepy = 1;
} }
dx = (x2 - x) * 2; dx = (x2 - x1) * 2;
if (dx < 0) { if (dx < 0) {
dx = -dx; dx = -dx;
stepx = -1; stepx = -1;
@ -41,7 +41,7 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
if (dx == 0 && dy == 0) { if (dx == 0 && dy == 0) {
/* The algorithm below cannot handle this special case; make it work at least for line width 1 */ /* The algorithm below cannot handle this special case; make it work at least for line width 1 */
if (x >= 0 && x < screen_width && y >= 0 && y < screen_height) set_pixel(x, y); if (x1 >= 0 && x1 < screen_width && y1 >= 0 && y1 < screen_height) set_pixel(x1, y1);
return; return;
} }
@ -67,14 +67,14 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
int dash_count = 0; int dash_count = 0;
if (dx > dy) { if (dx > dy) {
if (stepx < 0) { if (stepx < 0) {
std::swap(x, x2); std::swap(x1, x2);
std::swap(y, y2); std::swap(y1, y2);
stepy = -stepy; stepy = -stepy;
} }
if (x2 < 0 || x >= screen_width) return; if (x2 < 0 || x1 >= screen_width) return;
int y_low = y; int y_low = y1;
int y_high = y; int y_high = y1;
int frac_low = dy - frac_diff / 2; int frac_low = dy - frac_diff / 2;
int frac_high = dy + frac_diff / 2; int frac_high = dy + frac_diff / 2;
@ -87,10 +87,10 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
y_high += stepy; y_high += stepy;
} }
if (x < 0) { if (x1 < 0) {
dash_count = (-x) % (dash + gap); dash_count = (-x1) % (dash + gap);
auto adjust_frac = [&](int64 frac, int &y_bound) -> int { auto adjust_frac = [&](int64 frac, int &y_bound) -> int {
frac -= ((int64) dy) * ((int64) x); frac -= ((int64) dy) * ((int64) x1);
if (frac >= 0) { if (frac >= 0) {
int quotient = frac / dx; int quotient = frac / dx;
int remainder = frac % dx; int remainder = frac % dx;
@ -101,17 +101,17 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
}; };
frac_low = adjust_frac(frac_low, y_low); frac_low = adjust_frac(frac_low, y_low);
frac_high = adjust_frac(frac_high, y_high); frac_high = adjust_frac(frac_high, y_high);
x = 0; x1 = 0;
} }
x2++; x2++;
if (x2 > screen_width) { if (x2 > screen_width) {
x2 = screen_width; x2 = screen_width;
} }
while (x != x2) { while (x1 != x2) {
if (dash_count < dash) { if (dash_count < dash) {
for (int y = y_low; y != y_high; y += stepy) { for (int y = y_low; y != y_high; y += stepy) {
if (y >= 0 && y < screen_height) set_pixel(x, y); if (y >= 0 && y < screen_height) set_pixel(x1, y);
} }
} }
if (frac_low >= 0) { if (frac_low >= 0) {
@ -122,21 +122,21 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
y_high += stepy; y_high += stepy;
frac_high -= dx; frac_high -= dx;
} }
x++; x1++;
frac_low += dy; frac_low += dy;
frac_high += dy; frac_high += dy;
if (++dash_count >= dash + gap) dash_count = 0; if (++dash_count >= dash + gap) dash_count = 0;
} }
} else { } else {
if (stepy < 0) { if (stepy < 0) {
std::swap(x, x2); std::swap(x1, x2);
std::swap(y, y2); std::swap(y1, y2);
stepx = -stepx; stepx = -stepx;
} }
if (y2 < 0 || y >= screen_height) return; if (y2 < 0 || y1 >= screen_height) return;
int x_low = x; int x_low = x1;
int x_high = x; int x_high = x1;
int frac_low = dx - frac_diff / 2; int frac_low = dx - frac_diff / 2;
int frac_high = dx + frac_diff / 2; int frac_high = dx + frac_diff / 2;
@ -149,10 +149,10 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
x_high += stepx; x_high += stepx;
} }
if (y < 0) { if (y1 < 0) {
dash_count = (-y) % (dash + gap); dash_count = (-y1) % (dash + gap);
auto adjust_frac = [&](int64 frac, int &x_bound) -> int { auto adjust_frac = [&](int64 frac, int &x_bound) -> int {
frac -= ((int64) dx) * ((int64) y); frac -= ((int64) dx) * ((int64) y1);
if (frac >= 0) { if (frac >= 0) {
int quotient = frac / dy; int quotient = frac / dy;
int remainder = frac % dy; int remainder = frac % dy;
@ -163,17 +163,17 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
}; };
frac_low = adjust_frac(frac_low, x_low); frac_low = adjust_frac(frac_low, x_low);
frac_high = adjust_frac(frac_high, x_high); frac_high = adjust_frac(frac_high, x_high);
y = 0; y1 = 0;
} }
y2++; y2++;
if (y2 > screen_height) { if (y2 > screen_height) {
y2 = screen_height; y2 = screen_height;
} }
while (y != y2) { while (y1 != y2) {
if (dash_count < dash) { if (dash_count < dash) {
for (int x = x_low; x != x_high; x += stepx) { for (int x = x_low; x != x_high; x += stepx) {
if (x >= 0 && x < screen_width) set_pixel(x, y); if (x >= 0 && x < screen_width) set_pixel(x, y1);
} }
} }
if (frac_low >= 0) { if (frac_low >= 0) {
@ -184,7 +184,7 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
x_high += stepx; x_high += stepx;
frac_high -= dy; frac_high -= dy;
} }
y++; y1++;
frac_low += dx; frac_low += dx;
frac_high += dx; frac_high += dx;
if (++dash_count >= dash + gap) dash_count = 0; if (++dash_count >= dash + gap) dash_count = 0;

@ -776,11 +776,11 @@ public:
case WID_SCL_PRI_COL_DROPDOWN: { case WID_SCL_PRI_COL_DROPDOWN: {
this->square = GetSpriteSize(SPR_SQUARE); this->square = GetSpriteSize(SPR_SQUARE);
int padding = this->square.width + NWidgetScrollbar::GetVerticalDimension().width + 10; int string_padding = this->square.width + NWidgetScrollbar::GetVerticalDimension().width + 10;
for (const StringID *id = _colour_dropdown; id != endof(_colour_dropdown); id++) { for (const StringID *id = _colour_dropdown; id != endof(_colour_dropdown); id++) {
size->width = std::max(size->width, GetStringBoundingBox(*id).width + padding); size->width = std::max(size->width, GetStringBoundingBox(*id).width + string_padding);
} }
size->width = std::max(size->width, GetStringBoundingBox(STR_COLOUR_DEFAULT).width + padding); size->width = std::max(size->width, GetStringBoundingBox(STR_COLOUR_DEFAULT).width + string_padding);
break; break;
} }
} }

@ -2700,14 +2700,14 @@ struct IndustryCargoesWindow : public Window {
/** /**
* Compute what and where to display for industry type \a it. * Compute what and where to display for industry type \a it.
* @param it Industry type to display. * @param displayed_it Industry type to display.
*/ */
void ComputeIndustryDisplay(IndustryType it) void ComputeIndustryDisplay(IndustryType displayed_it)
{ {
this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION; this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
this->ind_cargo = it; this->ind_cargo = displayed_it;
_displayed_industries.reset(); _displayed_industries.reset();
_displayed_industries.set(it); _displayed_industries.set(displayed_it);
this->fields.clear(); this->fields.clear();
CargoesRow &row = this->fields.emplace_back(); CargoesRow &row = this->fields.emplace_back();
@ -2717,7 +2717,7 @@ struct IndustryCargoesWindow : public Window {
row.columns[3].MakeEmpty(CFT_SMALL_EMPTY); row.columns[3].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
const IndustrySpec *central_sp = GetIndustrySpec(it); const IndustrySpec *central_sp = GetIndustrySpec(displayed_it);
bool houses_supply = HousesCanSupply(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)); bool houses_supply = HousesCanSupply(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
bool houses_accept = HousesCanAccept(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)); bool houses_accept = HousesCanAccept(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
/* Make a field consisting of two cargo columns. */ /* Make a field consisting of two cargo columns. */
@ -2734,7 +2734,7 @@ struct IndustryCargoesWindow : public Window {
} }
/* Add central industry. */ /* Add central industry. */
int central_row = 1 + num_indrows / 2; int central_row = 1 + num_indrows / 2;
this->fields[central_row].columns[2].MakeIndustry(it); this->fields[central_row].columns[2].MakeIndustry(displayed_it);
this->fields[central_row].ConnectIndustryProduced(2); this->fields[central_row].ConnectIndustryProduced(2);
this->fields[central_row].ConnectIndustryAccepted(2); this->fields[central_row].ConnectIndustryAccepted(2);

@ -1010,9 +1010,9 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
/* First check whether anything depends on us */ /* First check whether anything depends on us */
int sel_count = 0; int sel_count = 0;
bool force_selection = false; bool force_selection = false;
for (const ContentInfo *ci : parents) { for (const ContentInfo *parent_ci : parents) {
if (ci->IsSelected()) sel_count++; if (parent_ci->IsSelected()) sel_count++;
if (ci->state == ContentInfo::SELECTED) force_selection = true; if (parent_ci->state == ContentInfo::SELECTED) force_selection = true;
} }
if (sel_count == 0) { if (sel_count == 0) {
/* Nothing depends on us */ /* Nothing depends on us */
@ -1027,8 +1027,8 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
this->ReverseLookupTreeDependency(parents, c); this->ReverseLookupTreeDependency(parents, c);
/* Is there anything that is "force" selected?, if so... we're done. */ /* Is there anything that is "force" selected?, if so... we're done. */
for (const ContentInfo *ci : parents) { for (const ContentInfo *parent_ci : parents) {
if (ci->state != ContentInfo::SELECTED) continue; if (parent_ci->state != ContentInfo::SELECTED) continue;
force_selection = true; force_selection = true;
break; break;

@ -550,16 +550,16 @@ uint32 StationResolverObject::GetDebugID() const
/** /**
* Resolver for stations. * Resolver for stations.
* @param statspec Station (type) specification. * @param statspec Station (type) specification.
* @param st Instance of the station. * @param base_station Instance of the station.
* @param tile %Tile of the station. * @param tile %Tile of the station.
* @param callback Callback ID. * @param callback Callback ID.
* @param callback_param1 First parameter (var 10) of the callback. * @param callback_param1 First parameter (var 10) of the callback.
* @param callback_param2 Second parameter (var 18) of the callback. * @param callback_param2 Second parameter (var 18) of the callback.
*/ */
StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile, StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseStation *base_station, TileIndex tile,
CallbackID callback, uint32 callback_param1, uint32 callback_param2) CallbackID callback, uint32 callback_param1, uint32 callback_param2)
: ResolverObject(statspec->grf_prop.grffile, callback, callback_param1, callback_param2), : ResolverObject(statspec->grf_prop.grffile, callback, callback_param1, callback_param2),
station_scope(*this, statspec, st, tile), town_scope(nullptr) station_scope(*this, statspec, base_station, tile), town_scope(nullptr)
{ {
/* Invalidate all cached vars */ /* Invalidate all cached vars */
_svc.valid = 0; _svc.valid = 0;
@ -921,7 +921,7 @@ void AnimateStationTile(TileIndex tile)
StationAnimationBase::AnimateTile(ss, BaseStation::GetByTile(tile), tile, HasBit(ss->flags, SSF_CB141_RANDOM_BITS)); StationAnimationBase::AnimateTile(ss, BaseStation::GetByTile(tile), tile, HasBit(ss->flags, SSF_CB141_RANDOM_BITS));
} }
void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type) void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAnimationTrigger trigger, CargoID cargo_type)
{ {
/* List of coverage areas for each animation trigger */ /* List of coverage areas for each animation trigger */
static const TriggerArea tas[] = { static const TriggerArea tas[] = {
@ -929,14 +929,14 @@ void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTr
}; };
/* Get Station if it wasn't supplied */ /* Get Station if it wasn't supplied */
if (st == nullptr) st = BaseStation::GetByTile(tile); if (st == nullptr) st = BaseStation::GetByTile(trigger_tile);
/* Check the cached animation trigger bitmask to see if we need /* Check the cached animation trigger bitmask to see if we need
* to bother with any further processing. */ * to bother with any further processing. */
if (!HasBit(st->cached_anim_triggers, trigger)) return; if (!HasBit(st->cached_anim_triggers, trigger)) return;
uint16 random_bits = Random(); uint16 random_bits = Random();
ETileArea area = ETileArea(st, tile, tas[trigger]); ETileArea area = ETileArea(st, trigger_tile, tas[trigger]);
/* Check all tiles over the station to check if the specindex is still in use */ /* Check all tiles over the station to check if the specindex is still in use */
for (TileIndex tile : area) { for (TileIndex tile : area) {
@ -958,11 +958,11 @@ void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTr
/** /**
* Trigger station randomisation * Trigger station randomisation
* @param st station being triggered * @param st station being triggered
* @param tile specific tile of platform to trigger * @param trigger_tile specific tile of platform to trigger
* @param trigger trigger type * @param trigger trigger type
* @param cargo_type cargo type causing trigger * @param cargo_type cargo type causing trigger
*/ */
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type) void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoID cargo_type)
{ {
/* List of coverage areas for each animation trigger */ /* List of coverage areas for each animation trigger */
static const TriggerArea tas[] = { static const TriggerArea tas[] = {
@ -970,7 +970,7 @@ void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigg
}; };
/* Get Station if it wasn't supplied */ /* Get Station if it wasn't supplied */
if (st == nullptr) st = Station::GetByTile(tile); if (st == nullptr) st = Station::GetByTile(trigger_tile);
/* Check the cached cargo trigger bitmask to see if we need /* Check the cached cargo trigger bitmask to see if we need
* to bother with any further processing. */ * to bother with any further processing. */
@ -978,7 +978,7 @@ void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigg
if (cargo_type != CT_INVALID && !HasBit(st->cached_cargo_triggers, cargo_type)) return; if (cargo_type != CT_INVALID && !HasBit(st->cached_cargo_triggers, cargo_type)) return;
uint32 whole_reseed = 0; uint32 whole_reseed = 0;
ETileArea area = ETileArea(st, tile, tas[trigger]); ETileArea area = ETileArea(st, trigger_tile, tas[trigger]);
CargoTypes empty_mask = 0; CargoTypes empty_mask = 0;
if (trigger == SRT_CARGO_TAKEN) { if (trigger == SRT_CARGO_TAKEN) {

@ -1359,11 +1359,11 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
for (;;) { for (;;) {
/* only build/remove signals with the specified density */ /* only build/remove signals with the specified density */
if (remove || minimise_gaps || signal_ctr % signal_density == 0) { if (remove || minimise_gaps || signal_ctr % signal_density == 0) {
uint32 p1 = GB(TrackdirToTrack(trackdir), 0, 3); uint32 param1 = GB(TrackdirToTrack(trackdir), 0, 3);
SB(p1, 3, 1, mode); SB(param1, 3, 1, mode);
SB(p1, 4, 1, semaphores); SB(param1, 4, 1, semaphores);
SB(p1, 5, 3, sigtype); SB(param1, 5, 3, sigtype);
if (!remove && signal_ctr == 0) SetBit(p1, 17); if (!remove && signal_ctr == 0) SetBit(param1, 17);
/* Pick the correct orientation for the track direction */ /* Pick the correct orientation for the track direction */
signals = 0; signals = 0;
@ -1372,7 +1372,7 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
/* Test tiles in between for suitability as well if minimising gaps. */ /* Test tiles in between for suitability as well if minimising gaps. */
bool test_only = !remove && minimise_gaps && signal_ctr < (last_used_ctr + signal_density); bool test_only = !remove && minimise_gaps && signal_ctr < (last_used_ctr + signal_density);
CommandCost ret = DoCommand(tile, p1, signals, test_only ? flags & ~DC_EXEC : flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS); CommandCost ret = DoCommand(tile, param1, signals, test_only ? flags & ~DC_EXEC : flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
if (ret.Succeeded()) { if (ret.Succeeded()) {
/* Remember last track piece where we can place a signal. */ /* Remember last track piece where we can place a signal. */

@ -1436,8 +1436,8 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
case WID_SM_ZOOM_IN: case WID_SM_ZOOM_IN:
case WID_SM_ZOOM_OUT: { case WID_SM_ZOOM_OUT: {
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP); const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
Point pt = { (int)wid->current_x / 2, (int)wid->current_y / 2}; Point zoom_pt = { (int)wid->current_x / 2, (int)wid->current_y / 2};
this->SetZoomLevel((widget == WID_SM_ZOOM_IN) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt); this->SetZoomLevel((widget == WID_SM_ZOOM_IN) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &zoom_pt);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
break; break;
} }

@ -498,16 +498,16 @@ static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *c
/** /**
* Get the cargo types being produced around the tile (in a rectangle). * Get the cargo types being produced around the tile (in a rectangle).
* @param tile Northtile of area * @param north_tile Northern most tile of area
* @param w X extent of the area * @param w X extent of the area
* @param h Y extent of the area * @param h Y extent of the area
* @param rad Search radius in addition to the given area * @param rad Search radius in addition to the given area
*/ */
CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad) CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad)
{ {
CargoArray produced; CargoArray produced;
std::set<IndustryID> industries; std::set<IndustryID> industries;
TileArea ta = TileArea(tile, w, h).Expand(rad); TileArea ta = TileArea(north_tile, w, h).Expand(rad);
/* Loop over all tiles to get the produced cargo of /* Loop over all tiles to get the produced cargo of
* everything except industries */ * everything except industries */
@ -535,19 +535,19 @@ CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad)
/** /**
* Get the acceptance of cargoes around the tile in 1/8. * Get the acceptance of cargoes around the tile in 1/8.
* @param tile Center of the search area * @param center_tile Center of the search area
* @param w X extent of area * @param w X extent of area
* @param h Y extent of area * @param h Y extent of area
* @param rad Search radius in addition to given area * @param rad Search radius in addition to given area
* @param always_accepted bitmask of cargo accepted by houses and headquarters; can be nullptr * @param always_accepted bitmask of cargo accepted by houses and headquarters; can be nullptr
* @param ind Industry associated with neutral station (e.g. oil rig) or nullptr * @param ind Industry associated with neutral station (e.g. oil rig) or nullptr
*/ */
CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, CargoTypes *always_accepted) CargoArray GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad, CargoTypes *always_accepted)
{ {
CargoArray acceptance; CargoArray acceptance;
if (always_accepted != nullptr) *always_accepted = 0; if (always_accepted != nullptr) *always_accepted = 0;
TileArea ta = TileArea(tile, w, h).Expand(rad); TileArea ta = TileArea(center_tile, w, h).Expand(rad);
for (TileIndex tile : ta) { for (TileIndex tile : ta) {
/* Ignore industry if it has a neutral station. */ /* Ignore industry if it has a neutral station. */

@ -226,18 +226,18 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
* Pass == 1: Collect the actual cost. */ * Pass == 1: Collect the actual cost. */
for (int pass = 0; pass < 2; pass++) { for (int pass = 0; pass < 2; pass++) {
for (TileIndexSet::const_iterator it = ts.dirty_tiles.begin(); it != ts.dirty_tiles.end(); it++) { for (TileIndexSet::const_iterator it = ts.dirty_tiles.begin(); it != ts.dirty_tiles.end(); it++) {
TileIndex tile = *it; TileIndex t = *it;
assert(tile < MapSize()); assert(t < MapSize());
/* MP_VOID tiles can be terraformed but as tunnels and bridges /* MP_VOID tiles can be terraformed but as tunnels and bridges
* cannot go under / over these tiles they don't need checking. */ * cannot go under / over these tiles they don't need checking. */
if (IsTileType(tile, MP_VOID)) continue; if (IsTileType(t, MP_VOID)) continue;
/* Find new heights of tile corners */ /* Find new heights of tile corners */
int z_N = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); int z_N = TerraformGetHeightOfTile(&ts, t + TileDiffXY(0, 0));
int z_W = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); int z_W = TerraformGetHeightOfTile(&ts, t + TileDiffXY(1, 0));
int z_S = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); int z_S = TerraformGetHeightOfTile(&ts, t + TileDiffXY(1, 1));
int z_E = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); int z_E = TerraformGetHeightOfTile(&ts, t + TileDiffXY(0, 1));
/* Find min and max height of tile */ /* Find min and max height of tile */
int z_min = std::min({z_N, z_W, z_S, z_E}); int z_min = std::min({z_N, z_W, z_S, z_E});
@ -252,31 +252,31 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (pass == 0) { if (pass == 0) {
/* Check if bridge would take damage */ /* Check if bridge would take damage */
if (IsBridgeAbove(tile)) { if (IsBridgeAbove(t)) {
int bridge_height = GetBridgeHeight(GetSouthernBridgeEnd(tile)); int bridge_height = GetBridgeHeight(GetSouthernBridgeEnd(t));
/* Check if bridge would take damage. */ /* Check if bridge would take damage. */
if (direction == 1 && bridge_height <= z_max) { if (direction == 1 && bridge_height <= z_max) {
_terraform_err_tile = tile; // highlight the tile under the bridge _terraform_err_tile = t; // highlight the tile under the bridge
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
} }
/* Is the bridge above not too high afterwards? */ /* Is the bridge above not too high afterwards? */
if (direction == -1 && bridge_height > (z_min + _settings_game.construction.max_bridge_height)) { if (direction == -1 && bridge_height > (z_min + _settings_game.construction.max_bridge_height)) {
_terraform_err_tile = tile; _terraform_err_tile = t;
return_cmd_error(STR_ERROR_BRIDGE_TOO_HIGH_AFTER_LOWER_LAND); return_cmd_error(STR_ERROR_BRIDGE_TOO_HIGH_AFTER_LOWER_LAND);
} }
} }
/* Check if tunnel would take damage */ /* Check if tunnel would take damage */
if (direction == -1 && IsTunnelInWay(tile, z_min)) { if (direction == -1 && IsTunnelInWay(t, z_min)) {
_terraform_err_tile = tile; // highlight the tile above the tunnel _terraform_err_tile = t; // highlight the tile above the tunnel
return_cmd_error(STR_ERROR_EXCAVATION_WOULD_DAMAGE); return_cmd_error(STR_ERROR_EXCAVATION_WOULD_DAMAGE);
} }
} }
/* Is the tile already cleared? */ /* Is the tile already cleared? */
const ClearedObjectArea *coa = FindClearedObject(tile); const ClearedObjectArea *coa = FindClearedObject(t);
bool indirectly_cleared = coa != nullptr && coa->first_tile != tile; bool indirectly_cleared = coa != nullptr && coa->first_tile != t;
/* Check tiletype-specific things, and add extra-cost */ /* Check tiletype-specific things, and add extra-cost */
const bool curr_gen = _generating_world; const bool curr_gen = _generating_world;
@ -288,13 +288,13 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
} }
CommandCost cost; CommandCost cost;
if (indirectly_cleared) { if (indirectly_cleared) {
cost = DoCommand(tile, 0, 0, tile_flags, CMD_LANDSCAPE_CLEAR); cost = DoCommand(t, 0, 0, tile_flags, CMD_LANDSCAPE_CLEAR);
} else { } else {
cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, tile_flags, z_min, tileh); cost = _tile_type_procs[GetTileType(t)]->terraform_tile_proc(t, tile_flags, z_min, tileh);
} }
_generating_world = curr_gen; _generating_world = curr_gen;
if (cost.Failed()) { if (cost.Failed()) {
_terraform_err_tile = tile; _terraform_err_tile = t;
return cost; return cost;
} }
if (pass == 1) total_cost.AddCost(cost); if (pass == 1) total_cost.AddCost(cost);
@ -318,10 +318,10 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* change the height */ /* change the height */
for (TileIndexToHeightMap::const_iterator it = ts.tile_to_new_height.begin(); for (TileIndexToHeightMap::const_iterator it = ts.tile_to_new_height.begin();
it != ts.tile_to_new_height.end(); it++) { it != ts.tile_to_new_height.end(); it++) {
TileIndex tile = it->first; TileIndex t = it->first;
int height = it->second; int height = it->second;
SetTileHeight(tile, (uint)height); SetTileHeight(t, (uint)height);
} }
if (c != nullptr) c->terraform_limit -= (uint32)ts.tile_to_new_height.size() << 16; if (c != nullptr) c->terraform_limit -= (uint32)ts.tile_to_new_height.size() << 16;

@ -2988,27 +2988,27 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
* these do not directly have an owner so we need to check adjacent * these do not directly have an owner so we need to check adjacent
* tiles. This won't work correctly in the same loop if the adjacent * tiles. This won't work correctly in the same loop if the adjacent
* tile was already deleted earlier in the loop. */ * tile was already deleted earlier in the loop. */
for (TileIndex tile = 0; tile < MapSize(); ++tile) { for (TileIndex current_tile = 0; current_tile < MapSize(); ++current_tile) {
if (IsTileType(tile, MP_TUNNELBRIDGE) && TestTownOwnsBridge(tile, t)) { if (IsTileType(current_tile, MP_TUNNELBRIDGE) && TestTownOwnsBridge(current_tile, t)) {
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); CommandCost ret = DoCommand(current_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
} }
} }
/* Check all remaining tiles for town ownership. */ /* Check all remaining tiles for town ownership. */
for (TileIndex tile = 0; tile < MapSize(); ++tile) { for (TileIndex current_tile = 0; current_tile < MapSize(); ++current_tile) {
bool try_clear = false; bool try_clear = false;
switch (GetTileType(tile)) { switch (GetTileType(current_tile)) {
case MP_ROAD: case MP_ROAD:
try_clear = HasTownOwnedRoad(tile) && GetTownIndex(tile) == t->index; try_clear = HasTownOwnedRoad(current_tile) && GetTownIndex(current_tile) == t->index;
break; break;
case MP_HOUSE: case MP_HOUSE:
try_clear = GetTownIndex(tile) == t->index; try_clear = GetTownIndex(current_tile) == t->index;
break; break;
case MP_INDUSTRY: case MP_INDUSTRY:
try_clear = Industry::GetByTile(tile)->town == t; try_clear = Industry::GetByTile(current_tile)->town == t;
break; break;
case MP_OBJECT: case MP_OBJECT:
@ -3016,7 +3016,7 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* No towns will be left, remove it! */ /* No towns will be left, remove it! */
try_clear = true; try_clear = true;
} else { } else {
Object *o = Object::GetByTile(tile); Object *o = Object::GetByTile(current_tile);
if (o->town == t) { if (o->town == t) {
if (o->type == OBJECT_STATUE) { if (o->type == OBJECT_STATUE) {
/* Statue... always remove. */ /* Statue... always remove. */
@ -3033,7 +3033,7 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
break; break;
} }
if (try_clear) { if (try_clear) {
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); CommandCost ret = DoCommand(current_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
} }
} }

@ -1391,7 +1391,7 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, uint16 data, uint3
} }
CommandCost cost(EXPENSES_NEW_VEHICLES); CommandCost cost(EXPENSES_NEW_VEHICLES);
for (Train *t = sell_head; t != nullptr; t = t->Next()) cost.AddCost(-t->value); for (Train *part = sell_head; part != nullptr; part = part->Next()) cost.AddCost(-part->value);
/* do it? */ /* do it? */
if (flags & DC_EXEC) { if (flags & DC_EXEC) {

@ -392,11 +392,11 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16)); int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
TileArea ta(tile, p2); TileArea ta(tile, p2);
for (TileIndex tile : ta) { for (TileIndex current_tile : ta) {
switch (GetTileType(tile)) { switch (GetTileType(current_tile)) {
case MP_TREES: case MP_TREES:
/* no more space for trees? */ /* no more space for trees? */
if (GetTreeCount(tile) == 4) { if (GetTreeCount(current_tile) == 4) {
msg = STR_ERROR_TREE_ALREADY_HERE; msg = STR_ERROR_TREE_ALREADY_HERE;
continue; continue;
} }
@ -408,8 +408,8 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
} }
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
AddTreeCount(tile, 1); AddTreeCount(current_tile, 1);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(current_tile);
if (c != nullptr) c->tree_limit -= 1 << 16; if (c != nullptr) c->tree_limit -= 1 << 16;
} }
/* 2x as expensive to add more trees to an existing tile */ /* 2x as expensive to add more trees to an existing tile */
@ -417,14 +417,14 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
break; break;
case MP_WATER: case MP_WATER:
if (!IsCoast(tile) || IsSlopeWithOneCornerRaised(GetTileSlope(tile))) { if (!IsCoast(current_tile) || IsSlopeWithOneCornerRaised(GetTileSlope(current_tile))) {
msg = STR_ERROR_CAN_T_BUILD_ON_WATER; msg = STR_ERROR_CAN_T_BUILD_ON_WATER;
continue; continue;
} }
FALLTHROUGH; FALLTHROUGH;
case MP_CLEAR: { case MP_CLEAR: {
if (IsBridgeAbove(tile)) { if (IsBridgeAbove(current_tile)) {
msg = STR_ERROR_SITE_UNSUITABLE; msg = STR_ERROR_SITE_UNSUITABLE;
continue; continue;
} }
@ -433,11 +433,11 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Be a bit picky about which trees go where. */ /* Be a bit picky about which trees go where. */
if (_settings_game.game_creation.landscape == LT_TROPIC && treetype != TREE_INVALID && ( if (_settings_game.game_creation.landscape == LT_TROPIC && treetype != TREE_INVALID && (
/* No cacti outside the desert */ /* No cacti outside the desert */
(treetype == TREE_CACTUS && GetTropicZone(tile) != TROPICZONE_DESERT) || (treetype == TREE_CACTUS && GetTropicZone(current_tile) != TROPICZONE_DESERT) ||
/* No rain forest trees outside the rain forest, except in the editor mode where it makes those tiles rain forest tile */ /* No rain forest trees outside the rain forest, except in the editor mode where it makes those tiles rain forest tile */
(IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS) && GetTropicZone(tile) != TROPICZONE_RAINFOREST && _game_mode != GM_EDITOR) || (IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS) && GetTropicZone(current_tile) != TROPICZONE_RAINFOREST && _game_mode != GM_EDITOR) ||
/* And no subtropical trees in the desert/rain forest */ /* And no subtropical trees in the desert/rain forest */
(IsInsideMM(treetype, TREE_SUB_TROPICAL, TREE_TOYLAND) && GetTropicZone(tile) != TROPICZONE_NORMAL))) { (IsInsideMM(treetype, TREE_SUB_TROPICAL, TREE_TOYLAND) && GetTropicZone(current_tile) != TROPICZONE_NORMAL))) {
msg = STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE; msg = STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE;
continue; continue;
} }
@ -453,7 +453,7 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
switch (GetRawClearGround(tile)) { switch (GetRawClearGround(tile)) {
case CLEAR_FIELDS: case CLEAR_FIELDS:
case CLEAR_ROCKS: { case CLEAR_ROCKS: {
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); CommandCost ret = DoCommand(current_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret);
break; break;
@ -464,24 +464,24 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
} }
if (_game_mode != GM_EDITOR && Company::IsValidID(_current_company)) { if (_game_mode != GM_EDITOR && Company::IsValidID(_current_company)) {
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); Town *t = ClosestTownFromTile(current_tile, _settings_game.economy.dist_local_authority);
if (t != nullptr) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags); if (t != nullptr) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
} }
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
if (treetype == TREE_INVALID) { if (treetype == TREE_INVALID) {
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8)); treetype = GetRandomTreeType(current_tile, GB(Random(), 24, 8));
if (treetype == TREE_INVALID) treetype = TREE_CACTUS; if (treetype == TREE_INVALID) treetype = TREE_CACTUS;
} }
/* Plant full grown trees in scenario editor */ /* Plant full grown trees in scenario editor */
PlantTreesOnTile(tile, treetype, 0, _game_mode == GM_EDITOR ? 3 : 0); PlantTreesOnTile(current_tile, treetype, 0, _game_mode == GM_EDITOR ? 3 : 0);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(current_tile);
if (c != nullptr) c->tree_limit -= 1 << 16; if (c != nullptr) c->tree_limit -= 1 << 16;
/* When planting rainforest-trees, set tropiczone to rainforest in editor. */ /* When planting rainforest-trees, set tropiczone to rainforest in editor. */
if (_game_mode == GM_EDITOR && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS)) { if (_game_mode == GM_EDITOR && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS)) {
SetTropicZone(tile, TROPICZONE_RAINFOREST); SetTropicZone(current_tile, TROPICZONE_RAINFOREST);
} }
} }
cost.AddCost(_price[PR_BUILD_TREES]); cost.AddCost(_price[PR_BUILD_TREES]);

@ -245,8 +245,8 @@ void InitializeWindowViewport(Window *w, int x, int y,
veh = Vehicle::Get(vp->follow_vehicle); veh = Vehicle::Get(vp->follow_vehicle);
pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
} else { } else {
uint x = TileX(follow_flags) * TILE_SIZE; x = TileX(follow_flags) * TILE_SIZE;
uint y = TileY(follow_flags) * TILE_SIZE; y = TileY(follow_flags) * TILE_SIZE;
vp->follow_vehicle = INVALID_VEHICLE; vp->follow_vehicle = INVALID_VEHICLE;
pt = MapXYZToViewport(vp, x, y, GetSlopePixelZ(x, y)); pt = MapXYZToViewport(vp, x, y, GetSlopePixelZ(x, y));

@ -467,19 +467,19 @@ CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
} }
for (; *iter != INVALID_TILE; ++(*iter)) { for (; *iter != INVALID_TILE; ++(*iter)) {
TileIndex tile = *iter; TileIndex current_tile = *iter;
CommandCost ret; CommandCost ret;
Slope slope = GetTileSlope(tile); Slope slope = GetTileSlope(current_tile);
if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) { if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) {
return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
} }
/* can't make water of water! */ /* can't make water of water! */
if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue; if (IsTileType(current_tile, MP_WATER) && (!IsTileOwner(current_tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue;
bool water = IsWaterTile(tile); bool water = IsWaterTile(current_tile);
ret = DoCommand(tile, 0, 0, flags | DC_FORCE_CLEAR_TILE, CMD_LANDSCAPE_CLEAR); ret = DoCommand(current_tile, 0, 0, flags | DC_FORCE_CLEAR_TILE, CMD_LANDSCAPE_CLEAR);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
if (!water) cost.AddCost(ret); if (!water) cost.AddCost(ret);
@ -487,31 +487,31 @@ CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
switch (wc) { switch (wc) {
case WATER_CLASS_RIVER: case WATER_CLASS_RIVER:
MakeRiver(tile, Random()); MakeRiver(current_tile, Random());
if (_game_mode == GM_EDITOR) { if (_game_mode == GM_EDITOR) {
TileIndex tile2 = tile; TileIndex tile2 = current_tile;
CircularTileSearch(&tile2, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr); CircularTileSearch(&tile2, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr);
} }
break; break;
case WATER_CLASS_SEA: case WATER_CLASS_SEA:
if (TileHeight(tile) == 0) { if (TileHeight(current_tile) == 0) {
MakeSea(tile); MakeSea(current_tile);
break; break;
} }
FALLTHROUGH; FALLTHROUGH;
default: default:
MakeCanal(tile, _current_company, Random()); MakeCanal(current_tile, _current_company, Random());
if (Company::IsValidID(_current_company)) { if (Company::IsValidID(_current_company)) {
Company::Get(_current_company)->infrastructure.water++; Company::Get(_current_company)->infrastructure.water++;
DirtyCompanyInfrastructureWindows(_current_company); DirtyCompanyInfrastructureWindows(_current_company);
} }
break; break;
} }
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(current_tile);
MarkCanalsAndRiversAroundDirty(tile); MarkCanalsAndRiversAroundDirty(current_tile);
CheckForDockingTile(tile); CheckForDockingTile(current_tile);
} }
cost.AddCost(_price[PR_BUILD_CANAL]); cost.AddCost(_price[PR_BUILD_CANAL]);
@ -1044,8 +1044,8 @@ static void FloodVehicles(TileIndex tile)
if (IsAirportTile(tile)) { if (IsAirportTile(tile)) {
const Station *st = Station::GetByTile(tile); const Station *st = Station::GetByTile(tile);
for (TileIndex tile : st->airport) { for (TileIndex airport_tile : st->airport) {
if (st->TileBelongsToAirport(tile)) FindVehicleOnPos(tile, &z, &FloodVehicleProc); if (st->TileBelongsToAirport(airport_tile)) FindVehicleOnPos(airport_tile, &z, &FloodVehicleProc);
} }
/* No vehicle could be flooded on this airport anymore */ /* No vehicle could be flooded on this airport anymore */

Loading…
Cancel
Save