(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
authortruelight
Wed, 02 Feb 2005 16:16:43 +0000
changeset 1266 9dc5638fe8cc
parent 1265 0430e635b116
child 1267 cbd68e5e31ac
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
(and should be an uint16, not uint8)
aircraft_cmd.c
economy.c
order_cmd.c
roadveh_cmd.c
saveload.c
ship_cmd.c
station.h
station_cmd.c
station_gui.c
train_cmd.c
vehicle.c
vehicle.h
--- a/aircraft_cmd.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/aircraft_cmd.c	Wed Feb 02 16:16:43 2005 +0000
@@ -232,7 +232,7 @@
 
 //		v->load_unload_time_rem = 0;
 //		v->progress = 0;
-		v->last_station_visited = 0xFFFF;
+		v->last_station_visited = INVALID_STATION;
 //		v->destination_coords = 0;
 
 		v->max_speed = avi->max_speed;
--- a/economy.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/economy.c	Wed Feb 02 16:16:43 2005 +0000
@@ -1208,7 +1208,7 @@
 	return false;
 }
 
-static int32 DeliverGoods(int num_pieces, byte cargo_type, byte source, byte dest, byte days_in_transit)
+static int32 DeliverGoods(int num_pieces, byte cargo_type, uint16 source, uint16 dest, byte days_in_transit)
 {
 	bool subsidised;
 	Station *s_from, *s_to;
@@ -1335,7 +1335,7 @@
 	int unloading_time = 20;
 	Vehicle *u = v;
 	int result = 0;
-	int last_visited;
+	uint16 last_visited;
 	Station *st;
 	GoodsEntry *ge;
 	int t;
@@ -1358,7 +1358,7 @@
 
 		/* unload? */
 		if (v->cargo_count != 0) {
-			if (v->cargo_source != (byte)last_visited && ge->waiting_acceptance & 0x8000) {
+			if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000) {
 				// deliver goods to the station
 				unloading_time += v->cargo_count; /* TTDBUG: bug in original TTD */
 				profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_days);
@@ -1376,7 +1376,7 @@
 					// Goods already waiting at station. Set counters to the worst value.
 					if (v->cargo_days >= ge->enroute_time)
 						ge->enroute_time = v->cargo_days;
-					if ((byte)last_visited != ge->enroute_from)
+					if (last_visited != ge->enroute_from)
 						ge->enroute_from = v->cargo_source;
 				}
 				// Update amount of waiting cargo
--- a/order_cmd.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/order_cmd.c	Wed Feb 02 16:16:43 2005 +0000
@@ -756,7 +756,7 @@
 
 		/* Forget about this station if this station is removed */
 		if (v->last_station_visited == dest.station && dest.type == OT_GOTO_STATION)
-			v->last_station_visited = 0xFFFF;
+			v->last_station_visited = INVALID_STATION;
 
 		/* Check the current order */
 		if (v->current_order.type    == dest.type &&
--- a/roadveh_cmd.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/roadveh_cmd.c	Wed Feb 02 16:16:43 2005 +0000
@@ -173,7 +173,7 @@
 		v->u.road.slotindex = 0;
 		v->u.road.slot_age = 0;
 
-		v->last_station_visited = 0xFFFF;
+		v->last_station_visited = INVALID_STATION;
 		v->max_speed = rvi->max_speed;
 		v->engine_type = (byte)p1;
 
@@ -639,7 +639,7 @@
 
 	if (order->type == OT_GOTO_STATION) {
 		if (order->station == v->last_station_visited)
-			v->last_station_visited = 0xFFFF;
+			v->last_station_visited = INVALID_STATION;
 		st = GetStation(order->station);
 
 		{
--- a/saveload.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/saveload.c	Wed Feb 02 16:16:43 2005 +0000
@@ -7,8 +7,8 @@
 #include "saveload.h"
 
 enum {
-	SAVEGAME_MAJOR_VERSION = 6,
-	SAVEGAME_MINOR_VERSION = 1,
+	SAVEGAME_MAJOR_VERSION = 7,
+	SAVEGAME_MINOR_VERSION = 0,
 
 	SAVEGAME_LOADABLE_VERSION = (SAVEGAME_MAJOR_VERSION << 8) + SAVEGAME_MINOR_VERSION
 };
--- a/ship_cmd.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/ship_cmd.c	Wed Feb 02 16:16:43 2005 +0000
@@ -254,7 +254,7 @@
 		const Station *st;
 
 		if (order->station == v->last_station_visited)
-			v->last_station_visited = 0xFFFF;
+			v->last_station_visited = INVALID_STATION;
 
 		st = GetStation(order->station);
 		if (st->dock_tile != 0) {
@@ -919,7 +919,7 @@
 		v->cargo_cap = svi->capacity;
 		v->value = value;
 
-		v->last_station_visited = 0xFFFF;
+		v->last_station_visited = INVALID_STATION;
 		v->max_speed = svi->max_speed;
 		v->engine_type = (byte)p1;
 
--- a/station.h	Wed Feb 02 15:45:53 2005 +0000
+++ b/station.h	Wed Feb 02 16:16:43 2005 +0000
@@ -9,7 +9,7 @@
 	uint16 waiting_acceptance;
 	byte days_since_pickup;
 	byte rating;
-	byte enroute_from;
+	uint16 enroute_from;
 	byte enroute_time;
 	byte last_speed;
 	byte last_age;
@@ -20,10 +20,13 @@
 	RS_TRUCK
 } RoadStopType;
 
-enum { NUM_ROAD_STOPS = 250 };
-enum { ROAD_STOP_LIMIT = 8 };
-enum { NUM_SLOTS = 2 };
-enum { INVALID_SLOT = 0xFFFF };
+enum {
+	INVALID_STATION = 0xFFFF,
+	INVALID_SLOT = 0xFFFF,
+	NUM_SLOTS = 2,
+	ROAD_STOP_LIMIT = 8,
+	NUM_ROAD_STOPS = 250,
+};
 
 typedef struct RoadStop {
 	TileIndex xy;
--- a/station_cmd.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/station_cmd.c	Wed Feb 02 16:16:43 2005 +0000
@@ -415,7 +415,7 @@
 	for(i=0,ge=st->goods; i!=NUM_CARGO; i++, ge++) {
 		ge->waiting_acceptance = 0;
 		ge->days_since_pickup = 0;
-		ge->enroute_from = 0xFF;
+		ge->enroute_from = INVALID_STATION;
 		ge->rating = 175;
 		ge->last_speed = 0;
 		ge->last_age = 0xFF;
@@ -2447,7 +2447,7 @@
 
 	ge = st->goods;
 	do {
-		if (ge->enroute_from != 0xFF) {
+		if (ge->enroute_from != INVALID_STATION) {
 			byte_inc_sat(&ge->enroute_time);
 			byte_inc_sat(&ge->days_since_pickup);
 
@@ -2589,7 +2589,7 @@
 				DistanceManhattan(tile, st->xy) <= radius) {
 			ge = st->goods;
 			for(i=0; i!=NUM_CARGO; i++,ge++) {
-				if (ge->enroute_from != 0xFF) {
+				if (ge->enroute_from != INVALID_STATION) {
 					ge->rating = clamp(ge->rating + amount, 0, 255);
 				}
 			}
@@ -2808,7 +2808,7 @@
 			for(j=0; j!=NUM_CARGO; j++) {
 				st->goods[j].waiting_acceptance = 0;
 				st->goods[j].days_since_pickup = 0;
-				st->goods[j].enroute_from = 0xFF;
+				st->goods[j].enroute_from = INVALID_STATION;
 				st->goods[j].rating = 175;
 				st->goods[j].last_speed = 0;
 				st->goods[j].last_age = 255;
@@ -2998,7 +2998,8 @@
 	SLE_VAR(GoodsEntry,waiting_acceptance,SLE_UINT16),
 	SLE_VAR(GoodsEntry,days_since_pickup,	SLE_UINT8),
 	SLE_VAR(GoodsEntry,rating,						SLE_UINT8),
-	SLE_VAR(GoodsEntry,enroute_from,			SLE_UINT8),
+	SLE_CONDVAR(GoodsEntry,enroute_from,			SLE_FILE_U8 | SLE_VAR_U16, 0, 6),
+	SLE_CONDVAR(GoodsEntry,enroute_from,			SLE_UINT16, 7, 255),
 	SLE_VAR(GoodsEntry,enroute_time,			SLE_UINT8),
 	SLE_VAR(GoodsEntry,last_speed,				SLE_UINT8),
 	SLE_VAR(GoodsEntry,last_age,					SLE_UINT8),
@@ -3012,8 +3013,13 @@
 	int i;
 
 	SlObject(st, _station_desc);
-	for (i = 0; i != NUM_CARGO; i++)
+	for (i = 0; i != NUM_CARGO; i++) {
 		SlObject(&st->goods[i], _goods_desc);
+
+		/* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */
+		if (_sl.full_version < 0x700 && st->goods[i].enroute_from == 0xFF)
+			st->goods[i].enroute_from = 0xFFFF;
+	}
 }
 
 static void Save_STNS(void)
--- a/station_gui.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/station_gui.c	Wed Feb 02 16:16:43 2005 +0000
@@ -432,7 +432,7 @@
 
 		y = 77;
 		for(i=0; i!=NUM_CARGO; i++) {
-			if (st->goods[i].enroute_from != 0xFF) {
+			if (st->goods[i].enroute_from != INVALID_STATION) {
 				SetDParam(0, _cargoc.names_s[i]);
 				SetDParam(2, st->goods[i].rating * 101 >> 8);
 				SetDParam(1, STR_3035_APPALLING + (st->goods[i].rating >> 5));
--- a/train_cmd.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/train_cmd.c	Wed Feb 02 16:16:43 2005 +0000
@@ -586,7 +586,7 @@
 			v->cargo_cap = rvi->capacity;
 			v->max_speed = rvi->max_speed;
 			v->value = value;
-			v->last_station_visited = 0xFFFF;
+			v->last_station_visited = INVALID_STATION;
 			v->dest_tile = 0;
 
 			v->engine_type = (byte)p1;
@@ -1938,7 +1938,7 @@
 	switch (order->type) {
 		case OT_GOTO_STATION:
 			if (order->station == v->last_station_visited)
-				v->last_station_visited = 0xFFFF;
+				v->last_station_visited = INVALID_STATION;
 			v->dest_tile = GetStation(order->station)->xy;
 			result = CheckReverseTrain(v);
 			break;
--- a/vehicle.c	Wed Feb 02 15:45:53 2005 +0000
+++ b/vehicle.c	Wed Feb 02 16:16:43 2005 +0000
@@ -1807,7 +1807,8 @@
 
 	SLE_VAR(Vehicle,cargo_type,				SLE_UINT8),
 	SLE_VAR(Vehicle,cargo_days,				SLE_UINT8),
-	SLE_VAR(Vehicle,cargo_source,			SLE_UINT8),
+	SLE_CONDVAR(Vehicle,cargo_source,			SLE_FILE_U8 | SLE_VAR_U16, 0, 6),
+	SLE_CONDVAR(Vehicle,cargo_source,			SLE_UINT16, 7, 255),
 	SLE_VAR(Vehicle,cargo_cap,				SLE_UINT16),
 	SLE_VAR(Vehicle,cargo_count,			SLE_UINT16),
 
--- a/vehicle.h	Wed Feb 02 15:45:53 2005 +0000
+++ b/vehicle.h	Wed Feb 02 16:16:43 2005 +0000
@@ -138,7 +138,7 @@
 
 	byte cargo_type;	// type of cargo this vehicle is carrying
 	byte cargo_days; // how many days have the pieces been in transit
-	byte cargo_source;// source of cargo
+	uint16 cargo_source;// source of cargo
 	uint16 cargo_cap;	// total capacity
 	uint16 cargo_count;// how many pieces are used