Changeset - r5998:69c1cce26321
[Not reviewed]
master
0 6 0
celestar - 18 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
 
@@ -1510,25 +1510,25 @@ int LoadUnloadVehicle(Vehicle *v, bool j
 
			} else {
 
				unloading_time = 20;
 
			}
 
		}
 
	}
 

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

	
 
	v->load_unload_time_rem = unloading_time;
 

	
 
	if (completely_empty) {
 
		TriggerVehicle(v, VEHICLE_TRIGGER_EMPTY);
 
	}
 

	
src/station.cpp
Show inline comments
 
@@ -170,24 +170,74 @@ bool Station::TileBelongsToRailStation(T
 
			return st;
 
		}
 
	}
 

	
 
	/* Check if we can add a block to the pool */
 
	if (AddBlockToPool(&_Station_pool)) return AllocateRaw();
 

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

	
 
/** Determines whether a station exists
 
 * @todo replace 0 by INVALID_TILE
 
 */
 
bool Station::IsValid() const
src/station.h
Show inline comments
 
@@ -158,24 +158,26 @@ struct Station {
 
	/* normal new/delete operators. Used when building/removing station */
 
	void* operator new (size_t size);
 
	void operator delete(void *p);
 

	
 
	/* new/delete operators accepting station index. Used when loading station from savegame. */
 
	void* operator new (size_t size, int st_idx);
 
	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);
 
};
 

	
 
enum {
 
	FACIL_TRAIN      = 0x01,
 
	FACIL_TRUCK_STOP = 0x02,
 
	FACIL_BUS_STOP   = 0x04,
 
	FACIL_AIRPORT    = 0x08,
 
@@ -251,26 +253,24 @@ static inline bool IsValidStationID(Stat
 

	
 
DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000)
 

	
 
#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) if (rs->IsValid())
 
#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
 

	
 
/* 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);
 
uint GetNumRoadStops(const Station* st, RoadStop::Type type);
 
RoadStop * AllocateRoadStop( void );
 
void ClearSlot(Vehicle *v);
 

	
 
void DeleteOilRig(TileIndex t);
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -1131,75 +1131,24 @@ int32 CmdRemoveFromRailroadStation(TileI
 
		UpdateStationSignCoord(st);
 

	
 
		// if we deleted the whole station, delete the train facility.
 
		if (st->train_tile == 0) {
 
			st->facilities &= ~FACIL_TRAIN;
 
			UpdateStationVirtCoordDirty(st);
 
			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;
 

	
 
	/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
 
	if (_current_player == OWNER_WATER && _patches.nonuniform_stations)
 
		return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
 

	
 
	/* Current player owns the station? */
 
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
src/train_cmd.cpp
Show inline comments
 
@@ -347,25 +347,25 @@ static int GetTrainAcceleration(Vehicle 
 

	
 
		if (curvecount[0] == 1 && curvecount[1] == 1) {
 
			max_speed = 0xFFFF;
 
		} else if (total > 1) {
 
			max_speed = 232 - (13 - clamp(sum, 1, 12)) * (13 - clamp(sum, 1, 12));
 
		}
 
	}
 

	
 
	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))
 
				max_speed = v->cur_speed - (delta_v / 10);
 

	
 
			max_speed = max(max_speed, 25 * station_length);
 
		}
 
	}
 

	
src/yapf/follow_track.hpp
Show inline comments
 
@@ -188,25 +188,25 @@ protected:
 
			} else if (IsBridge(m_new_tile)) {
 
				if (!m_is_bridge) {
 
					DiagDirection ramp_enderdir = GetBridgeRampDirection(m_new_tile);
 
					if (ramp_enderdir != m_exitdir) return false;
 
				}
 
			}
 
		}
 

	
 
		// 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);
 
			return true;
 
		}
 

	
 
		return true;
 
	}
 

	
0 comments (0 inline, 0 general)