# HG changeset patch # User celestar # Date 1171384598 0 # Node ID ebf3649bd88f182c4dadaa91323fc52e5358316d # Parent cf5e2e4b31568a67658b9a9da62aa1874de91086 (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed. diff -r cf5e2e4b3156 -r ebf3649bd88f src/economy.cpp --- a/src/economy.cpp Tue Feb 13 15:44:37 2007 +0000 +++ b/src/economy.cpp Tue Feb 13 16:36:38 2007 +0000 @@ -1519,7 +1519,7 @@ if (v->type == VEH_Train) { // Each platform tile is worth 2 rail vehicles. - int overhang = v->u.rail.cached_total_length - GetStationPlatforms(st, v->tile) * TILE_SIZE; + int overhang = v->u.rail.cached_total_length - st->GetPlatformLength(v->tile) * TILE_SIZE; if (overhang > 0) { unloading_time <<= 1; unloading_time += (overhang * unloading_time) / 8; diff -r cf5e2e4b3156 -r ebf3649bd88f src/station.cpp --- a/src/station.cpp Tue Feb 13 15:44:37 2007 +0000 +++ b/src/station.cpp Tue Feb 13 16:36:38 2007 +0000 @@ -179,6 +179,56 @@ } +/** Obtain the length of a platform + * @pre tile must be a railway station tile + * @param tile A tile that contains the platform in question + * @returns The length of the platform + */ +uint Station::GetPlatformLength(TileIndex tile) const +{ + TileIndex t; + TileIndexDiff delta; + uint len = 0; + assert(TileBelongsToRailStation(tile)); + + delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); + + t = tile; + do { + t -= delta; + len++; + } while (IsCompatibleTrainStationTile(t, tile)); + + t = tile; + do { + t += delta; + len++; + } while (IsCompatibleTrainStationTile(t, tile)); + + return len - 1; +} + +/** Determines the REMAINING length of a platform, starting at (and including) + * the given tile. + * @param tile the tile from which to start searching. Must be a railway station tile + * @param dir The direction in which to search. + * @return The platform length + */ +uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const +{ + TileIndex start_tile = tile; + uint length = 0; + assert(IsRailwayStationTile(tile)); + assert(dir < DIAGDIR_END); + + do { + length ++; + tile += TileOffsByDiagDir(dir); + } while (IsCompatibleTrainStationTile(tile, start_tile)); + + return length; +} + /** Determines whether a station is a buoy only. * @todo Ditch this encoding of buoys */ diff -r cf5e2e4b3156 -r ebf3649bd88f src/station.h --- a/src/station.h Tue Feb 13 15:44:37 2007 +0000 +++ b/src/station.h Tue Feb 13 16:36:38 2007 +0000 @@ -167,6 +167,8 @@ void MarkDirty() const; void MarkTilesDirty() const; bool TileBelongsToRailStation(TileIndex tile) const; + uint GetPlatformLength(TileIndex tile, DiagDirection dir) const; + uint GetPlatformLength(TileIndex tile) const; bool IsBuoy() const; bool IsValid() const; @@ -260,8 +262,6 @@ void AfterLoadStations(void); void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, int w, int h, int rad); void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, int w, int h, int rad); -uint GetStationPlatforms(const Station *st, TileIndex tile); -uint GetPlatformLength(TileIndex tile, DiagDirection dir); const DrawTileSprites *GetStationTileLayout(byte gfx); diff -r cf5e2e4b3156 -r ebf3649bd88f src/station_cmd.cpp --- a/src/station_cmd.cpp Tue Feb 13 15:44:37 2007 +0000 +++ b/src/station_cmd.cpp Tue Feb 13 16:36:38 2007 +0000 @@ -1140,57 +1140,6 @@ return _price.remove_rail_station; } -// determine the number of platforms for the station -uint GetStationPlatforms(const Station *st, TileIndex tile) -{ - TileIndex t; - TileIndexDiff delta; - Axis axis; - uint len; - assert(st->TileBelongsToRailStation(tile)); - - len = 0; - axis = GetRailStationAxis(tile); - delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); - - // find starting tile.. - t = tile; - do { - t -= delta; - len++; - } while (st->TileBelongsToRailStation(t) && GetRailStationAxis(t) == axis); - - // find ending tile - t = tile; - do { - t += delta; - len++; - } while (st->TileBelongsToRailStation(t) && GetRailStationAxis(t) == axis); - - return len - 1; -} - -/** Determines the REMAINING length of a platform, starting at (and including) - * the given tile. - * @param tile the tile from which to start searching. Must be a railway station tile - * @param dir The direction in which to search. - * @return The platform length - */ -uint GetPlatformLength(TileIndex tile, DiagDirection dir) -{ - TileIndex start_tile = tile; - uint length = 0; - assert(IsRailwayStationTile(tile)); - assert(dir < DIAGDIR_END); - - do { - length ++; - tile += TileOffsByDiagDir(dir); - } while (IsCompatibleTrainStationTile(tile, start_tile)); - - return length; -} - static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) { diff -r cf5e2e4b3156 -r ebf3649bd88f src/train_cmd.cpp --- a/src/train_cmd.cpp Tue Feb 13 15:44:37 2007 +0000 +++ b/src/train_cmd.cpp Tue Feb 13 16:36:38 2007 +0000 @@ -356,7 +356,7 @@ if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) { if (TrainShouldStop(v, v->tile)) { - int station_length = GetPlatformLength(v->tile, DirToDiagDir(v->direction)); + int station_length = GetStationByTile(v->tile)->GetPlatformLength(v->tile, DirToDiagDir(v->direction)); int delta_v; max_speed = 120; diff -r cf5e2e4b3156 -r ebf3649bd88f src/yapf/follow_track.hpp --- a/src/yapf/follow_track.hpp Tue Feb 13 15:44:37 2007 +0000 +++ b/src/yapf/follow_track.hpp Tue Feb 13 16:36:38 2007 +0000 @@ -197,7 +197,7 @@ if (IsRailTT() && m_is_station) { // entered railway station // get platform length - uint length = GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td)); + uint length = GetStationByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td)); // how big step we must do to get to the last platform tile; m_tiles_skipped = length - 1; // move to the platform end