author | tron |
Fri, 28 Jan 2005 15:31:04 +0000 | |
changeset 1202 | 4d2a20c50760 |
parent 1193 | edf70d2a5ea6 |
child 1209 | 2e00193652b2 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
473
diff
changeset
|
3 |
#include "map.h" |
0 | 4 |
#include <stdarg.h> |
5 |
#include "gfx.h" |
|
6 |
#include "viewport.h" |
|
7 |
#include "command.h" |
|
8 |
#include "vehicle.h" |
|
9 |
||
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
10 |
extern const TileTypeProcs |
0 | 11 |
_tile_type_clear_procs, |
12 |
_tile_type_rail_procs, |
|
13 |
_tile_type_road_procs, |
|
14 |
_tile_type_town_procs, |
|
15 |
_tile_type_trees_procs, |
|
16 |
_tile_type_station_procs, |
|
17 |
_tile_type_water_procs, |
|
18 |
_tile_type_dummy_procs, |
|
19 |
_tile_type_industry_procs, |
|
20 |
_tile_type_tunnelbridge_procs, |
|
21 |
_tile_type_unmovable_procs; |
|
22 |
||
23 |
const TileTypeProcs * const _tile_type_procs[16] = { |
|
24 |
&_tile_type_clear_procs, |
|
25 |
&_tile_type_rail_procs, |
|
26 |
&_tile_type_road_procs, |
|
27 |
&_tile_type_town_procs, |
|
28 |
&_tile_type_trees_procs, |
|
29 |
&_tile_type_station_procs, |
|
30 |
&_tile_type_water_procs, |
|
31 |
&_tile_type_dummy_procs, |
|
32 |
&_tile_type_industry_procs, |
|
33 |
&_tile_type_tunnelbridge_procs, |
|
34 |
&_tile_type_unmovable_procs, |
|
35 |
}; |
|
36 |
||
37 |
/* landscape slope => sprite */ |
|
38 |
const byte _tileh_to_sprite[32] = { |
|
39 |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0, |
|
40 |
0,0,0,0,0,0,0,16,0,0,0,17,0,15,18,0, |
|
41 |
}; |
|
42 |
||
43 |
uint GetTileSlope(uint tile, int *h) |
|
44 |
{ |
|
45 |
uint a,b,c,d,min; |
|
46 |
int r; |
|
47 |
||
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:
925
diff
changeset
|
48 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) { |
0 | 49 |
if (h) |
50 |
*h = 0; |
|
51 |
return 0; |
|
52 |
} |
|
53 |
||
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:
925
diff
changeset
|
54 |
assert(tile < MapSize() && TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY()); |
0 | 55 |
|
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
56 |
min = a = TileHeight(tile); |
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
57 |
b = TileHeight(tile + TILE_XY(1,0)); |
0 | 58 |
if (min >= b) min = b; |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
59 |
c = TileHeight(tile + TILE_XY(0,1)); |
0 | 60 |
if (min >= c) min = c; |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
61 |
d = TileHeight(tile + TILE_XY(1,1)); |
0 | 62 |
if (min >= d) min = d; |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
63 |
|
0 | 64 |
r = 0; |
65 |
if ((a-=min)!=0) { r += (--a << 4) + 8; } |
|
66 |
if ((c-=min)!=0) { r += (--c << 4) + 4; } |
|
67 |
if ((d-=min)!=0) { r += (--d << 4) + 2; } |
|
68 |
if ((b-=min)!=0) { r += (--b << 4) + 1; } |
|
69 |
||
70 |
if (h != 0) |
|
71 |
*h = min * 8; |
|
72 |
||
73 |
return r; |
|
74 |
} |
|
75 |
||
76 |
int GetTileZ(uint tile) |
|
77 |
{ |
|
78 |
int h; |
|
79 |
GetTileSlope(tile, &h); |
|
80 |
return h; |
|
81 |
} |
|
82 |
||
1193
edf70d2a5ea6
(svn r1697) Remove superflous special case for the VOID border tiles in FindLandscapeHeightByTile()
tron
parents:
1184
diff
changeset
|
83 |
void FindLandscapeHeightByTile(TileInfo *ti, TileIndex tile) |
0 | 84 |
{ |
1193
edf70d2a5ea6
(svn r1697) Remove superflous special case for the VOID border tiles in FindLandscapeHeightByTile()
tron
parents:
1184
diff
changeset
|
85 |
assert(tile < MapSize()); |
0 | 86 |
|
87 |
ti->tile = tile; |
|
88 |
ti->map5 = _map5[tile]; |
|
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:
959
diff
changeset
|
89 |
ti->type = TileType(tile); |
0 | 90 |
ti->tileh = GetTileSlope(tile, &ti->z); |
91 |
} |
|
92 |
||
93 |
/* find the landscape height for the coordinates x y */ |
|
94 |
void FindLandscapeHeight(TileInfo *ti, uint x, uint y) |
|
95 |
{ |
|
96 |
int tile; |
|
97 |
||
98 |
ti->x = x; |
|
99 |
ti->y = y; |
|
100 |
||
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
851
diff
changeset
|
101 |
if (x >= MapMaxX() * 16 - 1 || y >= MapMaxY() * 16 - 1) { |
0 | 102 |
ti->tileh = 0; |
925
47d7952c6c14
(svn r1413) Fixed a serious memory leak problem. The invisible tiles on the southern border now have the correct tile type (MP_VOID) again. Please note that older maps might still have incorrect border tiles, thus still causing overflows.
dominik
parents:
909
diff
changeset
|
103 |
ti->type = MP_VOID; |
0 | 104 |
ti->tile = 0; |
105 |
ti->map5 = 0; |
|
106 |
ti->z = 0; |
|
107 |
return; |
|
108 |
} |
|
109 |
||
110 |
tile = TILE_FROM_XY(x,y); |
|
111 |
FindLandscapeHeightByTile(ti, tile); |
|
112 |
} |
|
113 |
||
114 |
uint GetPartialZ(int x, int y, int corners) |
|
115 |
{ |
|
116 |
int z = 0; |
|
117 |
||
118 |
switch(corners) { |
|
119 |
case 1: |
|
120 |
if (x - y >= 0) |
|
121 |
z = (x - y) >> 1; |
|
122 |
break; |
|
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
123 |
|
0 | 124 |
case 2: |
125 |
y^=0xF; |
|
126 |
if ( (x - y) >= 0) |
|
127 |
z = (x - y) >> 1; |
|
128 |
break; |
|
129 |
||
130 |
case 3: |
|
131 |
z = (x>>1) + 1; |
|
132 |
break; |
|
133 |
||
134 |
case 4: |
|
135 |
if (y - x >= 0) |
|
136 |
z = (y - x) >> 1; |
|
137 |
break; |
|
138 |
||
139 |
case 5: |
|
140 |
case 10: |
|
141 |
case 15: |
|
142 |
z = 4; |
|
143 |
break; |
|
144 |
||
145 |
case 6: |
|
146 |
z = (y>>1) + 1; |
|
147 |
break; |
|
148 |
||
149 |
case 7: |
|
150 |
z = 8; |
|
151 |
y^=0xF; |
|
152 |
if (x - y < 0) |
|
153 |
z += (x - y) >> 1; |
|
154 |
break; |
|
155 |
||
156 |
case 8: |
|
157 |
y ^= 0xF; |
|
158 |
if (y - x >= 0) |
|
159 |
z = (y - x) >> 1; |
|
160 |
break; |
|
161 |
||
162 |
case 9: |
|
163 |
z = (y^0xF)>>1; |
|
164 |
break; |
|
165 |
||
166 |
case 11: |
|
167 |
z = 8; |
|
168 |
if (x - y < 0) |
|
169 |
z += (x - y) >> 1; |
|
170 |
break; |
|
171 |
||
172 |
case 12: |
|
173 |
z = (x^0xF)>>1; |
|
174 |
break; |
|
175 |
||
176 |
case 13: |
|
177 |
z = 8; |
|
178 |
y ^= 0xF; |
|
179 |
if (y - x < 0) |
|
180 |
z += (y - x) >> 1; |
|
181 |
break; |
|
182 |
||
183 |
case 14: |
|
184 |
z = 8; |
|
185 |
if (y - x < 0) |
|
186 |
z += (y - x) >> 1; |
|
187 |
break; |
|
188 |
||
189 |
case 23: |
|
190 |
z = 1 + ((x+y)>>1); |
|
191 |
break; |
|
192 |
||
193 |
case 27: |
|
194 |
z = 1 + ((x+(y^0xF))>>1); |
|
195 |
break; |
|
196 |
||
197 |
case 29: |
|
198 |
z = 1 + (((x^0xF)+(y^0xF))>>1); |
|
199 |
break; |
|
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
200 |
|
0 | 201 |
case 30: |
202 |
z = 1 + (((x^0xF)+(y^0xF))>>1); |
|
203 |
break; |
|
204 |
} |
|
205 |
||
206 |
return z; |
|
207 |
} |
|
208 |
||
209 |
uint GetSlopeZ(int x, int y) |
|
210 |
{ |
|
211 |
TileInfo ti; |
|
212 |
// int z; |
|
213 |
||
214 |
FindLandscapeHeight(&ti, x, y); |
|
215 |
||
216 |
/* |
|
217 |
z = ti.z; |
|
218 |
x &= 0xF; |
|
219 |
y &= 0xF; |
|
220 |
||
221 |
||
222 |
assert(z < 256); |
|
223 |
*/ |
|
224 |
return _tile_type_procs[ti.type]->get_slope_z_proc(&ti); |
|
225 |
} |
|
226 |
||
39 | 227 |
// direction=true: check for foundation in east and south corner |
228 |
// direction=false: check for foundation in west and south corner |
|
1095 | 229 |
static bool hasFoundation(TileInfo *ti, bool direction) |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
230 |
{ |
39 | 231 |
bool south, other; // southern corner and east/west corner |
232 |
uint slope = _tile_type_procs[ti->type]->get_slope_tileh_proc(ti); |
|
50 | 233 |
uint tileh = ti->tileh; |
234 |
||
235 |
if(slope==0 && slope!=tileh) tileh=15; |
|
236 |
south = (tileh & 2) != (slope & 2); |
|
39 | 237 |
|
238 |
if(direction) |
|
50 | 239 |
other = (tileh & 4) != (slope & 4); |
39 | 240 |
else |
50 | 241 |
other = (tileh & 1) != (slope & 1); |
242 |
return south || other; |
|
39 | 243 |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
244 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
245 |
|
0 | 246 |
void DrawFoundation(TileInfo *ti, uint f) |
247 |
{ |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
248 |
uint32 sprite_base = SPR_SLOPES_BASE-14; |
39 | 249 |
|
250 |
TileInfo ti2; |
|
251 |
FindLandscapeHeight(&ti2, ti->x, ti->y-1); |
|
252 |
if(hasFoundation( &ti2, true )) sprite_base += 22; // foundation in NW direction |
|
253 |
FindLandscapeHeight(&ti2, ti->x-1, ti->y); |
|
254 |
if(hasFoundation( &ti2, false )) sprite_base += 22*2; // foundation in NE direction |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
255 |
|
0 | 256 |
if (f < 15) { |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
257 |
// leveled foundation |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
258 |
if( sprite_base < SPR_SLOPES_BASE ) sprite_base = 990; // use original slope sprites |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
259 |
|
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
260 |
AddSortableSpriteToDraw(f-1 + sprite_base, ti->x, ti->y, 16, 16, 7, ti->z); |
0 | 261 |
ti->z += 8; |
262 |
ti->tileh = 0; |
|
263 |
OffsetGroundSprite(31, 1); |
|
264 |
} else { |
|
265 |
// inclined foundation |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
266 |
sprite_base += 14; |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
267 |
|
0 | 268 |
AddSortableSpriteToDraw( |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
269 |
HASBIT( (1<<1) | (1<<2) | (1<<4) | (1<<8), ti->tileh) ? sprite_base + (f - 15) : ti->tileh + 0x3DE - 1, |
0 | 270 |
ti->x, ti->y, 1, 1, 1, ti->z |
271 |
); |
|
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
272 |
|
0 | 273 |
ti->tileh = _inclined_tileh[f - 15]; |
274 |
OffsetGroundSprite(31, 9); |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
void DoClearSquare(uint tile) |
|
279 |
{ |
|
280 |
ModifyTile(tile, |
|
281 |
MP_SETTYPE(MP_CLEAR) | |
|
282 |
MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5, |
|
283 |
OWNER_NONE, /* map_owner */ |
|
284 |
_generating_world ? 3 : 0 /* map5 */ |
|
285 |
); |
|
286 |
} |
|
287 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
131
diff
changeset
|
288 |
uint32 GetTileTrackStatus(uint tile, TransportType mode) |
0 | 289 |
{ |
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:
959
diff
changeset
|
290 |
return _tile_type_procs[TileType(tile)]->get_tile_track_status_proc(tile, mode); |
0 | 291 |
} |
292 |
||
293 |
void ChangeTileOwner(uint tile, byte old_player, byte new_player) |
|
294 |
{ |
|
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:
959
diff
changeset
|
295 |
_tile_type_procs[TileType(tile)]->change_tile_owner_proc(tile, old_player, new_player); |
0 | 296 |
} |
297 |
||
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
183
diff
changeset
|
298 |
void GetAcceptedCargo(uint tile, AcceptedCargo ac) |
0 | 299 |
{ |
300 |
memset(ac, 0, sizeof(AcceptedCargo)); |
|
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:
959
diff
changeset
|
301 |
_tile_type_procs[TileType(tile)]->get_accepted_cargo_proc(tile, ac); |
0 | 302 |
} |
303 |
||
304 |
void AnimateTile(uint tile) |
|
305 |
{ |
|
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:
959
diff
changeset
|
306 |
_tile_type_procs[TileType(tile)]->animate_tile_proc(tile); |
0 | 307 |
} |
308 |
||
309 |
void ClickTile(uint tile) |
|
310 |
{ |
|
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:
959
diff
changeset
|
311 |
_tile_type_procs[TileType(tile)]->click_tile_proc(tile); |
0 | 312 |
} |
313 |
||
314 |
void DrawTile(TileInfo *ti) |
|
315 |
{ |
|
316 |
_tile_type_procs[ti->type]->draw_tile_proc(ti); |
|
317 |
} |
|
318 |
||
319 |
void GetTileDesc(uint tile, TileDesc *td) |
|
320 |
{ |
|
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:
959
diff
changeset
|
321 |
_tile_type_procs[TileType(tile)]->get_tile_desc_proc(tile, td); |
0 | 322 |
} |
323 |
||
324 |
/* Clear a piece of landscape |
|
325 |
* p1 = 0, |
|
326 |
* p2 = 0 |
|
327 |
*/ |
|
328 |
||
329 |
int32 CmdLandscapeClear(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
330 |
{ |
|
331 |
uint tile; |
|
332 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
333 |
||
334 |
tile = TILE_FROM_XY(x,y); |
|
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:
959
diff
changeset
|
335 |
return _tile_type_procs[TileType(tile)]->clear_tile_proc(tile, flags); |
0 | 336 |
} |
337 |
||
338 |
// p1 = end tile |
|
339 |
int32 CmdClearArea(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
340 |
{ |
|
341 |
int32 cost,ret, money; |
|
342 |
int sx,sy; |
|
343 |
int x,y; |
|
344 |
bool success = false; |
|
345 |
||
889
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
346 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
347 |
|
0 | 348 |
// make sure sx,sy are smaller than ex,ey |
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:
925
diff
changeset
|
349 |
sx = TileX(p1) * 16; |
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:
925
diff
changeset
|
350 |
sy = TileY(p1) * 16; |
0 | 351 |
if (ex < sx) intswap(ex, sx); |
352 |
if (ey < sy) intswap(ey, sy); |
|
353 |
||
354 |
money = GetAvailableMoneyForCommand(); |
|
355 |
cost = 0; |
|
356 |
||
357 |
for(x=sx; x<=ex; x+=16) { |
|
358 |
for(y=sy; y<=ey; y+=16) { |
|
359 |
ret = DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags &~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
360 |
if (ret == CMD_ERROR) continue; |
|
361 |
cost += ret; |
|
362 |
success = true; |
|
363 |
||
364 |
if (flags & DC_EXEC) { |
|
365 |
if ( ret>0 && (money -= ret) < 0) { |
|
366 |
_additional_cash_required = ret; |
|
367 |
return cost - ret; |
|
368 |
} |
|
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
369 |
DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
0 | 370 |
|
371 |
// draw explosion animation... |
|
372 |
if ((x==sx || x==ex) && (y==sy || y==ey)) { |
|
373 |
// big explosion in each corner, or small explosion for single tiles |
|
374 |
CreateEffectVehicleAbove(x + 8,y + 8, 2, sy==ey && sx==ex ? EV_DEMOLISH : EV_CRASHED_SMOKE); |
|
375 |
} |
|
376 |
} |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
if (!success) |
|
381 |
cost = CMD_ERROR; |
|
382 |
return cost; |
|
383 |
} |
|
384 |
||
385 |
||
386 |
/* utility function used to modify a tile */ |
|
387 |
void CDECL ModifyTile(uint tile, uint flags, ...) |
|
388 |
{ |
|
389 |
va_list va; |
|
390 |
int i; |
|
391 |
||
392 |
va_start(va, flags); |
|
393 |
||
394 |
if ((i = (flags >> 8) & 0xF) != 0) { |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
395 |
SetTileType(tile, i - 1); |
0 | 396 |
} |
397 |
||
398 |
if (flags & (MP_MAP2_CLEAR | MP_MAP2)) { |
|
399 |
int x = 0; |
|
400 |
if (flags & MP_MAP2) x = va_arg(va, int); |
|
401 |
_map2[tile] = x; |
|
402 |
} |
|
403 |
||
404 |
if (flags & (MP_MAP3LO_CLEAR | MP_MAP3LO)) { |
|
405 |
int x = 0; |
|
406 |
if (flags & MP_MAP3LO) x = va_arg(va, int); |
|
407 |
_map3_lo[tile] = x; |
|
408 |
} |
|
409 |
||
410 |
if (flags & (MP_MAP3HI_CLEAR | MP_MAP3HI)) { |
|
411 |
int x = 0; |
|
412 |
if (flags & MP_MAP3HI) x = va_arg(va, int); |
|
413 |
_map3_hi[tile] = x; |
|
414 |
} |
|
415 |
||
416 |
if (flags & (MP_MAPOWNER|MP_MAPOWNER_CURRENT)) { |
|
417 |
byte x = _current_player; |
|
418 |
if (flags & MP_MAPOWNER) x = va_arg(va, int); |
|
419 |
_map_owner[tile] = x; |
|
420 |
} |
|
421 |
||
422 |
if (flags & MP_MAP5) { |
|
423 |
_map5[tile] = va_arg(va, int); |
|
424 |
} |
|
425 |
||
426 |
va_end(va); |
|
427 |
||
428 |
if (!(flags & MP_NODIRTY)) |
|
429 |
MarkTileDirtyByTile(tile); |
|
430 |
} |
|
431 |
||
432 |
void SetMapExtraBits(uint tile, byte bits) |
|
433 |
{ |
|
434 |
_map_extra_bits[tile >> 2] &= ~(3 << ((tile&3)*2)); |
|
435 |
_map_extra_bits[tile >> 2] |= (bits&3) << ((tile&3)*2); |
|
436 |
} |
|
437 |
||
438 |
uint GetMapExtraBits(uint tile) |
|
439 |
{ |
|
1140
82396799e4eb
(svn r1641) Remove a boundary check added in r1332 to work around a bug - the real cause has been eleminated in r1413.
tron
parents:
1095
diff
changeset
|
440 |
assert(tile < MapSize()); |
82396799e4eb
(svn r1641) Remove a boundary check added in r1332 to work around a bug - the real cause has been eleminated in r1413.
tron
parents:
1095
diff
changeset
|
441 |
return (_map_extra_bits[tile >> 2] >> (tile & 3) * 2) & 3; |
0 | 442 |
} |
443 |
||
444 |
#define TILELOOP_BITS 4 |
|
445 |
#define TILELOOP_SIZE (1 << TILELOOP_BITS) |
|
927
94fec9843fd3
(svn r1415) Move TILE_FROM_XY and TILE_XY to map.h and push TILE_[XY] bits from map.h into map.c.
tron
parents:
926
diff
changeset
|
446 |
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE-1) + ((TILELOOP_SIZE-1) << MapLogX())) |
94fec9843fd3
(svn r1415) Move TILE_FROM_XY and TILE_XY to map.h and push TILE_[XY] bits from map.h into map.c.
tron
parents:
926
diff
changeset
|
447 |
#define TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS) |
0 | 448 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
449 |
void RunTileLoop(void) |
0 | 450 |
{ |
451 |
uint tile; |
|
452 |
uint count; |
|
453 |
||
454 |
tile = _cur_tileloop_tile; |
|
455 |
||
456 |
assert( (tile & ~TILELOOP_ASSERTMASK) == 0); |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
857
diff
changeset
|
457 |
count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE); |
0 | 458 |
do { |
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:
959
diff
changeset
|
459 |
_tile_type_procs[TileType(tile)]->tile_loop_proc(tile); |
0 | 460 |
|
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:
925
diff
changeset
|
461 |
if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) { |
0 | 462 |
tile += TILELOOP_SIZE; /* no overflow */ |
463 |
} else { |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
857
diff
changeset
|
464 |
tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE-1) + TILE_XY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */ |
0 | 465 |
} |
466 |
} while (--count); |
|
467 |
assert( (tile & ~TILELOOP_ASSERTMASK) == 0); |
|
468 |
||
469 |
tile += 9; |
|
470 |
if (tile & TILELOOP_CHKMASK) |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
857
diff
changeset
|
471 |
tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK; |
0 | 472 |
_cur_tileloop_tile = tile; |
473 |
} |
|
474 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
475 |
void InitializeLandscape(void) |
0 | 476 |
{ |
695
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
679
diff
changeset
|
477 |
uint map_size = MapSize(); |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
927
diff
changeset
|
478 |
uint i; |
0 | 479 |
|
840
10fbbdd22777
(svn r1321) -Fix: Revision 1302 partly solved the problem and created an other.
truelight
parents:
831
diff
changeset
|
480 |
memset(_map_owner, OWNER_NONE, map_size); |
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
695
diff
changeset
|
481 |
memset(_map2, 0, map_size * sizeof(uint16)); |
695
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
679
diff
changeset
|
482 |
memset(_map3_lo, 0, map_size); |
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
679
diff
changeset
|
483 |
memset(_map3_hi, 0, map_size); |
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
679
diff
changeset
|
484 |
memset(_map_extra_bits, 0, map_size / 4); |
840
10fbbdd22777
(svn r1321) -Fix: Revision 1302 partly solved the problem and created an other.
truelight
parents:
831
diff
changeset
|
485 |
memset(_map_type_and_height, MP_CLEAR << 4, map_size); |
0 | 486 |
|
1181
3cbae3ef2590
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1174
diff
changeset
|
487 |
// create void tiles at the border |
3cbae3ef2590
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1174
diff
changeset
|
488 |
for (i = 0; i < MapMaxY(); ++i) |
3cbae3ef2590
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1174
diff
changeset
|
489 |
SetTileType(i * MapSizeX() + MapMaxX(), MP_VOID); |
3cbae3ef2590
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1174
diff
changeset
|
490 |
for (i = 0; i < MapSizeX(); ++i) |
3cbae3ef2590
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1174
diff
changeset
|
491 |
SetTileType(MapSizeX() * MapMaxY() + i, MP_VOID); |
0 | 492 |
|
695
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
679
diff
changeset
|
493 |
memset(_map5, 3, map_size); |
0 | 494 |
} |
495 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
496 |
void ConvertGroundTilesIntoWaterTiles(void) |
0 | 497 |
{ |
498 |
uint tile = 0; |
|
499 |
int h; |
|
500 |
||
501 |
while(true) { |
|
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:
959
diff
changeset
|
502 |
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) { |
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
503 |
SetTileType(tile, MP_WATER); |
0 | 504 |
_map5[tile] = 0; |
505 |
_map_owner[tile] = OWNER_WATER; |
|
506 |
} |
|
507 |
tile++; |
|
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:
925
diff
changeset
|
508 |
if (TileX(tile) == MapMaxX()) { |
857
cd1fdb44121d
(svn r1338) -Fix: fix signed/unsigned warnings introduced when ditching the macros for map querying.
darkvater
parents:
856
diff
changeset
|
509 |
tile += TILE_XY(-(int)MapMaxX(), 1); |
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:
925
diff
changeset
|
510 |
if (TileY(tile) == MapMaxY()) |
0 | 511 |
break; |
512 |
} |
|
513 |
} |
|
514 |
} |
|
515 |
||
516 |
static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 }; |
|
517 |
static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 }; |
|
518 |
||
519 |
static void GenerateTerrain(int type, int flag) |
|
520 |
{ |
|
521 |
uint32 r; |
|
857
cd1fdb44121d
(svn r1338) -Fix: fix signed/unsigned warnings introduced when ditching the macros for map querying.
darkvater
parents:
856
diff
changeset
|
522 |
uint x,y; |
0 | 523 |
int w,h; |
524 |
byte *p,*tile; |
|
525 |
byte direction; |
|
526 |
||
527 |
r = Random(); |
|
528 |
p = GetSpritePtr((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845); |
|
529 |
||
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
851
diff
changeset
|
530 |
x = r & MapMaxX(); |
927
94fec9843fd3
(svn r1415) Move TILE_FROM_XY and TILE_XY to map.h and push TILE_[XY] bits from map.h into map.c.
tron
parents:
926
diff
changeset
|
531 |
y = (r >> MapLogX()) & MapMaxY(); |
0 | 532 |
|
533 |
||
534 |
if (x < 2 || y < 2) |
|
535 |
return; |
|
536 |
||
537 |
direction = (byte)(r >> 22) & 3; |
|
538 |
w = p[2]; |
|
539 |
h = p[1]; |
|
540 |
if (direction & 1) { w = p[1]; h = p[2]; } |
|
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
541 |
p += 8; |
0 | 542 |
|
543 |
if (flag & 4) { |
|
544 |
if (!(flag & 2)) { |
|
545 |
if (!(flag & 1)) { |
|
546 |
if (x + y > 190) |
|
547 |
return; |
|
548 |
} else { |
|
549 |
if (y < 30 + x) |
|
550 |
return; |
|
551 |
} |
|
552 |
} else { |
|
553 |
if (!(flag & 1)) { |
|
554 |
if (x + y < 256) |
|
555 |
return; |
|
556 |
} else { |
|
557 |
if (x < 30 + y) |
|
558 |
return; |
|
559 |
} |
|
560 |
} |
|
561 |
} |
|
562 |
||
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
851
diff
changeset
|
563 |
if (x + w >= MapMaxX() - 1) |
0 | 564 |
return; |
565 |
||
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
851
diff
changeset
|
566 |
if (y + h >= MapMaxY() - 1) |
0 | 567 |
return; |
568 |
||
569 |
tile = &_map_type_and_height[TILE_XY(x,y)]; |
|
570 |
||
571 |
if (direction == 0) { |
|
572 |
do { |
|
573 |
int w_cur = w; |
|
574 |
byte *tile_cur = tile; |
|
575 |
do { |
|
576 |
if (*p >= *tile_cur) *tile_cur = *p; |
|
577 |
p++; |
|
578 |
tile_cur++; |
|
579 |
} while (--w_cur != 0); |
|
580 |
tile += TILE_XY(0,1); |
|
581 |
} while (--h != 0); |
|
582 |
} else if (direction == 1) { |
|
583 |
do { |
|
584 |
int h_cur = h; |
|
585 |
byte *tile_cur = tile; |
|
586 |
do { |
|
587 |
if (*p >= *tile_cur) *tile_cur = *p; |
|
588 |
p++; |
|
589 |
tile_cur+=TILE_XY(0,1); |
|
590 |
} while (--h_cur != 0); |
|
591 |
tile++; |
|
592 |
} while (--w != 0); |
|
593 |
} else if (direction == 2) { |
|
594 |
tile += w - 1; |
|
595 |
do { |
|
596 |
int w_cur = w; |
|
597 |
byte *tile_cur = tile; |
|
598 |
do { |
|
599 |
if (*p >= *tile_cur) *tile_cur = *p; |
|
600 |
p++; |
|
601 |
tile_cur--; |
|
602 |
} while (--w_cur != 0); |
|
603 |
tile += TILE_XY(0,1); |
|
604 |
} while (--h != 0); |
|
605 |
} else { |
|
606 |
tile += (h - 1) * TILE_XY(0,1); |
|
607 |
do { |
|
608 |
int h_cur = h; |
|
609 |
byte *tile_cur = tile; |
|
610 |
do { |
|
611 |
if (*p >= *tile_cur) *tile_cur = *p; |
|
612 |
p++; |
|
613 |
tile_cur-=TILE_XY(0,1); |
|
614 |
} while (--h_cur != 0); |
|
615 |
tile++; |
|
616 |
} while (--w != 0); |
|
617 |
} |
|
618 |
} |
|
619 |
||
620 |
||
621 |
#include "table/genland.h" |
|
622 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
623 |
static void CreateDesertOrRainForest(void) |
0 | 624 |
{ |
625 |
uint tile; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
626 |
const TileIndexDiffC *data; |
0 | 627 |
int i; |
628 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
629 |
for (tile = 0; tile != MapSize(); ++tile) { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
630 |
for (data = _make_desert_or_rainforest_data; |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
631 |
data != endof(_make_desert_or_rainforest_data); ++data) { |
1184
9792417da988
(svn r1686) Fix (Work around?) crash when generating tropical maps
tron
parents:
1181
diff
changeset
|
632 |
TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data)); |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
633 |
if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
634 |
} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
635 |
if (data == endof(_make_desert_or_rainforest_data)) |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
636 |
SetMapExtraBits(tile, 1); |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
637 |
} |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
638 |
|
0 | 639 |
for(i=0; i!=256; i++) |
640 |
RunTileLoop(); |
|
641 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
642 |
for (tile = 0; tile != MapSize(); ++tile) { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
643 |
for (data = _make_desert_or_rainforest_data; |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
644 |
data != endof(_make_desert_or_rainforest_data); ++data) { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
645 |
TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data)); |
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:
959
diff
changeset
|
646 |
if (IsTileType(t, MP_CLEAR) && (_map5[t] & 0x1c) == 0x14) break; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
647 |
} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
648 |
if (data == endof(_make_desert_or_rainforest_data)) |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
649 |
SetMapExtraBits(tile, 2); |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
650 |
} |
0 | 651 |
} |
652 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
653 |
void GenerateLandscape(void) |
0 | 654 |
{ |
655 |
int i,flag; |
|
656 |
uint32 r; |
|
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
657 |
|
0 | 658 |
if (_opt.landscape == LT_HILLY) { |
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1193
diff
changeset
|
659 |
i = ScaleByMapSize((Random() & 0x7F) + 950); |
0 | 660 |
do { |
661 |
GenerateTerrain(2, 0); |
|
662 |
} while (--i); |
|
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
663 |
|
0 | 664 |
r = Random(); |
665 |
flag = (r & 3) | 4; |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1193
diff
changeset
|
666 |
i = ScaleByMapSize(((r >> 16) & 0x7F) + 450); |
0 | 667 |
do { |
668 |
GenerateTerrain(4, flag); |
|
669 |
} while (--i); |
|
670 |
} else if (_opt.landscape == LT_DESERT) { |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1193
diff
changeset
|
671 |
i = ScaleByMapSize((Random()&0x7F) + 170); |
0 | 672 |
do { |
673 |
GenerateTerrain(0, 0); |
|
674 |
} while (--i); |
|
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
675 |
|
0 | 676 |
r = Random(); |
677 |
flag = (r & 3) | 4; |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1193
diff
changeset
|
678 |
i = ScaleByMapSize(((r >> 16) & 0xFF) + 1700); |
0 | 679 |
do { |
680 |
GenerateTerrain(0, flag); |
|
681 |
} while (--i); |
|
682 |
||
683 |
flag ^= 2; |
|
684 |
||
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1193
diff
changeset
|
685 |
i = ScaleByMapSize((Random() & 0x7F) + 410); |
0 | 686 |
do { |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
687 |
GenerateTerrain(3, flag); |
0 | 688 |
} while (--i); |
689 |
} else { |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1193
diff
changeset
|
690 |
i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100); |
0 | 691 |
do { |
692 |
GenerateTerrain(_opt.diff.terrain_type, 0); |
|
693 |
} while (--i); |
|
694 |
} |
|
695 |
||
696 |
ConvertGroundTilesIntoWaterTiles(); |
|
697 |
||
698 |
if (_opt.landscape == LT_DESERT) |
|
699 |
CreateDesertOrRainForest(); |
|
700 |
} |
|
701 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
702 |
void OnTick_Town(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
703 |
void OnTick_Trees(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
704 |
void OnTick_Station(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
705 |
void OnTick_Industry(void); |
0 | 706 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
707 |
void OnTick_Players(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
708 |
void OnTick_Train(void); |
0 | 709 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
710 |
void CallLandscapeTick(void) |
0 | 711 |
{ |
712 |
OnTick_Town(); |
|
713 |
OnTick_Trees(); |
|
714 |
OnTick_Station(); |
|
715 |
OnTick_Industry(); |
|
716 |
||
717 |
OnTick_Players(); |
|
718 |
OnTick_Train(); |
|
719 |
} |
|
720 |
||
721 |
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng) |
|
722 |
{ |
|
723 |
int rn = rng; |
|
724 |
uint32 r = Random(); |
|
725 |
||
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:
1140
diff
changeset
|
726 |
return TILE_MASK(TILE_XY( |
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:
925
diff
changeset
|
727 |
TileX(a) + ((byte)r * rn * 2 >> 8) - rn, |
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:
925
diff
changeset
|
728 |
TileY(a) + ((byte)(r >> 8) * rn * 2 >> 8) - rn |
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:
1140
diff
changeset
|
729 |
)); |
0 | 730 |
} |
731 |
||
131
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
732 |
// This function checks if we add addx/addy to tile, if we |
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
733 |
// do wrap around the edges. For example, tile = (10,2) and |
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
734 |
// addx = +3 and addy = -4. This function will now return |
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
735 |
// TILE_WRAPPED, because the y is wrapped. This is needed in |
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
736 |
// for example, farmland. When the tile is not wrapped, |
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
737 |
// the result will be tile + TILE_XY(addx, addy) |
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
738 |
uint TileAddWrap(TileIndex tile, int addx, int addy) |
0 | 739 |
{ |
857
cd1fdb44121d
(svn r1338) -Fix: fix signed/unsigned warnings introduced when ditching the macros for map querying.
darkvater
parents:
856
diff
changeset
|
740 |
uint x, y; |
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:
925
diff
changeset
|
741 |
x = TileX(tile) + addx; |
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:
925
diff
changeset
|
742 |
y = TileY(tile) + addy; |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
743 |
|
131
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
744 |
// Are we about to wrap? |
857
cd1fdb44121d
(svn r1338) -Fix: fix signed/unsigned warnings introduced when ditching the macros for map querying.
darkvater
parents:
856
diff
changeset
|
745 |
if (x < MapMaxX() && y < MapMaxY()) |
131
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
746 |
return tile + TILE_XY(addx, addy); |
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
50
diff
changeset
|
747 |
|
0 | 748 |
return TILE_WRAPPED; |
749 |
} |
|
750 |
||
751 |
bool IsValidTile(uint tile) |
|
752 |
{ |
|
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:
925
diff
changeset
|
753 |
return (tile < MapSizeX() * MapMaxY() && TileX(tile) != MapMaxX()); |
0 | 754 |
} |