mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
(svn r2035) - Remove unneeded realloc()
- Use TileOffsByDir() instead of home brewed table
This commit is contained in:
parent
a9c0a173bf
commit
9655764730
22
train_cmd.c
22
train_cmd.c
@ -81,7 +81,7 @@ static bool TrainShouldStop(Vehicle *v, TileIndex tile)
|
|||||||
//new acceleration
|
//new acceleration
|
||||||
static int GetTrainAcceleration(Vehicle *v, bool mode)
|
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 num = 0; //number of vehicles, change this into the number of axles later
|
||||||
int power = 0;
|
int power = 0;
|
||||||
int mass = 0;
|
int mass = 0;
|
||||||
@ -96,25 +96,24 @@ static int GetTrainAcceleration(Vehicle *v, bool mode)
|
|||||||
int pos = 0;
|
int pos = 0;
|
||||||
int lastpos = -1;
|
int lastpos = -1;
|
||||||
int curvecount[2] = {0, 0};
|
int curvecount[2] = {0, 0};
|
||||||
int *dist = NULL;
|
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
int numcurve = 0;
|
int numcurve = 0;
|
||||||
int i;
|
|
||||||
|
|
||||||
speed *= 10;
|
speed *= 10;
|
||||||
speed /= 16;
|
speed /= 16;
|
||||||
|
|
||||||
//first find the curve speed limit
|
//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 dir = u->direction;
|
||||||
int ndir = u->next->direction;
|
int ndir = u->next->direction;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if ( _curve_neighbours45[dir][i] == ndir) {
|
if ( _curve_neighbours45[dir][i] == ndir) {
|
||||||
curvecount[i]++;
|
curvecount[i]++;
|
||||||
if (lastpos != -1) {
|
if (lastpos != -1) {
|
||||||
dist = realloc(dist, sizeof(int) * ++numcurve);
|
numcurve++;
|
||||||
dist[numcurve - 1] = pos - lastpos;
|
sum += pos - lastpos;
|
||||||
if (pos - lastpos == 1) {
|
if (pos - lastpos == 1) {
|
||||||
max_speed = 88;
|
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 (numcurve > 0) sum /= numcurve;
|
||||||
|
|
||||||
if ((curvecount[0] != 0 || curvecount[1] != 0) && max_speed > 88) {
|
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;
|
max_speed += (max_speed / 2) * v->u.rail.railtype;
|
||||||
|
|
||||||
if (IsTileType(v->tile, MP_STATION) && v->subtype == TS_Front_Engine) {
|
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)) {
|
if (TrainShouldStop(v, v->tile)) {
|
||||||
int station_length = 0;
|
int station_length = 0;
|
||||||
TileIndex tile = v->tile;
|
TileIndex tile = v->tile;
|
||||||
@ -162,7 +152,7 @@ static int GetTrainAcceleration(Vehicle *v, bool mode)
|
|||||||
max_speed = 120;
|
max_speed = 120;
|
||||||
do {
|
do {
|
||||||
station_length++;
|
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));
|
} while (IsTileType(tile, MP_STATION));
|
||||||
|
|
||||||
delta_v = v->cur_speed / (station_length + 1);
|
delta_v = v->cur_speed / (station_length + 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user