Files
@ r2583:e4e32ba4ba59
Branch filter:
Location: cpp/openttd-patchpack/source/unmovable_cmd.c - annotation
r2583:e4e32ba4ba59
10.9 KiB
text/x-c
(svn r3120) Update the turkish translation, about 2000 strings.
Many thanks to jnmbk for his effort!
Many thanks to jnmbk for his effort!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | r2186:5ee653b1b5e1 r2186:5ee653b1b5e1 r0:d63b455452f6 r1891:c5c5466afa35 r507:b1b0a0a3c313 r2148:f279899fdbd0 r2163:ae001e2aa5b0 r679:3a7b08cc8504 r1209:5955f8748394 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r384:75b26a2a614a r0:d63b455452f6 r0:d63b455452f6 r405:af2e0e5f1331 r2159:2c706fe6b0a7 r0:d63b455452f6 r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r2026:25935f6b221a r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1962:cc4c06e3f6b5 r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1981:addba4bccc89 r1981:addba4bccc89 r1981:addba4bccc89 r1981:addba4bccc89 r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r2473:65366a23d295 r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1977:1f8b99c96041 r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1980:3622a0cd06c2 r1962:cc4c06e3f6b5 r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r2473:65366a23d295 r2473:65366a23d295 r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1981:addba4bccc89 r1981:addba4bccc89 r1981:addba4bccc89 r1981:addba4bccc89 r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r1796:4bbf4ea0805e r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r193:6aa65dc5a4b4 r0:d63b455452f6 r0:d63b455452f6 r193:6aa65dc5a4b4 r0:d63b455452f6 r2517:f67017080a5a r0:d63b455452f6 r1901:e806afa50723 r2517:f67017080a5a r497:beb1bd29f06e r2148:f279899fdbd0 r0:d63b455452f6 r0:d63b455452f6 r193:6aa65dc5a4b4 r0:d63b455452f6 r0:d63b455452f6 r193:6aa65dc5a4b4 r0:d63b455452f6 r2517:f67017080a5a r0:d63b455452f6 r193:6aa65dc5a4b4 r193:6aa65dc5a4b4 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r193:6aa65dc5a4b4 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r193:6aa65dc5a4b4 r193:6aa65dc5a4b4 r0:d63b455452f6 r0:d63b455452f6 r497:beb1bd29f06e r2148:f279899fdbd0 r193:6aa65dc5a4b4 r193:6aa65dc5a4b4 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r384:75b26a2a614a r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1901:e806afa50723 r0:d63b455452f6 r384:75b26a2a614a r384:75b26a2a614a r0:d63b455452f6 r384:75b26a2a614a r2026:25935f6b221a r0:d63b455452f6 r2148:f279899fdbd0 r0:d63b455452f6 r497:beb1bd29f06e r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2537:eb2232d81b9c r0:d63b455452f6 r2537:eb2232d81b9c r0:d63b455452f6 r0:d63b455452f6 r2436:963efe8b84cc r39:c8e54423ac24 r39:c8e54423ac24 r39:c8e54423ac24 r39:c8e54423ac24 r1977:1f8b99c96041 r0:d63b455452f6 r2049:7e26d55f0f4c r193:6aa65dc5a4b4 r147:612ed080a7f6 r1796:4bbf4ea0805e r0:d63b455452f6 r193:6aa65dc5a4b4 r0:d63b455452f6 r2026:25935f6b221a r0:d63b455452f6 r0:d63b455452f6 r149:2fc05d1c9173 r149:2fc05d1c9173 r149:2fc05d1c9173 r193:6aa65dc5a4b4 r193:6aa65dc5a4b4 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r2049:7e26d55f0f4c r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r473:f7d76ddceb3a r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r473:f7d76ddceb3a r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r193:6aa65dc5a4b4 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r2049:7e26d55f0f4c r0:d63b455452f6 r0:d63b455452f6 r1901:e806afa50723 r0:d63b455452f6 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r2049:7e26d55f0f4c r2150:8d17c2dcd791 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2150:8d17c2dcd791 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2150:8d17c2dcd791 r2150:8d17c2dcd791 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2150:8d17c2dcd791 r2150:8d17c2dcd791 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r2049:7e26d55f0f4c r1901:e806afa50723 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r909:898755bd4512 r909:898755bd4512 r909:898755bd4512 r909:898755bd4512 r909:898755bd4512 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r1981:addba4bccc89 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2049:7e26d55f0f4c r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1093:18f56ef2d029 r0:d63b455452f6 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r0:d63b455452f6 r1335:da4955366538 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1202:95cf4c0fd209 r1202:95cf4c0fd209 r0:d63b455452f6 r2051:04d7c352ccc4 r1035:d35ec5ea5f73 r0:d63b455452f6 r0:d63b455452f6 r1059:bbcabb62c19c r2049:7e26d55f0f4c r1902:cfc758cf1057 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r193:6aa65dc5a4b4 r0:d63b455452f6 r1202:95cf4c0fd209 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r856:e23ff9905ff0 r193:6aa65dc5a4b4 r1981:addba4bccc89 r1981:addba4bccc89 r1981:addba4bccc89 r1981:addba4bccc89 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r909:898755bd4512 r1035:d35ec5ea5f73 r193:6aa65dc5a4b4 r0:d63b455452f6 r0:d63b455452f6 r1059:bbcabb62c19c r2049:7e26d55f0f4c r1902:cfc758cf1057 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2436:963efe8b84cc r0:d63b455452f6 r1901:e806afa50723 r193:6aa65dc5a4b4 r2502:2c4fc1650942 r1902:cfc758cf1057 r2026:25935f6b221a r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r1493:462e510ee912 r0:d63b455452f6 | /* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "table/strings.h"
#include "table/sprites.h"
#include "functions.h"
#include "map.h"
#include "tile.h"
#include "command.h"
#include "viewport.h"
#include "player.h"
#include "gui.h"
#include "station.h"
#include "economy.h"
#include "town.h"
#include "sprite.h"
#include "variables.h"
/** Destroy a HQ.
* During normal gameplay you can only implicitely destroy a HQ when you are
* rebuilding it. Otherwise, only water can destroy it.
* @param tile tile coordinates where HQ is located to destroy
* @param flags docommand flags of calling function
*/
int32 DestroyCompanyHQ(TileIndex tile, uint32 flags)
{
Player *p;
SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
/* Find player that has HQ flooded, and reset their location_of_house */
if (_current_player == OWNER_WATER) {
bool dodelete = false;
FOR_ALL_PLAYERS(p) {
if (p->location_of_house == tile) {
dodelete = true;
break;
}
}
if (!dodelete) return CMD_ERROR;
} else /* Destruction was initiated by player */
p = GetPlayer(_current_player);
if (p->location_of_house == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
DoClearSquare(p->location_of_house + TileDiffXY(0, 0));
DoClearSquare(p->location_of_house + TileDiffXY(0, 1));
DoClearSquare(p->location_of_house + TileDiffXY(1, 0));
DoClearSquare(p->location_of_house + TileDiffXY(1, 1));
p->location_of_house = 0; // reset HQ position
InvalidateWindow(WC_COMPANY, (int)p->index);
}
// cost of relocating company is 1% of company value
return CalculateCompanyValue(p) / 100;
}
/** Build or relocate the HQ. This depends if the HQ is already built or not
* @param x,y the coordinates where the HQ will be built or relocated to
* @param p1 unused
* @param p2 unused
*/
extern int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, int *);
int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
TileIndex tile = TileVirtXY(x, y);
Player *p = GetPlayer(_current_player);
int cost;
SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
if (CmdFailed(cost)) return CMD_ERROR;
if (p->location_of_house != 0) { /* Moving HQ */
int32 ret = DestroyCompanyHQ(p->location_of_house, flags);
if (CmdFailed(ret)) return CMD_ERROR;
cost += ret;
}
if (flags & DC_EXEC) {
int score = UpdateCompanyRatingAndValue(p, false);
p->location_of_house = tile;
ModifyTile(tile + TileDiffXY(0, 0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x80);
ModifyTile(tile + TileDiffXY(0, 1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x81);
ModifyTile(tile + TileDiffXY(1, 0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x82);
ModifyTile(tile + TileDiffXY(1, 1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x83);
UpdatePlayerHouse(p, score);
InvalidateWindow(WC_COMPANY, (int)p->index);
}
return cost;
}
typedef struct DrawTileUnmovableStruct {
uint16 image;
byte subcoord_x;
byte subcoord_y;
byte width;
byte height;
byte z_size;
byte unused;
} DrawTileUnmovableStruct;
#include "table/unmovable_land.h"
static void DrawTile_Unmovable(TileInfo *ti)
{
uint32 image, ormod;
if (!(ti->map5 & 0x80)) {
if (ti->map5 == 2) {
// statue
DrawGroundSprite(SPR_STATUE_GROUND);
image = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
image += PALETTE_MODIFIER_COLOR | SPR_STATUE_COMPANY;
if (_display_opt & DO_TRANS_BUILDINGS)
MAKE_TRANSPARENT(image);
AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 25, ti->z);
} else if (ti->map5 == 3) {
// "owned by" sign
DrawClearLandTile(ti, 0);
AddSortableSpriteToDraw(
PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)) + PALETTE_MODIFIER_COLOR + SPR_BOUGHT_LAND,
ti->x+8, ti->y+8,
1, 1,
10,
GetSlopeZ(ti->x+8, ti->y+8)
);
} else {
// lighthouse or transmitter
const DrawTileUnmovableStruct *dtus;
if (ti->tileh) DrawFoundation(ti, ti->tileh);
DrawClearLandTile(ti, 2);
dtus = &_draw_tile_unmovable_data[ti->map5];
image = dtus->image;
if (_display_opt & DO_TRANS_BUILDINGS)
MAKE_TRANSPARENT(image);
AddSortableSpriteToDraw(image,
ti->x | dtus->subcoord_x,
ti->y | dtus->subcoord_y,
dtus->width, dtus->height,
dtus->z_size, ti->z);
}
} else {
const DrawTileSeqStruct *dtss;
const DrawTileSprites *t;
if (ti->tileh) DrawFoundation(ti, ti->tileh);
ormod = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
t = &_unmovable_display_datas[ti->map5 & 0x7F];
DrawGroundSprite(t->ground_sprite | ormod);
foreach_draw_tile_seq(dtss, t->seq) {
image = dtss->image;
if (_display_opt & DO_TRANS_BUILDINGS) {
MAKE_TRANSPARENT(image);
} else {
image |= ormod;
}
AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y,
dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z);
}
}
}
static uint GetSlopeZ_Unmovable(const TileInfo* ti)
{
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z;
}
static uint GetSlopeTileh_Unmovable(const TileInfo *ti)
{
return 0;
}
static int32 ClearTile_Unmovable(TileIndex tile, byte flags)
{
byte m5 = _m[tile].m5;
if (m5 & 0x80) {
if (_current_player == OWNER_WATER) return DestroyCompanyHQ(tile, DC_EXEC);
return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
}
if (m5 == 3) // company owned land
return DoCommandByTile(tile, 0, 0, flags, CMD_SELL_LAND_AREA);
// checks if you're allowed to remove unmovable things
if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) )
return_cmd_error(STR_5800_OBJECT_IN_THE_WAY);
if (flags & DC_EXEC) {
DoClearSquare(tile);
}
return 0;
}
static void GetAcceptedCargo_Unmovable(TileIndex tile, AcceptedCargo ac)
{
byte m5 = _m[tile].m5;
uint level; // HQ level (depends on company performance) in the range 1..5.
if (!(m5 & 0x80)) {
/* not used */
return;
}
/* HQ accepts passenger and mail; but we have to divide the values
* between 4 tiles it occupies! */
level = (m5 & ~0x80) / 4 + 1;
// Top town building generates 10, so to make HQ interesting, the top
// type makes 20.
ac[CT_PASSENGERS] = max(1, level);
// Top town building generates 4, HQ can make up to 8. The
// proportion passengers:mail is different because such a huge
// commercial building generates unusually high amount of mail
// correspondence per physical visitor.
ac[CT_MAIL] = max(1, level / 2);
}
static const StringID _unmovable_tile_str[] = {
STR_5803_COMPANY_HEADQUARTERS,
STR_5801_TRANSMITTER,
STR_5802_LIGHTHOUSE,
STR_2016_STATUE,
STR_5805_COMPANY_OWNED_LAND,
};
static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td)
{
int i = _m[tile].m5;
if (i & 0x80) i = -1;
td->str = _unmovable_tile_str[i + 1];
td->owner = GetTileOwner(tile);
}
static void AnimateTile_Unmovable(TileIndex tile)
{
/* not used */
}
static void TileLoop_Unmovable(TileIndex tile)
{
byte m5 = _m[tile].m5;
uint level; // HQ level (depends on company performance) in the range 1..5.
uint32 r;
if (!(m5 & 0x80)) {
/* not used */
return;
}
/* HQ accepts passenger and mail; but we have to divide the values
* between 4 tiles it occupies! */
level = GB(m5, 0, 7) / 4 + 1;
assert(level < 6);
r = Random();
// Top town buildings generate 250, so the top HQ type makes 256.
if (GB(r, 0, 8) < (256 / 4 / (6 - level))) {
uint amt = GB(r, 0, 8) / 8 / 4 + 1;
if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt);
}
// Top town building generates 90, HQ can make up to 196. The
// proportion passengers:mail is about the same as in the acceptance
// equations.
if (GB(r, 8, 8) < (196 / 4 / (6 - level))) {
uint amt = GB(r, 8, 8) / 8 / 4 + 1;
if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt);
}
}
static uint32 GetTileTrackStatus_Unmovable(TileIndex tile, TransportType mode)
{
return 0;
}
static void ClickTile_Unmovable(TileIndex tile)
{
if (_m[tile].m5 & 0x80) {
ShowPlayerCompany(GetTileOwner(tile));
}
}
static const TileIndexDiffC _tile_add[] = {
{ 1, 0},
{ 0, 1},
{-1, 0},
{ 0, -1}
};
/* checks, if a radio tower is within a 9x9 tile square around tile */
static bool checkRadioTowerNearby(TileIndex tile)
{
TileIndex tile_s = tile - TileDiffXY(4, 4);
BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
// already a radio tower here?
if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 0)
return false;
END_TILE_LOOP(tile, 9, 9, tile_s)
return true;
}
void GenerateUnmovables(void)
{
int i,j;
TileIndex tile;
uint32 r;
int dir;
uint h;
if (_opt.landscape == LT_CANDY)
return;
/* add radio tower */
i = ScaleByMapSize(1000);
j = ScaleByMapSize(40); // maximum number of radio towers on the map
do {
tile = RandomTile();
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
if(!checkRadioTowerNearby(tile))
continue;
SetTileType(tile, MP_UNMOVABLE);
_m[tile].m5 = 0;
SetTileOwner(tile, OWNER_NONE);
if (--j == 0)
break;
}
} while (--i);
if (_opt.landscape == LT_DESERT)
return;
/* add lighthouses */
i = ScaleByMapSize1D((Random() & 3) + 7);
do {
restart:
r = Random();
dir = r >> 30;
r %= (dir == 0 || dir == 2) ? MapMaxY() : MapMaxX();
tile =
(dir == 0) ? TileXY(0, r) : 0 + // left
(dir == 1) ? TileXY(r, 0) : 0 + // top
(dir == 2) ? TileXY(MapMaxX(), r) : 0 + // right
(dir == 3) ? TileXY(r, MapMaxY()) : 0; // bottom
j = 20;
do {
if (--j == 0)
goto restart;
tile = TILE_MASK(tile + ToTileIndexDiff(_tile_add[dir]));
} while (!(IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h <= 16));
assert(tile == TILE_MASK(tile));
SetTileType(tile, MP_UNMOVABLE);
_m[tile].m5 = 1;
SetTileOwner(tile, OWNER_NONE);
} while (--i);
}
static void ChangeTileOwner_Unmovable(TileIndex tile, PlayerID old_player, PlayerID new_player)
{
if (!IsTileOwner(tile, old_player)) return;
if (_m[tile].m5 == 3 && new_player != OWNER_SPECTATOR) {
SetTileOwner(tile, new_player);
} else {
DoClearSquare(tile);
}
}
const TileTypeProcs _tile_type_unmovable_procs = {
DrawTile_Unmovable, /* draw_tile_proc */
GetSlopeZ_Unmovable, /* get_slope_z_proc */
ClearTile_Unmovable, /* clear_tile_proc */
GetAcceptedCargo_Unmovable, /* get_accepted_cargo_proc */
GetTileDesc_Unmovable, /* get_tile_desc_proc */
GetTileTrackStatus_Unmovable, /* get_tile_track_status_proc */
ClickTile_Unmovable, /* click_tile_proc */
AnimateTile_Unmovable, /* animate_tile_proc */
TileLoop_Unmovable, /* tile_loop_clear */
ChangeTileOwner_Unmovable, /* change_tile_owner_clear */
NULL, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
GetSlopeTileh_Unmovable, /* get_slope_tileh_proc */
};
|