MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / InternalPostBefore

Method InternalPostBefore

src/command.cpp:207–227  ·  view source on GitHub ↗

* Decide what to do with the command depending on current game state. * @param cmd Command to execute. * @param flags Command flags. * @param tile Tile of command execution. * @param err_message Message prefix to show on error. * @param network_command Does this command come from the network? * @return error state + do only cost estimation? + send to network only? */

Source from the content-addressed store, hash-verified

205 * @return error state + do only cost estimation? + send to network only?
206 */
207std::tuple<bool, bool, bool> CommandHelperBase::InternalPostBefore(Commands cmd, CommandFlags flags, TileIndex tile, StringID err_message, bool network_command)
208{
209 /* Cost estimation is generally only done when the
210 * local user presses shift while doing something.
211 * However, in case of incoming network commands,
212 * map generation or the pause button we do want
213 * to execute. */
214 bool estimate_only = _shift_pressed && IsLocalCompany() && !_generating_world && !network_command && !flags.Test(CommandFlag::NoEst);
215
216 /* We're only sending the command, so don't do
217 * fancy things for 'success'. */
218 bool only_sending = _networking && !network_command;
219
220 if (_pause_mode.Any() && !IsCommandAllowedWhilePaused(cmd) && !estimate_only) {
221 ShowErrorMessage(GetEncodedString(err_message), GetEncodedString(STR_ERROR_NOT_ALLOWED_WHILE_PAUSED),
222 WL_INFO, TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE);
223 return { true, estimate_only, only_sending };
224 } else {
225 return { false, estimate_only, only_sending };
226 }
227}
228
229/**
230 * Process result of executing a command, possibly displaying any error to the player.

Callers

nothing calls this directly

Calls 8

IsLocalCompanyFunction · 0.85
ShowErrorMessageFunction · 0.85
TileXFunction · 0.85
TileYFunction · 0.85
TestMethod · 0.80
AnyMethod · 0.80
GetEncodedStringFunction · 0.70

Tested by

no test coverage detected