From a21cafd2a10b9f3d2dc40a3b489b41dfa896a18d Mon Sep 17 00:00:00 2001 From: dP Date: Sun, 2 Apr 2023 17:03:20 +0400 Subject: [PATCH] Show output of all producing industries on the minimap --- src/build_vehicle_gui.cpp | 1 + src/citymania/cm_blueprint.cpp | 4 +-- src/citymania/cm_command_type.hpp | 4 +-- src/citymania/cm_game.hpp | 1 + src/citymania/cm_highlight.cpp | 42 +++++++++++++++++++---------- src/citymania/cm_highlight_type.hpp | 3 +++ src/citymania/cm_minimap.cpp | 6 +++-- src/lang/english.txt | 4 ++- src/lang/german.txt | 2 +- 9 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index f50411858c..1b6bf06708 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -910,6 +910,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, if (_settings_client.gui.newgrf_developer_tools) { SetDParam(0, e->index); + SetDParam(1, e->grf_prop.local_id); DrawString(left, right, y, CM_STR_PURCHASE_ENGINE_ID); y += FONT_HEIGHT_NORMAL; } diff --git a/src/citymania/cm_blueprint.cpp b/src/citymania/cm_blueprint.cpp index 4f5d5faf4a..ce1f5f6e3a 100644 --- a/src/citymania/cm_blueprint.cpp +++ b/src/citymania/cm_blueprint.cpp @@ -215,14 +215,14 @@ std::multimap Blueprint::GetTiles(TileIndex tile std::set can_build_station_sign; for (auto &item: this->items) { if (item.type != Item::Type::RAIL_STATION) continue; - if (GetBlueprintCommand(tile, item)->test()) + if (GetBlueprintCommand(tile, item)->test().Succeeded()) can_build_station_sign.insert(item.u.rail.station.id); } for (auto &o: this->items) { auto otile = AddTileIndexDiffCWrap(tile, o.tdiff); auto palette = CM_PALETTE_TINT_WHITE; - if (o.type != Item::Type::RAIL_SIGNAL && !GetBlueprintCommand(tile, o)->test()) + if (o.type != Item::Type::RAIL_SIGNAL && !GetBlueprintCommand(tile, o)->test().Succeeded()) palette = CM_PALETTE_TINT_RED_DEEP; switch(o.type) { diff --git a/src/citymania/cm_command_type.hpp b/src/citymania/cm_command_type.hpp index 312b2f32e1..474f98ba8b 100644 --- a/src/citymania/cm_command_type.hpp +++ b/src/citymania/cm_command_type.hpp @@ -70,8 +70,8 @@ public: return res; } - bool test() { - return this->call(DC_NONE).Succeeded(); + CommandCost test() { + return this->call(DC_NONE); } Command &with_tile(TileIndex tile) { diff --git a/src/citymania/cm_game.hpp b/src/citymania/cm_game.hpp index e6948006a9..15ba6d389c 100644 --- a/src/citymania/cm_game.hpp +++ b/src/citymania/cm_game.hpp @@ -11,6 +11,7 @@ class Game { protected: TownsGrowthTilesIndex towns_growth_tiles_last_month; TownsGrowthTilesIndex towns_growth_tiles; + uint64 start_countdown = 0; public: event::Dispatcher events; diff --git a/src/citymania/cm_highlight.cpp b/src/citymania/cm_highlight.cpp index 6044831c0a..15dbbaf945 100644 --- a/src/citymania/cm_highlight.cpp +++ b/src/citymania/cm_highlight.cpp @@ -336,6 +336,7 @@ void ObjectHighlight::AddTile(TileIndex tile, ObjectTileHighlight &&oh) { void ObjectHighlight::UpdateTiles() { this->tiles.clear(); this->sprites.clear(); + this->cost = CMD_ERROR; switch (this->type) { case Type::NONE: break; @@ -343,11 +344,12 @@ void ObjectHighlight::UpdateTiles() { case Type::RAIL_DEPOT: { auto dir = this->ddir; - auto palette = (cmd::BuildTrainDepot( + this->cost = cmd::BuildTrainDepot( this->tile, _cur_railtype, dir - ).test() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); + ).test(); + auto palette = (cost.Succeeded() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); this->tiles.insert(std::make_pair(this->tile, ObjectTileHighlight::make_rail_depot(palette, dir))); auto tile = this->tile + TileOffsByDiagDir(dir); @@ -364,7 +366,7 @@ void ObjectHighlight::UpdateTiles() { auto plat_len = ta.h; if (this->axis == AXIS_X) Swap(numtracks, plat_len); - auto palette = (cmd::BuildRailStation( + this->cost = cmd::BuildRailStation( this->tile, _cur_railtype, this->axis, @@ -374,7 +376,8 @@ void ObjectHighlight::UpdateTiles() { _railstation.station_type, NEW_STATION, true - ).test() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); + ).test(); + auto palette = (this->cost.Succeeded() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); auto layout_ptr = AllocaM(byte, (int)numtracks * plat_len); GetStationLayout(layout_ptr, numtracks, plat_len, nullptr); // TODO statspec @@ -396,7 +399,7 @@ void ObjectHighlight::UpdateTiles() { } case Type::ROAD_STOP: { auto ta = OrthogonalTileArea(this->tile, this->end_tile); - auto palette = (cmd::BuildRoadStop( + this->cost = cmd::BuildRoadStop( this->tile, ta.w, ta.h, @@ -406,7 +409,8 @@ void ObjectHighlight::UpdateTiles() { this->roadtype, NEW_STATION, true - ).test() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); + ).test(); + auto palette = (this->cost.Succeeded() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); for (TileIndex tile : ta) { this->AddTile(tile, ObjectTileHighlight::make_road_stop(palette, this->roadtype, this->ddir, this->is_truck)); } @@ -414,23 +418,25 @@ void ObjectHighlight::UpdateTiles() { } case Type::ROAD_DEPOT: { - auto palette = (cmd::BuildRoadDepot( + this->cost = cmd::BuildRoadDepot( this->tile, this->roadtype, this->ddir - ).test() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); + ).test(); + auto palette = (this->cost.Succeeded() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); this->AddTile(this->tile, ObjectTileHighlight::make_road_depot(palette, this->roadtype, this->ddir)); break; } case Type::AIRPORT: { - auto palette = (cmd::BuildAirport( + this->cost = cmd::BuildAirport( this->tile, this->airport_type, this->airport_layout, NEW_STATION, true - ).test() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); + ).test(); + auto palette = (this->cost.Succeeded() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); const AirportSpec *as = AirportSpec::Get(this->airport_type); if (!as->IsAvailable() || this->airport_layout >= as->num_table) break; @@ -523,8 +529,8 @@ void ObjectHighlight::UpdateTiles() { break; } case Type::INDUSTRY: { - auto cost = cmd::BuildIndustry{this->tile, this->ind_type, this->ind_layout, true, 0}.call(DC_NONE); - if (cost.Succeeded()) { + this->cost = cmd::BuildIndustry{this->tile, this->ind_type, this->ind_layout, true, 0}.call(DC_NONE); + if (this->cost.Succeeded()) { const IndustrySpec *indspec = GetIndustrySpec(this->ind_type); if (indspec == nullptr) break; if (cost.cm.industry_layout >= indspec->layouts.size()) break; @@ -554,6 +560,10 @@ void ObjectHighlight::UpdateTiles() { default: NOT_REACHED(); } + + if (this->cost.Succeeded()) { + // TODO overlay size + } } void ObjectHighlight::MarkDirty() { @@ -1288,7 +1298,7 @@ bool Intersects(const Rect &rect, int left, int top, int right, int bottom) { } -void ObjectHighlight::DrawOverlay(DrawPixelInfo *dpi) { +void ObjectHighlight::DrawSelectionOverlay(DrawPixelInfo *dpi) { for (auto &s : this->sprites) { DrawSpriteViewport(s.sprite_id, s.palette_id, s.pt.x, s.pt.y); } @@ -1314,6 +1324,10 @@ void ObjectHighlight::DrawOverlay(DrawPixelInfo *dpi) { // } } +void ObjectHighlight::DrawOverlay(DrawPixelInfo *dpi) { + if (!this->cost.Succeeded()) return; +} + template uint8 Get(uint32 x, uint32 y, F getter) { if (x >= MapSizeX() || y >= MapSizeY()) return 0; @@ -1665,7 +1679,7 @@ bool DrawTileSelection(const TileInfo *ti, const TileHighlightType &tht) { } void DrawSelectionOverlay(DrawPixelInfo *dpi) { - _thd.cm.DrawOverlay(dpi); + _thd.cm.DrawSelectionOverlay(dpi); } diff --git a/src/citymania/cm_highlight_type.hpp b/src/citymania/cm_highlight_type.hpp index 92d2c47f7b..a9b480d4b5 100644 --- a/src/citymania/cm_highlight_type.hpp +++ b/src/citymania/cm_highlight_type.hpp @@ -306,6 +306,8 @@ public: sp blueprint = nullptr; IndustryType ind_type = INVALID_INDUSTRYTYPE; uint32 ind_layout = 0; + CommandCost cost; + Dimension overlay_dim; protected: bool tiles_updated = false; @@ -333,6 +335,7 @@ public: TileHighlight GetTileHighlight(const TileInfo *ti); void Draw(const TileInfo *ti); + void DrawSelectionOverlay(DrawPixelInfo *dpi); void DrawOverlay(DrawPixelInfo *dpi); void UpdateTiles(); void MarkDirty(); diff --git a/src/citymania/cm_minimap.cpp b/src/citymania/cm_minimap.cpp index 027991e705..ff7346eb57 100644 --- a/src/citymania/cm_minimap.cpp +++ b/src/citymania/cm_minimap.cpp @@ -237,8 +237,10 @@ MinimapIndustryKdtree _minimap_industry_idx{Kdtree_MinimapIndustryXYFunc}; uint _max_industry_outputs = 0; bool is_cached_industry(const Industry *ind) { - const IndustrySpec *indspec = GetIndustrySpec(ind->type); - return ((indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0); + for (auto i = 0; i < INDUSTRY_NUM_OUTPUTS; i++) + if (ind->produced_cargo[i] != INVALID_CARGO) + return true; + return false; } MinimapIndustryKdtreeEntry get_industry_entry(const Industry *ind) { diff --git a/src/lang/english.txt b/src/lang/english.txt index 8fde82c662..959f01ab4d 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -5916,7 +5916,7 @@ CM_STR_CONFIG_SETTING_OPEN_VEHICLE_FOR_SHARED_CLONE :Open vehicle wi CM_STR_CONFIG_SETTING_OPEN_VEHICLE_FOR_SHARED_CLONE_HELPTEXT :Open vehicle window when cloning vehicles with shared orders (as it does for non-shared ones) CM_STR_CONFIG_SETTING_OPEN_ORDERS_FOR_NEW_VEHICLES :Open orders window for new vehicles: {STRING2} CM_STR_CONFIG_SETTING_OPEN_ORDERS_FOR_NEW_VEHICLES_HELPTEXT :Automatically open orders window along with a vehicle window for a new vehicles -CM_STR_PURCHASE_ENGINE_ID :{BLACK}Engine ID: {GOLD}{NUM} +CM_STR_PURCHASE_ENGINE_ID :{BLACK}Engine ID: {GOLD}{NUM} {BLACK}ID(GRF): {GOLD}{NUM} CM_STR_SMALLMAP_TOOLTIP_SHOW_IMBA_ON_MAP :{BLACK}Show industries on map combined with land contours and vegetation CM_STR_CONFIG_SETTING_PAUSE_AFTER_LOAD :Pause the game after loading: {STRING2} CM_STR_CONFIG_SETTING_PAUSE_AFTER_LOAD_HELPTEXT :Control whether the game should be paused after load (if it's not already paused). Useful for desync debugging. @@ -6059,3 +6059,5 @@ CM_STR_VIEWPORT_TOWN_TINY_EXCELLENT_RATING :{TINY_FONT}{GRE CM_STR_CARGO_WITH_ID :{STRING} {SILVER}#{NUM} CM_STR_INDUSTRY_TYPE_WITH_ID :{STRING} {SILVER}#{NUM} CM_STR_CONFIG_SETTING_TYPE_DROPDOWN_CITYMANIA :CityMania patchpack settings + +CM_BUILDING_PREVIEW_COST_ENOUGH :Cost \ No newline at end of file diff --git a/src/lang/german.txt b/src/lang/german.txt index 39860a5aac..096b160b08 100644 --- a/src/lang/german.txt +++ b/src/lang/german.txt @@ -5909,7 +5909,7 @@ CM_STR_CONFIG_SETTING_OPEN_VEHICLE_FOR_SHARED_CLONE :Fahrzeugfenster CM_STR_CONFIG_SETTING_OPEN_VEHICLE_FOR_SHARED_CLONE_HELPTEXT :Fahrzeugfenster beim Klonen von Fahrzeugen mit geteilten Aufträgen öffnen (wie es bei den nicht-geteilten der Fall ist) CM_STR_CONFIG_SETTING_OPEN_ORDERS_FOR_NEW_VEHICLES :Auftragsfenster für neue Fahrzeuge öffnen: {STRING} CM_STR_CONFIG_SETTING_OPEN_ORDERS_FOR_NEW_VEHICLES_HELPTEXT :Auftragsfenster automatisch zusammen mit dem Fahrzeugfenster für neue Fahrzeuge öffnen -CM_STR_PURCHASE_ENGINE_ID :{BLACK}Fahrzeug-ID: {GOLD}{NUM} +CM_STR_PURCHASE_ENGINE_ID :{BLACK}Fahrzeug-ID: {GOLD}{NUM} {BLACK}ID(GRF}: {GOLD}{NUM} CM_STR_SMALLMAP_TOOLTIP_SHOW_IMBA_ON_MAP :{BLACK}Industrien zusammen mit Landkonturen und Vegetation auf der Karte anzeigen CM_STR_CONFIG_SETTING_PAUSE_AFTER_LOAD :Spiel nach dem Laden pausieren: {STRING} CM_STR_CONFIG_SETTING_PAUSE_AFTER_LOAD_HELPTEXT :Beeinflusst ob das Spiel nach dem Laden pausiert werden soll (falls es noch nicht pausiert ist). Zum Desync-Debugging nützlich.