* Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp * * @param tile The tile where the signal will build or edit */
| 234 | * @param tile The tile where the signal will build or edit |
| 235 | */ |
| 236 | static void GenericPlaceSignals(TileIndex tile) |
| 237 | { |
| 238 | TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)); |
| 239 | |
| 240 | if (trackbits & TRACK_BIT_VERT) { // N-S direction |
| 241 | trackbits = (_tile_fract_coords.x <= _tile_fract_coords.y) ? TRACK_BIT_RIGHT : TRACK_BIT_LEFT; |
| 242 | } |
| 243 | |
| 244 | if (trackbits & TRACK_BIT_HORZ) { // E-W direction |
| 245 | trackbits = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? TRACK_BIT_UPPER : TRACK_BIT_LOWER; |
| 246 | } |
| 247 | |
| 248 | Track track = FindFirstTrack(trackbits); |
| 249 | |
| 250 | if (_remove_button_clicked) { |
| 251 | Command<CMD_REMOVE_SINGLE_SIGNAL>::Post(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM, CcPlaySound_CONSTRUCTION_RAIL, tile, track); |
| 252 | } else { |
| 253 | /* Which signals should we cycle through? */ |
| 254 | bool tile_has_signal = IsPlainRailTile(tile) && IsValidTrack(track) && HasSignalOnTrack(tile, track); |
| 255 | SignalType cur_signal_on_tile = tile_has_signal ? GetSignalType(tile, track) : _cur_signal_type; |
| 256 | SignalType cycle_start; |
| 257 | SignalType cycle_end; |
| 258 | |
| 259 | /* Start with the least restrictive case: the player wants to cycle through all signals they can see. */ |
| 260 | if (_settings_client.gui.cycle_signal_types == SIGNAL_CYCLE_ALL) { |
| 261 | cycle_start = _settings_client.gui.signal_gui_mode == SIGNAL_GUI_ALL ? SIGTYPE_BLOCK : SIGTYPE_PBS; |
| 262 | cycle_end = SIGTYPE_LAST; |
| 263 | } else { |
| 264 | /* Only cycle through signals of the same group (block or path) as the current signal on the tile. */ |
| 265 | if (cur_signal_on_tile <= SIGTYPE_LAST_NOPBS) { |
| 266 | /* Block signals only. */ |
| 267 | cycle_start = SIGTYPE_BLOCK; |
| 268 | cycle_end = SIGTYPE_LAST_NOPBS; |
| 269 | } else { |
| 270 | /* Path signals only. */ |
| 271 | cycle_start = SIGTYPE_PBS; |
| 272 | cycle_end = SIGTYPE_LAST; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if (FindWindowById(WC_BUILD_SIGNAL, 0) != nullptr) { |
| 277 | /* signal GUI is used */ |
| 278 | Command<CMD_BUILD_SINGLE_SIGNAL>::Post(_convert_signal_button ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL, |
| 279 | tile, track, _cur_signal_type, _cur_signal_variant, _convert_signal_button, false, _ctrl_pressed, cycle_start, cycle_end, 0, 0); |
| 280 | } else { |
| 281 | SignalVariant sigvar = TimerGameCalendar::year < _settings_client.gui.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC; |
| 282 | Command<CMD_BUILD_SINGLE_SIGNAL>::Post(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL, |
| 283 | tile, track, _settings_client.gui.default_signal_type, sigvar, false, false, _ctrl_pressed, cycle_start, cycle_end, 0, 0); |
| 284 | |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Start placing a rail bridge. |
no test coverage detected