author | rubidium |
Sun, 02 Sep 2007 11:58:58 +0000 | |
branch | NewGRF_ports |
changeset 6868 | 7eb395287b3d |
parent 6743 | cabfaa4a0295 |
child 6870 | ca3fd1fbe311 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
3 |
/** @file clear_cmd.cpp */ |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1878
diff
changeset
|
6 |
#include "openttd.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
2989
diff
changeset
|
7 |
#include "clear_map.h" |
4041
caf4fcb4e05b
(svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents:
4031
diff
changeset
|
8 |
#include "rail_map.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
473
diff
changeset
|
9 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
10 |
#include "functions.h" |
679
e959706a3e4d
(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" |
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2153
diff
changeset
|
12 |
#include "player.h" |
1209
a1ac96655b79
(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
|
13 |
#include "tile.h" |
0 | 14 |
#include "viewport.h" |
15 |
#include "command.h" |
|
3156
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3144
diff
changeset
|
16 |
#include "tunnel_map.h" |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
4815
diff
changeset
|
17 |
#include "bridge_map.h" |
6486
4f8af35b11eb
(svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents:
6449
diff
changeset
|
18 |
#include "bridge.h" |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6574
diff
changeset
|
19 |
#include "landscape.h" |
2153
91e89aa8c299
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
20 |
#include "variables.h" |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
21 |
#include "table/sprites.h" |
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
22 |
#include "unmovable_map.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
23 |
#include "genworld.h" |
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
24 |
#include "industry.h" |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
25 |
#include "water_map.h" |
0 | 26 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
27 |
/* |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
28 |
* In one terraforming command all four corners of a initial tile can be raised/lowered (though this is not available to the player). |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
29 |
* The maximal amount of height modifications is archieved when raising a complete flat land from sea level to MAX_TILE_HEIGHT or vice versa. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
30 |
* This affects all corners with a manhatten distance smaller than MAX_TILE_HEIGHT to one of the initial 4 corners. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
31 |
* Their maximal amount is computed to 4 * \sum_{i=1}^{h_max} i = 2 * h_max * (h_max + 1). |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
32 |
*/ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
33 |
static const int TERRAFORMER_MODHEIGHT_SIZE = 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 1); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
34 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
35 |
/* |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
36 |
* The maximal amount of affected tiles (i.e. the tiles that incident with one of the corners above, is computed similiar to |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
37 |
* 1 + 4 * \sum_{i=1}^{h_max} (i+1) = 1 + 2 * h_max + (h_max + 3). |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
38 |
*/ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
39 |
static const int TERRAFORMER_TILE_TABLE_SIZE = 1 + 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 3); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
40 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
41 |
struct TerraformerHeightMod { |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
42 |
TileIndex tile; ///< Referenced tile. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
43 |
byte height; ///< New TileHeight (height of north corner) of the tile. |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
44 |
}; |
0 | 45 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
46 |
struct TerraformerState { |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
47 |
int modheight_count; ///< amount of entries in "modheight". |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
48 |
int tile_table_count; ///< amount of entries in "tile_table". |
0 | 49 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
50 |
TileIndex tile_table[TERRAFORMER_TILE_TABLE_SIZE]; ///< Dirty tiles, i.e. at least one corner changed. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
51 |
TerraformerHeightMod modheight[TERRAFORMER_MODHEIGHT_SIZE]; ///< Height modifications. |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
52 |
}; |
0 | 53 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
54 |
/** |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
55 |
* Gets the TileHeight (height of north corner) of a tile as of current terraforming progress. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
56 |
* |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
57 |
* @param ts TerraformerState. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
58 |
* @param tile Tile. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
59 |
* @return TileHeight. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
60 |
*/ |
0 | 61 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
62 |
{ |
|
63 |
TerraformerHeightMod *mod = ts->modheight; |
|
64 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
65 |
|
2639 | 66 |
for (count = ts->modheight_count; count != 0; count--, mod++) { |
67 |
if (mod->tile == tile) return mod->height; |
|
0 | 68 |
} |
69 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
70 |
/* TileHeight unchanged so far, read value from map. */ |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
71 |
return TileHeight(tile); |
0 | 72 |
} |
73 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
74 |
/** |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
75 |
* Stores the TileHeight (height of north corner) of a tile in a TerraformerState. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
76 |
* |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
77 |
* @param ts TerraformerState. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
78 |
* @param tile Tile. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
79 |
* @param height New TileHeight. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
80 |
*/ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
81 |
static void TerraformSetHeightOfTile(TerraformerState *ts, TileIndex tile, int height) |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
82 |
{ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
83 |
/* Find tile in the "modheight" table. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
84 |
* Note: In a normal user-terraform command the tile will not be found in the "modheight" table. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
85 |
* But during house- or industry-construction multiple corners can be terraformed at once. */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
86 |
TerraformerHeightMod *mod = ts->modheight; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
87 |
int count = ts->modheight_count; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
88 |
while ((count > 0) && (mod->tile != tile)) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
89 |
mod++; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
90 |
count--; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
91 |
} |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
92 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
93 |
/* New entry? */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
94 |
if (count == 0) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
95 |
assert(ts->modheight_count < TERRAFORMER_MODHEIGHT_SIZE); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
96 |
ts->modheight_count++; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
97 |
} |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
98 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
99 |
/* Finally store the new value */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
100 |
mod->tile = tile; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
101 |
mod->height = (byte)height; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
102 |
} |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
103 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
104 |
/** |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
105 |
* Adds a tile to the "tile_table" in a TerraformerState. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
106 |
* |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
107 |
* @param ts TerraformerState. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
108 |
* @param tile Tile. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
109 |
*/ |
0 | 110 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
111 |
{ |
|
112 |
int count; |
|
113 |
TileIndex *t; |
|
114 |
||
115 |
count = ts->tile_table_count; |
|
116 |
||
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6683
diff
changeset
|
117 |
for (t = ts->tile_table; count != 0; count--, t++) { |
2639 | 118 |
if (*t == tile) return; |
0 | 119 |
} |
120 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
121 |
assert(ts->tile_table_count < TERRAFORMER_TILE_TABLE_SIZE); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
122 |
|
0 | 123 |
ts->tile_table[ts->tile_table_count++] = tile; |
124 |
} |
|
125 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
126 |
/** |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
127 |
* Adds all tiles that incident with the north corner of a specific tile to the "tile_table" in a TerraformerState. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
128 |
* |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
129 |
* @param ts TerraformerState. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
130 |
* @param tile Tile. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
131 |
*/ |
0 | 132 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
133 |
{ |
|
1981 | 134 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
135 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
136 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 137 |
TerraformAddDirtyTile(ts, tile); |
138 |
} |
|
139 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
140 |
/** |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
141 |
* Terraform the north corner of a tile to a specific height. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
142 |
* |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
143 |
* @param ts TerraformerState. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
144 |
* @param tile Tile. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
145 |
* @param height Aimed height. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
146 |
* @param return Error code or cost. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
147 |
*/ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
148 |
static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 149 |
{ |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
150 |
CommandCost total_cost = CommandCost(); |
0 | 151 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
152 |
assert(tile < MapSize()); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
153 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
154 |
/* Check range of destination height */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
155 |
if (height < 0) return_cmd_error(STR_1003_ALREADY_AT_SEA_LEVEL); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
156 |
if (height > MAX_TILE_HEIGHT) return_cmd_error(STR_1004_TOO_HIGH); |
2686
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
157 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
158 |
/* |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
159 |
* Check if the terraforming has any effect. |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
160 |
* This can only be true, if multiple corners of the start-tile are terraformed (i.e. the terraforming is done by towns/industries etc.). |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
161 |
* In this case the terraforming should fail. (Don't know why.) |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
162 |
*/ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
163 |
if (height == TerraformGetHeightOfTile(ts, tile)) return CMD_ERROR; |
0 | 164 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
165 |
/* Check "too close to edge of map" */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
166 |
uint x = TileX(tile); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
167 |
uint y = TileY(tile); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
168 |
if ((x <= 1) || (y <= 1) || (x >= MapMaxX() - 1) || (y >= MapMaxY() - 1)) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
169 |
/* |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
170 |
* Determine a sensible error tile |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
171 |
* Note: If x and y are both zero this will disable the error tile. (Tile 0 cannot be highlighted :( ) |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
172 |
*/ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
173 |
if ((x == 1) && (y != 0)) x = 0; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
174 |
if ((y == 1) && (x != 0)) y = 0; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
175 |
_terraform_err_tile = TileXY(x, y); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
176 |
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); |
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
177 |
} |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
178 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
179 |
/* Mark incident tiles, that are involved in the terraforming */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
180 |
TerraformAddDirtyTileAround(ts, tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
181 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
182 |
/* Store the height modification */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
183 |
TerraformSetHeightOfTile(ts, tile, height); |
0 | 184 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
185 |
/* Increment cost */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
186 |
total_cost.AddCost(_price.terraform); |
0 | 187 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
188 |
/* Recurse to neighboured corners if height difference is larger than 1 */ |
0 | 189 |
{ |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
190 |
const TileIndexDiffC *ttm; |
0 | 191 |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
192 |
static const TileIndexDiffC _terraform_tilepos[] = { |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
193 |
{ 1, 0}, // move to tile in SE |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
194 |
{-2, 0}, // undo last move, and move to tile in NW |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
195 |
{ 1, 1}, // undo last move, and move to tile in SW |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
196 |
{ 0, -2} // undo last move, and move to tile in NE |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
197 |
}; |
0 | 198 |
|
2952 | 199 |
for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
200 |
tile += ToTileIndexDiff(*ttm); |
0 | 201 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
202 |
/* Get TileHeight of neighboured tile as of current terraform progress */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
203 |
int r = TerraformGetHeightOfTile(ts, tile); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
204 |
int height_diff = height - r; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
205 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
206 |
/* Is the height difference to the neighboured corner greater than 1? */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
207 |
if (abs(height_diff) > 1) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
208 |
/* Terraform the neighboured corner. The resulting height difference should be 1. */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
209 |
height_diff += (height_diff < 0 ? 1 : -1); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
210 |
CommandCost cost = TerraformTileHeight(ts, tile, r + height_diff); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
211 |
if (CmdFailed(cost)) return cost; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
212 |
total_cost.AddCost(cost); |
0 | 213 |
} |
214 |
} |
|
215 |
} |
|
216 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
217 |
return total_cost; |
0 | 218 |
} |
219 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
220 |
/** Terraform land |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
221 |
* @param tile tile to terraform |
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
222 |
* @param flags for this command type |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
223 |
* @param p1 corners to terraform (SLOPE_xxx) |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
224 |
* @param p2 direction; eg up (non-zero) or down (zero) |
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
225 |
* @return error or cost of terraforming |
0 | 226 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
227 |
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 228 |
{ |
229 |
TerraformerState ts; |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
230 |
CommandCost total_cost = CommandCost(); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
231 |
int direction = (p2 != 0 ? 1 : -1); |
0 | 232 |
|
233 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
234 |
||
235 |
_terraform_err_tile = 0; |
|
236 |
||
237 |
ts.modheight_count = ts.tile_table_count = 0; |
|
238 |
||
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
239 |
/* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2705
diff
changeset
|
240 |
if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR; |
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
241 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
242 |
/* Compute the costs and the terraforming result in a model of the landscape */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
243 |
if ((p1 & SLOPE_W) != 0) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
244 |
TileIndex t = tile + TileDiffXY(1, 0); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
245 |
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
246 |
if (CmdFailed(cost)) return cost; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
247 |
total_cost.AddCost(cost); |
0 | 248 |
} |
249 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
250 |
if ((p1 & SLOPE_S) != 0) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
251 |
TileIndex t = tile + TileDiffXY(1, 1); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
252 |
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
253 |
if (CmdFailed(cost)) return cost; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
254 |
total_cost.AddCost(cost); |
0 | 255 |
} |
256 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
257 |
if ((p1 & SLOPE_E) != 0) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
258 |
TileIndex t = tile + TileDiffXY(0, 1); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
259 |
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
260 |
if (CmdFailed(cost)) return cost; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
261 |
total_cost.AddCost(cost); |
0 | 262 |
} |
263 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
264 |
if ((p1 & SLOPE_N) != 0) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
265 |
TileIndex t = tile + TileDiffXY(0, 0); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
266 |
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
267 |
if (CmdFailed(cost)) return cost; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
268 |
total_cost.AddCost(cost); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
269 |
} |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
270 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
271 |
/* Check if the terraforming is valid wrt. tunnels, bridges and objects on the surface */ |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
4815
diff
changeset
|
272 |
{ |
0 | 273 |
int count; |
274 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
275 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
276 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
277 |
TileIndex tile = *ti; |
0 | 278 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
279 |
/* Find new heights of tile corners */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
280 |
uint z_N = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
281 |
uint z_W = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
282 |
uint z_S = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
283 |
uint z_E = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6683
diff
changeset
|
284 |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
285 |
/* Find min and max height of tile */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
286 |
uint z_min = min(min(z_N, z_W), min(z_S, z_E)); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
287 |
uint z_max = max(max(z_N, z_W), max(z_S, z_E)); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
288 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
289 |
/* Compute tile slope */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
290 |
uint tileh = (z_max > z_min + 1 ? SLOPE_STEEP : SLOPE_FLAT); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
291 |
if (z_W > z_min) tileh += SLOPE_W; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
292 |
if (z_S > z_min) tileh += SLOPE_S; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
293 |
if (z_E > z_min) tileh += SLOPE_E; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
294 |
if (z_N > z_min) tileh += SLOPE_N; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
295 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
296 |
/* Check if bridge would take damage */ |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6683
diff
changeset
|
297 |
if (direction == 1 && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6683
diff
changeset
|
298 |
GetBridgeHeight(GetSouthernBridgeEnd(tile)) <= z_max * TILE_HEIGHT) { |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
299 |
_terraform_err_tile = tile; // highlight the tile under the bridge |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
4815
diff
changeset
|
300 |
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
4815
diff
changeset
|
301 |
} |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
302 |
/* Check if tunnel would take damage */ |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6683
diff
changeset
|
303 |
if (direction == -1 && IsTunnelInWay(tile, z_min * TILE_HEIGHT)) { |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
304 |
_terraform_err_tile = tile; // highlight the tile above the tunnel |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6683
diff
changeset
|
305 |
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
2639 | 306 |
} |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
307 |
/* Check tiletype-specific things, and add extra-cost */ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
308 |
CommandCost cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, flags, z_min * TILE_HEIGHT, (Slope) tileh); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
309 |
if (CmdFailed(cost)) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
310 |
_terraform_err_tile = tile; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
311 |
return cost; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
312 |
} |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
313 |
total_cost.AddCost(cost); |
0 | 314 |
} |
315 |
} |
|
316 |
||
317 |
if (flags & DC_EXEC) { |
|
318 |
/* change the height */ |
|
319 |
{ |
|
320 |
int count; |
|
321 |
TerraformerHeightMod *mod; |
|
322 |
||
323 |
mod = ts.modheight; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
324 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
f4462d4e8e62
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
325 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
326 |
|
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
327 |
SetTileHeight(til, mod->height); |
0 | 328 |
} |
329 |
} |
|
330 |
||
331 |
/* finally mark the dirty tiles dirty */ |
|
332 |
{ |
|
333 |
int count; |
|
334 |
TileIndex *ti = ts.tile_table; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
335 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 336 |
MarkTileDirtyByTile(*ti); |
337 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
338 |
} |
0 | 339 |
} |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
340 |
return total_cost; |
0 | 341 |
} |
342 |
||
343 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
344 |
/** Levels a selected (rectangle) area of land |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
345 |
* @param tile end tile of area-drag |
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
346 |
* @param flags for this command type |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
347 |
* @param p1 start tile of area drag |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
348 |
* @param p2 unused |
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
349 |
* @return error or cost of terraforming |
0 | 350 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
351 |
CommandCost CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 352 |
{ |
353 |
int size_x, size_y; |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
354 |
int ex; |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
355 |
int ey; |
0 | 356 |
int sx, sy; |
357 |
uint h, curh; |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
358 |
CommandCost money; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
359 |
CommandCost ret; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
360 |
CommandCost cost; |
0 | 361 |
|
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2705
diff
changeset
|
362 |
if (p1 >= MapSize()) return CMD_ERROR; |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
363 |
|
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
364 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
365 |
|
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
366 |
/* remember level height */ |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
367 |
h = TileHeight(p1); |
0 | 368 |
|
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
369 |
/* make sure sx,sy are smaller than ex,ey */ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
370 |
ex = TileX(tile); |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
371 |
ey = TileY(tile); |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
372 |
sx = TileX(p1); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
373 |
sy = TileY(p1); |
6432 | 374 |
if (ex < sx) Swap(ex, sx); |
375 |
if (ey < sy) Swap(ey, sy); |
|
1981 | 376 |
tile = TileXY(sx, sy); |
0 | 377 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6683
diff
changeset
|
378 |
size_x = ex - sx + 1; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6683
diff
changeset
|
379 |
size_y = ey - sy + 1; |
0 | 380 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
381 |
money.AddCost(GetAvailableMoneyForCommand()); |
0 | 382 |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
383 |
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
384 |
curh = TileHeight(tile2); |
0 | 385 |
while (curh != h) { |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
386 |
ret = DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
387 |
if (CmdFailed(ret)) break; |
0 | 388 |
|
389 |
if (flags & DC_EXEC) { |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
390 |
money.AddCost(-ret.GetCost()); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
391 |
if (money.GetCost() < 0) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
392 |
_additional_cash_required = ret.GetCost(); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
393 |
return cost; |
0 | 394 |
} |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
395 |
DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 396 |
} |
397 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
398 |
cost.AddCost(ret); |
0 | 399 |
curh += (curh > h) ? -1 : 1; |
400 |
} |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
401 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 402 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
403 |
return (cost.GetCost() == 0) ? CMD_ERROR : cost; |
0 | 404 |
} |
405 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
406 |
/** Purchase a land area. Actually you only purchase one tile, so |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
407 |
* the name is a bit confusing ;p |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
408 |
* @param tile the tile the player is purchasing |
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
409 |
* @param flags for this command type |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
410 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
411 |
* @param p2 unused |
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
412 |
* @return error of cost of operation |
0 | 413 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
414 |
CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 415 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
416 |
CommandCost cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
417 |
|
0 | 418 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
419 |
|
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
420 |
if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) { |
0 | 421 |
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
422 |
} |
0 | 423 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
424 |
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
425 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 426 |
|
427 |
if (flags & DC_EXEC) { |
|
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
428 |
MakeOwnedLand(tile, _current_player); |
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
429 |
MarkTileDirtyByTile(tile); |
0 | 430 |
} |
431 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
432 |
return cost.AddCost(_price.purchase_land * 10); |
0 | 433 |
} |
434 |
||
435 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
436 |
static CommandCost ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 437 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
438 |
static const Money* clear_price_table[] = { |
2220 | 439 |
&_price.clear_1, |
440 |
&_price.purchase_land, |
|
441 |
&_price.clear_2, |
|
442 |
&_price.clear_3, |
|
443 |
&_price.purchase_land, |
|
444 |
&_price.purchase_land, |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
445 |
&_price.clear_2, // XXX unused? |
0 | 446 |
}; |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
447 |
CommandCost price; |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
448 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
449 |
if (!IsClearGround(tile, CLEAR_GRASS) || GetClearDensity(tile) != 0) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
450 |
price.AddCost(*clear_price_table[GetClearGround(tile)]); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
451 |
} |
0 | 452 |
|
2220 | 453 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 454 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
455 |
return price; |
0 | 456 |
} |
457 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
458 |
/** Sell a land area. Actually you only sell one tile, so |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
459 |
* the name is a bit confusing ;p |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
460 |
* @param tile the tile the player is selling |
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
461 |
* @param flags for this command type |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
462 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
463 |
* @param p2 unused |
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
464 |
* @return error or cost of operation |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
465 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
466 |
CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 467 |
{ |
468 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
469 |
||
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
470 |
if (!IsOwnedLandTile(tile)) return CMD_ERROR; |
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
471 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; |
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
472 |
|
0 | 473 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
474 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 475 |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
476 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 477 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
478 |
return CommandCost(- _price.purchase_land * 2); |
0 | 479 |
} |
480 |
||
481 |
||
482 |
#include "table/clear_land.h" |
|
483 |
||
484 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
485 |
void DrawClearLandTile(const TileInfo *ti, byte set) |
0 | 486 |
{ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
487 |
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19, PAL_NONE); |
0 | 488 |
} |
489 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
490 |
void DrawHillyLandTile(const TileInfo *ti) |
0 | 491 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
492 |
if (ti->tileh != SLOPE_FLAT) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
493 |
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh], PAL_NONE); |
0 | 494 |
} else { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
495 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)], PAL_NONE); |
0 | 496 |
} |
497 |
} |
|
498 |
||
2220 | 499 |
void DrawClearLandFence(const TileInfo *ti) |
0 | 500 |
{ |
501 |
byte z = ti->z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
502 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
503 |
if (ti->tileh & SLOPE_S) { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
504 |
z += TILE_HEIGHT; |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
505 |
if (ti->tileh == SLOPE_STEEP_S) z += TILE_HEIGHT; |
0 | 506 |
} |
507 |
||
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
508 |
if (GetFenceSW(ti->tile) != 0) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
509 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSW(ti->tile) - 1] + _fence_mod_by_tileh[ti->tileh], PAL_NONE, ti->x, ti->y, z); |
0 | 510 |
} |
511 |
||
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
512 |
if (GetFenceSE(ti->tile) != 0) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
513 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSE(ti->tile) - 1] + _fence_mod_by_tileh_2[ti->tileh], PAL_NONE, ti->x, ti->y, z); |
0 | 514 |
} |
515 |
} |
|
516 |
||
517 |
static void DrawTile_Clear(TileInfo *ti) |
|
518 |
{ |
|
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
519 |
switch (GetClearGround(ti->tile)) { |
3447 | 520 |
case CLEAR_GRASS: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
521 |
DrawClearLandTile(ti, GetClearDensity(ti->tile)); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
522 |
break; |
0 | 523 |
|
3447 | 524 |
case CLEAR_ROUGH: |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
525 |
DrawHillyLandTile(ti); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
526 |
break; |
0 | 527 |
|
3447 | 528 |
case CLEAR_ROCKS: |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
529 |
DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh], PAL_NONE); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
530 |
break; |
0 | 531 |
|
3447 | 532 |
case CLEAR_FIELDS: |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
533 |
DrawGroundSprite(_clear_land_sprites_1[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
534 |
break; |
0 | 535 |
|
3447 | 536 |
case CLEAR_SNOW: |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
537 |
DrawGroundSprite(_clear_land_sprites_2[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
538 |
break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
539 |
|
3447 | 540 |
case CLEAR_DESERT: |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
541 |
DrawGroundSprite(_clear_land_sprites_3[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
542 |
break; |
0 | 543 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
544 |
|
2220 | 545 |
DrawClearLandFence(ti); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
4815
diff
changeset
|
546 |
DrawBridgeMiddle(ti); |
0 | 547 |
} |
548 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
549 |
static uint GetSlopeZ_Clear(TileIndex tile, uint x, uint y) |
1095 | 550 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
551 |
uint z; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
552 |
Slope tileh = GetTileSlope(tile, &z); |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
553 |
|
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
554 |
return z + GetPartialZ(x & 0xF, y & 0xF, tileh); |
1095 | 555 |
} |
0 | 556 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
557 |
static Foundation GetFoundation_Clear(TileIndex tile, Slope tileh) |
39 | 558 |
{ |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
559 |
return FOUNDATION_NONE; |
39 | 560 |
} |
561 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
562 |
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac) |
0 | 563 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
564 |
/* unused */ |
0 | 565 |
} |
566 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
567 |
static void AnimateTile_Clear(TileIndex tile) |
0 | 568 |
{ |
569 |
/* unused */ |
|
570 |
} |
|
571 |
||
1293 | 572 |
void TileLoopClearHelper(TileIndex tile) |
0 | 573 |
{ |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
574 |
byte self; |
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
575 |
byte neighbour; |
1293 | 576 |
TileIndex dirty = INVALID_TILE; |
0 | 577 |
|
3447 | 578 |
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)); |
0 | 579 |
|
3447 | 580 |
neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CLEAR_FIELDS)); |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
581 |
if (GetFenceSW(tile) == 0) { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
582 |
if (self != neighbour) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
583 |
SetFenceSW(tile, 3); |
0 | 584 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
585 |
} |
0 | 586 |
} else { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
587 |
if (self == 0 && neighbour == 0) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
588 |
SetFenceSW(tile, 0); |
0 | 589 |
dirty = tile; |
590 |
} |
|
591 |
} |
|
592 |
||
3447 | 593 |
neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CLEAR_FIELDS)); |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
594 |
if (GetFenceSE(tile) == 0) { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
595 |
if (self != neighbour) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
596 |
SetFenceSE(tile, 3); |
0 | 597 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
598 |
} |
0 | 599 |
} else { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
600 |
if (self == 0 && neighbour == 0) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
601 |
SetFenceSE(tile, 0); |
0 | 602 |
dirty = tile; |
603 |
} |
|
604 |
} |
|
605 |
||
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
606 |
if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty); |
0 | 607 |
} |
608 |
||
609 |
||
610 |
/* convert into snowy tiles */ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
611 |
static void TileLoopClearAlps(TileIndex tile) |
0 | 612 |
{ |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6574
diff
changeset
|
613 |
int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
614 |
|
4157
0c3210247472
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
4069
diff
changeset
|
615 |
if (k < 0) { // well below the snow line |
3447 | 616 |
if (!IsClearGround(tile, CLEAR_SNOW)) return; |
617 |
if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3); |
|
0 | 618 |
} else { |
3447 | 619 |
if (!IsClearGround(tile, CLEAR_SNOW)) { |
620 |
SetClearGroundDensity(tile, CLEAR_SNOW, 0); |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
621 |
} else { |
4157
0c3210247472
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
4069
diff
changeset
|
622 |
uint density = min((uint)k / TILE_HEIGHT, 3); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
623 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
624 |
if (GetClearDensity(tile) < density) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
625 |
AddClearDensity(tile, 1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
626 |
} else if (GetClearDensity(tile) > density) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
627 |
AddClearDensity(tile, -1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
628 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
629 |
return; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
630 |
} |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
631 |
} |
0 | 632 |
} |
633 |
||
634 |
MarkTileDirtyByTile(tile); |
|
635 |
} |
|
636 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
637 |
static void TileLoopClearDesert(TileIndex tile) |
0 | 638 |
{ |
3447 | 639 |
if (IsClearGround(tile, CLEAR_DESERT)) return; |
0 | 640 |
|
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
641 |
if (GetTropicZone(tile) == TROPICZONE_DESERT) { |
3447 | 642 |
SetClearGroundDensity(tile, CLEAR_DESERT, 3); |
0 | 643 |
} else { |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
644 |
if (GetTropicZone(tile + TileDiffXY( 1, 0)) != TROPICZONE_DESERT && |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
645 |
GetTropicZone(tile + TileDiffXY(-1, 0)) != TROPICZONE_DESERT && |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
646 |
GetTropicZone(tile + TileDiffXY( 0, 1)) != TROPICZONE_DESERT && |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
647 |
GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT) |
1981 | 648 |
return; |
3447 | 649 |
SetClearGroundDensity(tile, CLEAR_DESERT, 1); |
0 | 650 |
} |
651 |
||
652 |
MarkTileDirtyByTile(tile); |
|
653 |
} |
|
654 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
655 |
static void TileLoop_Clear(TileIndex tile) |
0 | 656 |
{ |
657 |
TileLoopClearHelper(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
658 |
|
2989 | 659 |
switch (_opt.landscape) { |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
660 |
case LT_TROPIC: TileLoopClearDesert(tile); break; |
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
661 |
case LT_ARCTIC: TileLoopClearAlps(tile); break; |
0 | 662 |
} |
663 |
||
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
664 |
switch (GetClearGround(tile)) { |
3447 | 665 |
case CLEAR_GRASS: |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
666 |
if (GetClearDensity(tile) == 3) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
667 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
668 |
if (_game_mode != GM_EDITOR) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
669 |
if (GetClearCounter(tile) < 7) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
670 |
AddClearCounter(tile, 1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
671 |
return; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
672 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
673 |
SetClearCounter(tile, 0); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
674 |
AddClearDensity(tile, 1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
675 |
} |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
676 |
} else { |
3447 | 677 |
SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CLEAR_GRASS : CLEAR_ROUGH, 3); |
0 | 678 |
} |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
679 |
break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
680 |
|
3447 | 681 |
case CLEAR_FIELDS: { |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
682 |
uint field_type; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
683 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
684 |
if (_game_mode == GM_EDITOR) return; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
685 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
686 |
if (GetClearCounter(tile) < 7) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
687 |
AddClearCounter(tile, 1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
688 |
return; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
689 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
690 |
SetClearCounter(tile, 0); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
691 |
} |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
692 |
|
4333
2ff83c9c81fa
(svn r6032) -Fix: when a farm is gone, remove the fields when it is full grown and should be harvest (not before that)
truelight
parents:
4328
diff
changeset
|
693 |
if (GetIndustryIndexOfField(tile) == INVALID_INDUSTRY && GetFieldType(tile) >= 7) { |
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
694 |
/* This farmfield is no longer farmfield, so make it grass again */ |
4815
c2a54b213fde
(svn r6739) -Fix (r6001): Crash on removing farmland belonging to a farm. The search would loop
Darkvater
parents:
4560
diff
changeset
|
695 |
MakeClear(tile, CLEAR_GRASS, 2); |
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
696 |
} else { |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
697 |
field_type = GetFieldType(tile); |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
698 |
field_type = (field_type < 8) ? field_type + 1 : 0; |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
699 |
SetFieldType(tile, field_type); |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
700 |
} |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
701 |
break; |
0 | 702 |
} |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
703 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
704 |
default: |
0 | 705 |
return; |
706 |
} |
|
707 |
||
708 |
MarkTileDirtyByTile(tile); |
|
709 |
} |
|
710 |
||
6573 | 711 |
void GenerateClearTile() |
0 | 712 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
713 |
uint i, gi; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
714 |
TileIndex tile; |
0 | 715 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
716 |
/* add rough tiles */ |
2635 | 717 |
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
718 |
gi = ScaleByMapSize(GB(Random(), 0, 7) + 0x80); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
719 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
720 |
SetGeneratingWorldProgress(GWP_ROUGH_ROCKY, gi + i); |
0 | 721 |
do { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
722 |
IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY); |
2051 | 723 |
tile = RandomTile(); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
724 |
if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3); |
0 | 725 |
} while (--i); |
726 |
||
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
727 |
/* add rocky tiles */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
728 |
i = gi; |
0 | 729 |
do { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
730 |
uint32 r = Random(); |
2051 | 731 |
tile = RandomTileSeed(r); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
732 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
733 |
IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
734 |
if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
735 |
uint j = GB(r, 16, 4) + 5; |
2951 | 736 |
for (;;) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
737 |
TileIndex tile_new; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
738 |
|
3447 | 739 |
SetClearGroundDensity(tile, CLEAR_ROCKS, 3); |
0 | 740 |
do { |
741 |
if (--j == 0) goto get_out; |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
742 |
tile_new = tile + TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2)); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
743 |
} while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT)); |
0 | 744 |
tile = tile_new; |
745 |
} |
|
746 |
get_out:; |
|
747 |
} |
|
748 |
} while (--i); |
|
749 |
} |
|
750 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
751 |
static void ClickTile_Clear(TileIndex tile) |
0 | 752 |
{ |
753 |
/* not used */ |
|
754 |
} |
|
755 |
||
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6683
diff
changeset
|
756 |
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode, uint sub_mode) |
0 | 757 |
{ |
758 |
return 0; |
|
759 |
} |
|
760 |
||
2220 | 761 |
static const StringID _clear_land_str[] = { |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
762 |
STR_080D_GRASS, |
0 | 763 |
STR_080B_ROUGH_LAND, |
764 |
STR_080A_ROCKS, |
|
765 |
STR_080E_FIELDS, |
|
766 |
STR_080F_SNOW_COVERED_LAND, |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
767 |
STR_0810_DESERT |
0 | 768 |
}; |
769 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
770 |
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
0 | 771 |
{ |
3447 | 772 |
if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) { |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
773 |
td->str = STR_080C_BARE_LAND; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
774 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
775 |
td->str = _clear_land_str[GetClearGround(tile)]; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
776 |
} |
1901
fb05044cf5c3
(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
|
777 |
td->owner = GetTileOwner(tile); |
0 | 778 |
} |
779 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
780 |
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 781 |
{ |
782 |
return; |
|
783 |
} |
|
784 |
||
6573 | 785 |
void InitializeClearLand() |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
786 |
{ |
3422
12cdb13ddb56
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
787 |
_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT; |
0 | 788 |
} |
789 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
790 |
static CommandCost TerraformTile_Clear(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
791 |
{ |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
792 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
793 |
} |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
794 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
795 |
extern const TileTypeProcs _tile_type_clear_procs = { |
6449
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
796 |
DrawTile_Clear, ///< draw_tile_proc |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
797 |
GetSlopeZ_Clear, ///< get_slope_z_proc |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
798 |
ClearTile_Clear, ///< clear_tile_proc |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
799 |
GetAcceptedCargo_Clear, ///< get_accepted_cargo_proc |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
800 |
GetTileDesc_Clear, ///< get_tile_desc_proc |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
801 |
GetTileTrackStatus_Clear, ///< get_tile_track_status_proc |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
802 |
ClickTile_Clear, ///< click_tile_proc |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
803 |
AnimateTile_Clear, ///< animate_tile_proc |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
804 |
TileLoop_Clear, ///< tile_loop_clear |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
805 |
ChangeTileOwner_Clear, ///< change_tile_owner_clear |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
806 |
NULL, ///< get_produced_cargo_proc |
e520244dc71e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6432
diff
changeset
|
807 |
NULL, ///< vehicle_enter_tile_proc |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
808 |
GetFoundation_Clear, ///< get_foundation_proc |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6743
diff
changeset
|
809 |
TerraformTile_Clear, ///< terraform_tile_proc |
0 | 810 |
}; |