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

@@ -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) {