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