summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2005-04-03 13:57:39 +0000
committerdarkvater <darkvater@openttd.org>2005-04-03 13:57:39 +0000
commit2ac7077571ebf4b9781dc4c934869bdf77f5e9be (patch)
treeaf8f20e2823b731c700cb949df47409bb61b00dc
parent31381af8a076b7451e3067a100fd56d4a10c7c73 (diff)
downloadopenttd-2ac7077571ebf4b9781dc4c934869bdf77f5e9be.tar.xz
(svn r2144) - Fix: AI crash when trying to remove stations with index higher than 256.
-rw-r--r--ai.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/ai.c b/ai.c
index f740cb28d..52c607b20 100644
--- a/ai.c
+++ b/ai.c
@@ -3609,23 +3609,25 @@ return_to_loop:;
static void AiStateRemoveStation(Player *p)
{
// Remove stations that aren't in use by any vehicle
- byte in_use[256], *used;
+ byte *in_use;
+ const byte *used;
const Order *ord;
- Station *st;
- uint tile;
+ const Station *st;
+ TileIndex tile;
// Go to this state when we're done.
p->ai.state = AIS_1;
// Get a list of all stations that are in use by a vehicle
- memset(in_use, 0, sizeof(in_use));
+ in_use = malloc(GetStationPoolSize());
+ memset(in_use, 0, GetStationPoolSize());
FOR_ALL_ORDERS(ord) {
if (ord->type == OT_GOTO_STATION)
in_use[ord->station] = 1;
}
// Go through all stations and delete those that aren't in use
- used=in_use;
+ used = in_use;
FOR_ALL_STATIONS(st) {
if (st->xy != 0 && st->owner == _current_player && !*used &&
( (st->bus_stops != NULL && (tile = st->bus_stops->xy) != 0) ||
@@ -3638,6 +3640,7 @@ static void AiStateRemoveStation(Player *p)
used++;
}
+ free(in_use);
}
static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile)