Changeset - r5994:2d36164769d3
[Not reviewed]
master
0 2 0
rubidium - 17 years ago 2007-02-13 11:29:20
rubidium@openttd.org
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
2 files changed with 31 insertions and 31 deletions:
0 comments (0 inline, 0 general)
src/ship_cmd.cpp
Show inline comments
 
@@ -690,18 +690,18 @@ static void ShipController(Vehicle *v)
 

	
 
	if (!ShipAccelerate(v)) return;
 

	
 
	BeginVehicleMove(v);
 

	
 
	if (GetNewVehiclePos(v, &gp)) {
 
		// staying in tile
 
		/* Staying in tile */
 
		if (IsShipInDepot(v)) {
 
			gp.x = v->x_pos;
 
			gp.y = v->y_pos;
 
		} else {
 
			/* isnot inside depot */
 
			/* Not inside depot */
 
			r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
 
			if (HASBIT(r, VETS_CANNOT_ENTER)) goto reverse_direction;
 

	
 
			/* A leave station order only needs one tick to get processed, so we can
 
			 * always skip ahead. */
 
			if (v->current_order.type == OT_LEAVESTATION) {
 
@@ -719,13 +719,13 @@ static void ShipController(Vehicle *v)
 
					v->current_order.type = OT_DUMMY;
 
					InvalidateVehicleOrder(v);
 
				} else {
 
					/* Non-buoy orders really need to reach the tile */
 
					if (v->dest_tile == gp.new_tile) {
 
						if (v->current_order.type == OT_GOTO_DEPOT) {
 
							if ((gp.x&0xF)==8 && (gp.y&0xF)==8) {
 
							if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) {
 
								VehicleEnterDepot(v);
 
								return;
 
							}
 
						} else if (v->current_order.type == OT_GOTO_STATION) {
 
							Station *st;
 

	
 
@@ -754,32 +754,31 @@ static void ShipController(Vehicle *v)
 
					}
 
				}
 
			}
 
		}
 
	} else {
 
		DiagDirection diagdir;
 
		// new tile
 
		if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY())
 
		/* New tile */
 
		if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY()) {
 
			goto reverse_direction;
 
		}
 

	
 
		dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile);
 
		assert(dir == DIR_NE || dir == DIR_SE || dir == DIR_SW || dir == DIR_NW);
 
		diagdir = DirToDiagDir(dir);
 
		tracks = GetAvailShipTracks(gp.new_tile, diagdir);
 
		if (tracks == 0)
 
			goto reverse_direction;
 
		if (tracks == TRACK_BIT_NONE) goto reverse_direction;
 

	
 
		// Choose a direction, and continue if we find one
 
		/* Choose a direction, and continue if we find one */
 
		track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
 
		if (track == INVALID_TRACK)
 
			goto reverse_direction;
 
		if (track == INVALID_TRACK) goto reverse_direction;
 

	
 
		b = _ship_subcoord[diagdir][track];
 

	
 
		gp.x = (gp.x&~0xF) | b[0];
 
		gp.y = (gp.y&~0xF) | b[1];
 
		gp.x = (gp.x & ~0xF) | b[0];
 
		gp.y = (gp.y & ~0xF) | b[1];
 

	
 
		/* Call the landscape function and tell it that the vehicle entered the tile */
 
		r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
 
		if (HASBIT(r, VETS_CANNOT_ENTER)) goto reverse_direction;
 

	
 
		if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) {
src/train_cmd.cpp
Show inline comments
 
@@ -2992,13 +2992,13 @@ static void *CheckVehicleAtSignal(Vehicl
 
}
 

	
 
static void TrainController(Vehicle *v, bool update_image)
 
{
 
	Vehicle *prev;
 
	GetNewVehiclePosResult gp;
 
	uint32 r, tracks,ts;
 
	uint32 r, tracks, ts;
 
	Trackdir i;
 
	DiagDirection enterdir;
 
	Direction dir;
 
	Direction newdir;
 
	Direction chosen_dir;
 
	TrackBits chosen_track;
 
@@ -3010,17 +3010,17 @@ static void TrainController(Vehicle *v, 
 

	
 
		if (v->u.rail.track != TRACK_BIT_WORMHOLE) {
 
			/* Not inside tunnel */
 
			if (GetNewVehiclePos(v, &gp)) {
 
				/* Staying in the old tile */
 
				if (v->u.rail.track == TRACK_BIT_DEPOT) {
 
					/* inside depot */
 
					/* Inside depot */
 
					gp.x = v->x_pos;
 
					gp.y = v->y_pos;
 
				} else {
 
					/* is not inside depot */
 
					/* Not inside depot */
 

	
 
					if (IsFrontEngine(v) && !TrainCheckIfLineEnds(v)) return;
 

	
 
					r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
 
					if (HASBIT(r, VETS_CANNOT_ENTER)) {
 
						goto invalid_rail;
 
@@ -3040,13 +3040,13 @@ static void TrainController(Vehicle *v, 
 
				/* A new tile is about to be entered. */
 

	
 
				TrackBits bits;
 
				/* Determine what direction we're entering the new tile from */
 
				dir = GetNewVehicleDirectionByTile(gp.new_tile, gp.old_tile);
 
				enterdir = DirToDiagDir(dir);
 
				assert(enterdir==0 || enterdir==1 || enterdir==2 || enterdir==3);
 
				assert(IsValidDiagDirection(enterdir));
 

	
 
				/* Get the status of the tracks in the new tile and mask
 
				 * away the bits that aren't reachable. */
 
				ts = GetTileTrackStatus(gp.new_tile, TRANSPORT_RAIL) & _reachable_tracks[enterdir];
 

	
 
				/* Combine the from & to directions.
 
@@ -3057,41 +3057,43 @@ static void TrainController(Vehicle *v, 
 
				if ((_patches.new_pathfinding_all || _patches.yapf.rail_use_yapf) && _patches.forbid_90_deg && prev == NULL) {
 
					/* We allow wagons to make 90 deg turns, because forbid_90_deg
 
					 * can be switched on halfway a turn */
 
					bits &= ~TrackCrossesTracks(FindFirstTrack(v->u.rail.track));
 
				}
 

	
 
				if (bits == TRACK_BIT_NONE) {
 
					//debug("%x == 0", bits);
 
					goto invalid_rail;
 
				}
 
				if (bits == TRACK_BIT_NONE) goto invalid_rail;
 

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

	
 
				if (prev == NULL) {
 
					/* Currently the locomotive is active. Determine which one of the
 
					 * available tracks to choose */
 
					chosen_track = 1 << ChooseTrainTrack(v, gp.new_tile, enterdir, bits);
 
					assert(chosen_track & tracks);
 

	
 
					/* Check if it's a red signal and that force proceed is not clicked. */
 
					if ( (tracks>>16)&chosen_track && v->u.rail.force_proceed == 0) goto red_light;
 
					if ((tracks >> 16) & chosen_track && v->u.rail.force_proceed == 0) goto red_light;
 
				} else {
 
					static byte _matching_tracks[8] = {0x30, 1, 0xC, 2, 0x30, 1, 0xC, 2};
 
					static const TrackBits _matching_tracks[8] = {
 
							TRACK_BIT_LEFT  | TRACK_BIT_RIGHT, TRACK_BIT_X,
 
							TRACK_BIT_UPPER | TRACK_BIT_LOWER, TRACK_BIT_Y,
 
							TRACK_BIT_LEFT  | TRACK_BIT_RIGHT, TRACK_BIT_X,
 
							TRACK_BIT_UPPER | TRACK_BIT_LOWER, TRACK_BIT_Y
 
					};
 

	
 
					/* The wagon is active, simply follow the prev vehicle. */
 
					chosen_track = (TrackBits)(byte)(_matching_tracks[GetDirectionToVehicle(prev, gp.x, gp.y)] & bits);
 
				}
 

	
 
				/* make sure chosen track is a valid track */
 
				assert(chosen_track==1 || chosen_track==2 || chosen_track==4 || chosen_track==8 || chosen_track==16 || chosen_track==32);
 
				/* Make sure chosen track is a valid track */
 
				assert(
 
						chosen_track == TRACK_BIT_X     || chosen_track == TRACK_BIT_Y ||
 
						chosen_track == TRACK_BIT_UPPER || chosen_track == TRACK_BIT_LOWER ||
 
						chosen_track == TRACK_BIT_LEFT  || chosen_track == TRACK_BIT_RIGHT);
 

	
 
				/* Update XY to reflect the entrance to the new tile, and select the direction to use */
 
				{
 
					const byte *b = _initial_tile_subcoord[FIND_FIRST_BIT(chosen_track)][enterdir];
 
					gp.x = (gp.x & ~0xF) | b[0];
 
					gp.y = (gp.y & ~0xF) | b[1];
 
@@ -3123,21 +3125,20 @@ static void TrainController(Vehicle *v, 
 
				}
 

	
 
				if (IsFrontEngine(v)) TrainMovedChangeSignals(gp.new_tile, enterdir);
 

	
 
				/* Signals can only change when the first
 
				 * (above) or the last vehicle moves. */
 
				if (v->next == NULL)
 
					TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir));
 
				if (v->next == NULL) TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir));
 

	
 
				if (prev == NULL) AffectSpeedByDirChange(v, chosen_dir);
 

	
 
				v->direction = chosen_dir;
 
			}
 
		} else {
 
			/* in tunnel on on a bridge */
 
			/* In tunnel or on a bridge */
 
			GetNewVehiclePos(v, &gp);
 

	
 
			SetSpeedLimitOnBridge(v);
 

	
 
			if (!(IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) || !HASBIT(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
 
				v->x_pos = gp.x;
0 comments (0 inline, 0 general)