Changeset - r7390:444ff4a56f72
[Not reviewed]
master
0 6 0
rubidium - 17 years ago 2007-08-02 23:21:52
rubidium@openttd.org
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
6 files changed with 43 insertions and 84 deletions:
0 comments (0 inline, 0 general)
src/ai/default/default.cpp
Show inline comments
 
@@ -453,25 +453,25 @@ struct FoundRoute {
 
	void *from;
 
	void *to;
 
};
 

	
 
static Town *AiFindRandomTown()
 
{
 
	return GetRandomTown();
 
}
 

	
 
static Industry *AiFindRandomIndustry()
 
{
 
	int num = RandomRange(GetMaxIndustryIndex());
 
	if (IsValidIndustry(GetIndustry(num))) return GetIndustry(num);
 
	if (IsValidIndustryID(num)) return GetIndustry(num);
 

	
 
	return NULL;
 
}
 

	
 
static void AiFindSubsidyIndustryRoute(FoundRoute *fr)
 
{
 
	uint i;
 
	CargoID cargo;
 
	const Subsidy* s;
 
	Industry* from;
 
	TileIndex to_xy;
 

	
src/industry.h
Show inline comments
 
@@ -77,55 +77,61 @@ enum IndustyBehaviour {
 
	INDUSTRYBEH_DONT_INCR_PROD        = 1 << 7,  ///< do not increase production (oil wells) in the temperate climate
 
	INDUSTRYBEH_BEFORE_1950           = 1 << 8,  ///< can only be built before 1950 (oil wells)
 
	INDUSTRYBEH_AFTER_1960            = 1 << 9,  ///< can only be built after 1960 (oil rigs)
 
	INDUSTRYBEH_AI_AIRSHIP_ROUTES     = 1 << 10, ///< ai will attempt to establish air/ship routes to this industry (oil rig)
 
	INDUSTRYBEH_AIRPLANE_ATTACKS      = 1 << 11, ///< can be exploded by a military airplane (oil refinery)
 
	INDUSTRYBEH_CHOPPER_ATTACKS       = 1 << 12, ///< can be exploded by a military helicopter (factory)
 
	INDUSTRYBEH_CAN_SUBSIDENCE        = 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
 
};
 

	
 

	
 
DECLARE_ENUM_AS_BIT_SET(IndustyBehaviour);
 

	
 
struct Industry;
 
DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
 

	
 
/**
 
 * Defines the internal data of a functionnal industry
 
 */
 
struct Industry {
 
struct Industry : PoolItem<Industry, IndustryID, &_Industry_pool> {
 
	TileIndex xy;                       ///< coordinates of the primary tile the industry is built one
 
	byte width;
 
	byte height;
 
	const Town *town;                   ///< Nearest town
 
	uint16 produced_cargo_waiting[2];   ///< amount of cargo produced per cargo
 
	uint16 incoming_cargo_waiting[3];   ///< incoming cargo waiting to be processed
 
	byte production_rate[2];            ///< production rate for each cargo
 
	byte prod_level;                    ///< general production level
 
	uint16 this_month_production[2];    ///< stats of this month's production per cargo
 
	uint16 this_month_transported[2];   ///< stats of this month's transport per cargo
 
	byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
 
	uint16 last_month_production[2];    ///< total units produced per cargo in the last full month
 
	uint16 last_month_transported[2];   ///< total units transported per cargo in the last full month
 
	uint16 counter;                     ///< used for animation and/or production (if available cargo)
 

	
 
	IndustryType type;                  ///< type of industry.
 
	OwnerByte owner;                    ///< owner of the industry.  Which SHOULD always be (imho) OWNER_NONE
 
	byte random_color;                  ///< randomized colour of the industry, for display purpose
 
	Year last_prod_year;                ///< last year of production
 
	byte was_cargo_delivered;           ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
 

	
 
	IndustryID index;                   ///< index of the industry in the pool of industries
 

	
 
	OwnerByte founder;                  ///< Founder of the industry
 
	Date construction_date;             ///< Date of the construction of the industry
 
	uint8 construction_type;            ///< Way the industry was constructed (@see IndustryConstructionType)
 
	Date last_cargo_accepted_at;        ///< Last day cargo was accepted by this industry
 

	
 
	Industry(TileIndex tile = 0) : xy(tile) {}
 
	~Industry();
 

	
 
	bool IsValid() const { return this->xy != 0; }
 
};
 

	
 
struct IndustryTileTable {
 
	TileIndexDiffC ti;
 
	IndustryGfx gfx;
 
};
 

	
 
/** Data related to the handling of grf files.  Common to both industry and industry tile */
 
struct GRFFileProps {
 
	uint8 subst_id;
 
	uint16 local_id;                      ///< id defined by the grf file for this industry
 
	struct SpriteGroup *spritegroup;      ///< pointer to the different sprites of the industry
 
@@ -207,44 +213,32 @@ struct IndustryTileSpec {
 
const IndustrySpec *GetIndustrySpec(IndustryType thistype);    ///< Array of industries data
 
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx, bool full_check = true);  ///< Array of industry tiles data
 
void ResetIndustries();
 
void PlantRandomFarmField(const Industry *i);
 

	
 
/* writable arrays of specs */
 
extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
 
extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
 

	
 
/* smallmap_gui.cpp */
 
void BuildIndustriesLegend();
 

	
 
DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
 

	
 
/**
 
 * Check if an Industry really exists.
 
 * @param industry to check
 
 * @return true if position is a valid one
 
 */
 
static inline bool IsValidIndustry(const Industry *industry)
 
{
 
	return industry->xy != 0;
 
}
 

	
 
/**
 
 * Check if an Industry exists whithin the pool of industries
 
 * @param index of the desired industry
 
 * @return true if it is inside the pool
 
 */
 
static inline bool IsValidIndustryID(IndustryID index)
 
{
 
	return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index));
 
	return index < GetIndustryPoolSize() && GetIndustry(index)->IsValid();
 
}
 

	
 

	
 
static inline IndustryID GetMaxIndustryIndex()
 
{
 
	/* TODO - This isn't the real content of the function, but
 
	 *  with the new pool-system this will be replaced with one that
 
	 *  _really_ returns the highest index. Now it just returns
 
	 *  the next safe value we are sure about everything is below.
 
	 */
 
	return GetIndustryPoolSize() - 1;
 
}
 
@@ -309,29 +303,21 @@ static inline Industry *GetRandomIndustr
 
		index++;
 

	
 
		/* Make sure we have a valid industry */
 
		while (!IsValidIndustryID(index)) {
 
			index++;
 
			assert(index <= GetMaxIndustryIndex());
 
		}
 
	}
 

	
 
	return GetIndustry(index);
 
}
 

	
 
void DestroyIndustry(Industry *i);
 

	
 
static inline void DeleteIndustry(Industry *i)
 
{
 
	DestroyIndustry(i);
 
	i->xy = 0;
 
}
 

	
 
#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (IsValidIndustry(i))
 
#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (i->IsValid())
 
#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
 

	
 
extern const Industry **_industry_sort;
 
extern bool _industry_sort_dirty;
 

	
 
static const uint8 IT_INVALID = 255;
 

	
 
#endif /* INDUSTRY_H */
src/industry_cmd.cpp
Show inline comments
 
@@ -26,24 +26,25 @@
 
#include "variables.h"
 
#include "table/industry_land.h"
 
#include "table/build_industry.h"
 
#include "genworld.h"
 
#include "date.h"
 
#include "water_map.h"
 
#include "tree_map.h"
 
#include "cargotype.h"
 
#include "newgrf_commons.h"
 
#include "newgrf_industries.h"
 
#include "newgrf_industrytiles.h"
 
#include "newgrf_callbacks.h"
 
#include "misc/autoptr.hpp"
 

	
 
void ShowIndustryViewWindow(int industry);
 
void BuildOilRig(TileIndex tile);
 

	
 
static byte _industry_sound_ctr;
 
static TileIndex _industry_sound_tile;
 

	
 
int _total_industries;                      //general counter
 
uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
 

	
 
const Industry **_industry_sort;
 
bool _industry_sort_dirty;
 
@@ -66,52 +67,40 @@ void ResetIndustries()
 
	}
 

	
 
	memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs));
 
	memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs));
 
}
 

	
 
void ResetIndustryCreationProbility(IndustryType type)
 
{
 
	assert(type < INVALID_INDUSTRYTYPE);
 
	_industry_specs[type].appear_creation[_opt.landscape] = 0;
 
}
 

	
 
/**
 
 * Called if a new block is added to the industry-pool
 
 */
 
static void IndustryPoolNewBlock(uint start_item)
 
{
 
	Industry *i;
 

	
 
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
 
	 * TODO - This is just a temporary stage, this will be removed. */
 
	for (i = GetIndustry(start_item); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) i->index = start_item++;
 
}
 

	
 
DEFINE_OLD_POOL(Industry, Industry, IndustryPoolNewBlock, NULL)
 
DEFINE_OLD_POOL_GENERIC(Industry, Industry)
 

	
 
/**
 
 * Retrieve the type for this industry.  Although it is accessed by a tile,
 
 * it will return the general type of industry, and not the sprite index
 
 * as would do GetIndustryGfx.
 
 * @param tile that is queried
 
 * @pre IsTileType(tile, MP_INDUSTRY)
 
 * @return general type for this industry, as defined in industry.h
 
 **/
 
IndustryType GetIndustryType(TileIndex tile)
 
{
 
	assert(IsTileType(tile, MP_INDUSTRY));
 

	
 
	const Industry *ind = GetIndustryByTile(tile);
 
	return IsValidIndustry(ind) ? ind->type : (IndustryType)IT_INVALID;
 
	return ind->IsValid() ? ind->type : (IndustryType)IT_INVALID;
 
}
 

	
 
/**
 
 * Accessor for array _industry_specs.
 
 * This will ensure at once : proper access and
 
 * not allowing modifications of it.
 
 * @param thistype of industry (which is the index in _industry_specs)
 
 * @pre thistype < NUM_INDUSTRYTYPES
 
 * @return a pointer to the corresponding industry spec
 
 **/
 
const IndustrySpec *GetIndustrySpec(IndustryType thistype)
 
{
 
@@ -130,53 +119,61 @@ const IndustrySpec *GetIndustrySpec(Indu
 
 * @return a pointer to the corresponding industrytile spec
 
 **/
 
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx, bool full_check)
 
{
 
	assert(gfx < INVALID_INDUSTRYTILE);
 
	const IndustryTileSpec *its = &_industry_tile_specs[gfx];
 
	if (full_check && its->grf_prop.override != INVALID_INDUSTRYTILE) {
 
		its = &_industry_tile_specs[its->grf_prop.override];
 
	}
 
	return its;
 
}
 

	
 
void DestroyIndustry(Industry *i)
 
Industry::~Industry()
 
{
 
	BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
 
	/* Industry can also be destroyed when not fully initialized.
 
	 * This means that we do not have to clear tiles either. */
 
	if (this->width == 0) {
 
		this->xy = 0;
 
		return;
 
	}
 

	
 
	BEGIN_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
 
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
 
			if (GetIndustryIndex(tile_cur) == i->index) {
 
			if (GetIndustryIndex(tile_cur) == this->index) {
 
				DoClearSquare(tile_cur);
 
			}
 
		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 
			DeleteOilRig(tile_cur);
 
		}
 
	END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
 
	END_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
 

	
 
	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
 
	if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
 
		/* Remove the farmland and convert it to regular tiles over time. */
 
		BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) {
 
		BEGIN_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiffXY(21, 21)) {
 
			tile_cur = TILE_MASK(tile_cur);
 
			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
 
					GetIndustryIndexOfField(tile_cur) == i->index) {
 
					GetIndustryIndexOfField(tile_cur) == this->index) {
 
				SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
 
			}
 
		} END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21))
 
		} END_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiff(21, 21))
 
	}
 

	
 
	_industry_sort_dirty = true;
 
	DecIndustryTypeCount(i->type);
 
	DecIndustryTypeCount(this->type);
 

	
 
	DeleteSubsidyWithIndustry(i->index);
 
	DeleteWindowById(WC_INDUSTRY_VIEW, i->index);
 
	DeleteSubsidyWithIndustry(this->index);
 
	DeleteWindowById(WC_INDUSTRY_VIEW, this->index);
 
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
 
	this->xy = 0;
 
}
 

	
 
static void IndustryDrawSugarMine(const TileInfo *ti)
 
{
 
	const DrawIndustryAnimationStruct *d;
 

	
 
	if (!IsIndustryCompleted(ti->tile)) return;
 

	
 
	d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)];
 

	
 
	AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0);
 

	
 
@@ -384,25 +381,25 @@ static CommandCost ClearTile_Industry(Ti
 
	/* water can destroy industries
 
	 * in editor you can bulldoze industries
 
	 * with magic_bulldozer cheat you can destroy industries
 
	 * (area around OILRIG is water, so water shouldn't flood it
 
	 */
 
	if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR &&
 
			!_cheats.magic_bulldozer.value) ||
 
			(_current_player == OWNER_WATER && (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER))) {
 
		SetDParam(0, indspec->name);
 
		return_cmd_error(STR_4800_IN_THE_WAY);
 
	}
 

	
 
	if (flags & DC_EXEC) DeleteIndustry(i);
 
	if (flags & DC_EXEC) delete i;
 
	return CommandCost();
 
}
 

	
 
static void TransportIndustryGoods(TileIndex tile)
 
{
 
	Industry *i = GetIndustryByTile(tile);
 
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
 
	uint cw, am;
 

	
 
	cw = min(i->produced_cargo_waiting[0], 255);
 
	if (cw > indspec->minimal_cargo/* && i->produced_cargo[0] != 0xFF*/) {
 
		i->produced_cargo_waiting[0] -= cw;
 
@@ -1388,45 +1385,24 @@ static bool CheckIfTooCloseToIndustry(Ti
 
		}
 

	
 
		/* check "not close to" field. */
 
		if ((i->type == indspec->conflicting[0] || i->type == indspec->conflicting[1] || i->type == indspec->conflicting[2]) &&
 
				DistanceMax(tile, i->xy) <= 14) {
 
			_error_message = STR_INDUSTRY_TOO_CLOSE;
 
			return false;
 
		}
 
	}
 
	return true;
 
}
 

	
 
static Industry *AllocateIndustry()
 
{
 
	Industry *i;
 

	
 
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
 
	 * TODO - This is just a temporary stage, this will be removed. */
 
	for (i = GetIndustry(0); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) {
 
		IndustryID index = i->index;
 

	
 
		if (IsValidIndustry(i)) continue;
 

	
 
		memset(i, 0, sizeof(*i));
 
		i->index = index;
 

	
 
		return i;
 
	}
 

	
 
	/* Check if we can add a block to the pool */
 
	return AddBlockToPool(&_Industry_pool) ? AllocateIndustry() : NULL;
 
}
 

	
 
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, Owner owner)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(type);
 
	uint32 r;
 
	int j;
 

	
 
	i->xy = tile;
 
	i->width = i->height = 0;
 
	i->type = type;
 
	IncIndustryTypeCount(type);
 

	
 
	i->production_rate[0] = indspec->production_rate[0];
 
@@ -1521,30 +1497,32 @@ static Industry *CreateNewIndustryHelper
 
		if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
 
	}
 

	
 
	if (!custom_shape_check && _patches.land_generator == LG_TERRAGENESIS && _generating_world && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
 
	if (!CheckIfTooCloseToIndustry(tile, type)) return NULL;
 

	
 
	const Town *t = CheckMultipleIndustryInTown(tile, type);
 
	if (t == NULL) return NULL;
 

	
 
	if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
 
	if (!CheckSuitableIndustryPos(tile)) return NULL;
 

	
 
	Industry *i = AllocateIndustry();
 
	Industry *i = new Industry(tile);
 
	if (i == NULL) return NULL;
 
	AutoPtrT<Industry> i_auto_delete = i;
 

	
 
	if (flags & DC_EXEC) {
 
		if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type);
 
		DoCreateNewIndustry(i, tile, type, it, t, OWNER_NONE);
 
		i_auto_delete.Detach();
 
	}
 

	
 
	return i;
 
}
 

	
 
/** Build/Fund an industry
 
 * @param tile tile where industry is built
 
 * @param flags of operations to conduct
 
 * @param p1 industry type see build_industry.h and see industry.h
 
 * @param p2 unused
 
 * @return index of the newly create industry, or CMD_ERROR if it failed
 
 */
 
@@ -1799,25 +1777,25 @@ static void UpdateIndustryStatistics(Ind
 
			i->this_month_production[j] = 0;
 

	
 
			i->last_month_transported[j] = i->this_month_transported[j];
 
			i->this_month_transported[j] = 0;
 
			refresh = true;
 
		}
 
	}
 

	
 
	if (refresh)
 
		InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
 

	
 
	if (i->prod_level == 0) {
 
		DeleteIndustry(i);
 
		delete i;
 
	} else if (_patches.smooth_economy) {
 
		ExtChangeIndustryProduction(i);
 
	}
 
}
 

	
 
/** Simple helper that will collect data for the generation of industries */
 
struct ProbabilityHelper {
 
	uint16 prob;      ///< probability
 
	IndustryType ind; ///< industry id correcponding
 
};
 

	
 
/**
 
@@ -2084,30 +2062,25 @@ static void Save_TIDS()
 
		SlSetArrayIndex(i);
 
		SlObject(&_industile_mngr.mapping_ID[i], _industries_id_mapping_desc);
 
	}
 
}
 

	
 
static void Load_INDY()
 
{
 
	int index;
 

	
 
	ResetIndustryCounts();
 

	
 
	while ((index = SlIterateArray()) != -1) {
 
		Industry *i;
 

	
 
		if (!AddBlockIfNeeded(&_Industry_pool, index))
 
			error("Industries: failed loading savegame: too many industries");
 

	
 
		i = GetIndustry(index);
 
		Industry *i = new (index) Industry();
 
		SlObject(i, _industry_desc);
 
		IncIndustryTypeCount(i->type);
 
	}
 
}
 

	
 
static void Load_IIDS()
 
{
 
	int index;
 
	uint max_id;
 

	
 
	/* clear the current mapping stored.
 
	 * This will create the manager if ever it is not yet done */
src/oldloader.cpp
Show inline comments
 
@@ -706,25 +706,25 @@ static const OldChunks industry_chunk[] 
 
};
 

	
 
static bool LoadOldIndustry(LoadgameState *ls, int num)
 
{
 
	Industry *i;
 

	
 
	if (!AddBlockIfNeeded(&_Industry_pool, num))
 
		error("Industries: failed loading savegame: too many industries");
 

	
 
	i = GetIndustry(num);
 
	if (!LoadChunk(ls, i, industry_chunk)) return false;
 

	
 
	if (IsValidIndustry(i)) {
 
	if (i->IsValid()) {
 
		i->town = GetTown(REMAP_TOWN_IDX(_old_town_index));
 
	}
 

	
 
	return true;
 
}
 

	
 
static PlayerID _current_player_id;
 
static int32 _old_yearly;
 

	
 
static const OldChunks player_yearly_chunk[] = {
 
	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
 
	OCL_END()
src/strings.cpp
Show inline comments
 
@@ -647,25 +647,25 @@ static char* FormatString(char* buff, co
 
			}
 

	
 
			case SCC_STATION_FEATURES: { /* {STATIONFEATURES} */
 
				buff = StationGetSpecialString(buff, GetInt32(&argv), last);
 
				break;
 
			}
 

	
 
			case SCC_INDUSTRY_NAME: { /* {INDUSTRY} */
 
				const Industry* i = GetIndustry(GetInt32(&argv));
 
				int64 args[2];
 

	
 
				/* industry not valid anymore? */
 
				if (!IsValidIndustry(i)) break;
 
				if (!i->IsValid()) break;
 

	
 
				/* First print the town name and the industry type name
 
				 * The string STR_INDUSTRY_PATTERN controls the formatting */
 
				args[0] = i->town->index;
 
				args[1] = GetIndustrySpec(i->type)->name;
 
				buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24, last);
 
				modifier = 0;
 
				break;
 
			}
 

	
 
			case SCC_VOLUME: { // {VOLUME}
 
				int64 args[1];
src/town_cmd.cpp
Show inline comments
 
@@ -52,25 +52,25 @@ Town::Town(TileIndex tile)
 

	
 
Town::~Town()
 
{
 
	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) DeleteIndustry(i);
 
	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)
0 comments (0 inline, 0 general)