diff options
author | tron <tron@openttd.org> | 2005-03-23 08:24:13 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-03-23 08:24:13 +0000 |
commit | b19553574e336faa9e124577405052acdb3bf7db (patch) | |
tree | e753676487913d74a8a65442a0645a3cda67d2e9 | |
parent | fbc2eacadedf6638ec483d4a1523b0d88b2330c9 (diff) | |
download | openttd-b19553574e336faa9e124577405052acdb3bf7db.tar.xz |
(svn r2035) - Remove unneeded realloc()
- Use TileOffsByDir() instead of home brewed table
-rw-r--r-- | train_cmd.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/train_cmd.c b/train_cmd.c index 22b9801d4..09b2ce019 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -81,7 +81,7 @@ static bool TrainShouldStop(Vehicle *v, TileIndex tile) //new acceleration static int GetTrainAcceleration(Vehicle *v, bool mode) { - Vehicle *u = v; + const Vehicle *u; int num = 0; //number of vehicles, change this into the number of axles later int power = 0; int mass = 0; @@ -96,25 +96,24 @@ static int GetTrainAcceleration(Vehicle *v, bool mode) int pos = 0; int lastpos = -1; int curvecount[2] = {0, 0}; - int *dist = NULL; int sum = 0; int numcurve = 0; - int i; speed *= 10; speed /= 16; //first find the curve speed limit - for (; u->next != NULL; u = u->next, pos++) { + for (u = v; u->next != NULL; u = u->next, pos++) { int dir = u->direction; int ndir = u->next->direction; + int i; for (i = 0; i < 2; i++) { if ( _curve_neighbours45[dir][i] == ndir) { curvecount[i]++; if (lastpos != -1) { - dist = realloc(dist, sizeof(int) * ++numcurve); - dist[numcurve - 1] = pos - lastpos; + numcurve++; + sum += pos - lastpos; if (pos - lastpos == 1) { max_speed = 88; } @@ -130,11 +129,6 @@ static int GetTrainAcceleration(Vehicle *v, bool mode) } } - for (i = 0; i < numcurve; i++) sum += dist[i]; - - free(dist); - dist = NULL; - if (numcurve > 0) sum /= numcurve; if ((curvecount[0] != 0 || curvecount[1] != 0) && max_speed > 88) { @@ -150,10 +144,6 @@ static int GetTrainAcceleration(Vehicle *v, bool mode) max_speed += (max_speed / 2) * v->u.rail.railtype; if (IsTileType(v->tile, MP_STATION) && v->subtype == TS_Front_Engine) { - static const TileIndexDiffC _station_dir_from_vdir[] = { - {0, 0}, {-1, 0}, {0, 0}, {0, 1}, {0, 0}, {1, 0}, {0, 0}, {0, -1} - }; - if (TrainShouldStop(v, v->tile)) { int station_length = 0; TileIndex tile = v->tile; @@ -162,7 +152,7 @@ static int GetTrainAcceleration(Vehicle *v, bool mode) max_speed = 120; do { station_length++; - tile = TILE_ADD(tile, ToTileIndexDiff(_station_dir_from_vdir[v->direction])); + tile = TILE_ADD(tile, TileOffsByDir(v->direction / 2)); } while (IsTileType(tile, MP_STATION)); delta_v = v->cur_speed / (station_length + 1); |