* Pause/Unpause the game (server-only). * Set or unset a bit in the pause mode. If pause mode is zero the game is * unpaused. A bitset is used instead of a boolean value/counter to have * more control over the game when saving/loading, etc. * @param flags operation to perform * @param mode the pause mode to change * @param pause true pauses, false unpauses this mode * @return the cost of th
| 165 | * @return the cost of this operation or an error |
| 166 | */ |
| 167 | CommandCost CmdPause(DoCommandFlags flags, PauseMode mode, bool pause) |
| 168 | { |
| 169 | switch (mode) { |
| 170 | case PauseMode::SaveLoad: |
| 171 | case PauseMode::Error: |
| 172 | case PauseMode::Normal: |
| 173 | case PauseMode::GameScript: |
| 174 | case PauseMode::LinkGraph: |
| 175 | break; |
| 176 | |
| 177 | case PauseMode::Join: |
| 178 | case PauseMode::ActiveClients: |
| 179 | if (!_networking) return CMD_ERROR; |
| 180 | break; |
| 181 | |
| 182 | default: return CMD_ERROR; |
| 183 | } |
| 184 | if (flags.Test(DoCommandFlag::Execute)) { |
| 185 | if (mode == PauseMode::Normal && _pause_mode.Test(PauseMode::Error)) { |
| 186 | ShowQuery( |
| 187 | GetEncodedString(STR_NEWGRF_UNPAUSE_WARNING_TITLE), |
| 188 | GetEncodedString(STR_NEWGRF_UNPAUSE_WARNING), |
| 189 | nullptr, |
| 190 | AskUnsafeUnpauseCallback |
| 191 | ); |
| 192 | } else { |
| 193 | PauseModes prev_mode = _pause_mode; |
| 194 | |
| 195 | if (pause) { |
| 196 | _pause_mode.Set(mode); |
| 197 | } else { |
| 198 | _pause_mode.Reset(mode); |
| 199 | |
| 200 | /* If the only remaining reason to be paused is that we saw a command during pause, unpause. */ |
| 201 | if (_pause_mode == PauseMode::CommandDuringPause) { |
| 202 | _pause_mode = {}; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | NetworkHandlePauseChange(prev_mode, mode); |
| 207 | } |
| 208 | |
| 209 | SetWindowDirty(WC_STATUS_BAR, 0); |
| 210 | SetWindowDirty(WC_MAIN_TOOLBAR, 0); |
| 211 | } |
| 212 | return CommandCost(); |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Change the financial flow of your company. |
nothing calls this directly
no test coverage detected