2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file town.h Base of the town class. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef TOWN_H
|
|
|
|
#define TOWN_H
|
|
|
|
|
2006-12-03 17:27:43 +00:00
|
|
|
#include "oldpool.h"
|
2008-04-01 16:27:01 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "core/random_func.hpp"
|
|
|
|
#include "cargo_type.h"
|
2007-12-25 23:42:52 +00:00
|
|
|
#include "tile_type.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_type.h"
|
2008-01-07 14:02:26 +00:00
|
|
|
#include "town_type.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_type.h"
|
2008-04-01 16:27:01 +00:00
|
|
|
#include "settings_type.h"
|
2008-04-17 11:47:22 +00:00
|
|
|
#include "strings_type.h"
|
2008-05-07 13:10:15 +00:00
|
|
|
#include "viewport_type.h"
|
2008-06-05 01:43:03 +00:00
|
|
|
#include "economy_type.h"
|
2008-10-20 19:46:49 +00:00
|
|
|
#include "map_type.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-09 14:18:08 +00:00
|
|
|
enum {
|
2007-03-19 11:27:30 +00:00
|
|
|
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_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)
|
|
|
|
|
2008-01-16 02:53:55 +00:00
|
|
|
enum HouseZonesBits {
|
2008-04-04 14:53:06 +00:00
|
|
|
HZB_BEGIN = 0,
|
2008-01-16 02:53:55 +00:00
|
|
|
HZB_TOWN_EDGE = 0,
|
|
|
|
HZB_TOWN_OUTSKIRT,
|
|
|
|
HZB_TOWN_OUTER_SUBURB,
|
|
|
|
HZB_TOWN_INNER_SUBURB,
|
|
|
|
HZB_TOWN_CENTRE,
|
2008-04-04 14:53:06 +00:00
|
|
|
HZB_END,
|
2008-01-16 02:53:55 +00:00
|
|
|
};
|
2008-04-04 14:53:06 +00:00
|
|
|
assert_compile(HZB_END == 5);
|
|
|
|
|
|
|
|
DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
|
2008-01-16 02:53:55 +00:00
|
|
|
|
2007-03-19 11:27:30 +00:00
|
|
|
enum HouseZones { ///< Bit Value Meaning
|
|
|
|
HZ_NOZNS = 0x0000, ///< 0 This is just to get rid of zeros, meaning none
|
2008-01-16 02:53:55 +00:00
|
|
|
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
|
2007-03-19 11:27:30 +00:00
|
|
|
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
|
2008-09-30 20:39:50 +00:00
|
|
|
BUILDING_IS_PROTECTED = 1U << 1, ///< towns and AI will not remove this house, while human players will be able to
|
2007-03-19 11:27:30 +00:00
|
|
|
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 BuildingCounts {
|
|
|
|
uint8 id_count[HOUSE_MAX];
|
|
|
|
uint8 class_count[HOUSE_CLASS_MAX];
|
2006-12-09 14:18:08 +00:00
|
|
|
};
|
|
|
|
|
2007-08-02 21:05:54 +00:00
|
|
|
DECLARE_OLD_POOL(Town, Town, 3, 8000)
|
|
|
|
|
|
|
|
struct Town : PoolItem<Town, TownID, &_Town_pool> {
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex xy;
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Current population of people and amount of houses. */
|
2008-03-18 12:28:21 +00:00
|
|
|
uint32 num_houses;
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 population;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Town name */
|
2007-06-18 23:00:55 +00:00
|
|
|
uint32 townnamegrfid;
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 townnametype;
|
|
|
|
uint32 townnameparts;
|
2008-01-12 19:58:06 +00:00
|
|
|
char *name;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* NOSAVE: Location of name sign, UpdateTownVirtCoord updates this. */
|
2004-08-09 17:04:08 +00:00
|
|
|
ViewportSign sign;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Makes sure we don't build certain house types twice.
|
|
|
|
* bit 0 = Building funds received
|
|
|
|
* bit 1 = CHURCH
|
|
|
|
* bit 2 = STADIUM */
|
2004-08-09 17:04:08 +00:00
|
|
|
byte flags12;
|
|
|
|
|
2008-05-24 02:54:47 +00:00
|
|
|
/* level of noise that all the airports are generating */
|
|
|
|
uint16 noise_reached;
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Which companies have a statue? */
|
2008-12-23 21:03:43 +00:00
|
|
|
CompanyMask statues;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* 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];
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Maximum amount of passengers and mail that can be transported. */
|
2005-02-17 10:56:19 +00:00
|
|
|
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;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Amount of passengers that were transported. */
|
2004-08-09 17:04:08 +00:00
|
|
|
byte pct_pass_transported;
|
|
|
|
byte pct_mail_transported;
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Amount of food and paper that was transported. Actually a bit mask would be enough. */
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 act_food;
|
2004-08-10 14:42:52 +00:00
|
|
|
uint16 act_water;
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 new_act_food;
|
2004-08-10 14:42:52 +00:00
|
|
|
uint16 new_act_water;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Time until we rebuild a house. */
|
2007-04-12 17:24:34 +00:00
|
|
|
uint16 time_until_rebuild;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* When to grow town next time. */
|
2007-04-12 17:24:34 +00:00
|
|
|
uint16 grow_counter;
|
|
|
|
int16 growth_rate;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Fund buildings program in action? */
|
2004-08-09 17:04:08 +00:00
|
|
|
byte fund_buildings_months;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Fund road reconstruction in action? */
|
2004-08-09 17:04:08 +00:00
|
|
|
byte road_build_months;
|
|
|
|
|
2007-04-18 14:23:30 +00:00
|
|
|
/* If this is a larger town, and should grow more quickly. */
|
|
|
|
bool larger_town;
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* NOSAVE: UpdateTownRadius updates this given the house count. */
|
2008-04-15 22:27:28 +00:00
|
|
|
uint32 squared_town_zone_radius[HZB_END];
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* NOSAVE: The number of each type of building in the town. */
|
2007-03-19 11:27:30 +00:00
|
|
|
BuildingCounts building_counts;
|
2007-08-02 21:05:54 +00:00
|
|
|
|
2008-04-01 16:27:01 +00:00
|
|
|
/* NOSAVE: The town specific road layout */
|
|
|
|
TownLayout layout;
|
|
|
|
|
2007-08-02 21:05:54 +00:00
|
|
|
/**
|
|
|
|
* Creates a new town
|
|
|
|
*/
|
2009-01-03 16:06:58 +00:00
|
|
|
Town(TileIndex tile = INVALID_TILE);
|
2007-08-02 21:05:54 +00:00
|
|
|
|
|
|
|
/** Destroy the town */
|
|
|
|
~Town();
|
|
|
|
|
2009-01-03 16:06:58 +00:00
|
|
|
inline bool IsValid() const { return this->xy != INVALID_TILE; }
|
2008-04-01 16:27:01 +00:00
|
|
|
|
|
|
|
void InitializeLayout();
|
|
|
|
|
|
|
|
inline TownLayout GetActiveLayout() const;
|
2008-05-24 02:54:47 +00:00
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
return ((this->population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3);
|
2008-05-24 02:54:47 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2008-04-01 16:27:01 +00:00
|
|
|
/**
|
|
|
|
* Get the current valid layout for the town
|
|
|
|
* @return the active layout for this town
|
|
|
|
*/
|
|
|
|
inline TownLayout Town::GetActiveLayout() const
|
|
|
|
{
|
2008-05-29 15:13:28 +00:00
|
|
|
return (_settings_game.economy.town_layout == TL_RANDOM) ? this->layout : _settings_game.economy.town_layout;
|
2008-04-01 16:27:01 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 11:27:30 +00:00
|
|
|
struct HouseSpec {
|
|
|
|
/* Standard properties */
|
2008-06-03 03:06:16 +00:00
|
|
|
Year min_year; ///< introduction year of the house
|
|
|
|
Year max_year; ///< last year it can be built
|
2007-03-19 11:27:30 +00:00
|
|
|
byte population; ///< population (Zero on other tiles in multi tile house.)
|
|
|
|
byte removal_cost; ///< cost multiplier for removing it
|
2008-04-17 11:47:22 +00:00
|
|
|
StringID building_name; ///< building name
|
2007-03-19 11:27:30 +00:00
|
|
|
uint16 remove_rating_decrease; ///< rating decrease if removed
|
|
|
|
byte mail_generation; ///< mail generation multiplier (tile based, as the acceptances below)
|
2007-03-20 02:24:14 +00:00
|
|
|
byte cargo_acceptance[3]; ///< acceptance level for the cargo slots
|
|
|
|
CargoID accepts_cargo[3]; ///< 3 input cargo slots
|
2007-03-19 11:27:30 +00:00
|
|
|
BuildingFlags building_flags; ///< some flags that describe the house (size, stadium etc...)
|
|
|
|
HouseZones building_availability; ///< where can it be built (climates, zones)
|
2007-05-10 16:03:06 +00:00
|
|
|
bool enabled; ///< the house is available to build (true by default, but can be disabled by newgrf)
|
2007-03-19 11:27:30 +00:00
|
|
|
|
|
|
|
/* NewHouses properties */
|
2007-05-10 16:03:06 +00:00
|
|
|
HouseID substitute_id; ///< which original house this one is based on
|
2007-03-19 11:27:30 +00:00
|
|
|
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
|
2007-05-10 16:03:06 +00:00
|
|
|
byte minimum_life; ///< The minimum number of years this house will survive before the town rebuilds it
|
2007-03-19 11:27:30 +00:00
|
|
|
|
|
|
|
/* 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
|
2008-06-05 01:43:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cost for removing this house
|
|
|
|
* @return the cost (inflation corrected etc)
|
|
|
|
*/
|
|
|
|
Money GetRemovalCost() const;
|
|
|
|
|
2007-03-19 11:27:30 +00:00
|
|
|
};
|
|
|
|
|
2008-01-13 13:36:01 +00:00
|
|
|
extern HouseSpec _house_specs[HOUSE_MAX];
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
uint32 GetWorldPopulation();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-31 18:57:24 +00:00
|
|
|
void UpdateTownVirtCoord(Town *t);
|
2007-11-25 20:20:16 +00:00
|
|
|
void UpdateAllTownVirtCoords();
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeTown();
|
2006-03-26 22:41:56 +00:00
|
|
|
void ShowTownViewWindow(TownID town);
|
2004-08-09 17:04:08 +00:00
|
|
|
void ExpandTown(Town *t);
|
2007-04-18 14:23:30 +00:00
|
|
|
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
ROAD_REMOVE = 0,
|
|
|
|
UNMOVEABLE_REMOVE = 1,
|
|
|
|
TUNNELBRIDGE_REMOVE = 1,
|
|
|
|
INDUSTRY_REMOVE = 2
|
|
|
|
};
|
|
|
|
|
2007-04-12 17:24:34 +00:00
|
|
|
/** 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;
|
2006-04-03 14:56:07 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/** This enum is used in conjonction with town->flags12.
|
2006-04-03 14:56:07 +00:00
|
|
|
* 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 flags12...
|
|
|
|
*/
|
|
|
|
enum {
|
2007-04-04 03:21:14 +00:00
|
|
|
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.
|
2005-01-14 09:20:12 +00:00
|
|
|
};
|
|
|
|
|
2006-02-02 07:15:46 +00:00
|
|
|
bool CheckforTownRating(uint32 flags, Town *t, byte type);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-19 11:27:30 +00:00
|
|
|
static inline HouseSpec *GetHouseSpecs(HouseID house_id)
|
|
|
|
{
|
|
|
|
assert(house_id < HOUSE_MAX);
|
|
|
|
return &_house_specs[house_id];
|
|
|
|
}
|
|
|
|
|
2008-10-20 19:35:48 +00:00
|
|
|
TileIndexDiff GetHouseNorthPart(HouseID &house);
|
2008-06-25 20:04:27 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/**
|
|
|
|
* Check if a TownID is valid.
|
2007-04-18 00:41:09 +00:00
|
|
|
* @param index to inquiry in the pool of town
|
2007-04-04 03:21:14 +00:00
|
|
|
* @return true if it exists
|
|
|
|
*/
|
2006-12-09 14:18:08 +00:00
|
|
|
static inline bool IsValidTownID(TownID index)
|
|
|
|
{
|
2007-08-02 21:05:54 +00:00
|
|
|
return index < GetTownPoolSize() && GetTown(index)->IsValid();
|
2006-12-09 14:18:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static inline TownID GetMaxTownIndex()
|
2006-08-22 20:41:26 +00:00
|
|
|
{
|
|
|
|
/* TODO - This isn't the real content of the function, but
|
|
|
|
* with the new pool-system this will be replaced with one that
|
2006-12-05 13:58:20 +00:00
|
|
|
* _really_ returns the highest index. Now it just returns
|
2006-08-22 20:41:26 +00:00
|
|
|
* the next safe value we are sure about everything is below.
|
|
|
|
*/
|
2006-12-09 14:14:51 +00:00
|
|
|
return GetTownPoolSize() - 1;
|
2006-12-05 13:58:20 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static inline uint GetNumTowns()
|
2006-12-05 13:58:20 +00:00
|
|
|
{
|
2008-01-13 13:36:01 +00:00
|
|
|
extern uint _total_towns;
|
|
|
|
|
2006-08-22 21:17:19 +00:00
|
|
|
return _total_towns;
|
2006-08-22 20:41:26 +00:00
|
|
|
}
|
|
|
|
|
2006-08-22 21:14:45 +00:00
|
|
|
/**
|
|
|
|
* Return a random valid town.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
static inline Town *GetRandomTown()
|
2006-08-22 21:14:45 +00:00
|
|
|
{
|
2006-12-09 14:18:08 +00:00
|
|
|
int num = RandomRange(GetNumTowns());
|
|
|
|
TownID index = INVALID_TOWN;
|
2006-08-22 21:14:45 +00:00
|
|
|
|
2006-12-09 14:18:08 +00:00
|
|
|
while (num >= 0) {
|
2006-08-22 21:14:45 +00:00
|
|
|
num--;
|
|
|
|
|
|
|
|
index++;
|
2007-02-11 19:31:29 +00:00
|
|
|
/* Make sure we have a valid town */
|
2006-12-09 14:18:08 +00:00
|
|
|
while (!IsValidTownID(index)) {
|
2006-08-22 21:14:45 +00:00
|
|
|
index++;
|
2006-12-09 14:18:08 +00:00
|
|
|
assert(index <= GetMaxTownIndex());
|
2006-08-22 21:14:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetTown(index);
|
|
|
|
}
|
|
|
|
|
2008-01-13 13:36:01 +00:00
|
|
|
Town *CalcClosestTownFromTile(TileIndex tile, uint threshold);
|
2007-02-09 16:21:03 +00:00
|
|
|
|
2007-08-02 21:05:54 +00:00
|
|
|
#define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) if (t->IsValid())
|
2005-02-01 18:32:01 +00:00
|
|
|
#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2008-01-13 13:36:01 +00:00
|
|
|
extern Town *_cleared_town;
|
|
|
|
extern int _cleared_town_rating;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-19 11:27:30 +00:00
|
|
|
void ResetHouses();
|
|
|
|
|
|
|
|
void ClearTownHouse(Town *t, TileIndex tile);
|
2007-12-25 11:26:07 +00:00
|
|
|
void UpdateTownMaxPass(Town *t);
|
2008-03-18 12:28:21 +00:00
|
|
|
void UpdateTownRadius(Town *t);
|
2007-12-25 11:26:07 +00:00
|
|
|
bool CheckIfAuthorityAllows(TileIndex tile);
|
|
|
|
Town *ClosestTownFromTile(TileIndex tile, uint threshold);
|
|
|
|
void ChangeTownRating(Town *t, int add, int max);
|
2008-01-16 02:53:55 +00:00
|
|
|
HouseZonesBits GetTownRadiusGroup(const Town* t, TileIndex tile);
|
2008-01-09 17:47:05 +00:00
|
|
|
void SetTownRatingTestMode(bool mode);
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2008-04-01 16:27:01 +00:00
|
|
|
/**
|
|
|
|
* Calculate a hash value from a tile position
|
|
|
|
*
|
|
|
|
* @param x The X coordinate
|
|
|
|
* @param y The Y coordinate
|
|
|
|
* @return The hash of the tile
|
|
|
|
*/
|
|
|
|
static inline uint TileHash(uint x, uint y)
|
|
|
|
{
|
|
|
|
uint hash = x >> 4;
|
|
|
|
hash ^= x >> 6;
|
|
|
|
hash ^= y >> 4;
|
|
|
|
hash -= y >> 6;
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the last two bits of the TileHash
|
|
|
|
* from a tile position.
|
|
|
|
*
|
|
|
|
* @see TileHash()
|
|
|
|
* @param x The X coordinate
|
|
|
|
* @param y The Y coordinate
|
|
|
|
* @return The last two bits from hash of the tile
|
|
|
|
*/
|
|
|
|
static inline uint TileHash2Bit(uint x, uint y)
|
|
|
|
{
|
|
|
|
return GB(TileHash(x, y), 0, 2);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif /* TOWN_H */
|