From f81537df1e637c804f6e20935b03029208e8f263 Mon Sep 17 00:00:00 2001 From: Pavel Stupnikov Date: Wed, 5 Feb 2020 02:56:24 +0300 Subject: [PATCH] Cache advertisement zoning and use tinting for them as well --- src/citymania/zoning.cpp | 32 ++++++++++++++++++++++++++++++++ src/rev.cpp | 2 +- src/zoning_cmd.cpp | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/citymania/zoning.cpp b/src/citymania/zoning.cpp index dba6c355fd..57dcd87288 100644 --- a/src/citymania/zoning.cpp +++ b/src/citymania/zoning.cpp @@ -24,6 +24,7 @@ namespace citymania { struct TileZoning { uint8 town_zone : 3; uint8 industry_fund_result : 2; + uint8 advertisement_zone : 2; IndustryType industry_fund_type; }; @@ -169,6 +170,19 @@ TileHighlight GetTileHighlight(const TileInfo *ti) { } else if (_zoning.outer == CHECKINDUNSER) { auto pal = GetIndustryZoningPalette(ti->tile); if (pal) th.ground_pal = th.structure_pal = PALETTE_TINT_RED_DEEP; + } else if (_zoning.outer == CHECKTOWNADZONES) { + auto getter = [](TileIndex t) { return _mz[t].advertisement_zone; }; + auto b = CalcTileBorders(ti->tile, getter); + if (b.first != ZoningBorder::NONE) { + th.border = b.first; + const SpriteID pal[] = {PAL_NONE, SPR_PALETTE_ZONING_YELLOW, SPR_PALETTE_ZONING_ORANGE, SPR_PALETTE_ZONING_RED}; + th.border_color = pal[b.second]; + } + auto z = getter(ti->tile); + if (z) { + const SpriteID pal[] = {PAL_NONE, PALETTE_TINT_YELLOW, PALETTE_TINT_ORANGE, PALETTE_TINT_RED}; + th.ground_pal = th.structure_pal = pal[b.second]; + } } if (_settings_client.gui.show_industry_forbidden_tiles && @@ -270,11 +284,29 @@ void UpdateTownZoning(Town *town, uint32 prev_edge) { } } +void UpdateAdvertisementZoning(TileIndex center, uint radius, uint8 zone) { + uint16 x1, y1, x2, y2; + x1 = (uint16)max(0, TileX(center) - radius); + x2 = (uint16)min(TileX(center) + radius + 1, MapSizeX()); + y1 = (uint16)max(0, TileY(center) - radius); + y2 = (uint16)min(TileY(center) + radius + 1, MapSizeY()); + for (uint16 y = y1; y < y2; y++) { + for (uint16 x = x1; x < x2; x++) { + auto tile = TileXY(x, y); + _mz[tile].advertisement_zone = max(_mz[tile].advertisement_zone, zone); + } + } +} + void InitializeZoningMap() { for (Town *t : Town::Iterate()) { UpdateTownZoning(t, 0); + UpdateAdvertisementZoning(t->xy, 10, 3); + UpdateAdvertisementZoning(t->xy, 15, 2); + UpdateAdvertisementZoning(t->xy, 20, 1); } } + std::pair GetTownZoneBorder(TileIndex tile) { return CalcTileBorders(tile, [](TileIndex t) { return _mz[t].town_zone; }); } diff --git a/src/rev.cpp b/src/rev.cpp index 7872b64cb3..7017208da0 100644 --- a/src/rev.cpp +++ b/src/rev.cpp @@ -83,4 +83,4 @@ const byte _openttd_revision_tagged = 1; const uint32 _openttd_newgrf_version = 1 << 28 | 10 << 24 | 0 << 20 | 0 << 19 | 28004; -const char _citymania_version[] = "20200205-master-mabbc38728e 05.02.20"; +const char _citymania_version[] = "20200205-master-m830f265f55 05.02.20"; diff --git a/src/zoning_cmd.cpp b/src/zoning_cmd.cpp index 43c827dbb4..1812805a84 100644 --- a/src/zoning_cmd.cpp +++ b/src/zoning_cmd.cpp @@ -425,6 +425,7 @@ void DrawTileZoning(const TileInfo *ti) { if (_zoning.outer == CHECKTOWNZONES || _zoning.outer == CHECKBULUNSER || _zoning.outer == CHECKINDUNSER || + _zoning.outer == CHECKTOWNADZONES || _zoning.outer == CHECKSTACATCH || _zoning.outer == CHECKTOWNGROWTHTILES) { // handled by citymania zoning