From ea0fa2194a90e59724df49191440946f06205ede Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 21 Feb 2024 23:04:41 +0000 Subject: [PATCH] Add debug console command to unblock bay road stops with incorrect occupancy state --- src/console_cmds.cpp | 26 ++++++++++++++++++++++++++ src/roadstop.cpp | 15 +++++++++++++++ src/roadstop_base.h | 3 +++ 3 files changed, 44 insertions(+) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index ac54f45d88..35673219c2 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -63,6 +63,7 @@ #include "tile_cmd.h" #include "object_base.h" #include "newgrf_newsignals.h" +#include "roadstop_base.h" #include #include "3rdparty/cpp-btree/btree_set.h" @@ -2593,6 +2594,30 @@ DEF_CONSOLE_CMD(ConMergeLinkgraphJobsAsap) return true; } +DEF_CONSOLE_CMD(ConUnblockBayRoadStops) +{ + if (argc == 0) { + IConsoleHelp("Unblock bay road stops blocked by a bug, for single-player use only."); + return true; + } + + for (Station *st : Station::Iterate()) { + for (RoadStopType rs_type : { ROADSTOP_BUS, ROADSTOP_TRUCK }) { + for (RoadStop *rs = st->GetPrimaryRoadStop(rs_type); rs != nullptr; rs = rs->next) { + if (IsBayRoadStopTile(rs->xy)) { + rs->DebugClearOccupancy(); + } + } + } + } + for (const RoadVehicle *rv : RoadVehicle::Iterate()) { + if (IsInsideMM(rv->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) { + RoadStop::GetByTile(rv->tile, GetRoadStopType(rv->tile))->DebugReEnter(rv); + } + } + return true; +} + DEF_CONSOLE_CMD(ConDbgSpecial) { if (argc == 0) { @@ -4113,6 +4138,7 @@ void IConsoleStdLibRegister() /* Bug workarounds */ IConsole::CmdRegister("jgrpp_bug_workaround_unblock_heliports", ConResetBlockedHeliports, ConHookNoNetwork, true); IConsole::CmdRegister("merge_linkgraph_jobs_asap", ConMergeLinkgraphJobsAsap, ConHookNoNetwork, true); + IConsole::CmdRegister("unblock_bay_road_stops", ConUnblockBayRoadStops, ConHookNoNetwork, true); IConsole::CmdRegister("dbgspecial", ConDbgSpecial, ConHookSpecialCmd, true); diff --git a/src/roadstop.cpp b/src/roadstop.cpp index cf95fcc155..0a4cacd17f 100644 --- a/src/roadstop.cpp +++ b/src/roadstop.cpp @@ -370,6 +370,21 @@ bool RoadStop::Enter(RoadVehicle *rv) } } +void RoadStop::DebugClearOccupancy() +{ + SetBit(this->status, RSSFB_BAY0_FREE); + SetBit(this->status, RSSFB_BAY1_FREE); + ClrBit(this->status, RSSFB_ENTRY_BUSY); +} + +void RoadStop::DebugReEnter(const RoadVehicle *rv) +{ + if (!IsInsideMM(rv->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) return; + + ClrBit(this->status, HasBit(rv->state, RVS_USING_SECOND_BAY) ? RSSFB_BAY1_FREE : RSSFB_BAY0_FREE); + if (!HasBit(rv->state, RVS_ENTERED_STOP)) SetBit(this->status, RSSFB_ENTRY_BUSY); +} + /** * Leave the road stop * @param rv the vehicle that leaves the stop diff --git a/src/roadstop_base.h b/src/roadstop_base.h index 1474cd115c..7281fa9f7b 100644 --- a/src/roadstop_base.h +++ b/src/roadstop_base.h @@ -167,6 +167,9 @@ struct RoadStop : RoadStopPool::PoolItem<&_roadstop_pool> { static bool IsDriveThroughRoadStopContinuation(TileIndex rs, TileIndex next); + void DebugClearOccupancy(); + void DebugReEnter(const RoadVehicle *rv); + private: Entry *east; ///< The vehicles that entered from the east Entry *west; ///< The vehicles that entered from the west