mirror of https://github.com/OpenTTD/OpenTTD
Change: Adapt how ships enter and leave extended depots.
parent
3715dcf2d7
commit
8a9a627577
|
@ -374,6 +374,12 @@ static bool CheckReverseShip(const Ship *v, Trackdir *trackdir = nullptr)
|
||||||
return YapfShipCheckReverse(v, trackdir);
|
return YapfShipCheckReverse(v, trackdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool CheckPlaceShipOnDepot(TileIndex tile)
|
||||||
|
{
|
||||||
|
assert(IsShipDepotTile(tile));
|
||||||
|
return !IsExtendedDepot(tile) || IsExtendedDepotEmpty(tile);
|
||||||
|
}
|
||||||
|
|
||||||
void HandleShipEnterDepot(Ship *v)
|
void HandleShipEnterDepot(Ship *v)
|
||||||
{
|
{
|
||||||
assert(IsShipDepotTile(v->tile));
|
assert(IsShipDepotTile(v->tile));
|
||||||
|
@ -403,19 +409,21 @@ static bool CheckShipLeaveDepot(Ship *v)
|
||||||
/* We are leaving a depot, but have to go to the exact same one; re-enter */
|
/* We are leaving a depot, but have to go to the exact same one; re-enter */
|
||||||
if (v->current_order.IsType(OT_GOTO_DEPOT) &&
|
if (v->current_order.IsType(OT_GOTO_DEPOT) &&
|
||||||
IsShipDepotTile(v->tile) && GetDepotIndex(v->tile) == v->current_order.GetDestination()) {
|
IsShipDepotTile(v->tile) && GetDepotIndex(v->tile) == v->current_order.GetDestination()) {
|
||||||
VehicleEnterDepot(v);
|
HandleShipEnterDepot(v);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't leave depot if no destination set */
|
/* Don't leave depot if no destination set */
|
||||||
if (v->dest_tile == 0) return true;
|
if (v->dest_tile == 0) return true;
|
||||||
|
|
||||||
|
if (!IsExtendedDepot(v->tile)) {
|
||||||
/* Don't leave depot if another vehicle is already entering/leaving */
|
/* Don't leave depot if another vehicle is already entering/leaving */
|
||||||
/* This helps avoid CPU load if many ships are set to start at the same time */
|
/* This helps avoid CPU load if many ships are set to start at the same time */
|
||||||
if (HasVehicleOnPos(v->tile, nullptr, &EnsureNoMovingShipProc)) return true;
|
if (HasVehicleOnPos(v->tile, nullptr, &EnsureNoMovingShipProc)) return true;
|
||||||
|
|
||||||
TileIndex tile = v->tile;
|
TileIndex tile = v->tile;
|
||||||
Axis axis = GetShipDepotAxis(tile);
|
Axis axis = GetShipDepotAxis(tile);
|
||||||
|
bool reverse = false;
|
||||||
|
|
||||||
DiagDirection north_dir = ReverseDiagDir(AxisToDiagDir(axis));
|
DiagDirection north_dir = ReverseDiagDir(AxisToDiagDir(axis));
|
||||||
TileIndex north_neighbour = TileAdd(tile, TileOffsByDiagDir(north_dir));
|
TileIndex north_neighbour = TileAdd(tile, TileOffsByDiagDir(north_dir));
|
||||||
|
@ -442,6 +450,14 @@ static bool CheckShipLeaveDepot(Ship *v)
|
||||||
v->state = AxisToTrackBits(axis);
|
v->state = AxisToTrackBits(axis);
|
||||||
v->vehstatus &= ~VS_HIDDEN;
|
v->vehstatus &= ~VS_HIDDEN;
|
||||||
|
|
||||||
|
/* Leave towards south if reverse. */
|
||||||
|
v->rotation = v->direction = DiagDirToDir(reverse ? south_dir : north_dir);
|
||||||
|
|
||||||
|
v->state = AxisToTrackBits(axis);
|
||||||
|
v->vehstatus &= ~VS_HIDDEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
v->state &= ~TRACK_BIT_DEPOT;
|
||||||
v->cur_speed = 0;
|
v->cur_speed = 0;
|
||||||
v->UpdateViewport(true, true);
|
v->UpdateViewport(true, true);
|
||||||
DepotID depot_id = GetDepotIndex(v->tile);
|
DepotID depot_id = GetDepotIndex(v->tile);
|
||||||
|
@ -733,6 +749,8 @@ static void ShipController(Ship *v)
|
||||||
|
|
||||||
if (v->vehstatus & VS_STOPPED) return;
|
if (v->vehstatus & VS_STOPPED) return;
|
||||||
|
|
||||||
|
if (v->ContinueServicing()) return;
|
||||||
|
|
||||||
if (ProcessOrders(v) && CheckReverseShip(v)) return ReverseShip(v);
|
if (ProcessOrders(v) && CheckReverseShip(v)) return ReverseShip(v);
|
||||||
|
|
||||||
v->HandleLoading();
|
v->HandleLoading();
|
||||||
|
@ -816,11 +834,13 @@ static void ShipController(Ship *v)
|
||||||
IsShipDepotTile(gp.new_tile) &&
|
IsShipDepotTile(gp.new_tile) &&
|
||||||
GetOtherShipDepotTile(gp.new_tile) == gp.old_tile &&
|
GetOtherShipDepotTile(gp.new_tile) == gp.old_tile &&
|
||||||
v->current_order.GetDestination() == GetDepotIndex(gp.new_tile)) {
|
v->current_order.GetDestination() == GetDepotIndex(gp.new_tile)) {
|
||||||
|
if (CheckPlaceShipOnDepot(v->tile)) {
|
||||||
HandleShipEnterDepot(v);
|
HandleShipEnterDepot(v);
|
||||||
v->UpdatePosition();
|
v->UpdatePosition();
|
||||||
v->UpdateViewport(true, true);
|
v->UpdateViewport(true, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const DiagDirection diagdir = DiagdirBetweenTiles(gp.old_tile, gp.new_tile);
|
const DiagDirection diagdir = DiagdirBetweenTiles(gp.old_tile, gp.new_tile);
|
||||||
assert(diagdir != INVALID_DIAGDIR);
|
assert(diagdir != INVALID_DIAGDIR);
|
||||||
|
|
Loading…
Reference in New Issue