author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1529 | 3a8196d15b01 |
child 1638 | 4779658c2d03 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1304
diff
changeset
|
3 |
#include "strings.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
4 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
543
diff
changeset
|
5 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
6 |
#include "tile.h" |
0 | 7 |
#include "viewport.h" |
8 |
#include "town.h" |
|
9 |
#include "command.h" |
|
10 |
#include "pathfind.h" |
|
11 |
#include "gfx.h" |
|
12 |
#include "industry.h" |
|
13 |
#include "station.h" |
|
14 |
#include "player.h" |
|
15 |
#include "news.h" |
|
16 |
#include "saveload.h" |
|
17 |
#include "economy.h" |
|
18 |
#include "gui.h" |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
19 |
#include "network.h" |
0 | 20 |
|
483
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
21 |
enum { |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
22 |
/* Max towns: 64000 (8 * 8000) */ |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
23 |
TOWN_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */ |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
24 |
TOWN_POOL_MAX_BLOCKS = 8000, |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
25 |
}; |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
26 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
27 |
/** |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
28 |
* Called if a new block is added to the town-pool |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
29 |
*/ |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
30 |
static void TownPoolNewBlock(uint start_item) |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
31 |
{ |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
32 |
Town *t; |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
33 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
34 |
FOR_ALL_TOWNS_FROM(t, start_item) |
1261
914ecc20a2df
(svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents:
1260
diff
changeset
|
35 |
t->index = start_item++; |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
36 |
} |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
37 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
38 |
/* Initialize the town-pool */ |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
39 |
MemoryPool _town_pool = { "Towns", TOWN_POOL_MAX_BLOCKS, TOWN_POOL_BLOCK_SIZE_BITS, sizeof(Town), &TownPoolNewBlock, 0, 0, NULL }; |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
40 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
41 |
|
1451
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
42 |
/* This is the base "normal" number of towns on the 8x8 map, when |
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
43 |
* one town should get grown per tick. The other numbers of towns |
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
44 |
* are then scaled based on that. */ |
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
45 |
#define TOWN_GROWTH_FREQUENCY 23 |
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
46 |
|
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
47 |
enum { |
483
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
48 |
TOWN_HAS_CHURCH = 0x02, |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
49 |
TOWN_HAS_STADIUM = 0x04 |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
50 |
}; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
51 |
|
0 | 52 |
// Local |
53 |
static int _grow_town_result; |
|
54 |
||
55 |
static bool BuildTownHouse(Town *t, uint tile); |
|
56 |
static void ClearTownHouse(Town *t, uint tile); |
|
57 |
static void DoBuildTownHouse(Town *t, uint tile); |
|
58 |
||
59 |
typedef struct DrawTownTileStruct { |
|
60 |
uint32 sprite_1; |
|
61 |
uint32 sprite_2; |
|
62 |
||
482 | 63 |
byte subtile_x:4; |
64 |
byte subtile_y:4; |
|
65 |
byte width:4; |
|
66 |
byte height:4; |
|
0 | 67 |
byte dz; |
68 |
byte proc; |
|
69 |
} DrawTownTileStruct; |
|
70 |
||
71 |
#include "table/town_land.h" |
|
72 |
||
73 |
||
74 |
static void TownDrawTileProc1(TileInfo *ti) |
|
75 |
{ |
|
76 |
AddChildSpriteScreen(0x5A3, 0xE, 0x3C - (_map_owner[ti->tile]&0x7F)); |
|
77 |
} |
|
78 |
||
79 |
typedef void TownDrawTileProc(TileInfo *ti); |
|
80 |
static TownDrawTileProc * const _town_draw_tile_procs[1] = { |
|
81 |
TownDrawTileProc1 |
|
82 |
}; |
|
83 |
||
84 |
||
85 |
static void DrawTile_Town(TileInfo *ti) |
|
86 |
{ |
|
87 |
const DrawTownTileStruct *dcts; |
|
88 |
byte z; |
|
89 |
uint32 image; |
|
90 |
||
91 |
/* Retrieve pointer to the draw town tile struct */ |
|
92 |
{ |
|
480
2e915fd96ac3
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
93 |
/* this "randomizes" on the (up to) 4 variants of a building */ |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
94 |
byte gfx = (byte)_map3_hi[ti->tile]; |
480
2e915fd96ac3
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
95 |
byte stage = _map3_lo[ti->tile] >> 6; |
2e915fd96ac3
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
96 |
uint variant; |
2e915fd96ac3
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
97 |
variant = ti->x >> 4; |
2e915fd96ac3
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
98 |
variant ^= ti->x >> 6; |
2e915fd96ac3
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
99 |
variant ^= ti->y >> 4; |
2e915fd96ac3
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
100 |
variant -= ti->y >> 6; |
2e915fd96ac3
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
101 |
variant &= 3; |
2e915fd96ac3
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
102 |
dcts = &_town_draw_tile_data[gfx << 4 | variant << 2 | stage]; |
0 | 103 |
} |
104 |
||
105 |
z = ti->z; |
|
106 |
||
107 |
/* Add bricks below the house? */ |
|
108 |
if (ti->tileh) { |
|
109 |
AddSortableSpriteToDraw(0x3DD + ti->tileh, ti->x, ti->y, 16, 16, 7, z); |
|
110 |
AddChildSpriteScreen(dcts->sprite_1, 0x1F, 1); |
|
111 |
z += 8; |
|
112 |
} else { |
|
113 |
/* Else draw regular ground */ |
|
114 |
DrawGroundSprite(dcts->sprite_1); |
|
115 |
} |
|
116 |
||
117 |
/* Add a house on top of the ground? */ |
|
118 |
if ((image = dcts->sprite_2) != 0) { |
|
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
483
diff
changeset
|
119 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 120 |
image = (image & 0x3FFF) | 0x3224000; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
121 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
122 |
AddSortableSpriteToDraw(image, |
482 | 123 |
ti->x + dcts->subtile_x, |
124 |
ti->y + dcts->subtile_y, |
|
125 |
dcts->width + 1, |
|
126 |
dcts->height + 1, |
|
0 | 127 |
dcts->dz, |
128 |
z); |
|
129 |
||
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
483
diff
changeset
|
130 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 131 |
return; |
132 |
} |
|
133 |
||
134 |
{ |
|
135 |
int proc; |
|
136 |
if ((proc=dcts->proc-1) >= 0 ) |
|
137 |
_town_draw_tile_procs[proc](ti); |
|
138 |
} |
|
139 |
} |
|
140 |
||
141 |
static uint GetSlopeZ_Town(TileInfo *ti) |
|
142 |
{ |
|
143 |
uint z = GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
|
144 |
if (ti->tileh != 0) z = (z & ~7) + 4; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
145 |
return (uint16) z; |
0 | 146 |
} |
147 |
||
39 | 148 |
static uint GetSlopeTileh_Town(TileInfo *ti) |
149 |
{ |
|
150 |
return ti->tileh; |
|
151 |
} |
|
152 |
||
0 | 153 |
static void AnimateTile_Town(uint tile) |
154 |
{ |
|
155 |
int old; |
|
156 |
int i; |
|
157 |
int a,b; |
|
158 |
||
159 |
if (_tick_counter & 3) |
|
160 |
return; |
|
161 |
||
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
162 |
if (_map3_hi[tile] != 4 && _map3_hi[tile] != 5) |
0 | 163 |
return; |
164 |
||
165 |
if (!((old=_map_owner[tile])&0x80)) { |
|
166 |
_map_owner[tile] |= 0x80; |
|
167 |
||
168 |
do { |
|
169 |
i = (Random()&7) - 1; |
|
170 |
} while (i < 0 || i == 1 || i*6==old); |
|
171 |
||
172 |
_map5[tile] = (_map5[tile] & ~0x3F) | i; |
|
173 |
} |
|
174 |
||
175 |
a = _map_owner[tile]&0x7F; |
|
176 |
b = (_map5[tile]&0x3F) * 6; |
|
177 |
a += (a < b) ? 1 : -1; |
|
178 |
_map_owner[tile] = (_map_owner[tile]&0x80)|a; |
|
179 |
||
180 |
if (a == b) { |
|
181 |
_map5[tile] &= 0x40; |
|
182 |
_map_owner[tile] &= 0x7F; |
|
183 |
DeleteAnimatedTile(tile); |
|
184 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
185 |
|
0 | 186 |
MarkTileDirtyByTile(tile); |
187 |
} |
|
188 |
||
189 |
static void UpdateTownRadius(Town *t); |
|
190 |
||
191 |
static bool IsCloseToTown(uint tile, uint dist) |
|
192 |
{ |
|
193 |
Town *t; |
|
194 |
||
195 |
FOR_ALL_TOWNS(t) { |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
196 |
if (t->xy != 0 && DistanceManhattan(tile, t->xy) < dist) |
0 | 197 |
return true; |
198 |
} |
|
199 |
return false; |
|
200 |
} |
|
201 |
||
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
202 |
static void MarkTownSignDirty(Town *t) |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
203 |
{ |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
204 |
MarkAllViewportsDirty( |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
205 |
t->sign.left-6, |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
206 |
t->sign.top-3, |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
207 |
t->sign.left+t->sign.width_1*4+12, |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
208 |
t->sign.top + 45 |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
209 |
); |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
210 |
} |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
211 |
|
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
212 |
void UpdateTownVirtCoord(Town *t) |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
213 |
{ |
836 | 214 |
Point pt; |
215 |
||
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
216 |
MarkTownSignDirty(t); |
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
217 |
pt = RemapCoords2(TileX(t->xy) * 16, TileY(t->xy) * 16); |
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
218 |
SetDParam(0, t->townnametype); |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
219 |
SetDParam(1, t->townnameparts); |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
220 |
SetDParam(2, t->population); |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
221 |
UpdateViewportSignPos(&t->sign, pt.x, pt.y - 24, _patches.population_in_label ? STR_TOWN_LABEL_POP : STR_2001); |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
222 |
MarkTownSignDirty(t); |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
223 |
} |
0 | 224 |
|
225 |
static void ChangePopulation(Town *t, int mod) |
|
226 |
{ |
|
227 |
t->population += mod; |
|
228 |
InvalidateWindow(WC_TOWN_VIEW, t->index); |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
229 |
UpdateTownVirtCoord(t); |
0 | 230 |
|
231 |
if (_town_sort_order & 2) _town_sort_dirty = true; |
|
232 |
} |
|
233 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
234 |
uint32 GetWorldPopulation(void) |
1080
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
235 |
{ |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
236 |
uint32 pop; |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
237 |
Town *t; |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
238 |
pop = 0; |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
239 |
FOR_ALL_TOWNS(t) { |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
240 |
pop += t->population; |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
241 |
} |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
242 |
return pop; |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
243 |
} |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
244 |
|
0 | 245 |
static void MakeSingleHouseBigger(uint tile) |
246 |
{ |
|
247 |
byte b; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
248 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
249 |
assert(IsTileType(tile, MP_HOUSE)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
250 |
|
0 | 251 |
b = _map5[tile]; |
252 |
if (b & 0x80) |
|
253 |
return; |
|
254 |
||
255 |
_map5[tile] = (b & 0xC0) | ((b+1)&7); |
|
256 |
||
257 |
if ((_map5[tile]&7) != 0) |
|
258 |
return; |
|
259 |
||
260 |
_map3_lo[tile] = _map3_lo[tile] + 0x40; |
|
261 |
||
262 |
if ( (_map3_lo[tile] & 0xC0) == 0xC0) { |
|
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
263 |
ChangePopulation(GetTown(_map2[tile]), _housetype_population[_map3_hi[tile]]); |
0 | 264 |
} |
265 |
MarkTileDirtyByTile(tile); |
|
266 |
} |
|
267 |
||
268 |
static void MakeTownHouseBigger(uint tile) |
|
269 |
{ |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
270 |
uint flags = _house_more_flags[_map3_hi[tile]]; |
0 | 271 |
if (flags & 8) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0)); |
272 |
if (flags & 4) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1)); |
|
273 |
if (flags & 2) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0)); |
|
274 |
if (flags & 1) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1)); |
|
275 |
} |
|
276 |
||
277 |
static void TileLoop_Town(uint tile) |
|
278 |
{ |
|
279 |
int house; |
|
280 |
Town *t; |
|
281 |
uint32 r; |
|
282 |
||
283 |
if ((_map3_lo[tile] & 0xC0) != 0xC0) { |
|
284 |
MakeTownHouseBigger(tile); |
|
285 |
return; |
|
286 |
} |
|
287 |
||
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
288 |
house = _map3_hi[tile]; |
0 | 289 |
if (_housetype_extra_flags[house] & 0x20 && |
290 |
!(_map5[tile] & 0x80) && |
|
291 |
CHANCE16(1,2) && |
|
292 |
AddAnimatedTile(tile)) { |
|
293 |
_map5[tile] = (_map5[tile] & 0x40)|0x80; |
|
294 |
} |
|
295 |
||
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
296 |
t = GetTown(_map2[tile]); |
0 | 297 |
|
298 |
r = Random(); |
|
299 |
||
300 |
if ( (byte)r < _housetype_population[house] ) { |
|
301 |
uint amt = ((byte)r >> 3) + 1, moved; |
|
302 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
|
303 |
t->new_max_pass += amt; |
|
304 |
moved = MoveGoodsToStation(tile, 1, 1, CT_PASSENGERS, amt); |
|
305 |
t->new_act_pass += moved; |
|
306 |
} |
|
307 |
||
308 |
if ( (byte)(r>>8) < _housetype_mailamount[house] ) { |
|
309 |
uint amt = ((byte)(r>>8) >> 3) + 1, moved; |
|
310 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
|
311 |
t->new_max_mail += amt; |
|
312 |
moved = MoveGoodsToStation(tile, 1, 1, CT_MAIL, amt); |
|
313 |
t->new_act_mail += moved; |
|
314 |
} |
|
315 |
||
316 |
if (_house_more_flags[house]&8 && (t->flags12&1) && --t->time_until_rebuild == 0) { |
|
317 |
r>>=16; |
|
318 |
t->time_until_rebuild = (r & 63) + 130; |
|
319 |
||
320 |
_current_player = OWNER_TOWN; |
|
321 |
||
322 |
ClearTownHouse(t, tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
323 |
|
0 | 324 |
// rebuild with another house? |
325 |
if ( (byte) (r >> 8) >= 12) { |
|
326 |
DoBuildTownHouse(t, tile); |
|
327 |
} |
|
314 | 328 |
|
329 |
_current_player = OWNER_NONE; |
|
0 | 330 |
} |
331 |
} |
|
332 |
||
333 |
static void ClickTile_Town(uint tile) |
|
334 |
{ |
|
335 |
/* not used */ |
|
336 |
} |
|
337 |
||
338 |
static int32 ClearTile_Town(uint tile, byte flags) |
|
339 |
{ |
|
340 |
int house, rating; |
|
341 |
int32 cost; |
|
342 |
Town *t; |
|
343 |
||
344 |
// safety checks |
|
345 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
346 |
if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
347 |
||
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
348 |
house = _map3_hi[tile]; |
0 | 349 |
cost = _price.remove_house * _housetype_remove_cost[house] >> 8; |
350 |
||
351 |
rating = _housetype_remove_ratingmod[house]; |
|
352 |
_cleared_town_rating += rating; |
|
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
353 |
_cleared_town = t = GetTown(_map2[tile]); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
354 |
|
0 | 355 |
if (_current_player < MAX_PLAYERS) { |
356 |
if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
357 |
SetDParam(0, t->index); |
0 | 358 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
359 |
} |
0 | 360 |
} |
361 |
||
362 |
if (flags & DC_EXEC) { |
|
1005 | 363 |
ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM); |
0 | 364 |
ClearTownHouse(t, tile); |
365 |
} |
|
366 |
||
367 |
return cost; |
|
368 |
} |
|
369 |
||
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
470
diff
changeset
|
370 |
static void GetAcceptedCargo_Town(uint tile, AcceptedCargo ac) |
0 | 371 |
{ |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
372 |
int type = _map3_hi[tile]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
373 |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
470
diff
changeset
|
374 |
ac[CT_PASSENGERS] = _housetype_cargo_passengers[type]; |
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
470
diff
changeset
|
375 |
ac[CT_MAIL] = _housetype_cargo_mail[type]; |
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
470
diff
changeset
|
376 |
ac[CT_GOODS] = _housetype_cargo_goods[type]; |
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
470
diff
changeset
|
377 |
ac[CT_FOOD] = _housetype_cargo_food[type]; |
0 | 378 |
} |
379 |
||
380 |
static void GetTileDesc_Town(uint tile, TileDesc *td) |
|
381 |
{ |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
382 |
td->str = _town_tile_names[_map3_hi[tile]]; |
0 | 383 |
if ((_map3_lo[tile] & 0xC0) != 0xC0) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
384 |
SetDParamX(td->dparam, 0, td->str); |
0 | 385 |
td->str = STR_2058_UNDER_CONSTRUCTION; |
386 |
} |
|
387 |
||
388 |
td->owner = OWNER_TOWN; |
|
389 |
} |
|
390 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
121
diff
changeset
|
391 |
static uint32 GetTileTrackStatus_Town(uint tile, TransportType mode) |
0 | 392 |
{ |
393 |
/* not used */ |
|
394 |
return 0; |
|
395 |
} |
|
396 |
||
397 |
static void ChangeTileOwner_Town(uint tile, byte old_player, byte new_player) |
|
398 |
{ |
|
399 |
/* not used */ |
|
400 |
} |
|
401 |
||
402 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
403 |
static const TileIndexDiffC _roadblock_tileadd[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
404 |
{ 0, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
405 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
406 |
{ 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
407 |
{-1, 0}, |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
408 |
|
0 | 409 |
// Store the first 3 elements again. |
410 |
// Lets us rotate without using &3. |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
411 |
{ 0, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
412 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
413 |
{ 0, 1} |
0 | 414 |
}; |
415 |
||
416 |
static void TownTickHandler(Town *t) |
|
417 |
{ |
|
418 |
if (t->flags12&1) { |
|
419 |
int i = t->grow_counter - 1; |
|
420 |
if (i < 0) { |
|
421 |
if (GrowTown(t)) { |
|
422 |
i = t->growth_rate; |
|
423 |
} else { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
424 |
i = 0; |
0 | 425 |
} |
426 |
} |
|
427 |
t->grow_counter = i; |
|
428 |
} |
|
429 |
||
430 |
UpdateTownRadius(t); |
|
431 |
} |
|
432 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
433 |
void OnTick_Town(void) |
0 | 434 |
{ |
435 |
if (_game_mode == GM_EDITOR) |
|
436 |
return; |
|
437 |
||
1451
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
438 |
/* Make sure each town's tickhandler invocation frequency is about the |
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
439 |
* same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */ |
1529
3a8196d15b01
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
440 |
for (_cur_town_iter += GetTownPoolSize(); |
3a8196d15b01
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
441 |
_cur_town_iter >= TOWN_GROWTH_FREQUENCY; |
3a8196d15b01
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
442 |
_cur_town_iter -= TOWN_GROWTH_FREQUENCY) { |
1517
596d52828893
(svn r2021) Fix: Enlarge _cur_town_ctr from byte to uint32 so that all the towns are considered when growing them even for big maps, where much more than 256 towns are around; reported by Tomasz Dubi?ski <uboottd@hydra.polsl.gliwice.pl>. The savegame still saves just the lowest 8 bits but that doesn't hurt so much.
pasky
parents:
1500
diff
changeset
|
443 |
uint32 i = _cur_town_ctr; |
1451
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
444 |
Town *t; |
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
445 |
|
1448
472b3b3855e7
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
446 |
if (++_cur_town_ctr >= GetTownPoolSize()) |
472b3b3855e7
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
447 |
_cur_town_ctr = 0; |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
448 |
|
1448
472b3b3855e7
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
449 |
t = GetTown(i); |
0 | 450 |
|
1448
472b3b3855e7
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
451 |
if (t->xy != 0) |
472b3b3855e7
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
452 |
TownTickHandler(t); |
472b3b3855e7
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
453 |
} |
0 | 454 |
} |
455 |
||
456 |
static byte GetTownRoadMask(TileIndex tile) |
|
457 |
{ |
|
516
035c53a7da94
(svn r831) Remove station-specific roadbits magic. Tron already fixed road stations so that they don't give out roadbits in r780.
pasky
parents:
515
diff
changeset
|
458 |
byte b = GetRoadBitsByTile(tile); |
0 | 459 |
byte r=0; |
460 |
if (b&1) r|=10; |
|
461 |
if (b&2) r|=5; |
|
462 |
if (b&4) r|=9; |
|
463 |
if (b&8) r|=6; |
|
464 |
if (b&16) r|=3; |
|
465 |
if (b&32) r|=12; |
|
466 |
return r; |
|
467 |
} |
|
468 |
||
469 |
static bool IsRoadAllowedHere(uint tile, int dir) |
|
470 |
{ |
|
471 |
uint k; |
|
472 |
uint slope; |
|
473 |
||
474 |
// If this assertion fails, it might be because the world contains |
|
475 |
// land at the edges. This is not ok. |
|
476 |
TILE_ASSERT(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
477 |
|
0 | 478 |
for(;;) { |
479 |
// Check if there already is a road at this point? |
|
516
035c53a7da94
(svn r831) Remove station-specific roadbits magic. Tron already fixed road stations so that they don't give out roadbits in r780.
pasky
parents:
515
diff
changeset
|
480 |
if (GetRoadBitsByTile(tile) == 0) { |
0 | 481 |
// No, try to build one in the direction. |
482 |
// if that fails clear the land, and if that fails exit. |
|
483 |
// This is to make sure that we can build a road here later. |
|
484 |
if (DoCommandByTile(tile, (dir&1)?0xA:0x5, 0, DC_AUTO, CMD_BUILD_ROAD) == CMD_ERROR && |
|
485 |
DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) == CMD_ERROR) |
|
486 |
return false; |
|
487 |
} |
|
488 |
||
489 |
slope = GetTileSlope(tile, NULL); |
|
490 |
if (slope == 0) { |
|
465
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
491 |
no_slope: |
0 | 492 |
// Tile has no slope |
493 |
// Disallow the road if any neighboring tile has a road. |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
494 |
if (HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+1]))), dir^2) || |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
495 |
HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+3]))), dir^2) || |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
496 |
HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+1]) + ToTileIndexDiff(_roadblock_tileadd[dir+2]))), dir) || |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
497 |
HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+3]) + ToTileIndexDiff(_roadblock_tileadd[dir+2]))), dir)) |
0 | 498 |
return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
499 |
|
0 | 500 |
// Otherwise allow |
501 |
return true; |
|
502 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
503 |
|
0 | 504 |
// If the tile is not a slope in the right direction, then |
505 |
// maybe terraform some. |
|
506 |
if ((k = (dir&1)?0xC:0x9) != slope && (k^0xF) != slope) { |
|
507 |
uint32 r = Random(); |
|
508 |
||
509 |
if (CHANCE16I(1,8, r) && !_generating_world) { |
|
465
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
510 |
int32 res; |
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
511 |
|
0 | 512 |
if (CHANCE16I(1,16,r)) |
465
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
513 |
res = DoCommandByTile(tile, slope, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, |
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
514 |
CMD_TERRAFORM_LAND); |
0 | 515 |
else |
465
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
516 |
res = DoCommandByTile(tile, slope^0xF, 1, DC_EXEC | DC_AUTO | DC_NO_WATER, |
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
517 |
CMD_TERRAFORM_LAND); |
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
518 |
if (res == CMD_ERROR && CHANCE16I(1,3,r)) |
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
519 |
// We can consider building on the slope, though. |
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
520 |
goto no_slope; |
0 | 521 |
} |
522 |
return false; |
|
523 |
} |
|
524 |
||
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
525 |
/* Can somebody explain for what this is needed? :s */ |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
526 |
// tile = TILE_ADD(tile, _roadblock_tileadd[dir]); |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
527 |
return true; |
0 | 528 |
} |
529 |
} |
|
530 |
||
531 |
static bool TerraformTownTile(uint tile, int edges, int dir) |
|
532 |
{ |
|
533 |
int32 r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
534 |
|
0 | 535 |
TILE_ASSERT(tile); |
536 |
||
537 |
r = DoCommandByTile(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
|
538 |
if (r == CMD_ERROR || r >= 126*16) |
|
539 |
return false; |
|
540 |
DoCommandByTile(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND); |
|
541 |
return true; |
|
542 |
} |
|
543 |
||
544 |
static void LevelTownLand(uint tile) |
|
545 |
{ |
|
546 |
TileInfo ti; |
|
547 |
||
548 |
TILE_ASSERT(tile); |
|
549 |
||
550 |
// Don't terraform if land is plain or if there's a house there. |
|
551 |
FindLandscapeHeightByTile(&ti, tile); |
|
552 |
if (ti.tileh == 0 || ti.type == MP_HOUSE) |
|
553 |
return; |
|
554 |
||
555 |
// First try up, then down |
|
556 |
if (!TerraformTownTile(tile, ~ti.tileh & 0xF, 1)) { |
|
557 |
TerraformTownTile(tile, ti.tileh & 0xF, 0); |
|
558 |
} |
|
559 |
} |
|
560 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
561 |
#define IS_WATER_TILE(t) (IsTileType((t), MP_WATER) && _map5[(t)] == 0) |
0 | 562 |
|
563 |
static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1) |
|
564 |
{ |
|
565 |
uint16 r; |
|
566 |
int a,b,rcmd; |
|
567 |
uint tmptile; |
|
568 |
TileInfo ti; |
|
569 |
int i; |
|
570 |
int j; |
|
571 |
uint tile = *tile_ptr; |
|
572 |
||
573 |
TILE_ASSERT(tile); |
|
574 |
||
575 |
if (mask == 0) { |
|
576 |
// Tile has no road. First reset the status counter |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
577 |
// to say that this is the last iteration. |
0 | 578 |
_grow_town_result = 0; |
579 |
||
580 |
// Remove hills etc |
|
581 |
LevelTownLand(tile); |
|
582 |
||
583 |
// Is a road allowed here? |
|
584 |
if (!IsRoadAllowedHere(tile, block)) |
|
585 |
return; |
|
586 |
||
587 |
// Randomize new road block numbers |
|
588 |
a = block; |
|
589 |
b = block ^ 2; |
|
590 |
r = (uint16)Random(); |
|
591 |
if (r <= 0x4000) do { |
|
592 |
a = (int)Random() & 3; |
|
593 |
} while(a == b); |
|
594 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
595 |
if (!IsRoadAllowedHere(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a])), a)) { |
0 | 596 |
// A road is not allowed to continue the randomized road, |
597 |
// return if the road we're trying to build is curved. |
|
598 |
if ( a != (b^2)) |
|
599 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
600 |
|
0 | 601 |
// Return if neither side of the new road is a house |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
602 |
if (!IsTileType(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a + 1])), MP_HOUSE) && |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
603 |
!IsTileType(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a + 3])), MP_HOUSE)) |
0 | 604 |
return; |
605 |
||
606 |
// That means that the road is only allowed if there is a house |
|
607 |
// at any side of the new road. |
|
608 |
} |
|
609 |
rcmd = (1 << a) + (1 << b); |
|
610 |
||
611 |
} else if (block < 5 && !HASBIT(mask,block^2)) { |
|
612 |
// Continue building on a partial road. |
|
613 |
// Always OK. |
|
614 |
_grow_town_result = 0; |
|
615 |
rcmd = 1 << (block^2); |
|
616 |
} else { |
|
617 |
||
618 |
// Reached a tunnel? Then continue at the other side of it. |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
619 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile]& ~3) == 4) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
121
diff
changeset
|
620 |
FindLengthOfTunnelResult flotr = FindLengthOfTunnel(tile, _map5[tile]&3); |
0 | 621 |
*tile_ptr = flotr.tile; |
622 |
return; |
|
623 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
624 |
|
0 | 625 |
// For any other kind of tunnel/bridge, bail out. |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
626 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) |
0 | 627 |
return; |
628 |
||
629 |
// Possibly extend the road in a direction. |
|
630 |
// Randomize a direction and if it has a road, bail out. |
|
631 |
i = (int)Random() & 3; |
|
632 |
if (HASBIT(mask, i)) |
|
633 |
return; |
|
634 |
||
635 |
// This is the tile we will reach if we extend to this direction. |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
636 |
tmptile = TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[i])); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
637 |
|
0 | 638 |
// Don't do it if it reaches to water. |
639 |
if (IS_WATER_TILE(tmptile)) |
|
640 |
return; |
|
641 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
642 |
// Build a house at the edge. 60% chance or |
0 | 643 |
// always ok if no road allowed. |
644 |
if (!IsRoadAllowedHere(tmptile, i) || CHANCE16(6,10)) { |
|
645 |
// But not if there already is a house there. |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
646 |
if (!IsTileType(tmptile, MP_HOUSE)) { |
0 | 647 |
// Level the land if possible |
648 |
LevelTownLand(tmptile); |
|
649 |
||
650 |
// And build a house. |
|
651 |
// Set result to -1 if we managed to build it. |
|
652 |
if (BuildTownHouse(t1, tmptile)) |
|
653 |
_grow_town_result = -1; |
|
654 |
} |
|
655 |
return; |
|
656 |
} |
|
657 |
||
658 |
_grow_town_result = 0; |
|
659 |
rcmd = 1 << i; |
|
660 |
} |
|
661 |
||
662 |
FindLandscapeHeightByTile(&ti, tile); |
|
663 |
||
664 |
// Return if a water tile |
|
665 |
if (ti.type == MP_WATER && ti.map5==0) |
|
666 |
return; |
|
667 |
||
668 |
// Determine direction of slope, |
|
669 |
// and build a road if not a special slope. |
|
670 |
if ((i=0,ti.tileh != 3) && |
|
671 |
(i++,ti.tileh != 9) && |
|
672 |
(i++,ti.tileh != 12) && |
|
673 |
(i++,ti.tileh != 6)) { |
|
674 |
build_road_and_exit: |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
675 |
if (DoCommandByTile(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD) != CMD_ERROR) |
0 | 676 |
_grow_town_result = -1; |
677 |
return; |
|
678 |
} |
|
679 |
||
680 |
tmptile = tile; |
|
681 |
||
682 |
// Now it contains the direction of the slope |
|
683 |
j = -11; // max 11 tile long bridges |
|
684 |
do { |
|
685 |
if (++j == 0) |
|
686 |
goto build_road_and_exit; |
|
900 | 687 |
tmptile = TILE_MASK(tmptile + TileOffsByDir(i)); |
0 | 688 |
} while (IS_WATER_TILE(tmptile)); |
689 |
||
690 |
// no water tiles in between? |
|
691 |
if (j == -10) |
|
692 |
goto build_road_and_exit; |
|
693 |
||
694 |
// Quit if it selecting an appropiate bridge type fails a large number of times. |
|
695 |
j = 22; |
|
696 |
{ |
|
697 |
int32 bridge_len = GetBridgeLength(tile, tmptile); |
|
698 |
do { |
|
699 |
byte bridge_type = RandomRange(MAX_BRIDGES - 1); |
|
700 |
if (CheckBridge_Stuff(bridge_type, bridge_len)) { |
|
701 |
if (DoCommandByTile(tile, tmptile, 0x8000 + bridge_type, DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE) != CMD_ERROR) |
|
702 |
_grow_town_result = -1; |
|
703 |
||
704 |
// obviously, if building any bridge would fail, there is no need to try other bridge-types |
|
705 |
return; |
|
706 |
} |
|
707 |
} while(--j != 0); |
|
708 |
} |
|
709 |
} |
|
710 |
#undef IS_WATER_TILE |
|
711 |
||
712 |
||
713 |
// Returns true if a house was built, or no if the build failed. |
|
714 |
static int GrowTownAtRoad(Town *t, uint tile) |
|
715 |
{ |
|
716 |
uint mask; |
|
717 |
int block = 5; // special case |
|
718 |
||
719 |
TILE_ASSERT(tile); |
|
720 |
||
721 |
// Number of times to search. |
|
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
722 |
_grow_town_result = 10 + t->num_houses * 4 / 9; |
0 | 723 |
|
724 |
do { |
|
725 |
// Get a bitmask of the road blocks on a tile |
|
726 |
mask = GetTownRoadMask(tile); |
|
727 |
||
728 |
// Try to grow the town from this point |
|
729 |
GrowTownInTile(&tile,mask,block,t); |
|
730 |
||
731 |
// Exclude the source position from the bitmask |
|
732 |
// and return if no more road blocks available |
|
733 |
CLRBIT(mask, (block ^ 2)); |
|
734 |
if (mask == 0) |
|
735 |
return _grow_town_result; |
|
736 |
||
737 |
// Select a random bit from the blockmask, walk a step |
|
738 |
// and continue the search from there. |
|
739 |
do block = Random() & 3; while (!HASBIT(mask,block)); |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
740 |
tile += ToTileIndexDiff(_roadblock_tileadd[block]); |
0 | 741 |
|
1327
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
742 |
if (IsTileType(tile, MP_STREET)) { |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
743 |
/* Don't allow building over roads of other cities */ |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
744 |
if (_map_owner[tile] == OWNER_TOWN && GetTown(_map2[tile]) != t) |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
745 |
_grow_town_result = -1; |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
746 |
else if (_game_mode == GM_EDITOR) { |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
747 |
/* If we are in the SE, and this road-piece has no town owner yet, it just found an |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
748 |
* owner :) (happy happy happy road now) */ |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
749 |
_map_owner[tile] = OWNER_TOWN; |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
750 |
_map2[tile] = t->index; |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
751 |
} |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
752 |
} |
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
753 |
|
0 | 754 |
// Max number of times is checked. |
755 |
} while (--_grow_town_result >= 0); |
|
756 |
||
757 |
return (_grow_town_result == -2); |
|
758 |
} |
|
759 |
||
760 |
// Generate a random road block |
|
761 |
// The probability of a straight road |
|
762 |
// is somewhat higher than a curved. |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
763 |
static int GenRandomRoadBits(void) |
0 | 764 |
{ |
765 |
uint32 r = Random(); |
|
766 |
int a = r&3, b = (r >> 8) & 3; |
|
767 |
if (a == b) b ^= 2; |
|
768 |
return (1<<a)+(1<<b); |
|
769 |
} |
|
770 |
||
771 |
// Grow the town |
|
772 |
// Returns true if a house was built, or no if the build failed. |
|
773 |
bool GrowTown(Town *t) |
|
774 |
{ |
|
775 |
uint tile; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
776 |
const TileIndexDiffC *ptr; |
0 | 777 |
TileInfo ti; |
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
778 |
byte old_player; |
0 | 779 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
780 |
static const TileIndexDiffC _town_coord_mod[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
781 |
{-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
782 |
{ 1, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
783 |
{ 1, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
784 |
{-1, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
785 |
{-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
786 |
{ 0, 2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
787 |
{ 2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
788 |
{ 0, -2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
789 |
{-1, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
790 |
{-2, 2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
791 |
{ 2, 2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
792 |
{ 2, -2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
793 |
{ 0, 0} |
0 | 794 |
}; |
795 |
||
796 |
// Current player is a town |
|
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
797 |
old_player = _current_player; |
0 | 798 |
_current_player = OWNER_TOWN; |
799 |
||
800 |
// Find a road that we can base the construction on. |
|
801 |
tile = t->xy; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
802 |
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
516
035c53a7da94
(svn r831) Remove station-specific roadbits magic. Tron already fixed road stations so that they don't give out roadbits in r780.
pasky
parents:
515
diff
changeset
|
803 |
if (GetRoadBitsByTile(tile) != 0) { |
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
804 |
int r = GrowTownAtRoad(t, tile); |
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
805 |
_current_player = old_player; |
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
806 |
return r; |
0 | 807 |
} |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
808 |
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
809 |
} |
0 | 810 |
|
811 |
// No road available, try to build a random road block by |
|
812 |
// clearing some land and then building a road there. |
|
813 |
tile = t->xy; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
814 |
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
0 | 815 |
FindLandscapeHeightByTile(&ti, tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
816 |
|
0 | 817 |
// Only work with plain land that not already has a house with map5=0 |
818 |
if (ti.tileh == 0 && !(ti.type==MP_HOUSE && ti.map5==0)) { |
|
819 |
if (DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) { |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
820 |
DoCommandByTile(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD); |
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
821 |
_current_player = old_player; |
0 | 822 |
return true; |
823 |
} |
|
824 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
825 |
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
826 |
} |
0 | 827 |
|
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
828 |
_current_player = old_player; |
0 | 829 |
return false; |
830 |
} |
|
831 |
||
832 |
static void UpdateTownRadius(Town *t) |
|
833 |
{ |
|
834 |
static const uint16 _town_radius_data[23][5] = { |
|
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
835 |
{ 4, 0, 0, 0, 0}, // 0 |
0 | 836 |
{16, 0, 0, 0, 0}, |
837 |
{25, 0, 0, 0, 0}, |
|
838 |
{36, 0, 0, 0, 0}, |
|
839 |
{49, 0, 4, 0, 0}, |
|
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
840 |
{64, 0, 4, 0, 0}, // 20 |
0 | 841 |
{64, 0, 9, 0, 1}, |
842 |
{64, 0, 9, 0, 4}, |
|
843 |
{64, 0, 16, 0, 4}, |
|
844 |
{81, 0, 16, 0, 4}, |
|
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
845 |
{81, 0, 16, 0, 4}, // 40 |
0 | 846 |
{81, 0, 25, 0, 9}, |
847 |
{81, 36, 25, 0, 9}, |
|
848 |
{81, 36, 25, 16, 9}, |
|
849 |
{81, 49, 0, 25, 9}, |
|
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
850 |
{81, 64, 0, 25, 9}, // 60 |
0 | 851 |
{81, 64, 0, 36, 9}, |
852 |
{81, 64, 0, 36, 16}, |
|
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
853 |
{100, 81, 0, 49, 16}, |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
854 |
{100, 81, 0, 49, 25}, |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
855 |
{121, 81, 0, 49, 25}, // 80 |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
856 |
{121, 81, 0, 49, 25}, |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
857 |
{121, 81, 0, 49, 36}, // 88 |
0 | 858 |
}; |
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
859 |
|
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
860 |
if (t->num_houses < 92) { |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
861 |
memcpy(t->radius, _town_radius_data[t->num_houses / 4], sizeof(t->radius)); |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
862 |
} else { |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
863 |
int mass = t->num_houses / 8; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
864 |
// At least very roughly extrapolate. Empirical numbers dancing between |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
865 |
// overwhelming by cottages and skyscrapers outskirts. |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
866 |
t->radius[0] = mass * mass; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
867 |
// Actually we are proportional to sqrt() but that's right because |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
868 |
// we are covering an area. |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
869 |
t->radius[1] = mass * 7; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
870 |
t->radius[2] = 0; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
871 |
t->radius[3] = mass * 4; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
872 |
t->radius[4] = mass * 3; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
873 |
//debug("%d (->%d): %d %d %d %d\n", t->num_houses, mass, t->radius[0], t->radius[1], t->radius[3], t->radius[4]); |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
874 |
} |
0 | 875 |
} |
876 |
||
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
877 |
static bool CreateTownName(uint32 *townnameparts) |
0 | 878 |
{ |
879 |
Town *t2; |
|
880 |
char buf1[64]; |
|
881 |
char buf2[64]; |
|
882 |
uint32 r; |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
883 |
/* Do not set too low tries, since when we run out of names, we loop |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
884 |
* for #tries only one time anyway - then we stop generating more |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
885 |
* towns. Do not show it too high neither, since looping through all |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
886 |
* the other towns may take considerable amount of time (10000 is |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
887 |
* too much). */ |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
888 |
int tries = 1000; |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
889 |
uint16 townnametype = SPECSTR_TOWNNAME_START + _opt.town_name; |
0 | 890 |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
891 |
assert(townnameparts); |
0 | 892 |
|
893 |
for(;;) { |
|
894 |
restart: |
|
895 |
r = Random(); |
|
896 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
897 |
SetDParam(0, r); |
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
898 |
GetString(buf1, townnametype); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
899 |
|
0 | 900 |
// Check size and width |
901 |
if (strlen(buf1) >= 31 || GetStringWidth(buf1) > 130) |
|
902 |
continue; |
|
903 |
||
904 |
FOR_ALL_TOWNS(t2) { |
|
905 |
if (t2->xy != 0) { |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
906 |
// We can't just compare the numbers since |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
907 |
// several numbers may map to a single name. |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
908 |
SetDParam(0, t2->townnameparts); |
0 | 909 |
GetString(buf2, t2->townnametype); |
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
910 |
if (strcmp(buf1, buf2) == 0) { |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
911 |
if (tries-- < 0) |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
912 |
return false; |
0 | 913 |
goto restart; |
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
914 |
} |
0 | 915 |
} |
916 |
} |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
917 |
*townnameparts = r; |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
918 |
return true; |
0 | 919 |
} |
920 |
} |
|
921 |
||
1377
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
922 |
void UpdateTownMaxPass(Town *t) |
0 | 923 |
{ |
924 |
t->max_pass = t->population >> 3; |
|
925 |
t->max_mail = t->population >> 4; |
|
926 |
} |
|
927 |
||
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
928 |
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts) |
0 | 929 |
{ |
930 |
int x, i; |
|
931 |
||
932 |
// clear the town struct |
|
933 |
i = t->index; |
|
934 |
memset(t, 0, sizeof(Town)); |
|
935 |
t->index = i; |
|
936 |
||
937 |
t->xy = tile; |
|
938 |
t->num_houses = 0; |
|
939 |
t->time_until_rebuild = 10; |
|
940 |
UpdateTownRadius(t); |
|
941 |
t->flags12 = 0; |
|
942 |
t->population = 0; |
|
943 |
t->grow_counter = 0; |
|
944 |
t->growth_rate = 250; |
|
945 |
t->new_max_pass = 0; |
|
946 |
t->new_max_mail = 0; |
|
947 |
t->new_act_pass = 0; |
|
948 |
t->new_act_mail = 0; |
|
949 |
t->max_pass = 0; |
|
950 |
t->max_mail = 0; |
|
951 |
t->act_pass = 0; |
|
952 |
t->act_mail = 0; |
|
953 |
||
954 |
t->pct_pass_transported = 0; |
|
955 |
t->pct_mail_transported = 0; |
|
956 |
t->fund_buildings_months = 0; |
|
957 |
t->new_act_food = 0; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
958 |
t->new_act_water = 0; |
0 | 959 |
t->act_food = 0; |
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
960 |
t->act_water = 0; |
0 | 961 |
|
962 |
for(i = 0; i != MAX_PLAYERS; i++) |
|
963 |
t->ratings[i] = 500; |
|
964 |
||
965 |
t->have_ratings = 0; |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
966 |
t->exclusivity = (byte)-1; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
967 |
t->exclusive_counter = 0; |
0 | 968 |
t->statues = 0; |
969 |
||
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
970 |
t->townnametype = SPECSTR_TOWNNAME_START + _opt.town_name; |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
971 |
t->townnameparts = townnameparts; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
972 |
|
0 | 973 |
UpdateTownVirtCoord(t); |
974 |
_town_sort_dirty = true; |
|
975 |
||
976 |
x = (Random() & 0xF) + 8; |
|
977 |
if (_game_mode == GM_EDITOR) |
|
978 |
x = _new_town_size * 16 + 3; |
|
979 |
||
980 |
t->num_houses += x; |
|
981 |
UpdateTownRadius(t); |
|
982 |
||
983 |
i = x * 4; |
|
984 |
do { |
|
985 |
GrowTown(t); |
|
986 |
} while (--i); |
|
987 |
||
988 |
t->num_houses -= x; |
|
989 |
UpdateTownRadius(t); |
|
990 |
UpdateTownMaxPass(t); |
|
991 |
} |
|
992 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
993 |
static Town *AllocateTown(void) |
0 | 994 |
{ |
995 |
Town *t; |
|
996 |
FOR_ALL_TOWNS(t) { |
|
997 |
if (t->xy == 0) { |
|
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
998 |
uint index = t->index; |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
999 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1000 |
if (t->index > _total_towns) |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1001 |
_total_towns = t->index; |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1002 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1003 |
memset(t, 0, sizeof(Town)); |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1004 |
t->index = index; |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1005 |
|
0 | 1006 |
return t; |
1007 |
} |
|
1008 |
} |
|
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1009 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1010 |
/* Check if we can add a block to the pool */ |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1011 |
if (AddBlockToPool(&_town_pool)) |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1012 |
return AllocateTown(); |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1013 |
|
0 | 1014 |
return NULL; |
1015 |
} |
|
1016 |
||
1017 |
int32 CmdBuildTown(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1018 |
{ |
|
1019 |
uint tile = TILE_FROM_XY(x,y); |
|
1020 |
TileInfo ti; |
|
1021 |
Town *t; |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1022 |
uint32 townnameparts; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1023 |
|
0 | 1024 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
1025 |
||
1026 |
// Check if too close to the edge of map |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
1027 |
if (DistanceFromEdge(tile) < 12) |
0 | 1028 |
return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP); |
1029 |
||
1030 |
// Can only build on clear flat areas. |
|
1031 |
FindLandscapeHeightByTile(&ti, tile); |
|
1032 |
if (ti.type != MP_CLEAR || ti.tileh != 0) |
|
1033 |
return_cmd_error(STR_0239_SITE_UNSUITABLE); |
|
1034 |
||
1035 |
// Check distance to all other towns. |
|
1036 |
if (IsCloseToTown(tile, 20)) |
|
1037 |
return_cmd_error(STR_0238_TOO_CLOSE_TO_ANOTHER_TOWN); |
|
1038 |
||
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1039 |
// Get a unique name for the town. |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1040 |
if (!CreateTownName(&townnameparts)) |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1041 |
return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1042 |
|
0 | 1043 |
// Allocate town struct |
1044 |
t = AllocateTown(); |
|
1045 |
if (t == NULL) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1046 |
return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
0 | 1047 |
|
1048 |
// Create the town |
|
1049 |
if (flags & DC_EXEC) { |
|
1050 |
_generating_world = true; |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1051 |
DoCreateTown(t, tile, townnameparts); |
0 | 1052 |
_generating_world = false; |
1053 |
} |
|
1054 |
return 0; |
|
1055 |
} |
|
1056 |
||
1362
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1057 |
Town *CreateRandomTown(uint attempts) |
0 | 1058 |
{ |
1059 |
uint tile; |
|
1060 |
TileInfo ti; |
|
1061 |
Town *t; |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1062 |
uint32 townnameparts; |
0 | 1063 |
|
1064 |
do { |
|
1065 |
// Generate a tile index not too close from the edge |
|
1066 |
tile = TILE_MASK(Random()); |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
1067 |
if (DistanceFromEdge(tile) < 20) |
0 | 1068 |
continue; |
1069 |
||
1070 |
// Make sure the tile is plain |
|
1071 |
FindLandscapeHeightByTile(&ti, tile); |
|
1072 |
if (ti.type != MP_CLEAR || ti.tileh != 0) |
|
1073 |
continue; |
|
1074 |
||
1075 |
// Check not too close to a town |
|
1076 |
if (IsCloseToTown(tile, 20)) |
|
1077 |
continue; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1078 |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1079 |
// Get a unique name for the town. |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1080 |
if (!CreateTownName(&townnameparts)) |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1081 |
break; |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1082 |
|
0 | 1083 |
// Allocate a town struct |
1084 |
t = AllocateTown(); |
|
1085 |
if (t == NULL) |
|
1086 |
break; |
|
1087 |
||
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1088 |
DoCreateTown(t, tile, townnameparts); |
0 | 1089 |
return t; |
1362
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1090 |
} while (--attempts); |
0 | 1091 |
return NULL; |
1092 |
} |
|
1093 |
||
1094 |
static const byte _num_initial_towns[3] = { |
|
1095 |
11, 23, 46 |
|
1096 |
}; |
|
1097 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
1098 |
void GenerateTowns(void) |
0 | 1099 |
{ |
1362
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1100 |
uint num = 0; |
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1101 |
uint n = |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1102 |
ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7)); |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1103 |
|
1362
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1104 |
do { |
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1105 |
if (CreateRandomTown(20) != NULL) //try 20 times for the first loop |
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1106 |
num++; |
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1107 |
} while (--n); |
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1108 |
|
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1109 |
if (num == 0 && CreateRandomTown(10000) == NULL) { |
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1110 |
//XXX can we handle that more gracefully? |
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1111 |
error("Could not generate any town"); |
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1112 |
} |
0 | 1113 |
} |
1114 |
||
1115 |
static bool CheckBuildHouseMode(Town *t1, uint tile, uint tileh, int mode) { |
|
1116 |
int b; |
|
1117 |
uint slope; |
|
1118 |
||
1119 |
static const byte _masks[8] = { |
|
1120 |
0xC,0x3,0x9,0x6, |
|
1121 |
0x3,0xC,0x6,0x9, |
|
1122 |
}; |
|
1123 |
||
1124 |
slope = GetTileSlope(tile, NULL); |
|
1125 |
if (slope & 0x10) |
|
1126 |
return false; |
|
1127 |
||
1128 |
b = 0; |
|
1129 |
if ((slope & 0xF && ~slope & _masks[mode])) b = ~b; |
|
1130 |
if ((tileh & 0xF && ~tileh & _masks[mode+4])) b = ~b; |
|
1131 |
if (b) |
|
1132 |
return false; |
|
1133 |
||
1134 |
return DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR) != CMD_ERROR; |
|
1135 |
} |
|
1136 |
||
1137 |
int GetTownRadiusGroup(Town *t, uint tile) |
|
1138 |
{ |
|
1139 |
uint dist; |
|
1140 |
int i,smallest; |
|
1141 |
||
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
1142 |
dist = DistanceSquare(tile, t->xy); |
0 | 1143 |
if (t->fund_buildings_months && dist <= 25) |
1144 |
return 4; |
|
1145 |
||
1146 |
smallest = 0; |
|
1147 |
for(i=0; i!=lengthof(t->radius); i++) { |
|
1148 |
if (dist < t->radius[i]) |
|
1149 |
smallest = i; |
|
1150 |
} |
|
1151 |
||
1152 |
return smallest; |
|
1153 |
} |
|
1154 |
||
1155 |
static bool CheckFree2x2Area(Town *t1, uint tile) |
|
1156 |
{ |
|
1157 |
int i; |
|
1158 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1159 |
static const TileIndexDiffC _tile_add[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1160 |
{0 , 0 }, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1161 |
{0 - 0, 1 - 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1162 |
{1 - 0, 0 - 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1163 |
{1 - 1, 1 - 0} |
0 | 1164 |
}; |
1165 |
||
1166 |
for(i=0; i!=4; i++) { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1167 |
tile += ToTileIndexDiff(_tile_add[i]); |
0 | 1168 |
|
1169 |
if (GetTileSlope(tile, NULL)) |
|
1170 |
return false; |
|
1171 |
||
1172 |
if (DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_FORCETEST, CMD_LANDSCAPE_CLEAR) == CMD_ERROR) |
|
1173 |
return false; |
|
1174 |
} |
|
1175 |
||
1176 |
return true; |
|
1177 |
} |
|
1178 |
||
1179 |
static void DoBuildTownHouse(Town *t, uint tile) |
|
1180 |
{ |
|
1181 |
int i; |
|
1182 |
uint bitmask; |
|
1183 |
int house; |
|
1184 |
uint slope; |
|
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
1185 |
uint z; |
0 | 1186 |
uint oneof; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1187 |
|
0 | 1188 |
// Above snow? |
1189 |
slope = GetTileSlope(tile, &z); |
|
1190 |
||
1191 |
// Get the town zone type |
|
1192 |
{ |
|
1193 |
uint rad = GetTownRadiusGroup(t, tile); |
|
1194 |
||
1195 |
int land = _opt.landscape; |
|
1196 |
if (land == LT_HILLY && z >= _opt.snow_line) |
|
1197 |
land = -1; |
|
1198 |
||
1199 |
bitmask = (1 << rad) + (1 << (land + 12)); |
|
1200 |
} |
|
1201 |
||
1202 |
// bits 0-4 are used |
|
1203 |
// bits 11-15 are used |
|
1204 |
// bits 5-10 are not used. |
|
1205 |
{ |
|
1206 |
byte houses[lengthof(_housetype_flags)]; |
|
1207 |
int num = 0; |
|
1208 |
||
1209 |
// Generate a list of all possible houses that can be built. |
|
1210 |
for(i=0; i!=lengthof(_housetype_flags); i++) { |
|
1211 |
if ((~_housetype_flags[i] & bitmask) == 0) |
|
1212 |
houses[num++] = (byte)i; |
|
1213 |
} |
|
1214 |
||
1215 |
for(;;) { |
|
1216 |
house = houses[RandomRange(num)]; |
|
1217 |
||
1218 |
if (_cur_year < _housetype_years[house].min || _cur_year > _housetype_years[house].max) |
|
1219 |
continue; |
|
1220 |
||
1221 |
// Special houses that there can be only one of. |
|
483
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1222 |
switch (house) { |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1223 |
case HOUSE_TEMP_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1224 |
case HOUSE_ARCT_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1225 |
case HOUSE_SNOW_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1226 |
case HOUSE_TROP_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1227 |
case HOUSE_TOY_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1228 |
oneof = TOWN_HAS_CHURCH; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1229 |
break; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1230 |
case HOUSE_STADIUM: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1231 |
case HOUSE_MODERN_STADIUM: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1232 |
oneof = TOWN_HAS_STADIUM; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1233 |
break; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1234 |
default: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1235 |
oneof = 0; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1236 |
break; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1237 |
} |
0 | 1238 |
|
1239 |
if (t->flags12 & oneof) |
|
1240 |
continue; |
|
1241 |
||
1242 |
// Make sure there is no slope? |
|
1243 |
if (_housetype_extra_flags[house]&0x12 && slope) |
|
1244 |
continue; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1245 |
|
0 | 1246 |
if (_housetype_extra_flags[house]&0x10) { |
1247 |
if (CheckFree2x2Area(t,tile) || |
|
1248 |
CheckFree2x2Area(t,(tile+=TILE_XY(-1,0))) || |
|
1249 |
CheckFree2x2Area(t,(tile+=TILE_XY(0,-1))) || |
|
1250 |
CheckFree2x2Area(t,(tile+=TILE_XY(1,0)))) |
|
1251 |
break; |
|
1252 |
tile += TILE_XY(0,1); |
|
1253 |
} else if (_housetype_extra_flags[house]&4) { |
|
1254 |
if (CheckBuildHouseMode(t, tile+TILE_XY(1,0), slope, 0)) |
|
1255 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1256 |
|
0 | 1257 |
if (CheckBuildHouseMode(t, tile+TILE_XY(-1,0), slope, 1)) { |
1258 |
tile += TILE_XY(-1,0); |
|
1259 |
break; |
|
1260 |
} |
|
1261 |
} else if (_housetype_extra_flags[house]&8) { |
|
1262 |
if (CheckBuildHouseMode(t, tile+TILE_XY(0,1), slope, 2)) |
|
1263 |
break; |
|
1264 |
||
1265 |
if (CheckBuildHouseMode(t, tile+TILE_XY(0,-1), slope, 3)) { |
|
1266 |
tile += TILE_XY(0,-1); |
|
1267 |
break; |
|
1268 |
} |
|
1269 |
} else |
|
1270 |
break; |
|
1271 |
} |
|
1272 |
} |
|
1273 |
||
1274 |
t->num_houses++; |
|
1275 |
||
1276 |
// Special houses that there can be only one of. |
|
1277 |
t->flags12 |= oneof; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1278 |
|
0 | 1279 |
{ |
1280 |
int m3lo,m5,eflags; |
|
1281 |
||
1282 |
// ENDING_2 |
|
1283 |
m3lo = 0; |
|
1284 |
m5 = 0; |
|
1285 |
if (_generating_world) { |
|
1286 |
uint32 r = Random(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1287 |
|
0 | 1288 |
// Value for map3lo |
1289 |
m3lo = 0xC0; |
|
1290 |
if ((byte)r >= 220) m3lo &= (r>>8); |
|
1291 |
||
1292 |
if (m3lo == 0xC0) |
|
1293 |
ChangePopulation(t, _housetype_population[house]); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1294 |
|
0 | 1295 |
// Initial value for map5. |
1296 |
m5 = (r >> 16) & 0x3F; |
|
1297 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1298 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1299 |
assert(IsTileType(tile, MP_CLEAR)); |
0 | 1300 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1301 |
ModifyTile(tile, |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1302 |
MP_SETTYPE(MP_HOUSE) | MP_MAP3HI | MP_MAP3LO | MP_MAP2 | MP_MAP5 | MP_MAPOWNER, |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1303 |
t->index, |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1304 |
m3lo, /* map3_lo */ |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1305 |
house, /* map3_hi */ |
0 | 1306 |
0, /* map_owner */ |
1307 |
m5 /* map5 */ |
|
1308 |
); |
|
1309 |
||
1310 |
eflags = _housetype_extra_flags[house]; |
|
1311 |
||
1312 |
if (eflags&0x18) { |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1313 |
assert(IsTileType(tile + TILE_XY(0,1), MP_CLEAR)); |
0 | 1314 |
ModifyTile(tile + TILE_XY(0,1), |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1315 |
MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER, |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1316 |
t->index, |
0 | 1317 |
m3lo, /* map3_lo */ |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1318 |
++house, /* map3_hi */ |
0 | 1319 |
0, /* map_owner */ |
1320 |
m5 /* map5 */ |
|
1321 |
); |
|
1322 |
} |
|
1323 |
||
1324 |
if (eflags&0x14) { |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1325 |
assert(IsTileType(tile + TILE_XY(1,0), MP_CLEAR)); |
0 | 1326 |
ModifyTile(tile + TILE_XY(1,0), |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1327 |
MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER, |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1328 |
t->index, |
0 | 1329 |
m3lo, /* map3_lo */ |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1330 |
++house, /* map3_hi */ |
0 | 1331 |
0, /* map_owner */ |
1332 |
m5 /* map5 */ |
|
1333 |
); |
|
1334 |
} |
|
1335 |
||
1336 |
if (eflags&0x10) { |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1337 |
assert(IsTileType(tile + TILE_XY(1,1), MP_CLEAR)); |
0 | 1338 |
ModifyTile(tile + TILE_XY(1,1), |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1339 |
MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER, |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1340 |
t->index, |
0 | 1341 |
m3lo, /* map3_lo */ |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1342 |
++house, /* map3_hi */ |
0 | 1343 |
0, /* map_owner */ |
1344 |
m5 /* map5 */ |
|
1345 |
); |
|
1346 |
} |
|
1347 |
} |
|
1348 |
||
1349 |
// ENDING |
|
1350 |
} |
|
1351 |
||
1352 |
static bool BuildTownHouse(Town *t, uint tile) |
|
1353 |
{ |
|
1354 |
int32 r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1355 |
|
0 | 1356 |
// make sure it's possible |
1357 |
if (!EnsureNoVehicle(tile)) return false; |
|
1358 |
if (GetTileSlope(tile, NULL) & 0x10) return false; |
|
1359 |
||
1360 |
r = DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR); |
|
1361 |
if (r == CMD_ERROR) return false; |
|
1362 |
||
1363 |
DoBuildTownHouse(t, tile); |
|
1364 |
return true; |
|
1365 |
} |
|
1366 |
||
1367 |
||
1368 |
static void DoClearTownHouseHelper(uint tile) |
|
1369 |
{ |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1370 |
assert(IsTileType(tile, MP_HOUSE)); |
0 | 1371 |
DoClearSquare(tile); |
1372 |
DeleteAnimatedTile(tile); |
|
1373 |
} |
|
1374 |
||
1375 |
static void ClearTownHouse(Town *t, uint tile) { |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1376 |
uint house = _map3_hi[tile]; |
0 | 1377 |
uint eflags; |
1378 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1379 |
assert(IsTileType(tile, MP_HOUSE)); |
0 | 1380 |
|
1381 |
// need to align the tile to point to the upper left corner of the house |
|
1382 |
if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks. |
|
1383 |
if (_housetype_extra_flags[house-1] & 0x04) { |
|
1384 |
house--; |
|
1385 |
tile += TILE_XY(-1,0); |
|
1386 |
} else if (_housetype_extra_flags[house-1] & 0x18) { |
|
1387 |
house--; |
|
1388 |
tile += TILE_XY(0,-1); |
|
1389 |
} else if (_housetype_extra_flags[house-2] & 0x10) { |
|
1390 |
house-=2; |
|
1391 |
tile += TILE_XY(-1,0); |
|
1392 |
} else if (_housetype_extra_flags[house-3] & 0x10) { |
|
1393 |
house-=3; |
|
1394 |
tile += TILE_XY(-1,-1); |
|
1395 |
} |
|
1396 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1397 |
|
0 | 1398 |
// Remove population from the town if the |
1399 |
// house is finished. |
|
1400 |
if ((~_map3_lo[tile] & 0xC0) == 0) { |
|
1401 |
ChangePopulation(t, -_housetype_population[house]); |
|
1402 |
} |
|
1403 |
||
1404 |
t->num_houses--; |
|
1405 |
||
1406 |
// Clear flags for houses that only may exist once/town. |
|
483
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1407 |
switch (house) { |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1408 |
case HOUSE_TEMP_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1409 |
case HOUSE_ARCT_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1410 |
case HOUSE_SNOW_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1411 |
case HOUSE_TROP_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1412 |
case HOUSE_TOY_CHURCH: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1413 |
t->flags12 &= ~TOWN_HAS_CHURCH; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1414 |
break; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1415 |
case HOUSE_STADIUM: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1416 |
case HOUSE_MODERN_STADIUM: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1417 |
t->flags12 &= ~TOWN_HAS_STADIUM; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1418 |
break; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1419 |
default: |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1420 |
break; |
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1421 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1422 |
|
0 | 1423 |
// Do the actual clearing of tiles |
1424 |
eflags = _housetype_extra_flags[house]; |
|
1425 |
DoClearTownHouseHelper(tile); |
|
1426 |
if (eflags & 0x14) DoClearTownHouseHelper(tile + TILE_XY(1,0)); |
|
1427 |
if (eflags & 0x18) DoClearTownHouseHelper(tile + TILE_XY(0,1)); |
|
1428 |
if (eflags & 0x10) DoClearTownHouseHelper(tile + TILE_XY(1,1)); |
|
1429 |
} |
|
1430 |
||
1431 |
int32 CmdRenameTown(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1432 |
{ |
|
1433 |
StringID str; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1434 |
Town *t = GetTown(p1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1435 |
|
1328
eacd8225ed42
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1327
diff
changeset
|
1436 |
str = AllocateNameUnique((const char*)_decode_parameters, 4); |
0 | 1437 |
if (str == 0) |
1438 |
return CMD_ERROR; |
|
1439 |
||
1440 |
if (flags & DC_EXEC) { |
|
1441 |
StringID old_str = t->townnametype; |
|
1442 |
t->townnametype = str; |
|
1443 |
DeleteName(old_str); |
|
1444 |
||
1445 |
UpdateTownVirtCoord(t); |
|
1446 |
_town_sort_dirty = true; |
|
1447 |
UpdateAllStationVirtCoord(); |
|
1448 |
MarkWholeScreenDirty(); |
|
1449 |
} else { |
|
1450 |
DeleteName(str); |
|
1451 |
} |
|
1452 |
return 0; |
|
1453 |
} |
|
1454 |
||
1455 |
// Called from GUI |
|
1456 |
void DeleteTown(Town *t) |
|
1457 |
{ |
|
1458 |
Industry *i; |
|
1252
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1459 |
TileIndex tile; |
0 | 1460 |
|
1461 |
// Delete town authority window |
|
1462 |
// and remove from list of sorted towns |
|
1463 |
DeleteWindowById(WC_TOWN_VIEW, t->index); |
|
1464 |
_town_sort_dirty = true; |
|
1465 |
||
1466 |
// Delete all industries belonging to the town |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1467 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1468 |
if (i->xy && i->town == t) |
1469 |
DeleteIndustry(i); |
|
1470 |
} |
|
1471 |
||
1472 |
// Go through all tiles and delete those belonging to the town |
|
1252
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1473 |
for (tile = 0; tile < MapSize(); ++tile) { |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1474 |
switch (GetTileType(tile)) { |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1475 |
case MP_HOUSE: |
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
1476 |
if (GetTown(_map2[tile]) == t) |
1252
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1477 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1478 |
break; |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1479 |
|
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1480 |
case MP_STREET: |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1481 |
case MP_TUNNELBRIDGE: |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1482 |
if (_map_owner[tile] == OWNER_TOWN && |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1483 |
ClosestTownFromTile(tile, (uint)-1) == t) |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1484 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1485 |
break; |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1486 |
|
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1487 |
default: |
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1488 |
break; |
0 | 1489 |
} |
1252
fa73bce0f2e0
(svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents:
1245
diff
changeset
|
1490 |
} |
0 | 1491 |
|
1492 |
t->xy = 0; |
|
1493 |
DeleteName(t->townnametype); |
|
1494 |
||
1495 |
MarkWholeScreenDirty(); |
|
1496 |
} |
|
1497 |
||
1498 |
// Called from GUI |
|
1499 |
void ExpandTown(Town *t) |
|
1500 |
{ |
|
1501 |
int amount, n; |
|
1502 |
||
1503 |
_generating_world = true; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1504 |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
1505 |
/* The more houses, the faster we grow */ |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
1506 |
amount = RandomRange(t->num_houses / 10) + 3; |
0 | 1507 |
t->num_houses += amount; |
1508 |
UpdateTownRadius(t); |
|
1509 |
||
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
1510 |
n = amount * 10; |
0 | 1511 |
do GrowTown(t); while (--n); |
1512 |
||
1513 |
t->num_houses -= amount; |
|
1514 |
UpdateTownRadius(t); |
|
1515 |
||
1516 |
UpdateTownMaxPass(t); |
|
1517 |
_generating_world = false; |
|
1518 |
} |
|
1519 |
||
1520 |
const byte _town_action_costs[8] = { |
|
1521 |
2, 4, 9, 35, 48, 53, 117, 175 |
|
1522 |
}; |
|
1523 |
||
1524 |
typedef void TownActionProc(Town *t, int action); |
|
1525 |
||
1526 |
static void TownActionAdvertise(Town *t, int action) |
|
1527 |
{ |
|
1528 |
static const byte _advertising_amount[3] = {0x40, 0x70, 0xA0}; |
|
1529 |
static const byte _advertising_radius[3] = {10,15,20}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1530 |
ModifyStationRatingAround(t->xy, _current_player, |
0 | 1531 |
_advertising_amount[action], |
1532 |
_advertising_radius[action]); |
|
1533 |
} |
|
1534 |
||
1535 |
static void TownActionRoadRebuild(Town *t, int action) |
|
1536 |
{ |
|
1537 |
Player *p; |
|
1538 |
||
1539 |
t->road_build_months = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1540 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1541 |
SetDParam(0, t->index); |
0 | 1542 |
|
1543 |
p = DEREF_PLAYER(_current_player); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1544 |
SetDParam(1, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1545 |
SetDParam(2, p->name_2); |
0 | 1546 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1547 |
AddNewsItem(STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING, |
0 | 1548 |
NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_GENERAL, 0), t->xy, 0); |
1549 |
} |
|
1550 |
||
1551 |
static bool DoBuildStatueOfCompany(uint tile) |
|
1552 |
{ |
|
1553 |
TileInfo ti; |
|
1554 |
byte old; |
|
1555 |
int32 r; |
|
1556 |
||
1557 |
FindLandscapeHeightByTile(&ti, tile); |
|
1558 |
if (ti.tileh != 0) |
|
1559 |
return false; |
|
1560 |
||
1561 |
if (ti.type != MP_HOUSE && ti.type != MP_CLEAR && ti.type != MP_TREES) |
|
1562 |
return false; |
|
1563 |
||
1564 |
||
1565 |
old = _current_player; |
|
1566 |
_current_player = OWNER_NONE; |
|
1567 |
r = DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1568 |
_current_player = old; |
|
1569 |
||
1570 |
if (r == CMD_ERROR) |
|
1571 |
return false; |
|
1572 |
||
1573 |
ModifyTile(tile, MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
1574 |
2 /* map5 */ |
|
1575 |
); |
|
1576 |
||
1577 |
return true; |
|
1578 |
} |
|
1579 |
||
1580 |
static void TownActionBuildStatue(Town *t, int action) |
|
1581 |
{ |
|
1582 |
// Layouted as an outward spiral |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1583 |
static const TileIndexDiffC _statue_tiles[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1584 |
{-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1585 |
{ 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1586 |
{ 1, 0}, { 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1587 |
{ 0,-1}, { 0,-1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1588 |
{-1, 0}, {-1, 0}, {-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1589 |
{ 0, 1}, { 0, 1}, { 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1590 |
{ 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1591 |
{ 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1592 |
{-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1593 |
{ 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1594 |
{ 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1595 |
{ 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1596 |
{-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1597 |
{ 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1598 |
{ 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1599 |
{ 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1600 |
{-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1601 |
{ 0, 0} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1602 |
}; |
0 | 1603 |
uint tile = t->xy; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1604 |
const TileIndexDiffC *p; |
0 | 1605 |
|
1606 |
SETBIT(t->statues, _current_player); |
|
1607 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1608 |
for (p = _statue_tiles; p != endof(_statue_tiles); ++p) { |
0 | 1609 |
if (DoBuildStatueOfCompany(tile)) |
1610 |
return; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1611 |
tile = TILE_ADD(tile, ToTileIndexDiff(*p)); |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1612 |
} |
0 | 1613 |
} |
1614 |
||
1615 |
static void TownActionFundBuildings(Town *t, int action) |
|
1616 |
{ |
|
1617 |
t->grow_counter = 1; |
|
1618 |
t->flags12 |= 1; |
|
1619 |
t->fund_buildings_months = 3; |
|
1620 |
} |
|
1621 |
||
1622 |
static void TownActionBuyRights(Town *t, int action) |
|
1623 |
{ |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1624 |
t->exclusive_counter = 12; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1625 |
t->exclusivity = _current_player; |
0 | 1626 |
|
1627 |
ModifyStationRatingAround(t->xy, _current_player, 130, 17); |
|
1628 |
} |
|
1629 |
||
1630 |
static void TownActionBribe(Town *t, int action) |
|
1631 |
{ |
|
1632 |
if (!RandomRange(15)) { |
|
1633 |
GoodsEntry *ge; |
|
1634 |
Station *st; |
|
1635 |
int i, rating; |
|
1636 |
||
1637 |
// set as unwanted for 6 months |
|
1638 |
t->unwanted[_current_player] = 6; |
|
1639 |
||
1640 |
// set all close by station ratings to 0 |
|
1641 |
FOR_ALL_STATIONS(st) { |
|
1642 |
if (st->town == t && st->owner == _current_player) { |
|
1643 |
for (i=0, ge = st->goods; i != NUM_CARGO; i++, ge++) |
|
1644 |
ge->rating = 0; |
|
1645 |
} |
|
1646 |
} |
|
1647 |
||
1648 |
// only show errormessage to the executing player. All errors are handled command.c |
|
1649 |
// but this is special, because it can only 'fail' on a DC_EXEC |
|
1650 |
if (!_networking || (_current_player == _local_player)) |
|
1651 |
ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 0, 0); |
|
1652 |
||
1653 |
/* decrease by a lot! |
|
1654 |
* ChangeTownRating is only for stuff in demolishing. Bribe failure should |
|
1655 |
* be independent of any cheat settings |
|
1656 |
*/ |
|
1657 |
rating = t->ratings[_current_player]; |
|
1658 |
if (rating > -50) |
|
1005 | 1659 |
t->ratings[_current_player] = RATING_BRIBE_DOWN_TO; |
0 | 1660 |
} else { |
1005 | 1661 |
ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM); |
0 | 1662 |
} |
1663 |
} |
|
1664 |
||
1665 |
static TownActionProc * const _town_action_proc[] = { |
|
1666 |
TownActionAdvertise, |
|
1667 |
TownActionAdvertise, |
|
1668 |
TownActionAdvertise, |
|
1669 |
TownActionRoadRebuild, |
|
1670 |
TownActionBuildStatue, |
|
1671 |
TownActionFundBuildings, |
|
1672 |
TownActionBuyRights, |
|
1673 |
TownActionBribe |
|
1674 |
}; |
|
1675 |
||
1676 |
// p1 = town |
|
1677 |
// p2 = action |
|
1678 |
int32 CmdDoTownAction(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1679 |
{ |
|
1680 |
int32 cost; |
|
1681 |
||
1682 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1683 |
||
1684 |
cost = (_price.build_industry >> 8) * _town_action_costs[p2]; |
|
1685 |
||
1686 |
if (flags & DC_EXEC) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1687 |
_town_action_proc[p2](GetTown(p1), p2); |
0 | 1688 |
InvalidateWindow(WC_TOWN_AUTHORITY, p1); |
1689 |
} |
|
1690 |
||
1691 |
return cost; |
|
1692 |
} |
|
1693 |
||
1694 |
static void UpdateTownGrowRate(Town *t) |
|
1695 |
{ |
|
1696 |
int n; |
|
1697 |
Station *st; |
|
1698 |
byte m; |
|
1699 |
Player *p; |
|
1700 |
||
1701 |
// Reset player ratings if they're low |
|
1702 |
FOR_ALL_PLAYERS(p) { |
|
1703 |
if (p->is_active && t->ratings[p->index] <= 200) { |
|
1704 |
t->ratings[p->index] += 5; |
|
1705 |
} |
|
1706 |
} |
|
1707 |
||
1708 |
n = 0; |
|
1709 |
FOR_ALL_STATIONS(st) { |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
1710 |
if (DistanceSquare(st->xy, t->xy) <= t->radius[0]) { |
0 | 1711 |
if (st->time_since_load <= 20 || st->time_since_unload <= 20) { |
1712 |
n++; |
|
1713 |
if (st->owner < MAX_PLAYERS && t->ratings[st->owner] <= 1000-12) |
|
1714 |
t->ratings[st->owner] += 12; |
|
1715 |
} else { |
|
1716 |
if (st->owner < MAX_PLAYERS && t->ratings[st->owner] >= -1000+15) |
|
1717 |
t->ratings[st->owner] -= 15; |
|
1718 |
} |
|
1719 |
} |
|
1720 |
} |
|
1721 |
||
1722 |
t->flags12 &= ~1; |
|
1723 |
||
1724 |
if (t->fund_buildings_months != 0) { |
|
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1725 |
static const byte _grow_count_values[6] = { |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1726 |
60, 60, 60, 50, 40, 30 |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1727 |
}; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1728 |
m = _grow_count_values[min(n, 5)]; |
0 | 1729 |
t->fund_buildings_months--; |
1730 |
} else if (n == 0) { |
|
1731 |
m = 160; |
|
1732 |
if (!CHANCE16(1, 12)) |
|
1733 |
return; |
|
1734 |
} else { |
|
1735 |
static const byte _grow_count_values[5] = { |
|
1736 |
210, 150, 110, 80, 50 |
|
1737 |
}; |
|
1738 |
m = _grow_count_values[min(n, 5) - 1]; |
|
1739 |
} |
|
1740 |
||
1741 |
if (_opt.landscape == LT_HILLY) { |
|
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
1742 |
if (TilePixelHeight(t->xy) >= _opt.snow_line && t->act_food == 0 && t->population > 90) |
0 | 1743 |
return; |
1744 |
} else if (_opt.landscape == LT_DESERT) { |
|
468
3a36baf27955
(svn r698) Merge a town growth fix from TTDPatch - in arctic and desert climate, require food (and possibly water) only if the population is more than 90, so that the town gets chance to actually accept it. (By Marcin?)
pasky
parents:
466
diff
changeset
|
1745 |
if (GetMapExtraBits(t->xy) == 1 && (t->act_food==0 || t->act_water==0) && t->population > 60) |
0 | 1746 |
return; |
1747 |
} |
|
1748 |
||
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1749 |
t->growth_rate = m / (t->num_houses / 50 + 1); |
0 | 1750 |
if (m <= t->grow_counter) |
1751 |
t->grow_counter = m; |
|
1752 |
||
1753 |
t->flags12 |= 1; |
|
1754 |
} |
|
1755 |
||
1756 |
static void UpdateTownAmounts(Town *t) |
|
1757 |
{ |
|
1758 |
// Using +1 here to prevent overflow and division by zero |
|
1759 |
t->pct_pass_transported = t->new_act_pass * 256 / (t->new_max_pass + 1); |
|
1760 |
||
1761 |
t->max_pass = t->new_max_pass; t->new_max_pass = 0; |
|
1762 |
t->act_pass = t->new_act_pass; t->new_act_pass = 0; |
|
1763 |
t->act_food = t->new_act_food; t->new_act_food = 0; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1764 |
t->act_water = t->new_act_water; t->new_act_water = 0; |
0 | 1765 |
|
1766 |
// Using +1 here to prevent overflow and division by zero |
|
1767 |
t->pct_mail_transported = t->new_act_mail * 256 / (t->new_max_mail + 1); |
|
1768 |
t->max_mail = t->new_max_mail; t->new_max_mail = 0; |
|
1769 |
t->act_mail = t->new_act_mail; t->new_act_mail = 0; |
|
1770 |
||
1771 |
InvalidateWindow(WC_TOWN_VIEW, t->index); |
|
1772 |
} |
|
1773 |
||
1774 |
static void UpdateTownUnwanted(Town *t) |
|
1775 |
{ |
|
1776 |
Player *p; |
|
1777 |
||
1778 |
FOR_ALL_PLAYERS(p) { |
|
1779 |
if (t->unwanted[p->index] > 0) |
|
1780 |
t->unwanted[p->index]--; |
|
1781 |
} |
|
1782 |
} |
|
1783 |
||
1784 |
bool CheckIfAuthorityAllows(uint tile) |
|
1785 |
{ |
|
1786 |
Town *t; |
|
1787 |
||
1788 |
if (_current_player >= MAX_PLAYERS) |
|
1789 |
return true; |
|
1790 |
||
1791 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
|
1792 |
if (t == NULL) |
|
1793 |
return true; |
|
1794 |
||
1795 |
if (t->ratings[_current_player] > -200) |
|
1796 |
return true; |
|
1797 |
||
1798 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1799 |
SetDParam(0, t->index); |
0 | 1800 |
|
1801 |
return false; |
|
1802 |
} |
|
1803 |
||
1804 |
||
1805 |
Town *ClosestTownFromTile(uint tile, uint threshold) |
|
1806 |
{ |
|
1807 |
Town *t; |
|
1808 |
uint dist, best = threshold; |
|
1809 |
Town *best_town = NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1810 |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1811 |
if ((IsTileType(tile, MP_STREET) && _map_owner[tile] == OWNER_TOWN) || IsTileType(tile, MP_HOUSE)) |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1812 |
return GetTown(_map2[tile]); |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1261
diff
changeset
|
1813 |
|
0 | 1814 |
FOR_ALL_TOWNS(t) { |
1815 |
if (t->xy != 0) { |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
1816 |
dist = DistanceManhattan(tile, t->xy); |
0 | 1817 |
if (dist < best) { |
1818 |
best = dist; |
|
1819 |
best_town = t; |
|
1820 |
} |
|
1821 |
} |
|
1822 |
} |
|
1823 |
||
1824 |
return best_town; |
|
1825 |
} |
|
1826 |
||
1827 |
void ChangeTownRating(Town *t, int add, int max) |
|
1828 |
{ |
|
1829 |
int rating; |
|
1830 |
||
1831 |
// if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff |
|
1832 |
if (t == NULL || _current_player >= MAX_PLAYERS || (_cheats.magic_bulldozer.value && add < 0) ) |
|
1833 |
return; |
|
1834 |
||
1835 |
SETBIT(t->have_ratings, _current_player); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1836 |
|
0 | 1837 |
rating = t->ratings[_current_player]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1838 |
|
0 | 1839 |
if (add < 0) { |
1840 |
if (rating > max) { |
|
1841 |
rating += add; |
|
1842 |
if (rating < max) rating = max; |
|
1843 |
} |
|
1844 |
} else { |
|
1845 |
if (rating < max) { |
|
1846 |
rating += add; |
|
1847 |
if (rating > max) rating = max; |
|
1848 |
} |
|
1849 |
} |
|
1850 |
t->ratings[_current_player] = rating; |
|
1851 |
} |
|
1852 |
||
1853 |
/* penalty for removing town-owned stuff */ |
|
1854 |
static const int _default_rating_settings [3][3] = { |
|
1855 |
// ROAD_REMOVE, TUNNELBRIDGE_REMOVE, INDUSTRY_REMOVE |
|
1856 |
{ 0, 128, 384}, // Permissive |
|
1857 |
{ 48, 192, 480}, // Neutral |
|
1858 |
{ 96, 384, 768}, // Hostile |
|
1859 |
}; |
|
1860 |
||
1861 |
bool CheckforTownRating(uint tile, uint32 flags, Town *t, byte type) |
|
1862 |
{ |
|
1863 |
int modemod; |
|
1864 |
||
1865 |
// if magic_bulldozer cheat is active, town doesn't restrict your destructive actions |
|
1866 |
if (t == NULL || _current_player >= MAX_PLAYERS || _cheats.magic_bulldozer.value) |
|
1867 |
return true; |
|
1868 |
||
1869 |
/* check if you're allowed to remove the street/bridge/tunnel/industry |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1870 |
* owned by a town no removal if rating is lower than ... depends now on |
0 | 1871 |
* difficulty setting. Minimum town rating selected by difficulty level |
1872 |
*/ |
|
1500
a66721629bc0
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1451
diff
changeset
|
1873 |
modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type]; |
0 | 1874 |
|
1875 |
if (t->ratings[_current_player] < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1876 |
SetDParam(0, t->index); |
0 | 1877 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
1878 |
return false; |
|
1879 |
} |
|
1880 |
||
1881 |
return true; |
|
1882 |
} |
|
1883 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
1884 |
void TownsMonthlyLoop(void) |
0 | 1885 |
{ |
1886 |
Town *t; |
|
1887 |
||
1888 |
FOR_ALL_TOWNS(t) if (t->xy != 0) { |
|
1889 |
if (t->road_build_months != 0) |
|
1890 |
t->road_build_months--; |
|
1891 |
||
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1892 |
if (t->exclusive_counter != 0) |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1893 |
if(--t->exclusive_counter==0) |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1894 |
t->exclusivity = (byte)-1; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1895 |
|
0 | 1896 |
UpdateTownGrowRate(t); |
1897 |
UpdateTownAmounts(t); |
|
1898 |
UpdateTownUnwanted(t); |
|
1899 |
} |
|
1900 |
} |
|
1901 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
1902 |
void InitializeTowns(void) |
0 | 1903 |
{ |
1904 |
Subsidy *s; |
|
1905 |
||
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1906 |
/* Clean the town pool and create 1 block in it */ |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1907 |
CleanPool(&_town_pool); |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1908 |
AddBlockToPool(&_town_pool); |
0 | 1909 |
|
1910 |
memset(_subsidies, 0, sizeof(_subsidies)); |
|
1911 |
for (s=_subsidies; s != endof(_subsidies); s++) |
|
1912 |
s->cargo_type = 0xFF; |
|
1913 |
||
1914 |
_cur_town_ctr = 0; |
|
1529
3a8196d15b01
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
1915 |
_cur_town_iter = 0; |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1916 |
_total_towns = 0; |
0 | 1917 |
_town_sort_dirty = true; |
1918 |
} |
|
1919 |
||
1920 |
const TileTypeProcs _tile_type_town_procs = { |
|
1921 |
DrawTile_Town, /* draw_tile_proc */ |
|
1922 |
GetSlopeZ_Town, /* get_slope_z_proc */ |
|
1923 |
ClearTile_Town, /* clear_tile_proc */ |
|
1924 |
GetAcceptedCargo_Town, /* get_accepted_cargo_proc */ |
|
1925 |
GetTileDesc_Town, /* get_tile_desc_proc */ |
|
1926 |
GetTileTrackStatus_Town, /* get_tile_track_status_proc */ |
|
1927 |
ClickTile_Town, /* click_tile_proc */ |
|
1928 |
AnimateTile_Town, /* animate_tile_proc */ |
|
1929 |
TileLoop_Town, /* tile_loop_clear */ |
|
1930 |
ChangeTileOwner_Town, /* change_tile_owner_clear */ |
|
1931 |
NULL, /* get_produced_cargo_proc */ |
|
1932 |
NULL, /* vehicle_enter_tile_proc */ |
|
1933 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1934 |
GetSlopeTileh_Town, /* get_slope_tileh_proc */ |
0 | 1935 |
}; |
1936 |
||
1937 |
||
1938 |
// Save and load of towns. |
|
1939 |
static const byte _town_desc[] = { |
|
1174
6a5e747f3ba6
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
1940 |
SLE_CONDVAR(Town, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
6a5e747f3ba6
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
1941 |
SLE_CONDVAR(Town, xy, SLE_UINT32, 6, 255), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1942 |
|
0 | 1943 |
SLE_CONDVAR(Town,population, SLE_FILE_U16 | SLE_VAR_U32, 0, 2), |
1944 |
SLE_CONDVAR(Town,population, SLE_UINT32, 3, 255), |
|
1945 |
||
1946 |
||
1947 |
SLE_VAR(Town,num_houses, SLE_UINT16), |
|
1948 |
SLE_VAR(Town,townnametype,SLE_UINT16), |
|
1949 |
SLE_VAR(Town,townnameparts,SLE_UINT32), |
|
1950 |
||
1951 |
SLE_VAR(Town,flags12, SLE_UINT8), |
|
1952 |
SLE_VAR(Town,statues, SLE_UINT8), |
|
1953 |
||
1954 |
// sort_index_obsolete was stored here in savegame format 0 - 1 |
|
1955 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 1, 0, 1), |
|
1956 |
||
1957 |
SLE_VAR(Town,have_ratings,SLE_UINT8), |
|
1958 |
SLE_ARR(Town,ratings, SLE_INT16, 8), |
|
1959 |
// failed bribe attempts are stored since savegame format 4 |
|
1960 |
SLE_CONDARR(Town,unwanted, SLE_INT8, 8, 4,255), |
|
1961 |
||
1377
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1962 |
SLE_CONDVAR(Town,max_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1963 |
SLE_CONDVAR(Town,max_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1964 |
SLE_CONDVAR(Town,new_max_pass,SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1965 |
SLE_CONDVAR(Town,new_max_mail,SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1966 |
SLE_CONDVAR(Town,act_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1967 |
SLE_CONDVAR(Town,act_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1968 |
SLE_CONDVAR(Town,new_act_pass,SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1969 |
SLE_CONDVAR(Town,new_act_mail,SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1970 |
|
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1971 |
SLE_CONDVAR(Town,max_pass, SLE_UINT32, 9, 255), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1972 |
SLE_CONDVAR(Town,max_mail, SLE_UINT32, 9, 255), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1973 |
SLE_CONDVAR(Town,new_max_pass,SLE_UINT32, 9, 255), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1974 |
SLE_CONDVAR(Town,new_max_mail,SLE_UINT32, 9, 255), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1975 |
SLE_CONDVAR(Town,act_pass, SLE_UINT32, 9, 255), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1976 |
SLE_CONDVAR(Town,act_mail, SLE_UINT32, 9, 255), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1977 |
SLE_CONDVAR(Town,new_act_pass,SLE_UINT32, 9, 255), |
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1978 |
SLE_CONDVAR(Town,new_act_mail,SLE_UINT32, 9, 255), |
0 | 1979 |
|
1980 |
SLE_VAR(Town,pct_pass_transported,SLE_UINT8), |
|
1981 |
SLE_VAR(Town,pct_mail_transported,SLE_UINT8), |
|
1982 |
||
1983 |
SLE_VAR(Town,act_food, SLE_UINT16), |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1984 |
SLE_VAR(Town,act_water, SLE_UINT16), |
0 | 1985 |
SLE_VAR(Town,new_act_food,SLE_UINT16), |
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1986 |
SLE_VAR(Town,new_act_water,SLE_UINT16), |
0 | 1987 |
|
1988 |
SLE_VAR(Town,time_until_rebuild, SLE_UINT8), |
|
1989 |
SLE_VAR(Town,grow_counter, SLE_UINT8), |
|
1990 |
SLE_VAR(Town,growth_rate, SLE_UINT8), |
|
1991 |
SLE_VAR(Town,fund_buildings_months, SLE_UINT8), |
|
1992 |
SLE_VAR(Town,road_build_months, SLE_UINT8), |
|
1993 |
||
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1994 |
SLE_VAR(Town,exclusivity, SLE_UINT8), |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1995 |
SLE_VAR(Town,exclusive_counter, SLE_UINT8), |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1996 |
// reserve extra space in savegame here. (currently 30 bytes) |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1997 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 30, 2, 255), |
0 | 1998 |
|
1999 |
SLE_END() |
|
2000 |
}; |
|
2001 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
2002 |
static void Save_TOWN(void) |
0 | 2003 |
{ |
2004 |
Town *t; |
|
2005 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2006 |
FOR_ALL_TOWNS(t) { |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2007 |
if (t->xy != 0) { |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2008 |
SlSetArrayIndex(t->index); |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2009 |
SlObject(t, _town_desc); |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2010 |
} |
0 | 2011 |
} |
2012 |
} |
|
2013 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
2014 |
static void Load_TOWN(void) |
0 | 2015 |
{ |
2016 |
int index; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2017 |
|
1261
914ecc20a2df
(svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents:
1260
diff
changeset
|
2018 |
_total_towns = 0; |
914ecc20a2df
(svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents:
1260
diff
changeset
|
2019 |
|
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2020 |
while ((index = SlIterateArray()) != -1) { |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2021 |
Town *t; |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2022 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2023 |
if (!AddBlockIfNeeded(&_town_pool, index)) |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2024 |
error("Towns: failed loading savegame: too many towns"); |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2025 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2026 |
t = GetTown(index); |
0 | 2027 |
SlObject(t, _town_desc); |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2028 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2029 |
if ((uint)index > _total_towns) |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2030 |
_total_towns = index; |
0 | 2031 |
} |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2032 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2033 |
/* This is to ensure all pointers are within the limits of |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2034 |
* the size of the TownPool */ |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2035 |
if (_cur_town_ctr >= GetTownPoolSize()) |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2036 |
_cur_town_ctr = 0; |
0 | 2037 |
} |
2038 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
2039 |
void AfterLoadTown(void) |
0 | 2040 |
{ |
2041 |
Town *t; |
|
2042 |
FOR_ALL_TOWNS(t) { |
|
2043 |
if (t->xy != 0) { |
|
2044 |
UpdateTownRadius(t); |
|
2045 |
UpdateTownVirtCoord(t); |
|
2046 |
} |
|
2047 |
} |
|
2048 |
_town_sort_dirty = true; |
|
2049 |
} |
|
2050 |
||
2051 |
||
2052 |
const ChunkHandler _town_chunk_handlers[] = { |
|
2053 |
{ 'CITY', Save_TOWN, Load_TOWN, CH_ARRAY | CH_LAST}, |
|
2054 |
}; |
|
2055 |
||
2056 |