Changeset - r15352:61cc54bb72c5
[Not reviewed]
master
0 5 0
frosch - 14 years ago 2010-06-21 17:35:27
frosch@openttd.org
(svn r20005) -Codechange: Enumify force_proceed.
5 files changed with 27 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/saveload/afterload.cpp
Show inline comments
 
@@ -2009,13 +2009,15 @@ bool AfterLoadGame()
 

	
 
	/* The behaviour of force_proceed has been changed. Now
 
	 * it counts signals instead of some random time out. */
 
	if (CheckSavegameVersion(131)) {
 
		Train *t;
 
		FOR_ALL_TRAINS(t) {
 
			t->force_proceed = min<byte>(t->force_proceed, 1);
 
			if (t->force_proceed != TFP_NONE) {
 
				t->force_proceed = TFP_STUCK;
 
			}
 
		}
 
	}
 

	
 
	/* The bits for the tree ground and tree density have
 
	 * been swapped (m2 bits 7..6 and 5..4. */
 
	if (CheckSavegameVersion(135)) {
src/train.h
Show inline comments
 
@@ -40,12 +40,20 @@ enum VehicleRailFlags {
 
	VRF_TOGGLE_REVERSE = 7,
 

	
 
	/* used to mark a train that can't get a path reservation */
 
	VRF_TRAIN_STUCK    = 8,
 
};
 

	
 
/** Modes for ignoring signals. */
 
enum TrainForceProceeding {
 
	TFP_NONE   = 0,    ///< Normal operation.
 
	TFP_STUCK  = 1,    ///< Proceed till next signal, but ignore being stuck till then. This includes force leaving depots.
 
	TFP_SIGNAL = 2,    ///< Ignore next signal, after the signal ignore being stucked.
 
};
 
typedef SimpleTinyEnumT<TrainForceProceeding, byte> TrainForceProceedingByte;
 

	
 
byte FreightWagonMult(CargoID cargo);
 

	
 
void CheckTrainsLengths();
 

	
 
void FreeTrainTrackReservation(const Train *v, TileIndex origin = INVALID_TILE, Trackdir orig_td = INVALID_TRACKDIR);
 
bool TryPathReserve(Train *v, bool mark_as_stuck = false, bool first_tile_okay = false);
 
@@ -91,13 +99,13 @@ struct Train : public GroundVehicle<Trai
 
	Train *other_multiheaded_part;
 

	
 
	uint16 crash_anim_pos;
 

	
 
	uint16 flags;
 
	TrackBitsByte track;
 
	byte force_proceed;
 
	TrainForceProceedingByte force_proceed;
 
	RailTypeByte railtype;
 
	RailTypes compatible_railtypes;
 

	
 
	/** Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals. */
 
	uint16 wait_counter;
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -1846,13 +1846,13 @@ CommandCost CmdReverseTrainDirection(Til
 

	
 
		if (flags & DC_EXEC) {
 
			ToggleBit(v->flags, VRF_REVERSE_DIRECTION);
 
			SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
 
			SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
 
			/* We cancel any 'skip signal at dangers' here */
 
			v->force_proceed = 0;
 
			v->force_proceed = TFP_NONE;
 
			SetWindowDirty(WC_VEHICLE_VIEW, v->index);
 
		}
 
	} else {
 
		/* turn the whole train around */
 
		if ((v->vehstatus & VS_CRASHED) || v->breakdown_ctr != 0) return CMD_ERROR;
 

	
 
@@ -1866,13 +1866,13 @@ CommandCost CmdReverseTrainDirection(Til
 
				if (!IsTileType(last->tile, MP_STATION) || GetStationIndex(last->tile) != GetStationIndex(v->tile)) {
 
					v->LeaveStation();
 
				}
 
			}
 

	
 
			/* We cancel any 'skip signal at dangers' here */
 
			v->force_proceed = 0;
 
			v->force_proceed = TFP_NONE;
 
			SetWindowDirty(WC_VEHICLE_VIEW, v->index);
 

	
 
			if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && v->cur_speed != 0) {
 
				ToggleBit(v->flags, VRF_REVERSING);
 
			} else {
 
				v->cur_speed = 0;
 
@@ -1905,13 +1905,13 @@ CommandCost CmdForceTrainProceed(TileInd
 
	if (flags & DC_EXEC) {
 
		/* If we are forced to proceed, cancel that order.
 
		 * If we are marked stuck we would want to force the train
 
		 * to proceed to the next signal. In the other cases we
 
		 * would like to pass the signal at danger and run till the
 
		 * next signal we encounter. */
 
		t->force_proceed = t->force_proceed == 2 ? 0 : HasBit(t->flags, VRF_TRAIN_STUCK) || t->IsInDepot() ? 1 : 2;
 
		t->force_proceed = t->force_proceed == TFP_SIGNAL ? TFP_NONE : HasBit(t->flags, VRF_TRAIN_STUCK) || t->IsInDepot() ? TFP_STUCK : TFP_SIGNAL;
 
		SetWindowDirty(WC_VEHICLE_VIEW, t->index);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
@@ -2183,13 +2183,13 @@ static bool CheckTrainStayInDepot(Train 
 
		SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
 
		return true;
 
	}
 

	
 
	SigSegState seg_state;
 

	
 
	if (v->force_proceed == 0) {
 
	if (v->force_proceed == TFP_NONE) {
 
		/* force proceed was not pressed */
 
		if (++v->wait_counter < 37) {
 
			SetWindowClassesDirty(WC_TRAINS_LIST);
 
			return true;
 
		}
 

	
 
@@ -2212,13 +2212,13 @@ static bool CheckTrainStayInDepot(Train 
 
		SetDepotReservation(v->tile, true);
 
		VehicleEnterDepot(v);
 
		return true;
 
	}
 

	
 
	/* Only leave when we can reserve a path to our destination. */
 
	if (seg_state == SIGSEG_PBS && !TryPathReserve(v) && v->force_proceed == 0) {
 
	if (seg_state == SIGSEG_PBS && !TryPathReserve(v) && v->force_proceed == TFP_NONE) {
 
		/* No path and no force proceed. */
 
		SetWindowClassesDirty(WC_TRAINS_LIST);
 
		MarkTrainAsStuck(v);
 
		return true;
 
	}
 

	
 
@@ -2902,13 +2902,13 @@ static void TrainEnterStation(Train *v, 
 
			v->index,
 
			st->index
 
		);
 
		AI::NewEvent(v->owner, new AIEventStationFirstVehicle(st->index, v->index));
 
	}
 

	
 
	v->force_proceed = 0;
 
	v->force_proceed = TFP_NONE;
 
	SetWindowDirty(WC_VEHICLE_VIEW, v->index);
 

	
 
	v->BeginLoading();
 

	
 
	StationAnimationTrigger(st, v->tile, STAT_ANIM_TRAIN_ARRIVES);
 
}
 
@@ -3203,29 +3203,29 @@ static void TrainController(Train *v, Ve
 
				if (prev == NULL) {
 
					/* Currently the locomotive is active. Determine which one of the
 
					 * available tracks to choose */
 
					chosen_track = TrackToTrackBits(ChooseTrainTrack(v, gp.new_tile, enterdir, bits, false, NULL, true));
 
					assert(chosen_track & (bits | GetReservedTrackbits(gp.new_tile)));
 

	
 
					if (v->force_proceed != 0 && IsPlainRailTile(gp.new_tile) && HasSignals(gp.new_tile)) {
 
					if (v->force_proceed != TFP_NONE && IsPlainRailTile(gp.new_tile) && HasSignals(gp.new_tile)) {
 
						/* For each signal we find decrease the counter by one.
 
						 * We start at two, so the first signal we pass decreases
 
						 * this to one, then if we reach the next signal it is
 
						 * decreased to zero and we won't pass that new signal. */
 
						Trackdir dir = FindFirstTrackdir(trackdirbits);
 
						if (GetSignalType(gp.new_tile, TrackdirToTrack(dir)) != SIGTYPE_PBS ||
 
								!HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(dir))) {
 
							/* However, we do not want to be stopped by PBS signals
 
							 * entered via the back. */
 
							v->force_proceed--;
 
							v->force_proceed = (v->force_proceed == TFP_SIGNAL) ? TFP_STUCK : TFP_NONE;
 
							SetWindowDirty(WC_VEHICLE_VIEW, v->index);
 
						}
 
					}
 

	
 
					/* Check if it's a red signal and that force proceed is not clicked. */
 
					if ((red_signals & chosen_track) && v->force_proceed == 0) {
 
					if ((red_signals & chosen_track) && v->force_proceed == TFP_NONE) {
 
						/* In front of a red signal */
 
						Trackdir i = FindFirstTrackdir(trackdirbits);
 

	
 
						/* Don't handle stuck trains here. */
 
						if (HasBit(v->flags, VRF_TRAIN_STUCK)) return;
 

	
 
@@ -3792,13 +3792,13 @@ static bool TrainLocoHandler(Train *v, b
 
{
 
	/* train has crashed? */
 
	if (v->vehstatus & VS_CRASHED) {
 
		return mode ? true : HandleCrashedTrain(v); // 'this' can be deleted here
 
	}
 

	
 
	if (v->force_proceed != 0) {
 
	if (v->force_proceed != TFP_NONE) {
 
		ClrBit(v->flags, VRF_TRAIN_STUCK);
 
		SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
	}
 

	
 
	/* train is broken down? */
 
	if (v->breakdown_ctr != 0) {
 
@@ -3842,13 +3842,13 @@ static bool TrainLocoHandler(Train *v, b
 
	if (!mode && HasBit(v->flags, VRF_TRAIN_STUCK)) {
 
		++v->wait_counter;
 

	
 
		/* Should we try reversing this tick if still stuck? */
 
		bool turn_around = v->wait_counter % (_settings_game.pf.wait_for_pbs_path * DAY_TICKS) == 0 && _settings_game.pf.wait_for_pbs_path < 255;
 

	
 
		if (!turn_around && v->wait_counter % _settings_game.pf.path_backoff_interval != 0 && v->force_proceed == 0) return true;
 
		if (!turn_around && v->wait_counter % _settings_game.pf.path_backoff_interval != 0 && v->force_proceed == TFP_NONE) return true;
 
		if (!TryPathReserve(v)) {
 
			/* Still stuck. */
 
			if (turn_around) ReverseTrainDirection(v);
 

	
 
			if (HasBit(v->flags, VRF_TRAIN_STUCK) && v->wait_counter > 2 * _settings_game.pf.wait_for_pbs_path * DAY_TICKS) {
 
				/* Show message to player. */
 
@@ -3860,13 +3860,13 @@ static bool TrainLocoHandler(Train *v, b
 
						v->index
 
					);
 
				}
 
				v->wait_counter = 0;
 
			}
 
			/* Exit if force proceed not pressed, else reset stuck flag anyway. */
 
			if (v->force_proceed == 0) return true;
 
			if (v->force_proceed == TFP_NONE) return true;
 
			ClrBit(v->flags, VRF_TRAIN_STUCK);
 
			v->wait_counter = 0;
 
			SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
	}
 

	
 
@@ -3878,13 +3878,13 @@ static bool TrainLocoHandler(Train *v, b
 

	
 
	int j = v->UpdateSpeed();
 

	
 
	/* we need to invalidate the widget if we are stopping from 'Stopping 0 km/h' to 'Stopped' */
 
	if (v->cur_speed == 0 && (v->vehstatus & VS_STOPPED)) {
 
		/* If we manually stopped, we're not force-proceeding anymore. */
 
		v->force_proceed = 0;
 
		v->force_proceed = TFP_NONE;
 
		SetWindowDirty(WC_VEHICLE_VIEW, v->index);
 
	}
 

	
 
	int adv_spd = (v->direction & 1) ? 192 : 256;
 
	if (j < adv_spd) {
 
		/* if the vehicle has speed 0, update the last_speed field. */
src/vehicle.cpp
Show inline comments
 
@@ -1058,13 +1058,13 @@ void VehicleEnterDepot(Vehicle *v)
 
			/* Clear path reservation */
 
			SetDepotReservation(t->tile, false);
 
			if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(t->tile);
 

	
 
			UpdateSignalsOnSegment(t->tile, INVALID_DIAGDIR, t->owner);
 
			t->wait_counter = 0;
 
			t->force_proceed = 0;
 
			t->force_proceed = TFP_NONE;
 
			ClrBit(t->flags, VRF_TOGGLE_REVERSE);
 
			t->ConsistChanged(true);
 
			break;
 
		}
 

	
 
		case VEH_ROAD:
src/vehicle_gui.cpp
Show inline comments
 
@@ -2022,13 +2022,13 @@ public:
 

	
 
		this->SetWidgetDisabledState(VVW_WIDGET_GOTO_DEPOT, !is_localcompany);
 
		this->SetWidgetDisabledState(VVW_WIDGET_REFIT_VEH, !refitable_and_stopped_in_depot || !is_localcompany);
 
		this->SetWidgetDisabledState(VVW_WIDGET_CLONE_VEH, !is_localcompany);
 

	
 
		if (v->type == VEH_TRAIN) {
 
			this->SetWidgetLoweredState(VVW_WIDGET_FORCE_PROCEED, Train::From(v)->force_proceed == 2);
 
			this->SetWidgetLoweredState(VVW_WIDGET_FORCE_PROCEED, Train::From(v)->force_proceed == TFP_SIGNAL);
 
			this->SetWidgetDisabledState(VVW_WIDGET_FORCE_PROCEED, !is_localcompany);
 
			this->SetWidgetDisabledState(VVW_WIDGET_TURN_AROUND, !is_localcompany);
 
		}
 

	
 
		this->DrawWidgets();
 
	}
0 comments (0 inline, 0 general)