src/town_cmd.cpp
changeset 9354 845e07db4549
parent 9341 bd60c3b2d1e0
child 9358 2e1e4d2f71dd
equal deleted inserted replaced
9353:9d76aef9fe2b 9354:845e07db4549
   322 	MarkTownSignDirty(t);
   322 	MarkTownSignDirty(t);
   323 	Point pt = RemapCoords2(TileX(t->xy) * TILE_SIZE, TileY(t->xy) * TILE_SIZE);
   323 	Point pt = RemapCoords2(TileX(t->xy) * TILE_SIZE, TileY(t->xy) * TILE_SIZE);
   324 	SetDParam(0, t->index);
   324 	SetDParam(0, t->index);
   325 	SetDParam(1, t->population);
   325 	SetDParam(1, t->population);
   326 	UpdateViewportSignPos(&t->sign, pt.x, pt.y - 24,
   326 	UpdateViewportSignPos(&t->sign, pt.x, pt.y - 24,
   327 		_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL);
   327 		_settings.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL);
   328 	MarkTownSignDirty(t);
   328 	MarkTownSignDirty(t);
   329 }
   329 }
   330 
   330 
   331 /** Update the virtual coords needed to draw the town sign for all towns. */
   331 /** Update the virtual coords needed to draw the town sign for all towns. */
   332 void UpdateAllTownVirtCoords()
   332 void UpdateAllTownVirtCoords()
  1253 static bool GrowTown(Town *t)
  1253 static bool GrowTown(Town *t)
  1254 {
  1254 {
  1255 	/* Let the town be a ghost town
  1255 	/* Let the town be a ghost town
  1256 	 * The player wanted it in such a way. Thus there he has it. ;)
  1256 	 * The player wanted it in such a way. Thus there he has it. ;)
  1257 	 * Never reached in editor mode. */
  1257 	 * Never reached in editor mode. */
  1258 	if (_patches.town_layout == TL_NO_ROADS && _generating_world) {
  1258 	if (_settings.economy.town_layout == TL_NO_ROADS && _generating_world) {
  1259 		return false;
  1259 		return false;
  1260 	}
  1260 	}
  1261 
  1261 
  1262 	static const TileIndexDiffC _town_coord_mod[] = {
  1262 	static const TileIndexDiffC _town_coord_mod[] = {
  1263 		{-1,  0},
  1263 		{-1,  0},
  1483 			x = size * 16 + 3;
  1483 			x = size * 16 + 3;
  1484 			t->larger_town = false;
  1484 			t->larger_town = false;
  1485 			break;
  1485 			break;
  1486 
  1486 
  1487 		case TSM_CITY:
  1487 		case TSM_CITY:
  1488 			x *= _patches.initial_city_size;
  1488 			x *= _settings.economy.initial_city_size;
  1489 			t->larger_town = true;
  1489 			t->larger_town = true;
  1490 			break;
  1490 			break;
  1491 	}
  1491 	}
  1492 
  1492 
  1493 	t->noise_reached = 0;
  1493 	t->noise_reached = 0;
  1584 
  1584 
  1585 bool GenerateTowns()
  1585 bool GenerateTowns()
  1586 {
  1586 {
  1587 	uint num = 0;
  1587 	uint num = 0;
  1588 	uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
  1588 	uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
  1589 	uint num_cities = _patches.larger_towns == 0 ? 0 : n / _patches.larger_towns;
  1589 	uint num_cities = _settings.economy.larger_towns == 0 ? 0 : n / _settings.economy.larger_towns;
  1590 
  1590 
  1591 	SetGeneratingWorldProgress(GWP_TOWN, n);
  1591 	SetGeneratingWorldProgress(GWP_TOWN, n);
  1592 
  1592 
  1593 	do {
  1593 	do {
  1594 		IncreaseGeneratingWorldProgress(GWP_TOWN);
  1594 		IncreaseGeneratingWorldProgress(GWP_TOWN);
  1595 		/* try 20 times to create a random-sized town for the first loop. */
  1595 		/* try 20 times to create a random-sized town for the first loop. */
  1596 		TownSizeMode mode = num_cities > 0 ? TSM_CITY : TSM_RANDOM;
  1596 		TownSizeMode mode = num_cities > 0 ? TSM_CITY : TSM_RANDOM;
  1597 		if (CreateRandomTown(20, mode, _patches.initial_city_size) != NULL) num++;
  1597 		if (CreateRandomTown(20, mode, _settings.economy.initial_city_size) != NULL) num++;
  1598 		if (num_cities > 0) num_cities--;
  1598 		if (num_cities > 0) num_cities--;
  1599 	} while (--n);
  1599 	} while (--n);
  1600 
  1600 
  1601 	/* give it a last try, but now more aggressive */
  1601 	/* give it a last try, but now more aggressive */
  1602 	if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0) == NULL) {
  1602 	if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0) == NULL) {
  2217 }
  2217 }
  2218 
  2218 
  2219 static void TownActionBuyRights(Town *t)
  2219 static void TownActionBuyRights(Town *t)
  2220 {
  2220 {
  2221 	/* Check if it's allowed to by the rights */
  2221 	/* Check if it's allowed to by the rights */
  2222 	if (!_patches.exclusive_rights) return;
  2222 	if (!_settings.economy.exclusive_rights) return;
  2223 
  2223 
  2224 	t->exclusive_counter = 12;
  2224 	t->exclusive_counter = 12;
  2225 	t->exclusivity = _current_player;
  2225 	t->exclusivity = _current_player;
  2226 
  2226 
  2227 	ModifyStationRatingAround(t->xy, _current_player, 130, 17);
  2227 	ModifyStationRatingAround(t->xy, _current_player, 130, 17);
  2331 	for (uint i = 0; i < MAX_PLAYERS; i++) {
  2331 	for (uint i = 0; i < MAX_PLAYERS; i++) {
  2332 		t->ratings[i] = Clamp(t->ratings[i], RATING_MINIMUM, RATING_MAXIMUM);
  2332 		t->ratings[i] = Clamp(t->ratings[i], RATING_MINIMUM, RATING_MAXIMUM);
  2333 	}
  2333 	}
  2334 
  2334 
  2335 	ClrBit(t->flags12, TOWN_IS_FUNDED);
  2335 	ClrBit(t->flags12, TOWN_IS_FUNDED);
  2336 	if (_patches.town_growth_rate == 0 && t->fund_buildings_months == 0) return;
  2336 	if (_settings.economy.town_growth_rate == 0 && t->fund_buildings_months == 0) return;
  2337 
  2337 
  2338 	/** Towns are processed every TOWN_GROWTH_FREQUENCY ticks, and this is the
  2338 	/** Towns are processed every TOWN_GROWTH_FREQUENCY ticks, and this is the
  2339 	 * number of times towns are processed before a new building is built. */
  2339 	 * number of times towns are processed before a new building is built. */
  2340 	static const uint16 _grow_count_values[2][6] = {
  2340 	static const uint16 _grow_count_values[2][6] = {
  2341 		{ 120, 120, 120, 100,  80,  60 }, // Fund new buildings has been activated
  2341 		{ 120, 120, 120, 100,  80,  60 }, // Fund new buildings has been activated
  2360 			return;
  2360 			return;
  2361 	}
  2361 	}
  2362 
  2362 
  2363 	/* Use the normal growth rate values if new buildings have been funded in
  2363 	/* Use the normal growth rate values if new buildings have been funded in
  2364 	 * this town and the growth rate is set to none. */
  2364 	 * this town and the growth rate is set to none. */
  2365 	uint growth_multiplier = _patches.town_growth_rate != 0 ? _patches.town_growth_rate - 1 : 1;
  2365 	uint growth_multiplier = _settings.economy.town_growth_rate != 0 ? _settings.economy.town_growth_rate - 1 : 1;
  2366 
  2366 
  2367 	m >>= growth_multiplier;
  2367 	m >>= growth_multiplier;
  2368 	if (t->larger_town) m /= 2;
  2368 	if (t->larger_town) m /= 2;
  2369 
  2369 
  2370 	t->growth_rate = m / (t->num_houses / 50 + 1);
  2370 	t->growth_rate = m / (t->num_houses / 50 + 1);
  2403 
  2403 
  2404 bool CheckIfAuthorityAllows(TileIndex tile)
  2404 bool CheckIfAuthorityAllows(TileIndex tile)
  2405 {
  2405 {
  2406 	if (!IsValidPlayer(_current_player)) return true;
  2406 	if (!IsValidPlayer(_current_player)) return true;
  2407 
  2407 
  2408 	Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
  2408 	Town *t = ClosestTownFromTile(tile, _settings.economy.dist_local_authority);
  2409 	if (t == NULL) return true;
  2409 	if (t == NULL) return true;
  2410 
  2410 
  2411 	if (t->ratings[_current_player] > RATING_VERYPOOR) return true;
  2411 	if (t->ratings[_current_player] > RATING_VERYPOOR) return true;
  2412 
  2412 
  2413 	_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
  2413 	_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;