diff options
-rw-r--r-- | src/openttd.h | 5 | ||||
-rw-r--r-- | src/rail_cmd.cpp | 8 | ||||
-rw-r--r-- | src/road_cmd.cpp | 4 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 12 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 6 | ||||
-rw-r--r-- | src/station_cmd.cpp | 6 | ||||
-rw-r--r-- | src/train_cmd.cpp | 14 | ||||
-rw-r--r-- | src/tunnelbridge_cmd.cpp | 32 | ||||
-rw-r--r-- | src/vehicle.cpp | 9 | ||||
-rw-r--r-- | src/vehicle.h | 20 | ||||
-rw-r--r-- | src/water_cmd.cpp | 2 |
11 files changed, 67 insertions, 51 deletions
diff --git a/src/openttd.h b/src/openttd.h index 0126d72c8..b4581ea36 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -361,10 +361,7 @@ typedef void ClickTileProc(TileIndex tile); typedef void AnimateTileProc(TileIndex tile); typedef void TileLoopProc(TileIndex tile); typedef void ChangeTileOwnerProc(TileIndex tile, PlayerID old_player, PlayerID new_player); -/* Return value has bit 0x2 set, when the vehicle enters a station. Then, - * result << 8 contains the id of the station entered. If the return value has - * bit 0x8 set, the vehicle could not and did not enter the tile. Are there - * other bits that can be set? */ +/** @see VehicleEnterTileStatus to see what the return values mean */ typedef uint32 VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y); typedef Slope GetSlopeTilehProc(TileIndex, Slope tileh); diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 04deae559..bb8ba81a8 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1946,7 +1946,7 @@ static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) int length; // this routine applies only to trains in depot tiles - if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0; + if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return VETSB_CONTINUE; /* depot direction */ dir = GetRailDepotDirection(tile); @@ -1965,7 +1965,7 @@ static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) if (_fractcoords_behind[dir] == fract_coord) { /* make sure a train is not entering the tile from behind */ - return 8; + return VETSB_CANNOT_ENTER; } else if (_fractcoords_enter[dir] == fract_coord) { if (DiagDirToDir(ReverseDiagDir(dir)) == v->direction) { /* enter the depot */ @@ -1976,7 +1976,7 @@ static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) v->tile = tile; InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); - return 4; + return VETSB_ENTERED_WORMHOLE; } } else if (fract_coord_leave == fract_coord) { if (DiagDirToDir(dir) == v->direction) { @@ -1988,7 +1988,7 @@ static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) } } - return 0; + return VETSB_CONTINUE; } diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index cbad915d4..caea8ea2d 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1016,13 +1016,13 @@ static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) v->u.road.frame == 11 && _roadveh_enter_depot_unk0[GetRoadDepotDirection(tile)] == v->u.road.state) { VehicleEnterDepot(v); - return 4; + return VETSB_ENTERED_WORMHOLE; } break; default: break; } - return 0; + return VETSB_CONTINUE; } diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 3c1278985..34035e621 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1340,7 +1340,7 @@ static void RoadVehController(Vehicle *v) return; } - if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) { + if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && HASBIT(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) { /* Vehicle has just entered a bridge or tunnel */ v->cur_image = GetRoadVehImage(v, v->direction); UpdateRoadVehDeltaXY(v); @@ -1388,7 +1388,7 @@ again: if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; r = VehicleEnterTile(v, tile, x, y); - if (r & 8) { + if (HASBIT(r, VETS_CANNOT_ENTER)) { /* Vehicle cannot enter the tile */ if (!IsTileType(tile, MP_TUNNELBRIDGE)) { v->cur_speed = 0; @@ -1416,7 +1416,7 @@ again: } } - if (!(r & 4)) { + if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) { /* Set vehicle to first frame on new tile */ v->tile = tile; v->u.road.state = (byte)dir; @@ -1457,7 +1457,7 @@ again: if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; r = VehicleEnterTile(v, v->tile, x, y); - if (r & 8) { + if (HASBIT(r, VETS_CANNOT_ENTER)) { /* Vehicle cannot enter the tile */ v->cur_speed = 0; return; @@ -1599,7 +1599,7 @@ again: /* Check tile position conditions - i.e. stop position in depot, * entry onto bridge or into tunnel */ r = VehicleEnterTile(v, v->tile, x, y); - if (r & 8) { + if (HASBIT(r, VETS_CANNOT_ENTER)) { /* Vehicle cannot continue */ v->cur_speed = 0; return; @@ -1607,7 +1607,7 @@ again: /* Move to next frame unless vehicle arrived at a stop position * in a depot or entered a tunnel/bridge */ - if ((r & 4) == 0) v->u.road.frame++; + if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) v->u.road.frame++; v->cur_image = GetRoadVehImage(v, v->direction); UpdateRoadVehDeltaXY(v); diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 82408ad23..6b73dade8 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -700,7 +700,7 @@ static void ShipController(Vehicle *v) } else { /* isnot inside depot */ r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); - if (r & 0x8) goto reverse_direction; + 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. */ @@ -780,9 +780,9 @@ static void ShipController(Vehicle *v) /* Call the landscape function and tell it that the vehicle entered the tile */ r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); - if (r&0x8) goto reverse_direction; + if (HASBIT(r, VETS_CANNOT_ENTER)) goto reverse_direction; - if (!(r&0x4)) { + if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) { v->tile = gp.new_tile; v->u.ship.state = TrackToTrackBits(track); } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 2e3ae49c6..d994aa7ee 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2260,7 +2260,7 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) if (DiagDirToAxis(dir) != AXIS_X) intswap(x, y); if (y == TILE_SIZE / 2) { if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x; - if (x == 12) return 2 | (station_id << 8); /* enter station */ + if (x == 12) return VETSB_ENTERED_STATION | (station_id << VETS_STATION_ID_OFFSET); /* enter station */ if (x < 12) { uint16 spd; @@ -2279,7 +2279,7 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile)); /* Check if station is busy or if there are no free bays. */ - if (rs->IsEntranceBusy() || !rs->HasFreeBay()) return 8; + if (rs->IsEntranceBusy() || !rs->HasFreeBay()) return VETSB_CANNOT_ENTER; v->u.road.state += 32; @@ -2293,7 +2293,7 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) } } - return 0; + return VETSB_CONTINUE; } /* this function is called for one station each tick */ diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 37e42cde0..3020caa8e 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3022,12 +3022,11 @@ static void TrainController(Vehicle *v, bool update_image) if (IsFrontEngine(v) && !TrainCheckIfLineEnds(v)) return; r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); - if (r & 0x8) { - //debug("%x & 0x8", r); + if (HASBIT(r, VETS_ENTERED_WORMHOLE)) { goto invalid_rail; } - if (r & 0x2) { - TrainEnterStation(v, r >> 8); + if (HASBIT(r, VETS_ENTERED_STATION)) { + TrainEnterStation(v, r >> VETS_STATION_ID_OFFSET); return; } @@ -3101,8 +3100,7 @@ static void TrainController(Vehicle *v, bool update_image) /* Call the landscape function and tell it that the vehicle entered the tile */ r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); - if (r & 0x8) { - //debug("%x & 0x8", r); + if (HASBIT(r, VETS_CANNOT_ENTER)) { goto invalid_rail; } @@ -3113,7 +3111,7 @@ static void TrainController(Vehicle *v, bool update_image) if (IsFrontEngine(v)) v->load_unload_time_rem = 0; - if (!(r&0x4)) { + if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) { v->tile = gp.new_tile; if (GetTileRailType(gp.new_tile, FindFirstTrack(chosen_track)) != GetTileRailType(gp.old_tile, FindFirstTrack(v->u.rail.track))) { @@ -3141,7 +3139,7 @@ static void TrainController(Vehicle *v, bool update_image) SetSpeedLimitOnBridge(v); - if (!(IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) || !(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 0x4)) { + 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; v->y_pos = gp.y; VehiclePositionChanged(v); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index eab5b2a18..3df78215c 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1262,7 +1262,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y { int z = GetSlopeZ(x, y) - v->z_pos; - if (myabs(z) > 2) return 8; + if (myabs(z) > 2) return VETSB_CANNOT_ENTER; if (IsTunnel(tile)) { byte fc; @@ -1280,13 +1280,13 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y if (!PlayVehicleSound(v, VSE_TUNNEL) && v->spritenum < 4) { SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); } - return 0; + return VETSB_CONTINUE; } if (fc == _tunnel_fractcoord_2[dir]) { v->tile = tile; v->u.rail.track = TRACK_BIT_WORMHOLE; v->vehstatus |= VS_HIDDEN; - return 4; + return VETSB_ENTERED_WORMHOLE; } } @@ -1296,7 +1296,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y v->u.rail.track = (TrackBits)_exit_tunnel_track[dir]; assert(v->u.rail.track); v->vehstatus &= ~VS_HIDDEN; - return 4; + return VETSB_ENTERED_WORMHOLE; } } else if (v->type == VEH_Road) { fc = (x & 0xF) + (y << 4); @@ -1310,9 +1310,9 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y v->tile = tile; v->u.road.state = 0xFF; v->vehstatus |= VS_HIDDEN; - return 4; + return VETSB_ENTERED_WORMHOLE; } else { - return 0; + return VETSB_CONTINUE; } } @@ -1326,7 +1326,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y v->u.road.state = _road_exit_tunnel_state[dir]; v->u.road.frame = _road_exit_tunnel_frame[dir]; v->vehstatus &= ~VS_HIDDEN; - return 4; + return VETSB_ENTERED_WORMHOLE; } } } else if (IsBridge(tile)) { // XXX is this necessary? @@ -1344,10 +1344,10 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y if (DirToDiagDir(v->direction) == dir) { switch (dir) { default: NOT_REACHED(); - case DIAGDIR_NE: if ((x & 0xF) != 0) return 0; break; - case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break; - case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break; - case DIAGDIR_NW: if ((y & 0xF) != 0) return 0; break; + case DIAGDIR_NE: if ((x & 0xF) != 0) return VETSB_CONTINUE; break; + case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break; + case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break; + case DIAGDIR_NW: if ((y & 0xF) != 0) return VETSB_CONTINUE; break; } if (v->type == VEH_Train) { v->u.rail.track = TRACK_BIT_WORMHOLE; @@ -1356,25 +1356,25 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y } else { v->u.road.state = 0xFF; } - return 4; + return VETSB_ENTERED_WORMHOLE; } else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) { v->tile = tile; if (v->type == VEH_Train) { if (v->u.rail.track == 0x40) { v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y); - return 4; + return VETSB_ENTERED_WORMHOLE; } } else { if (v->u.road.state == 0xFF) { v->u.road.state = _road_exit_tunnel_state[dir]; v->u.road.frame = 0; - return 4; + return VETSB_ENTERED_WORMHOLE; } } - return 0; + return VETSB_CONTINUE; } } - return 0; + return VETSB_CONTINUE; } extern const TileTypeProcs _tile_type_tunnelbridge_procs = { diff --git a/src/vehicle.cpp b/src/vehicle.cpp index bdee6fcd5..5f6fe6a52 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2769,10 +2769,11 @@ Trackdir GetVehicleTrackdir(const Vehicle* v) default: return INVALID_TRACKDIR; } } -/* Return value has bit 0x2 set, when the vehicle enters a station. Then, - * result << 8 contains the id of the station entered. If the return value has - * bit 0x8 set, the vehicle could not and did not enter the tile. Are there - * other bits that can be set? */ + +/** + * Returns some meta-data over the to be entered tile. + * @see VehicleEnterTileStatus to see what the bits in the return value mean. + */ uint32 VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y) { return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y); diff --git a/src/vehicle.h b/src/vehicle.h index 9fa8837d9..7a2fe8780 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -7,6 +7,26 @@ #include "order.h" #include "rail.h" +/** The returned bits of VehicleEnterTile. */ +enum VehicleEnterTileStatus { + VETS_ENTERED_STATION = 1, ///< The vehicle entered a station + VETS_ENTERED_WORMHOLE = 2, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel) + VETS_CANNOT_ENTER = 3, ///< The vehicle cannot enter the tile + + /** + * Shift the VehicleEnterTileStatus this many bits + * to the right to get the station ID when + * VETS_ENTERED_STATION is set + */ + VETS_STATION_ID_OFFSET = 8, + + /** Bit sets of the above specified bits */ + VETSB_CONTINUE = 0, ///< The vehicle can continue normally + VETSB_ENTERED_STATION = 1 << VETS_ENTERED_STATION, ///< The vehicle entered a station + VETSB_ENTERED_WORMHOLE = 1 << VETS_ENTERED_WORMHOLE, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel) + VETSB_CANNOT_ENTER = 1 << VETS_CANNOT_ENTER, ///< The vehicle cannot enter the tile +}; + enum { VEH_Train, VEH_Road, diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 00f2fa934..cd42138d5 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -742,7 +742,7 @@ static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID static uint32 VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y) { - return 0; + return VETSB_CONTINUE; } |