summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2006-04-18 08:50:17 +0000
committercelestar <celestar@openttd.org>2006-04-18 08:50:17 +0000
commite75e4e8f74614e360414c7ec43899b8c461c911f (patch)
tree30ec24c2a1d82c9e46e78489ed951320b67741d9
parent62f7907d3a5210160a1a3bf134e95213382c9c90 (diff)
downloadopenttd-e75e4e8f74614e360414c7ec43899b8c461c911f.tar.xz
(svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
-Negative side effect: upon loading old games, stations whose last vehicle was a station have (temporarily) lower ratings. -Positive side effect: station.h no longer includes vehicle.h (breaks the station.h->vehicle.h->rail.h chain)
-rw-r--r--economy.c2
-rw-r--r--oldloader.c2
-rw-r--r--openttd.c7
-rw-r--r--saveload.c2
-rw-r--r--station.h3
-rw-r--r--station_cmd.c10
-rw-r--r--vehicle.h1
7 files changed, 17 insertions, 10 deletions
diff --git a/economy.c b/economy.c
index 2d4d30aad..7e7446b46 100644
--- a/economy.c
+++ b/economy.c
@@ -1435,7 +1435,7 @@ int LoadUnloadVehicle(Vehicle *v)
v->cargo_source = ge->enroute_from;
v->cargo_days = ge->enroute_time;
result |= 2;
- st->last_vehicle = v->index;
+ st->last_vehicle_type = v->type;
}
}
diff --git a/oldloader.c b/oldloader.c
index 31f2ab293..be129c2c7 100644
--- a/oldloader.c
+++ b/oldloader.c
@@ -682,7 +682,7 @@ static const OldChunks station_chunk[] = {
OCL_SVAR( OC_UINT8, Station, blocked_months_obsolete ),
OCL_NULL( 1 ), // Unknown
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Station, airport_flags ),
- OCL_SVAR( OC_UINT16, Station, last_vehicle ),
+ OCL_NULL( 2 ), // last_vehicle. now last_vehicle_type
OCL_NULL( 4 ), // Junk at end of chunk
diff --git a/openttd.c b/openttd.c
index 0818b03d4..e924a6ea2 100644
--- a/openttd.c
+++ b/openttd.c
@@ -1403,6 +1403,13 @@ bool AfterLoadGame(void)
}
}
+ if (CheckSavegameVersion(26)) {
+ Station *st;
+ FOR_ALL_STATIONS(st) {
+ st->last_vehicle_type = VEH_Invalid;
+ }
+ }
+
FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index);
return true;
diff --git a/saveload.c b/saveload.c
index 475a7675c..39e3d2591 100644
--- a/saveload.c
+++ b/saveload.c
@@ -30,7 +30,7 @@
#include "variables.h"
#include <setjmp.h>
-const uint16 SAVEGAME_VERSION = 25;
+const uint16 SAVEGAME_VERSION = 26;
uint16 _sl_version; /// the major savegame version identifier
byte _sl_minor_version; /// the minor savegame version, DO NOT USE!
diff --git a/station.h b/station.h
index e448c14fa..2869708d5 100644
--- a/station.h
+++ b/station.h
@@ -7,7 +7,6 @@
#include "pool.h"
#include "sprite.h"
#include "tile.h"
-#include "vehicle.h"
#include "newgrf_station.h"
typedef struct GoodsEntry {
@@ -72,7 +71,7 @@ struct Station {
uint32 airport_flags;
StationID index;
- VehicleID last_vehicle;
+ byte last_vehicle_type;
GoodsEntry goods[NUM_CARGO];
/* Stuff that is no longer used, but needed for conversion */
diff --git a/station_cmd.c b/station_cmd.c
index a6fdad852..62d71ccb8 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -467,7 +467,7 @@ static void StationInitialize(Station *st, TileIndex tile)
st->delete_ctr = 0;
st->facilities = 0;
- st->last_vehicle = INVALID_VEHICLE;
+ st->last_vehicle_type = VEH_Invalid;
for (ge = st->goods; ge != endof(st->goods); ge++) {
ge->waiting_acceptance = 0;
@@ -2317,8 +2317,7 @@ static void UpdateStationRating(Station *st)
{
byte days = ge->days_since_pickup;
- if (st->last_vehicle != INVALID_VEHICLE &&
- GetVehicle(st->last_vehicle)->type == VEH_Ship)
+ if (st->last_vehicle_type == VEH_Ship)
days >>= 2;
(days > 21) ||
(rating += 25, days > 12) ||
@@ -2644,7 +2643,7 @@ void BuildOilRig(TileIndex tile)
st->time_since_load = 255;
st->time_since_unload = 255;
st->delete_ctr = 0;
- st->last_vehicle = INVALID_VEHICLE;
+ st->last_vehicle_type = VEH_Invalid;
st->facilities = FACIL_AIRPORT | FACIL_DOCK;
st->build_date = _date;
@@ -2817,7 +2816,8 @@ static const SaveLoad _station_desc[] = {
SLE_CONDVAR(Station,airport_flags, SLE_VAR_U32 | SLE_FILE_U16, 0, 2),
SLE_CONDVAR(Station,airport_flags, SLE_UINT32, 3, SL_MAX_VERSION),
- SLE_VAR(Station,last_vehicle, SLE_UINT16),
+ SLE_CONDNULL(2, 0, 25), /* Ex last-vehicle */
+ SLE_CONDVAR(Station,last_vehicle_type, SLE_UINT8 , 26, SL_MAX_VERSION),
// Was custom station class and id
SLE_CONDNULL(2, 3, 25),
diff --git a/vehicle.h b/vehicle.h
index b82319e63..e6a1f5dbf 100644
--- a/vehicle.h
+++ b/vehicle.h
@@ -8,6 +8,7 @@
#include "rail.h"
enum {
+ VEH_Invalid = 0,
VEH_Train = 0x10,
VEH_Road = 0x11,
VEH_Ship = 0x12,