diff --git a/src/citymania/cm_command_type.hpp b/src/citymania/cm_command_type.hpp index a81cf0c908..29c82ba3c9 100644 --- a/src/citymania/cm_command_type.hpp +++ b/src/citymania/cm_command_type.hpp @@ -26,13 +26,13 @@ namespace citymania { typedef std::function CommandCallback; -extern bool _auto_command; +extern bool _no_estimate_command; extern CommandCallback _current_callback; class Command { public: TileIndex tile = 0; - bool automatic = false; + bool no_estimate_flag = false; CompanyID company = INVALID_COMPANY; StringID error = (StringID)0; CommandCallback callback = nullptr; @@ -50,11 +50,11 @@ public: CompanyID old = _current_company; if (this->company != INVALID_COMPANY) _current_company = company; - _auto_command = this->automatic; + _no_estimate_command = this->no_estimate_flag; _current_callback = this->callback; bool res = this->_post(reinterpret_cast<::CommandCallback *>(reinterpret_cast(callback))); _current_callback = nullptr; - _auto_command = false; + _no_estimate_command = false; _current_company = old; return res; } @@ -86,8 +86,8 @@ public: return *this; } - Command &set_auto() { - this->automatic = true; + Command &no_estimate() { + this->no_estimate_flag = true; return *this; } diff --git a/src/citymania/cm_commands.cpp b/src/citymania/cm_commands.cpp index 33bbd5b6d3..f6da2a8108 100644 --- a/src/citymania/cm_commands.cpp +++ b/src/citymania/cm_commands.cpp @@ -18,7 +18,7 @@ const uint32 MAX_CALLBACK_LIFETIME = 30; // it should be executed within few fr std::map>> _command_callbacks; std::queue> _command_sent; CommandCallback _current_callback = nullptr; -bool _auto_command = false; +bool _no_estimate_command = false; std::queue> _callback_queue; uint GetCurrentQueueDelay(); diff --git a/src/command.cpp b/src/command.cpp index 1f4682a6db..8ca5f3a60f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -234,7 +234,7 @@ std::tuple CommandHelperBase::InternalPostBefore(Commands cmd, * However, in case of incoming network commands, * map generation or the pause button we do want * to execute. */ - bool estimate_only = citymania::_estimate_mod && IsLocalCompany() && !_generating_world && !network_command && !(flags & CMD_NO_EST) && !citymania::_auto_command; + bool estimate_only = citymania::_estimate_mod && IsLocalCompany() && !_generating_world && !network_command && !(flags & CMD_NO_EST) && !citymania::_no_estimate_command; /* We're only sending the command, so don't do * fancy things for 'success'. */ diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 1e93934725..75232f1fa5 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -37,6 +37,7 @@ #include "widgets/order_widget.h" +#include "citymania/cm_commands.hpp" #include "citymania/cm_hotkeys.hpp" #include "safeguards.h" @@ -814,6 +815,7 @@ private: if (citymania::_fn_mod && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return; if (this->vehicle->GetNumOrders() <= 1) return; + // TODO no estimate Command::Post(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER, this->vehicle->tile, this->vehicle->index, citymania::_fn_mod ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders())); } @@ -1581,16 +1583,36 @@ public: if (feeder_mod != FeederOrderMod::NONE) { if (feeder_mod == FeederOrderMod::LOAD) { - if (Command::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, 1, cmd)) { - Command::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, 0); + if (citymania::cmd::InsertOrder(this->vehicle->index, 1, cmd) + .with_tile(this->vehicle->tile) + .with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER) + .no_estimate() + .post()) { + citymania::cmd::DeleteOrder(this->vehicle->index, 0) + .with_tile(this->vehicle->tile) + .with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER) + .no_estimate() + .post(); } } else if (feeder_mod == FeederOrderMod::UNLOAD) { // still flushes the whole order table - if (Command::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->vehicle->GetNumOrders(), cmd)) { - Command::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->vehicle->GetNumOrders() + (int)_networking - 2); + if (citymania::cmd::InsertOrder(this->vehicle->index, this->vehicle->GetNumOrders(), cmd) + .with_tile(this->vehicle->tile) + .with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER) + .no_estimate() + .post()) { + citymania::cmd::DeleteOrder(this->vehicle->index, this->vehicle->GetNumOrders() + (int)_networking - 2) + .with_tile(this->vehicle->tile) + .with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER) + .no_estimate() + .post(); } } - } else if (Command::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), cmd)) { + } else if (citymania::cmd::InsertOrder(this->vehicle->index, this->OrderGetSel(), cmd) + .with_tile(this->vehicle->tile) + .with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER) + .no_estimate() + .post()) { /* With quick goto the Go To button stays active */ if (!_settings_client.gui.quick_goto) ResetObjectToPlace(); } diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 17a692df28..c8f99dbc97 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -921,7 +921,7 @@ static void DoRegularFunding(Town *t) citymania::cmd::DoTownAction(t->index, HK_FUND) .with_tile(t->xy) - .set_auto() + .no_estimate() .as_company(_local_company) .post(); t->last_funding = _tick_counter; @@ -958,7 +958,7 @@ static void DoRegularAdvertising(Town *t) { citymania::cmd::DoTownAction(t->index, HK_LADVERT) .with_tile(t->xy) - .set_auto() + .no_estimate() .as_company(_local_company) .post(); }