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
|
/* 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. */
|
* version check is necessary. This is done here as the SLV_182 check below needs the blocked status. */
|
||||||
for (auto t : Map::Iterate()) {
|
for (auto t : Map::Iterate()) {
|
||||||
if (HasStationTileRail(t)) {
|
if (HasStationTileRail(t)) SetRailStationTileFlags(t, GetStationSpec(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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1294,6 +1294,24 @@ static CommandCost CalculateRailStationCost(TileArea tile_area, DoCommandFlag fl
|
||||||
return cost;
|
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
|
* Build rail station
|
||||||
* @param flags operation to perform
|
* @param flags operation to perform
|
||||||
|
@ -1456,18 +1474,9 @@ CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, RailTyp
|
||||||
TriggerStationAnimation(st, tile, SAT_BUILT);
|
TriggerStationAnimation(st, tile, SAT_BUILT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should be the same as layout but axis component could be wrong... */
|
SetRailStationTileFlags(tile, statspec);
|
||||||
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);
|
if (!IsStationTileBlocked(tile)) c->infrastructure.rail[rt]++;
|
||||||
SetStationTileHavePylons(tile, pylons);
|
|
||||||
SetStationTileHaveWires(tile, wires);
|
|
||||||
|
|
||||||
if (!blocked) c->infrastructure.rail[rt]++;
|
|
||||||
c->infrastructure.station++;
|
c->infrastructure.station++;
|
||||||
|
|
||||||
tile += tile_delta;
|
tile += tile_delta;
|
||||||
|
|
|
@ -33,6 +33,7 @@ void UpdateStationAcceptance(Station *st, bool show_msg);
|
||||||
CargoTypes GetAcceptanceMask(const Station *st);
|
CargoTypes GetAcceptanceMask(const Station *st);
|
||||||
CargoTypes GetEmptyMask(const Station *st);
|
CargoTypes GetEmptyMask(const Station *st);
|
||||||
|
|
||||||
|
void SetRailStationTileFlags(TileIndex tile, const StationSpec *statspec);
|
||||||
const DrawTileSprites *GetStationTileLayout(StationType st, uint8_t gfx);
|
const DrawTileSprites *GetStationTileLayout(StationType st, uint8_t gfx);
|
||||||
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image);
|
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));
|
MakeRailWaypoint(tile, wp->owner, wp->index, axis, layout[i], GetRailType(tile));
|
||||||
SetCustomStationSpecIndex(tile, map_spec_index);
|
SetCustomStationSpecIndex(tile, map_spec_index);
|
||||||
|
|
||||||
/* Should be the same as layout but axis component could be wrong... */
|
SetRailStationTileFlags(tile, spec);
|
||||||
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);
|
|
||||||
|
|
||||||
SetRailStationReservation(tile, reserved);
|
SetRailStationReservation(tile, reserved);
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
|
|
Loading…
Reference in New Issue