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