* Actually create a town. * * @param t The town. * @param tile Where to put it. * @param townnameparts The town name. * @param size The preset size of the town. * @param city Should we create a city? * @param layout The road layout of the town. * @param manual Was the town placed manually? */
| 2034 | * @param manual Was the town placed manually? |
| 2035 | */ |
| 2036 | static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSize size, bool city, TownLayout layout, bool manual) |
| 2037 | { |
| 2038 | AutoRestoreBackup backup(_generating_town, true); |
| 2039 | |
| 2040 | t->xy = tile; |
| 2041 | t->cache.num_houses = 0; |
| 2042 | t->time_until_rebuild = 10; |
| 2043 | UpdateTownRadius(t); |
| 2044 | t->flags.Reset(); |
| 2045 | t->cache.population = 0; |
| 2046 | InitializeBuildingCounts(t); |
| 2047 | /* Spread growth across ticks so even if there are many |
| 2048 | * similar towns they're unlikely to grow all in one tick */ |
| 2049 | t->grow_counter = t->index % Ticks::TOWN_GROWTH_TICKS; |
| 2050 | t->growth_rate = TownTicksToGameTicks(250); |
| 2051 | t->show_zone = false; |
| 2052 | |
| 2053 | _town_kdtree.Insert(t->index); |
| 2054 | |
| 2055 | /* Set the default cargo requirement for town growth */ |
| 2056 | switch (_settings_game.game_creation.landscape) { |
| 2057 | case LandscapeType::Arctic: |
| 2058 | if (FindFirstCargoWithTownAcceptanceEffect(TAE_FOOD) != nullptr) t->goal[TAE_FOOD] = TOWN_GROWTH_WINTER; |
| 2059 | break; |
| 2060 | |
| 2061 | case LandscapeType::Tropic: |
| 2062 | if (FindFirstCargoWithTownAcceptanceEffect(TAE_FOOD) != nullptr) t->goal[TAE_FOOD] = TOWN_GROWTH_DESERT; |
| 2063 | if (FindFirstCargoWithTownAcceptanceEffect(TAE_WATER) != nullptr) t->goal[TAE_WATER] = TOWN_GROWTH_DESERT; |
| 2064 | break; |
| 2065 | |
| 2066 | default: |
| 2067 | break; |
| 2068 | } |
| 2069 | |
| 2070 | t->fund_buildings_months = 0; |
| 2071 | |
| 2072 | for (uint i = 0; i != MAX_COMPANIES; i++) t->ratings[i] = RATING_INITIAL; |
| 2073 | |
| 2074 | t->have_ratings = {}; |
| 2075 | t->exclusivity = CompanyID::Invalid(); |
| 2076 | t->exclusive_counter = 0; |
| 2077 | t->statues = {}; |
| 2078 | |
| 2079 | { |
| 2080 | TownNameParams tnp(_settings_game.game_creation.town_name); |
| 2081 | t->townnamegrfid = tnp.grfid; |
| 2082 | t->townnametype = tnp.type; |
| 2083 | } |
| 2084 | t->townnameparts = townnameparts; |
| 2085 | |
| 2086 | t->InitializeLayout(layout); |
| 2087 | |
| 2088 | t->larger_town = city; |
| 2089 | |
| 2090 | int x = (int)size * 16 + 3; |
| 2091 | if (size == TSZ_RANDOM) x = (Random() & 0xF) + 8; |
| 2092 | /* Don't create huge cities when founding town in-game */ |
| 2093 | if (city && (!manual || _game_mode == GM_EDITOR)) x *= _settings_game.economy.initial_city_size; |
no test coverage detected