From 8a9afd462107b2c430ddca96a6662e965423bd1b Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 15 Apr 2022 17:46:42 +0100 Subject: [PATCH] Add road stops flag for drive-through stops only --- docs/newgrf-roadstops-nml.html | 2 ++ docs/newgrf-roadstops.html | 1 + src/newgrf_roadstop.h | 1 + src/road_gui.cpp | 28 ++++++++++++++++++++++++++-- src/station_cmd.cpp | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/newgrf-roadstops-nml.html b/docs/newgrf-roadstops-nml.html index 27298adb81..4cc908b753 100644 --- a/docs/newgrf-roadstops-nml.html +++ b/docs/newgrf-roadstops-nml.html @@ -80,6 +80,8 @@ Do not show one way road overlay sprites, this should only be set if different graphics are provided for the different one-way states using the one_way_info variable.

RST_GENERAL_FLAG_NO_CATENARY
Do not show catenary graphics. (This only takes effect from road_stops version 2).

+

RSF_GENERAL_FLAG_DRIVE_THROUGH_ONLY
+ Only allow drive-through stops (not bay stops). (This only takes effect from road_stops version 2).

minimum_bridge_heightArray of 6 items [0..255, ...]Minimum clearances required for a bridge for each of the 6 views/rotations (or 0 to not allow any bridge). Values are given in height level units (1 level == 8px). disallowed_bridge_pillarsArray of 6 items [bitmask(RST_BRIDGE_PILLAR_FLAG_, ...), ...] diff --git a/docs/newgrf-roadstops.html b/docs/newgrf-roadstops.html index 3fe9d73944..c6e08f9a89 100644 --- a/docs/newgrf-roadstops.html +++ b/docs/newgrf-roadstops.html @@ -151,6 +151,7 @@ 01Callback 141 needs random bits in variable 10 12Do not show one way road overlay sprites, this should only be set if different graphics are provided for the different one-way states using bits 0..1 of variable 50. 24Do not catenary graphics.
This requires road_stops, version 2. + 38Only allow drive-through stops (not bay stops).
This requires road_stops, version 2. The default value is 0 (no flags enabled).

diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index 19dfbd10a7..a7caa9feb3 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -67,6 +67,7 @@ enum RoadStopSpecFlags { RSF_CB141_RANDOM_BITS, ///< Callback 141 needs random bits. RSF_NO_ONE_WAY_OVERLAY, ///< Do not show one-way road overlays. RSF_NO_CATENARY, ///< Do not show catenary. + RSF_DRIVE_THROUGH_ONLY, ///< Stop is drive-through only. }; enum RoadStopSpecIntlFlags { diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 46a1b50cf6..a264bfc53f 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -1209,6 +1209,19 @@ private: this->vscrollList->ScrollTowards(pos); } + void CheckOrientationValid() + { + if (_roadstop_gui_settings.orientation >= DIAGDIR_END) return; + const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(_roadstop_gui_settings.roadstop_type); + if (spec != nullptr && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) { + this->RaiseWidget(_roadstop_gui_settings.orientation + WID_BROS_STATION_NE); + _roadstop_gui_settings.orientation = DIAGDIR_END; + this->LowerWidget(_roadstop_gui_settings.orientation + WID_BROS_STATION_NE); + this->SetDirty(); + DeleteWindowById(WC_SELECT_STATION, 0); + } + } + public: BuildRoadStationWindow(WindowDesc *desc, Window *parent, RoadStopType rs) : PickerWindowBase(desc, parent), filter_editbox(EDITBOX_MAX_SIZE * MAX_CHAR_LENGTH, EDITBOX_MAX_SIZE) { @@ -1291,6 +1304,7 @@ public: matrix->SetClicked(_roadstop_gui_settings.roadstop_type); this->EnsureSelectedClassIsVisible(); + this->CheckOrientationValid(); } } @@ -1479,8 +1493,10 @@ public: case WID_BROS_STATION_Y: { StationType st = GetRoadStationTypeByWindowClass(this->window_class); const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(_roadstop_gui_settings.roadstop_type); - if (spec == nullptr) { + bool disabled = (spec != nullptr && widget < WID_BROS_STATION_X && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)); + if (spec == nullptr || disabled) { StationPickerDrawSprite(r.left + WD_MATRIX_LEFT + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), st, INVALID_RAILTYPE, _cur_roadtype, widget - WID_BROS_STATION_NE); + if (disabled) GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER); } else { DrawRoadStopTile(r.left + WD_MATRIX_LEFT + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), _cur_roadtype, spec, st, (int)widget - WID_BROS_STATION_NE); } @@ -1523,7 +1539,9 @@ public: if (spec == nullptr) { StationPickerDrawSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), st, INVALID_RAILTYPE, _cur_roadtype, _roadstop_gui_settings.orientation); } else { - DrawRoadStopTile(x, y, _cur_roadtype, spec, st, (uint8)_roadstop_gui_settings.orientation); + DiagDirection orientation = _roadstop_gui_settings.orientation; + if (orientation < DIAGDIR_END && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) orientation = DIAGDIR_END; + DrawRoadStopTile(x, y, _cur_roadtype, spec, st, (uint8)orientation); } _cur_dpi = old_dpi; } @@ -1554,6 +1572,10 @@ public: case WID_BROS_STATION_NW: case WID_BROS_STATION_X: case WID_BROS_STATION_Y: + if (widget < WID_BROS_STATION_X) { + const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(_roadstop_gui_settings.roadstop_type); + if (spec != nullptr && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) return; + } this->RaiseWidget(_roadstop_gui_settings.orientation + WID_BROS_STATION_NE); _roadstop_gui_settings.orientation = (DiagDirection)(widget - WID_BROS_STATION_NE); this->LowerWidget(_roadstop_gui_settings.orientation + WID_BROS_STATION_NE); @@ -1585,6 +1607,7 @@ public: NWidgetMatrix *matrix = this->GetWidget(WID_BROS_MATRIX); matrix->SetCount(_roadstop_gui_settings.roadstop_count); matrix->SetClicked(_roadstop_gui_settings.roadstop_type); + this->CheckOrientationValid(); } if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); this->SetDirty(); @@ -1609,6 +1632,7 @@ public: if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); this->SetDirty(); DeleteWindowById(WC_SELECT_STATION, 0); + this->CheckOrientationValid(); break; } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 449f2fa772..af3834f03c 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2092,6 +2092,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin if (roadstopspec != nullptr) { if (type && roadstopspec->stop_type != ROADSTOPTYPE_FREIGHT && roadstopspec->stop_type != ROADSTOPTYPE_ALL) return CMD_ERROR; if (!type && roadstopspec->stop_type != ROADSTOPTYPE_PASSENGER && roadstopspec->stop_type != ROADSTOPTYPE_ALL) return CMD_ERROR; + if (!is_drive_through && HasBit(roadstopspec->flags, RSF_DRIVE_THROUGH_ONLY)) return CMD_ERROR; } /* Check if the requested road stop is too big */