Changeset - r13967:0df597ac93ec
[Not reviewed]
master
0 3 0
rubidium - 15 years ago 2009-12-16 16:23:44
rubidium@openttd.org
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
-Fix [FS#2891]: when you pass a signal at danger, in a PBS controlled area, don't try to do the 'safe' thing and stop, but continue going; the user wanted the train to pass the signal at danger so (s)he has to suffer the consequences. Ofcourse one can always stop the train manually.
3 files changed with 43 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/saveload/afterload.cpp
Show inline comments
 
@@ -1958,24 +1958,33 @@ bool AfterLoadGame()
 
		Station *st;
 
		FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
 
	}
 

	
 
	if (CheckSavegameVersion(128)) {
 
		const Depot *d;
 
		FOR_ALL_DEPOTS(d) {
 
			_m[d->xy].m2 = d->index;
 
			if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index;
 
		}
 
	}
 

	
 
	/* 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);
 
		}
 
	}
 

	
 
	/* Road stops is 'only' updating some caches */
 
	AfterLoadRoadStops();
 
	AfterLoadLabelMaps();
 

	
 
	GamelogPrintDebug(1);
 

	
 
	InitializeWindowsAndCaches();
 
	/* Restore the signals */
 
	ResetSignalHandlers();
 
	return true;
 
}
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -1981,41 +1981,48 @@ CommandCost CmdReverseTrainDirection(Til
 
		}
 

	
 
		Train *front = v->First();
 
		/* make sure the vehicle is stopped in the depot */
 
		if (!front->IsStoppedInDepot()) {
 
			return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT);
 
		}
 

	
 
		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;
 
			SetWindowDirty(WC_VEHICLE_VIEW, v->index);
 
		}
 
	} else {
 
		/* turn the whole train around */
 
		if ((v->vehstatus & VS_CRASHED) || v->breakdown_ctr != 0) return CMD_ERROR;
 

	
 
		if (flags & DC_EXEC) {
 
			/* Properly leave the station if we are loading and won't be loading anymore */
 
			if (v->current_order.IsType(OT_LOADING)) {
 
				const Vehicle *last = v;
 
				while (last->Next() != NULL) last = last->Next();
 

	
 
				/* not a station || different station --> leave the station */
 
				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;
 
			SetWindowDirty(WC_VEHICLE_VIEW, v->index);
 

	
 
			if (_settings_game.vehicle.train_acceleration_model != TAM_ORIGINAL && v->cur_speed != 0) {
 
				ToggleBit(v->flags, VRF_REVERSING);
 
			} else {
 
				v->cur_speed = 0;
 
				SetLastSpeed(v, 0);
 
				HideFillingPercent(&v->fill_percent_te_id);
 
				ReverseTrainDirection(v);
 
			}
 
		}
 
	}
 
	return CommandCost();
 
}
 
@@ -2024,25 +2031,33 @@ CommandCost CmdReverseTrainDirection(Til
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to ignore the red signal
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Train *t = Train::GetIfValid(p1);
 
	if (t == NULL || !CheckOwnership(t->owner)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) t->force_proceed = 0x50;
 
	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;
 
		SetWindowDirty(WC_VEHICLE_VIEW, t->index);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Refits a train to the specified cargo type.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID of the train to refit
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle
 
@@ -3339,24 +3354,39 @@ static void TrainController(Train *v, Ve
 

	
 
				/* Check if the new tile contrains tracks that are compatible
 
				 * with the current train, if not, bail out. */
 
				if (!CheckCompatibleRail(v, gp.new_tile)) goto invalid_rail;
 

	
 
				TrackBits chosen_track;
 
				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)) {
 
						/* 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--;
 
							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) {
 
						/* In front of a red signal */
 
						Trackdir i = FindFirstTrackdir(trackdirbits);
 

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

	
 
						if (!HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(i))) {
 
							v->cur_speed = 0;
 
							v->subspeed = 0;
 
							v->progress = 255 - 100;
 
@@ -3912,25 +3942,24 @@ static bool TrainCheckIfLineEnds(Train *
 
	return true;
 
}
 

	
 

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

	
 
	if (v->force_proceed != 0) {
 
		v->force_proceed--;
 
		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) {
 
		if (v->breakdown_ctr <= 2) {
 
			HandleBrokenTrain(v);
 
			return true;
 
		}
 
		if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
 
	}
 
@@ -3997,24 +4026,26 @@ static bool TrainLocoHandler(Train *v, b
 
	}
 

	
 
	if (v->current_order.IsType(OT_LEAVESTATION)) {
 
		v->current_order.Free();
 
		SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		return true;
 
	}
 

	
 
	int j = UpdateTrainSpeed(v);
 

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

	
 
	int adv_spd = (v->direction & 1) ? 192 : 256;
 
	if (j < adv_spd) {
 
		/* if the vehicle has speed 0, update the last_speed field. */
 
		if (v->cur_speed == 0) SetLastSpeed(v, v->cur_speed);
 
	} else {
 
		TrainCheckIfLineEnds(v);
 
		/* Loop until the train has finished moving. */
 
		for (;;) {
 
			j -= adv_spd;
src/vehicle_gui.cpp
Show inline comments
 
@@ -1950,24 +1950,25 @@ public:
 

	
 
	virtual void OnPaint()
 
	{
 
		const Vehicle *v = Vehicle::Get(this->window_number);
 
		bool is_localcompany = v->owner == _local_company;
 
		bool refitable_and_stopped_in_depot = IsVehicleRefitable(v);
 

	
 
		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->SetWidgetDisabledState(VVW_WIDGET_FORCE_PROCEED, !is_localcompany);
 
			this->SetWidgetDisabledState(VVW_WIDGET_TURN_AROUND, !is_localcompany);
 
		}
 

	
 
		this->DrawWidgets();
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget != VVW_WIDGET_CAPTION) return;
 

	
 
		const Vehicle *v = Vehicle::Get(this->window_number);
0 comments (0 inline, 0 general)