mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Replace bitstuffed VehicleEnterTileStatus. (#14027)
VehicleEnterTileStatus was an bitset-style enum, but bitstuffed with a StationID. However the StationID part was only used by trains, and only in two locations. Instead, return just the enum bitset. The two places which require the StationID just call GetStationIndex() directly.pull/14052/head
parent
cb113cfed0
commit
fc45bb5a2b
|
@ -2933,10 +2933,10 @@ int TicksToLeaveDepot(const Train *v)
|
||||||
* Tile callback routine when vehicle enters tile
|
* Tile callback routine when vehicle enters tile
|
||||||
* @see vehicle_enter_tile_proc
|
* @see vehicle_enter_tile_proc
|
||||||
*/
|
*/
|
||||||
static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int x, int y)
|
static VehicleEnterTileStates VehicleEnter_Track(Vehicle *u, TileIndex tile, int x, int y)
|
||||||
{
|
{
|
||||||
/* This routine applies only to trains in depot tiles. */
|
/* This routine applies only to trains in depot tiles. */
|
||||||
if (u->type != VEH_TRAIN || !IsRailDepotTile(tile)) return VETSB_CONTINUE;
|
if (u->type != VEH_TRAIN || !IsRailDepotTile(tile)) return {};
|
||||||
|
|
||||||
/* Depot direction. */
|
/* Depot direction. */
|
||||||
DiagDirection dir = GetRailDepotDirection(tile);
|
DiagDirection dir = GetRailDepotDirection(tile);
|
||||||
|
@ -2944,7 +2944,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
|
||||||
uint8_t fract_coord = (x & 0xF) + ((y & 0xF) << 4);
|
uint8_t fract_coord = (x & 0xF) + ((y & 0xF) << 4);
|
||||||
|
|
||||||
/* Make sure a train is not entering the tile from behind. */
|
/* Make sure a train is not entering the tile from behind. */
|
||||||
if (_fractcoords_behind[dir] == fract_coord) return VETSB_CANNOT_ENTER;
|
if (_fractcoords_behind[dir] == fract_coord) return VehicleEnterTileState::CannotEnter;
|
||||||
|
|
||||||
Train *v = Train::From(u);
|
Train *v = Train::From(u);
|
||||||
|
|
||||||
|
@ -2976,10 +2976,10 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
|
||||||
v->tile = tile;
|
v->tile = tile;
|
||||||
|
|
||||||
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
|
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
}
|
}
|
||||||
|
|
||||||
return VETSB_CONTINUE;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2250,7 +2250,7 @@ static const uint8_t _roadveh_enter_depot_dir[4] = {
|
||||||
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE
|
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE
|
||||||
};
|
};
|
||||||
|
|
||||||
static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int, int)
|
static VehicleEnterTileStates VehicleEnter_Road(Vehicle *v, TileIndex tile, int, int)
|
||||||
{
|
{
|
||||||
switch (GetRoadTileType(tile)) {
|
switch (GetRoadTileType(tile)) {
|
||||||
case ROAD_TILE_DEPOT: {
|
case ROAD_TILE_DEPOT: {
|
||||||
|
@ -2266,14 +2266,14 @@ static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int,
|
||||||
rv->tile = tile;
|
rv->tile = tile;
|
||||||
|
|
||||||
InvalidateWindowData(WC_VEHICLE_DEPOT, rv->tile);
|
InvalidateWindowData(WC_VEHICLE_DEPOT, rv->tile);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return VETSB_CONTINUE;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1164,7 +1164,7 @@ bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
|
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && VehicleEnterTile(v, gp.new_tile, gp.x, gp.y).Test(VehicleEnterTileState::EnteredWormhole)) {
|
||||||
/* Vehicle has just entered a bridge or tunnel */
|
/* Vehicle has just entered a bridge or tunnel */
|
||||||
v->x_pos = gp.x;
|
v->x_pos = gp.x;
|
||||||
v->y_pos = gp.y;
|
v->y_pos = gp.y;
|
||||||
|
@ -1284,8 +1284,8 @@ again:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t r = VehicleEnterTile(v, tile, x, y);
|
auto vets = VehicleEnterTile(v, tile, x, y);
|
||||||
if (HasBit(r, VETS_CANNOT_ENTER)) {
|
if (vets.Test(VehicleEnterTileState::CannotEnter)) {
|
||||||
if (!IsTileType(tile, MP_TUNNELBRIDGE)) {
|
if (!IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||||
v->cur_speed = 0;
|
v->cur_speed = 0;
|
||||||
return false;
|
return false;
|
||||||
|
@ -1321,7 +1321,7 @@ again:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
|
if (!vets.Test(VehicleEnterTileState::EnteredWormhole)) {
|
||||||
TileIndex old_tile = v->tile;
|
TileIndex old_tile = v->tile;
|
||||||
|
|
||||||
v->tile = tile;
|
v->tile = tile;
|
||||||
|
@ -1399,8 +1399,8 @@ again:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t r = VehicleEnterTile(v, v->tile, x, y);
|
auto vets = VehicleEnterTile(v, v->tile, x, y);
|
||||||
if (HasBit(r, VETS_CANNOT_ENTER)) {
|
if (vets.Test(VehicleEnterTileState::CannotEnter)) {
|
||||||
v->cur_speed = 0;
|
v->cur_speed = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1541,8 +1541,8 @@ again:
|
||||||
|
|
||||||
/* Check tile position conditions - i.e. stop position in depot,
|
/* Check tile position conditions - i.e. stop position in depot,
|
||||||
* entry onto bridge or into tunnel */
|
* entry onto bridge or into tunnel */
|
||||||
uint32_t r = VehicleEnterTile(v, v->tile, x, y);
|
auto vets = VehicleEnterTile(v, v->tile, x, y);
|
||||||
if (HasBit(r, VETS_CANNOT_ENTER)) {
|
if (vets.Test(VehicleEnterTileState::CannotEnter)) {
|
||||||
v->cur_speed = 0;
|
v->cur_speed = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1553,7 +1553,7 @@ again:
|
||||||
|
|
||||||
/* Move to next frame unless vehicle arrived at a stop position
|
/* Move to next frame unless vehicle arrived at a stop position
|
||||||
* in a depot or entered a tunnel/bridge */
|
* in a depot or entered a tunnel/bridge */
|
||||||
if (!HasBit(r, VETS_ENTERED_WORMHOLE)) v->frame++;
|
if (!vets.Test(VehicleEnterTileState::EnteredWormhole)) v->frame++;
|
||||||
v->x_pos = x;
|
v->x_pos = x;
|
||||||
v->y_pos = y;
|
v->y_pos = y;
|
||||||
v->UpdatePosition();
|
v->UpdatePosition();
|
||||||
|
|
|
@ -742,8 +742,8 @@ static void ShipController(Ship *v)
|
||||||
gp.y = v->y_pos;
|
gp.y = v->y_pos;
|
||||||
} else {
|
} else {
|
||||||
/* Not inside depot */
|
/* Not inside depot */
|
||||||
const VehicleEnterTileStatus r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
auto vets = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
||||||
if (HasBit(r, VETS_CANNOT_ENTER)) return ReverseShip(v);
|
if (vets.Test(VehicleEnterTileState::CannotEnter)) return ReverseShip(v);
|
||||||
|
|
||||||
/* A leave station order only needs one tick to get processed, so we can
|
/* A leave station order only needs one tick to get processed, so we can
|
||||||
* always skip ahead. */
|
* always skip ahead. */
|
||||||
|
@ -810,10 +810,10 @@ static void ShipController(Ship *v)
|
||||||
gp.y = (gp.y & ~0xF) | b.y_subcoord;
|
gp.y = (gp.y & ~0xF) | b.y_subcoord;
|
||||||
|
|
||||||
/* Call the landscape function and tell it that the vehicle entered the tile */
|
/* Call the landscape function and tell it that the vehicle entered the tile */
|
||||||
const VehicleEnterTileStatus r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
auto vets = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
||||||
if (HasBit(r, VETS_CANNOT_ENTER)) return ReverseShip(v);
|
if (vets.Test(VehicleEnterTileState::CannotEnter)) return ReverseShip(v);
|
||||||
|
|
||||||
if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
|
if (!vets.Test(VehicleEnterTileState::EnteredWormhole)) {
|
||||||
v->tile = gp.new_tile;
|
v->tile = gp.new_tile;
|
||||||
v->state = TrackToTrackBits(track);
|
v->state = TrackToTrackBits(track);
|
||||||
|
|
||||||
|
@ -843,7 +843,7 @@ static void ShipController(Ship *v)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* On a bridge */
|
/* On a bridge */
|
||||||
if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
|
if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !VehicleEnterTile(v, gp.new_tile, gp.x, gp.y).Test(VehicleEnterTileState::EnteredWormhole)) {
|
||||||
v->x_pos = gp.x;
|
v->x_pos = gp.x;
|
||||||
v->y_pos = gp.y;
|
v->y_pos = gp.y;
|
||||||
v->UpdatePosition();
|
v->UpdatePosition();
|
||||||
|
|
|
@ -3696,12 +3696,12 @@ static bool ClickTile_Station(TileIndex tile)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
|
static VehicleEnterTileStates VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
|
||||||
{
|
{
|
||||||
if (v->type == VEH_TRAIN) {
|
if (v->type == VEH_TRAIN) {
|
||||||
StationID station_id = GetStationIndex(tile);
|
StationID station_id = GetStationIndex(tile);
|
||||||
if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE;
|
if (!v->current_order.ShouldStopAtStation(v, station_id)) return {};
|
||||||
if (!IsRailStation(tile) || !v->IsFrontEngine()) return VETSB_CONTINUE;
|
if (!IsRailStation(tile) || !v->IsFrontEngine()) return {};
|
||||||
|
|
||||||
int station_ahead;
|
int station_ahead;
|
||||||
int station_length;
|
int station_length;
|
||||||
|
@ -3711,7 +3711,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
|
||||||
* begin of the platform to the stop location is longer than the length
|
* begin of the platform to the stop location is longer than the length
|
||||||
* of the platform. Station ahead 'includes' the current tile where the
|
* of the platform. Station ahead 'includes' the current tile where the
|
||||||
* vehicle is on, so we need to subtract that. */
|
* vehicle is on, so we need to subtract that. */
|
||||||
if (stop + station_ahead - (int)TILE_SIZE >= station_length) return VETSB_CONTINUE;
|
if (stop + station_ahead - (int)TILE_SIZE >= station_length) return {};
|
||||||
|
|
||||||
DiagDirection dir = DirToDiagDir(v->direction);
|
DiagDirection dir = DirToDiagDir(v->direction);
|
||||||
|
|
||||||
|
@ -3724,7 +3724,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
|
||||||
stop &= TILE_SIZE - 1;
|
stop &= TILE_SIZE - 1;
|
||||||
|
|
||||||
if (x == stop) {
|
if (x == stop) {
|
||||||
return VETSB_ENTERED_STATION | static_cast<VehicleEnterTileStatus>(station_id.base() << VETS_STATION_ID_OFFSET); // enter station
|
return VehicleEnterTileState::EnteredStation; // enter station
|
||||||
} else if (x < stop) {
|
} else if (x < stop) {
|
||||||
v->vehstatus.Set(VehState::TrainSlowing);
|
v->vehstatus.Set(VehState::TrainSlowing);
|
||||||
uint16_t spd = std::max(0, (stop - x) * 20 - 15);
|
uint16_t spd = std::max(0, (stop - x) * 20 - 15);
|
||||||
|
@ -3736,12 +3736,13 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
|
||||||
if (rv->state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)rv->state) && rv->frame == 0) {
|
if (rv->state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)rv->state) && rv->frame == 0) {
|
||||||
if (IsStationRoadStop(tile) && rv->IsFrontEngine()) {
|
if (IsStationRoadStop(tile) && rv->IsFrontEngine()) {
|
||||||
/* Attempt to allocate a parking bay in a road stop */
|
/* Attempt to allocate a parking bay in a road stop */
|
||||||
return RoadStop::GetByTile(tile, GetRoadStopType(tile))->Enter(rv) ? VETSB_CONTINUE : VETSB_CANNOT_ENTER;
|
if (RoadStop::GetByTile(tile, GetRoadStopType(tile))->Enter(rv)) return {};
|
||||||
|
return VehicleEnterTileState::CannotEnter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return VETSB_CONTINUE;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,27 +17,13 @@
|
||||||
#include "tile_map.h"
|
#include "tile_map.h"
|
||||||
#include "timer/timer_game_calendar.h"
|
#include "timer/timer_game_calendar.h"
|
||||||
|
|
||||||
/** The returned bits of VehicleEnterTile. */
|
enum class VehicleEnterTileState : uint8_t {
|
||||||
enum VehicleEnterTileStatus : uint32_t {
|
EnteredStation, ///< The vehicle entered a station
|
||||||
VETS_ENTERED_STATION = 1, ///< The vehicle entered a station
|
EnteredWormhole, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel)
|
||||||
VETS_ENTERED_WORMHOLE = 2, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel)
|
CannotEnter, ///< The vehicle cannot enter the tile
|
||||||
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,
|
|
||||||
VETS_STATION_MASK = 0xFFFF << VETS_STATION_ID_OFFSET,
|
|
||||||
|
|
||||||
/** 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
|
|
||||||
};
|
};
|
||||||
DECLARE_ENUM_AS_BIT_SET(VehicleEnterTileStatus)
|
|
||||||
|
using VehicleEnterTileStates = EnumBitSet<VehicleEnterTileState, uint8_t>;
|
||||||
|
|
||||||
/** Tile information, used while rendering the tile */
|
/** Tile information, used while rendering the tile */
|
||||||
struct TileInfo {
|
struct TileInfo {
|
||||||
|
@ -131,8 +117,7 @@ typedef void AnimateTileProc(TileIndex tile);
|
||||||
typedef void TileLoopProc(TileIndex tile);
|
typedef void TileLoopProc(TileIndex tile);
|
||||||
typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
|
typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
|
||||||
|
|
||||||
/** @see VehicleEnterTileStatus to see what the return values mean */
|
typedef VehicleEnterTileStates VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
|
||||||
typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
|
|
||||||
typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
|
typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,7 +161,7 @@ struct TileTypeProcs {
|
||||||
extern const TileTypeProcs * const _tile_type_procs[16];
|
extern const TileTypeProcs * const _tile_type_procs[16];
|
||||||
|
|
||||||
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
|
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
|
||||||
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
|
VehicleEnterTileStates VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
|
||||||
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
|
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
|
||||||
void GetTileDesc(TileIndex tile, TileDesc &td);
|
void GetTileDesc(TileIndex tile, TileDesc &td);
|
||||||
|
|
||||||
|
|
|
@ -3300,13 +3300,13 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
|
||||||
/* Reverse when we are at the end of the track already, do not move to the new position */
|
/* Reverse when we are at the end of the track already, do not move to the new position */
|
||||||
if (v->IsFrontEngine() && !TrainCheckIfLineEnds(v, reverse)) return false;
|
if (v->IsFrontEngine() && !TrainCheckIfLineEnds(v, reverse)) return false;
|
||||||
|
|
||||||
uint32_t r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
auto vets = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
||||||
if (HasBit(r, VETS_CANNOT_ENTER)) {
|
if (vets.Test(VehicleEnterTileState::CannotEnter)) {
|
||||||
goto invalid_rail;
|
goto invalid_rail;
|
||||||
}
|
}
|
||||||
if (HasBit(r, VETS_ENTERED_STATION)) {
|
if (vets.Test(VehicleEnterTileState::EnteredStation)) {
|
||||||
/* The new position is the end of the platform */
|
/* The new position is the end of the platform */
|
||||||
TrainEnterStation(v, StationID(r >> VETS_STATION_ID_OFFSET));
|
TrainEnterStation(v, GetStationIndex(gp.new_tile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -3447,12 +3447,12 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
|
||||||
Direction chosen_dir = (Direction)b[2];
|
Direction chosen_dir = (Direction)b[2];
|
||||||
|
|
||||||
/* Call the landscape function and tell it that the vehicle entered the tile */
|
/* Call the landscape function and tell it that the vehicle entered the tile */
|
||||||
uint32_t r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
auto vets = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
||||||
if (HasBit(r, VETS_CANNOT_ENTER)) {
|
if (vets.Test(VehicleEnterTileState::CannotEnter)) {
|
||||||
goto invalid_rail;
|
goto invalid_rail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
|
if (!vets.Test(VehicleEnterTileState::EnteredWormhole)) {
|
||||||
Track track = FindFirstTrack(chosen_track);
|
Track track = FindFirstTrack(chosen_track);
|
||||||
Trackdir tdir = TrackDirectionToTrackdir(track, chosen_dir);
|
Trackdir tdir = TrackDirectionToTrackdir(track, chosen_dir);
|
||||||
if (v->IsFrontEngine() && HasPbsSignalOnTrackdir(gp.new_tile, tdir)) {
|
if (v->IsFrontEngine() && HasPbsSignalOnTrackdir(gp.new_tile, tdir)) {
|
||||||
|
@ -3498,13 +3498,13 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
|
||||||
CheckNextTrainTile(v);
|
CheckNextTrainTile(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HasBit(r, VETS_ENTERED_STATION)) {
|
if (vets.Test(VehicleEnterTileState::EnteredStation)) {
|
||||||
/* The new position is the location where we want to stop */
|
/* The new position is the location where we want to stop */
|
||||||
TrainEnterStation(v, StationID(r >> VETS_STATION_ID_OFFSET));
|
TrainEnterStation(v, GetStationIndex(gp.new_tile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
|
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && VehicleEnterTile(v, gp.new_tile, gp.x, gp.y).Test(VehicleEnterTileState::EnteredWormhole)) {
|
||||||
/* Perform look-ahead on tunnel exit. */
|
/* Perform look-ahead on tunnel exit. */
|
||||||
if (v->IsFrontEngine()) {
|
if (v->IsFrontEngine()) {
|
||||||
TryReserveRailTrack(gp.new_tile, DiagDirToDiagTrack(GetTunnelBridgeDirection(gp.new_tile)));
|
TryReserveRailTrack(gp.new_tile, DiagDirToDiagTrack(GetTunnelBridgeDirection(gp.new_tile)));
|
||||||
|
|
|
@ -1882,11 +1882,11 @@ static const uint8_t TUNNEL_SOUND_FRAME = 1;
|
||||||
*/
|
*/
|
||||||
extern const uint8_t _tunnel_visibility_frame[DIAGDIR_END] = {12, 8, 8, 12};
|
extern const uint8_t _tunnel_visibility_frame[DIAGDIR_END] = {12, 8, 8, 12};
|
||||||
|
|
||||||
static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
|
static VehicleEnterTileStates VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
|
||||||
{
|
{
|
||||||
int z = GetSlopePixelZ(x, y, true) - v->z_pos;
|
int z = GetSlopePixelZ(x, y, true) - v->z_pos;
|
||||||
|
|
||||||
if (abs(z) > 2) return VETSB_CANNOT_ENTER;
|
if (abs(z) > 2) return VehicleEnterTileState::CannotEnter;
|
||||||
/* Direction into the wormhole */
|
/* Direction into the wormhole */
|
||||||
const DiagDirection dir = GetTunnelBridgeDirection(tile);
|
const DiagDirection dir = GetTunnelBridgeDirection(tile);
|
||||||
/* Direction of the vehicle */
|
/* Direction of the vehicle */
|
||||||
|
@ -1905,13 +1905,13 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
if (!PlayVehicleSound(t, VSE_TUNNEL) && RailVehInfo(t->engine_type)->engclass == 0) {
|
if (!PlayVehicleSound(t, VSE_TUNNEL) && RailVehInfo(t->engine_type)->engclass == 0) {
|
||||||
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
|
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
|
||||||
}
|
}
|
||||||
return VETSB_CONTINUE;
|
return {};
|
||||||
}
|
}
|
||||||
if (frame == _tunnel_visibility_frame[dir]) {
|
if (frame == _tunnel_visibility_frame[dir]) {
|
||||||
t->tile = tile;
|
t->tile = tile;
|
||||||
t->track = TRACK_BIT_WORMHOLE;
|
t->track = TRACK_BIT_WORMHOLE;
|
||||||
t->vehstatus.Set(VehState::Hidden);
|
t->vehstatus.Set(VehState::Hidden);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1921,7 +1921,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
t->track = DiagDirToDiagTrackBits(vdir);
|
t->track = DiagDirToDiagTrackBits(vdir);
|
||||||
assert(t->track);
|
assert(t->track);
|
||||||
t->vehstatus.Reset(VehState::Hidden);
|
t->vehstatus.Reset(VehState::Hidden);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
}
|
}
|
||||||
} else if (v->type == VEH_ROAD) {
|
} else if (v->type == VEH_ROAD) {
|
||||||
RoadVehicle *rv = RoadVehicle::From(v);
|
RoadVehicle *rv = RoadVehicle::From(v);
|
||||||
|
@ -1934,9 +1934,9 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
rv->tile = tile;
|
rv->tile = tile;
|
||||||
rv->state = RVSB_WORMHOLE;
|
rv->state = RVSB_WORMHOLE;
|
||||||
rv->vehstatus.Set(VehState::Hidden);
|
rv->vehstatus.Set(VehState::Hidden);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
} else {
|
} else {
|
||||||
return VETSB_CONTINUE;
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1946,7 +1946,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
rv->state = DiagDirToDiagTrackdir(vdir);
|
rv->state = DiagDirToDiagTrackdir(vdir);
|
||||||
rv->frame = frame;
|
rv->frame = frame;
|
||||||
rv->vehstatus.Reset(VehState::Hidden);
|
rv->vehstatus.Reset(VehState::Hidden);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // IsBridge(tile)
|
} else { // IsBridge(tile)
|
||||||
|
@ -1961,7 +1961,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
|
|
||||||
if (vdir == dir) {
|
if (vdir == dir) {
|
||||||
/* Vehicle enters bridge at the last frame inside this tile. */
|
/* Vehicle enters bridge at the last frame inside this tile. */
|
||||||
if (frame != TILE_SIZE - 1) return VETSB_CONTINUE;
|
if (frame != TILE_SIZE - 1) return {};
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN: {
|
case VEH_TRAIN: {
|
||||||
Train *t = Train::From(v);
|
Train *t = Train::From(v);
|
||||||
|
@ -1983,7 +1983,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
} else if (vdir == ReverseDiagDir(dir)) {
|
} else if (vdir == ReverseDiagDir(dir)) {
|
||||||
v->tile = tile;
|
v->tile = tile;
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
|
@ -1991,7 +1991,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
Train *t = Train::From(v);
|
Train *t = Train::From(v);
|
||||||
if (t->track == TRACK_BIT_WORMHOLE) {
|
if (t->track == TRACK_BIT_WORMHOLE) {
|
||||||
t->track = DiagDirToDiagTrackBits(vdir);
|
t->track = DiagDirToDiagTrackBits(vdir);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2001,7 +2001,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
if (rv->state == RVSB_WORMHOLE) {
|
if (rv->state == RVSB_WORMHOLE) {
|
||||||
rv->state = DiagDirToDiagTrackdir(vdir);
|
rv->state = DiagDirToDiagTrackdir(vdir);
|
||||||
rv->frame = 0;
|
rv->frame = 0;
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2010,7 +2010,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
Ship *ship = Ship::From(v);
|
Ship *ship = Ship::From(v);
|
||||||
if (ship->state == TRACK_BIT_WORMHOLE) {
|
if (ship->state == TRACK_BIT_WORMHOLE) {
|
||||||
ship->state = DiagDirToDiagTrackBits(vdir);
|
ship->state = DiagDirToDiagTrackBits(vdir);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VehicleEnterTileState::EnteredWormhole;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2019,7 +2019,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return VETSB_CONTINUE;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
|
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
|
||||||
|
|
|
@ -1837,9 +1837,9 @@ Direction GetDirectionTowards(const Vehicle *v, int x, int y)
|
||||||
* @param x X position
|
* @param x X position
|
||||||
* @param y Y position
|
* @param y Y position
|
||||||
* @return Some meta-data over the to be entered tile.
|
* @return Some meta-data over the to be entered tile.
|
||||||
* @see VehicleEnterTileStatus to see what the bits in the return value mean.
|
* @see VehicleEnterTileStates to see what the bits in the return value mean.
|
||||||
*/
|
*/
|
||||||
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
|
VehicleEnterTileStates VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
|
||||||
{
|
{
|
||||||
return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y);
|
return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1400,9 +1400,9 @@ static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_own
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *, TileIndex, int, int)
|
static VehicleEnterTileStates VehicleEnter_Water(Vehicle *, TileIndex, int, int)
|
||||||
{
|
{
|
||||||
return VETSB_CONTINUE;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static CommandCost TerraformTile_Water(TileIndex tile, DoCommandFlags flags, int, Slope)
|
static CommandCost TerraformTile_Water(TileIndex tile, DoCommandFlags flags, int, Slope)
|
||||||
|
|
Loading…
Reference in New Issue