diff --git a/cm_changelog.txt b/cm_changelog.txt index b2b5839a9e..f54dc7a141 100644 --- a/cm_changelog.txt +++ b/cm_changelog.txt @@ -76,7 +76,8 @@ This is usable for any OpenTTD servers *** next - Add new minimap mode showing industries, height and farms at the same time. -- Rename "CB town border" zone to "CB cargo acceptance", switch it to new colored highlight and fix for new CB mode. +- Rename "CB town border" zone to "CB cargo acceptance", switch it to a new colored highlight and fix for new CB mode. +- Rename "New CB borders" zone to "CB town limit" and switch it to a new colored highlight. Remove old "CB borders" zone. - Show engine id in build window in newgrf developer mode. *** 1.10.1 (15 Apr 2020) *** diff --git a/src/citymania/highlight.cpp b/src/citymania/highlight.cpp index d934eb620c..d372760454 100644 --- a/src/citymania/highlight.cpp +++ b/src/citymania/highlight.cpp @@ -14,6 +14,8 @@ #include "../viewport_func.h" #include "../zoning.h" +#include + #include "station_ui.hpp" @@ -46,6 +48,7 @@ extern const Station *_station_to_join; extern const Station *_highlight_station_to_join; extern TileArea _highlight_join_area; +std::set, std::greater > > _town_cache; // struct { // int w; // int h; @@ -208,7 +211,7 @@ std::pair CalcCBAcceptanceBorders(TileIndex tile) { (uint16)min(ty + radius + 1, MapSizeY()), [tx, ty, radius, &in_zone, &border] (TownID tid) { Town *town = Town::GetIfValid(tid); - if (!town) + if (!town || town->larger_town) return; int dx = TileX(town->xy) - tx; @@ -223,6 +226,45 @@ std::pair CalcCBAcceptanceBorders(TileIndex tile) { return std::make_pair(border, in_zone); } + +void AddTownCBLimitBorder(TileIndex tile, const Town *town, ZoningBorder &border, bool &in_zone) { + auto sq = town->cache.squared_town_zone_radius[0] + 30; + auto x = CalcTileBorders(tile, [town, sq] (TileIndex tile) { + return DistanceSquare(tile, town->xy) <= sq ? 1 : 0; + }); + border |= x.first; + in_zone = in_zone || x.second; +} + +std::pair CalcCBTownLimitBorder(TileIndex tile) { + auto n = Town::GetNumItems(); + uint32 sq = 0; + uint i = 0; + ZoningBorder border = ZoningBorder::NONE; + bool in_zone = false; + for (auto &p : _town_cache) { + sq = p.second->cache.squared_town_zone_radius[0] + 30; + if (4 * sq * n < MapSize() * i) break; + AddTownCBLimitBorder(tile, p.second, border, in_zone); + i++; + } + uint radius = IntSqrt(sq); + int tx = TileX(tile), ty = TileY(tile); + _town_kdtree.FindContained( + (uint16)max(0, tx - radius), + (uint16)max(0, ty - radius), + (uint16)min(tx + radius + 1, MapSizeX()), + (uint16)min(ty + radius + 1, MapSizeY()), + [tile, &in_zone, &border] (TownID tid) { + Town *town = Town::GetIfValid(tid); + if (!town || town->larger_town) + return; + AddTownCBLimitBorder(tile, town, border, in_zone); + } + ); + return std::make_pair(border, in_zone); +} + TileHighlight GetTileHighlight(const TileInfo *ti) { TileHighlight th; if (ti->tile == INVALID_TILE) return th; @@ -299,6 +341,12 @@ TileHighlight GetTileHighlight(const TileInfo *ti) { th.add_border(b.first, SPR_PALETTE_ZONING_WHITE); if (b.second) th.ground_pal = th.structure_pal = PALETTE_TINT_WHITE; + } else if (_zoning.outer == CHECKCBTOWNLIMIT) { + auto b = CalcCBTownLimitBorder(ti->tile); + if (b.first) + th.add_border(b.first, SPR_PALETTE_ZONING_WHITE); + if (b.second) + th.ground_pal = th.structure_pal = PALETTE_TINT_WHITE; } else if (_zoning.outer == CHECKACTIVESTATIONS) { auto getter = [](TileIndex t) { if (!IsTileType (t, MP_STATION)) return 0; @@ -428,13 +476,23 @@ void UpdateAdvertisementZoning(TileIndex center, uint radius, uint8 zone) { } } +void UpdateZoningTownHouses(const Town *town, uint32 old_houses) { + if (!town->larger_town) + return; + _town_cache.erase(std::make_pair(old_houses, town)); + _town_cache.insert(std::make_pair(town->cache.num_houses, town)); +} void InitializeZoningMap() { + _town_cache.clear(); for (Town *t : Town::Iterate()) { UpdateTownZoning(t, 0); UpdateAdvertisementZoning(t->xy, 10, 3); UpdateAdvertisementZoning(t->xy, 15, 2); UpdateAdvertisementZoning(t->xy, 20, 1); + UpdateZoningTownHouses(t, 0); + if (!t->larger_town) + _town_cache.insert(std::make_pair(t->cache.num_houses, t)); } } diff --git a/src/citymania/highlight.hpp b/src/citymania/highlight.hpp index 2d5f50e1b7..c36781e417 100644 --- a/src/citymania/highlight.hpp +++ b/src/citymania/highlight.hpp @@ -65,6 +65,7 @@ void AllocateZoningMap(uint map_size); void InitializeZoningMap(); void UpdateTownZoning(Town *town, uint32 prev_edge); +void UpdateZoningTownHouses(const Town *town, uint32 old_houses); std::pair GetTownZoneBorder(TileIndex tile); ZoningBorder GetAnyStationCatchmentBorder(TileIndex tlie); diff --git a/src/citymania/station_ui.cpp b/src/citymania/station_ui.cpp index 523e471f59..c8ef463f44 100644 --- a/src/citymania/station_ui.cpp +++ b/src/citymania/station_ui.cpp @@ -50,8 +50,6 @@ const Station *_station_to_join = nullptr; const Station *_highlight_station_to_join = nullptr; TileArea _highlight_join_area; -void CheckRedrawStationCoverage(); - // void SetStationTileSelectSize(int w, int h, int catchment) { // _station_select.w = w; // _station_select.h = h; diff --git a/src/lang/english.txt b/src/lang/english.txt index b0cbf0e568..20577fe87f 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -5260,8 +5260,7 @@ STR_ZONING_BUL_UNSER :{BLACK}Unserved STR_ZONING_IND_UNSER :{BLACK}Unserved industries STR_ZONING_TOWN_ZONES :{BLACK}Town zones STR_ZONING_CB_ACCEPTANCE :{BLACK}CB cargo acceptance -STR_ZONING_CB_BORDERS :{BLACK}CB borders -STR_ZONING_NEW_CB_BORDERS :{BLACK}New CB borders +STR_ZONING_CB_TOWN_LIMIT :{BLACK}CB town limit STR_ZONING_ADVERTISEMENT_ZONES :{BLACK}Advertisement STR_ZONING_TOWN_GROWTH_TILES :{BLACK}Town growth tiles STR_ZONING_ACTIVE_STATIONS :{BLACK}Active stations diff --git a/src/rev.cpp b/src/rev.cpp index b6a45578fc..f915434ee6 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 | 1 << 19 | 28004; -const char _citymania_version[] = "20200518-master-m81787f93a5 18.05.20"; +const char _citymania_version[] = "20200519-master-m7275346033 19.05.20"; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 202904ae8e..e506c9b6f5 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -469,9 +469,8 @@ void ClearAllTownCachedNames() */ static void ChangePopulation(Town *t, int mod) { - // if(mod > 0 && t->houses_construction > 0) t->houses_construction--; - t->cache.population += mod; + InvalidateWindowData(WC_TOWN_VIEW, t->index); // Cargo requirements may appear/vanish for small populations if (_settings_client.gui.population_in_label) t->UpdateVirtCoord(); @@ -2896,6 +2895,8 @@ static bool BuildTownHouse(Town *t, TileIndex tile) } } + citymania::UpdateZoningTownHouses(t, t->cache.num_houses - 1); + MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits); UpdateTownGrowthTile(tile, TGTS_NEW_HOUSE); UpdateTownRadius(t); @@ -2987,6 +2988,7 @@ void ClearTownHouse(Town *t, TileIndex tile) if (eflags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(1, 1), t, ++house); UpdateTownRadius(t); + citymania::UpdateZoningTownHouses(t, t->cache.num_houses + 1); /* Update cargo acceptance. */ UpdateTownCargoes(t, tile); diff --git a/src/zoning.h b/src/zoning.h index 6c5acdf4b4..a7ecd4327e 100644 --- a/src/zoning.h +++ b/src/zoning.h @@ -14,9 +14,8 @@ enum EvaluationMode { CHECKBULUNSER, ///< Check for unserved buildings CHECKINDUNSER, ///< Check for unserved industries CHECKTOWNZONES, ///< Town zones (Tz*) - CHECKCBBORDERS, ///< Citybuilder cargo acceptment zone - CHECKNEWCBBORDERS, ///< Citybuilder cargo acceptment zone CHECKCBACCEPTANCE, ///< Citybuilder cargo acceptance zone + CHECKCBTOWNLIMIT, ///< Citybuilder cargo acceptment zone CHECKTOWNADZONES, ///< Town advertisement zone CHECKTOWNGROWTHTILES, ///< Town growth tiles (new house, skipped/removed house) }; diff --git a/src/zoning_cmd.cpp b/src/zoning_cmd.cpp index 7003eeb284..d6bf05c868 100644 --- a/src/zoning_cmd.cpp +++ b/src/zoning_cmd.cpp @@ -360,9 +360,8 @@ SpriteID TileZoningSpriteEvaluation(TileIndex tile, Owner owner, EvaluationMode case CHECKBULUNSER: return TileZoneCheckUnservedBuildingsEvaluation(tile); case CHECKINDUNSER: return TileZoneCheckUnservedIndustriesEvaluation(tile); case CHECKTOWNZONES: return TileZoneCheckTownZones(tile); - case CHECKCBBORDERS: return TileZoneCheckCBBorders(tile); - case CHECKNEWCBBORDERS: return TileZoneCheckNewCBBorders(tile); case CHECKCBACCEPTANCE: return TileZoneCheckCBBorders(tile); + case CHECKCBTOWNLIMIT: return TileZoneCheckNewCBBorders(tile); case CHECKTOWNADZONES: return TileZoneCheckTownAdvertisementZones(tile); case CHECKTOWNGROWTHTILES: return TileZoneCheckTownsGrowthTiles(tile); case CHECKACTIVESTATIONS: return TileZoneCheckActiveStations(tile); @@ -425,6 +424,7 @@ void DrawTileZoning(const TileInfo *ti) { _zoning.outer == CHECKTOWNADZONES || _zoning.outer == CHECKSTACATCH || _zoning.outer == CHECKCBACCEPTANCE || + _zoning.outer == CHECKCBTOWNLIMIT || _zoning.outer == CHECKACTIVESTATIONS || _zoning.outer == CHECKTOWNGROWTHTILES) { // handled by citymania zoning diff --git a/src/zoning_gui.cpp b/src/zoning_gui.cpp index 05f89ae896..c73ba1e9ae 100644 --- a/src/zoning_gui.cpp +++ b/src/zoning_gui.cpp @@ -17,14 +17,13 @@ const StringID _zone_types[] = { STR_ZONING_BUL_UNSER, STR_ZONING_IND_UNSER, STR_ZONING_TOWN_ZONES, - STR_ZONING_CB_BORDERS, - STR_ZONING_NEW_CB_BORDERS, STR_ZONING_CB_ACCEPTANCE, + STR_ZONING_CB_TOWN_LIMIT, STR_ZONING_ADVERTISEMENT_ZONES, STR_ZONING_TOWN_GROWTH_TILES, }; -const int ZONES_COUNT = 12; +const int ZONES_COUNT = 11; enum ZoningToolbarWidgets { ZTW_CAPTION, @@ -141,8 +140,8 @@ static Hotkey zoning_hotkeys[] = { Hotkey(WKC_SHIFT | '4', "unserved_buildings", ZTW_OUTER_FIRST + CHECKBULUNSER), Hotkey(WKC_SHIFT | '5', "unserved_industries", ZTW_OUTER_FIRST + CHECKINDUNSER), Hotkey(WKC_SHIFT | '6', "town_zone", ZTW_OUTER_FIRST + CHECKTOWNZONES), - Hotkey(WKC_SHIFT | '7', "CB_acceptance", ZTW_OUTER_FIRST + CHECKCBACCEPTANCE), - Hotkey(WKC_SHIFT | '8', "CB_build_borders", ZTW_OUTER_FIRST + CHECKCBACCEPTANCE), + Hotkey(WKC_SHIFT | '7', "cb_acceptance", ZTW_OUTER_FIRST + CHECKCBACCEPTANCE), + Hotkey(WKC_SHIFT | '8', "cb_town_limit", ZTW_OUTER_FIRST + CHECKCBTOWNLIMIT), Hotkey(WKC_SHIFT | '9', "advertisement", ZTW_OUTER_FIRST + CHECKTOWNADZONES), Hotkey(WKC_SHIFT | '0', "growth_tiles", ZTW_OUTER_FIRST + CHECKTOWNGROWTHTILES), Hotkey((uint16)0, "active_stations", ZTW_OUTER_FIRST + CHECKACTIVESTATIONS),