From a31e86c7781547a1d527226099d0e9d45ee2a903 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 2 Aug 2008 22:53:21 +0000 Subject: (svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc) --- src/train_cmd.cpp | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/train_cmd.cpp') diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 229f70d30..6b6f548ed 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1614,10 +1614,27 @@ static inline void SetLastSpeed(Vehicle *v, int spd) } } -static void SwapTrainFlags(byte *swap_flag1, byte *swap_flag2) +/** Mark a train as stuck and stop it if it isn't stopped right now. */ +static void MarkTrainAsStuck(Vehicle *v) { - byte flag1 = *swap_flag1; - byte flag2 = *swap_flag2; + if (!HasBit(v->u.rail.flags, VRF_TRAIN_STUCK)) { + /* It is the first time the problem occured, set the "train stuck" flag. */ + SetBit(v->u.rail.flags, VRF_TRAIN_STUCK); + v->load_unload_time_rem = 0; + + /* Stop train */ + v->cur_speed = 0; + v->subspeed = 0; + SetLastSpeed(v, 0); + + InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); + } +} + +static void SwapTrainFlags(uint16 *swap_flag1, uint16 *swap_flag2) +{ + uint16 flag1 = *swap_flag1; + uint16 flag2 = *swap_flag2; /* Clear the flags */ ClrBit(*swap_flag1, VRF_GOINGUP); @@ -2670,7 +2687,7 @@ static int UpdateTrainSpeed(Vehicle *v) { uint accel; - if (v->vehstatus & VS_STOPPED || HasBit(v->u.rail.flags, VRF_REVERSING)) { + if (v->vehstatus & VS_STOPPED || HasBit(v->u.rail.flags, VRF_REVERSING) || HasBit(v->u.rail.flags, VRF_TRAIN_STUCK)) { if (_settings_game.vehicle.realistic_acceleration) { accel = GetTrainAcceleration(v, AM_BRAKE) * 2; } else { @@ -3059,6 +3076,9 @@ static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image) /* In front of a red signal */ Trackdir i = FindFirstTrackdir(trackdirbits); + /* Don't handle stuck trains here. */ + if (HasBit(v->u.rail.flags, VRF_TRAIN_STUCK)) return; + if (!HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(i))) { v->cur_speed = 0; v->subspeed = 0; @@ -3499,7 +3519,11 @@ static void TrainLocoHandler(Vehicle *v, bool mode) return; } - if (v->u.rail.force_proceed != 0) v->u.rail.force_proceed--; + if (v->u.rail.force_proceed != 0) { + v->u.rail.force_proceed--; + ClrBit(v->u.rail.flags, VRF_TRAIN_STUCK); + InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); + } /* train is broken down? */ if (v->breakdown_ctr != 0) { -- cgit v1.2.3-54-g00ecf