--- a/src/town_cmd.cpp Tue May 27 00:50:55 2008 +0000
+++ b/src/town_cmd.cpp Tue Jun 17 10:32:49 2008 +0000
@@ -55,10 +55,6 @@
uint _total_towns;
HouseSpec _house_specs[HOUSE_MAX];
-bool _town_sort_dirty;
-byte _town_sort_order;
-const Town **_town_sort;
-
Town *_cleared_town;
int _cleared_town_rating;
@@ -82,7 +78,7 @@
/* Delete town authority window
* and remove from list of sorted towns */
DeleteWindowById(WC_TOWN_VIEW, this->index);
- _town_sort_dirty = true;
+ InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0);
_total_towns--;
/* Delete all industries belonging to the town */
@@ -131,6 +127,11 @@
}
}
+Money HouseSpec::GetRemovalCost() const
+{
+ return (_price.remove_house * this->removal_cost) >> 8;
+}
+
// Local
static int _grow_town_result;
@@ -324,7 +325,7 @@
SetDParam(0, t->index);
SetDParam(1, t->population);
UpdateViewportSignPos(&t->sign, pt.x, pt.y - 24,
- _settings.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL);
+ _settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL);
MarkTownSignDirty(t);
}
@@ -348,7 +349,7 @@
InvalidateWindow(WC_TOWN_VIEW, t->index);
UpdateTownVirtCoord(t);
- if (_town_sort_order & 2) _town_sort_dirty = true;
+ InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
}
/**
@@ -521,7 +522,7 @@
const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
CommandCost cost(EXPENSES_CONSTRUCTION);
- cost.AddCost(_price.remove_house * hs->removal_cost >> 8);
+ cost.AddCost(hs->GetRemovalCost());
int rating = hs->remove_rating_decrease;
_cleared_town_rating += rating;
@@ -596,7 +597,7 @@
if (callback != CALLBACK_FAILED) {
if (accepts[0] != CT_INVALID) ac[accepts[0]] = GB(callback, 0, 4);
if (accepts[1] != CT_INVALID) ac[accepts[1]] = GB(callback, 4, 4);
- if (_settings.game_creation.landscape != LT_TEMPERATE && HasBit(callback, 12)) {
+ if (_settings_game.game_creation.landscape != LT_TEMPERATE && HasBit(callback, 12)) {
/* The 'S' bit indicates food instead of goods */
ac[CT_FOOD] = GB(callback, 8, 4);
} else {
@@ -1255,7 +1256,7 @@
/* Let the town be a ghost town
* The player wanted it in such a way. Thus there he has it. ;)
* Never reached in editor mode. */
- if (_settings.economy.town_layout == TL_NO_ROADS && _generating_world) {
+ if (_settings_game.economy.town_layout == TL_NO_ROADS && _generating_world) {
return false;
}
@@ -1367,9 +1368,9 @@
* the other towns may take considerable amount of time (10000 is
* too much). */
int tries = 1000;
- bool grf = (_settings.game_creation.town_name >= _nb_orig_names);
- uint32 grfid = grf ? GetGRFTownNameId(_settings.game_creation.town_name - _nb_orig_names) : 0;
- uint16 townnametype = grf ? GetGRFTownNameType(_settings.game_creation.town_name - _nb_orig_names) : SPECSTR_TOWNNAME_START + _settings.game_creation.town_name;
+ bool grf = (_settings_game.game_creation.town_name >= _nb_orig_names);
+ uint32 grfid = grf ? GetGRFTownNameId(_settings_game.game_creation.town_name - _nb_orig_names) : 0;
+ uint16 townnametype = grf ? GetGRFTownNameType(_settings_game.game_creation.town_name - _nb_orig_names) : SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
assert(townnameparts != NULL);
@@ -1453,19 +1454,19 @@
t->exclusive_counter = 0;
t->statues = 0;
- if (_settings.game_creation.town_name < _nb_orig_names) {
+ if (_settings_game.game_creation.town_name < _nb_orig_names) {
/* Original town name */
t->townnamegrfid = 0;
- t->townnametype = SPECSTR_TOWNNAME_START + _settings.game_creation.town_name;
+ t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
} else {
/* Newgrf town name */
- t->townnamegrfid = GetGRFTownNameId(_settings.game_creation.town_name - _nb_orig_names);
- t->townnametype = GetGRFTownNameType(_settings.game_creation.town_name - _nb_orig_names);
+ t->townnamegrfid = GetGRFTownNameId(_settings_game.game_creation.town_name - _nb_orig_names);
+ t->townnametype = GetGRFTownNameType(_settings_game.game_creation.town_name - _nb_orig_names);
}
t->townnameparts = townnameparts;
UpdateTownVirtCoord(t);
- _town_sort_dirty = true;
+ InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0);
t->InitializeLayout();
@@ -1485,7 +1486,7 @@
break;
case TSM_CITY:
- x *= _settings.economy.initial_city_size;
+ x *= _settings_game.economy.initial_city_size;
t->larger_town = true;
break;
}
@@ -1585,8 +1586,8 @@
bool GenerateTowns()
{
uint num = 0;
- uint n = ScaleByMapSize(_num_initial_towns[_settings.difficulty.number_towns] + (Random() & 7));
- uint num_cities = _settings.economy.larger_towns == 0 ? 0 : n / _settings.economy.larger_towns;
+ uint n = ScaleByMapSize(_num_initial_towns[_settings_game.difficulty.number_towns] + (Random() & 7));
+ uint num_cities = _settings_game.economy.larger_towns == 0 ? 0 : n / _settings_game.economy.larger_towns;
SetGeneratingWorldProgress(GWP_TOWN, n);
@@ -1594,7 +1595,7 @@
IncreaseGeneratingWorldProgress(GWP_TOWN);
/* try 20 times to create a random-sized town for the first loop. */
TownSizeMode mode = num_cities > 0 ? TSM_CITY : TSM_RANDOM;
- if (CreateRandomTown(20, mode, _settings.economy.initial_city_size) != NULL) num++;
+ if (CreateRandomTown(20, mode, _settings_game.economy.initial_city_size) != NULL) num++;
if (num_cities > 0) num_cities--;
} while (--n);
@@ -1602,7 +1603,7 @@
if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0) == NULL) {
if (GetNumTowns() == 0) {
/* XXX - can we handle that more gracefully? */
- if (_game_mode != GM_EDITOR) error("Could not generate any town");
+ if (_game_mode != GM_EDITOR) usererror("Could not generate any town");
return false;
}
@@ -1643,11 +1644,7 @@
*/
static inline void ClearMakeHouseTile(TileIndex tile, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
{
- #if !defined(NDEBUG) || defined(WITH_ASSERT)
- CommandCost cc =
- #endif /* !defined(NDEBUG) || defined(WITH_ASSERT) */
-
- DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
+ CommandCost cc = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
assert(CmdSucceeded(cc));
@@ -1879,8 +1876,8 @@
HouseZonesBits rad = GetTownRadiusGroup(t, tile);
/* Above snow? */
- int land = _settings.game_creation.landscape;
- if (land == LT_ARCTIC && z >= _settings.game_creation.snow_line) land = -1;
+ int land = _settings_game.game_creation.landscape;
+ if (land == LT_ARCTIC && z >= _settings_game.game_creation.snow_line) land = -1;
uint bitmask = (1 << rad) + (1 << (land + 12));
@@ -1939,7 +1936,7 @@
}
}
- if (_cur_year < hs->min_date || _cur_year > hs->max_date) continue;
+ if (_cur_year < hs->min_year || _cur_year > hs->max_year) continue;
/* Special houses that there can be only one of. */
uint oneof = 0;
@@ -2099,7 +2096,7 @@
t->name = strdup(_cmd_text);
UpdateTownVirtCoord(t);
- _town_sort_dirty = true;
+ InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
UpdateAllStationVirtCoord();
UpdateAllWaypointSigns();
MarkWholeScreenDirty();
@@ -2201,7 +2198,7 @@
{
TileIndex tile = t->xy;
- if (CircularTileSearch(tile, 9, SearchTileForStatue, t->index)) {
+ if (CircularTileSearch(&tile, 9, SearchTileForStatue, t->index)) {
SetBit(t->statues, _current_player); // Once found and built, "inform" the Town
}
}
@@ -2219,7 +2216,7 @@
static void TownActionBuyRights(Town *t)
{
/* Check if it's allowed to by the rights */
- if (!_settings.economy.exclusive_rights) return;
+ if (!_settings_game.economy.exclusive_rights) return;
t->exclusive_counter = 12;
t->exclusivity = _current_player;
@@ -2251,6 +2248,7 @@
*/
if (t->ratings[_current_player] > RATING_BRIBE_DOWN_TO) {
t->ratings[_current_player] = RATING_BRIBE_DOWN_TO;
+ InvalidateWindow(WC_TOWN_AUTHORITY, t->index);
}
} else {
ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM);
@@ -2332,8 +2330,10 @@
t->ratings[i] = Clamp(t->ratings[i], RATING_MINIMUM, RATING_MAXIMUM);
}
+ InvalidateWindow(WC_TOWN_AUTHORITY, t->index);
+
ClrBit(t->flags12, TOWN_IS_FUNDED);
- if (_settings.economy.town_growth_rate == 0 && t->fund_buildings_months == 0) return;
+ if (_settings_game.economy.town_growth_rate == 0 && t->fund_buildings_months == 0) return;
/** Towns are processed every TOWN_GROWTH_FREQUENCY ticks, and this is the
* number of times towns are processed before a new building is built. */
@@ -2352,17 +2352,17 @@
if (n == 0 && !Chance16(1, 12)) return;
}
- if (_settings.game_creation.landscape == LT_ARCTIC) {
+ if (_settings_game.game_creation.landscape == LT_ARCTIC) {
if (TilePixelHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90)
return;
- } else if (_settings.game_creation.landscape == LT_TROPIC) {
+ } else if (_settings_game.game_creation.landscape == LT_TROPIC) {
if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food == 0 || t->act_water == 0) && t->population > 60)
return;
}
/* Use the normal growth rate values if new buildings have been funded in
* this town and the growth rate is set to none. */
- uint growth_multiplier = _settings.economy.town_growth_rate != 0 ? _settings.economy.town_growth_rate - 1 : 1;
+ uint growth_multiplier = _settings_game.economy.town_growth_rate != 0 ? _settings_game.economy.town_growth_rate - 1 : 1;
m >>= growth_multiplier;
if (t->larger_town) m /= 2;
@@ -2405,7 +2405,7 @@
{
if (!IsValidPlayer(_current_player)) return true;
- Town *t = ClosestTownFromTile(tile, _settings.economy.dist_local_authority);
+ Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
if (t == NULL) return true;
if (t->ratings[_current_player] > RATING_VERYPOOR) return true;
@@ -2503,6 +2503,7 @@
_town_test_ratings[t] = rating;
} else {
t->ratings[_current_player] = rating;
+ InvalidateWindow(WC_TOWN_AUTHORITY, t->index);
}
}
@@ -2524,7 +2525,7 @@
* owned by a town no removal if rating is lower than ... depends now on
* difficulty setting. Minimum town rating selected by difficulty level
*/
- int modemod = _default_rating_settings[_settings.difficulty.town_council_tolerance][type];
+ int modemod = _default_rating_settings[_settings_game.difficulty.town_council_tolerance][type];
if (GetRating(t) < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) {
SetDParam(0, t->index);
@@ -2565,7 +2566,6 @@
_cur_town_ctr = 0;
_cur_town_iter = 0;
_total_towns = 0;
- _town_sort_dirty = true;
}
static CommandCost TerraformTile_Town(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
@@ -2736,8 +2736,6 @@
void AfterLoadTown()
{
- _town_sort_dirty = true;
-
Town *t;
FOR_ALL_TOWNS(t) t->InitializeLayout();
}