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