summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ship_cmd.cpp23
-rw-r--r--src/train_cmd.cpp39
2 files changed, 31 insertions, 31 deletions
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 1ce2aaf3a..74f5554d1 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -693,12 +693,12 @@ static void ShipController(Vehicle *v)
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;
@@ -722,7 +722,7 @@ static void ShipController(Vehicle *v)
/* 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;
}
@@ -757,26 +757,25 @@ 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);
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index d9e0d029a..16f5bf915 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2995,7 +2995,7 @@ 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;
@@ -3013,11 +3013,11 @@ static void TrainController(Vehicle *v, bool update_image)
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;
@@ -3043,7 +3043,7 @@ static void TrainController(Vehicle *v, bool update_image)
/* 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. */
@@ -3060,17 +3060,11 @@ static void TrainController(Vehicle *v, bool update_image)
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
@@ -3079,16 +3073,24 @@ static void TrainController(Vehicle *v, bool update_image)
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 */
{
@@ -3126,15 +3128,14 @@ static void TrainController(Vehicle *v, bool update_image)
/* 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);