diff --git a/src/citymania/cm_cargo_table_gui.cpp b/src/citymania/cm_cargo_table_gui.cpp index 9eac5a8e97..bdf15ff3e0 100644 --- a/src/citymania/cm_cargo_table_gui.cpp +++ b/src/citymania/cm_cargo_table_gui.cpp @@ -76,8 +76,7 @@ struct CargosWindow : Window { } case WID_CT_HEADER_CARGO: case WID_CT_LIST: { - for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { - const CargoSpec *cs = _sorted_cargo_specs[i]; + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { size->width = std::max(GetStringBoundingBox(cs->name).width + icon_space, size->width); } size->width = std::max(GetStringBoundingBox(STR_TOOLBAR_CARGOS_HEADER_TOTAL_MONTH).width, size->width); @@ -94,7 +93,7 @@ struct CargosWindow : Window { case WID_CT_AMOUNT: case WID_CT_INCOME: case WID_CT_LIST: { - size->height = _sorted_standard_cargo_specs_size * line_height + CT_LINESPACE + FONT_HEIGHT_NORMAL; + size->height = _sorted_standard_cargo_specs.size() * line_height + CT_LINESPACE + FONT_HEIGHT_NORMAL; break; } } @@ -103,7 +102,7 @@ struct CargosWindow : Window { Dimension GetMaxIconSize() const { const CargoSpec *cs; Dimension size = {0, 0}; - FOR_ALL_CARGOSPECS(cs) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { Dimension icon_size = GetSpriteSize(cs->GetCargoIcon()); size.width = std::max(size.width, icon_size.width); size.height = std::max(size.height, icon_size.height); @@ -134,8 +133,7 @@ struct CargosWindow : Window { case WID_CT_LIST: { int rect_x = r.left + WD_FRAMERECT_LEFT; - for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { - const CargoSpec *cs = _sorted_cargo_specs[i]; + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { Dimension icon_size = GetSpriteSize(cs->GetCargoIcon()); DrawSprite(cs->GetCargoIcon(), PAL_NONE, r.left + max_icon_size.width - icon_size.width, @@ -156,8 +154,7 @@ struct CargosWindow : Window { break; } case WID_CT_AMOUNT: - for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { - const CargoSpec *cs = _sorted_cargo_specs[i]; + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { auto &economy = (this->cargoPeriod == WID_CT_OPTION_CARGO_MONTH ? c->old_economy[0] : c->cur_economy); sum_cargo_amount += economy.delivered_cargo[cs->Index()]; SetDParam(0, economy.delivered_cargo[cs->Index()]); @@ -173,8 +170,7 @@ struct CargosWindow : Window { break; case WID_CT_INCOME: - for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { - const CargoSpec *cs = _sorted_cargo_specs[i]; + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { auto &economy = (this->cargoPeriod == WID_CT_OPTION_CARGO_MONTH ? c->old_economy[0] : c->cur_economy); sum_cargo_income += economy.cm.cargo_income[cs->Index()]; diff --git a/src/citymania/cm_commands_gui.cpp b/src/citymania/cm_commands_gui.cpp index c39a687850..06ffc8bdfd 100644 --- a/src/citymania/cm_commands_gui.cpp +++ b/src/citymania/cm_commands_gui.cpp @@ -1,8 +1,9 @@ #include "stdafx.h" -#include "citymania/cm_commands_gui.hpp" +#include "cm_commands_gui.hpp" -#include "citymania/cm_base64.hpp" +#include "cm_base64.hpp" +#include "cm_main.hpp" #include "core/geometry_func.hpp" //maxdim #include "settings_type.h" @@ -367,7 +368,8 @@ struct CommandsToolbarWindow : Window { strecpy(ip, NOVAPOLIS_IPV4_PRIMARY, lastof(ip)); // else strecpy(ip, NOVAPOLIS_IPV4_SECONDARY, lastof(ip)); - NetworkClientConnectGame(ip, (3980 + widget - CTW_NS0), COMPANY_SPECTATOR); + // FIXME + // NetworkClientConnectGame(ip, (3980 + widget - CTW_NS0), COMPANY_SPECTATOR); } else if (widget >= CTW_CARGO_FIRST) { int i = widget - CTW_CARGO_FIRST; @@ -446,7 +448,7 @@ struct CommandsToolbarWindow : Window { void OnHundredthTick() { - for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { + for (int i = 0; i < _sorted_standard_cargo_specs.size(); i++) { if (this->IsWidgetLowered(i + CTW_CARGO_FIRST)) { static int x = 0; x++; @@ -466,13 +468,13 @@ static NWidgetBase *MakeCargoButtons(int *biggest_index) { NWidgetVertical *ver = new NWidgetVertical; - for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { + for (int i = 0; i < _sorted_standard_cargo_specs.size(); i++) { NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, COLOUR_ORANGE, CTW_CARGO_FIRST + i, NULL); leaf->tool_tip = STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO; leaf->SetFill(1, 0); ver->Add(leaf); } - *biggest_index = CTW_CARGO_FIRST + _sorted_standard_cargo_specs_size - 1; + *biggest_index = CTW_CARGO_FIRST + _sorted_standard_cargo_specs.size() - 1; return ver; } @@ -849,7 +851,7 @@ static WindowDesc _login_window_desc( void ShowLoginWindow() { IniLoginInitiate(); - DeleteWindowByClass(WC_LOGIN_WINDOW); + CloseWindowByClass(WC_LOGIN_WINDOW); AllocateWindowDescFront(&_login_window_desc, 0); } diff --git a/src/citymania/cm_console_cmds.cpp b/src/citymania/cm_console_cmds.cpp index 39d881aa38..71e9b45ee4 100644 --- a/src/citymania/cm_console_cmds.cpp +++ b/src/citymania/cm_console_cmds.cpp @@ -83,13 +83,13 @@ bool ConTreeMap(byte argc, char *argv[]) { std::string filename = argv[1]; if (_game_mode != GM_EDITOR) { - IConsolePrintF(CC_ERROR, "This command is only available in scenario editor."); + IConsolePrint(CC_ERROR, "This command is only available in scenario editor."); return true; } if (filename.size() < 4) { - IConsolePrintF(CC_ERROR, "Unknown treemap extension should be .bmp or .png."); + IConsolePrint(CC_ERROR, "Unknown treemap extension should be .bmp or .png."); return true; } @@ -101,9 +101,9 @@ bool ConTreeMap(byte argc, char *argv[]) { #endif else { #ifdef WITH_PNG - IConsolePrintF(CC_ERROR, "Unknown treemap extension %s, should be .bmp or .png.", ext.c_str()); + IConsolePrint(CC_ERROR, "Unknown treemap extension {}, should be .bmp or .png.", ext.c_str()); #else - IConsolePrintF(CC_ERROR, "Unknown treemap extension %s, should be .bmp (game was compiled without PNG support).", ext.c_str()); + IConsolePrint(CC_ERROR, "Unknown treemap extension {}, should be .bmp (game was compiled without PNG support).", ext.c_str()); #endif return true; } @@ -166,9 +166,9 @@ static std::queue _fake_commands; void MakeReplaySave() { char *filename = str_fmt("replay_%d.sav", _replay_ticks); if (SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) { - IConsolePrintF(CC_ERROR, "Replay save failed"); + IConsolePrint(CC_ERROR, "Replay save failed"); } else { - IConsolePrintF(CC_DEFAULT, "Replay saved to %s", filename); + IConsolePrint(CC_DEFAULT, "Replay saved to {}", filename); } _replay_last_save = _replay_ticks; } @@ -213,7 +213,7 @@ void ExecuteFakeCommands(Date date, DateFract date_fract) { cp.p1 = x.p1; cp.p2 = x.p2; cp.cmd = x.cmd; - strecpy(cp.text, x.text.c_str(), lastof(cp.text)); + cp.text = x.text; cp.company = (CompanyID)x.company_id; cp.frame = _frame_counter_max + 1; cp.callback = nullptr; diff --git a/src/citymania/cm_highlight.cpp b/src/citymania/cm_highlight.cpp index fda507d26c..0a3bec8c3a 100644 --- a/src/citymania/cm_highlight.cpp +++ b/src/citymania/cm_highlight.cpp @@ -50,7 +50,7 @@ extern DiagDirection _build_depot_direction; ///< Currently selected depot direc extern DiagDirection _road_station_picker_orientation; extern DiagDirection _road_depot_orientation; extern uint32 _realtime_tick; -extern void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec); +extern void GetStationLayout(byte *layout, uint numtracks, uint plat_len, const StationSpec *statspec); struct RailStationGUISettings { Axis orientation; ///< Currently selected rail station orientation @@ -266,7 +266,7 @@ static bool CanBuild(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd) { p2, cmd, nullptr, // callback - nullptr, // text + "", // text true, // my_cmd true // estimate_only ).Succeeded(); @@ -340,7 +340,7 @@ void ObjectHighlight::UpdateTiles() { CMD_BUILD_ROAD_STOP ) ? PALETTE_TINT_WHITE : PALETTE_TINT_RED_DEEP); TileIndex tile; - TILE_AREA_LOOP(tile, ta) { + for (TileIndex tile : ta) { this->tiles.insert(std::make_pair(tile, ObjectTileHighlight::make_road_stop(palette, this->roadtype, this->ddir, this->is_truck))); } break; @@ -1313,7 +1313,7 @@ void UpdateTownZoning(Town *town, uint32 prev_edge) { recalc = false; } // TODO mark dirty only if zoning is on - TILE_AREA_LOOP(tile, area) { + for(TileIndex tile : area) { uint8 group = GetTownZone(town, tile); if (_mz[tile].town_zone != group) diff --git a/src/citymania/cm_hotkeys.cpp b/src/citymania/cm_hotkeys.cpp index 0fd73df0c2..4022950be1 100644 --- a/src/citymania/cm_hotkeys.cpp +++ b/src/citymania/cm_hotkeys.cpp @@ -85,14 +85,13 @@ void UpdateModKeys(bool shift_pressed, bool ctrl_pressed, bool alt_pressed) { _remove_mod = mod_pressed[(size_t)_settings_client.gui.cm_remove_mod]; _estimate_mod = mod_pressed[(size_t)_settings_client.gui.cm_estimate_mod]; - Window *w; if (fn_mod_prev != _fn_mod) { - FOR_ALL_WINDOWS_FROM_FRONT(w) { + for (auto w : Window::IterateFromFront()) { if (w->CM_OnFnModStateChange() == ES_HANDLED) break; } } if (remove_mod_prev != _remove_mod) { - FOR_ALL_WINDOWS_FROM_FRONT(w) { + for (auto w : Window::IterateFromFront()) { if (w->CM_OnRemoveModStateChange() == ES_HANDLED) break; } } @@ -166,7 +165,7 @@ void RailToolbar_UpdateRemoveWidgetStatus(Window *w, int widget, bool remove_act bool RailToolbar_RemoveModChanged(Window *w, bool invert_remove, bool remove_active, bool button_clicked) { if (w->IsWidgetDisabled(WID_RAT_REMOVE)) return false; - DeleteWindowById(WC_SELECT_STATION, 0); + CloseWindowById(WC_SELECT_STATION, 0); for (uint i = WID_RAT_BUILD_NS; i < WID_RAT_REMOVE; i++) { if (w->IsWidgetLowered(i)) { auto old_active = remove_active; @@ -248,7 +247,7 @@ void RoadToolbar_UpdateOptionWidgetStatus(Window *w, int widget, bool remove_act bool RoadToolbar_RemoveModChanged(Window *w, bool remove_active, bool button_clicked, bool is_road) { if (w->IsWidgetDisabled(WID_ROT_REMOVE)) return false; - DeleteWindowById(WC_SELECT_STATION, 0); + CloseWindowById(WC_SELECT_STATION, 0); for (uint i = WID_ROT_ROAD_X; i < WID_ROT_REMOVE; i++) { if (w->IsWidgetLowered(i)) { auto old_active = remove_active; diff --git a/src/citymania/cm_main.cpp b/src/citymania/cm_main.cpp index 8fd8539caa..e2c92a2c1f 100644 --- a/src/citymania/cm_main.cpp +++ b/src/citymania/cm_main.cpp @@ -4,6 +4,7 @@ #include "cm_hotkeys.hpp" #include "cm_minimap.hpp" +#include "../network/network_func.h" #include "../window_func.h" #include "../safeguards.h" @@ -27,4 +28,8 @@ void ToggleSmallMap() { delete w; } +void NetworkClientSendChatToServer(const std::string &msg) { + NetworkClientSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, CLIENT_ID_SERVER, msg); +} + } // namespace citymania \ No newline at end of file diff --git a/src/citymania/cm_main.hpp b/src/citymania/cm_main.hpp index 6f8c659f38..69f61ced27 100644 --- a/src/citymania/cm_main.hpp +++ b/src/citymania/cm_main.hpp @@ -17,6 +17,7 @@ void Emit(const T &event) { } void ToggleSmallMap(); +void NetworkClientSendChatToServer(const std::string &msg); } // namespace citymania diff --git a/src/citymania/cm_minimap.cpp b/src/citymania/cm_minimap.cpp index 668fcfebb6..a00e8860ff 100644 --- a/src/citymania/cm_minimap.cpp +++ b/src/citymania/cm_minimap.cpp @@ -729,7 +729,7 @@ inline uint32 SmallMapWindow::GetTileColours(const TileArea &ta) const TileIndex tile = INVALID_TILE; // Position of the most important tile. TileType et = MP_VOID; // Effective tile type at that position. - TILE_AREA_LOOP(ti, ta) { + for(TileIndex ti : ta) { TileType ttype = GetTileType(ti); switch (ttype) { diff --git a/src/citymania/cm_misc_gui.cpp b/src/citymania/cm_misc_gui.cpp index 75e1ba2bd4..3c1cde2563 100644 --- a/src/citymania/cm_misc_gui.cpp +++ b/src/citymania/cm_misc_gui.cpp @@ -112,17 +112,17 @@ public: #else # define LANDINFOD_LEVEL 1 #endif - DEBUG(misc, LANDINFOD_LEVEL, "TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile)); - DEBUG(misc, LANDINFOD_LEVEL, "type = %#x", _m[tile].type); - DEBUG(misc, LANDINFOD_LEVEL, "height = %#x", _m[tile].height); - DEBUG(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1); - DEBUG(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2); - DEBUG(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3); - DEBUG(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4); - DEBUG(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5); - DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _me[tile].m6); - DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7); - DEBUG(misc, LANDINFOD_LEVEL, "m8 = %#x", _me[tile].m8); + Debug(misc, LANDINFOD_LEVEL, "TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile)); + Debug(misc, LANDINFOD_LEVEL, "type = %#x", _m[tile].type); + Debug(misc, LANDINFOD_LEVEL, "height = %#x", _m[tile].height); + Debug(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1); + Debug(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2); + Debug(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3); + Debug(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4); + Debug(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5); + Debug(misc, LANDINFOD_LEVEL, "m6 = %#x", _me[tile].m6); + Debug(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7); + Debug(misc, LANDINFOD_LEVEL, "m8 = %#x", _me[tile].m8); #undef LANDINFOD_LEVEL } @@ -386,7 +386,7 @@ void ShowLandInfo(TileIndex tile, TileIndex end_tile) if (tile == last_tooltip_tile) return; last_tooltip_tile = tile; - DeleteWindowById(WC_LAND_INFO, 0); + CloseWindowById(WC_LAND_INFO, 0); if (tile == INVALID_TILE) return; new LandInfoWindow(tile, end_tile); } diff --git a/src/citymania/cm_station_gui.cpp b/src/citymania/cm_station_gui.cpp index 444720f175..f10750fb50 100644 --- a/src/citymania/cm_station_gui.cpp +++ b/src/citymania/cm_station_gui.cpp @@ -289,7 +289,7 @@ static RoadBits FindRoadsToConnect(TileIndex tile, RoadType roadtype) { } bool CheckDriveThroughRoadStopDirection(TileArea area, RoadBits r) { - TILE_AREA_LOOP(tile, area) { + for (TileIndex tile : area) { if (GetTileType(tile) != MP_ROAD) continue; if (GetRoadTileType(tile) != ROAD_TILE_NORMAL) continue; if (GetAllRoadBits(tile) & ~r) return false; @@ -436,7 +436,7 @@ static void FindStationsAroundSelection(const TileArea &location) Station *adjacent = nullptr; /* Direct loop instead of FindStationsAroundTiles as we are not interested in catchment area */ - TILE_AREA_LOOP(tile, ta) { + for (auto tile : ta) { if (IsTileType(tile, MP_STATION) && GetTileOwner(tile) == _local_company) { Station *st = Station::GetByTile(tile); if (st == nullptr) continue; @@ -571,7 +571,7 @@ CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad) /* Loop over all tiles to get the produced cargo of * everything except industries */ - TILE_AREA_LOOP(tile, ta) { + for(auto tile : ta) { switch (GetTileType(tile)) { case MP_INDUSTRY: industries.insert(GetIndustryIndex(tile)); diff --git a/src/citymania/cm_tooltips.cpp b/src/citymania/cm_tooltips.cpp index afd59644e6..bef0539a91 100644 --- a/src/citymania/cm_tooltips.cpp +++ b/src/citymania/cm_tooltips.cpp @@ -104,9 +104,7 @@ struct LandTooltipsWindow : public Window SetDParam(0, st->index); size->width = std::max(GetStringBoundingBox(STR_CM_LAND_TOOLTIPS_STATION_NAME).width, size->width); - for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { - const CargoSpec *cs = _sorted_cargo_specs[i]; - if(cs == NULL) continue; + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { int cargoid = cs->Index(); if (HasBit(st->goods[cargoid].status, GoodsEntry::GES_RATING)) { size->height += line_height; @@ -186,9 +184,7 @@ struct LandTooltipsWindow : public Window DrawString(left, right, y, STR_CM_LAND_TOOLTIPS_STATION_NAME, TC_BLACK, SA_CENTER); y += FONT_HEIGHT_NORMAL + 2; - for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { - const CargoSpec *cs = _sorted_cargo_specs[i]; - if(cs == NULL) continue; + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { int cargoid = cs->Index(); if (HasBit(st->goods[cargoid].status, GoodsEntry::GES_RATING)) { SetDParam(0, cs->name); @@ -223,7 +219,7 @@ void ShowLandTooltips(TileIndex tile, Window *parent) { last_tooltip_tile = tile; if (tile == INVALID_TILE) { - DeleteWindowById(CM_WC_LAND_TOOLTIPS, 0); + CloseWindowById(CM_WC_LAND_TOOLTIPS, 0); return; } @@ -255,7 +251,7 @@ void ShowLandTooltips(TileIndex tile, Window *parent) { default: break; } - DeleteWindowById(CM_WC_LAND_TOOLTIPS, 0); + CloseWindowById(CM_WC_LAND_TOOLTIPS, 0); if (param == 0) return; new LandTooltipsWindow(parent, param); @@ -504,7 +500,7 @@ public: }; bool ShowStationRatingTooltip(Window *parent, const Station *st, const CargoSpec *cs, TooltipCloseCondition close_cond) { - DeleteWindowById(WC_STATION_RATING_TOOLTIP, 0); + CloseWindowById(WC_STATION_RATING_TOOLTIP, 0); new StationRatingTooltipWindow(parent, st, cs, close_cond); return true; } diff --git a/src/citymania/cm_watch_gui.cpp b/src/citymania/cm_watch_gui.cpp index 8973c01fcc..648355b5f4 100644 --- a/src/citymania/cm_watch_gui.cpp +++ b/src/citymania/cm_watch_gui.cpp @@ -3,6 +3,7 @@ #include "../stdafx.h" #include "cm_watch_gui.hpp" +#include "cm_main.hpp" #include "../widget_type.h" #include "../gfx_type.h" diff --git a/src/citymania/cm_watch_gui.hpp b/src/citymania/cm_watch_gui.hpp index c4aa536211..8bb197c121 100644 --- a/src/citymania/cm_watch_gui.hpp +++ b/src/citymania/cm_watch_gui.hpp @@ -5,6 +5,7 @@ #include "../window_gui.h" #include "../company_base.h" +#include "../network/core/config.h" namespace citymania { diff --git a/src/company_gui.cpp b/src/company_gui.cpp index d896588971..f037877de4 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -41,6 +41,7 @@ #include "widgets/company_widget.h" #include "citymania/cm_hotkeys.hpp" +#include "citymania/cm_main.hpp" #include "safeguards.h" @@ -2220,7 +2221,7 @@ static void ResetCallback(Window *w, bool confirmed) CompanyID company2 = (CompanyID)w->window_number; char msg[128]; seprintf(msg, lastof(msg), "!reset %i", company2 + 1); - NetworkClientSendChatToServer(msg); + citymania::NetworkClientSendChatToServer(msg); } } @@ -2652,7 +2653,7 @@ struct CompanyWindow : Window // this->query_widget = WID_C_MOD_COMPANY_JOIN; char msg[128]; seprintf(msg, lastof(msg), "!move %i", company2 + 1); - NetworkClientSendChatToServer(msg); + citymania::NetworkClientSendChatToServer(msg); MarkWholeScreenDirty(); break; } @@ -2668,7 +2669,7 @@ struct CompanyWindow : Window CompanyID company2 = (CompanyID)this->window_number; char msg[128]; seprintf(msg, lastof(msg), "!lockp %i", company2 + 1); - NetworkClientSendChatToServer(msg); + citymania::NetworkClientSendChatToServer(msg); MarkWholeScreenDirty(); break; } diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 015c9d4dd7..67d8baee51 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -182,7 +182,7 @@ static void LoadSpriteTables() PAL_DOS != used_set->palette ); } - LoadGrfFile("cmclient-3.grf", SPR_INNER_HIGHLIGHT_BASE - 4, i++); + LoadGrfFile("cmclient-3.grf", SPR_INNER_HIGHLIGHT_BASE - 4, PAL_DOS != used_set->palette); /* Initialize the unicode to sprite mapping table */ InitializeUnicodeGlyphMap(); diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index df123a7d53..998cc6ab3b 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -725,8 +725,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { } Dimension max_cargo_dim = {0, 0}; - const CargoSpec *cs; - FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { SetDParam(0, cs->name); max_cargo_dim = maxdim(max_cargo_dim, GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO)); } @@ -735,7 +734,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { this->line_height = this->icon_size + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; size->width = (max_cargo_dim.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + 1 + (this->show_cargo_colors ? this->icon_size + WD_PAR_VSEP_NORMAL : 0)); - size->height = std::max(size->height, this->line_height * _sorted_standard_cargo_specs_size); + size->height = std::max(size->height, this->line_height * _sorted_standard_cargo_specs.size()); resize->width = 0; resize->height = this->line_height; fill->width = 0; @@ -757,8 +756,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { int pos = this->vscroll->GetPosition(); int max = pos + this->vscroll->GetCapacity(); - const CargoSpec *cs; - FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { if (pos-- > 0) continue; if (--max < 0) break; @@ -789,8 +787,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { this->excluded_data = 0; int i = 0; - const CargoSpec *cs; - FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i); i++; } @@ -813,8 +810,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { case WID_CPR_DISABLE_CARGOES: { /* Add all cargoes to the excluded lists. */ int i = 0; - const CargoSpec *cs; - FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { SetBit(_legend_excluded_cargo, cs->Index()); SetBit(this->excluded_data, i); i++; @@ -824,11 +820,10 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { } case WID_CPR_MATRIX: { - uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CPR_MATRIX, 0, this->line_height); + uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CPR_MATRIX); if (row >= this->vscroll->GetCount()) return; - const CargoSpec *cs; - FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { if (row-- > 0) continue; ToggleBit(_legend_excluded_cargo, cs->Index()); @@ -945,7 +940,7 @@ struct IncomeGraphWindow : ExcludingCargoBaseGraphWindow { { this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR); - this->vscroll->SetCount(_sorted_standard_cargo_specs_size); + this->vscroll->SetCount(_sorted_standard_cargo_specs.size()); this->UpdateExcludedData(); this->FinishInitNested(window_number); } @@ -956,8 +951,7 @@ struct IncomeGraphWindow : ExcludingCargoBaseGraphWindow { return c->old_economy[j].income; } uint total_income = 0; - const CargoSpec *cs; - FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { if (!HasBit(_legend_excluded_cargo, cs->Index())){ total_income += c->old_economy[j].cm.cargo_income[cs->Index()]; } @@ -1063,7 +1057,7 @@ struct DeliveredCargoGraphWindow : ExcludingCargoBaseGraphWindow { { this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR); - this->vscroll->SetCount(_sorted_standard_cargo_specs_size); + this->vscroll->SetCount(_sorted_standard_cargo_specs.size()); this->OnHundredthTick(); this->FinishInitNested(window_number); } @@ -1074,8 +1068,7 @@ struct DeliveredCargoGraphWindow : ExcludingCargoBaseGraphWindow { return c->old_economy[j].delivered_cargo.GetSum(); } uint total_delivered = 0; - const CargoSpec *cs; - FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { if (!HasBit(_legend_excluded_cargo, cs->Index())){ total_delivered += c->old_economy[j].delivered_cargo[cs->Index()]; } diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index e743f887af..3fbe9cb7d5 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -41,7 +41,7 @@ /* This file handles all the client-commands */ -void SyncCMUser(const char *msg); +void SyncCMUser(const std::string &msg); // extern const std::map OPENTTD_NEWGRF_VERSIONS; // extern const std::map OPENTTD_RELEASE_REVISIONS; static const uint32 OPENTTD_NEWGRF_REVISION_MASK = (1 << 19) - 1; @@ -1016,7 +1016,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p) } if (ci != nullptr) { - if (strncmp(msg, "synccmuser", 10) == 0) SyncCMUser(msg); + if (msg.rfind("synccmuser", 0) == 0) SyncCMUser(msg); else NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), self_send, name, msg, data); } return NETWORK_RECV_STATUS_OKAY; @@ -1339,10 +1339,6 @@ void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const MyClient::SendChat(action, type, dest, msg, data); } -void NetworkClientSendChatToServer(const char * msg) -{ - NetworkClientSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, CLIENT_ID_SERVER, msg); -} /** * Set/Reset company password on the client side. * @param password Password to be set. @@ -1378,10 +1374,10 @@ bool NetworkMaxCompaniesReached() return Company::GetNumItems() >= (_network_server ? _settings_client.network.max_companies : _network_server_max_companies); } -void SyncCMUser(const char *msg) { +void SyncCMUser(const std::string &msg) { uint user_id, role; - sscanf(msg + 10, "%u %u", &user_id, &role); + sscanf(msg.c_str() + 10, "%u %u", &user_id, &role); _novarole = (role >= 50); - DEBUG(net, 1, "CityMania user synchronized: %u %u", user_id, role); + Debug(net, 1, "CityMania user synchronized: %u %u", user_id, role); } diff --git a/src/network/network_func.h b/src/network/network_func.h index bb9b766c62..17d50683c9 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -57,7 +57,6 @@ void NetworkClientJoinGame(); void NetworkClientRequestMove(CompanyID company, const std::string &pass = ""); void NetworkClientSendRcon(const std::string &password, const std::string &command); void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data = 0); -void NetworkClientSendChatToServer(const std::string &msg); bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio); bool NetworkCompanyIsPassworded(CompanyID company_id); bool NetworkMaxCompaniesReached(); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index e0a555e4e9..85d0f5e3ec 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -798,7 +798,7 @@ public: case WID_NG_REDDIT: case WID_NG_CITYMANIA: if(!UDP_CC_queried){ - NetworkUDPQueryMasterServer(); + // FIXME NetworkUDPQueryMasterServer(); UDP_CC_queried = true; } if(widget == WID_NG_NICE) this->filter_editbox.text.Assign("n-ice"); diff --git a/src/openttd.cpp b/src/openttd.cpp index 9ef577fc66..bce47d7dcf 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -655,7 +655,7 @@ int openttd_main(int argc, char *argv[]) case 'x': scanner->save_config = false; break; case 'X': only_local_path = true; break; case 'C': { - DeterminePaths(argv[0]); + DeterminePaths(argv[0], true); if (StrEmpty(mgo.opt)) { ret = 1; return ret; diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 669792263c..5d06ee6a50 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -763,8 +763,6 @@ private: DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER)); - /* Transfer and unload orders with leave empty as default */ - if (unload_type == OUFB_TRANSFER || unload_type == OUFB_UNLOAD) { bool set_no_load = false; if (unload_type == OUFB_TRANSFER){ set_no_load = _settings_client.gui.auto_noload_on_transfer; diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 82a73cb7f0..3f4750afc7 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1327,7 +1327,7 @@ public: _railstation.orientation = OtherAxis(_railstation.orientation); this->LowerWidget(_railstation.orientation + WID_BRAS_PLATFORM_DIR_X); this->SetDirty(); - DeleteWindowById(WC_SELECT_STATION, 0); + CloseWindowById(WC_SELECT_STATION, 0); return ES_HANDLED; default: diff --git a/src/station_gui.cpp b/src/station_gui.cpp index e8ef40f7d8..4969d2b75e 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -2139,8 +2139,7 @@ struct StationViewWindow : public Window { if (ofs_y < 0) return false; const Station *st = Station::Get(this->window_number); - const CargoSpec *cs; - FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { const GoodsEntry *ge = &st->goods[cs->Index()]; if (!ge->HasRating()) continue; ofs_y -= FONT_HEIGHT_NORMAL; diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index b0d6d051e5..e16c0783bc 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -126,49 +126,48 @@ bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_t tree_start_tile = tree_recent_tile = prev_tile = 0; if (!citymania::_fn_mod) { OrthogonalTileArea square_area = OrthogonalTileArea(start_tile, end_tile); - TILE_AREA_LOOP(curr_tile, square_area) { + for (auto cur_tile : square_area) { // if we're on a non-consecutive tile or we've hit a black-marked tile // safe tiles are: TREES or non-FIELD clear tiles (because they're expensive to demolish) if (tree_start_tile != 0 && - (curr_tile != prev_tile + 1 || - (!IsTileType(curr_tile, MP_TREES) && (!IsTileType(curr_tile, MP_CLEAR) || IsClearGround(curr_tile, CLEAR_FIELDS))))) { + (cur_tile != prev_tile + 1 || + (!IsTileType(cur_tile, MP_TREES) && (!IsTileType(cur_tile, MP_CLEAR) || IsClearGround(cur_tile, CLEAR_FIELDS))))) { DoCommandP(tree_start_tile, tree_recent_tile, 0, CMD_CLEAR_AREA | CMD_MSG(STR_ERROR_CAN_T_CLEAR_THIS_AREA), CcPlaySound_EXPLOSION); tree_start_tile = tree_recent_tile = 0; } // if current tile is a tree - if (IsTileType(curr_tile, MP_TREES)) { + if (IsTileType(cur_tile, MP_TREES)) { if (tree_start_tile == 0) { - tree_start_tile = curr_tile; + tree_start_tile = cur_tile; } - tree_recent_tile = curr_tile; + tree_recent_tile = cur_tile; } - prev_tile = curr_tile; + prev_tile = cur_tile; } // one last ride to flavortown if (tree_start_tile != 0) { DoCommandP(tree_start_tile, tree_recent_tile, 0, CMD_CLEAR_AREA | CMD_MSG(STR_ERROR_CAN_T_CLEAR_THIS_AREA), CcPlaySound_EXPLOSION); } } else { // diagonal area - DiagonalTileArea diagonal_area = DiagonalTileArea(start_tile, end_tile); - DIAGONAL_TILE_AREA_LOOP(curr_tile, diagonal_area) { + for (DiagonalTileIterator cur_tile{start_tile, end_tile}; cur_tile != INVALID_TILE; ++cur_tile) { // same as above but with a different criteria for consecutive tiles - TileIndexDiffC tile_diff = TileIndexToTileIndexDiffC(curr_tile, prev_tile); + TileIndexDiffC tile_diff = TileIndexToTileIndexDiffC(cur_tile, prev_tile); // if we're on a non-consecutive tile or we've hit a black-marked tile // safe tiles are: TREES or non-FIELD clear tiles (because they're expensive to demolish) if (tree_start_tile != 0 && (!((tile_diff.x == 1 && tile_diff.y == 1) || (tile_diff.x == -1 && tile_diff.y == -1)) || - (!IsTileType(curr_tile, MP_TREES) && (!IsTileType(curr_tile, MP_CLEAR) || IsClearGround(curr_tile, CLEAR_FIELDS))))) { + (!IsTileType(cur_tile, MP_TREES) && (!IsTileType(cur_tile, MP_CLEAR) || IsClearGround(cur_tile, CLEAR_FIELDS))))) { DoCommandP(tree_start_tile, tree_recent_tile, 1, CMD_CLEAR_AREA | CMD_MSG(STR_ERROR_CAN_T_CLEAR_THIS_AREA), CcPlaySound_EXPLOSION); tree_start_tile = tree_recent_tile = 0; } // if current tile is a tree - if (IsTileType(curr_tile, MP_TREES)) { + if (IsTileType(cur_tile, MP_TREES)) { if (tree_start_tile == 0) { - tree_start_tile = curr_tile; + tree_start_tile = cur_tile; } - tree_recent_tile = curr_tile; + tree_recent_tile = cur_tile; } - prev_tile = curr_tile; + prev_tile = cur_tile; } // one last ride to flavortown if (tree_start_tile != 0) { diff --git a/src/video/null_v.cpp b/src/video/null_v.cpp index 2915ef8af1..2b77557dc5 100644 --- a/src/video/null_v.cpp +++ b/src/video/null_v.cpp @@ -63,9 +63,9 @@ void VideoDriver_Null::MainLoop() fprintf(stderr, "Null driver ran for %u tics, save: %s\n", this->ticks, this->savefile.c_str()); if (!this->savefile.empty()) { if (SaveOrLoad(this->savefile.c_str(), SLO_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) { - IConsolePrintF(CC_ERROR, "Error saving the final game state."); + IConsolePrint(CC_ERROR, "Error saving the final game state."); } else { - IConsolePrintF(CC_DEFAULT, "Saved the final game state to %s", this->savefile.c_str()); + IConsolePrint(CC_DEFAULT, "Saved the final game state to {}", this->savefile); } }