mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Unify where rail station tile flags are set. (#12531)
This avoids repeating the logic in three places.
This commit is contained in:
parent
04a3bf76e8
commit
45886e50b2
|
@ -2878,19 +2878,7 @@ bool AfterLoadGame()
|
|||
/* Station blocked, wires and pylon flags need to be stored in the map. This is effectively cached data, so no
|
||||
* version check is necessary. This is done here as the SLV_182 check below needs the blocked status. */
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (HasStationTileRail(t)) {
|
||||
StationGfx gfx = GetStationGfx(t);
|
||||
const StationSpec *statspec = GetStationSpec(t);
|
||||
|
||||
bool blocked = statspec != nullptr && HasBit(statspec->blocked, gfx);
|
||||
/* Default stations do not draw pylons under roofs (gfx >= 4) */
|
||||
bool pylons = statspec != nullptr ? HasBit(statspec->pylons, gfx) : gfx < 4;
|
||||
bool wires = statspec == nullptr || !HasBit(statspec->wires, gfx);
|
||||
|
||||
SetStationTileBlocked(t, blocked);
|
||||
SetStationTileHavePylons(t, pylons);
|
||||
SetStationTileHaveWires(t, wires);
|
||||
}
|
||||
if (HasStationTileRail(t)) SetRailStationTileFlags(t, GetStationSpec(t));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1294,6 +1294,24 @@ static CommandCost CalculateRailStationCost(TileArea tile_area, DoCommandFlag fl
|
|||
return cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set rail station tile flags for the given tile.
|
||||
* @param tile Tile to set flags on.
|
||||
* @param statspec Statspec of the tile.
|
||||
*/
|
||||
void SetRailStationTileFlags(TileIndex tile, const StationSpec *statspec)
|
||||
{
|
||||
const StationGfx gfx = GetStationGfx(tile);
|
||||
bool blocked = statspec != nullptr && HasBit(statspec->blocked, gfx);
|
||||
/* Default stations do not draw pylons under roofs (gfx >= 4) */
|
||||
bool pylons = statspec != nullptr ? HasBit(statspec->pylons, gfx) : gfx < 4;
|
||||
bool wires = statspec == nullptr || !HasBit(statspec->wires, gfx);
|
||||
|
||||
SetStationTileBlocked(tile, blocked);
|
||||
SetStationTileHavePylons(tile, pylons);
|
||||
SetStationTileHaveWires(tile, wires);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build rail station
|
||||
* @param flags operation to perform
|
||||
|
@ -1456,18 +1474,9 @@ CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, RailTyp
|
|||
TriggerStationAnimation(st, tile, SAT_BUILT);
|
||||
}
|
||||
|
||||
/* Should be the same as layout but axis component could be wrong... */
|
||||
StationGfx gfx = GetStationGfx(tile);
|
||||
bool blocked = statspec != nullptr && HasBit(statspec->blocked, gfx);
|
||||
/* Default stations do not draw pylons under roofs (gfx >= 4) */
|
||||
bool pylons = statspec != nullptr ? HasBit(statspec->pylons, gfx) : gfx < 4;
|
||||
bool wires = statspec == nullptr || !HasBit(statspec->wires, gfx);
|
||||
SetRailStationTileFlags(tile, statspec);
|
||||
|
||||
SetStationTileBlocked(tile, blocked);
|
||||
SetStationTileHavePylons(tile, pylons);
|
||||
SetStationTileHaveWires(tile, wires);
|
||||
|
||||
if (!blocked) c->infrastructure.rail[rt]++;
|
||||
if (!IsStationTileBlocked(tile)) c->infrastructure.rail[rt]++;
|
||||
c->infrastructure.station++;
|
||||
|
||||
tile += tile_delta;
|
||||
|
|
|
@ -33,6 +33,7 @@ void UpdateStationAcceptance(Station *st, bool show_msg);
|
|||
CargoTypes GetAcceptanceMask(const Station *st);
|
||||
CargoTypes GetEmptyMask(const Station *st);
|
||||
|
||||
void SetRailStationTileFlags(TileIndex tile, const StationSpec *statspec);
|
||||
const DrawTileSprites *GetStationTileLayout(StationType st, uint8_t gfx);
|
||||
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image);
|
||||
|
||||
|
|
|
@ -276,16 +276,7 @@ CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis
|
|||
MakeRailWaypoint(tile, wp->owner, wp->index, axis, layout[i], GetRailType(tile));
|
||||
SetCustomStationSpecIndex(tile, map_spec_index);
|
||||
|
||||
/* Should be the same as layout but axis component could be wrong... */
|
||||
StationGfx gfx = GetStationGfx(tile);
|
||||
bool blocked = spec != nullptr && HasBit(spec->blocked, gfx);
|
||||
/* Default stations do not draw pylons under roofs (gfx >= 4) */
|
||||
bool pylons = spec != nullptr ? HasBit(spec->pylons, gfx) : gfx < 4;
|
||||
bool wires = spec == nullptr || !HasBit(spec->wires, gfx);
|
||||
|
||||
SetStationTileBlocked(tile, blocked);
|
||||
SetStationTileHavePylons(tile, pylons);
|
||||
SetStationTileHaveWires(tile, wires);
|
||||
SetRailStationTileFlags(tile, spec);
|
||||
|
||||
SetRailStationReservation(tile, reserved);
|
||||
MarkTileDirtyByTile(tile);
|
||||
|
|
Loading…
Reference in New Issue