Index: train_cmd.c =================================================================== --- train_cmd.c (revision 11224) +++ train_cmd.c (working copy) @@ -614,7 +614,8 @@ FOR_ALL_VEHICLES(w) { if (w->type == VEH_Train && w->tile == tile && - IsFreeWagon(w) && w->engine_type == engine) { + IsFreeWagon(w) && w->engine_type == engine && + !HASBITS(w->vehstatus, VS_CRASHED)) { /// do not connect new wagon with crashed/flooded consists u = GetLastVehicleInChain(w); break; } @@ -935,7 +936,7 @@ TileIndex tile = src->tile; FOR_ALL_VEHICLES(dst) { - if (dst->type == VEH_Train && IsFreeWagon(dst) && dst->tile == tile) { + if (dst->type == VEH_Train && IsFreeWagon(dst) && dst->tile == tile && !HASBITS(dst->vehstatus, VS_CRASHED)) { // check so all vehicles in the line have the same engine. Vehicle *v = dst; @@ -1006,6 +1007,9 @@ if (src->type != VEH_Train || !CheckOwnership(src->owner)) return CMD_ERROR; + /* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */ + if (HASBITS(src->vehstatus, VS_CRASHED)) return CMD_ERROR; + // if nothing is selected as destination, try and find a matching vehicle to drag to. if (d == INVALID_VEHICLE) { dst = IsTrainEngine(src) ? NULL : FindGoodVehiclePos(src); @@ -1013,6 +1017,9 @@ if (!IsValidVehicleID(d)) return CMD_ERROR; dst = GetVehicle(d); if (dst->type != VEH_Train || !CheckOwnership(dst->owner)) return CMD_ERROR; + + /* Do not allow appending to crashed vehicles, too */ + if (HASBITS(dst->vehstatus, VS_CRASHED)) return CMD_ERROR; } // if an articulated part is being handled, deal with its parent vehicle @@ -3579,9 +3586,15 @@ if (v->type == VEH_Train && IsFrontEngine(v)) TrainLocoHandler(v, true); } else if (IsFreeWagon(v) && HASBITS(v->vehstatus, VS_CRASHED)) { - // Delete flooded standalone wagon - if (++v->u.rail.crash_anim_pos >= 4400) - DeleteVehicle(v); + // Delete flooded standalone wagon chain + if (++v->u.rail.crash_anim_pos >= 4400) { + Vehicle *w = GetFirstVehicleInChain(v); + do { + Vehicle *u = w->next; + DeleteVehicle(w); + w = u; + } while (w != NULL); + } } }