(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID

This commit is contained in:
Darkvater 2005-05-05 20:44:52 +00:00
parent df21566f9f
commit 42eb63a7de
2 changed files with 41 additions and 43 deletions

View File

@ -207,7 +207,7 @@ static Vehicle *InitializeVehicle(Vehicle *v)
v->left_coord = INVALID_COORD; v->left_coord = INVALID_COORD;
v->first = NULL; v->first = NULL;
v->next = NULL; v->next = NULL;
v->next_hash = 0xffff; v->next_hash = INVALID_VEHICLE;
v->string_id = 0; v->string_id = 0;
v->next_shared = NULL; v->next_shared = NULL;
v->prev_shared = NULL; v->prev_shared = NULL;
@ -375,15 +375,20 @@ Vehicle *GetFirstVehicleInChain(const Vehicle *v)
Vehicle* u; Vehicle* u;
if (v->first != NULL) { if (v->first != NULL) {
if (v->first->subtype == TS_Front_Engine) { if (v->first->subtype == TS_Front_Engine) return v->first;
return v->first;
} else { DEBUG(misc, 0) ("v->first cache faulty. We shouldn't be here, rebuilding cache!");
DEBUG(misc, 0) ("v->first cache faulty. We shouldn't be here");
}
} }
/* It is the fact (currently) that newly built vehicles do not have
* their ->first pointer set. When this is the case, go up to the
* first engine and set the pointers correctly. Also the first pointer
* is not saved in a savegame, so this has to be fixed up after loading */
/* Find the 'locomotive' or the first wagon in a chain */
while ((u = GetPrevVehicleInChain(v)) != NULL) v = u; while ((u = GetPrevVehicleInChain(v)) != NULL) v = u;
/* Set the first pointer of all vehicles in that chain to the first wagon */
if (v->subtype == TS_Front_Engine) if (v->subtype == TS_Front_Engine)
for (u = (Vehicle *)v; u != NULL; u = u->next) u->first = (Vehicle *)v; for (u = (Vehicle *)v; u != NULL; u = u->next) u->first = (Vehicle *)v;
@ -402,7 +407,7 @@ void DeleteVehicle(Vehicle *v)
DeleteName(v->string_id); DeleteName(v->string_id);
v->type = 0; v->type = 0;
UpdateVehiclePosHash(v, INVALID_COORD, 0); UpdateVehiclePosHash(v, INVALID_COORD, 0);
v->next_hash = 0xffff; v->next_hash = INVALID_VEHICLE;
if (v->orders != NULL) if (v->orders != NULL)
DeleteVehicleOrders(v); DeleteVehicleOrders(v);
@ -414,7 +419,7 @@ void DeleteVehicleChain(Vehicle *v)
Vehicle *u = v; Vehicle *u = v;
v = v->next; v = v->next;
DeleteVehicle(u); DeleteVehicle(u);
} while (v); } while (v != NULL);
} }
@ -1716,40 +1721,36 @@ byte GetDirectionTowards(Vehicle *v, int x, int y)
byte GetVehicleTrackdir(const Vehicle* v) byte GetVehicleTrackdir(const Vehicle* v)
{ {
if (v->vehstatus & VS_CRASHED) if (v->vehstatus & VS_CRASHED) return 0xFF;
return 0xff;
switch(v->type) switch(v->type)
{ {
case VEH_Train: case VEH_Train:
if (v->u.rail.track == 0x80) if (v->u.rail.track == 0x80) /* We'll assume the train is facing outwards */
/* We'll assume the train is facing outwards */
return _dir_to_diag_trackdir[GetDepotDirection(v->tile, TRANSPORT_RAIL)]; /* Train in depot */ return _dir_to_diag_trackdir[GetDepotDirection(v->tile, TRANSPORT_RAIL)]; /* Train in depot */
else if (v->u.rail.track == 0x40)
/* train in tunnel, so just use his direction and assume a diagonal track */ if (v->u.rail.track == 0x40) /* train in tunnel, so just use his direction and assume a diagonal track */
return _dir_to_diag_trackdir[(v->direction>>1)&3]; return _dir_to_diag_trackdir[(v->direction >> 1) & 3];
else
return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.rail.track)][v->direction]; return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.rail.track)][v->direction];
break;
case VEH_Ship: case VEH_Ship:
if (v->u.ship.state == 0x80) if (v->u.ship.state == 0x80) /* We'll assume the ship is facing outwards */
/* We'll assume the ship is facing outwards */
return _dir_to_diag_trackdir[GetDepotDirection(v->tile, TRANSPORT_WATER)]; /* Ship in depot */ return _dir_to_diag_trackdir[GetDepotDirection(v->tile, TRANSPORT_WATER)]; /* Ship in depot */
else
return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.ship.state)][v->direction]; return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.ship.state)][v->direction];
break;
case VEH_Road: case VEH_Road:
if (v->u.road.state == 254) if (v->u.road.state == 254) /* We'll assume the road vehicle is facing outwards */
/* We'll assume the road vehicle is facing outwards */
return _dir_to_diag_trackdir[GetDepotDirection(v->tile, TRANSPORT_ROAD)]; /* Road vehicle in depot */ return _dir_to_diag_trackdir[GetDepotDirection(v->tile, TRANSPORT_ROAD)]; /* Road vehicle in depot */
else if (IsRoadStationTile(v->tile))
/* We'll assume the road vehicle is facing outwards */ if (IsRoadStationTile(v->tile)) /* We'll assume the road vehicle is facing outwards */
return _dir_to_diag_trackdir[GetRoadStationDir(v->tile)]; /* Road vehicle in a station */ return _dir_to_diag_trackdir[GetRoadStationDir(v->tile)]; /* Road vehicle in a station */
else
return _dir_to_diag_trackdir[(v->direction>>1)&3]; return _dir_to_diag_trackdir[(v->direction >> 1) & 3];
case VEH_Aircraft: break;
case VEH_Special: /* case VEH_Aircraft: case VEH_Special: case VEH_Disaster: */
case VEH_Disaster: default: return 0xFF;
default:
return 0xFF;
} }
} }
/* Return value has bit 0x2 set, when the vehicle enters a station. Then, /* Return value has bit 0x2 set, when the vehicle enters a station. Then,

View File

@ -134,7 +134,7 @@ struct Vehicle {
byte type; // type, ie roadven,train,ship,aircraft,special byte type; // type, ie roadven,train,ship,aircraft,special
byte subtype; // subtype (Filled with values from EffectVehicles or TrainSubTypes)(Filled with values from EffectVehicles or TrainSubTypes) byte subtype; // subtype (Filled with values from EffectVehicles or TrainSubTypes)(Filled with values from EffectVehicles or TrainSubTypes)
uint16 index; // NOSAVE: Index in vehicle array VehicleID index; // NOSAVE: Index in vehicle array
Vehicle *next; // next Vehicle *next; // next
Vehicle *first; // NOSAVE: pointer to the first vehicle in the chain Vehicle *first; // NOSAVE: pointer to the first vehicle in the chain
@ -235,9 +235,9 @@ struct Vehicle {
} u; } u;
}; };
#define is_custom_sprite(x) (x >= 0xfd) #define is_custom_sprite(x) (x >= 0xFD)
#define is_custom_firsthead_sprite(x) (x == 0xfd) #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
#define is_custom_secondhead_sprite(x) (x == 0xfe) #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
typedef void VehicleTickProc(Vehicle *v); typedef void VehicleTickProc(Vehicle *v);
typedef void *VehicleFromPosProc(Vehicle *v, void *data); typedef void *VehicleFromPosProc(Vehicle *v, void *data);
@ -378,8 +378,7 @@ static inline bool IsValidVehicle(Vehicle* v)
*/ */
static inline bool IsVehicleIndex(uint index) static inline bool IsVehicleIndex(uint index)
{ {
if (index < GetVehiclePoolSize()) if (index < GetVehiclePoolSize()) return true;
return true;
return false; return false;
} }
@ -389,8 +388,7 @@ static inline Order *GetVehicleOrder(const Vehicle *v, int index)
{ {
Order *order = v->orders; Order *order = v->orders;
if (index < 0) if (index < 0) return NULL;
return NULL;
while (order != NULL && index-- > 0) while (order != NULL && index-- > 0)
order = order->next; order = order->next;
@ -403,8 +401,7 @@ static inline Order *GetLastVehicleOrder(const Vehicle *v)
{ {
Order *order = v->orders; Order *order = v->orders;
if (order == NULL) if (order == NULL) return NULL;
return NULL;
while (order->next != NULL) while (order->next != NULL)
order = order->next; order = order->next;
@ -438,7 +435,7 @@ VARDEF byte _cmd_build_rail_veh_var1;
// for each player, for each vehicle type, keep a list of the vehicles. // for each player, for each vehicle type, keep a list of the vehicles.
//VARDEF Vehicle *_vehicle_arr[8][4]; //VARDEF Vehicle *_vehicle_arr[8][4];
#define INVALID_VEHICLE 0xffff #define INVALID_VEHICLE 0xFFFF
/* A lot of code calls for the invalidation of the status bar, which is widget 5. /* A lot of code calls for the invalidation of the status bar, which is widget 5.
* Best is to have a virtual value for it when it needs to change again */ * Best is to have a virtual value for it when it needs to change again */