src/unmovable_cmd.cpp
author truelight
Wed, 20 Jun 2007 12:09:47 +0000
changeset 6979 c4abd9b85a7a
parent 6953 230d1e3ac86c
child 7202 dc312a87f450
permissions -rw-r--r--
(svn r10235) -Fix: the 32bpp-anim blitter repainted pixel color 0, which is transparency and therefor should never be repainted (spotted by Rubidium)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
     3
/** @file unmovable_cmd.cpp */
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1796
diff changeset
     6
#include "openttd.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     7
#include "table/strings.h"
2148
542ea702738c (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2051
diff changeset
     8
#include "table/sprites.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     9
#include "functions.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6427
diff changeset
    10
#include "landscape.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
    11
#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
    12
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#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
    17
#include "station.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "economy.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "town.h"
405
415546028e8d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 384
diff changeset
    20
#include "sprite.h"
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
    21
#include "unmovable_map.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    22
#include "variables.h"
3654
c09872510a61 (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
    23
#include "table/unmovable_land.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    24
#include "genworld.h"
6160
fa42299e967e (svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents: 5668
diff changeset
    25
#include "bridge.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    27
/** Destroy a HQ.
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    28
 * During normal gameplay you can only implicitely destroy a HQ when you are
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    29
 * rebuilding it. Otherwise, only water can destroy it.
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
    30
 * @param pid Player requesting the destruction of his HQ
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    31
 * @param flags docommand flags of calling function
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
    32
 * @return cost of the operation
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    33
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6720
diff changeset
    34
static CommandCost DestroyCompanyHQ(PlayerID pid, uint32 flags)
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    35
{
4060
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    36
	Player* p = GetPlayer(pid);
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    37
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    38
	SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    39
4060
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    40
	if (flags & DC_EXEC) {
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    41
		TileIndex t = p->location_of_house;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    42
4060
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    43
		DoClearSquare(t + TileDiffXY(0, 0));
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    44
		DoClearSquare(t + TileDiffXY(0, 1));
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    45
		DoClearSquare(t + TileDiffXY(1, 0));
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    46
		DoClearSquare(t + TileDiffXY(1, 1));
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    47
		p->location_of_house = 0; // reset HQ position
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    48
		InvalidateWindow(WC_COMPANY, pid);
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
    49
	}
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    50
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
    51
	/* cost of relocating company is 1% of company value */
6953
230d1e3ac86c (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents: 6950
diff changeset
    52
	return CommandCost(CalculateCompanyValue(p) / 100);
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    53
}
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    54
3386
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    55
void UpdateCompanyHQ(Player *p, uint score)
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    56
{
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    57
	byte val;
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    58
	TileIndex tile = p->location_of_house;
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    59
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
    60
	if (tile == 0) return;
3386
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    61
3388
e94795a55f13 (svn r4196) -Codechange: Add and make use of an accessor that modifies the size of the Company HQ
celestar
parents: 3386
diff changeset
    62
	(val = 0, score < 170) ||
e94795a55f13 (svn r4196) -Codechange: Add and make use of an accessor that modifies the size of the Company HQ
celestar
parents: 3386
diff changeset
    63
	(val++, score < 350) ||
e94795a55f13 (svn r4196) -Codechange: Add and make use of an accessor that modifies the size of the Company HQ
celestar
parents: 3386
diff changeset
    64
	(val++, score < 520) ||
e94795a55f13 (svn r4196) -Codechange: Add and make use of an accessor that modifies the size of the Company HQ
celestar
parents: 3386
diff changeset
    65
	(val++, score < 720) ||
e94795a55f13 (svn r4196) -Codechange: Add and make use of an accessor that modifies the size of the Company HQ
celestar
parents: 3386
diff changeset
    66
	(val++, true);
3386
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    67
3388
e94795a55f13 (svn r4196) -Codechange: Add and make use of an accessor that modifies the size of the Company HQ
celestar
parents: 3386
diff changeset
    68
	EnlargeCompanyHQ(tile, val);
3386
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    69
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    70
	MarkTileDirtyByTile(tile + TileDiffXY(0, 0));
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    71
	MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    72
	MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    73
	MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    74
}
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
    75
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6720
diff changeset
    76
extern CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station, bool check_clear = true);
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
    77
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    78
/** Build or relocate the HQ. This depends if the HQ is already built or not
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: 3427
diff changeset
    79
 * @param tile tile where the HQ will be built or relocated to
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
    80
 * @param flags type of operation
2473
37fb41e00282 (svn r2999) Do not pass if the HQ gets built for the first time or gets relocated as parameter - the command function has to check this anyway
tron
parents: 2436
diff changeset
    81
 * @param p1 unused
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    82
 * @param p2 unused
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    83
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6720
diff changeset
    84
CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    85
{
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1902
diff changeset
    86
	Player *p = GetPlayer(_current_player);
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6720
diff changeset
    87
	CommandCost cost;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    88
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    89
	SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    90
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
    91
	cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
    92
	if (CmdFailed(cost)) return cost;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    93
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
    94
	if (p->location_of_house != 0) { // Moving HQ
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
    95
		cost.AddCost(DestroyCompanyHQ(_current_player, flags));
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    96
	}
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    97
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    98
	if (flags & DC_EXEC) {
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
    99
		int score = UpdateCompanyRatingAndValue(p, false);
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
   100
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
   101
		p->location_of_house = tile;
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
   102
3385
18e4ca6d3ef4 (svn r4193) -Codechange: Add and make use of an accessor function to create company HQs
celestar
parents: 3310
diff changeset
   103
		MakeCompanyHQ(tile, _current_player);
18e4ca6d3ef4 (svn r4193) -Codechange: Add and make use of an accessor function to create company HQs
celestar
parents: 3310
diff changeset
   104
3386
6d088afdabf4 (svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents: 3385
diff changeset
   105
		UpdateCompanyHQ(p, score);
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: 2951
diff changeset
   106
		InvalidateWindow(WC_COMPANY, p->index);
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
   107
	}
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
   108
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
   109
	return cost;
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
   110
}
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1792
diff changeset
   111
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
static void DrawTile_Unmovable(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   114
	SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   115
	SpriteID pal;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   116
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   117
	switch (GetUnmovableType(ti->tile)) {
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   118
		case UNMOVABLE_TRANSMITTER:
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   119
		case UNMOVABLE_LIGHTHOUSE: {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   120
			const DrawTileUnmovableStruct* dtus;
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   121
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   122
			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   123
			DrawClearLandTile(ti, 2);
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   124
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   125
			dtus = &_draw_tile_unmovable_data[GetUnmovableType(ti->tile)];
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   126
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   127
			image = dtus->image;
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6423
diff changeset
   128
			if (HASBIT(_transparent_opt, TO_STRUCTURES)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   129
				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   130
				pal = PALETTE_TO_TRANSPARENT;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   131
			} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   132
				pal = PAL_NONE;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   133
			}
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   134
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   135
			AddSortableSpriteToDraw(
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   136
				image, pal, ti->x | dtus->subcoord_x, ti->y | dtus->subcoord_y,
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   137
				dtus->width, dtus->height, dtus->z_size, ti->z
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   138
			);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   139
			break;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   140
		}
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   141
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   142
		case UNMOVABLE_STATUE:
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   143
			DrawGroundSprite(SPR_CONCRETE_GROUND, PAL_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   145
			image = SPR_STATUE_COMPANY;
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6423
diff changeset
   146
			if (HASBIT(_transparent_opt, TO_STRUCTURES)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   147
				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   148
				pal = PALETTE_TO_TRANSPARENT;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   149
			} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   150
				pal = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   151
			}
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   152
			AddSortableSpriteToDraw(image, pal, ti->x, ti->y, 16, 16, 25, ti->z);
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   153
			break;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   154
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   155
		case UNMOVABLE_OWNED_LAND:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
			DrawClearLandTile(ti, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   157
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   158
			image = SPR_BOUGHT_LAND;
6258
631f838368f5 (svn r9067) -Fix [FS#637]: don't make owner signs transparent, as then you loose the information who it owns
truelight
parents: 6257
diff changeset
   159
			pal = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
			AddSortableSpriteToDraw(
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   161
				image, pal,
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   162
				ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 10, GetSlopeZ(ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
			);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4848
diff changeset
   164
			DrawBridgeMiddle(ti);
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   165
			break;
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   166
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   167
		default: {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   168
			const DrawTileSeqStruct* dtss;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   169
			const DrawTileSprites* t;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   170
			SpriteID palette;
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   171
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   172
			assert(IsCompanyHQ(ti->tile));
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   173
			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   174
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   175
			palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   176
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   177
			t = &_unmovable_display_datas[GetCompanyHQSection(ti->tile)];
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   178
			DrawGroundSprite(t->ground_sprite, palette);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   179
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   180
			foreach_draw_tile_seq(dtss, t->seq) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   181
				image = dtss->image;
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6423
diff changeset
   182
				if (HASBIT(_transparent_opt, TO_STRUCTURES)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   183
					SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   184
					pal = PALETTE_TO_TRANSPARENT;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   185
				} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   186
					pal = palette;
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   187
				}
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   188
				AddSortableSpriteToDraw(
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   189
					image, pal,
4230
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4083
diff changeset
   190
					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4083
diff changeset
   191
					dtss->size_x, dtss->size_y,
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4083
diff changeset
   192
					dtss->size_z, ti->z + dtss->delta_z
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   193
				);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   194
			}
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   195
			break;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4060
diff changeset
   196
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
   200
static uint GetSlopeZ_Unmovable(TileIndex tile, uint x, uint y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
   202
	if (IsOwnedLand(tile)) {
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
   203
		uint z;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   204
		Slope tileh = GetTileSlope(tile, &z);
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
   205
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
   206
		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
3282
d026008a8f7c (svn r3996) -Fix: Slope and height information returned for some tile types is wrong
tron
parents: 3183
diff changeset
   207
	} else {
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
   208
		return GetTileMaxZ(tile);
3282
d026008a8f7c (svn r3996) -Fix: Slope and height information returned for some tile types is wrong
tron
parents: 3183
diff changeset
   209
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   212
static Slope GetSlopeTileh_Unmovable(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   213
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   214
	return IsOwnedLand(tile) ? tileh : SLOPE_FLAT;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   215
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   216
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6720
diff changeset
   217
static CommandCost ClearTile_Unmovable(TileIndex tile, byte flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
{
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   219
	if (IsCompanyHQ(tile)) {
4060
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
   220
		if (_current_player == OWNER_WATER) {
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
   221
			return DestroyCompanyHQ(GetTileOwner(tile), DC_EXEC);
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
   222
		} else {
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
   223
			return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
376824550cef (svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
tron
parents: 3657
diff changeset
   224
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   225
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   227
	if (IsOwnedLand(tile)) {
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: 3427
diff changeset
   228
		return DoCommand(tile, 0, 0, flags, CMD_SELL_LAND_AREA);
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   229
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   231
	/* checks if you're allowed to remove unmovable things */
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 147
diff changeset
   232
	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
   233
		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
   234
6257
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
   235
	if (IsStatue(tile)) {
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
   236
		TownID town = GetStatueTownID(tile);
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
   237
		CLRBIT(GetTown(town)->statues, _current_player);
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
   238
		InvalidateWindow(WC_TOWN_AUTHORITY, town);
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
   239
	}
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
   240
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   241
	if (flags & DC_EXEC) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
		DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   245
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   248
static void GetAcceptedCargo_Unmovable(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	uint level; // HQ level (depends on company performance) in the range 1..5.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   252
	if (!IsCompanyHQ(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	/* HQ accepts passenger and mail; but we have to divide the values
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	 * between 4 tiles it occupies! */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   257
	level = GetCompanyHQSize(tile) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   259
	/* Top town building generates 10, so to make HQ interesting, the top
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   260
	 * type makes 20. */
5601
d58f82901b2f (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5587
diff changeset
   261
	ac[CT_PASSENGERS] = max(1U, level);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   263
	/* Top town building generates 4, HQ can make up to 8. The
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   264
	 * proportion passengers:mail is different because such a huge
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   265
	 * commercial building generates unusually high amount of mail
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   266
	 * correspondence per physical visitor. */
5601
d58f82901b2f (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5587
diff changeset
   267
	ac[CT_MAIL] = max(1U, level / 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   271
static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
{
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   273
	switch (GetUnmovableType(tile)) {
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   274
		case UNMOVABLE_TRANSMITTER: td->str = STR_5801_TRANSMITTER; break;
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   275
		case UNMOVABLE_LIGHTHOUSE:  td->str = STR_5802_LIGHTHOUSE; break;
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   276
		case UNMOVABLE_STATUE:      td->str = STR_2016_STATUE; break;
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   277
		case UNMOVABLE_OWNED_LAND:  td->str = STR_5805_COMPANY_OWNED_LAND; break;
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   278
		default:                    td->str = STR_5803_COMPANY_HEADQUARTERS; break;
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   279
	}
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   280
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   283
static void AnimateTile_Unmovable(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   288
static void TileLoop_Unmovable(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
{
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   290
	uint level; // HQ level (depends on company performance) in the range 1..5.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   293
	if (!IsCompanyHQ(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	/* HQ accepts passenger and mail; but we have to divide the values
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	 * between 4 tiles it occupies! */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   298
	level = GetCompanyHQSize(tile) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	assert(level < 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	r = Random();
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   302
	/* Top town buildings generate 250, so the top HQ type makes 256. */
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   303
	if (GB(r, 0, 8) < (256 / 4 / (6 - level))) {
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   304
		uint amt = GB(r, 0, 8) / 8 / 4 + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
		if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
		MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   309
	/* Top town building generates 90, HQ can make up to 196. The
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   310
	 * proportion passengers:mail is about the same as in the acceptance
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6357
diff changeset
   311
	 * equations. */
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   312
	if (GB(r, 8, 8) < (196 / 4 / (6 - level))) {
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   313
		uint amt = GB(r, 8, 8) / 8 / 4 + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
		if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
		MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6484
diff changeset
   320
static uint32 GetTileTrackStatus_Unmovable(TileIndex tile, TransportType mode, uint sub_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   325
static void ClickTile_Unmovable(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
{
3427
3a512f7b7f6a (svn r4255) -Codechange: Add and make use of more accessor functions concerning unmovables. unmovable_cmd is now map access free
celestar
parents: 3422
diff changeset
   327
	if (IsCompanyHQ(tile)) ShowPlayerCompany(GetTileOwner(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
/* checks, if a radio tower is within a 9x9 tile square around tile */
4083
09ca2e8a41ea (svn r5398) Rename checkRadioTowerNearby() to IsRadioTowerNearby() and flip its return value to make it a bit less ambiguous
tron
parents: 4077
diff changeset
   332
static bool IsRadioTowerNearby(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
{
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   334
	TileIndex tile_s = tile - TileDiffXY(4, 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
4083
09ca2e8a41ea (svn r5398) Rename checkRadioTowerNearby() to IsRadioTowerNearby() and flip its return value to make it a bit less ambiguous
tron
parents: 4077
diff changeset
   337
		if (IsTransmitterTile(tile)) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	END_TILE_LOOP(tile, 9, 9, tile_s)
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   339
4083
09ca2e8a41ea (svn r5398) Rename checkRadioTowerNearby() to IsRadioTowerNearby() and flip its return value to make it a bit less ambiguous
tron
parents: 4077
diff changeset
   340
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6160
diff changeset
   343
void GenerateUnmovables()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
{
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   345
	int i, li, j, loop_count;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   346
	TileIndex tile;
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1225
diff changeset
   347
	uint h;
3164
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   348
	uint maxx;
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   349
	uint maxy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6258
diff changeset
   351
	if (_opt.landscape == LT_TOYLAND) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
	/* add radio tower */
1202
4d2a20c50760 (svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents: 1093
diff changeset
   354
	i = ScaleByMapSize(1000);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   355
	j = ScaleByMapSize(15); // maximum number of radio towers on the map
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   356
	li = ScaleByMapSize1D((Random() & 3) + 7);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   357
	SetGeneratingWorldProgress(GWP_UNMOVABLE, j + li);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   358
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
	do {
2051
e369160ce2f3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   360
		tile = RandomTile();
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   361
		if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h >= TILE_HEIGHT * 4) {
4083
09ca2e8a41ea (svn r5398) Rename checkRadioTowerNearby() to IsRadioTowerNearby() and flip its return value to make it a bit less ambiguous
tron
parents: 4077
diff changeset
   362
			if (IsRadioTowerNearby(tile)) continue;
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   363
			MakeTransmitter(tile);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   364
			IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2893
diff changeset
   365
			if (--j == 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6258
diff changeset
   369
	if (_opt.landscape == LT_TROPIC) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   370
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	/* add lighthouses */
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   372
	i = li;
3164
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   373
	maxx = MapMaxX();
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   374
	maxy = MapMaxY();
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   375
	loop_count = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	do {
3164
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   377
		uint32 r;
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   378
		DiagDirection dir;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   379
		int perimeter;
3164
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   380
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
restart:
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   382
		/* Avoid infinite loops */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   383
		if (++loop_count > 1000) break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   384
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
		r = Random();
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   386
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   387
		/* Scatter the lighthouses more evenly around the perimeter */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   388
		perimeter = (GB(r, 16, 16) % (2 * (maxx + maxy))) - maxy;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   389
		for (dir = DIAGDIR_NE; perimeter > 0; dir++) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   390
			perimeter -= (DiagDirToAxis(dir) == AXIS_X) ? maxx : maxy;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   391
		}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   392
3164
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   393
		switch (dir) {
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   394
			default:
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   395
			case DIAGDIR_NE: tile = TileXY(maxx,     r % maxy); break;
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   396
			case DIAGDIR_SE: tile = TileXY(r % maxx, 0);        break;
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   397
			case DIAGDIR_SW: tile = TileXY(0,        r % maxy); break;
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   398
			case DIAGDIR_NW: tile = TileXY(r % maxx, maxy);     break;
3b7658159a12 (svn r3791) Replace home grown direction handling for placing lighthouses by standard DiagDir
tron
parents: 3017
diff changeset
   399
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
		j = 20;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
		do {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2893
diff changeset
   402
			if (--j == 0) goto restart;
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4300
diff changeset
   403
			tile = TILE_MASK(tile + TileOffsByDiagDir(dir));
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   404
		} while (!(IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h <= TILE_HEIGHT * 2));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   405
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
		assert(tile == TILE_MASK(tile));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
   408
		MakeLighthouse(tile);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   409
		IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2186
diff changeset
   413
static void ChangeTileOwner_Unmovable(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
{
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   415
	if (!IsTileOwner(tile, old_player)) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   416
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4559
diff changeset
   417
	if (IsOwnedLand(tile) && new_player != PLAYER_SPECTATOR) {
1902
86b7fb11f938 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
   418
		SetTileOwner(tile, new_player);
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 1981
diff changeset
   419
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
		DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   424
extern 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
   425
	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
   426
	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
   427
	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
   428
	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
   429
	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
   430
	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
   431
	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
   432
	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
   433
	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
   434
	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
   435
	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
   436
	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
   437
	GetSlopeTileh_Unmovable,        /* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
};