(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id

(and should be an uint16, not uint8)
This commit is contained in:
truelight 2005-02-02 16:16:43 +00:00
parent 944bba1031
commit ab3ed5c431
12 changed files with 38 additions and 28 deletions

View File

@ -232,7 +232,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// 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;

View File

@ -1208,7 +1208,7 @@ static bool CheckSubsidised(Station *from, Station *to, byte cargo_type)
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 LoadUnloadVehicle(Vehicle *v)
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 @@ int LoadUnloadVehicle(Vehicle *v)
/* 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 @@ int LoadUnloadVehicle(Vehicle *v)
// 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

View File

@ -756,7 +756,7 @@ void DeleteDestinationFromVehicleOrder(Order dest)
/* 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 &&

View File

@ -173,7 +173,7 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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 @@ static void ProcessRoadVehOrder(Vehicle *v)
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);
{

View File

@ -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
};

View File

@ -254,7 +254,7 @@ static void ProcessShipOrder(Vehicle *v)
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 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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;

View File

@ -9,7 +9,7 @@ typedef struct GoodsEntry {
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 @@ typedef enum RoadStopType {
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;

View File

@ -415,7 +415,7 @@ static void StationInitialize(Station *st, TileIndex tile)
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 @@ static void UpdateStationRating(Station *st)
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 @@ void ModifyStationRatingAround(TileIndex tile, byte owner, int amount, uint radi
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 @@ void BuildOilRig(uint tile)
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 @@ static const byte _goods_desc[] = {
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 @@ static void SaveLoad_STNS(Station *st)
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)

View File

@ -432,7 +432,7 @@ static void DrawStationViewWindow(Window *w)
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));

View File

@ -586,7 +586,7 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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 @@ static bool ProcessTrainOrder(Vehicle *v)
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;

View File

@ -1807,7 +1807,8 @@ const byte _common_veh_desc[] = {
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),

View File

@ -138,7 +138,7 @@ struct Vehicle {
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