author | dominik |
Sun, 14 Nov 2004 20:02:43 +0000 | |
changeset 411 | dc46e54bd2ed |
parent 410 | 0efd84450b01 |
child 473 | 77f0ef57e7cf |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
#include "command.h" |
|
4 |
#include "viewport.h" |
|
5 |
#include "player.h" |
|
6 |
#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
|
7 |
#include "station.h" |
0 | 8 |
#include "economy.h" |
9 |
#include "town.h" |
|
405
415546028e8d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
384
diff
changeset
|
10 |
#include "sprite.h" |
0 | 11 |
|
12 |
typedef struct DrawTileUnmovableStruct { |
|
13 |
uint16 image; |
|
14 |
byte subcoord_x; |
|
15 |
byte subcoord_y; |
|
16 |
byte width; |
|
17 |
byte height; |
|
18 |
byte z_size; |
|
19 |
byte unused; |
|
20 |
} DrawTileUnmovableStruct; |
|
21 |
||
22 |
#include "table/unmovable_land.h" |
|
23 |
||
24 |
static void DrawTile_Unmovable(TileInfo *ti) |
|
25 |
{ |
|
26 |
uint32 image, ormod; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
27 |
|
0 | 28 |
if (!(ti->map5 & 0x80)) { |
29 |
if (ti->map5 == 2) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
30 |
|
0 | 31 |
// statue |
32 |
DrawGroundSprite(0x58C); |
|
33 |
||
34 |
image = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]); |
|
35 |
image += 0x8A48; |
|
36 |
if (!(_display_opt & DO_TRANS_BUILDINGS)) |
|
37 |
image = (image & 0x3FFF) | 0x3224000; |
|
38 |
AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 25, ti->z); |
|
39 |
} else if (ti->map5 == 3) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
40 |
|
0 | 41 |
// "owned by" sign |
42 |
DrawClearLandTile(ti, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
43 |
|
0 | 44 |
AddSortableSpriteToDraw( |
45 |
PLAYER_SPRITE_COLOR(_map_owner[ti->tile]) + 0x92B6, |
|
46 |
ti->x+8, ti->y+8, |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
47 |
1, 1, |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
48 |
10, |
0 | 49 |
GetSlopeZ(ti->x+8, ti->y+8) |
50 |
); |
|
51 |
} else { |
|
52 |
// lighthouse or transmitter |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
53 |
|
0 | 54 |
const DrawTileUnmovableStruct *dtus; |
55 |
||
56 |
if (ti->tileh) DrawFoundation(ti, ti->tileh); |
|
57 |
DrawClearLandTile(ti, 2); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
58 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
59 |
dtus = &_draw_tile_unmovable_data[ti->map5]; |
0 | 60 |
|
61 |
image = dtus->image; |
|
62 |
if (!(_display_opt & DO_TRANS_BUILDINGS)) |
|
63 |
image = (image & 0x3FFF) | 0x3224000; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
64 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
65 |
AddSortableSpriteToDraw(image, |
0 | 66 |
ti->x | dtus->subcoord_x, |
67 |
ti->y | dtus->subcoord_y, |
|
68 |
dtus->width, dtus->height, |
|
69 |
dtus->z_size, ti->z); |
|
70 |
} |
|
71 |
} else { |
|
72 |
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
|
73 |
const DrawTileSprites *t; |
0 | 74 |
|
75 |
if (ti->tileh) DrawFoundation(ti, ti->tileh); |
|
76 |
||
77 |
ormod = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]); |
|
78 |
||
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
|
79 |
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
|
80 |
DrawGroundSprite(t->ground_sprite | ormod); |
0 | 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 |
foreach_draw_tile_seq(dtss, t->seq) { |
0 | 83 |
image = dtss->image; |
84 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
|
85 |
image |= ormod; |
|
86 |
} else { |
|
87 |
image = (image & 0x3FFF) | 0x03224000; |
|
88 |
} |
|
89 |
AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y, |
|
90 |
dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z); |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
95 |
static uint GetSlopeZ_Unmovable(TileInfo *ti) |
0 | 96 |
{ |
97 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
|
98 |
} |
|
99 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
100 |
static uint GetSlopeTileh_Unmovable(TileInfo *ti) |
39 | 101 |
{ |
102 |
return 0; |
|
103 |
} |
|
104 |
||
0 | 105 |
static int32 ClearTile_Unmovable(uint tile, byte flags) |
106 |
{ |
|
107 |
byte m5 = _map5[tile]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
108 |
|
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
|
109 |
if (m5 & 0x80) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
110 |
if (_current_player == OWNER_WATER) |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
147
diff
changeset
|
111 |
return DoCommandByTile(tile, OWNER_WATER, 0, DC_EXEC, CMD_DESTROY_COMPANY_HQ); |
0 | 112 |
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
|
113 |
} |
0 | 114 |
|
115 |
if (m5 == 3) // company owned land |
|
116 |
return DoCommandByTile(tile, 0, 0, flags, CMD_SELL_LAND_AREA); |
|
117 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
147
diff
changeset
|
118 |
// 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
|
119 |
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
|
120 |
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
|
121 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
122 |
if (flags & DC_EXEC) { |
0 | 123 |
DoClearSquare(tile); |
124 |
} |
|
125 |
||
126 |
return 0; |
|
127 |
} |
|
128 |
||
129 |
static void GetAcceptedCargo_Unmovable(uint tile, AcceptedCargo *ac) |
|
130 |
{ |
|
131 |
byte m5 = _map5[tile]; |
|
132 |
uint level; // HQ level (depends on company performance) in the range 1..5. |
|
133 |
||
134 |
if (!(m5 & 0x80)) { |
|
135 |
/* not used */ |
|
136 |
return; |
|
137 |
} |
|
138 |
||
139 |
/* HQ accepts passenger and mail; but we have to divide the values |
|
140 |
* between 4 tiles it occupies! */ |
|
141 |
||
142 |
level = (m5 & ~0x80) / 4 + 1; |
|
143 |
||
144 |
// Top town building generates 10, so to make HQ interesting, the top |
|
145 |
// type makes 20. |
|
146 |
ac->type_1 = CT_PASSENGERS; |
|
147 |
ac->amount_1 = level; |
|
148 |
if (!ac->amount_1) ac->amount_1 = 1; |
|
149 |
||
150 |
// Top town building generates 4, HQ can make up to 8. The |
|
151 |
// proportion passengers:mail is different because such a huge |
|
152 |
// commercial building generates unusually high amount of mail |
|
153 |
// correspondence per physical visitor. |
|
154 |
ac->type_2 = CT_MAIL; |
|
155 |
ac->amount_2 = level / 2; |
|
156 |
if (!ac->amount_2) ac->amount_2 = 1; |
|
157 |
} |
|
158 |
||
159 |
static const StringID _unmovable_tile_str[] = { |
|
160 |
STR_5803_COMPANY_HEADQUARTERS, |
|
161 |
STR_5801_TRANSMITTER, |
|
162 |
STR_5802_LIGHTHOUSE, |
|
163 |
STR_2016_STATUE, |
|
164 |
STR_5805_COMPANY_OWNED_LAND, |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
165 |
}; |
0 | 166 |
|
167 |
static void GetTileDesc_Unmovable(uint tile, TileDesc *td) |
|
168 |
{ |
|
169 |
int i = _map5[tile]; |
|
170 |
if (i & 0x80) i = -1; |
|
171 |
td->str = _unmovable_tile_str[i + 1]; |
|
172 |
td->owner = _map_owner[tile]; |
|
173 |
} |
|
174 |
||
175 |
static void AnimateTile_Unmovable(uint tile) |
|
176 |
{ |
|
177 |
/* not used */ |
|
178 |
} |
|
179 |
||
180 |
static void TileLoop_Unmovable(uint tile) |
|
181 |
{ |
|
182 |
byte m5 = _map5[tile]; |
|
183 |
byte level; // HQ level (depends on company performance) in the range 1..5. |
|
184 |
uint32 r; |
|
185 |
||
186 |
if (!(m5 & 0x80)) { |
|
187 |
/* not used */ |
|
188 |
return; |
|
189 |
} |
|
190 |
||
191 |
/* HQ accepts passenger and mail; but we have to divide the values |
|
192 |
* between 4 tiles it occupies! */ |
|
193 |
||
194 |
level = (m5 & ~0x80) / 4 + 1; |
|
195 |
assert(level < 6); |
|
196 |
||
197 |
r = Random(); |
|
198 |
// Top town buildings generate 250, so the top HQ type makes 256. |
|
199 |
if ((byte) r < (256 / 4 / (6 - level))) { |
|
200 |
uint amt = ((byte) r >> 3) / 4 + 1; |
|
201 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
|
202 |
MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt); |
|
203 |
} |
|
204 |
||
205 |
r >>= 8; |
|
206 |
// Top town building generates 90, HQ can make up to 196. The |
|
207 |
// proportion passengers:mail is about the same as in the acceptance |
|
208 |
// equations. |
|
209 |
if ((byte) r < (196 / 4 / (6 - level))) { |
|
210 |
uint amt = ((byte) r >> 3) / 4 + 1; |
|
211 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
|
212 |
MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt); |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
||
160
db200af4794a
(svn r161) -Fix: added missing file to project and solved wrong type bug
darkvater
parents:
149
diff
changeset
|
217 |
static uint32 GetTileTrackStatus_Unmovable(uint tile, TransportType mode) |
0 | 218 |
{ |
219 |
return 0; |
|
220 |
} |
|
221 |
||
222 |
static void ClickTile_Unmovable(uint tile) |
|
223 |
{ |
|
224 |
if (_map5[tile] & 0x80) { |
|
225 |
ShowPlayerCompany(_map_owner[tile]); |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
static const TileIndexDiff _tile_add[4] = { |
|
230 |
TILE_XY(1,0), |
|
231 |
TILE_XY(0,1), |
|
232 |
TILE_XY(-1,0), |
|
233 |
TILE_XY(0,-1), |
|
234 |
}; |
|
235 |
||
236 |
/* checks, if a radio tower is within a 9x9 tile square around tile */ |
|
410 | 237 |
static bool checkRadioTowerNearby(uint tile) |
0 | 238 |
{ |
239 |
uint tile_s; |
|
240 |
||
241 |
tile_s = TILE_XY( (int) GET_TILE_X(tile)-4, (int) GET_TILE_Y(tile)-4 ); |
|
242 |
||
243 |
BEGIN_TILE_LOOP(tile, 9, 9, tile_s) |
|
244 |
// already a radio tower here? |
|
245 |
if (IS_TILETYPE(tile, MP_UNMOVABLE) && _map5[tile] == 0) |
|
246 |
return false; |
|
247 |
END_TILE_LOOP(tile, 9, 9, tile_s) |
|
248 |
return true; |
|
249 |
} |
|
250 |
||
251 |
void GenerateUnmovables() |
|
252 |
{ |
|
253 |
int i,j; |
|
254 |
uint tile; |
|
255 |
uint32 r; |
|
256 |
int dir; |
|
257 |
int h; |
|
258 |
||
259 |
if (_opt.landscape == LT_CANDY) |
|
260 |
return; |
|
261 |
||
262 |
/* add radio tower */ |
|
263 |
i = 1000; |
|
264 |
j = 40; // limit of 40 radio towers per world. |
|
265 |
do { |
|
266 |
r = Random(); |
|
267 |
tile = r % (TILES_X*TILES_Y); |
|
268 |
// TILE_MASK seems to be not working correctly. Radio masts accumulate in one area. |
|
269 |
// tile = TILE_MASK(r); |
|
270 |
if (IS_TILETYPE(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) { |
|
271 |
if(!checkRadioTowerNearby(tile)) |
|
272 |
continue; |
|
273 |
_map_type_and_height[tile] |= MP_UNMOVABLE << 4; |
|
274 |
_map5[tile] = 0; |
|
275 |
_map_owner[tile] = OWNER_NONE; |
|
276 |
if (--j == 0) |
|
277 |
break; |
|
278 |
} |
|
279 |
} while (--i); |
|
280 |
||
281 |
if (_opt.landscape == LT_DESERT) |
|
282 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
283 |
|
0 | 284 |
/* add lighthouses */ |
285 |
i = (Random()&3) + 7; |
|
286 |
do { |
|
287 |
restart: |
|
288 |
r = Random(); |
|
289 |
dir = r >> 30; |
|
290 |
r = r%((dir==0 || dir== 2)?TILE_Y_MAX:TILE_X_MAX); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
291 |
tile = |
0 | 292 |
(dir==0)?TILE_XY(0,r):0 + // left |
293 |
(dir==1)?TILE_XY(r,0):0 + // top |
|
294 |
(dir==2)?TILE_XY(TILE_X_MAX,r):0 + // right |
|
295 |
(dir==3)?TILE_XY(r,TILE_Y_MAX):0; // bottom |
|
296 |
j = 20; |
|
297 |
do { |
|
298 |
if (--j == 0) |
|
299 |
goto restart; |
|
300 |
tile = TILE_MASK(tile + _tile_add[dir]); |
|
301 |
} while (!(IS_TILETYPE(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
|
302 |
|
0 | 303 |
assert(tile == TILE_MASK(tile)); |
304 |
||
305 |
_map_type_and_height[tile] |= MP_UNMOVABLE << 4; |
|
306 |
_map5[tile] = 1; |
|
307 |
_map_owner[tile] = OWNER_NONE; |
|
308 |
} while (--i); |
|
309 |
} |
|
310 |
||
311 |
extern int32 CheckFlatLandBelow(uint tile, uint w, uint h, uint flags, uint invalid_dirs, int *); |
|
312 |
||
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
|
313 |
/* p1 = relocate 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
|
314 |
p1&0xFF = player whose HQ is up for relocation |
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
|
315 |
*/ |
0 | 316 |
int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
317 |
{ |
|
318 |
uint 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
|
319 |
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
|
320 |
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
|
321 |
int32 cost = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
322 |
|
0 | 323 |
if (CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL) == CMD_ERROR) |
324 |
return CMD_ERROR; |
|
325 |
||
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
|
326 |
if (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
|
327 |
cost = DoCommand(GET_TILE_X(p->location_of_house)*16, GET_TILE_Y(p->location_of_house)*16, p1&0xFF, 0, flags, CMD_DESTROY_COMPANY_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
|
328 |
|
0 | 329 |
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
|
330 |
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
|
331 |
|
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
|
332 |
p->location_of_house = tile; |
0 | 333 |
|
334 |
ModifyTile(tile + TILE_XY(0,0), |
|
335 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
336 |
0x80 |
|
337 |
); |
|
338 |
||
339 |
ModifyTile(tile + TILE_XY(0,1), |
|
340 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
341 |
0x81 |
|
342 |
); |
|
343 |
||
344 |
ModifyTile(tile + TILE_XY(1,0), |
|
345 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
346 |
0x82 |
|
347 |
); |
|
348 |
||
349 |
ModifyTile(tile + TILE_XY(1,1), |
|
350 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
351 |
0x83 |
|
352 |
); |
|
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
|
353 |
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
|
354 |
InvalidateWindow(WC_COMPANY, (int)p->index); |
0 | 355 |
} |
356 |
||
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
|
357 |
return cost; |
0 | 358 |
} |
359 |
||
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
|
360 |
/* 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
|
361 |
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
|
362 |
{ |
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
|
363 |
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
|
364 |
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
|
365 |
|
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
|
366 |
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
|
367 |
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
|
368 |
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
|
369 |
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
|
370 |
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
|
371 |
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
|
372 |
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
|
373 |
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
|
374 |
} |
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 |
} |
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 |
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
|
377 |
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
|
378 |
} |
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 |
|
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 |
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
|
381 |
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
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
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
|
386 |
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
|
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 |
// 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
|
390 |
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
|
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 |
|
0 | 394 |
static void ChangeTileOwner_Unmovable(uint tile, byte old_player, byte new_player) |
395 |
{ |
|
396 |
if (_map_owner[tile] != old_player) |
|
397 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
398 |
|
0 | 399 |
if (_map5[tile]==3 && new_player != 255) { |
400 |
_map_owner[tile] = new_player; |
|
401 |
} else { |
|
402 |
DoClearSquare(tile); |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
const TileTypeProcs _tile_type_unmovable_procs = { |
|
407 |
DrawTile_Unmovable, /* draw_tile_proc */ |
|
408 |
GetSlopeZ_Unmovable, /* get_slope_z_proc */ |
|
409 |
ClearTile_Unmovable, /* clear_tile_proc */ |
|
410 |
GetAcceptedCargo_Unmovable, /* get_accepted_cargo_proc */ |
|
411 |
GetTileDesc_Unmovable, /* get_tile_desc_proc */ |
|
412 |
GetTileTrackStatus_Unmovable, /* get_tile_track_status_proc */ |
|
413 |
ClickTile_Unmovable, /* click_tile_proc */ |
|
414 |
AnimateTile_Unmovable, /* animate_tile_proc */ |
|
415 |
TileLoop_Unmovable, /* tile_loop_clear */ |
|
416 |
ChangeTileOwner_Unmovable, /* change_tile_owner_clear */ |
|
417 |
NULL, /* get_produced_cargo_proc */ |
|
418 |
NULL, /* vehicle_enter_tile_proc */ |
|
419 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 420 |
GetSlopeTileh_Unmovable, /* get_slope_tileh_proc */ |
0 | 421 |
}; |