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