Exclude virtual trains from various vehicle list iterations

This commit is contained in:
Jonathan G Rennison 2019-05-27 17:56:41 +01:00
parent 3c2ebc4588
commit 96f000226e
9 changed files with 17 additions and 14 deletions

View File

@ -556,7 +556,7 @@ static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
Vehicle *target;
FOR_ALL_VEHICLES(target) {
if (target->IsGroundVehicle()) {
if (target->IsGroundVehicle() && !HasBit(target->subtype, GVSF_VIRTUAL)) {
if (Delta(target->x_pos, v->x_pos) + Delta(target->y_pos, v->y_pos) <= 12 * (int)TILE_SIZE) {
target->breakdown_ctr = 5;
target->breakdown_delay = 0xF0;

View File

@ -782,7 +782,7 @@ static CompanyID GetPreviewCompany(Engine *e)
/* Check whether the company uses similar vehicles */
Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (v->owner != c->index || v->type != e->type) continue;
if (v->owner != c->index || v->type != e->type || HasBit(v->subtype, GVSF_VIRTUAL)) continue;
if (!v->GetEngine()->CanCarryCargo() || !HasBit(cargomask, v->cargo_type)) continue;
best_hist = c->old_economy[0].performance_history;
@ -933,7 +933,7 @@ static void NewVehicleAvailable(Engine *e)
c->block_preview = 20;
FOR_ALL_VEHICLES(v) {
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
if ((v->type == VEH_TRAIN && !HasBit(v->subtype, GVSF_VIRTUAL)) || v->type == VEH_ROAD || v->type == VEH_SHIP ||
(v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft())) {
if (v->owner == c->index && v->engine_type == index) {
/* The user did prove me wrong, so restore old value */

View File

@ -209,7 +209,7 @@ void GroupStatistics::Clear()
const Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (v->IsPrimaryVehicle() && v->age > VEHICLE_PROFIT_MIN_AGE) GroupStatistics::VehicleReachedProfitAge(v);
if (v->IsPrimaryVehicle() && v->age > VEHICLE_PROFIT_MIN_AGE && !HasBit(v->subtype, GVSF_VIRTUAL)) GroupStatistics::VehicleReachedProfitAge(v);
}
}

View File

@ -2499,7 +2499,7 @@ static int WhoCanServiceIndustry(Industry *ind)
/* Check whether it accepts the right kind of cargo */
bool c_accepts = false;
bool c_produces = false;
if (v->type == VEH_TRAIN && v->IsFrontEngine()) {
if (v->type == VEH_TRAIN && v->IsFrontEngine() && !HasBit(v->subtype, GVSF_VIRTUAL)) {
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces);
}

View File

@ -194,7 +194,7 @@ static void FixAllReservations()
assert(!_settings_game.economy.infrastructure_sharing[VEH_TRAIN]);
Train *v;
FOR_ALL_TRAINS(v) {
if (!v->IsPrimaryVehicle() || (v->vehstatus & VS_CRASHED) != 0) continue;
if (!v->IsPrimaryVehicle() || (v->vehstatus & VS_CRASHED) != 0 || HasBit(v->subtype, GVSF_VIRTUAL)) continue;
/* It might happen that the train reserved additional tracks,
* but FollowTrainReservation can't detect those because they are no longer reachable.
* detect this by first finding the end of the reservation,
@ -237,7 +237,7 @@ bool CheckSharingChangePossible(VehicleType type)
StringID error_message = STR_NULL;
Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (type != v->type) continue;
if (type != v->type || HasBit(v->subtype, GVSF_VIRTUAL)) continue;
if (v->Previous() != nullptr) continue;
/* Check vehicle positiion */

View File

@ -1581,7 +1581,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
/* Go through all vehicles and count the type of vehicles */
FOR_ALL_VEHICLES(v) {
if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle() || HasBit(v->subtype, GVSF_VIRTUAL)) continue;
byte type = 0;
switch (v->type) {
case VEH_TRAIN: type = NETWORK_VEH_TRAIN; break;
@ -1669,7 +1669,7 @@ static void NetworkAutoCleanCompanies()
const Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle() || HasBit(v->subtype, GVSF_VIRTUAL)) continue;
vehicles_in_company[v->owner]++;
}
}

View File

@ -89,7 +89,7 @@ void CheckTrainsLengths()
bool first = true;
FOR_ALL_TRAINS(v) {
if (v->First() == v && !(v->vehstatus & VS_CRASHED)) {
if (v->First() == v && !(v->vehstatus & VS_CRASHED) && !v->IsVirtual()) {
for (const Train *u = v, *w = v->Next(); w != nullptr; u = w, w = w->Next()) {
if (u->track != TRACK_BIT_DEPOT) {
if ((w->track != TRACK_BIT_DEPOT &&
@ -862,7 +862,8 @@ static CommandCost CmdBuildRailWagon(TileIndex tile, DoCommandFlag flags, const
w->engine_type == e->index && ///< Same type
w->First() != v && ///< Don't connect to ourself
!(w->vehstatus & VS_CRASHED) && ///< Not crashed/flooded
w->owner == v->owner) { ///< Same owner
w->owner == v->owner && ///< Same owner
!w->IsVirtual()) { ///< Not virtual
DoCommand(0, v->index | 1 << 20, w->Last()->index, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
break;
}
@ -879,7 +880,8 @@ static void NormalizeTrainVehInDepot(const Train *u)
FOR_ALL_TRAINS(v) {
if (v->IsFreeWagon() && v->tile == u->tile &&
v->track == TRACK_BIT_DEPOT &&
v->owner == u->owner) {
v->owner == u->owner &&
!v->IsVirtual()) {
if (DoCommand(0, v->index | 1 << 20, u->index, DC_EXEC,
CMD_MOVE_RAIL_VEHICLE).Failed())
break;
@ -1022,7 +1024,7 @@ static Train *FindGoodVehiclePos(const Train *src)
Train *dst;
FOR_ALL_TRAINS(dst) {
if (dst->IsFreeWagon() && dst->tile == tile && !(dst->vehstatus & VS_CRASHED) && dst->owner == src->owner) {
if (dst->IsFreeWagon() && dst->tile == tile && !(dst->vehstatus & VS_CRASHED) && dst->owner == src->owner && !dst->IsVirtual()) {
/* check so all vehicles in the line have the same engine. */
Train *t = dst;
while (t->engine_type == eng) {

View File

@ -38,7 +38,7 @@ void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p
const Vehicle *found = nullptr;
const Train *t;
FOR_ALL_TRAINS(t) {
if (t->IsFrontEngine() && t->tile == tile && t->IsStoppedInDepot()) {
if (t->IsFrontEngine() && t->tile == tile && t->IsStoppedInDepot() && !t->IsVirtual()) {
if (found != nullptr) return; // must be exactly one.
found = t;
}

View File

@ -79,6 +79,7 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine
/* General tests for all vehicle types */
if (v->type != type) continue;
if (v->tile != tile) continue;
if (HasBit(v->subtype, GVSF_VIRTUAL)) continue;
switch (type) {
case VEH_TRAIN: {