diff options
-rw-r--r-- | src/lang/english.txt | 8 | ||||
-rw-r--r-- | src/rail_cmd.cpp | 28 | ||||
-rw-r--r-- | src/rail_gui.cpp | 16 | ||||
-rw-r--r-- | src/settings.cpp | 2 | ||||
-rw-r--r-- | src/settings_gui.cpp | 2 | ||||
-rw-r--r-- | src/settings_type.h | 2 |
6 files changed, 46 insertions, 12 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt index 4752dd188..c7bb537ec 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1172,6 +1172,14 @@ STR_CONFIG_PATCHES_ALLOW_SHARES :{LTBLUE}Allow b STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY :{LTBLUE}When dragging, place signals every: {ORANGE}{STRING1} tile(s) STR_CONFIG_PATCHES_SEMAPHORE_BUILD_BEFORE_DATE :{LTBLUE}Automatically build semaphores before: {ORANGE}{STRING1} STR_CONFIG_PATCHES_ENABLE_SIGNAL_GUI :{LTBLUE}Enable the signal GUI: {ORANGE}{STRING1} +STR_CONFIG_PATCHES_DEFAULT_SIGNAL_TYPE :{LTBLUE}Signal type to build by default: {ORANGE}{STRING1} +STR_CONFIG_PATCHES_DEFAULT_SIGNAL_NORMAL :Normal +STR_CONFIG_PATCHES_DEFAULT_SIGNAL_PBS :Advanced +STR_CONFIG_PATCHES_DEFAULT_SIGNAL_PBSOWAY :One-way advanced +STR_CONFIG_PATCHES_CYCLE_SIGNAL_TYPES :{LTBLUE}Cycle through signal types: {ORANGE}{STRING1} +STR_CONFIG_PATCHES_CYCLE_SIGNAL_NORMAL :Normal only +STR_CONFIG_PATCHES_CYCLE_SIGNAL_PBS :Advanced only +STR_CONFIG_PATCHES_CYCLE_SIGNAL_ALL :All STR_CONFIG_PATCHES_TOWN_LAYOUT_INVALID :{WHITE}The town layout "no more roads" isn't valid in the scenario editor STR_CONFIG_PATCHES_TOWN_LAYOUT :{LTBLUE}Select town-road layout: {ORANGE}{STRING1} diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 4ac7f76ac..a7d9bd4f2 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -794,8 +794,10 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p * - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum) * - p1 = (bit 3) - 1 = override signal/semaphore, or pre/exit/combo signal or (for bit 7) toggle variant (CTRL-toggle) * - p1 = (bit 4) - 0 = signals, 1 = semaphores - * - p1 = (bit 5-6) - type of the signal, for valid values see enum SignalType in rail_map.h - * - p1 = (bit 7) - convert the present signal type and variant + * - p1 = (bit 5-7) - type of the signal, for valid values see enum SignalType in rail_map.h + * - p1 = (bit 8) - convert the present signal type and variant + * - p1 = (bit 9-11)- start cycle from this signal type + * - p1 = (bit 12-14)-wrap around after this signal type * @param p2 used for CmdBuildManySignals() to copy direction of first signal * TODO: p2 should be replaced by two bits for "along" and "against" the track. */ @@ -804,10 +806,14 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 Track track = (Track)GB(p1, 0, 3); bool ctrl_pressed = HasBit(p1, 3); // was the CTRL button pressed SignalVariant sigvar = (ctrl_pressed ^ HasBit(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC; // the signal variant of the new signal - SignalType sigtype = (SignalType)GB(p1, 5, 2); // the signal type of the new signal - bool convert_signal = HasBit(p1, 7); // convert button pressed + SignalType sigtype = (SignalType)GB(p1, 5, 3); // the signal type of the new signal + bool convert_signal = HasBit(p1, 8); // convert button pressed + SignalType cycle_start = (SignalType)GB(p1, 9, 3); + SignalType cycle_stop = (SignalType)GB(p1, 12, 3); CommandCost cost; + if (sigtype > SIGTYPE_LAST) return CMD_ERROR; + if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoTrainOnTrack(tile, track)) return CMD_ERROR; @@ -869,7 +875,7 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 if (p2 == 0) { if (!HasSignalOnTrack(tile, track)) { /* build new signals */ - SetPresentSignals(tile, GetPresentSignals(tile) | SignalOnTrack(track)); + SetPresentSignals(tile, GetPresentSignals(tile) | (IsPbsSignal(sigtype) ? KillFirstBit(SignalOnTrack(track)) : SignalOnTrack(track))); SetSignalType(tile, track, sigtype); SetSignalVariant(tile, track, sigvar); } else { @@ -886,10 +892,12 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 } } else if (ctrl_pressed) { - /* cycle between normal -> pre -> exit -> combo -> ... */ - sigtype = GetSignalType(tile, track); + /* cycle between cycle_start and cycle_end */ + sigtype = (SignalType)(GetSignalType(tile, track) + 1); + + if (sigtype < cycle_start || sigtype > cycle_stop) sigtype = cycle_start; - SetSignalType(tile, track, sigtype == SIGTYPE_COMBO ? SIGTYPE_NORMAL : (SignalType)(sigtype + 1)); + SetSignalType(tile, track, sigtype); } else { /* cycle the signal side: both -> left -> right -> both -> ... */ CycleSignalSide(tile, track); @@ -902,6 +910,10 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 SetSignalVariant(tile, track, sigvar); } + if (IsPbsSignal(sigtype)) { + uint mask = GetPresentSignals(tile) & SignalOnTrack(track); + SetSignalStates(tile, (GetSignalStates(tile) & ~mask) | ((HasBit(GetTrackReservation(tile), track) ? (uint)-1 : 0) & mask)); + } MarkTileDirtyByTile(tile); AddTrackToSignalBuffer(tile, track, _current_player); YapfNotifyTrackLayoutChange(tile, track); diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 579d7e62a..ee4decb59 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -52,6 +52,9 @@ static bool _convert_signal_button; ///< convert signal button in the s static SignalVariant _cur_signal_variant; ///< set the signal variant (for signal GUI) static SignalType _cur_signal_type; ///< set the signal type (for signal GUI) +/* Map _patches.default_signal_type to the corresponding signal type */ +static const SignalType _default_signal_type[] = {SIGTYPE_NORMAL, SIGTYPE_PBS, SIGTYPE_PBS_ONEWAY}; + struct RailStationGUISettings { Axis orientation; ///< Currently selected rail station orientation byte numtracks; ///< Currently selected number of tracks in station (if not \c dragdrop ) @@ -218,6 +221,9 @@ static void GenericPlaceSignals(TileIndex tile) } else { const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0); + /* Map _patches.cycle_signal_types to the lower and upper allowed signal type. */ + static const uint cycle_bounds[] = {SIGTYPE_NORMAL | (SIGTYPE_LAST_NOPBS << 3), SIGTYPE_PBS | (SIGTYPE_LAST << 3), SIGTYPE_NORMAL | (SIGTYPE_LAST << 3)}; + /* various bitstuffed elements for CmdBuildSingleSignal() */ uint32 p1 = track; @@ -225,13 +231,15 @@ static void GenericPlaceSignals(TileIndex tile) /* signal GUI is used */ SB(p1, 3, 1, _ctrl_pressed); SB(p1, 4, 1, _cur_signal_variant); - SB(p1, 5, 2, _cur_signal_type); - SB(p1, 7, 1, _convert_signal_button); + SB(p1, 5, 3, _cur_signal_type); + SB(p1, 8, 1, _convert_signal_button); + SB(p1, 9, 6, cycle_bounds[_settings_client.gui.cycle_signal_types]); } else { SB(p1, 3, 1, _ctrl_pressed); SB(p1, 4, 1, (_cur_year < _settings_client.gui.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC)); - SB(p1, 5, 2, SIGTYPE_NORMAL); - SB(p1, 7, 1, 0); + SB(p1, 5, 3, _default_signal_type[_settings_client.gui.default_signal_type]); + SB(p1, 8, 1, 0); + SB(p1, 9, 6, cycle_bounds[_settings_client.gui.cycle_signal_types]); } DoCommandP(tile, p1, 0, CcPlaySound1E, CMD_BUILD_SIGNALS | diff --git a/src/settings.cpp b/src/settings.cpp index 681c33b4c..5ef857258 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1790,6 +1790,8 @@ const SettingDesc _patch_settings[] = { SDTC_BOOL(gui.auto_euro, S, 0, true, STR_NULL, NULL), SDTC_VAR(gui.news_message_timeout, SLE_UINT8, S, 0, 2, 1, 255, 0, STR_NULL, NULL), SDTC_BOOL(gui.show_track_reservation, S, 0, false, STR_CONFIG_PATCHES_SHOW_TRACK_RESERVATION, RedrawScreen), + SDTC_VAR(gui.default_signal_type, SLE_UINT8, S, MS, 0, 0, 2, 1, STR_CONFIG_PATCHES_DEFAULT_SIGNAL_TYPE, NULL), + SDTC_VAR(gui.cycle_signal_types, SLE_UINT8, S, MS, 0, 0, 2, 1, STR_CONFIG_PATCHES_CYCLE_SIGNAL_TYPES, NULL), #ifdef ENABLE_NETWORK SDTC_VAR(network.sync_freq, SLE_UINT16,C|S,NO, 100, 0, 100, 0, STR_NULL, NULL), diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 395463b46..be4ef05d9 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -627,6 +627,8 @@ static const char *_patches_construction[] = { "gui.drag_signals_density", "game_creation.oil_refinery_limit", "gui.semaphore_build_before", + "gui.default_signal_type", + "gui.cycle_signal_types", }; static const char *_patches_stations[] = { diff --git a/src/settings_type.h b/src/settings_type.h index 97eb0a903..098d56f60 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -80,6 +80,8 @@ struct GUISettings { int32 autorenew_money; ///< how much money before autorenewing for new companies? byte news_message_timeout; ///< how much longer than the news message "age" should we keep the message in the history bool show_track_reservation; ///< highlight reserved tracks. + uint8 default_signal_type; ///< the signal type to build by default. + uint8 cycle_signal_types; ///< what signal types to cycle with the build signal tool. }; /** Settings related to currency/unit systems. */ |