mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r10756) -Codechange: use vehicle->IsValid in favour of IsValidVehicle(vehicle).
This commit is contained in:
parent
032de036dd
commit
99da45988a
@ -426,7 +426,7 @@ static void AiStateCheckReplaceVehicle(Player *p)
|
||||
{
|
||||
const Vehicle* v = p->ai.cur_veh;
|
||||
|
||||
if (!IsValidVehicle(v) ||
|
||||
if (!v->IsValid() ||
|
||||
v->owner != _current_player ||
|
||||
v->type > VEH_SHIP ||
|
||||
_veh_check_replace_proc[v->type - VEH_TRAIN](p, v) == INVALID_ENGINE) {
|
||||
@ -443,7 +443,7 @@ static void AiStateDoReplaceVehicle(Player *p)
|
||||
|
||||
p->ai.state = AIS_VEH_LOOP;
|
||||
// vehicle is not owned by the player anymore, something went very wrong.
|
||||
if (!IsValidVehicle(v) || v->owner != _current_player) return;
|
||||
if (!v->IsValid() || v->owner != _current_player) return;
|
||||
_veh_do_replace_proc[v->type - VEH_TRAIN](p);
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ static void RunVehicleDayProc(uint daytick)
|
||||
for (i = daytick; i < total; i += DAY_TICKS) {
|
||||
Vehicle *v = GetVehicle(i);
|
||||
|
||||
if (IsValidVehicle(v)) _on_new_vehicle_day_proc[v->type](v);
|
||||
if (v->IsValid()) _on_new_vehicle_day_proc[v->type](v);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1
|
||||
*/
|
||||
void RemoveVehicleFromGroup(const Vehicle *v)
|
||||
{
|
||||
if (!IsValidVehicle(v) || !(v->HasFront() && v->IsPrimaryVehicle())) return;
|
||||
if (!v->IsValid() || !(v->HasFront() && v->IsPrimaryVehicle())) return;
|
||||
|
||||
if (!IsDefaultGroupID(v->group_id)) DecreaseGroupNumVehicle(v->group_id);
|
||||
}
|
||||
@ -374,7 +374,7 @@ void SetTrainGroupID(Vehicle *v, GroupID new_g)
|
||||
{
|
||||
if (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g)) return;
|
||||
|
||||
assert(IsValidVehicle(v) && v->type == VEH_TRAIN && IsFrontEngine(v));
|
||||
assert(v->IsValid() && v->type == VEH_TRAIN && IsFrontEngine(v));
|
||||
|
||||
for (Vehicle *u = v; u != NULL; u = u->next) {
|
||||
if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g);
|
||||
@ -396,7 +396,7 @@ void SetTrainGroupID(Vehicle *v, GroupID new_g)
|
||||
*/
|
||||
void UpdateTrainGroupID(Vehicle *v)
|
||||
{
|
||||
assert(IsValidVehicle(v) && v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v)));
|
||||
assert(v->IsValid() && v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v)));
|
||||
|
||||
GroupID new_g = IsFrontEngine(v) ? v->group_id : (GroupID)DEFAULT_GROUP;
|
||||
for (Vehicle *u = v; u != NULL; u = u->next) {
|
||||
|
@ -557,7 +557,7 @@ static void GroupWndProc(Window *w, WindowEvent *e)
|
||||
|
||||
gv->vehicle_sel = v->index;
|
||||
|
||||
if (IsValidVehicle(v)) {
|
||||
if (v->IsValid()) {
|
||||
SetObjectToPlaceWnd(v->GetImage(DIR_W), GetVehiclePalette(v), 4, w);
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ Vehicle *ForceAllocateSpecialVehicle()
|
||||
if (v->index >= (1 << Vehicle_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES)
|
||||
return NULL;
|
||||
|
||||
if (!IsValidVehicle(v)) return InitializeVehicle(v);
|
||||
if (!v->IsValid()) return InitializeVehicle(v);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -358,7 +358,7 @@ static Vehicle *AllocateSingleVehicle(VehicleID *skip_vehicles)
|
||||
if (*skip_vehicles < (_Vehicle_pool.GetSize() - offset)) { // make sure the offset in the array is not larger than the array itself
|
||||
for (v = GetVehicle(offset + *skip_vehicles); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
|
||||
(*skip_vehicles)++;
|
||||
if (!IsValidVehicle(v)) return InitializeVehicle(v);
|
||||
if (!v->IsValid()) return InitializeVehicle(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -432,6 +432,8 @@ struct Vehicle {
|
||||
* Calls the tick handler of the vehicle
|
||||
*/
|
||||
virtual void Tick() = 0;
|
||||
|
||||
bool IsValid() const { return this->type != VEH_INVALID; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -634,14 +636,6 @@ static inline uint GetNumVehicles()
|
||||
return GetVehiclePoolSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Vehicle really exists.
|
||||
*/
|
||||
static inline bool IsValidVehicle(const Vehicle *v)
|
||||
{
|
||||
return v->type != VEH_INVALID;
|
||||
}
|
||||
|
||||
void DestroyVehicle(Vehicle *v);
|
||||
|
||||
static inline void DeleteVehicle(Vehicle *v)
|
||||
@ -668,7 +662,7 @@ static inline bool IsPlayerBuildableVehicleType(const Vehicle *v)
|
||||
return IsPlayerBuildableVehicleType(v->type);
|
||||
}
|
||||
|
||||
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (IsValidVehicle(v))
|
||||
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (v->IsValid())
|
||||
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
|
||||
|
||||
/**
|
||||
@ -678,7 +672,7 @@ static inline bool IsPlayerBuildableVehicleType(const Vehicle *v)
|
||||
*/
|
||||
static inline bool IsValidVehicleID(uint index)
|
||||
{
|
||||
return index < GetVehiclePoolSize() && IsValidVehicle(GetVehicle(index));
|
||||
return index < GetVehiclePoolSize() && GetVehicle(index)->IsValid();
|
||||
}
|
||||
|
||||
/* Returns order 'index' of a vehicle or NULL when it doesn't exists */
|
||||
|
Loading…
Reference in New Issue
Block a user