Add setting to allow auto-fill signal dragging to skip over stations/waypoints

This commit is contained in:
Jonathan G Rennison 2023-12-19 22:25:05 +00:00
parent 55bac952a4
commit 540cec2af5
7 changed files with 38 additions and 10 deletions

View File

@ -212,8 +212,8 @@ CommandProc CmdStoryPageButton;
CommandProc CmdLevelLand;
CommandProc CmdBuildSignalTrack;
CommandProc CmdRemoveSignalTrack;
CommandProcEx CmdBuildSignalTrack;
CommandProcEx CmdRemoveSignalTrack;
CommandProc CmdSetAutoReplace;

View File

@ -747,6 +747,9 @@ STR_CONFIG_SETTING_SCENARIO_HOUSE_IGNORE_ZONES_OFF :Off
STR_CONFIG_SETTING_SCENARIO_HOUSE_IGNORE_ZONES_WITHIN_TOWN :Within town
STR_CONFIG_SETTING_SCENARIO_HOUSE_IGNORE_ZONES_ANYWHERE :Anywhere
STR_CONFIG_SETTING_DRAG_SIGNALS_SKIP_STATIONS :When auto-fill dragging, continue past stations/waypoints: {STRING2}
STR_CONFIG_SETTING_DRAG_SIGNALS_SKIP_STATIONS_HELPTEXT :Select the behaviour of signal placement when Ctrl+dragging signals. If disabled, signal placement stops when reaching a station/waypoint tile. If enabled, signal placement continues on the far side of rail stations/waypoints
STR_CONFIG_SETTING_NETWORK_CHANGE_NOT_ALLOWED :{WHITE}Can't change setting...
STR_CONFIG_SETTING_NETWORK_CHANGE_NOT_ALLOWED_NEWGRF :{WHITE}...setting is observed by a NewGRF

View File

@ -1892,7 +1892,7 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1,
return cost;
}
static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal_ctr, bool remove)
static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal_ctr, bool remove, bool allow_station)
{
tile = AddTileIndexDiffCWrap(tile, _trackdelta[trackdir]);
if (tile == INVALID_TILE) return false;
@ -1958,6 +1958,12 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal
return true;
}
case MP_STATION: {
if (!allow_station) return false;
signal_ctr += 2;
return true;
}
default: return false;
}
}
@ -1977,10 +1983,12 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal
* - p2 = (bit 10) - 0 = keep fixed distance, 1 = minimise gaps between signals
* - p2 = (bit 11-14) - default signal style
* - p2 = (bit 24-31) - user defined signals_density
* @param p3 various bitstuffed elements
* - p3 = (bit 0) - 1 = skip over rail stations/waypoints, 0 = stop at rail stations/waypoints
* @param text unused
* @return the cost of this operation or an error
*/
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, uint64 p3, const char *text)
{
CommandCost total_cost(EXPENSES_CONSTRUCTION);
TileIndex start_tile = tile;
@ -1993,6 +2001,7 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
bool minimise_gaps = HasBit(p2, 10);
byte signal_density = GB(p2, 24, 8);
uint8 signal_style = GB(p2, 11, 4);
bool allow_station = HasBit(p3, 0);
if (p1 >= MapSize() || !ValParamTrackOrientation(track)) return CMD_ERROR;
TileIndex end_tile = p1;
@ -2136,7 +2145,7 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
}
if (autofill) {
if (!CheckSignalAutoFill(tile, trackdir, signal_ctr, remove)) break;
if (!CheckSignalAutoFill(tile, trackdir, signal_ctr, remove, allow_station)) break;
/* Prevent possible loops */
if (tile == start_tile && trackdir == start_trackdir) break;
@ -2174,13 +2183,15 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
* - p2 = (bit 10) - 0 = keep fixed distance, 1 = minimise gaps between signals
* - p2 = (bit 11-14) - default signal style
* - p2 = (bit 24-31) - user defined signals_density
* @param p3 various bitstuffed elements
* - p3 = (bit 0) - 1 = skip over rail stations/waypoints, 0 = stop at rail stations/waypoints
* @param text unused
* @return the cost of this operation or an error
* @see CmdSignalTrackHelper
*/
CommandCost CmdBuildSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdBuildSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, uint64 p3, const char *text, const CommandAuxiliaryBase *aux_data)
{
return CmdSignalTrackHelper(tile, flags, p1, p2, text);
return CmdSignalTrackHelper(tile, flags, p1, p2, p3, text);
}
/**
@ -2327,13 +2338,15 @@ CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1
* - p2 = (bit 6) - 0 = selected stretch, 1 = auto fill
* - p2 = (bit 7- 9) - default signal type
* - p2 = (bit 24-31) - user defined signals_density
* @param p3 various bitstuffed elements
* - p3 = (bit 0) - 1 = skip over rail stations/waypoints, 0 = stop at rail stations/waypoints
* @param text unused
* @return the cost of this operation or an error
* @see CmdSignalTrackHelper
*/
CommandCost CmdRemoveSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdRemoveSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, uint64 p3, const char *text, const CommandAuxiliaryBase *aux_data)
{
return CmdSignalTrackHelper(tile, flags, p1, SetBit(p2, 5), text); // bit 5 is remove bit
return CmdSignalTrackHelper(tile, flags, p1, SetBit(p2, 5), p3, text); // bit 5 is remove bit
}
/** Update power of train under which is the railtype being converted */

View File

@ -464,6 +464,7 @@ static void HandleAutodirPlacement()
static void HandleAutoSignalPlacement()
{
uint32 p2 = GB(_thd.drawstyle, 0, 3); // 0..5
uint64 p3 = 0;
if ((_thd.drawstyle & HT_DRAG_MASK) == HT_RECT) { // one tile case
GenericPlaceSignals(TileVirtXY(_thd.selend.x, _thd.selend.y));
@ -489,10 +490,11 @@ static void HandleAutoSignalPlacement()
SB(p2, 24, 8, _settings_client.gui.drag_signals_density);
SB(p2, 10, 1, !_settings_client.gui.drag_signals_fixed_distance);
}
SB(p3, 0, 1, _settings_client.gui.drag_signals_skip_stations);
/* _settings_client.gui.drag_signals_density is given as a parameter such that each user
* in a network game can specify their own signal density */
DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), p2,
DoCommandPEx(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), p2, p3,
_remove_button_clicked ?
CMD_REMOVE_SIGNAL_TRACK | CMD_MSG(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM) :
CMD_BUILD_SIGNAL_TRACK | CMD_MSG(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE),

View File

@ -2138,6 +2138,7 @@ static SettingsContainer &GetSettingsTree()
company->Add(new SettingEntry("gui.cycle_signal_types"));
company->Add(new SettingEntry("gui.signal_gui_mode"));
company->Add(new SettingEntry("gui.drag_signals_fixed_distance"));
company->Add(new SettingEntry("gui.drag_signals_skip_stations"));
company->Add(new SettingEntry("gui.auto_remove_signals"));
company->Add(new SettingEntry("gui.new_nonstop"));
company->Add(new SettingEntry("gui.stop_location"));

View File

@ -254,6 +254,7 @@ struct GUISettings : public TimeSettings {
bool auto_euro; ///< automatically switch to euro in 2002
byte drag_signals_density; ///< many signals density
bool drag_signals_fixed_distance; ///< keep fixed distance between signals when dragging
bool drag_signals_skip_stations; ///< continue past station/waypoint tiles when auto-fill dragging signals
Year semaphore_build_before; ///< build semaphore signals automatically before this year
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.

View File

@ -1079,6 +1079,14 @@ str = STR_CONFIG_SETTING_DRAG_SIGNALS_FIXED_DISTANCE
strhelp = STR_CONFIG_SETTING_DRAG_SIGNALS_FIXED_DISTANCE_HELPTEXT
cat = SC_EXPERT
[SDTC_BOOL]
var = gui.drag_signals_skip_stations
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_PATCH
def = false
str = STR_CONFIG_SETTING_DRAG_SIGNALS_SKIP_STATIONS
strhelp = STR_CONFIG_SETTING_DRAG_SIGNALS_SKIP_STATIONS_HELPTEXT
cat = SC_EXPERT
[SDTC_VAR]
var = gui.semaphore_build_before
type = SLE_INT32