Changeset - r16761:3ce15f9cf63f
[Not reviewed]
master
0 4 0
rubidium - 13 years ago 2010-12-13 21:52:39
rubidium@openttd.org
(svn r21504) -Codechange: move the "lost" bit from the train's flags to vehicle flags
4 files changed with 17 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/saveload/afterload.cpp
Show inline comments
 
@@ -2383,24 +2383,35 @@ bool AfterLoadGame()
 
			if (rv->state == RVSB_IN_DEPOT || rv->state == RVSB_WORMHOLE) continue;
 

	
 
			bool loading = rv->current_order.IsType(OT_LOADING) || rv->current_order.IsType(OT_LEAVESTATION);
 
			if (HasBit(rv->state, RVS_IN_ROAD_STOP)) {
 
				extern const byte _road_stop_stop_frame[];
 
				SB(rv->state, RVS_ENTERED_STOP, 1, loading || rv->frame > _road_stop_stop_frame[rv->state - RVSB_IN_ROAD_STOP + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)]);
 
			} else if (HasBit(rv->state, RVS_IN_DT_ROAD_STOP)) {
 
				SB(rv->state, RVS_ENTERED_STOP, 1, loading || rv->frame > RVC_DRIVE_THROUGH_STOP_FRAME);
 
			}
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(156)) {
 
		/* The train's pathfinder lost flag got moved. */
 
		Train *t;
 
		FOR_ALL_TRAINS(t) {
 
			if (!HasBit(t->flags, 5)) continue;
 

	
 
			ClrBit(t->flags, 5);
 
			SetBit(t->vehicle_flags, VF_PATHFINDER_LOST);
 
		}
 
	}
 

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

	
 
	GamelogPrintDebug(1);
 

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

	
src/train.h
Show inline comments
 
@@ -21,27 +21,24 @@
 

	
 
struct Train;
 

	
 
enum VehicleRailFlags {
 
	VRF_REVERSING         = 0,
 

	
 
	/* used to store if a wagon is powered or not */
 
	VRF_POWEREDWAGON      = 3,
 

	
 
	/* used to reverse the visible direction of the vehicle */
 
	VRF_REVERSE_DIRECTION = 4,
 

	
 
	/* used to mark train as lost because PF can't find the route */
 
	VRF_NO_PATH_TO_DESTINATION = 5,
 

	
 
	/* used to mark that electric train engine is allowed to run on normal rail */
 
	VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL = 6,
 

	
 
	/* used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle only) */
 
	VRF_TOGGLE_REVERSE = 7,
 

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

	
 
	/* used to mark a train that is just leaving a station */
 
	VRF_LEAVING_STATION = 9,
 
};
src/train_cmd.cpp
Show inline comments
 
@@ -2403,43 +2403,43 @@ static Track ChooseTrainTrack(Train *v, 
 

	
 
	if (res_dest.tile != INVALID_TILE && !res_dest.okay) {
 
		/* Pathfinders are able to tell that route was only 'guessed'. */
 
		bool      path_not_found = false;
 
		TileIndex new_tile = res_dest.tile;
 

	
 
		Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, &path_not_found, do_track_reservation, &res_dest);
 
		if (new_tile == tile) best_track = next_track;
 

	
 
		/* handle "path not found" state */
 
		if (path_not_found) {
 
			/* PF didn't find the route */
 
			if (!HasBit(v->flags, VRF_NO_PATH_TO_DESTINATION)) {
 
				/* it is first time the problem occurred, set the "path not found" flag */
 
				SetBit(v->flags, VRF_NO_PATH_TO_DESTINATION);
 
			if (!HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) {
 
				/* It is first time the problem occurred, set the "lost" flag. */
 
				SetBit(v->vehicle_flags, VF_PATHFINDER_LOST);
 
				/* and notify user about the event */
 
				AI::NewEvent(v->owner, new AIEventVehicleLost(v->index));
 
				if (_settings_client.gui.lost_train_warn && v->owner == _local_company) {
 
					SetDParam(0, v->index);
 
					AddVehicleNewsItem(
 
						STR_NEWS_TRAIN_IS_LOST,
 
						NS_ADVICE,
 
						v->index
 
					);
 
				}
 
			}
 
		} else {
 
			/* route found, is the train marked with "path not found" flag? */
 
			if (HasBit(v->flags, VRF_NO_PATH_TO_DESTINATION)) {
 
			if (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) {
 
				/* clear the flag as the PF's problem was solved */
 
				ClrBit(v->flags, VRF_NO_PATH_TO_DESTINATION);
 
				ClrBit(v->vehicle_flags, VF_PATHFINDER_LOST);
 
				/* can we also delete the "News" item somehow? */
 
			}
 
		}
 
	}
 

	
 
	/* No track reservation requested -> finished. */
 
	if (!do_track_reservation) return best_track;
 

	
 
	/* A path was found, but could not be reserved. */
 
	if (res_dest.tile != INVALID_TILE && !res_dest.okay) {
 
		if (mark_stuck) MarkTrainAsStuck(v);
 
		FreeTrainTrackReservation(v);
src/vehicle_base.h
Show inline comments
 
@@ -35,24 +35,25 @@ enum VehStatus {
 
	VS_CRASHED         = 0x80, ///< Vehicle is crashed.
 
};
 

	
 
/** Bit numbers in #Vehicle::vehicle_flags. */
 
enum VehicleFlags {
 
	VF_LOADING_FINISHED,        ///< Vehicle has finished loading.
 
	VF_CARGO_UNLOADING,         ///< Vehicle is unloading cargo.
 
	VF_BUILT_AS_PROTOTYPE,      ///< Vehicle is a prototype (accepted as exclusive preview).
 
	VF_TIMETABLE_STARTED,       ///< Whether the vehicle has started running on the timetable yet.
 
	VF_AUTOFILL_TIMETABLE,      ///< Whether the vehicle should fill in the timetable automatically.
 
	VF_AUTOFILL_PRES_WAIT_TIME, ///< Whether non-destructive auto-fill should preserve waiting times
 
	VF_STOP_LOADING,            ///< Don't load anymore during the next load cycle.
 
	VF_PATHFINDER_LOST,         ///< Vehicle's pathfinder is lost.
 
};
 

	
 
/** Bit numbers used to indicate which of the #NewGRFCache values are valid. */
 
enum NewGRFCacheValidValues {
 
	NCVV_POSITION_CONSIST_LENGTH   = 0, ///< This bit will be set if the NewGRF var 40 currently stored is valid.
 
	NCVV_POSITION_SAME_ID_LENGTH   = 1, ///< This bit will be set if the NewGRF var 41 currently stored is valid.
 
	NCVV_CONSIST_CARGO_INFORMATION = 2, ///< This bit will be set if the NewGRF var 42 currently stored is valid.
 
	NCVV_COMPANY_INFORMATION       = 3, ///< This bit will be set if the NewGRF var 43 currently stored is valid.
 
	NCVV_END,                           ///< End of the bits.
 
};
 

	
 
/** Cached often queried (NewGRF) values */
0 comments (0 inline, 0 general)