author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1493 | 414b3608df4d |
child 1786 | 7cfd46c3fcc4 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
507
diff
changeset
|
4 |
#include "map.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
|
5 |
#include "tile.h" |
0 | 6 |
#include "command.h" |
7 |
#include "viewport.h" |
|
8 |
#include "player.h" |
|
9 |
#include "gui.h" |
|
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
222
diff
changeset
|
10 |
#include "station.h" |
0 | 11 |
#include "economy.h" |
12 |
#include "town.h" |
|
405
415546028e8d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
384
diff
changeset
|
13 |
#include "sprite.h" |
0 | 14 |
|
15 |
typedef struct DrawTileUnmovableStruct { |
|
16 |
uint16 image; |
|
17 |
byte subcoord_x; |
|
18 |
byte subcoord_y; |
|
19 |
byte width; |
|
20 |
byte height; |
|
21 |
byte z_size; |
|
22 |
byte unused; |
|
23 |
} DrawTileUnmovableStruct; |
|
24 |
||
25 |
#include "table/unmovable_land.h" |
|
26 |
||
27 |
static void DrawTile_Unmovable(TileInfo *ti) |
|
28 |
{ |
|
29 |
uint32 image, ormod; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
30 |
|
0 | 31 |
if (!(ti->map5 & 0x80)) { |
32 |
if (ti->map5 == 2) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
33 |
|
0 | 34 |
// statue |
35 |
DrawGroundSprite(0x58C); |
|
36 |
||
37 |
image = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]); |
|
38 |
image += 0x8A48; |
|
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
39 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 40 |
image = (image & 0x3FFF) | 0x3224000; |
41 |
AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 25, ti->z); |
|
42 |
} else if (ti->map5 == 3) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
43 |
|
0 | 44 |
// "owned by" sign |
45 |
DrawClearLandTile(ti, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
46 |
|
0 | 47 |
AddSortableSpriteToDraw( |
48 |
PLAYER_SPRITE_COLOR(_map_owner[ti->tile]) + 0x92B6, |
|
49 |
ti->x+8, ti->y+8, |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
50 |
1, 1, |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
51 |
10, |
0 | 52 |
GetSlopeZ(ti->x+8, ti->y+8) |
53 |
); |
|
54 |
} else { |
|
55 |
// lighthouse or transmitter |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
56 |
|
0 | 57 |
const DrawTileUnmovableStruct *dtus; |
58 |
||
59 |
if (ti->tileh) DrawFoundation(ti, ti->tileh); |
|
60 |
DrawClearLandTile(ti, 2); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
61 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
62 |
dtus = &_draw_tile_unmovable_data[ti->map5]; |
0 | 63 |
|
64 |
image = dtus->image; |
|
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
65 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 66 |
image = (image & 0x3FFF) | 0x3224000; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
67 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
68 |
AddSortableSpriteToDraw(image, |
0 | 69 |
ti->x | dtus->subcoord_x, |
70 |
ti->y | dtus->subcoord_y, |
|
71 |
dtus->width, dtus->height, |
|
72 |
dtus->z_size, ti->z); |
|
73 |
} |
|
74 |
} else { |
|
75 |
const DrawTileSeqStruct *dtss; |
|
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
222
diff
changeset
|
76 |
const DrawTileSprites *t; |
0 | 77 |
|
78 |
if (ti->tileh) DrawFoundation(ti, ti->tileh); |
|
79 |
||
80 |
ormod = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]); |
|
81 |
||
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
222
diff
changeset
|
82 |
t = &_unmovable_display_datas[ti->map5 & 0x7F]; |
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
222
diff
changeset
|
83 |
DrawGroundSprite(t->ground_sprite | ormod); |
0 | 84 |
|
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
222
diff
changeset
|
85 |
foreach_draw_tile_seq(dtss, t->seq) { |
0 | 86 |
image = dtss->image; |
87 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
|
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
88 |
image = (image & 0x3FFF) | 0x03224000; |
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
89 |
} else { |
0 | 90 |
image |= ormod; |
91 |
} |
|
92 |
AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y, |
|
93 |
dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z); |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
98 |
static uint GetSlopeZ_Unmovable(TileInfo *ti) |
0 | 99 |
{ |
100 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
|
101 |
} |
|
102 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
103 |
static uint GetSlopeTileh_Unmovable(TileInfo *ti) |
39 | 104 |
{ |
105 |
return 0; |
|
106 |
} |
|
107 |
||
0 | 108 |
static int32 ClearTile_Unmovable(uint tile, byte flags) |
109 |
{ |
|
110 |
byte m5 = _map5[tile]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
111 |
|
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
112 |
if (m5 & 0x80) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
113 |
if (_current_player == OWNER_WATER) |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
147
diff
changeset
|
114 |
return DoCommandByTile(tile, OWNER_WATER, 0, DC_EXEC, CMD_DESTROY_COMPANY_HQ); |
0 | 115 |
return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
116 |
} |
0 | 117 |
|
118 |
if (m5 == 3) // company owned land |
|
119 |
return DoCommandByTile(tile, 0, 0, flags, CMD_SELL_LAND_AREA); |
|
120 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
147
diff
changeset
|
121 |
// checks if you're allowed to remove unmovable things |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
147
diff
changeset
|
122 |
if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) ) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
147
diff
changeset
|
123 |
return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
124 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
125 |
if (flags & DC_EXEC) { |
0 | 126 |
DoClearSquare(tile); |
127 |
} |
|
128 |
||
129 |
return 0; |
|
130 |
} |
|
131 |
||
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
132 |
static void GetAcceptedCargo_Unmovable(uint tile, AcceptedCargo ac) |
0 | 133 |
{ |
134 |
byte m5 = _map5[tile]; |
|
135 |
uint level; // HQ level (depends on company performance) in the range 1..5. |
|
136 |
||
137 |
if (!(m5 & 0x80)) { |
|
138 |
/* not used */ |
|
139 |
return; |
|
140 |
} |
|
141 |
||
142 |
/* HQ accepts passenger and mail; but we have to divide the values |
|
143 |
* between 4 tiles it occupies! */ |
|
144 |
||
145 |
level = (m5 & ~0x80) / 4 + 1; |
|
146 |
||
147 |
// Top town building generates 10, so to make HQ interesting, the top |
|
148 |
// type makes 20. |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
149 |
ac[CT_PASSENGERS] = max(1, level); |
0 | 150 |
|
151 |
// Top town building generates 4, HQ can make up to 8. The |
|
152 |
// proportion passengers:mail is different because such a huge |
|
153 |
// commercial building generates unusually high amount of mail |
|
154 |
// correspondence per physical visitor. |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
155 |
ac[CT_MAIL] = max(1, level / 2); |
0 | 156 |
} |
157 |
||
158 |
static const StringID _unmovable_tile_str[] = { |
|
159 |
STR_5803_COMPANY_HEADQUARTERS, |
|
160 |
STR_5801_TRANSMITTER, |
|
161 |
STR_5802_LIGHTHOUSE, |
|
162 |
STR_2016_STATUE, |
|
163 |
STR_5805_COMPANY_OWNED_LAND, |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
164 |
}; |
0 | 165 |
|
166 |
static void GetTileDesc_Unmovable(uint tile, TileDesc *td) |
|
167 |
{ |
|
168 |
int i = _map5[tile]; |
|
169 |
if (i & 0x80) i = -1; |
|
170 |
td->str = _unmovable_tile_str[i + 1]; |
|
171 |
td->owner = _map_owner[tile]; |
|
172 |
} |
|
173 |
||
174 |
static void AnimateTile_Unmovable(uint tile) |
|
175 |
{ |
|
176 |
/* not used */ |
|
177 |
} |
|
178 |
||
179 |
static void TileLoop_Unmovable(uint tile) |
|
180 |
{ |
|
181 |
byte m5 = _map5[tile]; |
|
182 |
byte level; // HQ level (depends on company performance) in the range 1..5. |
|
183 |
uint32 r; |
|
184 |
||
185 |
if (!(m5 & 0x80)) { |
|
186 |
/* not used */ |
|
187 |
return; |
|
188 |
} |
|
189 |
||
190 |
/* HQ accepts passenger and mail; but we have to divide the values |
|
191 |
* between 4 tiles it occupies! */ |
|
192 |
||
193 |
level = (m5 & ~0x80) / 4 + 1; |
|
194 |
assert(level < 6); |
|
195 |
||
196 |
r = Random(); |
|
197 |
// Top town buildings generate 250, so the top HQ type makes 256. |
|
198 |
if ((byte) r < (256 / 4 / (6 - level))) { |
|
199 |
uint amt = ((byte) r >> 3) / 4 + 1; |
|
200 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
|
201 |
MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt); |
|
202 |
} |
|
203 |
||
204 |
r >>= 8; |
|
205 |
// Top town building generates 90, HQ can make up to 196. The |
|
206 |
// proportion passengers:mail is about the same as in the acceptance |
|
207 |
// equations. |
|
208 |
if ((byte) r < (196 / 4 / (6 - level))) { |
|
209 |
uint amt = ((byte) r >> 3) / 4 + 1; |
|
210 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
|
211 |
MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt); |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
||
160
db200af4794a
(svn r161) -Fix: added missing file to project and solved wrong type bug
darkvater
parents:
149
diff
changeset
|
216 |
static uint32 GetTileTrackStatus_Unmovable(uint tile, TransportType mode) |
0 | 217 |
{ |
218 |
return 0; |
|
219 |
} |
|
220 |
||
221 |
static void ClickTile_Unmovable(uint tile) |
|
222 |
{ |
|
223 |
if (_map5[tile] & 0x80) { |
|
224 |
ShowPlayerCompany(_map_owner[tile]); |
|
225 |
} |
|
226 |
} |
|
227 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
228 |
static const TileIndexDiffC _tile_add[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
229 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
230 |
{ 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
231 |
{-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
232 |
{ 0, -1} |
0 | 233 |
}; |
234 |
||
235 |
/* checks, if a radio tower is within a 9x9 tile square around tile */ |
|
410 | 236 |
static bool checkRadioTowerNearby(uint tile) |
0 | 237 |
{ |
238 |
uint tile_s; |
|
239 |
||
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:
909
diff
changeset
|
240 |
tile_s = TILE_XY(TileX(tile) - 4, TileY(tile) - 4); |
0 | 241 |
|
242 |
BEGIN_TILE_LOOP(tile, 9, 9, tile_s) |
|
243 |
// already a radio tower here? |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
244 |
if (IsTileType(tile, MP_UNMOVABLE) && _map5[tile] == 0) |
0 | 245 |
return false; |
246 |
END_TILE_LOOP(tile, 9, 9, tile_s) |
|
247 |
return true; |
|
248 |
} |
|
249 |
||
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
|
250 |
void GenerateUnmovables(void) |
0 | 251 |
{ |
252 |
int i,j; |
|
253 |
uint tile; |
|
254 |
uint32 r; |
|
255 |
int dir; |
|
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1225
diff
changeset
|
256 |
uint h; |
0 | 257 |
|
258 |
if (_opt.landscape == LT_CANDY) |
|
259 |
return; |
|
260 |
||
261 |
/* add radio tower */ |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
262 |
i = ScaleByMapSize(1000); |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
263 |
j = ScaleByMapSize(40); // maximum number of radio towers on the map |
0 | 264 |
do { |
265 |
r = Random(); |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
266 |
tile = r % MapSize(); |
0 | 267 |
// TILE_MASK seems to be not working correctly. Radio masts accumulate in one area. |
268 |
// tile = TILE_MASK(r); |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
269 |
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) { |
0 | 270 |
if(!checkRadioTowerNearby(tile)) |
271 |
continue; |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1035
diff
changeset
|
272 |
SetTileType(tile, MP_UNMOVABLE); |
0 | 273 |
_map5[tile] = 0; |
274 |
_map_owner[tile] = OWNER_NONE; |
|
275 |
if (--j == 0) |
|
276 |
break; |
|
277 |
} |
|
278 |
} while (--i); |
|
279 |
||
280 |
if (_opt.landscape == LT_DESERT) |
|
281 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
282 |
|
0 | 283 |
/* add lighthouses */ |
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
284 |
i = ScaleByMapSize1D((Random() & 3) + 7); |
0 | 285 |
do { |
286 |
restart: |
|
287 |
r = Random(); |
|
288 |
dir = r >> 30; |
|
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
679
diff
changeset
|
289 |
r %= (dir == 0 || dir == 2) ? MapMaxY() : MapMaxX(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
290 |
tile = |
1489
d4139b9eeff3
(svn r1993) Fixed some devious [lack of] tabs usage.
pasky
parents:
1335
diff
changeset
|
291 |
(dir==0)?TILE_XY(0,r):0 + // left |
d4139b9eeff3
(svn r1993) Fixed some devious [lack of] tabs usage.
pasky
parents:
1335
diff
changeset
|
292 |
(dir==1)?TILE_XY(r,0):0 + // top |
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
679
diff
changeset
|
293 |
(dir == 2) ? TILE_XY(MapMaxX(), r) : 0 + // right |
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
679
diff
changeset
|
294 |
(dir == 3) ? TILE_XY(r, MapMaxY()) : 0; // bottom |
0 | 295 |
j = 20; |
296 |
do { |
|
297 |
if (--j == 0) |
|
298 |
goto restart; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
299 |
tile = TILE_MASK(tile + ToTileIndexDiff(_tile_add[dir])); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
300 |
} while (!(IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h <= 16)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
301 |
|
0 | 302 |
assert(tile == TILE_MASK(tile)); |
303 |
||
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1035
diff
changeset
|
304 |
SetTileType(tile, MP_UNMOVABLE); |
0 | 305 |
_map5[tile] = 1; |
306 |
_map_owner[tile] = OWNER_NONE; |
|
307 |
} while (--i); |
|
308 |
} |
|
309 |
||
310 |
extern int32 CheckFlatLandBelow(uint tile, uint w, uint h, uint flags, uint invalid_dirs, int *); |
|
311 |
||
1489
d4139b9eeff3
(svn r1993) Fixed some devious [lack of] tabs usage.
pasky
parents:
1335
diff
changeset
|
312 |
/* p1 = relocate HQ |
d4139b9eeff3
(svn r1993) Fixed some devious [lack of] tabs usage.
pasky
parents:
1335
diff
changeset
|
313 |
* p1&0xFF = player whose HQ is up for relocation |
d4139b9eeff3
(svn r1993) Fixed some devious [lack of] tabs usage.
pasky
parents:
1335
diff
changeset
|
314 |
*/ |
0 | 315 |
int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
316 |
{ |
|
1225
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
317 |
TileIndex tile = TILE_FROM_XY(x,y); |
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
318 |
Player *p = DEREF_PLAYER(_current_player); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
319 |
int score; |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
320 |
int32 cost = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
321 |
|
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
|
322 |
SET_EXPENSES_TYPE(EXPENSES_PROPERTY); |
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
|
323 |
|
1489
d4139b9eeff3
(svn r1993) Fixed some devious [lack of] tabs usage.
pasky
parents:
1335
diff
changeset
|
324 |
cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL); |
1225
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
325 |
|
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
326 |
if (cost == CMD_ERROR) |
0 | 327 |
return CMD_ERROR; |
328 |
||
1225
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
329 |
if (p1) { |
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
330 |
int32 ret = DoCommand( |
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:
909
diff
changeset
|
331 |
TileX(p->location_of_house) * 16, TileY(p->location_of_house) * 16, |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
332 |
p1 & 0xFF, 0, flags, CMD_DESTROY_COMPANY_HQ); |
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
333 |
|
1225
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
334 |
if (ret == CMD_ERROR) |
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
335 |
return CMD_ERROR; |
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
336 |
|
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
337 |
cost += ret; |
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
338 |
} |
16a44e26efa5
(svn r1729) - Fix: [ 1112469 ] Clearing land for free by reallocating HQ
darkvater
parents:
1209
diff
changeset
|
339 |
|
0 | 340 |
if (flags & DC_EXEC) { |
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
341 |
score = UpdateCompanyRatingAndValue(p, false); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
342 |
|
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
343 |
p->location_of_house = tile; |
0 | 344 |
|
345 |
ModifyTile(tile + TILE_XY(0,0), |
|
346 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
347 |
0x80 |
|
348 |
); |
|
349 |
||
350 |
ModifyTile(tile + TILE_XY(0,1), |
|
351 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
352 |
0x81 |
|
353 |
); |
|
354 |
||
355 |
ModifyTile(tile + TILE_XY(1,0), |
|
356 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
357 |
0x82 |
|
358 |
); |
|
359 |
||
360 |
ModifyTile(tile + TILE_XY(1,1), |
|
361 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
362 |
0x83 |
|
363 |
); |
|
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
364 |
UpdatePlayerHouse(p, score); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
365 |
InvalidateWindow(WC_COMPANY, (int)p->index); |
0 | 366 |
} |
367 |
||
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
368 |
return cost; |
0 | 369 |
} |
370 |
||
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
371 |
/* p1 = owner of the HQ */ |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
372 |
int32 CmdDestroyCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
373 |
{ |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
374 |
uint tile = TILE_FROM_XY(x,y); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
375 |
Player *p; |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
376 |
|
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
|
377 |
SET_EXPENSES_TYPE(EXPENSES_PROPERTY); |
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
|
378 |
|
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
379 |
if ((int)p1 != OWNER_WATER) // destruction was initiated by player |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
380 |
p = DEREF_PLAYER((byte)p1); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
381 |
else { // find player that has HQ flooded, and reset their location_of_house |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
382 |
bool dodelete = false; |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
383 |
FOR_ALL_PLAYERS(p) { |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
384 |
if (p->location_of_house == tile) { |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
385 |
dodelete = true; |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
386 |
break; |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
387 |
} |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
388 |
} |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
389 |
if (!dodelete) |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
390 |
return CMD_ERROR; |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
391 |
} |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
392 |
|
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
393 |
if (flags & DC_EXEC) { |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
394 |
p->location_of_house = 0; // reset HQ position |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
395 |
DoClearSquare(tile + TILE_XY(0,0)); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
396 |
DoClearSquare(tile + TILE_XY(0,1)); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
397 |
DoClearSquare(tile + TILE_XY(1,0)); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
398 |
DoClearSquare(tile + TILE_XY(1,1)); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
399 |
InvalidateWindow(WC_COMPANY, (int)p->index); |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
400 |
} |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
401 |
|
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
402 |
// cost of relocating company is 1% of company value |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
403 |
return CalculateCompanyValue(p) / 100; |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
404 |
} |
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
405 |
|
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
39
diff
changeset
|
406 |
|
0 | 407 |
static void ChangeTileOwner_Unmovable(uint tile, byte old_player, byte new_player) |
408 |
{ |
|
409 |
if (_map_owner[tile] != old_player) |
|
410 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
411 |
|
0 | 412 |
if (_map5[tile]==3 && new_player != 255) { |
413 |
_map_owner[tile] = new_player; |
|
414 |
} else { |
|
415 |
DoClearSquare(tile); |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
const TileTypeProcs _tile_type_unmovable_procs = { |
|
1493
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
420 |
DrawTile_Unmovable, /* draw_tile_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
421 |
GetSlopeZ_Unmovable, /* get_slope_z_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
422 |
ClearTile_Unmovable, /* clear_tile_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
423 |
GetAcceptedCargo_Unmovable, /* get_accepted_cargo_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
424 |
GetTileDesc_Unmovable, /* get_tile_desc_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
425 |
GetTileTrackStatus_Unmovable, /* get_tile_track_status_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
426 |
ClickTile_Unmovable, /* click_tile_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
427 |
AnimateTile_Unmovable, /* animate_tile_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
428 |
TileLoop_Unmovable, /* tile_loop_clear */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
429 |
ChangeTileOwner_Unmovable, /* change_tile_owner_clear */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
430 |
NULL, /* get_produced_cargo_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
431 |
NULL, /* vehicle_enter_tile_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
432 |
NULL, /* vehicle_leave_tile_proc */ |
414b3608df4d
(svn r1997) Fixed errorneous tab expansion on the indentation side which happenned in r1993. Pointed out by Tron.
pasky
parents:
1489
diff
changeset
|
433 |
GetSlopeTileh_Unmovable, /* get_slope_tileh_proc */ |
0 | 434 |
}; |