diff --git a/src/citymania/cm_command_type.hpp b/src/citymania/cm_command_type.hpp index 52b6a0a393..b35292a7fc 100644 --- a/src/citymania/cm_command_type.hpp +++ b/src/citymania/cm_command_type.hpp @@ -27,11 +27,13 @@ namespace citymania { typedef std::function CommandCallback; extern bool _no_estimate_command; +extern bool _automatic_command; extern CommandCallback _current_callback; class Command { public: bool no_estimate_flag = false; + bool automatic_flag = false; CompanyID company = INVALID_COMPANY; StringID error = (StringID)0; CommandCallback callback = nullptr; @@ -49,10 +51,12 @@ public: if (this->company != INVALID_COMPANY) _current_company = company; _no_estimate_command = this->no_estimate_flag; + _automatic_command = this->automatic_flag; _current_callback = this->callback; bool res = this->_post(reinterpret_cast<::CommandCallback *>(reinterpret_cast(callback))); _current_company = company_backup; _no_estimate_command = false; + _automatic_command = false; return res; } @@ -83,6 +87,13 @@ public: return *this; } + Command &set_auto() { + // Doesn't count for apm + this->automatic_flag = true; + this->no_estimate_flag = true; + return *this; + } + Command &as_company(CompanyID company) { this->company = company; return *this; diff --git a/src/citymania/cm_commands.cpp b/src/citymania/cm_commands.cpp index db80261d9b..28a32cdfe2 100644 --- a/src/citymania/cm_commands.cpp +++ b/src/citymania/cm_commands.cpp @@ -20,6 +20,7 @@ std::map>> _command_callb std::queue> _command_sent; CommandCallback _current_callback = nullptr; bool _no_estimate_command = false; +bool _automatic_command = false; template class SumLast { diff --git a/src/citymania/cm_hotkeys.cpp b/src/citymania/cm_hotkeys.cpp index ffdd5c9a1e..0c139a806e 100644 --- a/src/citymania/cm_hotkeys.cpp +++ b/src/citymania/cm_hotkeys.cpp @@ -28,6 +28,7 @@ struct RailStationGUISettings { byte station_count; ///< Number of custom stations (if newstations is \c true ) }; extern RailStationGUISettings _railstation; ///< Settings of the station builder GUI +extern bool _generating_world; namespace citymania { @@ -51,6 +52,7 @@ static void PurgeLastActions() { } void CountEffectiveAction() { + if (_generating_world) return; auto now = std::chrono::steady_clock::now(); if (!_first_effective_tick) _first_effective_tick = now; _effective_actions++; @@ -69,7 +71,7 @@ std::pair GetEPM() { if (!_first_effective_tick) return std::make_pair(0, 0); PurgeLastActions(); auto ms = std::chrono::duration_cast(now - *_first_effective_tick).count(); - if (ms == 0) return std::make_pair(0, 0); + if (ms < 1000) return std::make_pair(0, _last_actions.size()); return std::make_pair(_effective_actions * 60000 / ms, _last_actions.size()); } diff --git a/src/citymania/cm_station_gui.cpp b/src/citymania/cm_station_gui.cpp index 82f81b7034..8570b4faa0 100644 --- a/src/citymania/cm_station_gui.cpp +++ b/src/citymania/cm_station_gui.cpp @@ -1360,16 +1360,17 @@ bool AirportBuildTool::RemoveHandler::Execute(TileArea area) { // SizedPlacementHandler up AirportBuildTool::SizedPlacementHandler::GetCommand(TileIndex tile, StationID to_join) { - // STR_ERROR_CAN_T_BUILD_AIRPORT_HERE, byte airport_type = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex(); byte layout = _selected_airport_layout; - return make_up( + auto cmd = make_up( tile, airport_type, layout, StationBuildTool::station_to_join, true ); + cmd->with_error(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE); + return cmd; } bool AirportBuildTool::SizedPlacementHandler::Execute(TileIndex tile) { diff --git a/src/command.cpp b/src/command.cpp index 2feba43a35..dbea28b064 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -245,8 +245,6 @@ void CommandHelperBase::InternalPostResult(const CommandCost &res, TileIndex til int x = TileX(tile) * TILE_SIZE; int y = TileY(tile) * TILE_SIZE; - // FIXME if (!(cmd & CMD_NO_ESTIMATE) && my_cmd) citymania::CountEffectiveAction(); - if (res.Failed()) { /* Only show the error when it's for us. */ if (estimate_only || (IsLocalCompany() && err_message != 0 && my_cmd)) { diff --git a/src/command_func.h b/src/command_func.h index 5b65827810..6d6ffa71a2 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -24,7 +24,9 @@ extern uint32 _frame_counter; struct CommandPacket; namespace citymania { extern CommandCost _command_execute_cost; + extern bool _automatic_command; void ExecuteCurrentCallback(const CommandCost &cost); + void CountEffectiveAction(); } /** @@ -314,6 +316,7 @@ protected: Tret res = Execute(err_message, reinterpret_cast(callback), my_cmd, estimate_only, network_command, tile, args); InternalPostResult(ExtractCommandCost(res), tile, estimate_only, only_sending, err_message, my_cmd); citymania::_command_execute_cost = ExtractCommandCost(res); + if (!estimate_only && !only_sending && !citymania::_automatic_command && my_cmd) citymania::CountEffectiveAction(); if (!estimate_only && !only_sending && callback != nullptr) { if constexpr (std::is_same_v) { diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 85c8047ad8..23590a9aa4 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1650,7 +1650,7 @@ public: if (feeder_mod == FeederOrderMod::LOAD) { if (citymania::cmd::InsertOrder(this->vehicle->tile, this->vehicle->index, 1, cmd) .with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER) - .no_estimate() + .set_auto() .post()) { citymania::cmd::DeleteOrder(this->vehicle->tile, this->vehicle->index, 0) .with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER) @@ -1661,7 +1661,7 @@ public: } else if (feeder_mod == FeederOrderMod::UNLOAD) { // still flushes the whole order table if (citymania::cmd::InsertOrder(this->vehicle->tile, this->vehicle->index, this->vehicle->GetNumOrders(), cmd) .with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER) - .no_estimate() + .set_auto() .post()) { citymania::cmd::DeleteOrder(this->vehicle->tile, this->vehicle->index, this->vehicle->GetNumOrders() + (int)_networking - 2) .with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER) diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index d9e586dcfe..07b6cc9aee 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -243,7 +243,7 @@ struct StatusBarWindow : Window { this->SetWidgetDirty(WID_S_LEFT); }}; - TimeoutTimer cm_epm_interval = {std::chrono::seconds(1), [this]() { + IntervalTimer cm_epm_interval = {std::chrono::seconds(1), [this](uint) { this->SetWidgetDirty(CM_WID_S_APM); }}; }; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 1b26a9d44d..0b03b90d75 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -970,7 +970,7 @@ static void DoRegularFunding(Town *t) } else if (TimerGameTick::counter - t->last_funding < Ticks::TOWN_GROWTH_TICKS) return; citymania::cmd::DoTownAction(t->xy, t->index, HK_FUND) - .no_estimate() + .set_auto() .as_company(_local_company) .post(); t->last_funding = TimerGameTick::counter; @@ -1007,7 +1007,7 @@ static void DoRegularAdvertising(Town *t) { auto prev_rating = t->ad_ref_goods_entry->rating; citymania::cmd::DoTownAction(t->xy, t->index, HK_LADVERT) - .no_estimate() + .set_auto() .as_company(_local_company) .with_callback([=] (bool res) -> bool { if (res && prev_rating == t->ad_ref_goods_entry->rating) {