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