From f844546ed71bd5cc59b1b4eb95394dfc0a1459cf Mon Sep 17 00:00:00 2001 From: dP Date: Mon, 12 Feb 2024 12:32:30 +0530 Subject: [PATCH] Fix compilation errors --- src/citymania/cm_command_log.cpp | 2 +- src/citymania/cm_commands.cpp | 18 +++++++++--------- src/citymania/cm_commands.hpp | 4 ++-- src/citymania/cm_station_gui.cpp | 22 ++++++++++++++++++---- src/network/network_command.cpp | 2 +- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/citymania/cm_command_log.cpp b/src/citymania/cm_command_log.cpp index 54513f2467..8b68d9b017 100644 --- a/src/citymania/cm_command_log.cpp +++ b/src/citymania/cm_command_log.cpp @@ -69,7 +69,7 @@ void ExecuteFakeCommands(TimerGameTick::TickCounter counter) { for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) { if (cs->status >= NetworkClientSocket::STATUS_MAP) { - cs->outgoing_queue.Append(&x.cp); + cs->outgoing_queue.push_back(x.cp); } } } diff --git a/src/citymania/cm_commands.cpp b/src/citymania/cm_commands.cpp index 03dbbea3be..db80261d9b 100644 --- a/src/citymania/cm_commands.cpp +++ b/src/citymania/cm_commands.cpp @@ -103,16 +103,16 @@ void ExecuteCurrentCallback(const CommandCost &cost) { } } -void BeforeNetworkCommandExecution(const CommandPacket* cp) { - if (!cp->my_cmd) return; - size_t hash = GetCommandHash(cp->cmd, cp->company, cp->err_msg, cp->callback, cp->data); - Debug(misc, 5, "CM BeforeNetworkCommandExecution: cmd={} hash={}", cp->cmd, hash); +void BeforeNetworkCommandExecution(const CommandPacket &cp) { + if (!cp.my_cmd) return; + size_t hash = GetCommandHash(cp.cmd, cp.company, cp.err_msg, cp.callback, cp.data); + Debug(misc, 5, "CM BeforeNetworkCommandExecution: cmd={} hash={}", cp.cmd, hash); while (!_callback_queue.empty() && _callback_queue.front().hash != hash) { Debug(misc, 0, "CM Dismissing command from callback queue: hash={}", _callback_queue.front().hash); _callback_queue.pop(); } if (_callback_queue.empty()) { - Debug(misc, 0, "CM Received unexpected network command: cmd={}", cp->cmd); + Debug(misc, 0, "CM Received unexpected network command: cmd={}", cp.cmd); return; } auto &cbdata = _callback_queue.front(); @@ -122,8 +122,8 @@ void BeforeNetworkCommandExecution(const CommandPacket* cp) { return; } -void AfterNetworkCommandExecution(const CommandPacket* cp) { - Debug(misc, 5, "AfterNetworkCommandExecution {}", cp->cmd); +void AfterNetworkCommandExecution(const CommandPacket &cp) { + Debug(misc, 5, "AfterNetworkCommandExecution {}", cp.cmd); _current_callback = nullptr; } @@ -191,7 +191,7 @@ uint GetCurrentQueueDelay() { void FlushCommandQueue() { while (!_outgoing_queue.empty() && CanSendCommand()) { - MyClient::SendCommand(&_outgoing_queue.front()); + MyClient::SendCommand(_outgoing_queue.front()); _outgoing_queue.pop(); _commands_this_frame++; } @@ -206,7 +206,7 @@ void HandleNextClientFrame() { void SendClientCommand(const CommandPacket *cp) { AddCommandCallback(cp); if (_outgoing_queue.empty() && CanSendCommand()) { - MyClient::SendCommand(cp); + MyClient::SendCommand(*cp); _commands_this_frame++; return; } diff --git a/src/citymania/cm_commands.hpp b/src/citymania/cm_commands.hpp index ba9d764eaf..361c419511 100644 --- a/src/citymania/cm_commands.hpp +++ b/src/citymania/cm_commands.hpp @@ -13,8 +13,8 @@ namespace citymania { // void HandleCommandExecution(bool res, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, const std::string &text); void AddCommandCallback(const CommandPacket *cp); // void ExecuteCurrentCallback(const CommandCost &cost); -void BeforeNetworkCommandExecution(const CommandPacket* cp); -void AfterNetworkCommandExecution(const CommandPacket* cp); +void BeforeNetworkCommandExecution(const CommandPacket &cp); +void AfterNetworkCommandExecution(const CommandPacket &cp); void InitCommandQueue(); void HandleNextClientFrame(); diff --git a/src/citymania/cm_station_gui.cpp b/src/citymania/cm_station_gui.cpp index 2fe4b870cf..0e33dd4fff 100644 --- a/src/citymania/cm_station_gui.cpp +++ b/src/citymania/cm_station_gui.cpp @@ -569,8 +569,18 @@ static void AddProducedCargo_Town(TileIndex tile, CargoArray &produced) produced[cargo] += GetMonthlyFrom256Tick((uint)GB(callback, 0, 8)) ; } } else { - produced[CT_PASSENGERS] += GetAverageHouseProduction(hs->population); - produced[CT_MAIL] += GetAverageHouseProduction(hs->mail_generation); + if (hs->population > 0) { + auto avg = GetAverageHouseProduction(hs->population); + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_PASSENGERS]) { + produced[cs->Index()] += avg; + } + } + if (hs->mail_generation > 0) { + auto avg = GetAverageHouseProduction(hs->mail_generation); + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_MAIL]) { + produced[cs->Index()] += avg; + } + } } } @@ -602,8 +612,12 @@ CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad) break; case MP_OBJECT: if (IsObjectType(tile, OBJECT_HQ)) { - produced[CT_PASSENGERS] += GetMonthlyFrom256Tick(HQ_AVG_POP[EconomyIsInRecession() ? 1 : 0][GetAnimationFrame(tile)]); - produced[CT_MAIL] += GetMonthlyFrom256Tick(HQ_AVG_MAIL[EconomyIsInRecession() ? 1 : 0][GetAnimationFrame(tile)]); + auto pax_avg = GetMonthlyFrom256Tick(HQ_AVG_POP[EconomyIsInRecession() ? 1 : 0][GetAnimationFrame(tile)]); + auto mail_avg = GetMonthlyFrom256Tick(HQ_AVG_MAIL[EconomyIsInRecession() ? 1 : 0][GetAnimationFrame(tile)]); + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_PASSENGERS]) + produced[cs->Index()] += pax_avg; + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_MAIL]) + produced[cs->Index()] += mail_avg; } default: break; } diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp index a0a712fd83..09ebe7ca65 100644 --- a/src/network/network_command.cpp +++ b/src/network/network_command.cpp @@ -284,7 +284,7 @@ namespace citymania { size_t cb_index = FindCallbackIndex(cp->callback); assert(cb_index < _callback_tuple_size); assert(_cmd_dispatch[cp->cmd].Unpack[cb_index] != nullptr); - _cmd_dispatch[cp->cmd].Unpack[cb_index](cp); + _cmd_dispatch[cp->cmd].Unpack[cb_index](*cp); return _command_execute_cost; } }