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 "viewport_type.h"
00017 #include "command_type.h"
00018 #include "town_map.h"
00019 #include "subsidy_type.h"
00020 #include "newgrf_storage.h"
00021 #include "cargotype.h"
00022 #include "tilematrix_type.hpp"
00023 #include <list>
00024
00025 template <typename T>
00026 struct BuildingCounts {
00027 T id_count[HOUSE_MAX];
00028 T class_count[HOUSE_CLASS_MAX];
00029 };
00030
00031 typedef TileMatrix<uint32, 4> AcceptanceMatrix;
00032
00033 static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY = 4;
00034 static const uint CUSTOM_TOWN_MAX_NUMBER = 5000;
00035
00036 static const uint INVALID_TOWN = 0xFFFF;
00037
00038 static const uint TOWN_GROWTH_WINTER = 0xFFFFFFFE;
00039 static const uint TOWN_GROWTH_DESERT = 0xFFFFFFFF;
00040 static const uint16 TOWN_GROW_RATE_CUSTOM = 0x8000;
00041
00042 typedef Pool<Town, TownID, 64, 64000> TownPool;
00043 extern TownPool _town_pool;
00044
00046 struct Town : TownPool::PoolItem<&_town_pool> {
00047 TileIndex xy;
00048
00049 uint32 num_houses;
00050 uint32 population;
00051
00052
00053 uint32 townnamegrfid;
00054 uint16 townnametype;
00055 uint32 townnameparts;
00056 char *name;
00057
00058 ViewportSign sign;
00059
00060
00061
00062
00063
00064 byte flags;
00065
00066 uint16 noise_reached;
00067
00068 CompanyMask statues;
00069
00070
00071 CompanyMask have_ratings;
00072 uint8 unwanted[MAX_COMPANIES];
00073 CompanyByte exclusivity;
00074 uint8 exclusive_counter;
00075 int16 ratings[MAX_COMPANIES];
00076
00077 TransportedCargoStat<uint32> supplied[NUM_CARGO];
00078 TransportedCargoStat<uint16> received[NUM_TE];
00079 uint32 goal[NUM_TE];
00080
00081 char *text;
00082
00083 inline byte GetPercentTransported(CargoID cid) const { return this->supplied[cid].old_act * 256 / (this->supplied[cid].old_max + 1); }
00084
00085
00086 uint32 cargo_produced;
00087 AcceptanceMatrix cargo_accepted;
00088 uint32 cargo_accepted_total;
00089
00090 uint16 time_until_rebuild;
00091
00092 uint16 grow_counter;
00093 uint16 growth_rate;
00094
00095 byte fund_buildings_months;
00096 byte road_build_months;
00097
00098 bool larger_town;
00099 TownLayoutByte layout;
00100
00101 std::list<PersistentStorage *> psa_list;
00102
00103 PartOfSubsidyByte part_of_subsidy;
00104
00105 uint32 squared_town_zone_radius[HZB_END];
00106
00107 BuildingCounts<uint16> building_counts;
00108
00113 Town(TileIndex tile = INVALID_TILE) : xy(tile) { }
00114
00116 ~Town();
00117
00118 void InitializeLayout(TownLayout layout);
00119
00126 inline uint16 MaxTownNoise() const
00127 {
00128 if (this->population == 0) return 0;
00129
00130
00131 return (this->population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3;
00132 }
00133
00134 void UpdateVirtCoord();
00135
00136 static inline Town *GetByTile(TileIndex tile)
00137 {
00138 return Town::Get(GetTownIndex(tile));
00139 }
00140
00141 static Town *GetRandom();
00142 static void PostDestructor(size_t index);
00143 };
00144
00145 uint32 GetWorldPopulation();
00146
00147 void UpdateAllTownVirtCoords();
00148 void ShowTownViewWindow(TownID town);
00149 void ExpandTown(Town *t);
00150
00155 enum TownRatingCheckType {
00156 ROAD_REMOVE = 0,
00157 TUNNELBRIDGE_REMOVE = 1,
00158 TOWN_RATING_CHECK_TYPE_COUNT,
00159 };
00160
00168 enum TownFlags {
00169 TOWN_IS_FUNDED = 0,
00170 TOWN_HAS_CHURCH = 1,
00171 TOWN_HAS_STADIUM = 2,
00172 };
00173
00174 CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type);
00175
00176
00177 TileIndexDiff GetHouseNorthPart(HouseID &house);
00178
00179 Town *CalcClosestTownFromTile(TileIndex tile, uint threshold = UINT_MAX);
00180
00181 #define FOR_ALL_TOWNS_FROM(var, start) FOR_ALL_ITEMS_FROM(Town, town_index, var, start)
00182 #define FOR_ALL_TOWNS(var) FOR_ALL_TOWNS_FROM(var, 0)
00183
00184 void ResetHouses();
00185
00186 void ClearTownHouse(Town *t, TileIndex tile);
00187 void UpdateTownMaxPass(Town *t);
00188 void UpdateTownRadius(Town *t);
00189 void UpdateTownCargoes(Town *t);
00190 void UpdateTownCargoTotal(Town *t);
00191 void UpdateTownCargoBitmap();
00192 CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
00193 Town *ClosestTownFromTile(TileIndex tile, uint threshold);
00194 void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags);
00195 HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
00196 void SetTownRatingTestMode(bool mode);
00197 uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
00198 bool GenerateTowns(TownLayout layout);
00199 const CargoSpec *FindFirstCargoWithTownEffect(TownEffect effect);
00200
00201
00203 enum TownActions {
00204 TACT_NONE = 0x00,
00205
00206 TACT_ADVERTISE_SMALL = 0x01,
00207 TACT_ADVERTISE_MEDIUM = 0x02,
00208 TACT_ADVERTISE_LARGE = 0x04,
00209 TACT_ROAD_REBUILD = 0x08,
00210 TACT_BUILD_STATUE = 0x10,
00211 TACT_FUND_BUILDINGS = 0x20,
00212 TACT_BUY_RIGHTS = 0x40,
00213 TACT_BRIBE = 0x80,
00214
00215 TACT_COUNT = 8,
00216
00217 TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE,
00218 TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FUND_BUILDINGS,
00219 TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE,
00220 TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS,
00221 };
00222 DECLARE_ENUM_AS_BIT_SET(TownActions)
00223
00224 extern const byte _town_action_costs[TACT_COUNT];
00225 extern TownID _new_town_id;
00226
00232 template <class T>
00233 void MakeDefaultName(T *obj)
00234 {
00235
00236 assert(obj->name == NULL || obj->town_cn == UINT16_MAX);
00237
00238 obj->town = ClosestTownFromTile(obj->xy, UINT_MAX);
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 uint32 used = 0;
00252 uint32 next = 0;
00253 uint32 idx = 0;
00254 uint32 cid = 0;
00255
00256 do {
00257 T *lobj = T::GetIfValid(cid);
00258
00259
00260 if (lobj != NULL && obj != lobj) {
00261
00262 if (lobj->town == obj->town && lobj->IsOfType(obj)) {
00263
00264 uint i = (uint)lobj->town_cn - next;
00265
00266 if (i < 32) {
00267 SetBit(used, i);
00268 if (i == 0) {
00269
00270
00271 do {
00272 used >>= 1;
00273 next++;
00274 } while (HasBit(used, 0));
00275
00276
00277
00278 idx = cid;
00279 }
00280 }
00281 }
00282 }
00283
00284 cid++;
00285 if (cid == T::GetPoolSize()) cid = 0;
00286 } while (cid != idx);
00287
00288 obj->town_cn = (uint16)next;
00289 }
00290
00291 extern uint32 _town_cargoes_accepted;
00292
00293 #endif