Changeset - r12239:4ede50b8e95b
[Not reviewed]
master
0 15 2
smatz - 15 years ago 2009-06-26 13:44:14
smatz@openttd.org
(svn r16664) -Codechange: move house-related stuff from town.h and town_type.h to separate files
17 files changed with 184 insertions and 138 deletions:
0 comments (0 inline, 0 general)
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -1019,96 +1019,104 @@
 
				RelativePath=".\..\src\gamelog.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gamelog_internal.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\genworld.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gfx_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gfx_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gfxinit.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\group.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\group_gui.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\group_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gui.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\heightmap.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\highscore.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\house.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\house_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\industry.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\industry_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ini_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\landscape.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\landscape_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\livery.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\lzoconf.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\map_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\map_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\md5.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\minilzo.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\mixer.h"
 
				>
 
			</File>
 
			<File
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -1016,96 +1016,104 @@
 
				RelativePath=".\..\src\gamelog.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gamelog_internal.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\genworld.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gfx_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gfx_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gfxinit.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\group.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\group_gui.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\group_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\gui.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\heightmap.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\highscore.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\house.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\house_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\industry.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\industry_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ini_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\landscape.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\landscape_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\livery.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\lzoconf.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\map_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\map_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\md5.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\minilzo.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\mixer.h"
 
				>
 
			</File>
 
			<File
source.list
Show inline comments
 
@@ -149,96 +149,98 @@ command_type.h
 
company_base.h
 
company_func.h
 
company_gui.h
 
company_manager_face.h
 
company_type.h
 
console_func.h
 
console_gui.h
 
console_internal.h
 
console_type.h
 
currency.h
 
date_func.h
 
date_type.h
 
debug.h
 
video/dedicated_v.h
 
depot_base.h
 
depot_func.h
 
depot_map.h
 
depot_type.h
 
direction_func.h
 
direction_type.h
 
music/dmusic.h
 
driver.h
 
economy_func.h
 
economy_type.h
 
effectvehicle_base.h
 
effectvehicle_func.h
 
elrail_func.h
 
engine_base.h
 
engine_func.h
 
engine_gui.h
 
engine_type.h
 
fileio_func.h
 
fileio_type.h
 
fios.h
 
fontcache.h
 
functions.h
 
gamelog.h
 
gamelog_internal.h
 
genworld.h
 
gfx_func.h
 
gfx_type.h
 
gfxinit.h
 
group.h
 
group_gui.h
 
group_type.h
 
gui.h
 
heightmap.h
 
highscore.h
 
house.h
 
house_type.h
 
industry.h
 
industry_type.h
 
ini_type.h
 
landscape.h
 
landscape_type.h
 
livery.h
 
lzoconf.h
 
map_func.h
 
map_type.h
 
md5.h
 
minilzo.h
 
mixer.h
 
music.h
 
namegen_func.h
 
network/network.h
 
network/network_base.h
 
network/network_client.h
 
network/network_content.h
 
network/network_func.h
 
network/network_gamelist.h
 
network/network_gui.h
 
network/network_internal.h
 
network/network_server.h
 
network/network_type.h
 
network/network_udp.h
 
newgrf.h
 
newgrf_callbacks.h
 
newgrf_canal.h
 
newgrf_cargo.h
 
newgrf_commons.h
 
newgrf_config.h
 
newgrf_engine.h
 
newgrf_generic.h
 
newgrf_house.h
 
newgrf_industries.h
 
newgrf_industrytiles.h
 
newgrf_sound.h
 
newgrf_spritegroup.h
 
newgrf_station.h
 
newgrf_storage.h
 
newgrf_text.h
 
newgrf_town.h
 
newgrf_townname.h
 
news_func.h
 
news_gui.h
 
news_type.h
 
npf.h
 
music/null_m.h
src/house.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file house.h definition of HouseSpec and accessors */
 

	
 
#ifndef HOUSE_H
 
#define HOUSE_H
 

	
 
#include "strings_type.h"
 
#include "cargo_type.h"
 
#include "economy_type.h"
 
#include "date_type.h"
 
#include "house_type.h"
 

	
 
/** Simple value that indicates the house has reached the final stage of
 
 * construction. */
 
static const byte TOWN_HOUSE_COMPLETED = 3;
 

	
 
enum {
 
	HOUSE_NO_CLASS   = 0,
 
	NEW_HOUSE_OFFSET = 110,
 
	HOUSE_MAX        = 512,
 
	INVALID_HOUSE_ID = 0xFFFF,
 

	
 
	/* There can only be as many classes as there are new houses, plus one for
 
	 * NO_CLASS, as the original houses don't have classes. */
 
	HOUSE_CLASS_MAX  = HOUSE_MAX - NEW_HOUSE_OFFSET + 1,
 
};
 

	
 
enum BuildingFlags {
 
	TILE_NO_FLAG         =       0,
 
	TILE_SIZE_1x1        = 1U << 0,
 
	TILE_NOT_SLOPED      = 1U << 1,
 
	TILE_SIZE_2x1        = 1U << 2,
 
	TILE_SIZE_1x2        = 1U << 3,
 
	TILE_SIZE_2x2        = 1U << 4,
 
	BUILDING_IS_ANIMATED = 1U << 5,
 
	BUILDING_IS_CHURCH   = 1U << 6,
 
	BUILDING_IS_STADIUM  = 1U << 7,
 
	BUILDING_HAS_1_TILE  = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
 
	BUILDING_HAS_2_TILES = TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
 
	BUILDING_2_TILES_X   = TILE_SIZE_2x1 | TILE_SIZE_2x2,
 
	BUILDING_2_TILES_Y   = TILE_SIZE_1x2 | TILE_SIZE_2x2,
 
	BUILDING_HAS_4_TILES = TILE_SIZE_2x2,
 
};
 
DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
 

	
 
enum HouseZonesBits {
 
	HZB_BEGIN     = 0,
 
	HZB_TOWN_EDGE = 0,
 
	HZB_TOWN_OUTSKIRT,
 
	HZB_TOWN_OUTER_SUBURB,
 
	HZB_TOWN_INNER_SUBURB,
 
	HZB_TOWN_CENTRE,
 
	HZB_END,
 
};
 
assert_compile(HZB_END == 5);
 

	
 
DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
 

	
 
enum HouseZones {                  ///< Bit  Value       Meaning
 
	HZ_NOZNS             = 0x0000,  ///<       0          This is just to get rid of zeros, meaning none
 
	HZ_ZON1              = 1U << HZB_TOWN_EDGE,    ///< 0..4 1,2,4,8,10  which town zones the building can be built in, Zone1 been the further suburb
 
	HZ_ZON2              = 1U << HZB_TOWN_OUTSKIRT,
 
	HZ_ZON3              = 1U << HZB_TOWN_OUTER_SUBURB,
 
	HZ_ZON4              = 1U << HZB_TOWN_INNER_SUBURB,
 
	HZ_ZON5              = 1U << HZB_TOWN_CENTRE,  ///<  center of town
 
	HZ_ZONALL            = 0x001F,  ///<       1F         This is just to englobe all above types at once
 
	HZ_SUBARTC_ABOVE     = 0x0800,  ///< 11    800        can appear in sub-arctic climate above the snow line
 
	HZ_TEMP              = 0x1000,  ///< 12   1000        can appear in temperate climate
 
	HZ_SUBARTC_BELOW     = 0x2000,  ///< 13   2000        can appear in sub-arctic climate below the snow line
 
	HZ_SUBTROPIC         = 0x4000,  ///< 14   4000        can appear in subtropical climate
 
	HZ_TOYLND            = 0x8000   ///< 15   8000        can appear in toyland climate
 
};
 
DECLARE_ENUM_AS_BIT_SET(HouseZones)
 

	
 
enum HouseExtraFlags {
 
	NO_EXTRA_FLAG            =       0,
 
	BUILDING_IS_HISTORICAL   = 1U << 0,  ///< this house will only appear during town generation in random games, thus the historical
 
	BUILDING_IS_PROTECTED    = 1U << 1,  ///< towns and AI will not remove this house, while human players will be able to
 
	SYNCHRONISED_CALLBACK_1B = 1U << 2,  ///< synchronized callback 1B will be performed, on multi tile houses
 
	CALLBACK_1A_RANDOM_BITS  = 1U << 3,  ///< callback 1A needs random bits
 
};
 

	
 
DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
 

	
 
struct HouseSpec {
 
	/* Standard properties */
 
	Year min_year;                     ///< introduction year of the house
 
	Year max_year;                     ///< last year it can be built
 
	byte population;                   ///< population (Zero on other tiles in multi tile house.)
 
	byte removal_cost;                 ///< cost multiplier for removing it
 
	StringID building_name;            ///< building name
 
	uint16 remove_rating_decrease;     ///< rating decrease if removed
 
	byte mail_generation;              ///< mail generation multiplier (tile based, as the acceptances below)
 
	byte cargo_acceptance[3];          ///< acceptance level for the cargo slots
 
	CargoID accepts_cargo[3];          ///< 3 input cargo slots
 
	BuildingFlags building_flags;      ///< some flags that describe the house (size, stadium etc...)
 
	HouseZones building_availability;  ///< where can it be built (climates, zones)
 
	bool enabled;                      ///< the house is available to build (true by default, but can be disabled by newgrf)
 

	
 
	/* NewHouses properties */
 
	HouseID substitute_id;             ///< which original house this one is based on
 
	struct SpriteGroup *spritegroup;   ///< pointer to the different sprites of the house
 
	HouseID override;                  ///< which house this one replaces
 
	uint16 callback_mask;              ///< House callback flags
 
	byte random_colour[4];             ///< 4 "random" colours
 
	byte probability;                  ///< Relative probability of appearing (16 is the standard value)
 
	HouseExtraFlags extra_flags;       ///< some more flags
 
	HouseClassID class_id;             ///< defines the class this house has (grf file based) @See HouseGetVariable, prop 0x44
 
	byte animation_frames;             ///< number of animation frames
 
	byte animation_speed;              ///< amount of time between each of those frames
 
	byte processing_time;              ///< Periodic refresh multiplier
 
	byte minimum_life;                 ///< The minimum number of years this house will survive before the town rebuilds it
 

	
 
	/* grf file related properties*/
 
	uint8 local_id;                    ///< id defined by the grf file for this house
 
	const struct GRFFile *grffile;     ///< grf file that introduced this house
 

	
 
	/**
 
	 * Get the cost for removing this house
 
	 * @return the cost (inflation corrected etc)
 
	 */
 
	Money GetRemovalCost() const;
 

	
 
};
 

	
 
extern HouseSpec _house_specs[];
 

	
 
static inline HouseSpec *GetHouseSpecs(HouseID house_id)
 
{
 
	assert(house_id < HOUSE_MAX);
 
	return &_house_specs[house_id];
 
}
 

	
 
#endif /* HOUSE_H */
src/house_type.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file house_type.h declaration of basic house types and enums */
 

	
 
#ifndef HOUSE_TYPE_H
 
#define HOUSE_TYPE_H
 

	
 
typedef uint16 HouseID;
 
typedef uint16 HouseClassID;
 

	
 
struct HouseSpec;
 

	
 
#endif /* HOUSE_TYPE_H */
src/newgrf.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file newgrf.h Base for the NewGRF implementation. */
 

	
 
#ifndef NEWGRF_H
 
#define NEWGRF_H
 

	
 
#include "town_type.h"
 
#include "newgrf_config.h"
 
#include "cargotype.h"
 
#include "industry_type.h"
 
#include "station_type.h"
 
#include "rail_type.h"
 
#include "house_type.h"
 

	
 
enum GrfLoadingStage {
 
	GLS_FILESCAN,
 
	GLS_SAFETYSCAN,
 
	GLS_LABELSCAN,
 
	GLS_INIT,
 
	GLS_RESERVE,
 
	GLS_ACTIVATION,
 
	GLS_END,
 
};
 

	
 
DECLARE_POSTFIX_INCREMENT(GrfLoadingStage);
 

	
 
enum GrfMiscBit {
 
	GMB_DESERT_TREES_FIELDS    = 0, // Unsupported.
 
	GMB_DESERT_PAVED_ROADS     = 1,
 
	GMB_FIELD_BOUNDING_BOX     = 2, // Unsupported.
 
	GMB_TRAIN_WIDTH_32_PIXELS  = 3,
 
	GMB_AMBIENT_SOUND_CALLBACK = 4, // Unsupported.
 
	GMB_CATENARY_ON_3RD_TRACK  = 5, // Unsupported.
 
};
 

	
 
enum GrfSpecFeature {
 
	GSF_TRAIN,
 
	GSF_ROAD,
 
	GSF_SHIP,
 
	GSF_AIRCRAFT,
 
	GSF_STATION,
 
	GSF_CANAL,
 
	GSF_BRIDGE,
 
	GSF_TOWNHOUSE,
 
	GSF_GLOBALVAR,
 
	GSF_INDUSTRYTILES,
 
	GSF_INDUSTRIES,
 
	GSF_CARGOS,
 
	GSF_SOUNDFX,
 
	GSF_END,
 
};
 

	
 
static const uint32 INVALID_GRFID = 0xFFFFFFFF;
 

	
 
struct GRFLabel {
 
	byte label;
 
	uint32 nfo_line;
 
	size_t pos;
 
	struct GRFLabel *next;
 
};
 

	
src/newgrf_house.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file newgrf_house.cpp Implementation of NewGRF houses. */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "variables.h"
 
#include "debug.h"
 
#include "viewport_func.h"
 
#include "landscape.h"
 
#include "town_map.h"
 
#include "sprite.h"
 
#include "newgrf.h"
 
#include "newgrf_house.h"
 
#include "newgrf_spritegroup.h"
 
#include "newgrf_town.h"
 
#include "newgrf_sound.h"
 
#include "newgrf_commons.h"
 
#include "transparency.h"
 
#include "functions.h"
 
#include "company_func.h"
 
#include "animated_tile_func.h"
 
#include "company_base.h"
 
#include "town.h"
 

	
 
static BuildingCounts<uint32> _building_counts;
 
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
 

	
 
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID);
 

	
 
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
 
{
 
	/* Start from 1 because 0 means that no class has been assigned. */
 
	for (int i = 1; i != lengthof(_class_mapping); i++) {
 
		HouseClassMapping *map = &_class_mapping[i];
 

	
 
		if (map->class_id == grf_class_id && map->grfid == grfid) return (HouseClassID)i;
 

	
 
		if (map->class_id == 0 && map->grfid == 0) {
 
			map->class_id = grf_class_id;
 
			map->grfid    = grfid;
 
			return (HouseClassID)i;
 
		}
 
	}
 
	return HOUSE_NO_CLASS;
 
}
 

	
 
void InitializeBuildingCounts()
 
{
 
	memset(&_building_counts, 0, sizeof(_building_counts));
 
}
 

	
 
/**
 
 * IncreaseBuildingCount()
 
 * Increase the count of a building when it has been added by a town.
 
 * @param t The town that the building is being built in
 
 * @param house_id The id of the house being added
 
 */
 
void IncreaseBuildingCount(Town *t, HouseID house_id)
 
{
 
	HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
 

	
 
	if (!_loaded_newgrf_features.has_newhouses) return;
 

	
 
	t->building_counts.id_count[house_id]++;
 
	_building_counts.id_count[house_id]++;
 

	
 
	if (class_id == HOUSE_NO_CLASS) return;
 

	
 
	t->building_counts.class_count[class_id]++;
 
	_building_counts.class_count[class_id]++;
 
}
src/newgrf_house.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file newgrf_house.h Functions related to NewGRF houses. */
 

	
 
#ifndef NEWGRF_HOUSE_H
 
#define NEWGRF_HOUSE_H
 

	
 
#include "town_type.h"
 
#include "newgrf_callbacks.h"
 
#include "tile_cmd.h"
 
#include "house_type.h"
 

	
 
/**
 
 * Makes class IDs unique to each GRF file.
 
 * Houses can be assigned class IDs which are only comparable within the GRF
 
 * file they were defined in. This mapping ensures that if two houses have the
 
 * same class as defined by the GRF file, the classes are different within the
 
 * game. An array of HouseClassMapping structs is created, and the array index
 
 * of the struct that matches both the GRF ID and the class ID is the class ID
 
 * used in the game.
 
 *
 
 * Although similar to the HouseIDMapping struct above, this serves a different
 
 * purpose. Since the class ID is not saved anywhere, this mapping does not
 
 * need to be persistent; it just needs to keep class ids unique.
 
 */
 
struct HouseClassMapping {
 
	uint32 grfid;     ////< The GRF ID of the file this class belongs to
 
	uint8  class_id;  ////< The class id within the grf file
 
};
 

	
 
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid);
 

	
 
void InitializeBuildingCounts();
 
void IncreaseBuildingCount(Town *t, HouseID house_id);
 
void DecreaseBuildingCount(Town *t, HouseID house_id);
 

	
 
void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
 
void AnimateNewHouseTile(TileIndex tile);
 
void ChangeHouseAnimationFrame(const struct GRFFile *file, TileIndex tile, uint16 callback_result);
 

	
 
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile);
 

	
 
bool CanDeleteHouse(TileIndex tile);
 

	
 
bool NewHouseTileLoop(TileIndex tile);
 

	
 
enum HouseTrigger {
 
	/* The tile of the house has been triggered during the tileloop. */
 
	HOUSE_TRIGGER_TILE_LOOP     = 0x01,
 
	/*
 
	 * The top tile of a (multitile) building has been triggered during and all
 
	 * the tileloop other tiles of the same building get the same random value.
 
	 */
 
	HOUSE_TRIGGER_TILE_LOOP_TOP = 0x02,
 
};
 
void TriggerHouse(TileIndex t, HouseTrigger trigger);
 

	
 
#endif /* NEWGRF_HOUSE_H */
src/newgrf_spritegroup.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file newgrf_spritegroup.h Action 2 handling. */
 

	
 
#ifndef NEWGRF_SPRITEGROUP_H
 
#define NEWGRF_SPRITEGROUP_H
 

	
 
#include "town_type.h"
 
#include "industry_type.h"
 
#include "core/bitmath_func.hpp"
 
#include "gfx_type.h"
 
#include "engine_type.h"
 
#include "tile_type.h"
 
#include "core/pool_type.hpp"
 
#include "house_type.h"
 

	
 
#include "newgrf_cargo.h"
 
#include "newgrf_callbacks.h"
 
#include "newgrf_generic.h"
 
#include "newgrf_storage.h"
 

	
 
/**
 
 * Gets the value of a so-called newgrf "register".
 
 * @param i index of the register
 
 * @pre i < 0x110
 
 * @return the value of the register
 
 */
 
static inline uint32 GetRegister(uint i)
 
{
 
	extern TemporaryStorageArray<uint32, 0x110> _temp_store;
 
	return _temp_store.Get(i);
 
}
 

	
 
/* List of different sprite group types */
 
enum SpriteGroupType {
 
	SGT_REAL,
 
	SGT_DETERMINISTIC,
 
	SGT_RANDOMIZED,
 
	SGT_CALLBACK,
 
	SGT_RESULT,
 
	SGT_TILELAYOUT,
 
	SGT_INDUSTRY_PRODUCTION,
 
};
 

	
 
struct SpriteGroup;
 
typedef uint32 SpriteGroupID;
 

	
 
/* SPRITE_WIDTH is 24. ECS has roughly 30 sprite groups per real sprite.
 
 * Adding an 'extra' margin would be assuming 64 sprite groups per real
 
 * sprite. 64 = 2^6, so 2^30 should be enough (for now) */
 
typedef Pool<SpriteGroup, SpriteGroupID, 1024, 1 << 30> SpriteGroupPool;
 
extern SpriteGroupPool _spritegroup_pool;
 

	
 
/* Common wrapper for all the different sprite group types */
 
struct SpriteGroup : SpriteGroupPool::PoolItem<&_spritegroup_pool> {
 
protected:
 
	SpriteGroup(SpriteGroupType type) : type(type) {}
 
	/** Base sprite group resolver */
 
	virtual const SpriteGroup *Resolve(struct ResolverObject *object) const { return this; };
 

	
 
public:
 
	virtual ~SpriteGroup() {}
 

	
src/rail_cmd.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file rail_cmd.cpp Handling of rail tiles. */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "cmd_helper.h"
 
#include "landscape.h"
 
#include "town_map.h"
 
#include "viewport_func.h"
 
#include "command_func.h"
 
#include "engine_base.h"
 
#include "depot_base.h"
 
#include "waypoint.h"
 
#include "yapf/yapf.h"
 
#include "newgrf_engine.h"
 
#include "newgrf_station.h"
 
#include "newgrf_commons.h"
 
#include "train.h"
 
#include "variables.h"
 
#include "autoslope.h"
 
#include "water.h"
 
#include "tunnelbridge_map.h"
 
#include "window_func.h"
 
#include "vehicle_func.h"
 
#include "sound_func.h"
 
#include "tunnelbridge.h"
 
#include "station_map.h"
 
#include "functions.h"
 
#include "elrail_func.h"
 
#include "town.h"
 

	
 
#include "table/strings.h"
 
#include "table/railtypes.h"
 
#include "table/track_land.h"
 

	
 
RailtypeInfo _railtypes[RAILTYPE_END];
 

	
 
assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes));
 

	
 
/**
 
 * Initialize rail type information.
 
 */
 
void ResetRailTypes()
 
{
 
	memset(_railtypes, 0, sizeof(_railtypes));
 
	memcpy(_railtypes, _original_railtypes, sizeof(_original_railtypes));
 
}
 

	
 
const byte _track_sloped_sprites[14] = {
 
	14, 15, 22, 13,
 
	 0, 21, 17, 12,
 
	23,  0, 18, 20,
 
	19, 16
 
};
 

	
 

	
 
/*         4
 
 *     ---------
 
 *    |\       /|
 
 *    | \    1/ |
 
 *    |  \   /  |
 
 *    |   \ /   |
 
 *  16|    \    |32
 
 *    |   / \2  |
 
 *    |  /   \  |
 
 *    | /     \ |
 
 *    |/       \|
 
 *     ---------
 
 *         8
 
 */
 

	
 

	
 

	
 
/* MAP2 byte:    abcd???? => Signal On? Same coding as map3lo
 
 * MAP3LO byte:  abcd???? => Signal Exists?
 
 *               a and b are for diagonals, upper and left,
 
 *               one for each direction. (ie a == NE->SW, b ==
 
 *               SW->NE, or v.v., I don't know. b and c are
src/road_cmd.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file road_cmd.cpp Commands related to road tiles. */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "cmd_helper.h"
 
#include "road_internal.h"
 
#include "landscape.h"
 
#include "town_map.h"
 
#include "viewport_func.h"
 
#include "command_func.h"
 
#include "yapf/yapf.h"
 
#include "depot_base.h"
 
#include "newgrf.h"
 
#include "station_map.h"
 
#include "variables.h"
 
#include "autoslope.h"
 
#include "tunnelbridge_map.h"
 
#include "window_func.h"
 
#include "strings_func.h"
 
#include "vehicle_func.h"
 
#include "sound_func.h"
 
#include "tunnelbridge.h"
 
#include "cheat_type.h"
 
#include "functions.h"
 
#include "effectvehicle_func.h"
 
#include "elrail_func.h"
 
#include "roadveh.h"
 
#include "town.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
/**
 
 * Verify whether a road vehicle is available.
 
 * @return \c true if at least one road vehicle is available, \c false if not
 
 */
 
bool RoadVehiclesAreBuilt()
 
{
 
	const RoadVehicle *rv;
 
	FOR_ALL_ROADVEHICLES(rv) return true;
 

	
 
	return false;
 
}
 

	
 
#define M(x) (1 << (x))
 
/* Level crossings may only be built on these slopes */
 
static const uint32 VALID_LEVEL_CROSSING_SLOPES = (M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT));
 
#undef M
 

	
 
/* Invalid RoadBits on slopes  */
 
static const RoadBits _invalid_tileh_slopes_road[2][15] = {
 
	/* The inverse of the mixable RoadBits on a leveled slope */
 
	{
 
		ROAD_NONE,         // SLOPE_FLAT
 
		ROAD_NE | ROAD_SE, // SLOPE_W
 
		ROAD_NE | ROAD_NW, // SLOPE_S
 

	
 
		ROAD_NE,           // SLOPE_SW
 
		ROAD_NW | ROAD_SW, // SLOPE_E
 
		ROAD_NONE,         // SLOPE_EW
 

	
 
		ROAD_NW,           // SLOPE_SE
 
		ROAD_NONE,         // SLOPE_WSE
 
		ROAD_SE | ROAD_SW, // SLOPE_N
 

	
 
		ROAD_SE,           // SLOPE_NW
 
		ROAD_NONE,         // SLOPE_NS
 
		ROAD_NONE,         // SLOPE_ENW
 

	
 
		ROAD_SW,           // SLOPE_NE
 
		ROAD_NONE,         // SLOPE_SEN
 
		ROAD_NONE          // SLOPE_NWS
 
	},
 
	/* The inverse of the allowed straight roads on a slope
 
	 * (with and without a foundation). */
 
	{
src/saveload/afterload.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file afterload.cpp Code updating data after game load */
 

	
 
#include "../stdafx.h"
 
#include "../void_map.h"
 
#include "../signs_base.h"
 
#include "../roadstop_base.h"
 
#include "../window_func.h"
 
#include "../fios.h"
 
#include "../train.h"
 
#include "../string_func.h"
 
#include "../gamelog.h"
 
#include "../network/network.h"
 
#include "../gfxinit.h"
 
#include "../functions.h"
 
#include "../industry_map.h"
 
#include "../town_map.h"
 
#include "../clear_map.h"
 
#include "../vehicle_func.h"
 
#include "../newgrf_station.h"
 
#include "../yapf/yapf.hpp"
 
#include "../elrail_func.h"
 
#include "../signs_func.h"
 
#include "../aircraft.h"
 
#include "../unmovable_map.h"
 
#include "../tree_map.h"
 
#include "../company_func.h"
 
#include "../road_cmd.h"
 
#include "../ai/ai.hpp"
 
#include "../town.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "saveload_internal.h"
 

	
 
#include <signal.h>
 

	
 
extern StringID _switch_mode_errorstr;
 
extern Company *DoStartupNewCompany(bool is_ai);
 
extern void InitializeRailGUI();
 

	
 
/**
 
 * Makes a tile canal or water depending on the surroundings.
 
 *
 
 * Must only be used for converting old savegames. Use WaterClass now.
 
 *
 
 * This as for example docks and shipdepots do not store
 
 * whether the tile used to be canal or 'normal' water.
 
 * @param t the tile to change.
 
 * @param o the owner of the new tile.
 
 * @param include_invalid_water_class Also consider WATER_CLASS_INVALID, i.e. industry tiles on land
 
 */
 
void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_water_class)
 
{
 
	/* If the slope is not flat, we always assume 'land' (if allowed). Also for one-corner-raised-shores.
 
	 * Note: Wrt. autosloping under industry tiles this is the most fool-proof behaviour. */
 
	if (GetTileSlope(t, NULL) != SLOPE_FLAT) {
 
		if (include_invalid_water_class) {
 
			SetWaterClass(t, WATER_CLASS_INVALID);
 
			return;
 
		} else {
 
			NOT_REACHED();
 
		}
 
	}
 

	
 
	/* Mark tile dirty in all cases */
 
	MarkTileDirtyByTile(t);
 

	
 
	if (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1) {
 
		/* tiles at map borders are always WATER_CLASS_SEA */
 
		SetWaterClass(t, WATER_CLASS_SEA);
 
		return;
 
	}
 

	
 
	bool has_water = false;
 
	bool has_canal = false;
 
	bool has_river = false;
 

	
src/saveload/town_sl.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file town_sl.cpp Code handling saving and loading of towns and houses */
 

	
 
#include "../stdafx.h"
 
#include "../newgrf_house.h"
 
#include "../newgrf_commons.h"
 
#include "../variables.h"
 
#include "../town_map.h"
 
#include "../town.h"
 

	
 
#include "saveload.h"
 

	
 
/**
 
 * Check and update town and house values.
 
 *
 
 * Checked are the HouseIDs. Updated are the
 
 * town population the number of houses per
 
 * town, the town radius and the max passengers
 
 * of the town.
 
 */
 
void UpdateHousesAndTowns()
 
{
 
	Town *town;
 
	InitializeBuildingCounts();
 

	
 
	/* Reset town population and num_houses */
 
	FOR_ALL_TOWNS(town) {
 
		town->population = 0;
 
		town->num_houses = 0;
 
	}
 

	
 
	for (TileIndex t = 0; t < MapSize(); t++) {
 
		HouseID house_id;
 

	
 
		if (!IsTileType(t, MP_HOUSE)) continue;
 

	
 
		house_id = GetHouseType(t);
 
		if (!GetHouseSpecs(house_id)->enabled && house_id >= NEW_HOUSE_OFFSET) {
 
			/* The specs for this type of house are not available any more, so
 
			 * replace it with the substitute original house type. */
 
			house_id = _house_mngr.GetSubstituteID(house_id);
 
			SetHouseType(t, house_id);
 
		}
 

	
 
		town = GetTownByTile(t);
 
		IncreaseBuildingCount(town, house_id);
 
		if (IsHouseCompleted(t)) town->population += GetHouseSpecs(house_id)->population;
 

	
 
		/* Increase the number of houses for every house, but only once. */
 
		if (GetHouseNorthPart(house_id) == 0) town->num_houses++;
 
	}
 

	
 
	/* Update the population and num_house dependant values */
 
	FOR_ALL_TOWNS(town) {
 
		UpdateTownRadius(town);
 
	}
 
}
src/town.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file town.h Base of the town class. */
 

	
 
#ifndef TOWN_H
 
#define TOWN_H
 

	
 
#include "core/pool_type.hpp"
 
#include "core/bitmath_func.hpp"
 
#include "core/random_func.hpp"
 
#include "cargo_type.h"
 
#include "tile_type.h"
 
#include "date_type.h"
 
#include "town_type.h"
 
#include "company_type.h"
 
#include "settings_type.h"
 
#include "strings_type.h"
 
#include "viewport_type.h"
 
#include "economy_type.h"
 
#include "map_type.h"
 
#include "command_type.h"
 

	
 
enum {
 
	HOUSE_NO_CLASS   = 0,
 
	NEW_HOUSE_OFFSET = 110,
 
	HOUSE_MAX        = 512,
 
	INVALID_TOWN     = 0xFFFF,
 
	INVALID_HOUSE_ID = 0xFFFF,
 

	
 
	/* There can only be as many classes as there are new houses, plus one for
 
	 * NO_CLASS, as the original houses don't have classes. */
 
	HOUSE_CLASS_MAX  = HOUSE_MAX - NEW_HOUSE_OFFSET + 1,
 
};
 

	
 
enum BuildingFlags {
 
	TILE_NO_FLAG         =       0,
 
	TILE_SIZE_1x1        = 1U << 0,
 
	TILE_NOT_SLOPED      = 1U << 1,
 
	TILE_SIZE_2x1        = 1U << 2,
 
	TILE_SIZE_1x2        = 1U << 3,
 
	TILE_SIZE_2x2        = 1U << 4,
 
	BUILDING_IS_ANIMATED = 1U << 5,
 
	BUILDING_IS_CHURCH   = 1U << 6,
 
	BUILDING_IS_STADIUM  = 1U << 7,
 
	BUILDING_HAS_1_TILE  = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
 
	BUILDING_HAS_2_TILES = TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
 
	BUILDING_2_TILES_X   = TILE_SIZE_2x1 | TILE_SIZE_2x2,
 
	BUILDING_2_TILES_Y   = TILE_SIZE_1x2 | TILE_SIZE_2x2,
 
	BUILDING_HAS_4_TILES = TILE_SIZE_2x2,
 
};
 

	
 
DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
 

	
 
enum HouseZonesBits {
 
	HZB_BEGIN     = 0,
 
	HZB_TOWN_EDGE = 0,
 
	HZB_TOWN_OUTSKIRT,
 
	HZB_TOWN_OUTER_SUBURB,
 
	HZB_TOWN_INNER_SUBURB,
 
	HZB_TOWN_CENTRE,
 
	HZB_END,
 
};
 
assert_compile(HZB_END == 5);
 

	
 
DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
 

	
 
enum HouseZones {                  ///< Bit  Value       Meaning
 
	HZ_NOZNS             = 0x0000,  ///<       0          This is just to get rid of zeros, meaning none
 
	HZ_ZON1              = 1U << HZB_TOWN_EDGE,    ///< 0..4 1,2,4,8,10  which town zones the building can be built in, Zone1 been the further suburb
 
	HZ_ZON2              = 1U << HZB_TOWN_OUTSKIRT,
 
	HZ_ZON3              = 1U << HZB_TOWN_OUTER_SUBURB,
 
	HZ_ZON4              = 1U << HZB_TOWN_INNER_SUBURB,
 
	HZ_ZON5              = 1U << HZB_TOWN_CENTRE,  ///<  center of town
 
	HZ_ZONALL            = 0x001F,  ///<       1F         This is just to englobe all above types at once
 
	HZ_SUBARTC_ABOVE     = 0x0800,  ///< 11    800        can appear in sub-arctic climate above the snow line
 
	HZ_TEMP              = 0x1000,  ///< 12   1000        can appear in temperate climate
 
	HZ_SUBARTC_BELOW     = 0x2000,  ///< 13   2000        can appear in sub-arctic climate below the snow line
 
	HZ_SUBTROPIC         = 0x4000,  ///< 14   4000        can appear in subtropical climate
 
	HZ_TOYLND            = 0x8000   ///< 15   8000        can appear in toyland climate
 
};
 

	
 
DECLARE_ENUM_AS_BIT_SET(HouseZones)
 

	
 
enum HouseExtraFlags {
 
	NO_EXTRA_FLAG            =       0,
 
	BUILDING_IS_HISTORICAL   = 1U << 0,  ///< this house will only appear during town generation in random games, thus the historical
 
	BUILDING_IS_PROTECTED    = 1U << 1,  ///< towns and AI will not remove this house, while human players will be able to
 
	SYNCHRONISED_CALLBACK_1B = 1U << 2,  ///< synchronized callback 1B will be performed, on multi tile houses
 
	CALLBACK_1A_RANDOM_BITS  = 1U << 3,  ///< callback 1A needs random bits
 
};
 

	
 
DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
 
#include "town_map.h"
 

	
 
template <typename T>
 
struct BuildingCounts {
 
	T id_count[HOUSE_MAX];
 
	T class_count[HOUSE_CLASS_MAX];
 
};
 

	
 
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY  = 4; ///< value for custom town number in difficulty settings
 
static const uint CUSTOM_TOWN_MAX_NUMBER = 5000;  ///< this is the maximum number of towns a user can specify in customisation
 

	
 
static const uint INVALID_TOWN = 0xFFFF;
 

	
 
typedef Pool<Town, TownID, 64, 64000> TownPool;
 
extern TownPool _town_pool;
 

	
 
struct Town : TownPool::PoolItem<&_town_pool> {
 
	TileIndex xy;
 

	
 
	/* Current population of people and amount of houses. */
 
	uint32 num_houses;
 
	uint32 population;
 

	
 
	/* Town name */
 
	uint32 townnamegrfid;
 
	uint16 townnametype;
 
	uint32 townnameparts;
 
	char *name;
 

	
 
	/* NOSAVE: Location of name sign, UpdateTownVirtCoord updates this. */
 
	ViewportSign sign;
 

	
 
	/* Makes sure we don't build certain house types twice.
 
	 * bit 0 = Building funds received
 
	 * bit 1 = CHURCH
 
	 * bit 2 = STADIUM */
 
	byte flags;
 

	
 
	/* level of noise that all the airports are generating */
 
	uint16 noise_reached;
 

	
 
	/* Which companies have a statue? */
 
	CompanyMask statues;
 

	
 
	/* Company ratings as well as a mask that determines which companies have a rating. */
 
	CompanyMask have_ratings;
 
	uint8 unwanted[MAX_COMPANIES]; ///< how many months companies aren't wanted by towns (bribe)
 
	CompanyByte exclusivity;       ///< which company has exclusivity
 
	uint8 exclusive_counter;       ///< months till the exclusivity expires
 
	int16 ratings[MAX_COMPANIES];
 

	
 
	/* Maximum amount of passengers and mail that can be transported. */
 
	uint32 max_pass;
 
	uint32 max_mail;
 
	uint32 new_max_pass;
 
	uint32 new_max_mail;
 
	uint32 act_pass;
 
	uint32 act_mail;
 
	uint32 new_act_pass;
 
	uint32 new_act_mail;
 

	
 
@@ -160,182 +92,135 @@ struct Town : TownPool::PoolItem<&_town_
 

	
 
	/* Time until we rebuild a house. */
 
	uint16 time_until_rebuild;
 

	
 
	/* When to grow town next time. */
 
	uint16 grow_counter;
 
	int16 growth_rate;
 

	
 
	/* Fund buildings program in action? */
 
	byte fund_buildings_months;
 

	
 
	/* Fund road reconstruction in action? */
 
	byte road_build_months;
 

	
 
	/* If this is a larger town, and should grow more quickly. */
 
	bool larger_town;
 
	TownLayoutByte layout; ///< town specific road layout
 

	
 
	/* NOSAVE: UpdateTownRadius updates this given the house count. */
 
	uint32 squared_town_zone_radius[HZB_END];
 

	
 
	/* NOSAVE: The number of each type of building in the town. */
 
	BuildingCounts<uint16> building_counts;
 

	
 
	/**
 
	 * Creates a new town
 
	 */
 
	Town(TileIndex tile = INVALID_TILE) : xy(tile) { }
 

	
 
	/** Destroy the town */
 
	~Town();
 

	
 
	void InitializeLayout(TownLayout layout);
 

	
 
	/** Calculate the max town noise
 
	 * The value is counted using the population divided by the content of the
 
	 * entry in town_noise_population corespondig to the town's tolerance.
 
	 * To this result, we add 3, which is the noise of the lowest airport.
 
	 * So user can at least buld that airport
 
	 * @return the maximum noise level the town will tolerate */
 
	inline uint16 MaxTownNoise() const
 
	{
 
		if (this->population == 0) return 0; // no population? no noise
 

	
 
		return ((this->population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3);
 
	}
 
};
 

	
 
struct HouseSpec {
 
	/* Standard properties */
 
	Year min_year;                     ///< introduction year of the house
 
	Year max_year;                     ///< last year it can be built
 
	byte population;                   ///< population (Zero on other tiles in multi tile house.)
 
	byte removal_cost;                 ///< cost multiplier for removing it
 
	StringID building_name;            ///< building name
 
	uint16 remove_rating_decrease;     ///< rating decrease if removed
 
	byte mail_generation;              ///< mail generation multiplier (tile based, as the acceptances below)
 
	byte cargo_acceptance[3];          ///< acceptance level for the cargo slots
 
	CargoID accepts_cargo[3];          ///< 3 input cargo slots
 
	BuildingFlags building_flags;      ///< some flags that describe the house (size, stadium etc...)
 
	HouseZones building_availability;  ///< where can it be built (climates, zones)
 
	bool enabled;                      ///< the house is available to build (true by default, but can be disabled by newgrf)
 

	
 
	/* NewHouses properties */
 
	HouseID substitute_id;             ///< which original house this one is based on
 
	struct SpriteGroup *spritegroup;   ///< pointer to the different sprites of the house
 
	HouseID override;                  ///< which house this one replaces
 
	uint16 callback_mask;              ///< House callback flags
 
	byte random_colour[4];             ///< 4 "random" colours
 
	byte probability;                  ///< Relative probability of appearing (16 is the standard value)
 
	HouseExtraFlags extra_flags;       ///< some more flags
 
	HouseClassID class_id;             ///< defines the class this house has (grf file based) @See HouseGetVariable, prop 0x44
 
	byte animation_frames;             ///< number of animation frames
 
	byte animation_speed;              ///< amount of time between each of those frames
 
	byte processing_time;              ///< Periodic refresh multiplier
 
	byte minimum_life;                 ///< The minimum number of years this house will survive before the town rebuilds it
 

	
 
	/* grf file related properties*/
 
	uint8 local_id;                    ///< id defined by the grf file for this house
 
	const struct GRFFile *grffile;     ///< grf file that introduced this house
 

	
 
	/**
 
	 * Get the cost for removing this house
 
	 * @return the cost (inflation corrected etc)
 
	 */
 
	Money GetRemovalCost() const;
 

	
 
};
 

	
 
extern HouseSpec _house_specs[HOUSE_MAX];
 
static inline Town *GetTownByTile(TileIndex tile)
 
{
 
	return Town::Get(GetTownIndex(tile));
 
}
 

	
 
uint32 GetWorldPopulation();
 

	
 
void UpdateTownVirtCoord(Town *t);
 
void UpdateAllTownVirtCoords();
 
void InitializeTown();
 
void ShowTownViewWindow(TownID town);
 
void ExpandTown(Town *t);
 
Town *CreateRandomTown(uint attempts, TownSize size, bool city, TownLayout layout);
 

	
 
enum TownRatingCheckType {
 
	ROAD_REMOVE         = 0,
 
	TUNNELBRIDGE_REMOVE = 1,
 
	TOWN_RATING_CHECK_TYPE_COUNT,
 
};
 

	
 
/** This is the number of ticks between towns being processed for building new
 
 * houses or roads. This value originally came from the size of the town array
 
 * in TTD. */
 
static const byte TOWN_GROWTH_FREQUENCY = 70;
 

	
 
/** Simple value that indicates the house has reached the final stage of
 
 * construction. */
 
static const byte TOWN_HOUSE_COMPLETED = 3;
 

	
 
/** This enum is used in conjonction with town->flags.
 
 * IT simply states what bit is used for.
 
 * It is pretty unrealistic (IMHO) to only have one church/stadium
 
 * per town, NO MATTER the population of it.
 
 * And there are 5 more bits available on flags...
 
 */
 
enum {
 
	TOWN_IS_FUNDED      = 0,   ///< Town has received some funds for
 
	TOWN_HAS_CHURCH     = 1,   ///< There can be only one church by town.
 
	TOWN_HAS_STADIUM    = 2    ///< There can be only one stadium by town.
 
};
 

	
 
bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type);
 

	
 
static inline HouseSpec *GetHouseSpecs(HouseID house_id)
 
{
 
	assert(house_id < HOUSE_MAX);
 
	return &_house_specs[house_id];
 
}
 

	
 
TileIndexDiff GetHouseNorthPart(HouseID &house);
 

	
 
/**
 
 * Return a random valid town.
 
 */
 
static inline Town *GetRandomTown()
 
{
 
	int num = RandomRange((uint16)Town::GetNumItems());
 
	TownID index = INVALID_TOWN;
 

	
 
	while (num >= 0) {
 
		num--;
 

	
 
		index++;
 
		/* Make sure we have a valid town */
 
		while (!Town::IsValidID(index)) {
 
			index++;
 
			assert(index < Town::GetPoolSize());
 
		}
 
	}
 

	
 
	return Town::Get(index);
 
}
 

	
 
Town *CalcClosestTownFromTile(TileIndex tile, uint threshold = UINT_MAX, const Town *ignore = NULL);
 

	
 
#define FOR_ALL_TOWNS_FROM(var, start) FOR_ALL_ITEMS_FROM(Town, town_index, var, start)
 
#define FOR_ALL_TOWNS(var) FOR_ALL_TOWNS_FROM(var, 0)
 

	
 
extern Town *_cleared_town;
 
extern int _cleared_town_rating;
 

	
 
void ResetHouses();
 

	
 
void ClearTownHouse(Town *t, TileIndex tile);
 
void UpdateTownMaxPass(Town *t);
 
void UpdateTownRadius(Town *t);
 
bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
 
Town *ClosestTownFromTile(TileIndex tile, uint threshold);
 
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags);
 
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
 
void SetTownRatingTestMode(bool mode);
 
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
 
bool GenerateTowns(TownLayout layout);
 
bool GenerateTownName(uint32 *townnameparts);
 

	
 
/**
src/town_cmd.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file town_cmd.cpp Handling of town tiles. */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "road_type.h"
 
#include "road_internal.h" /* Cleaning up road bits */
 
#include "road_cmd.h"
 
#include "landscape.h"
 
#include "town_map.h"
 
#include "viewport_func.h"
 
#include "command_func.h"
 
#include "industry.h"
 
#include "station_base.h"
 
#include "company_base.h"
 
#include "news_func.h"
 
#include "gui.h"
 
#include "unmovable_map.h"
 
#include "water_map.h"
 
#include "variables.h"
 
#include "slope_func.h"
 
#include "genworld.h"
 
#include "newgrf.h"
 
#include "newgrf_house.h"
 
#include "newgrf_commons.h"
 
#include "newgrf_townname.h"
 
#include "newgrf_text.h"
 
#include "autoslope.h"
 
#include "waypoint.h"
 
#include "transparency.h"
 
#include "tunnelbridge_map.h"
 
#include "strings_func.h"
 
#include "window_func.h"
 
#include "string_func.h"
 
#include "newgrf_cargo.h"
 
#include "economy_func.h"
 
#include "station_func.h"
 
#include "cheat_type.h"
 
#include "functions.h"
 
#include "animated_tile_func.h"
 
#include "date_func.h"
 
#include "subsidy_func.h"
 
#include "core/smallmap_type.hpp"
 
#include "core/pool_func.hpp"
 
#include "town.h"
 

	
 
#include "table/strings.h"
 
#include "table/town_land.h"
 

	
 
HouseSpec _house_specs[HOUSE_MAX];
 

	
 
Town *_cleared_town;
 
int _cleared_town_rating;
 

	
 
uint32 _cur_town_ctr;     ///< iterator through all towns in OnTick_Town
 
uint32 _cur_town_iter;    ///< frequency iterator at the same place
 

	
 
/* Initialize the town-pool */
 
TownPool _town_pool("Town");
 
INSTANTIATE_POOL_METHODS(Town)
 

	
 
Town::~Town()
 
{
 
	free(this->name);
 

	
 
	if (CleaningPool()) return;
 

	
 
	Industry *i;
 

	
 
	/* Delete town authority window
 
	 * and remove from list of sorted towns */
 
	DeleteWindowById(WC_TOWN_VIEW, this->index);
 
	InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0);
 

	
 
	/* 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:
 
				/* Cached nearest town is updated later (after this town has been deleted) */
 
				if (HasTownOwnedRoad(tile) && GetTownIndex(tile) == this->index) {
 
					DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
				}
 
				break;
 

	
 
			case MP_TUNNELBRIDGE:
 
				if (IsTileOwner(tile, OWNER_TOWN) &&
src/town_map.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file town_map.h Accessors for towns */
 

	
 
#ifndef TOWN_MAP_H
 
#define TOWN_MAP_H
 

	
 
#include "town.h"
 
#include "tile_map.h"
 
#include "town_type.h"
 
#include "house.h"
 

	
 
/**
 
 * Get the index of which town this house/street is attached to.
 
 * @param t the tile
 
 * @pre IsTileType(t, MP_HOUSE) or IsTileType(t, MP_ROAD)
 
 * @return TownID
 
 */
 
static inline TownID GetTownIndex(TileIndex t)
 
{
 
	assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_ROAD)); // XXX incomplete
 
	return _m[t].m2;
 
}
 

	
 
/**
 
 * Set the town index for a road or house tile.
 
 * @param t the tile
 
 * @pre IsTileType(t, MP_HOUSE) or IsTileType(t, MP_ROAD)
 
 * @param index the index of the town
 
 * @pre IsTileType(t, MP_ROAD) || IsTileType(t, MP_HOUSE)
 
 */
 
static inline void SetTownIndex(TileIndex t, TownID index)
 
{
 
	assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_ROAD));
 
	_m[t].m2 = index;
 
}
 

	
 
/**
 
 * Gets the town associated with the house or road tile
 
 * @param t the tile to get the town of
 
 * @return the town
 
 */
 
static inline Town *GetTownByTile(TileIndex t)
 
{
 
	return Town::Get(GetTownIndex(t));
 
}
 

	
 
/**
 
 * Get the type of this house, which is an index into the house spec array
 
 * Since m4 is only a byte and we want to support 512 houses, we use the bit 6
 
 * of m3 as an additional bit to house type.
 
 * @param t the tile
 
 * @pre IsTileType(t, MP_HOUSE)
 
 * @return house type
 
 */
 
static inline HouseID GetHouseType(TileIndex t)
 
{
 
	assert(IsTileType(t, MP_HOUSE));
 
	return _m[t].m4 | (GB(_m[t].m3, 6, 1) << 8);
 
}
 

	
 
/**
 
 * Set the house type.
 
 * @param t the tile
 
 * @param house_id the new house type
 
 * @pre IsTileType(t, MP_HOUSE)
 
 */
 
static inline void SetHouseType(TileIndex t, HouseID house_id)
 
{
 
	assert(IsTileType(t, MP_HOUSE));
 
	_m[t].m4 = GB(house_id, 0, 8);
 
	SB(_m[t].m3, 6, 1, GB(house_id, 8, 1));
 
}
 

	
 
/**
 
 * Check if the lift of this animated house has a destination
 
 * @param t the tile
 
 * @return has destination
 
 */
 
static inline bool LiftHasDestination(TileIndex t)
 
{
 
	return HasBit(_me[t].m7, 0);
 
}
 

	
 
/**
 
 * Set the new destination of the lift for this animated house, and activate
 
 * the LiftHasDestination bit.
 
 * @param t the tile
 
 * @param dest new destination
 
 */
 
static inline void SetLiftDestination(TileIndex t, byte dest)
 
{
 
	SetBit(_me[t].m7, 0);
 
	SB(_me[t].m7, 1, 3, dest);
 
}
 

	
src/town_type.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file town_type.h Types related to towns. */
 

	
 
#ifndef TOWN_TYPE_H
 
#define TOWN_TYPE_H
 

	
 
#include "core/enum_type.hpp"
 

	
 
typedef uint16 TownID;
 
typedef uint16 HouseID;
 
typedef uint16 HouseClassID;
 

	
 
struct Town;
 
struct HouseSpec;
 

	
 
/** Supported initial town sizes */
 
enum TownSize {
 
	TS_SMALL,  ///< small town
 
	TS_MEDIUM, ///< medium town
 
	TS_LARGE,  ///< large town
 
	TS_RANDOM, ///< random size, bigger than small, smaller than large
 
};
 

	
 
enum {
 
	/* These refer to the maximums, so Appalling is -1000 to -400
 
	 * MAXIMUM RATINGS BOUNDARIES */
 
	RATING_MINIMUM     = -1000,
 
	RATING_APPALLING   =  -400,
 
	RATING_VERYPOOR    =  -200,
 
	RATING_POOR        =     0,
 
	RATING_MEDIOCRE    =   200,
 
	RATING_GOOD        =   400,
 
	RATING_VERYGOOD    =   600,
 
	RATING_EXCELLENT   =   800,
 
	RATING_OUTSTANDING =  1000,         ///< OUTSTANDING
 

	
 
	RATING_MAXIMUM = RATING_OUTSTANDING,
 

	
 
	RATING_INITIAL = 500, ///< initial rating
 

	
 
	/* RATINGS AFFECTING NUMBERS */
 
	RATING_TREE_DOWN_STEP = -35,
 
	RATING_TREE_MINIMUM   = RATING_MINIMUM,
 
	RATING_TREE_UP_STEP   = 7,
 
	RATING_TREE_MAXIMUM   = 220,
 

	
 
	RATING_GROWTH_UP_STEP    =   5, ///< when a town grows, all companies have rating increased a bit ...
 
	RATING_GROWTH_MAXIMUM    = RATING_MEDIOCRE, ///< ... up to RATING_MEDIOCRE
 
	RATING_STATION_UP_STEP   =  12, ///< when a town grows, company gains reputation for all well serviced stations ...
 
	RATING_STATION_DOWN_STEP = -15, ///< ... but loses for bad serviced stations
 

	
 
	RATING_TUNNEL_BRIDGE_DOWN_STEP = -250, ///< penalty for removing town owned tunnel or bridge
 
	RATING_TUNNEL_BRIDGE_MINIMUM   =    0, ///< minimum rating after removing tunnel or bridge
 
	RATING_TUNNEL_BRIDGE_NEEDED_PERMISSIVE = 144, ///< rating needed, "Permissive" difficulty settings
 
	RATING_TUNNEL_BRIDGE_NEEDED_NEUTRAL    = 208, ///< "Neutral"
 
	RATING_TUNNEL_BRIDGE_NEEDED_HOSTILE    = 400, ///< "Hostile"
 

	
 
	RATING_ROAD_DOWN_STEP_INNER =  -50, ///< removing a roadpiece in the middle
 
	RATING_ROAD_DOWN_STEP_EDGE  =  -18, ///< removing a roadpiece at the edge
 
	RATING_ROAD_MINIMUM         = -100, ///< minimum rating after removing town owned road
 
	RATING_ROAD_NEEDED_PERMISSIVE =  16, ///< rating needed, "Permissive" difficulty settings
 
	RATING_ROAD_NEEDED_NEUTRAL    =  64, ///< "Neutral"
0 comments (0 inline, 0 general)