Changeset - r5998:69c1cce26321
[Not reviewed]
master
0 6 0
celestar - 17 years ago 2007-02-13 16:36:38
celestar@openttd.org
(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.
6 files changed with 55 insertions and 56 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1516,13 +1516,13 @@ int LoadUnloadVehicle(Vehicle *v, bool j
 
	if (v_profit_total > 0) {
 
		ShowFeederIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, v_profit_total);
 
	}
 

	
 
	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;
 
		}
 
	}
 

	
src/station.cpp
Show inline comments
 
@@ -176,12 +176,62 @@ bool Station::TileBelongsToRailStation(T
 

	
 
	_error_message = STR_3008_TOO_MANY_STATIONS_LOADING;
 
	return NULL;
 
}
 

	
 

	
 
/** 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
 
 */
 
bool Station::IsBuoy() const
 
{
 
	return (had_vehicle_of_type & HVOT_BUOY) != 0;
src/station.h
Show inline comments
 
@@ -164,12 +164,14 @@ struct Station {
 
	void operator delete(void *p, int st_idx);
 

	
 
	void AddFacility(byte new_facility_bit, TileIndex facil_xy);
 
	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;
 

	
 
protected:
 
	static Station *AllocateRaw(void);
 
};
 
@@ -257,14 +259,12 @@ DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 
 
/* End of stuff for ROADSTOPS */
 

	
 

	
 
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);
 
void StationPickerDrawSprite(int x, int y, RailType railtype, int image);
 

	
 
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStop::Type type);
src/station_cmd.cpp
Show inline comments
 
@@ -1137,63 +1137,12 @@ int32 CmdRemoveFromRailroadStation(TileI
 
			DeleteStationIfEmpty(st);
 
		}
 
	}
 
	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)
 
{
 
	int w,h;
 
	int32 cost = 0;
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -353,13 +353,13 @@ static int GetTrainAcceleration(Vehicle 
 
	}
 

	
 
	max_speed += (max_speed / 2) * v->u.rail.railtype;
 

	
 
	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;
 

	
 
			delta_v = v->cur_speed / (station_length + 1);
 
			if (v->max_speed > (v->cur_speed - delta_v))
src/yapf/follow_track.hpp
Show inline comments
 
@@ -194,13 +194,13 @@ protected:
 
		}
 

	
 
		// special handling for rail stations - get to the end of platform
 
		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
 
			TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
 
			diff *= m_tiles_skipped;
 
			m_new_tile = TILE_ADD(m_new_tile, diff);
0 comments (0 inline, 0 general)