2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 21:21:05 +01:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 16:11:33 +01:00
|
|
|
/** @file town.h Base of the town class. */
|
2007-04-04 04:21:14 +01:00
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
#ifndef TOWN_H
|
|
|
|
#define TOWN_H
|
|
|
|
|
2009-05-22 16:39:22 +01:00
|
|
|
#include "core/pool_type.hpp"
|
2008-04-01 17:27:01 +01: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 21:51:04 +01:00
|
|
|
#include "company_type.h"
|
2008-04-01 17:27:01 +01:00
|
|
|
#include "settings_type.h"
|
2008-04-17 12:47:22 +01:00
|
|
|
#include "strings_type.h"
|
2008-05-07 14:10:15 +01:00
|
|
|
#include "viewport_type.h"
|
2008-06-05 02:43:03 +01:00
|
|
|
#include "economy_type.h"
|
2008-10-20 20:46:49 +01:00
|
|
|
#include "map_type.h"
|
2009-02-09 21:20:05 +00:00
|
|
|
#include "command_type.h"
|
2009-06-26 14:44:14 +01:00
|
|
|
#include "town_map.h"
|
2009-08-08 17:42:55 +01:00
|
|
|
#include "subsidy_type.h"
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2009-03-17 19:40:10 +00:00
|
|
|
template <typename T>
|
2007-03-19 11:27:30 +00:00
|
|
|
struct BuildingCounts {
|
2009-03-17 19:40:10 +00:00
|
|
|
T id_count[HOUSE_MAX];
|
|
|
|
T class_count[HOUSE_CLASS_MAX];
|
2006-12-09 14:18:08 +00:00
|
|
|
};
|
|
|
|
|
2009-03-13 00:48:03 +00:00
|
|
|
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
|
2009-03-12 23:54:20 +00:00
|
|
|
|
2009-06-26 14:44:14 +01:00
|
|
|
static const uint INVALID_TOWN = 0xFFFF;
|
|
|
|
|
2009-05-22 16:13:50 +01:00
|
|
|
typedef Pool<Town, TownID, 64, 64000> TownPool;
|
|
|
|
extern TownPool _town_pool;
|
2007-08-02 22:05:54 +01:00
|
|
|
|
2009-05-22 16:13:50 +01:00
|
|
|
struct Town : TownPool::PoolItem<&_town_pool> {
|
2004-08-09 18:04:08 +01:00
|
|
|
TileIndex xy;
|
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* Current population of people and amount of houses. */
|
2008-03-18 12:28:21 +00:00
|
|
|
uint32 num_houses;
|
2004-08-09 18:04:08 +01:00
|
|
|
uint32 population;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* Town name */
|
2007-06-19 00:00:55 +01:00
|
|
|
uint32 townnamegrfid;
|
2004-08-09 18:04:08 +01:00
|
|
|
uint16 townnametype;
|
|
|
|
uint32 townnameparts;
|
2008-01-12 19:58:06 +00:00
|
|
|
char *name;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2009-07-13 23:33:25 +01:00
|
|
|
/* NOSAVE: Location of name sign, UpdateVirtCoord updates this. */
|
2004-08-09 18:04:08 +01:00
|
|
|
ViewportSign sign;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* Makes sure we don't build certain house types twice.
|
|
|
|
* bit 0 = Building funds received
|
|
|
|
* bit 1 = CHURCH
|
|
|
|
* bit 2 = STADIUM */
|
2009-06-23 10:52:26 +01:00
|
|
|
byte flags;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-24 03:54:47 +01:00
|
|
|
/* level of noise that all the airports are generating */
|
|
|
|
uint16 noise_reached;
|
|
|
|
|
2008-09-30 21:39:50 +01:00
|
|
|
/* Which companies have a statue? */
|
2008-12-23 21:03:43 +00:00
|
|
|
CompanyMask statues;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-09-30 21:39:50 +01: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 20:02:27 +01:00
|
|
|
|
2007-04-04 04:21:14 +01: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 18:04:08 +01:00
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* Amount of passengers that were transported. */
|
2004-08-09 18:04:08 +01:00
|
|
|
byte pct_pass_transported;
|
|
|
|
byte pct_mail_transported;
|
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* Amount of food and paper that was transported. Actually a bit mask would be enough. */
|
2004-08-09 18:04:08 +01:00
|
|
|
uint16 act_food;
|
2004-08-10 15:42:52 +01:00
|
|
|
uint16 act_water;
|
2004-08-09 18:04:08 +01:00
|
|
|
uint16 new_act_food;
|
2004-08-10 15:42:52 +01:00
|
|
|
uint16 new_act_water;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* Time until we rebuild a house. */
|
2007-04-12 18:24:34 +01:00
|
|
|
uint16 time_until_rebuild;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* When to grow town next time. */
|
2007-04-12 18:24:34 +01:00
|
|
|
uint16 grow_counter;
|
|
|
|
int16 growth_rate;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* Fund buildings program in action? */
|
2004-08-09 18:04:08 +01:00
|
|
|
byte fund_buildings_months;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* Fund road reconstruction in action? */
|
2004-08-09 18:04:08 +01:00
|
|
|
byte road_build_months;
|
|
|
|
|
2007-04-18 15:23:30 +01:00
|
|
|
/* If this is a larger town, and should grow more quickly. */
|
|
|
|
bool larger_town;
|
2009-02-04 20:17:25 +00:00
|
|
|
TownLayoutByte layout; ///< town specific road layout
|
2007-04-18 15:23:30 +01:00
|
|
|
|
2009-08-08 17:42:55 +01:00
|
|
|
PartOfSubsidyByte part_of_subsidy; ///< NOSAVE: is this town a source/destination of a subsidy?
|
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* NOSAVE: UpdateTownRadius updates this given the house count. */
|
2008-04-15 23:27:28 +01:00
|
|
|
uint32 squared_town_zone_radius[HZB_END];
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2007-04-04 04:21:14 +01:00
|
|
|
/* NOSAVE: The number of each type of building in the town. */
|
2009-03-17 19:40:10 +00:00
|
|
|
BuildingCounts<uint16> building_counts;
|
2007-08-02 22:05:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new town
|
|
|
|
*/
|
2009-05-22 16:13:50 +01:00
|
|
|
Town(TileIndex tile = INVALID_TILE) : xy(tile) { }
|
2007-08-02 22:05:54 +01:00
|
|
|
|
|
|
|
/** Destroy the town */
|
|
|
|
~Town();
|
|
|
|
|
2009-02-04 22:52:34 +00:00
|
|
|
void InitializeLayout(TownLayout layout);
|
2008-04-01 17:27:01 +01:00
|
|
|
|
2008-05-24 03:54:47 +01: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 */
|
2009-02-04 20:17:25 +00:00
|
|
|
inline uint16 MaxTownNoise() const
|
|
|
|
{
|
2008-05-24 03:54:47 +01:00
|
|
|
if (this->population == 0) return 0; // no population? no noise
|
|
|
|
|
2008-05-29 16:13:28 +01:00
|
|
|
return ((this->population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3);
|
2008-05-24 03:54:47 +01:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2009-07-13 23:33:25 +01:00
|
|
|
void UpdateVirtCoord();
|
|
|
|
|
2009-06-26 14:46:23 +01:00
|
|
|
static FORCEINLINE Town *GetByTile(TileIndex tile)
|
|
|
|
{
|
|
|
|
return Town::Get(GetTownIndex(tile));
|
|
|
|
}
|
2009-06-26 16:08:54 +01:00
|
|
|
|
|
|
|
static Town *GetRandom();
|
2009-07-05 14:21:51 +01:00
|
|
|
static void PostDestructor(size_t index);
|
2009-06-26 14:46:23 +01:00
|
|
|
};
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
uint32 GetWorldPopulation();
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-11-25 20:20:16 +00:00
|
|
|
void UpdateAllTownVirtCoords();
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeTown();
|
2006-03-26 23:41:56 +01:00
|
|
|
void ShowTownViewWindow(TownID town);
|
2004-08-09 18:04:08 +01:00
|
|
|
void ExpandTown(Town *t);
|
2009-02-05 13:33:37 +00:00
|
|
|
Town *CreateRandomTown(uint attempts, TownSize size, bool city, TownLayout layout);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2009-05-11 12:55:41 +01:00
|
|
|
enum TownRatingCheckType {
|
2009-03-12 01:35:27 +00:00
|
|
|
ROAD_REMOVE = 0,
|
2004-08-09 18:04:08 +01:00
|
|
|
TUNNELBRIDGE_REMOVE = 1,
|
2009-05-11 12:55:41 +01:00
|
|
|
TOWN_RATING_CHECK_TYPE_COUNT,
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2007-04-12 18:24:34 +01: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;
|
|
|
|
|
2009-06-23 10:52:26 +01:00
|
|
|
/** This enum is used in conjonction with town->flags.
|
2006-04-03 15:56:07 +01: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.
|
2009-06-23 10:52:26 +01:00
|
|
|
* And there are 5 more bits available on flags...
|
2006-04-03 15:56:07 +01:00
|
|
|
*/
|
|
|
|
enum {
|
2007-04-04 04:21:14 +01: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
|
|
|
};
|
|
|
|
|
2009-05-11 12:55:41 +01:00
|
|
|
bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2008-10-20 20:35:48 +01:00
|
|
|
TileIndexDiff GetHouseNorthPart(HouseID &house);
|
2008-06-25 21:04:27 +01:00
|
|
|
|
2009-07-05 14:21:51 +01:00
|
|
|
Town *CalcClosestTownFromTile(TileIndex tile, uint threshold = UINT_MAX);
|
2007-02-09 16:21:03 +00:00
|
|
|
|
2009-05-22 15:23:36 +01:00
|
|
|
#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)
|
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 18:04:08 +01: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);
|
2009-02-09 21:20:05 +00:00
|
|
|
bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
|
2007-12-25 11:26:07 +00:00
|
|
|
Town *ClosestTownFromTile(TileIndex tile, uint threshold);
|
2009-02-11 18:50:47 +00:00
|
|
|
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags);
|
2009-01-10 00:31:47 +00:00
|
|
|
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
|
2008-01-09 17:47:05 +00:00
|
|
|
void SetTownRatingTestMode(bool mode);
|
2009-01-19 12:07:01 +00:00
|
|
|
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
|
2009-02-04 22:52:34 +00:00
|
|
|
bool GenerateTowns(TownLayout layout);
|
2009-02-16 23:23:33 +00:00
|
|
|
bool GenerateTownName(uint32 *townnameparts);
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2008-04-01 17:27:01 +01: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 18:04:08 +01:00
|
|
|
#endif /* TOWN_H */
|