town.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef TOWN_H
00013 #define TOWN_H
00014
00015 #include "core/pool_type.hpp"
00016 #include "core/bitmath_func.hpp"
00017 #include "core/random_func.hpp"
00018 #include "cargo_type.h"
00019 #include "tile_type.h"
00020 #include "date_type.h"
00021 #include "town_type.h"
00022 #include "company_type.h"
00023 #include "settings_type.h"
00024 #include "strings_type.h"
00025 #include "viewport_type.h"
00026 #include "economy_type.h"
00027 #include "map_type.h"
00028 #include "command_type.h"
00029 #include "town_map.h"
00030 #include "subsidy_type.h"
00031
00032 template <typename T>
00033 struct BuildingCounts {
00034 T id_count[HOUSE_MAX];
00035 T class_count[HOUSE_CLASS_MAX];
00036 };
00037
00038 static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY = 4;
00039 static const uint CUSTOM_TOWN_MAX_NUMBER = 5000;
00040
00041 static const uint INVALID_TOWN = 0xFFFF;
00042
00043 typedef Pool<Town, TownID, 64, 64000> TownPool;
00044 extern TownPool _town_pool;
00045
00046 struct Town : TownPool::PoolItem<&_town_pool> {
00047 TileIndex xy;
00048
00049
00050 uint32 num_houses;
00051 uint32 population;
00052
00053
00054 uint32 townnamegrfid;
00055 uint16 townnametype;
00056 uint32 townnameparts;
00057 char *name;
00058
00059
00060 ViewportSign sign;
00061
00062
00063
00064
00065
00066 byte flags;
00067
00068
00069 uint16 noise_reached;
00070
00071
00072 CompanyMask statues;
00073
00074
00075 CompanyMask have_ratings;
00076 uint8 unwanted[MAX_COMPANIES];
00077 CompanyByte exclusivity;
00078 uint8 exclusive_counter;
00079 int16 ratings[MAX_COMPANIES];
00080
00081
00082 uint32 max_pass;
00083 uint32 max_mail;
00084 uint32 new_max_pass;
00085 uint32 new_max_mail;
00086 uint32 act_pass;
00087 uint32 act_mail;
00088 uint32 new_act_pass;
00089 uint32 new_act_mail;
00090
00091
00092 byte pct_pass_transported;
00093 byte pct_mail_transported;
00094
00095
00096 uint16 act_food;
00097 uint16 act_water;
00098 uint16 new_act_food;
00099 uint16 new_act_water;
00100
00101
00102 uint16 time_until_rebuild;
00103
00104
00105 uint16 grow_counter;
00106 int16 growth_rate;
00107
00108
00109 byte fund_buildings_months;
00110
00111
00112 byte road_build_months;
00113
00114
00115 bool larger_town;
00116 TownLayoutByte layout;
00117
00118 PartOfSubsidyByte part_of_subsidy;
00119
00120
00121 uint32 squared_town_zone_radius[HZB_END];
00122
00123
00124 BuildingCounts<uint16> building_counts;
00125
00129 Town(TileIndex tile = INVALID_TILE) : xy(tile) { }
00130
00132 ~Town();
00133
00134 void InitializeLayout(TownLayout layout);
00135
00142 inline uint16 MaxTownNoise() const
00143 {
00144 if (this->population == 0) return 0;
00145
00146 return ((this->population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3);
00147 }
00148
00149 void UpdateVirtCoord();
00150
00151 static FORCEINLINE Town *GetByTile(TileIndex tile)
00152 {
00153 return Town::Get(GetTownIndex(tile));
00154 }
00155
00156 static Town *GetRandom();
00157 static void PostDestructor(size_t index);
00158 };
00159
00160 uint32 GetWorldPopulation();
00161
00162 void UpdateAllTownVirtCoords();
00163 void InitializeTown();
00164 void ShowTownViewWindow(TownID town);
00165 void ExpandTown(Town *t);
00166
00167 enum TownRatingCheckType {
00168 ROAD_REMOVE = 0,
00169 TUNNELBRIDGE_REMOVE = 1,
00170 TOWN_RATING_CHECK_TYPE_COUNT,
00171 };
00172
00176 static const byte TOWN_GROWTH_FREQUENCY = 70;
00177
00184 enum {
00185 TOWN_IS_FUNDED = 0,
00186 TOWN_HAS_CHURCH = 1,
00187 TOWN_HAS_STADIUM = 2
00188 };
00189
00190 bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type);
00191
00192
00193 TileIndexDiff GetHouseNorthPart(HouseID &house);
00194
00195 Town *CalcClosestTownFromTile(TileIndex tile, uint threshold = UINT_MAX);
00196
00197 #define FOR_ALL_TOWNS_FROM(var, start) FOR_ALL_ITEMS_FROM(Town, town_index, var, start)
00198 #define FOR_ALL_TOWNS(var) FOR_ALL_TOWNS_FROM(var, 0)
00199
00200 void ResetHouses();
00201
00202 void ClearTownHouse(Town *t, TileIndex tile);
00203 void UpdateTownMaxPass(Town *t);
00204 void UpdateTownRadius(Town *t);
00205 bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
00206 Town *ClosestTownFromTile(TileIndex tile, uint threshold);
00207 void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags);
00208 HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
00209 void SetTownRatingTestMode(bool mode);
00210 uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
00211 bool GenerateTowns(TownLayout layout);
00212
00213
00215 enum TownActions {
00216 TACT_NONE = 0x00,
00217
00218 TACT_ADVERTISE_SMALL = 0x01,
00219 TACT_ADVERTISE_MEDIUM = 0x02,
00220 TACT_ADVERTISE_LARGE = 0x04,
00221 TACT_ROAD_REBUILD = 0x08,
00222 TACT_BUILD_STATUE = 0x10,
00223 TACT_FOUND_BUILDINGS = 0x20,
00224 TACT_BUY_RIGHTS = 0x40,
00225 TACT_BRIBE = 0x80,
00226
00227 TACT_COUNT = 8,
00228
00229 TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE,
00230 TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS,
00231 TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE,
00232 TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS,
00233 };
00234 DECLARE_ENUM_AS_BIT_SET(TownActions);
00235
00236 extern const byte _town_action_costs[TACT_COUNT];
00237 extern TownID _new_town_id;
00238
00246 static inline uint TileHash(uint x, uint y)
00247 {
00248 uint hash = x >> 4;
00249 hash ^= x >> 6;
00250 hash ^= y >> 4;
00251 hash -= y >> 6;
00252 return hash;
00253 }
00254
00264 static inline uint TileHash2Bit(uint x, uint y)
00265 {
00266 return GB(TileHash(x, y), 0, 2);
00267 }
00268
00269 #endif