author | tron |
Sun, 23 Apr 2006 19:35:36 +0000 | |
changeset 3645 | 7f950533d510 |
parent 3636 | a36cc46e754d |
child 3773 | 0019b5f70ea9 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1793
diff
changeset
|
4 |
#include "openttd.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3111
diff
changeset
|
5 |
#include "clear_map.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.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
|
7 |
#include "map.h" |
2154
f86c59e73a16
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2150
diff
changeset
|
8 |
#include "player.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
|
9 |
#include "spritecache.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1359
diff
changeset
|
10 |
#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
|
11 |
#include "tile.h" |
0 | 12 |
#include <stdarg.h> |
13 |
#include "viewport.h" |
|
14 |
#include "command.h" |
|
15 |
#include "vehicle.h" |
|
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
16 |
#include "variables.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3111
diff
changeset
|
17 |
#include "void_map.h" |
3111
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3078
diff
changeset
|
18 |
#include "water_map.h" |
0 | 19 |
|
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
20 |
extern const TileTypeProcs |
0 | 21 |
_tile_type_clear_procs, |
22 |
_tile_type_rail_procs, |
|
23 |
_tile_type_road_procs, |
|
24 |
_tile_type_town_procs, |
|
25 |
_tile_type_trees_procs, |
|
26 |
_tile_type_station_procs, |
|
27 |
_tile_type_water_procs, |
|
28 |
_tile_type_dummy_procs, |
|
29 |
_tile_type_industry_procs, |
|
30 |
_tile_type_tunnelbridge_procs, |
|
31 |
_tile_type_unmovable_procs; |
|
32 |
||
33 |
const TileTypeProcs * const _tile_type_procs[16] = { |
|
34 |
&_tile_type_clear_procs, |
|
35 |
&_tile_type_rail_procs, |
|
36 |
&_tile_type_road_procs, |
|
37 |
&_tile_type_town_procs, |
|
38 |
&_tile_type_trees_procs, |
|
39 |
&_tile_type_station_procs, |
|
40 |
&_tile_type_water_procs, |
|
41 |
&_tile_type_dummy_procs, |
|
42 |
&_tile_type_industry_procs, |
|
43 |
&_tile_type_tunnelbridge_procs, |
|
44 |
&_tile_type_unmovable_procs, |
|
45 |
}; |
|
46 |
||
47 |
/* landscape slope => sprite */ |
|
48 |
const byte _tileh_to_sprite[32] = { |
|
49 |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0, |
|
50 |
0,0,0,0,0,0,0,16,0,0,0,17,0,15,18,0, |
|
51 |
}; |
|
52 |
||
1958
0266bb01a1e6
(svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents:
1902
diff
changeset
|
53 |
const byte _inclined_tileh[] = { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
54 |
SLOPE_SW, SLOPE_NW, SLOPE_SW, SLOPE_SE, SLOPE_NE, SLOPE_SE, SLOPE_NE, SLOPE_NW |
1958
0266bb01a1e6
(svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents:
1902
diff
changeset
|
55 |
}; |
0266bb01a1e6
(svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents:
1902
diff
changeset
|
56 |
|
0 | 57 |
|
58 |
/* find the landscape height for the coordinates x y */ |
|
59 |
void FindLandscapeHeight(TileInfo *ti, uint x, uint y) |
|
60 |
{ |
|
61 |
ti->x = x; |
|
62 |
ti->y = y; |
|
63 |
||
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
64 |
if (x >= MapMaxX() * TILE_SIZE - 1 || y >= MapMaxY() * TILE_SIZE - 1) { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
65 |
ti->tileh = SLOPE_FLAT; |
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
|
66 |
ti->type = MP_VOID; |
0 | 67 |
ti->tile = 0; |
68 |
ti->z = 0; |
|
3297
b2b8cf7364c9
(svn r4028) The last external user of FindLandscapeHeightByTile() is gone (r4027).
tron
parents:
3144
diff
changeset
|
69 |
} else { |
b2b8cf7364c9
(svn r4028) The last external user of FindLandscapeHeightByTile() is gone (r4027).
tron
parents:
3144
diff
changeset
|
70 |
TileIndex tile = TileVirtXY(x, y); |
b2b8cf7364c9
(svn r4028) The last external user of FindLandscapeHeightByTile() is gone (r4027).
tron
parents:
3144
diff
changeset
|
71 |
|
b2b8cf7364c9
(svn r4028) The last external user of FindLandscapeHeightByTile() is gone (r4027).
tron
parents:
3144
diff
changeset
|
72 |
ti->tile = tile; |
b2b8cf7364c9
(svn r4028) The last external user of FindLandscapeHeightByTile() is gone (r4027).
tron
parents:
3144
diff
changeset
|
73 |
ti->type = GetTileType(tile); |
b2b8cf7364c9
(svn r4028) The last external user of FindLandscapeHeightByTile() is gone (r4027).
tron
parents:
3144
diff
changeset
|
74 |
ti->tileh = GetTileSlope(tile, &ti->z); |
0 | 75 |
} |
76 |
} |
|
77 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
78 |
uint GetPartialZ(int x, int y, Slope corners) |
0 | 79 |
{ |
80 |
int z = 0; |
|
81 |
||
2952 | 82 |
switch (corners) { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
83 |
case SLOPE_W: |
0 | 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 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
88 |
case SLOPE_S: |
0 | 89 |
y^=0xF; |
90 |
if ( (x - y) >= 0) |
|
91 |
z = (x - y) >> 1; |
|
92 |
break; |
|
93 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
94 |
case SLOPE_SW: |
0 | 95 |
z = (x>>1) + 1; |
96 |
break; |
|
97 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
98 |
case SLOPE_E: |
0 | 99 |
if (y - x >= 0) |
100 |
z = (y - x) >> 1; |
|
101 |
break; |
|
102 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
103 |
case SLOPE_EW: |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
104 |
case SLOPE_NS: |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
105 |
case SLOPE_ELEVATED: |
0 | 106 |
z = 4; |
107 |
break; |
|
108 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
109 |
case SLOPE_SE: |
0 | 110 |
z = (y>>1) + 1; |
111 |
break; |
|
112 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
113 |
case SLOPE_WSE: |
0 | 114 |
z = 8; |
115 |
y^=0xF; |
|
116 |
if (x - y < 0) |
|
117 |
z += (x - y) >> 1; |
|
118 |
break; |
|
119 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
120 |
case SLOPE_N: |
0 | 121 |
y ^= 0xF; |
122 |
if (y - x >= 0) |
|
123 |
z = (y - x) >> 1; |
|
124 |
break; |
|
125 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
126 |
case SLOPE_NW: |
0 | 127 |
z = (y^0xF)>>1; |
128 |
break; |
|
129 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
130 |
case SLOPE_NWS: |
0 | 131 |
z = 8; |
132 |
if (x - y < 0) |
|
133 |
z += (x - y) >> 1; |
|
134 |
break; |
|
135 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
136 |
case SLOPE_NE: |
0 | 137 |
z = (x^0xF)>>1; |
138 |
break; |
|
139 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
140 |
case SLOPE_ENW: |
0 | 141 |
z = 8; |
142 |
y ^= 0xF; |
|
143 |
if (y - x < 0) |
|
144 |
z += (y - x) >> 1; |
|
145 |
break; |
|
146 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
147 |
case SLOPE_SEN: |
0 | 148 |
z = 8; |
149 |
if (y - x < 0) |
|
150 |
z += (y - x) >> 1; |
|
151 |
break; |
|
152 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
153 |
case SLOPE_STEEP_S: |
0 | 154 |
z = 1 + ((x+y)>>1); |
155 |
break; |
|
156 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
157 |
case SLOPE_STEEP_W: |
0 | 158 |
z = 1 + ((x+(y^0xF))>>1); |
159 |
break; |
|
160 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
161 |
case SLOPE_STEEP_N: |
0 | 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 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
165 |
case SLOPE_STEEP_E: |
0 | 166 |
z = 1 + (((x^0xF)+(y^0xF))>>1); |
167 |
break; |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
168 |
|
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
169 |
default: break; |
0 | 170 |
} |
171 |
||
172 |
return z; |
|
173 |
} |
|
174 |
||
2951 | 175 |
uint GetSlopeZ(int x, int y) |
0 | 176 |
{ |
177 |
TileInfo ti; |
|
178 |
||
179 |
FindLandscapeHeight(&ti, x, y); |
|
180 |
||
181 |
return _tile_type_procs[ti.type]->get_slope_z_proc(&ti); |
|
182 |
} |
|
183 |
||
39 | 184 |
// direction=true: check for foundation in east and south corner |
185 |
// direction=false: check for foundation in west and south corner |
|
3418
ec9003ebf933
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3416
diff
changeset
|
186 |
static bool HasFoundation(TileIndex tile, bool direction) |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
187 |
{ |
39 | 188 |
bool south, other; // southern corner and east/west corner |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
189 |
Slope tileh = GetTileSlope(tile, NULL); |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
190 |
Slope slope = _tile_type_procs[GetTileType(tile)]->get_slope_tileh_proc(tile, tileh); |
50 | 191 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
192 |
if (slope == SLOPE_FLAT && slope != tileh) tileh = SLOPE_ELEVATED; |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
193 |
south = (tileh & SLOPE_S) != (slope & SLOPE_S); |
39 | 194 |
|
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2535
diff
changeset
|
195 |
if (direction) { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
196 |
other = (tileh & SLOPE_E) != (slope & SLOPE_E); |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2535
diff
changeset
|
197 |
} else { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
198 |
other = (tileh & SLOPE_W) != (slope & SLOPE_W); |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2535
diff
changeset
|
199 |
} |
50 | 200 |
return south || other; |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
201 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
202 |
|
0 | 203 |
void DrawFoundation(TileInfo *ti, uint f) |
204 |
{ |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
205 |
uint32 sprite_base = SPR_SLOPES_BASE-14; |
39 | 206 |
|
3418
ec9003ebf933
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3416
diff
changeset
|
207 |
if (HasFoundation(TILE_ADDXY(ti->tile, 0, -1), true)) sprite_base += 22; // foundation in NW direction |
ec9003ebf933
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3416
diff
changeset
|
208 |
if (HasFoundation(TILE_ADDXY(ti->tile, -1, 0), false)) sprite_base += 44; // foundation in NE direction |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
209 |
|
0 | 210 |
if (f < 15) { |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
211 |
// leveled foundation |
2535 | 212 |
if (sprite_base < SPR_SLOPES_BASE) sprite_base = SPR_FOUNDATION_BASE + 1; // use original slope sprites |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
213 |
|
2639 | 214 |
AddSortableSpriteToDraw(f - 1 + sprite_base, ti->x, ti->y, 16, 16, 7, ti->z); |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
215 |
ti->z += TILE_HEIGHT; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
216 |
ti->tileh = SLOPE_FLAT; |
0 | 217 |
OffsetGroundSprite(31, 1); |
218 |
} else { |
|
219 |
// inclined foundation |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
220 |
sprite_base += 14; |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
221 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
222 |
#define M(x) (1 << (x)) |
0 | 223 |
AddSortableSpriteToDraw( |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
224 |
HASBIT(M(SLOPE_W) | M(SLOPE_S) | M(SLOPE_E) | M(SLOPE_N), ti->tileh) ? |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
225 |
sprite_base + (f - 15) : SPR_FOUNDATION_BASE + ti->tileh, |
0 | 226 |
ti->x, ti->y, 1, 1, 1, ti->z |
227 |
); |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
228 |
#undef M |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
229 |
|
0 | 230 |
ti->tileh = _inclined_tileh[f - 15]; |
231 |
OffsetGroundSprite(31, 9); |
|
232 |
} |
|
233 |
} |
|
234 |
||
1589
bac29165710f
(svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents:
1384
diff
changeset
|
235 |
void DoClearSquare(TileIndex tile) |
0 | 236 |
{ |
3447 | 237 |
MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
238 |
MarkTileDirtyByTile(tile); |
0 | 239 |
} |
240 |
||
1589
bac29165710f
(svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents:
1384
diff
changeset
|
241 |
uint32 GetTileTrackStatus(TileIndex tile, TransportType mode) |
0 | 242 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
243 |
return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode); |
0 | 244 |
} |
245 |
||
1589
bac29165710f
(svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents:
1384
diff
changeset
|
246 |
void ChangeTileOwner(TileIndex tile, byte old_player, byte new_player) |
0 | 247 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
248 |
_tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_player, new_player); |
0 | 249 |
} |
250 |
||
1589
bac29165710f
(svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents:
1384
diff
changeset
|
251 |
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac) |
0 | 252 |
{ |
253 |
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
|
254 |
_tile_type_procs[GetTileType(tile)]->get_accepted_cargo_proc(tile, ac); |
0 | 255 |
} |
256 |
||
1589
bac29165710f
(svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents:
1384
diff
changeset
|
257 |
void AnimateTile(TileIndex tile) |
0 | 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)]->animate_tile_proc(tile); |
0 | 260 |
} |
261 |
||
1589
bac29165710f
(svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents:
1384
diff
changeset
|
262 |
void ClickTile(TileIndex tile) |
0 | 263 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
264 |
_tile_type_procs[GetTileType(tile)]->click_tile_proc(tile); |
0 | 265 |
} |
266 |
||
267 |
void DrawTile(TileInfo *ti) |
|
268 |
{ |
|
269 |
_tile_type_procs[ti->type]->draw_tile_proc(ti); |
|
270 |
} |
|
271 |
||
1589
bac29165710f
(svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents:
1384
diff
changeset
|
272 |
void GetTileDesc(TileIndex tile, TileDesc *td) |
0 | 273 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
274 |
_tile_type_procs[GetTileType(tile)]->get_tile_desc_proc(tile, td); |
0 | 275 |
} |
276 |
||
1775
548dc04d50e2
(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 |
/** Clear a piece of landscape |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
278 |
* @param tile tile to clear |
1775
548dc04d50e2
(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 p1 unused |
548dc04d50e2
(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
|
280 |
* @param p2 unused |
0 | 281 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
282 |
int32 CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 283 |
{ |
284 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
285 |
||
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
286 |
return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags); |
0 | 287 |
} |
288 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
289 |
/** Clear a big piece of landscape |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
290 |
* @param tile end tile of area dragging |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
291 |
* @param p1 start tile of area dragging |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
292 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
293 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
294 |
int32 CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 295 |
{ |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
296 |
int32 cost, ret, money; |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
297 |
int ex; |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
298 |
int ey; |
0 | 299 |
int sx,sy; |
300 |
int x,y; |
|
301 |
bool success = false; |
|
302 |
||
2934
3f29a7212713
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2639
diff
changeset
|
303 |
if (p1 >= MapSize()) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
304 |
|
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
|
305 |
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
|
306 |
|
0 | 307 |
// make sure sx,sy are smaller than ex,ey |
3493
c77bcf04294d
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
308 |
ex = TileX(tile); |
c77bcf04294d
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
309 |
ey = TileY(tile); |
c77bcf04294d
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
310 |
sx = TileX(p1); |
c77bcf04294d
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
311 |
sy = TileY(p1); |
0 | 312 |
if (ex < sx) intswap(ex, sx); |
313 |
if (ey < sy) intswap(ey, sy); |
|
314 |
||
315 |
money = GetAvailableMoneyForCommand(); |
|
316 |
cost = 0; |
|
317 |
||
3493
c77bcf04294d
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
318 |
for (x = sx; x <= ex; ++x) { |
c77bcf04294d
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
319 |
for (y = sy; y <= ey; ++y) { |
c77bcf04294d
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
320 |
ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
321 |
if (CmdFailed(ret)) continue; |
0 | 322 |
cost += ret; |
323 |
success = true; |
|
324 |
||
325 |
if (flags & DC_EXEC) { |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
326 |
if (ret > 0 && (money -= ret) < 0) { |
0 | 327 |
_additional_cash_required = ret; |
328 |
return cost - ret; |
|
329 |
} |
|
3493
c77bcf04294d
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
330 |
DoCommand(TileXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
0 | 331 |
|
332 |
// draw explosion animation... |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
333 |
if ((x == sx || x == ex) && (y == sy || y == ey)) { |
0 | 334 |
// big explosion in each corner, or small explosion for single tiles |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
335 |
CreateEffectVehicleAbove(x * TILE_SIZE + TILE_SIZE / 2, y * TILE_SIZE + TILE_SIZE / 2, 2, |
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
|
336 |
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
|
337 |
); |
0 | 338 |
} |
339 |
} |
|
340 |
} |
|
341 |
} |
|
342 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
343 |
return (success) ? cost : CMD_ERROR; |
0 | 344 |
} |
345 |
||
346 |
||
347 |
#define TILELOOP_BITS 4 |
|
348 |
#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
|
349 |
#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
|
350 |
#define TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS) |
0 | 351 |
|
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
|
352 |
void RunTileLoop(void) |
0 | 353 |
{ |
1589
bac29165710f
(svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents:
1384
diff
changeset
|
354 |
TileIndex tile; |
0 | 355 |
uint count; |
356 |
||
357 |
tile = _cur_tileloop_tile; |
|
358 |
||
359 |
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
|
360 |
count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE); |
0 | 361 |
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
|
362 |
_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile); |
0 | 363 |
|
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
|
364 |
if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) { |
0 | 365 |
tile += TILELOOP_SIZE; /* no overflow */ |
366 |
} else { |
|
1981 | 367 |
tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */ |
0 | 368 |
} |
369 |
} while (--count); |
|
370 |
assert( (tile & ~TILELOOP_ASSERTMASK) == 0); |
|
371 |
||
372 |
tile += 9; |
|
373 |
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
|
374 |
tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK; |
0 | 375 |
_cur_tileloop_tile = tile; |
376 |
} |
|
377 |
||
2055
4926ed1a7562
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2051
diff
changeset
|
378 |
void InitializeLandscape(void) |
0 | 379 |
{ |
3078
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
380 |
uint maxx = MapMaxX(); |
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
381 |
uint maxy = MapMaxY(); |
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
382 |
uint sizex = MapSizeX(); |
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
383 |
uint x; |
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
384 |
uint y; |
1218 | 385 |
|
3078
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
386 |
for (y = 0; y < maxy; y++) { |
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
387 |
for (x = 0; x < maxx; x++) { |
3447 | 388 |
MakeClear(sizex * y + x, CLEAR_GRASS, 3); |
3078
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
389 |
SetTileHeight(sizex * y + x, 0); |
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
390 |
} |
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
391 |
MakeVoid(sizex * y + x); |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
392 |
} |
3078
cfce0beffa16
(svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents:
3076
diff
changeset
|
393 |
for (x = 0; x < sizex; x++) MakeVoid(sizex * y + x); |
0 | 394 |
} |
395 |
||
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
|
396 |
void ConvertGroundTilesIntoWaterTiles(void) |
0 | 397 |
{ |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
398 |
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
|
399 |
uint h; |
0 | 400 |
|
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
401 |
for (tile = 0; tile < MapSize(); ++tile) { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3529
diff
changeset
|
402 |
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h == 0) { |
3111
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3078
diff
changeset
|
403 |
MakeWater(tile); |
0 | 404 |
} |
405 |
} |
|
406 |
} |
|
407 |
||
408 |
static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 }; |
|
409 |
static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 }; |
|
410 |
||
411 |
static void GenerateTerrain(int type, int flag) |
|
412 |
{ |
|
413 |
uint32 r; |
|
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
414 |
uint x; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
415 |
uint y; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
416 |
uint w; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
417 |
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
|
418 |
const Sprite* template; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
419 |
const byte *p; |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
420 |
Tile* tile; |
0 | 421 |
byte direction; |
422 |
||
423 |
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
|
424 |
template = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845); |
0 | 425 |
|
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
851
diff
changeset
|
426 |
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
|
427 |
y = (r >> MapLogX()) & MapMaxY(); |
0 | 428 |
|
429 |
||
2951 | 430 |
if (x < 2 || y < 2) return; |
0 | 431 |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2055
diff
changeset
|
432 |
direction = GB(r, 22, 2); |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
433 |
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
|
434 |
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
|
435 |
h = template->width; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
436 |
} 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
|
437 |
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
|
438 |
h = template->height; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
439 |
} |
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
|
440 |
p = template->data; |
0 | 441 |
|
442 |
if (flag & 4) { |
|
1273
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
443 |
uint xw = x * MapSizeY(); |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
444 |
uint yw = y * MapSizeX(); |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
445 |
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
|
446 |
|
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
447 |
switch (flag & 3) { |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
448 |
case 0: |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
449 |
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
|
450 |
break; |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
451 |
|
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
452 |
case 1: |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
453 |
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
|
454 |
break; |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
455 |
|
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
456 |
case 2: |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
457 |
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
|
458 |
break; |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
459 |
|
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
460 |
case 3: |
e4849a568647
(svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents:
1247
diff
changeset
|
461 |
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
|
462 |
break; |
0 | 463 |
} |
464 |
} |
|
465 |
||
2951 | 466 |
if (x + w >= MapMaxX() - 1) return; |
467 |
if (y + h >= MapMaxY() - 1) return; |
|
0 | 468 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
469 |
tile = &_m[TileXY(x, y)]; |
0 | 470 |
|
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
471 |
switch (direction) { |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
472 |
case 0: |
0 | 473 |
do { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
474 |
Tile* tile_cur = tile; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
475 |
uint w_cur; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
476 |
|
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
477 |
for (w_cur = w; w_cur != 0; --w_cur) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
478 |
if (*p >= tile_cur->type_height) tile_cur->type_height = *p; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
479 |
p++; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
480 |
tile_cur++; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
481 |
} |
1981 | 482 |
tile += TileDiffXY(0, 1); |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
483 |
} while (--h != 0); |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
484 |
break; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
485 |
|
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
486 |
case 1: |
0 | 487 |
do { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
488 |
Tile* tile_cur = tile; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
489 |
uint h_cur; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
490 |
|
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
491 |
for (h_cur = h; h_cur != 0; --h_cur) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
492 |
if (*p >= tile_cur->type_height) tile_cur->type_height = *p; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
493 |
p++; |
1981 | 494 |
tile_cur += TileDiffXY(0, 1); |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
495 |
} |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
496 |
tile++; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
497 |
} while (--w != 0); |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
498 |
break; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
499 |
|
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
500 |
case 2: |
1981 | 501 |
tile += TileDiffXY(w - 1, 0); |
0 | 502 |
do { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
503 |
Tile* tile_cur = tile; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
504 |
uint w_cur; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
505 |
|
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
506 |
for (w_cur = w; w_cur != 0; --w_cur) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
507 |
if (*p >= tile_cur->type_height) tile_cur->type_height = *p; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
508 |
p++; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
509 |
tile_cur--; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
510 |
} |
1981 | 511 |
tile += TileDiffXY(0, 1); |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
512 |
} while (--h != 0); |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
513 |
break; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
514 |
|
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
515 |
case 3: |
1981 | 516 |
tile += TileDiffXY(0, h - 1); |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
517 |
do { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
518 |
Tile* tile_cur = tile; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
519 |
uint h_cur; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
520 |
|
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
521 |
for (h_cur = h; h_cur != 0; --h_cur) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
522 |
if (*p >= tile_cur->type_height) tile_cur->type_height = *p; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
523 |
p++; |
1981 | 524 |
tile_cur -= TileDiffXY(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
|
525 |
} |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
526 |
tile++; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
527 |
} while (--w != 0); |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
528 |
break; |
0 | 529 |
} |
530 |
} |
|
531 |
||
532 |
||
533 |
#include "table/genland.h" |
|
534 |
||
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
|
535 |
static void CreateDesertOrRainForest(void) |
0 | 536 |
{ |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
537 |
TileIndex tile; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
538 |
const TileIndexDiffC *data; |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
539 |
uint i; |
0 | 540 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
541 |
for (tile = 0; tile != MapSize(); ++tile) { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
542 |
for (data = _make_desert_or_rainforest_data; |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
543 |
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
|
544 |
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
|
545 |
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
|
546 |
} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
547 |
if (data == endof(_make_desert_or_rainforest_data)) |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3297
diff
changeset
|
548 |
SetTropicZone(tile, TROPICZONE_DESERT); |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
549 |
} |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
550 |
|
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
551 |
for (i = 0; i != 256; i++) |
0 | 552 |
RunTileLoop(); |
553 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
554 |
for (tile = 0; tile != MapSize(); ++tile) { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
555 |
for (data = _make_desert_or_rainforest_data; |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
556 |
data != endof(_make_desert_or_rainforest_data); ++data) { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
557 |
TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data)); |
3447 | 558 |
if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
559 |
} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
560 |
if (data == endof(_make_desert_or_rainforest_data)) |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3297
diff
changeset
|
561 |
SetTropicZone(tile, TROPICZONE_RAINFOREST); |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
562 |
} |
0 | 563 |
} |
564 |
||
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
|
565 |
void GenerateLandscape(void) |
0 | 566 |
{ |
1275
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
567 |
uint i; |
5d1b5fe31c78
(svn r1779) Make the map generation code slightly more readable
tron
parents:
1273
diff
changeset
|
568 |
uint flag; |
0 | 569 |
uint32 r; |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
570 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
571 |
switch (_opt.landscape) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
572 |
case LT_HILLY: |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
573 |
for (i = ScaleByMapSize((Random() & 0x7F) + 950); i != 0; --i) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
574 |
GenerateTerrain(2, 0); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
575 |
} |
183
ec2b02ea4c88
(svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents:
159
diff
changeset
|
576 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
577 |
r = Random(); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
578 |
flag = GB(r, 0, 2) | 4; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
579 |
for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
580 |
GenerateTerrain(4, flag); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
581 |
} |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
582 |
break; |
0 | 583 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
584 |
case LT_DESERT: |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
585 |
for (i = ScaleByMapSize((Random() & 0x7F) + 170); i != 0; --i) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
586 |
GenerateTerrain(0, 0); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
587 |
} |
0 | 588 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
589 |
r = Random(); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
590 |
flag = GB(r, 0, 2) | 4; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
591 |
for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
592 |
GenerateTerrain(0, flag); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
593 |
} |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
594 |
|
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
595 |
flag ^= 2; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
596 |
|
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
597 |
for (i = ScaleByMapSize((Random() & 0x7F) + 410); i != 0; --i) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
598 |
GenerateTerrain(3, flag); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
599 |
} |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
600 |
break; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
601 |
|
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
602 |
default: |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
603 |
i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
604 |
for (; i != 0; --i) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
605 |
GenerateTerrain(_opt.diff.terrain_type, 0); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
606 |
} |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
607 |
break; |
0 | 608 |
} |
609 |
||
610 |
ConvertGroundTilesIntoWaterTiles(); |
|
611 |
||
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2955
diff
changeset
|
612 |
if (_opt.landscape == LT_DESERT) CreateDesertOrRainForest(); |
0 | 613 |
} |
614 |
||
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
|
615 |
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
|
616 |
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
|
617 |
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
|
618 |
void OnTick_Industry(void); |
0 | 619 |
|
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
|
620 |
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
|
621 |
void OnTick_Train(void); |
0 | 622 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
623 |
void CallLandscapeTick(void) |
0 | 624 |
{ |
625 |
OnTick_Town(); |
|
626 |
OnTick_Trees(); |
|
627 |
OnTick_Station(); |
|
628 |
OnTick_Industry(); |
|
629 |
||
630 |
OnTick_Players(); |
|
631 |
OnTick_Train(); |
|
632 |
} |
|
633 |
||
634 |
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng) |
|
635 |
{ |
|
636 |
int rn = rng; |
|
637 |
uint32 r = Random(); |
|
638 |
||
1981 | 639 |
return TILE_MASK(TileXY( |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
640 |
TileX(a) + (GB(r, 0, 8) * rn * 2 >> 8) - rn, |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
641 |
TileY(a) + (GB(r, 8, 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
|
642 |
)); |
0 | 643 |
} |
644 |
||
1589
bac29165710f
(svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents:
1384
diff
changeset
|
645 |
bool IsValidTile(TileIndex tile) |
0 | 646 |
{ |
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
|
647 |
return (tile < MapSizeX() * MapMaxY() && TileX(tile) != MapMaxX()); |
0 | 648 |
} |