diff --git a/src/citymania/cm_blueprint.cpp b/src/citymania/cm_blueprint.cpp index 45ca1b4ee1..0a7f97de43 100644 --- a/src/citymania/cm_blueprint.cpp +++ b/src/citymania/cm_blueprint.cpp @@ -600,29 +600,34 @@ void BuildBlueprint(sp &blueprint, TileIndex start) { case Blueprint::Item::Type::RAIL_TUNNEL: case Blueprint::Item::Type::RAIL_BRIDGE: { auto cc = GetBlueprintCommand(start, item); - cc->post(); - if (item.type == Blueprint::Item::Type::RAIL_TRACK) last_rail = std::move(cc); + if (item.type == Blueprint::Item::Type::RAIL_TRACK) { + if (last_rail != nullptr) last_rail->post(); + last_rail = std::move(cc); + } else { + cc->post(); + } break; } case Blueprint::Item::Type::RAIL_STATION: { // TODO station types TileIndex tile = AddTileIndexDiffCWrap(start, item.tdiff); auto cc = GetBlueprintCommand(start, item); - // FIXME - /* DoCommandWithCallback(cc, - [blueprint, tile, start, sign_part=item.u.rail.station.has_part, sid=item.u.rail.station.id] (bool res)->bool { - if (!res) return false; - StationID station_id = GetStationIndex(tile); - for (auto &item : blueprint->items) { - if (item.type != Blueprint::Item::Type::RAIL_STATION_PART) continue; - if (item.u.rail.station_part.id != sid) continue; - auto cc = GetBlueprintCommand(start, item); - // FIXME DoCommandP(cc.tile, cc.p1 | (1 << 24), station_id << 16, cc.cmd); - } - if (!sign_part) ::Command::Post(tile, 0, false); - return true; + cc->with_callback([blueprint, tile, start, sign_part=item.u.rail.station.has_part, sid=item.u.rail.station.id] (bool res)->bool { + if (!res) return false; + StationID station_id = GetStationIndex(tile); + for (auto &item : blueprint->items) { + if (item.type != Blueprint::Item::Type::RAIL_STATION_PART) continue; + if (item.u.rail.station_part.id != sid) continue; + auto cc = GetBlueprintCommand(start, item); + auto &scmd = dynamic_cast(*cc); + scmd.adjacent = true; + scmd.station_to_join = station_id; + scmd.post(); } - );*/ + if (!sign_part) ::Command::Post(tile, 0, false); + return true; + } + ).post(); break; } default: @@ -630,16 +635,15 @@ void BuildBlueprint(sp &blueprint, TileIndex start) { } } - auto signal_callback = [start, blueprint](bool res) { - for (auto &item : blueprint->items) { - if (item.type != Blueprint::Item::Type::RAIL_SIGNAL) continue; - auto cc = GetBlueprintCommand(start, item); - cc->post(); - } - return true; - }; if (last_rail != nullptr) { // there can't be any signals if there are no rails -// FIXME AddCommandCallback(last_rail.tile, last_rail.p1, last_rail.p2, last_rail.cmd, "", signal_callback); + last_rail->with_callback([start, blueprint](bool res) { + for (auto &item : blueprint->items) { + if (item.type != Blueprint::Item::Type::RAIL_SIGNAL) continue; + auto cc = GetBlueprintCommand(start, item); + cc->post(); + } + return true; + }).post(); } } diff --git a/src/citymania/cm_commands.cpp b/src/citymania/cm_commands.cpp index 934a401855..33bbd5b6d3 100644 --- a/src/citymania/cm_commands.cpp +++ b/src/citymania/cm_commands.cpp @@ -63,8 +63,9 @@ 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->tile, cp->data); + Debug(misc, 5, "CM BeforeNetworkCommandExecution: cmd={} hash={}", cp->cmd, hash); while (!_callback_queue.empty() && _callback_queue.front().first != hash) { - Debug(misc, 0, "CM Dismissing command from callback queue: cmd={}", cp->cmd); + Debug(misc, 0, "CM Dismissing command from callback queue: hash={}", _callback_queue.front().first); _callback_queue.pop(); } if (_callback_queue.empty()) { @@ -82,6 +83,7 @@ void AfterNetworkCommandExecution(const CommandPacket* cp) { void AddCommandCallback(const CommandPacket *cp) { size_t hash = GetCommandHash(cp->cmd, cp->company, cp->err_msg, cp->callback, cp->tile, cp->data); + Debug(misc, 5, "CM Added callback: cmd={} hash={}", cp->cmd, hash); _callback_queue.push(std::make_pair(hash, _current_callback)); _current_callback = nullptr; } diff --git a/src/citymania/cm_commands.hpp b/src/citymania/cm_commands.hpp index 2158648fc3..f531ffab03 100644 --- a/src/citymania/cm_commands.hpp +++ b/src/citymania/cm_commands.hpp @@ -12,7 +12,7 @@ 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 ExecuteCurrentCallback(const CommandCost &cost); void BeforeNetworkCommandExecution(const CommandPacket* cp); void AfterNetworkCommandExecution(const CommandPacket* cp); diff --git a/src/command_func.h b/src/command_func.h index 67367feef6..88da2846a8 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -19,7 +19,7 @@ #include "tile_map.h" struct CommandPacket; -namespace citymania { extern void ExecuteCurrentCallback(const CommandCost &cost); } +namespace citymania { void ExecuteCurrentCallback(const CommandCost &cost); } /** * Define a default return value for a failed command. @@ -341,9 +341,10 @@ protected: std::apply(callback, std::tuple_cat(std::make_tuple(Tcmd), res, args)); } } - citymania::ExecuteCurrentCallback(ExtractCommandCost(res)); } + if (!estimate_only && !only_sending) citymania::ExecuteCurrentCallback(ExtractCommandCost(res)); + return ExtractCommandCost(res).Succeeded(); }