File diff r15351:fe3041e6c4c3 → r15352:61cc54bb72c5
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. */