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