(svn r18766) -Codechange: Make train acceleration type (rail/elrail/monorail vs maglev) a rail type property

This commit is contained in:
peter1138 2010-01-09 15:33:41 +00:00
parent b9052fff9f
commit 1382964fa0
3 changed files with 28 additions and 16 deletions

View File

@ -141,6 +141,11 @@ struct RailtypeInfo {
*/ */
uint8 cost_multiplier; uint8 cost_multiplier;
/**
* Acceleration type of this rail type
*/
uint8 acceleration_type;
/** /**
* Unique 32 bit rail type identifier * Unique 32 bit rail type identifier
*/ */

View File

@ -81,6 +81,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* cost multiplier */ /* cost multiplier */
8, 8,
/* accelration type */
0,
/* rail type label */ /* rail type label */
'RAIL', 'RAIL',
}, },
@ -153,6 +156,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* cost multiplier */ /* cost multiplier */
12, 12,
/* acceleration type */
0,
/* rail type label */ /* rail type label */
'ELRL', 'ELRL',
}, },
@ -221,6 +227,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* cost multiplier */ /* cost multiplier */
16, 16,
/* acceleration type */
1,
/* rail type label */ /* rail type label */
'MONO', 'MONO',
}, },
@ -289,6 +298,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* cost multiplier */ /* cost multiplier */
24, 24,
/* acceleration type */
2,
/* rail type label */ /* rail type label */
'MGLV', 'MGLV',
}, },

View File

@ -531,10 +531,12 @@ static int GetTrainAcceleration(Train *v, bool mode)
v->max_speed = max_speed; v->max_speed = max_speed;
bool maglev = GetRailTypeInfo(v->railtype)->acceleration_type == 2;
const int area = 120; const int area = 120;
const int friction = 35; //[1e-3] const int friction = 35; //[1e-3]
int resistance; int resistance;
if (v->railtype != RAILTYPE_MAGLEV) { if (!maglev) {
resistance = 13 * mass / 10; resistance = 13 * mass / 10;
resistance += 60 * num; resistance += 60 * num;
resistance += friction * mass * speed / 1000; resistance += friction * mass * speed / 1000;
@ -548,24 +550,17 @@ static int GetTrainAcceleration(Train *v, bool mode)
const int max_te = v->tcache.cached_max_te; // [N] const int max_te = v->tcache.cached_max_te; // [N]
int force; int force;
if (speed > 0) { if (speed > 0) {
switch (v->railtype) { if (!maglev) {
case RAILTYPE_RAIL: force = power / speed; //[N]
case RAILTYPE_ELECTRIC: force *= 22;
case RAILTYPE_MONO: force /= 10;
force = power / speed; //[N] if (mode == AM_ACCEL && force > max_te) force = max_te;
force *= 22; } else {
force /= 10; force = power / 25;
if (mode == AM_ACCEL && force > max_te) force = max_te;
break;
default: NOT_REACHED();
case RAILTYPE_MAGLEV:
force = power / 25;
break;
} }
} else { } else {
/* "kickoff" acceleration */ /* "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); force = max(force, (mass * 8) + resistance);
} }