From 0586e48c3bf93ddc0e84502910c0f4f564dd1b45 Mon Sep 17 00:00:00 2001 From: dP Date: Sun, 14 Dec 2025 16:16:29 +0500 Subject: [PATCH 1/4] Fix road/rail station building buttons malfunction when switching from other tool --- src/citymania/cm_highlight.cpp | 4 +--- src/road_gui.cpp | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/citymania/cm_highlight.cpp b/src/citymania/cm_highlight.cpp index d1e4a3937c..72840ddf41 100644 --- a/src/citymania/cm_highlight.cpp +++ b/src/citymania/cm_highlight.cpp @@ -2893,8 +2893,6 @@ bool HandlePlacePushButton(Window *w, WidgetID widget, up tool) { return false; } - w->LowerWidget(widget); - auto icon = tool->GetCursor(); if ((icon & ANIMCURSOR_FLAG) != 0) { SetAnimatedMouseCursor(_animcursors[icon & ~ANIMCURSOR_FLAG]); @@ -2904,9 +2902,9 @@ bool HandlePlacePushButton(Window *w, WidgetID widget, up tool) { citymania::SetActiveTool(std::move(tool)); _thd.window_class = w->window_class; _thd.window_number = w->window_number; + w->LowerWidget(widget); return true; - } } // namespace citymania diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 019f155c7e..710a84c1ee 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -569,8 +569,7 @@ struct BuildRoadToolbarWindow : Window { default: NOT_REACHED(); } citymania::RoadToolbar_UpdateOptionWidgetStatus(this, widget, _remove_button_clicked, RoadTypeIsRoad(this->roadtype)); - // this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget); - // if (citymania::_remove_mod) RoadToolbar_CtrlChanged(this); + //this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget); } EventState OnHotkey(int hotkey) override From fe6e89500198f6eda26f3de16f349b3c5558a2f2 Mon Sep 17 00:00:00 2001 From: dP Date: Sun, 14 Dec 2025 16:16:42 +0500 Subject: [PATCH 2/4] Fix some compiler warnings --- src/citymania/cm_station_gui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/citymania/cm_station_gui.cpp b/src/citymania/cm_station_gui.cpp index 5db4f21407..3e421670b2 100644 --- a/src/citymania/cm_station_gui.cpp +++ b/src/citymania/cm_station_gui.cpp @@ -962,7 +962,7 @@ ToolGUIInfo PlacementAction::PrepareGUIInfo(std::optional ohl, void SizedPlacementAction::Update(Point, TileIndex tile) { this->cur_tile = tile; - UpdateStationAction(this->GetArea(), std::move(this->GetCommand(tile, INVALID_STATION))); + UpdateStationAction(this->GetArea(), this->GetCommand(tile, INVALID_STATION)); } bool SizedPlacementAction::HandleMousePress() { @@ -1000,7 +1000,7 @@ void DragNDropPlacementAction::Update(Point, TileIndex tile) { this->cur_tile = tile; auto area = this->GetArea(); if (!area.has_value()) return; - UpdateStationAction(area, std::move(this->GetCommand(*area, INVALID_STATION))); + UpdateStationAction(area, this->GetCommand(*area, INVALID_STATION)); } bool DragNDropPlacementAction::HandleMousePress() { From d95e758bc28ca0ee95be94812d26927c4e72f498 Mon Sep 17 00:00:00 2001 From: dP Date: Sun, 14 Dec 2025 17:24:27 +0500 Subject: [PATCH 3/4] Don't show production of the hidden industries on a minimap --- src/citymania/cm_minimap.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/citymania/cm_minimap.cpp b/src/citymania/cm_minimap.cpp index ffd152e43f..bfda61f0f4 100644 --- a/src/citymania/cm_minimap.cpp +++ b/src/citymania/cm_minimap.cpp @@ -1030,6 +1030,7 @@ void SmallMapWindow::DrawIndustryProduction(const DrawPixelInfo *dpi) const [this] (auto &e) { auto ind = Industry::GetIfValid(e.index); if (ind == nullptr) return; + if (!_legend_from_industries[_industry_to_list_pos[ind->type]].show_on_map) return; auto pt = this->TileToPixel( TileX(ind->location.tile) * TILE_SIZE + ind->location.w * TILE_SIZE / 2, TileY(ind->location.tile) * TILE_SIZE + ind->location.h * TILE_SIZE / 2 From 2033299336547a32e5d6bcdf1ea4deea4836dd9e Mon Sep 17 00:00:00 2001 From: dP Date: Sun, 14 Dec 2025 17:37:16 +0500 Subject: [PATCH 4/4] Don't crash when opening airport build tool with no available airports --- src/citymania/cm_highlight.cpp | 9 ++++++--- src/citymania/cm_station_gui.cpp | 32 +++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/citymania/cm_highlight.cpp b/src/citymania/cm_highlight.cpp index 72840ddf41..5c7c5051cf 100644 --- a/src/citymania/cm_highlight.cpp +++ b/src/citymania/cm_highlight.cpp @@ -2500,9 +2500,12 @@ HighLightStyle UpdateTileSelection(HighLightStyle new_drawstyle) { } else if (_thd.select_proc == CM_DDSP_BUILD_AIRPORT) { auto tile = TileXY(_thd.new_pos.x / TILE_SIZE, _thd.new_pos.y / TILE_SIZE); if (_selected_airport_index != -1) { - const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index); - _thd.cm_new = ObjectHighlight::make_airport(tile, as->GetIndex(), _selected_airport_layout); - new_drawstyle = HT_RECT; + auto ac = AirportClass::Get(_selected_airport_class); + auto as = (ac != nullptr ? ac->GetSpec(_selected_airport_index) : nullptr); + if (as != nullptr) { + _thd.cm_new = ObjectHighlight::make_airport(tile, as->GetIndex(), _selected_airport_layout); + new_drawstyle = HT_RECT; + } } } else if (_thd.select_proc == DDSP_BUILD_STATION || _thd.select_proc == DDSP_BUILD_BUSSTOP || _thd.select_proc == DDSP_BUILD_TRUCKSTOP) { // station diff --git a/src/citymania/cm_station_gui.cpp b/src/citymania/cm_station_gui.cpp index 3e421670b2..039e476359 100644 --- a/src/citymania/cm_station_gui.cpp +++ b/src/citymania/cm_station_gui.cpp @@ -800,7 +800,7 @@ ToolGUIInfo RemoveAction::GetGUIInfo() { if (area.has_value()) { hlmap.AddTileAreaWithBorder(area.value(), CM_PALETTE_TINT_RED_DEEP); auto cmd = this->GetCommand(area.value()); - if (cmd) cost = cmd->test(); + if (cmd != nullptr) cost = cmd->test(); } return {hlmap, data, cost}; } @@ -810,7 +810,7 @@ void RemoveAction::OnStationRemoved(const Station *) {} // --- PlacementAction --- ToolGUIInfo PlacementAction::PrepareGUIInfo(std::optional ohl, up cmd, StationCoverageType sct, uint rad) { - if (!cmd || !ohl.has_value()) return {}; + if (cmd == nullptr || !ohl.has_value()) return {}; ohl.value().UpdateTiles(); auto palette = CM_PALETTE_TINT_WHITE; auto area = ohl.value().GetArea(); @@ -1106,6 +1106,7 @@ extern void ShowSelectStationWindow(TileArea ta, StationPickerCmdProc&& proc); template bool PostBuildStationCommand(Taction *action, Tcallback callback, Targ arg, StationID join_to) { auto cmd = action->GetCommand(arg, join_to); + if (cmd == nullptr) return false; if (UseImprovedStationJoin()) { cmd->with_callback([](bool res)->bool { if (!res) return false; @@ -1114,7 +1115,7 @@ bool PostBuildStationCommand(Taction *action, Tcallback callback, Targ arg, Stat return true; }); } - return cmd ? cmd->post(callback) : false; + return cmd->post(callback); } template @@ -1129,7 +1130,7 @@ bool ExecuteBuildCommand(Taction *action, Tcallback callback, Targ arg) { [&](StationAction::Picker &) { auto cmd = action->GetCommand(arg, INVALID_STATION); auto proc = [cmd=sp{std::move(cmd)}, callback](bool test, StationID to_join) -> bool { - if (!cmd) return false; + if (cmd == nullptr) return false; auto station_cmd = dynamic_cast(cmd.get()); if (station_cmd == nullptr) return false; station_cmd->station_to_join = to_join; @@ -1169,6 +1170,7 @@ up RailStationBuildTool::RemoveAction::GetCommand(TileArea area) { bool RailStationBuildTool::RemoveAction::Execute(TileArea area) { auto cmd = this->GetCommand(area); + if (cmd == nullptr) return false; return cmd->post(&CcPlaySound_CONSTRUCTION_RAIL); } @@ -1300,6 +1302,7 @@ up RoadStopBuildTool::RemoveAction::GetCommand(TileArea area) { bool RoadStopBuildTool::RemoveAction::Execute(TileArea area) { auto cmd = this->GetCommand(area); + if (cmd == nullptr) return false; return cmd->post(&CcPlaySound_CONSTRUCTION_OTHER); } @@ -1504,13 +1507,17 @@ bool AirportBuildTool::RemoveAction::Execute(TileArea area) { std::optional AirportBuildTool::SizedPlacementAction::GetArea() const { if (!IsValidTile(this->cur_tile)) return std::nullopt; - auto as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index); + auto ac = AirportClass::Get(_selected_airport_class); + if (ac == nullptr) return std::nullopt; + auto as = ac->GetSpec(_selected_airport_index); if (as == nullptr) return std::nullopt; return TileArea{this->cur_tile, as->size_x, as->size_y}; } up AirportBuildTool::SizedPlacementAction::GetCommand(TileIndex tile, StationID to_join) { - auto as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index); + auto ac = AirportClass::Get(_selected_airport_class); + if (ac == nullptr) return nullptr; + auto as = ac->GetSpec(_selected_airport_index); if (as == nullptr) return nullptr; byte airport_type = as->GetIndex(); byte layout = _selected_airport_layout; @@ -1530,14 +1537,21 @@ bool AirportBuildTool::SizedPlacementAction::Execute(TileIndex tile) { } std::optional AirportBuildTool::SizedPlacementAction::GetObjectHighlight(TileIndex tile) { - byte airport_type = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex(); + auto ac = AirportClass::Get(_selected_airport_class); + if (ac == nullptr) return std::nullopt; + auto as = ac->GetSpec(_selected_airport_index); + if (as == nullptr) return std::nullopt; + byte airport_type = as->GetIndex(); byte layout = _selected_airport_layout; return ObjectHighlight::make_airport(tile, airport_type, layout); } std::pair AirportBuildTool::SizedPlacementAction::GetCatchmentParams() { - auto rad = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->catchment; - return {SCT_ALL, rad}; + auto ac = AirportClass::Get(_selected_airport_class); + if (ac == nullptr) return {SCT_ALL, 0}; + auto as = ac->GetSpec(_selected_airport_index); + if (as == nullptr) return {SCT_ALL, 0}; + return {SCT_ALL, as->catchment}; }