@@ -530,13 +530,14 @@ static CommandCost CmdBuildRailWagon(Eng
Vehicle *u = NULL;
Vehicle *w;
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;
}
v->engine_type = engine;
@@ -851,13 +852,13 @@ static Vehicle *FindGoodVehiclePos(const
{
Vehicle *dst;
EngineID eng = src->engine_type;
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;
while (v->engine_type == eng) {
v = v->Next();
if (v == NULL) return dst;
@@ -922,20 +923,26 @@ CommandCost CmdMoveRailVehicle(TileIndex
if (!IsValidVehicleID(s)) return CMD_ERROR;
Vehicle *src = GetVehicle(s);
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);
} else {
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 */
while (IsArticulatedPart(src)) src = src->Previous();
if (dst != NULL) {
while (IsArticulatedPart(dst)) dst = dst->Previous();
@@ -3343,14 +3350,14 @@ void Train::Tick()
TrainLocoHandler(this, false);
/* make sure vehicle wasn't deleted. */
if (this->type == VEH_TRAIN && IsFrontEngine(this))
TrainLocoHandler(this, true);
} else if (IsFreeWagon(this) && HASBITS(this->vehstatus, VS_CRASHED)) {
/* Delete flooded standalone wagon */
if (++this->u.rail.crash_anim_pos >= 4400) delete this;
/* Delete flooded standalone wagon chain */
if (++this->u.rail.crash_anim_pos >= 4400) DeleteVehicleChain(this);
#define MAX_ACCEPTABLE_DEPOT_DIST 16
static void CheckIfTrainNeedsService(Vehicle *v)
Status change: