author | KUDr |
Sat, 21 Apr 2007 08:23:57 +0000 | |
branch | cpp_gui |
changeset 6308 | 646711c5feaa |
parent 6307 | f40e88cff863 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6307 | 3 |
/** @file town.h */ |
4 |
||
0 | 5 |
#ifndef TOWN_H |
6 |
#define TOWN_H |
|
7 |
||
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
4983
diff
changeset
|
8 |
#include "oldpool.h" |
0 | 9 |
#include "player.h" |
6303 | 10 |
#include "functions.h" |
11 |
#include "helpers.hpp" |
|
0 | 12 |
|
5299
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
13 |
enum { |
6303 | 14 |
HOUSE_NO_CLASS = 0, |
15 |
NEW_HOUSE_OFFSET = 110, |
|
16 |
HOUSE_MAX = 512, |
|
17 |
INVALID_TOWN = 0xFFFF, |
|
18 |
INVALID_HOUSE_ID = 0xFFFF, |
|
19 |
||
20 |
/* There can only be as many classes as there are new houses, plus one for |
|
21 |
* NO_CLASS, as the original houses don't have classes. */ |
|
22 |
HOUSE_CLASS_MAX = HOUSE_MAX - NEW_HOUSE_OFFSET + 1, |
|
23 |
}; |
|
24 |
||
25 |
enum BuildingFlags { |
|
26 |
TILE_NO_FLAG = 0, |
|
27 |
TILE_SIZE_1x1 = 1U << 0, |
|
28 |
TILE_NOT_SLOPED = 1U << 1, |
|
29 |
TILE_SIZE_2x1 = 1U << 2, |
|
30 |
TILE_SIZE_1x2 = 1U << 3, |
|
31 |
TILE_SIZE_2x2 = 1U << 4, |
|
32 |
BUILDING_IS_ANIMATED = 1U << 5, |
|
33 |
BUILDING_IS_CHURCH = 1U << 6, |
|
34 |
BUILDING_IS_STADIUM = 1U << 7, |
|
35 |
BUILDING_HAS_1_TILE = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2, |
|
36 |
BUILDING_2_TILES_X = TILE_SIZE_2x1 | TILE_SIZE_2x2, |
|
37 |
BUILDING_2_TILES_Y = TILE_SIZE_1x2 | TILE_SIZE_2x2, |
|
38 |
BUILDING_HAS_4_TILES = TILE_SIZE_2x2, |
|
39 |
}; |
|
40 |
||
41 |
DECLARE_ENUM_AS_BIT_SET(BuildingFlags) |
|
42 |
||
43 |
enum HouseZones { ///< Bit Value Meaning |
|
44 |
HZ_NOZNS = 0x0000, ///< 0 This is just to get rid of zeros, meaning none |
|
45 |
HZ_ZON1 = 0x0001, ///< 0..4 1,2,4,8,10 which town zones the building can be built in, Zone1 been the further suburb |
|
46 |
HZ_ZON2 = 0x0002, |
|
47 |
HZ_ZON3 = 0x0004, |
|
48 |
HZ_ZON4 = 0x0008, |
|
49 |
HZ_ZON5 = 0x0010, ///< center of town |
|
50 |
HZ_ZONALL = 0x001F, ///< 1F This is just to englobe all above types at once |
|
51 |
HZ_SUBARTC_ABOVE = 0x0800, ///< 11 800 can appear in sub-arctic climate above the snow line |
|
52 |
HZ_TEMP = 0x1000, ///< 12 1000 can appear in temperate climate |
|
53 |
HZ_SUBARTC_BELOW = 0x2000, ///< 13 2000 can appear in sub-arctic climate below the snow line |
|
54 |
HZ_SUBTROPIC = 0x4000, ///< 14 4000 can appear in subtropical climate |
|
55 |
HZ_TOYLND = 0x8000 ///< 15 8000 can appear in toyland climate |
|
56 |
}; |
|
57 |
||
58 |
DECLARE_ENUM_AS_BIT_SET(HouseZones) |
|
59 |
||
60 |
enum HouseExtraFlags { |
|
61 |
NO_EXTRA_FLAG = 0, |
|
62 |
BUILDING_IS_HISTORICAL = 1U << 0, ///< this house will only appear during town generation in random games, thus the historical |
|
63 |
BUILDING_IS_PROTECTED = 1U << 1, ///< towns and AI will not remove this house, while human players will be able tp |
|
64 |
SYNCHRONISED_CALLBACK_1B = 1U << 2, ///< synchronized callback 1B will be performed, on multi tile houses |
|
65 |
CALLBACK_1A_RANDOM_BITS = 1U << 3, ///< callback 1A needs random bits |
|
66 |
}; |
|
67 |
||
68 |
DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags) |
|
69 |
||
70 |
typedef uint16 HouseID; |
|
71 |
typedef uint16 HouseClassID; |
|
72 |
||
73 |
struct BuildingCounts { |
|
74 |
uint8 id_count[HOUSE_MAX]; |
|
75 |
uint8 class_count[HOUSE_CLASS_MAX]; |
|
5299
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
76 |
}; |
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
77 |
|
0 | 78 |
struct Town { |
79 |
TileIndex xy; |
|
80 |
||
6307 | 81 |
/* Current population of people and amount of houses. */ |
0 | 82 |
uint16 num_houses; |
83 |
uint32 population; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
84 |
|
6307 | 85 |
/* Town name */ |
0 | 86 |
uint16 townnametype; |
87 |
uint32 townnameparts; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
88 |
|
6307 | 89 |
/* NOSAVE: Location of name sign, UpdateTownVirtCoord updates this. */ |
0 | 90 |
ViewportSign sign; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
91 |
|
6307 | 92 |
/* Makes sure we don't build certain house types twice. |
93 |
* bit 0 = Building funds received |
|
94 |
* bit 1 = CHURCH |
|
95 |
* bit 2 = STADIUM */ |
|
0 | 96 |
byte flags12; |
97 |
||
6307 | 98 |
/* Which players have a statue? */ |
0 | 99 |
byte statues; |
100 |
||
6307 | 101 |
/* Player ratings as well as a mask that determines which players have a rating. */ |
0 | 102 |
byte have_ratings; |
6307 | 103 |
uint8 unwanted[MAX_PLAYERS]; ///< how many months companies aren't wanted by towns (bribe) |
104 |
PlayerByte exclusivity; ///< which player has exslusivity |
|
105 |
uint8 exclusive_counter; ///< months till the exclusivity expires |
|
0 | 106 |
int16 ratings[MAX_PLAYERS]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
107 |
|
6307 | 108 |
/* Maximum amount of passengers and mail that can be transported. */ |
1377
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
109 |
uint32 max_pass; |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
110 |
uint32 max_mail; |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
111 |
uint32 new_max_pass; |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
112 |
uint32 new_max_mail; |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
113 |
uint32 act_pass; |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
114 |
uint32 act_mail; |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
115 |
uint32 new_act_pass; |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
116 |
uint32 new_act_mail; |
0 | 117 |
|
6307 | 118 |
/* Amount of passengers that were transported. */ |
0 | 119 |
byte pct_pass_transported; |
120 |
byte pct_mail_transported; |
|
121 |
||
6307 | 122 |
/* Amount of food and paper that was transported. Actually a bit mask would be enough. */ |
0 | 123 |
uint16 act_food; |
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
124 |
uint16 act_water; |
0 | 125 |
uint16 new_act_food; |
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
126 |
uint16 new_act_water; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
127 |
|
6307 | 128 |
/* Time until we rebuild a house. */ |
129 |
uint16 time_until_rebuild; |
|
0 | 130 |
|
6307 | 131 |
/* When to grow town next time. */ |
132 |
uint16 grow_counter; |
|
133 |
int16 growth_rate; |
|
0 | 134 |
|
6307 | 135 |
/* Fund buildings program in action? */ |
0 | 136 |
byte fund_buildings_months; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
137 |
|
6307 | 138 |
/* Fund road reconstruction in action? */ |
0 | 139 |
byte road_build_months; |
140 |
||
6307 | 141 |
/* Index in town array */ |
3346
96c5db77aa83
(svn r4130) - CodeChange: Add proper semantics for TownID for such variables instead of using the general uint16-type. We probably need to change GetTown() and IsTownIndex() as well to use TownID.
Darkvater
parents:
2958
diff
changeset
|
142 |
TownID index; |
0 | 143 |
|
6308 | 144 |
/* If this is a larger town, and should grow more quickly. */ |
145 |
bool larger_town; |
|
146 |
||
6307 | 147 |
/* NOSAVE: UpdateTownRadius updates this given the house count. */ |
0 | 148 |
uint16 radius[5]; |
6303 | 149 |
|
6307 | 150 |
/* NOSAVE: The number of each type of building in the town. */ |
6303 | 151 |
BuildingCounts building_counts; |
0 | 152 |
}; |
153 |
||
6303 | 154 |
struct HouseSpec { |
155 |
/* Standard properties */ |
|
156 |
Year min_date; ///< introduction year of the house |
|
157 |
Year max_date; ///< last year it can be built |
|
158 |
byte population; ///< population (Zero on other tiles in multi tile house.) |
|
159 |
byte removal_cost; ///< cost multiplier for removing it |
|
160 |
StringID building_name; ///< building name |
|
161 |
uint16 remove_rating_decrease; ///< rating decrease if removed |
|
162 |
byte mail_generation; ///< mail generation multiplier (tile based, as the acceptances below) |
|
163 |
byte cargo_acceptance[3]; ///< acceptance level for the cargo slots |
|
164 |
CargoID accepts_cargo[3]; ///< 3 input cargo slots |
|
165 |
BuildingFlags building_flags; ///< some flags that describe the house (size, stadium etc...) |
|
166 |
HouseZones building_availability; ///< where can it be built (climates, zones) |
|
167 |
bool enabled; ///< the house is still avaible (by default, true.newgrf can disable it, though) |
|
168 |
||
169 |
/* NewHouses properties */ |
|
170 |
HouseID substitute_id; ///< which house this one is based on |
|
171 |
struct SpriteGroup *spritegroup; ///< pointer to the different sprites of the house |
|
172 |
HouseID override; ///< which house this one replaces |
|
173 |
uint16 callback_mask; ///< House callback flags |
|
174 |
byte random_colour[4]; ///< 4 "random" colours |
|
175 |
byte probability; ///< Relative probability of appearing (16 is the standard value) |
|
176 |
HouseExtraFlags extra_flags; ///< some more flags |
|
177 |
HouseClassID class_id; ///< defines the class this house has (grf file based) @See HouseGetVariable, prop 0x44 |
|
178 |
byte animation_frames; ///< number of animation frames |
|
179 |
byte animation_speed; ///< amount of time between each of those frames |
|
180 |
byte processing_time; ///< Periodic refresh multiplier |
|
181 |
||
182 |
/* grf file related properties*/ |
|
183 |
uint8 local_id; ///< id defined by the grf file for this house |
|
184 |
const struct GRFFile *grffile; ///< grf file that introduced this house |
|
185 |
}; |
|
186 |
||
6308 | 187 |
enum TownSizeMode { |
188 |
TSM_RANDOM, |
|
189 |
TSM_FIXED, |
|
190 |
TSM_CITY |
|
191 |
}; |
|
192 |
||
6303 | 193 |
VARDEF HouseSpec _house_specs[HOUSE_MAX]; |
194 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6233
diff
changeset
|
195 |
uint32 GetWorldPopulation(); |
0 | 196 |
|
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
820
diff
changeset
|
197 |
void UpdateTownVirtCoord(Town *t); |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6233
diff
changeset
|
198 |
void InitializeTown(); |
3346
96c5db77aa83
(svn r4130) - CodeChange: Add proper semantics for TownID for such variables instead of using the general uint16-type. We probably need to change GetTown() and IsTownIndex() as well to use TownID.
Darkvater
parents:
2958
diff
changeset
|
199 |
void ShowTownViewWindow(TownID town); |
0 | 200 |
void ExpandTown(Town *t); |
6308 | 201 |
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size); |
0 | 202 |
|
203 |
enum { |
|
204 |
ROAD_REMOVE = 0, |
|
205 |
UNMOVEABLE_REMOVE = 1, |
|
206 |
TUNNELBRIDGE_REMOVE = 1, |
|
207 |
INDUSTRY_REMOVE = 2 |
|
208 |
}; |
|
209 |
||
1005 | 210 |
enum { |
6307 | 211 |
/* These refer to the maximums, so Appalling is -1000 to -400 |
212 |
* MAXIMUM RATINGS BOUNDARIES */ |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
213 |
RATING_MINIMUM = -1000, |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
214 |
RATING_APPALLING = -400, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
215 |
RATING_VERYPOOR = -200, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
216 |
RATING_POOR = 0, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
217 |
RATING_MEDIOCRE = 200, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
218 |
RATING_GOOD = 400, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
219 |
RATING_VERYGOOD = 600, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
220 |
RATING_EXCELLENT = 800, |
6307 | 221 |
RATING_OUTSTANDING = 1000, ///< OUTSTANDING |
1005 | 222 |
|
223 |
RATING_MAXIMUM = RATING_OUTSTANDING, |
|
224 |
||
6307 | 225 |
/* RATINGS AFFECTING NUMBERS */ |
1005 | 226 |
RATING_TREE_DOWN_STEP = -35, |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
227 |
RATING_TREE_MINIMUM = RATING_MINIMUM, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
228 |
RATING_TREE_UP_STEP = 7, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
229 |
RATING_TREE_MAXIMUM = 220, |
1005 | 230 |
|
231 |
RATING_TUNNEL_BRIDGE_DOWN_STEP = -250, |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
232 |
RATING_TUNNEL_BRIDGE_MINIMUM = 0, |
1005 | 233 |
|
234 |
RATING_INDUSTRY_DOWN_STEP = -1500, |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
235 |
RATING_INDUSTRY_MINIMUM = RATING_MINIMUM, |
1005 | 236 |
|
237 |
RATING_ROAD_DOWN_STEP = -50, |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
238 |
RATING_ROAD_MINIMUM = -100, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4277
diff
changeset
|
239 |
RATING_HOUSE_MINIMUM = RATING_MINIMUM, |
1005 | 240 |
|
241 |
RATING_BRIBE_UP_STEP = 200, |
|
242 |
RATING_BRIBE_MAXIMUM = 800, |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
243 |
RATING_BRIBE_DOWN_TO = -50 // XXX SHOULD BE SOMETHING LOWER? |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
244 |
}; |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
245 |
|
6307 | 246 |
/** This is the number of ticks between towns being processed for building new |
247 |
* houses or roads. This value originally came from the size of the town array |
|
248 |
* in TTD. */ |
|
249 |
static const byte TOWN_GROWTH_FREQUENCY = 70; |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
250 |
|
6307 | 251 |
/** Simple value that indicates the house has reached the final stage of |
252 |
* construction. */ |
|
253 |
static const byte TOWN_HOUSE_COMPLETED = 3; |
|
254 |
||
255 |
/** This enum is used in conjonction with town->flags12. |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
256 |
* IT simply states what bit is used for. |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
257 |
* It is pretty unrealistic (IMHO) to only have one church/stadium |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
258 |
* per town, NO MATTER the population of it. |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
259 |
* And there are 5 more bits available on flags12... |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
260 |
*/ |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3349
diff
changeset
|
261 |
enum { |
6307 | 262 |
TOWN_IS_FUNDED = 0, ///< Town has received some funds for |
263 |
TOWN_HAS_CHURCH = 1, ///< There can be only one church by town. |
|
264 |
TOWN_HAS_STADIUM = 2 ///< There can be only one stadium by town. |
|
1005 | 265 |
}; |
266 |
||
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2817
diff
changeset
|
267 |
bool CheckforTownRating(uint32 flags, Town *t, byte type); |
0 | 268 |
|
4277
3539bd14f023
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
3674
diff
changeset
|
269 |
VARDEF const Town** _town_sort; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
835
diff
changeset
|
270 |
|
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
4983
diff
changeset
|
271 |
DECLARE_OLD_POOL(Town, Town, 3, 8000) |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1220
diff
changeset
|
272 |
|
6303 | 273 |
static inline HouseSpec *GetHouseSpecs(HouseID house_id) |
274 |
{ |
|
275 |
assert(house_id < HOUSE_MAX); |
|
276 |
return &_house_specs[house_id]; |
|
277 |
} |
|
278 |
||
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1220
diff
changeset
|
279 |
/** |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1260
diff
changeset
|
280 |
* Check if a Town really exists. |
6307 | 281 |
* @param town to inquiry |
282 |
* @return true if it exists |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1260
diff
changeset
|
283 |
*/ |
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2186
diff
changeset
|
284 |
static inline bool IsValidTown(const Town* town) |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1260
diff
changeset
|
285 |
{ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
286 |
return town->xy != 0; |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1260
diff
changeset
|
287 |
} |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1260
diff
changeset
|
288 |
|
6307 | 289 |
/** |
290 |
* Check if a TownID is valid. |
|
6308 | 291 |
* @param index to inquiry in the pool of town |
6307 | 292 |
* @return true if it exists |
293 |
*/ |
|
5299
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
294 |
static inline bool IsValidTownID(TownID index) |
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
295 |
{ |
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
296 |
return index < GetTownPoolSize() && IsValidTown(GetTown(index)); |
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
297 |
} |
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
298 |
|
4354
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
299 |
VARDEF uint _total_towns; |
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
300 |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6233
diff
changeset
|
301 |
static inline TownID GetMaxTownIndex() |
4354
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
302 |
{ |
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
303 |
/* TODO - This isn't the real content of the function, but |
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
304 |
* with the new pool-system this will be replaced with one that |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
305 |
* _really_ returns the highest index. Now it just returns |
4354
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
306 |
* the next safe value we are sure about everything is below. |
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
307 |
*/ |
5298
6d4c150bdd94
(svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents:
5247
diff
changeset
|
308 |
return GetTownPoolSize() - 1; |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
309 |
} |
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
310 |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6233
diff
changeset
|
311 |
static inline uint GetNumTowns() |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
312 |
{ |
4357
3d72606e9192
(svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents:
4356
diff
changeset
|
313 |
return _total_towns; |
4354
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
314 |
} |
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
315 |
|
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
316 |
/** |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
317 |
* Return a random valid town. |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
318 |
*/ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6233
diff
changeset
|
319 |
static inline Town *GetRandomTown() |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
320 |
{ |
5299
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
321 |
int num = RandomRange(GetNumTowns()); |
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
322 |
TownID index = INVALID_TOWN; |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
323 |
|
5299
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
324 |
while (num >= 0) { |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
325 |
num--; |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
326 |
|
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
327 |
index++; |
6233
57721387461b
(svn r8681) -Fix (FS#608): wrong comment (rfalke)
rubidium
parents:
6220
diff
changeset
|
328 |
/* Make sure we have a valid town */ |
5299
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
329 |
while (!IsValidTownID(index)) { |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
330 |
index++; |
5299
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
331 |
assert(index <= GetMaxTownIndex()); |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
332 |
} |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
333 |
} |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
334 |
|
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
335 |
return GetTown(index); |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
336 |
} |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
337 |
|
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4357
diff
changeset
|
338 |
void DestroyTown(Town *t); |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4357
diff
changeset
|
339 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4357
diff
changeset
|
340 |
static inline void DeleteTown(Town *t) |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4357
diff
changeset
|
341 |
{ |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4357
diff
changeset
|
342 |
DestroyTown(t); |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4357
diff
changeset
|
343 |
t->xy = 0; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4357
diff
changeset
|
344 |
} |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4357
diff
changeset
|
345 |
|
6220
0c2371b1edda
(svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents:
5838
diff
changeset
|
346 |
Town* CalcClosestTownFromTile(TileIndex tile, uint threshold); |
0c2371b1edda
(svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents:
5838
diff
changeset
|
347 |
|
4983 | 348 |
#define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) if (IsValidTown(t)) |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1220
diff
changeset
|
349 |
#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0) |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1220
diff
changeset
|
350 |
|
0 | 351 |
VARDEF bool _town_sort_dirty; |
352 |
VARDEF byte _town_sort_order; |
|
353 |
||
354 |
VARDEF Town *_cleared_town; |
|
355 |
VARDEF int _cleared_town_rating; |
|
356 |
||
6303 | 357 |
uint OriginalTileRandomiser(uint x, uint y); |
358 |
void ResetHouses(); |
|
359 |
||
360 |
void ClearTownHouse(Town *t, TileIndex tile); |
|
361 |
||
0 | 362 |
#endif /* TOWN_H */ |