1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-29 09:29:10 +00:00

(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)

This commit is contained in:
rubidium
2008-08-02 22:53:21 +00:00
parent 0dfaa88c1e
commit e9c33fb288
5 changed files with 38 additions and 7 deletions

View File

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