|
|
/* $Id$ */
|
|
|
|
|
|
/** @file town_cmd.cpp */
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include "openttd.h"
|
|
|
#include "functions.h"
|
|
|
#include "debug.h"
|
|
|
#include "strings.h"
|
|
|
#include "road_map.h"
|
|
|
#include "table/strings.h"
|
|
|
#include "table/sprites.h"
|
|
|
#include "map.h"
|
|
|
#include "landscape.h"
|
|
|
#include "tile.h"
|
|
|
#include "town_map.h"
|
|
|
#include "tunnel_map.h"
|
|
|
#include "viewport.h"
|
|
|
#include "town.h"
|
|
|
#include "command.h"
|
|
|
#include "gfx.h"
|
|
|
#include "industry.h"
|
|
|
#include "station.h"
|
|
|
#include "vehicle.h"
|
|
|
#include "player.h"
|
|
|
#include "news.h"
|
|
|
#include "saveload.h"
|
|
|
#include "economy.h"
|
|
|
#include "gui.h"
|
|
|
#include "unmovable_map.h"
|
|
|
#include "water_map.h"
|
|
|
#include "variables.h"
|
|
|
#include "bridge.h"
|
|
|
#include "bridge_map.h"
|
|
|
#include "date.h"
|
|
|
#include "table/town_land.h"
|
|
|
#include "genworld.h"
|
|
|
#include "newgrf.h"
|
|
|
#include "newgrf_callbacks.h"
|
|
|
#include "newgrf_house.h"
|
|
|
#include "newgrf_commons.h"
|
|
|
#include "newgrf_townname.h"
|
|
|
#include "misc/autoptr.hpp"
|
|
|
#include "autoslope.h"
|
|
|
|
|
|
/* Initialize the town-pool */
|
|
|
DEFINE_OLD_POOL_GENERIC(Town, Town)
|
|
|
|
|
|
Town::Town(TileIndex tile)
|
|
|
{
|
|
|
if (tile != 0) _total_towns++;
|
|
|
this->xy = tile;
|
|
|
}
|
|
|
|
|
|
Town::~Town()
|
|
|
{
|
|
|
DeleteName(this->townnametype);
|
|
|
|
|
|
if (CleaningPool()) return;
|
|
|
|
|
|
Industry *i;
|
|
|
|
|
|
/* Delete town authority window
|
|
|
* and remove from list of sorted towns */
|
|
|
DeleteWindowById(WC_TOWN_VIEW, this->index);
|
|
|
_town_sort_dirty = true;
|
|
|
_total_towns--;
|
|
|
|
|
|
/* Delete all industries belonging to the town */
|
|
|
FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i;
|
|
|
|
|
|
/* Go through all tiles and delete those belonging to the town */
|
|
|
for (TileIndex tile = 0; tile < MapSize(); ++tile) {
|
|
|
switch (GetTileType(tile)) {
|
|
|
case MP_HOUSE:
|
|
|
if (GetTownByTile(tile) == this) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
|
|
break;
|
|
|
|
|
|
case MP_ROAD:
|
|
|
case MP_TUNNELBRIDGE:
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) &&
|
|
|
ClosestTownFromTile(tile, (uint)-1) == this)
|
|
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
DeleteSubsidyWithTown(this->index);
|
|
|
|
|
@@ -2264,96 +2265,105 @@ bool CheckforTownRating(uint32 flags, To
|
|
|
*/
|
|
|
modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type];
|
|
|
|
|
|
if (t->ratings[_current_player] < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) {
|
|
|
SetDParam(0, t->index);
|
|
|
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
void TownsMonthlyLoop()
|
|
|
{
|
|
|
Town *t;
|
|
|
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
if (t->road_build_months != 0) t->road_build_months--;
|
|
|
|
|
|
if (t->exclusive_counter != 0)
|
|
|
if (--t->exclusive_counter == 0) t->exclusivity = INVALID_PLAYER;
|
|
|
|
|
|
UpdateTownGrowRate(t);
|
|
|
UpdateTownAmounts(t);
|
|
|
UpdateTownUnwanted(t);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void InitializeTowns()
|
|
|
{
|
|
|
Subsidy *s;
|
|
|
|
|
|
/* Clean the town pool and create 1 block in it */
|
|
|
_Town_pool.CleanPool();
|
|
|
_Town_pool.AddBlockToPool();
|
|
|
|
|
|
memset(_subsidies, 0, sizeof(_subsidies));
|
|
|
for (s=_subsidies; s != endof(_subsidies); s++)
|
|
|
s->cargo_type = CT_INVALID;
|
|
|
|
|
|
_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)
|
|
|
{
|
|
|
if (AutoslopeEnabled()) {
|
|
|
HouseID house = GetHouseType(tile);
|
|
|
HouseSpec *hs = GetHouseSpecs(house);
|
|
|
|
|
|
/* Here we differ from TTDP by checking TILE_NOT_SLOPED */
|
|
|
if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) &&
|
|
|
(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return _price.terraform;
|
|
|
}
|
|
|
|
|
|
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
}
|
|
|
|
|
|
extern const TileTypeProcs _tile_type_town_procs = {
|
|
|
DrawTile_Town, /* draw_tile_proc */
|
|
|
GetSlopeZ_Town, /* get_slope_z_proc */
|
|
|
ClearTile_Town, /* clear_tile_proc */
|
|
|
GetAcceptedCargo_Town, /* get_accepted_cargo_proc */
|
|
|
GetTileDesc_Town, /* get_tile_desc_proc */
|
|
|
GetTileTrackStatus_Town, /* get_tile_track_status_proc */
|
|
|
ClickTile_Town, /* click_tile_proc */
|
|
|
AnimateTile_Town, /* animate_tile_proc */
|
|
|
TileLoop_Town, /* tile_loop_clear */
|
|
|
ChangeTileOwner_Town, /* change_tile_owner_clear */
|
|
|
NULL, /* get_produced_cargo_proc */
|
|
|
NULL, /* vehicle_enter_tile_proc */
|
|
|
GetFoundation_Town, /* get_foundation_proc */
|
|
|
TerraformTile_Town, /* terraform_tile_proc */
|
|
|
};
|
|
|
|
|
|
|
|
|
/** Save and load of towns. */
|
|
|
static const SaveLoad _town_desc[] = {
|
|
|
SLE_CONDVAR(Town, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
|
|
|
SLE_CONDVAR(Town, xy, SLE_UINT32, 6, SL_MAX_VERSION),
|
|
|
|
|
|
SLE_CONDVAR(Town, population, SLE_FILE_U16 | SLE_VAR_U32, 0, 2),
|
|
|
SLE_CONDVAR(Town, population, SLE_UINT32, 3, SL_MAX_VERSION),
|
|
|
|
|
|
|
|
|
SLE_VAR(Town, num_houses, SLE_UINT16),
|
|
|
SLE_CONDVAR(Town, townnamegrfid, SLE_UINT32, 66, SL_MAX_VERSION),
|
|
|
SLE_VAR(Town, townnametype, SLE_UINT16),
|
|
|
SLE_VAR(Town, townnameparts, SLE_UINT32),
|
|
|
|
|
|
SLE_VAR(Town, flags12, SLE_UINT8),
|
|
|
SLE_VAR(Town, statues, SLE_UINT8),
|
|
|
|
|
|
/* sort_index_obsolete was stored here in savegame format 0 - 1 */
|
|
|
SLE_CONDNULL(1, 0, 1),
|
|
|
|
|
|
SLE_VAR(Town, have_ratings, SLE_UINT8),
|
|
|
SLE_ARR(Town, ratings, SLE_INT16, 8),
|
|
|
/* failed bribe attempts are stored since savegame format 4 */
|
|
|
SLE_CONDARR(Town, unwanted, SLE_INT8, 8, 4,SL_MAX_VERSION),
|
|
|
|
|
|
SLE_CONDVAR(Town, max_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
|
|
|
SLE_CONDVAR(Town, max_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
|