Changeset - r14205:9013b6f06a1e
[Not reviewed]
master
0 3 0
peter1138 - 15 years ago 2010-01-09 15:33:41
peter1138@openttd.org
(svn r18766) -Codechange: Make train acceleration type (rail/elrail/monorail vs maglev) a rail type property
3 files changed with 28 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/rail.h
Show inline comments
 
@@ -139,12 +139,17 @@ struct RailtypeInfo {
 
	/**
 
	 * Cost multiplier for building this rail type
 
	 */
 
	uint8 cost_multiplier;
 

	
 
	/**
 
	 * Acceleration type of this rail type
 
	 */
 
	uint8 acceleration_type;
 

	
 
	/**
 
	 * Unique 32 bit rail type identifier
 
	 */
 
	RailTypeLabel label;
 
};
 

	
 

	
src/table/railtypes.h
Show inline comments
 
@@ -78,12 +78,15 @@ static const RailtypeInfo _original_rail
 
		/* flags */
 
		RTFB_NONE,
 

	
 
		/* cost multiplier */
 
		8,
 

	
 
		/* accelration type */
 
		0,
 

	
 
		/* rail type label */
 
		'RAIL',
 
	},
 

	
 
	/** Electrified railway */
 
	{ // Main Sprites
 
@@ -150,12 +153,15 @@ static const RailtypeInfo _original_rail
 
		/* flags */
 
		RTFB_CATENARY,
 

	
 
		/* cost multiplier */
 
		12,
 

	
 
		/* acceleration type */
 
		0,
 

	
 
		/* rail type label */
 
		'ELRL',
 
	},
 

	
 
	/** Monorail */
 
	{ // Main Sprites
 
@@ -218,12 +224,15 @@ static const RailtypeInfo _original_rail
 
		/* flags */
 
		RTFB_NONE,
 

	
 
		/* cost multiplier */
 
		16,
 

	
 
		/* acceleration type */
 
		1,
 

	
 
		/* rail type label */
 
		'MONO',
 
	},
 

	
 
	/** Maglev */
 
	{ // Main sprites
 
@@ -286,12 +295,15 @@ static const RailtypeInfo _original_rail
 
		/* flags */
 
		RTFB_NONE,
 

	
 
		/* cost multiplier */
 
		24,
 

	
 
		/* acceleration type */
 
		2,
 

	
 
		/* rail type label */
 
		'MGLV',
 
	},
 
};
 

	
 
#endif /* RAILTYPES_H */
src/train_cmd.cpp
Show inline comments
 
@@ -528,16 +528,18 @@ static int GetTrainAcceleration(Train *v
 
			incl -= u->tcache.cached_veh_weight * 20 * _settings_game.vehicle.train_slope_steepness;
 
		}
 
	}
 

	
 
	v->max_speed = max_speed;
 

	
 
	bool maglev = GetRailTypeInfo(v->railtype)->acceleration_type == 2;
 

	
 
	const int area = 120;
 
	const int friction = 35; //[1e-3]
 
	int resistance;
 
	if (v->railtype != RAILTYPE_MAGLEV) {
 
	if (!maglev) {
 
		resistance = 13 * mass / 10;
 
		resistance += 60 * num;
 
		resistance += friction * mass * speed / 1000;
 
		resistance += (area * drag_coeff * speed * speed) / 10000;
 
	} else {
 
		resistance = (area * (drag_coeff / 2) * speed * speed) / 10000;
 
@@ -545,30 +547,23 @@ static int GetTrainAcceleration(Train *v
 
	resistance += incl;
 
	resistance *= 4; //[N]
 

	
 
	const int max_te = v->tcache.cached_max_te; // [N]
 
	int force;
 
	if (speed > 0) {
 
		switch (v->railtype) {
 
			case RAILTYPE_RAIL:
 
			case RAILTYPE_ELECTRIC:
 
			case RAILTYPE_MONO:
 
				force = power / speed; //[N]
 
				force *= 22;
 
				force /= 10;
 
				if (mode == AM_ACCEL && force > max_te) force = max_te;
 
				break;
 

	
 
			default: NOT_REACHED();
 
			case RAILTYPE_MAGLEV:
 
				force = power / 25;
 
				break;
 
		if (!maglev) {
 
			force = power / speed; //[N]
 
			force *= 22;
 
			force /= 10;
 
			if (mode == AM_ACCEL && force > max_te) force = max_te;
 
		} else {
 
			force = power / 25;
 
		}
 
	} else {
 
		/* "kickoff" acceleration */
 
		force = (mode == AM_ACCEL && v->railtype != RAILTYPE_MAGLEV) ? min(max_te, power) : power;
 
		force = (mode == AM_ACCEL && !maglev) ? min(max_te, power) : power;
 
		force = max(force, (mass * 8) + resistance);
 
	}
 

	
 
	if (mode == AM_ACCEL) {
 
		return (force - resistance) / (mass * 2);
 
	} else {
0 comments (0 inline, 0 general)