Changeset - r8169:954f67fb52e7
[Not reviewed]
master
0 3 0
peter1138 - 17 years ago 2008-01-01 14:00:31
peter1138@openttd.org
(svn r11732) -Fix (r4150): elrail merge gave elrail, monorail & maglev unintended speed bonuses for curves, as the bonus was based on the railtype index. The bonus is now specified by a property of the railtype.
3 files changed with 25 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/rail.h
Show inline comments
 
@@ -86,12 +86,17 @@ struct RailtypeInfo {
 
	SpriteID bridge_offset;
 

	
 
	/**
 
	 * Offset to add to ground sprite when drawing custom waypoints / stations
 
	 */
 
	byte custom_ground_offset;
 

	
 
	/**
 
	 * Multiplier for curve maximum speed advantage
 
	 */
 
	byte curve_speed;
 
};
 

	
 

	
 
/** these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block */
 
enum {
 
	NUM_SSD_ENTRY = 256, ///< max amount of blocks
src/railtypes.h
Show inline comments
 
@@ -54,12 +54,15 @@ RailtypeInfo _railtypes[] = {
 

	
 
		/* bridge offset */
 
		0,
 

	
 
		/* custom ground offset */
 
		0,
 

	
 
		/* curve speed advantage (multiplier) */
 
		0,
 
	},
 

	
 
	/** Electrified railway */
 
	{ /* Main Sprites */
 
		{ SPR_RAIL_TRACK_Y, SPR_RAIL_TRACK_N_S, SPR_RAIL_TRACK_BASE, SPR_RAIL_SINGLE_Y, SPR_RAIL_SINGLE_X,
 
			SPR_RAIL_SINGLE_NORTH, SPR_RAIL_SINGLE_SOUTH, SPR_RAIL_SINGLE_EAST, SPR_RAIL_SINGLE_WEST,
 
@@ -107,12 +110,15 @@ RailtypeInfo _railtypes[] = {
 

	
 
		/* bridge offset */
 
		0,
 

	
 
		/* custom ground offset */
 
		0,
 

	
 
		/* curve speed advantage (multiplier) */
 
		0,
 
	},
 

	
 
	/** Monorail */
 
	{ /* Main Sprites */
 
		{ SPR_MONO_TRACK_Y, SPR_MONO_TRACK_N_S, SPR_MONO_TRACK_BASE, SPR_MONO_SINGLE_Y, SPR_MONO_SINGLE_X,
 
			SPR_MONO_SINGLE_NORTH, SPR_MONO_SINGLE_SOUTH, SPR_MONO_SINGLE_EAST, SPR_MONO_SINGLE_WEST,
 
@@ -156,12 +162,15 @@ RailtypeInfo _railtypes[] = {
 

	
 
		/* bridge offset */
 
		16,
 

	
 
		/* custom ground offset */
 
		1,
 

	
 
		/* curve speed advantage (multiplier) */
 
		1,
 
	},
 

	
 
	/** Maglev */
 
	{ /* Main sprites */
 
		{ SPR_MGLV_TRACK_Y, SPR_MGLV_TRACK_N_S, SPR_MGLV_TRACK_BASE, SPR_MGLV_SINGLE_Y, SPR_MGLV_SINGLE_X,
 
			SPR_MGLV_SINGLE_NORTH, SPR_MGLV_SINGLE_SOUTH, SPR_MGLV_SINGLE_EAST, SPR_MGLV_SINGLE_WEST,
 
@@ -205,10 +214,13 @@ RailtypeInfo _railtypes[] = {
 

	
 
		/* bridge offset */
 
		24,
 

	
 
		/* custom ground offset */
 
		2,
 

	
 
		/* curve speed advantage (multiplier) */
 
		2,
 
	},
 
};
 

	
 
#endif /* RAILTYPES_H */
src/train_cmd.cpp
Show inline comments
 
@@ -308,13 +308,14 @@ static bool TrainShouldStop(const Vehicl
 
	return true;
 
}
 

	
 
/** new acceleration*/
 
static int GetTrainAcceleration(Vehicle *v, bool mode)
 
{
 
	int max_speed = 2000;
 
	static const int absolute_max_speed = 2000;
 
	int max_speed = absolute_max_speed;
 
	int speed = v->cur_speed * 10 / 16; // km-ish/h -> mp/h
 
	int curvecount[2] = {0, 0};
 

	
 
	/*first find the curve speed limit */
 
	int numcurve = 0;
 
	int sum = 0;
 
@@ -349,19 +350,23 @@ static int GetTrainAcceleration(Vehicle 
 
	if (numcurve > 0) sum /= numcurve;
 

	
 
	if ((curvecount[0] != 0 || curvecount[1] != 0) && max_speed > 88) {
 
		int total = curvecount[0] + curvecount[1];
 

	
 
		if (curvecount[0] == 1 && curvecount[1] == 1) {
 
			max_speed = 0xFFFF;
 
			max_speed = absolute_max_speed;
 
		} 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 (max_speed != absolute_max_speed) {
 
		/* Apply the engine's rail type curve speed advantage, if it slowed by curves */
 
		const RailtypeInfo *rti = GetRailTypeInfo(v->u.rail.railtype);
 
		max_speed += (max_speed / 2) * rti->curve_speed;
 
	}
 

	
 
	if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) {
 
		if (TrainShouldStop(v, v->tile)) {
 
			int station_length = GetStationByTile(v->tile)->GetPlatformLength(v->tile, DirToDiagDir(v->direction));
 
			int delta_v;
 

	
0 comments (0 inline, 0 general)