4 |
4 |
5 #ifndef TOWN_H |
5 #ifndef TOWN_H |
6 #define TOWN_H |
6 #define TOWN_H |
7 |
7 |
8 #include "oldpool.h" |
8 #include "oldpool.h" |
|
9 #include "core/bitmath_func.hpp" |
9 #include "core/random_func.hpp" |
10 #include "core/random_func.hpp" |
10 #include "cargo_type.h" |
11 #include "cargo_type.h" |
11 #include "tile_type.h" |
12 #include "tile_type.h" |
12 #include "date_type.h" |
13 #include "date_type.h" |
13 #include "town_type.h" |
14 #include "town_type.h" |
14 #include "player_type.h" |
15 #include "player_type.h" |
15 #include "newgrf_string_type.h" |
16 #include "newgrf_string_type.h" |
|
17 #include "settings_type.h" |
16 |
18 |
17 enum { |
19 enum { |
18 HOUSE_NO_CLASS = 0, |
20 HOUSE_NO_CLASS = 0, |
19 NEW_HOUSE_OFFSET = 110, |
21 NEW_HOUSE_OFFSET = 110, |
20 HOUSE_MAX = 512, |
22 HOUSE_MAX = 512, |
43 }; |
45 }; |
44 |
46 |
45 DECLARE_ENUM_AS_BIT_SET(BuildingFlags) |
47 DECLARE_ENUM_AS_BIT_SET(BuildingFlags) |
46 |
48 |
47 enum HouseZonesBits { |
49 enum HouseZonesBits { |
|
50 HZB_BEGIN = 0, |
48 HZB_TOWN_EDGE = 0, |
51 HZB_TOWN_EDGE = 0, |
49 HZB_TOWN_OUTSKIRT, |
52 HZB_TOWN_OUTSKIRT, |
50 HZB_TOWN_OUTER_SUBURB, |
53 HZB_TOWN_OUTER_SUBURB, |
51 HZB_TOWN_INNER_SUBURB, |
54 HZB_TOWN_INNER_SUBURB, |
52 HZB_TOWN_CENTRE, |
55 HZB_TOWN_CENTRE, |
53 }; |
56 HZB_END, |
|
57 }; |
|
58 assert_compile(HZB_END == 5); |
|
59 |
|
60 DECLARE_POSTFIX_INCREMENT(HouseZonesBits) |
54 |
61 |
55 enum HouseZones { ///< Bit Value Meaning |
62 enum HouseZones { ///< Bit Value Meaning |
56 HZ_NOZNS = 0x0000, ///< 0 This is just to get rid of zeros, meaning none |
63 HZ_NOZNS = 0x0000, ///< 0 This is just to get rid of zeros, meaning none |
57 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 |
64 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 |
58 HZ_ZON2 = 1U << HZB_TOWN_OUTSKIRT, |
65 HZ_ZON2 = 1U << HZB_TOWN_OUTSKIRT, |
154 |
161 |
155 /* If this is a larger town, and should grow more quickly. */ |
162 /* If this is a larger town, and should grow more quickly. */ |
156 bool larger_town; |
163 bool larger_town; |
157 |
164 |
158 /* NOSAVE: UpdateTownRadius updates this given the house count. */ |
165 /* NOSAVE: UpdateTownRadius updates this given the house count. */ |
159 uint16 radius[5]; |
166 uint16 radius[HZB_END]; |
160 |
167 |
161 /* NOSAVE: The number of each type of building in the town. */ |
168 /* NOSAVE: The number of each type of building in the town. */ |
162 BuildingCounts building_counts; |
169 BuildingCounts building_counts; |
|
170 |
|
171 /* NOSAVE: The town specific road layout */ |
|
172 TownLayout layout; |
163 |
173 |
164 /** |
174 /** |
165 * Creates a new town |
175 * Creates a new town |
166 */ |
176 */ |
167 Town(TileIndex tile = 0); |
177 Town(TileIndex tile = 0); |
168 |
178 |
169 /** Destroy the town */ |
179 /** Destroy the town */ |
170 ~Town(); |
180 ~Town(); |
171 |
181 |
172 inline bool IsValid() const { return this->xy != 0; } |
182 inline bool IsValid() const { return this->xy != 0; } |
173 }; |
183 |
|
184 void InitializeLayout(); |
|
185 |
|
186 inline TownLayout GetActiveLayout() const; |
|
187 }; |
|
188 |
|
189 /** |
|
190 * Get the current valid layout for the town |
|
191 * @return the active layout for this town |
|
192 */ |
|
193 inline TownLayout Town::GetActiveLayout() const |
|
194 { |
|
195 return (_patches.town_layout == TL_RANDOM) ? this->layout : _patches.town_layout; |
|
196 } |
174 |
197 |
175 struct HouseSpec { |
198 struct HouseSpec { |
176 /* Standard properties */ |
199 /* Standard properties */ |
177 Year min_date; ///< introduction year of the house |
200 Year min_date; ///< introduction year of the house |
178 Year max_date; ///< last year it can be built |
201 Year max_date; ///< last year it can be built |
312 extern const Town **_town_sort; |
335 extern const Town **_town_sort; |
313 |
336 |
314 extern Town *_cleared_town; |
337 extern Town *_cleared_town; |
315 extern int _cleared_town_rating; |
338 extern int _cleared_town_rating; |
316 |
339 |
317 uint OriginalTileRandomiser(uint x, uint y); |
|
318 void ResetHouses(); |
340 void ResetHouses(); |
319 |
341 |
320 void ClearTownHouse(Town *t, TileIndex tile); |
342 void ClearTownHouse(Town *t, TileIndex tile); |
321 void AfterLoadTown(); |
343 void AfterLoadTown(); |
322 void UpdateTownMaxPass(Town *t); |
344 void UpdateTownMaxPass(Town *t); |
325 Town *ClosestTownFromTile(TileIndex tile, uint threshold); |
347 Town *ClosestTownFromTile(TileIndex tile, uint threshold); |
326 void ChangeTownRating(Town *t, int add, int max); |
348 void ChangeTownRating(Town *t, int add, int max); |
327 HouseZonesBits GetTownRadiusGroup(const Town* t, TileIndex tile); |
349 HouseZonesBits GetTownRadiusGroup(const Town* t, TileIndex tile); |
328 void SetTownRatingTestMode(bool mode); |
350 void SetTownRatingTestMode(bool mode); |
329 |
351 |
|
352 /** |
|
353 * Calculate a hash value from a tile position |
|
354 * |
|
355 * @param x The X coordinate |
|
356 * @param y The Y coordinate |
|
357 * @return The hash of the tile |
|
358 */ |
|
359 static inline uint TileHash(uint x, uint y) |
|
360 { |
|
361 uint hash = x >> 4; |
|
362 hash ^= x >> 6; |
|
363 hash ^= y >> 4; |
|
364 hash -= y >> 6; |
|
365 return hash; |
|
366 } |
|
367 |
|
368 /** |
|
369 * Get the last two bits of the TileHash |
|
370 * from a tile position. |
|
371 * |
|
372 * @see TileHash() |
|
373 * @param x The X coordinate |
|
374 * @param y The Y coordinate |
|
375 * @return The last two bits from hash of the tile |
|
376 */ |
|
377 static inline uint TileHash2Bit(uint x, uint y) |
|
378 { |
|
379 return GB(TileHash(x, y), 0, 2); |
|
380 } |
|
381 |
330 #endif /* TOWN_H */ |
382 #endif /* TOWN_H */ |