author | tron |
Sun, 12 Mar 2006 12:19:25 +0000 | |
changeset 3183 | 90c676e6a50d |
parent 3181 | aa47118db959 |
child 3184 | 118a520164e4 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
3 |
/** @file tunnelbridge_cmd.c |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
4 |
* This file deals with tunnels and bridges (non-gui stuff) |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
5 |
* @todo seperate this file into two |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
6 |
*/ |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
7 |
|
0 | 8 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1884
diff
changeset
|
9 |
#include "openttd.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3069
diff
changeset
|
10 |
#include "road_map.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
11 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
12 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
13 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
541
diff
changeset
|
14 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1192
diff
changeset
|
15 |
#include "tile.h" |
3154 | 16 |
#include "tunnel_map.h" |
0 | 17 |
#include "vehicle.h" |
18 |
#include "viewport.h" |
|
19 |
#include "command.h" |
|
20 |
#include "player.h" |
|
21 |
#include "town.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
334
diff
changeset
|
22 |
#include "sound.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
23 |
#include "variables.h" |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
24 |
#include "bridge.h" |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2663
diff
changeset
|
25 |
#include "train.h" |
0 | 26 |
|
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
27 |
#include "table/bridge_land.h" |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
28 |
|
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
29 |
extern const byte _track_sloped_sprites[14]; |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
30 |
extern const SpriteID _water_shore_sprites[15]; |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
31 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
32 |
extern void DrawCanalWater(TileIndex tile); |
0 | 33 |
|
2478
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
34 |
const Bridge orig_bridge[] = { |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
35 |
/* |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2262
diff
changeset
|
36 |
year of availablity |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
37 |
| minimum length |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
38 |
| | maximum length |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
39 |
| | | price |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
40 |
| | | | maximum speed |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
41 |
| | | | | sprite to use in GUI string with description |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
42 |
| | | | | | | */ |
2478
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
43 |
{ 0, 0, 16, 80, 32, 0xA24 , STR_5012_WOODEN , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
44 |
{ 0, 0, 2, 112, 48, 0xA26 | PALETTE_TO_STRUCT_RED , STR_5013_CONCRETE , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
45 |
{ 10, 0, 5, 144, 64, 0xA25 , STR_500F_GIRDER_STEEL , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
46 |
{ 0, 2, 10, 168, 80, 0xA22 | PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
47 |
{ 10, 3, 16, 185, 96, 0xA22 , STR_500E_SUSPENSION_STEEL , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
48 |
{ 10, 3, 16, 192, 112, 0xA22 | PALETTE_TO_STRUCT_YELLOW , STR_500E_SUSPENSION_STEEL , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
49 |
{ 10, 3, 7, 224, 160, 0xA23 , STR_5010_CANTILEVER_STEEL , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
50 |
{ 10, 3, 8, 232, 208, 0xA23 | PALETTE_TO_STRUCT_BROWN , STR_5010_CANTILEVER_STEEL , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
51 |
{ 10, 3, 9, 248, 240, 0xA23 | PALETTE_TO_STRUCT_RED , STR_5010_CANTILEVER_STEEL , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
52 |
{ 10, 0, 2, 240, 256, 0xA27 , STR_500F_GIRDER_STEEL , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
53 |
{ 75, 2, 16, 255, 320, 0xA28 , STR_5014_TUBULAR_STEEL , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
54 |
{ 85, 2, 32, 380, 512, 0xA28 | PALETTE_TO_STRUCT_YELLOW , STR_5014_TUBULAR_STEEL , NULL, 0 }, |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
55 |
{ 90, 2, 32, 510, 608, 0xA28 | PALETTE_TO_STRUCT_GREY , STR_BRIDGE_TUBULAR_SILICON , NULL, 0 } |
0 | 56 |
}; |
57 |
||
2763 | 58 |
Bridge _bridge[MAX_BRIDGES]; |
59 |
||
60 |
||
0 | 61 |
// calculate the price factor for building a long bridge. |
62 |
// basically the cost delta is 1,1, 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6, 7,7,7,7,7,7,7, 8,8,8,8,8,8,8,8, |
|
63 |
int CalcBridgeLenCostFactor(int x) |
|
64 |
{ |
|
2639 | 65 |
int n; |
66 |
int r; |
|
67 |
||
0 | 68 |
if (x < 2) return x; |
69 |
x -= 2; |
|
2639 | 70 |
for (n = 0, r = 2;; n++) { |
0 | 71 |
if (x <= n) return r + x * n; |
72 |
r += n * n; |
|
73 |
x -= n; |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
enum { |
|
78 |
// foundation, whole tile is leveled up (tileh's 7, 11, 13, 14) --> 3 corners raised |
|
79 |
BRIDGE_FULL_LEVELED_FOUNDATION = 1 << 7 | 1 << 11 | 1 << 13 | 1 << 14, |
|
80 |
// foundation, tile is partly leveled up (tileh's 1, 2, 4, 8) --> 1 corner raised |
|
81 |
BRIDGE_PARTLY_LEVELED_FOUNDATION = 1 << 1 | 1 << 2 | 1 << 4 | 1 << 8, |
|
82 |
// no foundations (X,Y direction) (tileh's 0, 3, 6, 9, 12) |
|
83 |
BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12, |
|
84 |
}; |
|
85 |
||
2478
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
86 |
static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table) |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
87 |
{ |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
88 |
const Bridge *bridge = &_bridge[index]; |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
89 |
assert(table < 7); |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
90 |
if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) { |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
91 |
return _bridge_sprite_table[index][table]; |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
92 |
} else { |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
93 |
return bridge->sprite_table[table]; |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
94 |
} |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
95 |
} |
cd6a02ba3853
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
96 |
|
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
97 |
/** |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
98 |
* Determines which piece of a bridge is contained in the current tile |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
99 |
* @param tile The tile to analyze |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
100 |
* @return the piece |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
101 |
*/ |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
102 |
static inline int GetBridgePiece(TileIndex tile) |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
103 |
{ |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
104 |
return GB(_m[tile].m2, 0, 4); |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
105 |
} |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
106 |
|
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
107 |
/** |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
108 |
* Determines the type of bridge on a tile |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
109 |
* @param tile The tile to analyze |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
110 |
* @return The bridge type |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
111 |
*/ |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
112 |
static inline int GetBridgeType(TileIndex tile) |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
113 |
{ |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
114 |
return GB(_m[tile].m2, 4, 4); |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
115 |
} |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
116 |
|
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
117 |
/** check if bridge can be built on slope |
0 | 118 |
* direction 0 = X-axis, direction 1 = Y-axis |
119 |
* is_start_tile = false <-- end tile |
|
120 |
* is_start_tile = true <-- start tile |
|
121 |
*/ |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
122 |
static uint32 CheckBridgeSlope(Axis direction, uint tileh, bool is_start_tile) |
0 | 123 |
{ |
2639 | 124 |
if (IsSteepTileh(tileh)) return CMD_ERROR; |
0 | 125 |
|
2639 | 126 |
if (is_start_tile) { |
127 |
/* check slope at start tile |
|
128 |
- no extra cost |
|
129 |
- direction X: tiles 0, 12 |
|
130 |
- direction Y: tiles 0, 9 |
|
131 |
*/ |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
132 |
if ((direction == AXIS_X ? 0x1001 : 0x201) & (1 << tileh)) return 0; |
0 | 133 |
|
2639 | 134 |
// disallow certain start tiles to avoid certain crooked bridges |
135 |
if (tileh == 2) return CMD_ERROR; |
|
136 |
} else { |
|
137 |
/* check slope at end tile |
|
138 |
- no extra cost |
|
139 |
- direction X: tiles 0, 3 |
|
140 |
- direction Y: tiles 0, 6 |
|
141 |
*/ |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
142 |
if ((direction == AXIS_X ? 0x9 : 0x41) & (1 << tileh)) return 0; |
0 | 143 |
|
2639 | 144 |
// disallow certain end tiles to avoid certain crooked bridges |
145 |
if (tileh == 8) return CMD_ERROR; |
|
146 |
} |
|
0 | 147 |
|
2639 | 148 |
/* disallow common start/end tiles to avoid certain crooked bridges e.g. |
149 |
* start-tile: X 2,1 Y 2,4 (2 was disabled before) |
|
150 |
* end-tile: X 8,4 Y 8,1 (8 was disabled before) |
|
151 |
*/ |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
152 |
if ((tileh == 1 && is_start_tile != (direction != AXIS_X)) || |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
153 |
(tileh == 4 && is_start_tile == (direction != AXIS_X))) { |
2639 | 154 |
return CMD_ERROR; |
0 | 155 |
} |
156 |
||
2639 | 157 |
// slope foundations |
158 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh) || BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << tileh)) |
|
159 |
return _price.terraform; |
|
160 |
||
0 | 161 |
return CMD_ERROR; |
162 |
} |
|
163 |
||
164 |
uint32 GetBridgeLength(TileIndex begin, TileIndex end) |
|
165 |
{ |
|
2639 | 166 |
int x1 = TileX(begin); |
167 |
int y1 = TileY(begin); |
|
168 |
int x2 = TileX(end); |
|
169 |
int y2 = TileY(end); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
170 |
|
2639 | 171 |
return abs(x2 + y2 - x1 - y1) - 1; |
0 | 172 |
} |
173 |
||
2639 | 174 |
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len) |
0 | 175 |
{ |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
176 |
const Bridge *b = &_bridge[bridge_type]; |
2639 | 177 |
uint max; // max possible length of a bridge (with patch 100) |
0 | 178 |
|
1781
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
179 |
if (bridge_type >= MAX_BRIDGES) return false; |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
180 |
if (b->avail_year > _cur_year) return false; |
0 | 181 |
|
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
182 |
max = b->max_length; |
2639 | 183 |
if (max >= 16 && _patches.longbridges) max = 100; |
0 | 184 |
|
2639 | 185 |
return b->min_length <= bridge_len && bridge_len <= max; |
0 | 186 |
} |
187 |
||
1775
548dc04d50e2
(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:
1587
diff
changeset
|
188 |
/** Build a Bridge |
548dc04d50e2
(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:
1587
diff
changeset
|
189 |
* @param x,y end tile coord |
548dc04d50e2
(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:
1587
diff
changeset
|
190 |
* @param p1 packed start tile coords (~ dx) |
548dc04d50e2
(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:
1587
diff
changeset
|
191 |
* @param p2 various bitstuffed elements |
548dc04d50e2
(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:
1587
diff
changeset
|
192 |
* - p2 = (bit 0- 7) - bridge type (hi bh) |
548dc04d50e2
(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:
1587
diff
changeset
|
193 |
* - p2 = (bit 8-..) - rail type. bit15 ((x>>8)&0x80) means road bridge. |
0 | 194 |
*/ |
195 |
int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
196 |
{ |
|
197 |
int bridge_type; |
|
3180
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
198 |
byte m5; |
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
199 |
TransportType transport; |
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
200 |
RailType railtype; |
0 | 201 |
int sx,sy; |
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
202 |
TileInfo ti_start, ti_end; |
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
203 |
TileIndex tile; |
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
204 |
TileIndexDiff delta; |
2639 | 205 |
uint bridge_len; |
206 |
uint odd_middle_part; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
207 |
Axis direction; |
2639 | 208 |
uint i; |
0 | 209 |
int32 cost, terraformcost, ret; |
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
210 |
bool allow_on_slopes; |
0 | 211 |
|
212 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
213 |
|
0 | 214 |
/* unpack parameters */ |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
215 |
bridge_type = GB(p2, 0, 8); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
216 |
|
2934
3f29a7212713
(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:
2931
diff
changeset
|
217 |
if (p1 >= MapSize()) return CMD_ERROR; |
1775
548dc04d50e2
(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:
1587
diff
changeset
|
218 |
|
0 | 219 |
// type of bridge |
3180
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
220 |
if (HASBIT(p2, 15)) { |
0 | 221 |
railtype = 0; |
3180
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
222 |
transport = TRANSPORT_ROAD; |
0 | 223 |
} else { |
3180
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
224 |
if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR; |
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
225 |
railtype = GB(p2, 8, 8); |
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
226 |
transport = TRANSPORT_RAIL; |
0 | 227 |
} |
228 |
||
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
229 |
sx = TileX(p1) * 16; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
230 |
sy = TileY(p1) * 16; |
0 | 231 |
|
232 |
/* check if valid, and make sure that (x,y) are smaller than (sx,sy) */ |
|
233 |
if (x == sx) { |
|
2639 | 234 |
if (y == sy) return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
235 |
direction = AXIS_Y; |
0 | 236 |
if (y > sy) { |
237 |
intswap(y,sy); |
|
238 |
intswap(x,sx); |
|
239 |
} |
|
240 |
} else if (y == sy) { |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
241 |
direction = AXIS_X; |
0 | 242 |
if (x > sx) { |
243 |
intswap(y,sy); |
|
244 |
intswap(x,sx); |
|
245 |
} |
|
2639 | 246 |
} else { |
0 | 247 |
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); |
2639 | 248 |
} |
0 | 249 |
|
1781
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
250 |
/* set and test bridge length, availability */ |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
251 |
bridge_len = ((sx + sy - x - y) >> 4) - 1; |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
252 |
if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE); |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
253 |
|
0 | 254 |
/* retrieve landscape height and ensure it's on land */ |
2951 | 255 |
if (( |
256 |
FindLandscapeHeight(&ti_end, sx, sy), |
|
257 |
ti_end.type == MP_WATER && ti_end.map5 == 0 |
|
258 |
) || ( |
|
259 |
FindLandscapeHeight(&ti_start, x, y), |
|
260 |
ti_start.type == MP_WATER && ti_start.map5 == 0 |
|
261 |
)) { |
|
0 | 262 |
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH); |
2951 | 263 |
} |
0 | 264 |
|
265 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_start.tileh)) { |
|
266 |
ti_start.z += 8; |
|
267 |
ti_start.tileh = 0; |
|
268 |
} |
|
269 |
||
270 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_end.tileh)) { |
|
271 |
ti_end.z += 8; |
|
272 |
ti_end.tileh = 0; |
|
273 |
} |
|
274 |
||
275 |
if (ti_start.z != ti_end.z) |
|
276 |
return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); |
|
277 |
||
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
278 |
|
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
279 |
// Towns are not allowed to use bridges on slopes. |
2422
897a01f7c624
(svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents:
2314
diff
changeset
|
280 |
allow_on_slopes = (!_is_old_ai_player |
1781
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
281 |
&& _current_player != OWNER_TOWN && _patches.build_on_slopes); |
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
282 |
|
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
283 |
/* Try and clear the start landscape */ |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
284 |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
285 |
ret = DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
286 |
if (CmdFailed(ret)) return ret; |
0 | 287 |
cost = ret; |
288 |
||
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
289 |
// true - bridge-start-tile, false - bridge-end-tile |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
290 |
terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true); |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2676
diff
changeset
|
291 |
if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes)) |
0 | 292 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
293 |
cost += terraformcost; |
|
294 |
||
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
295 |
/* Try and clear the end landscape */ |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
296 |
|
2639 | 297 |
ret = DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
298 |
if (CmdFailed(ret)) return ret; |
0 | 299 |
cost += ret; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
300 |
|
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
301 |
// false - end tile slope check |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
302 |
terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false); |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2676
diff
changeset
|
303 |
if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes)) |
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
304 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
305 |
cost += terraformcost; |
0 | 306 |
|
307 |
||
308 |
/* do the drill? */ |
|
309 |
if (flags & DC_EXEC) { |
|
310 |
/* build the start tile */ |
|
311 |
ModifyTile(ti_start.tile, |
|
312 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
313 |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
314 |
(bridge_type << 4), /* map2 */ |
|
315 |
railtype, /* map3_lo */ |
|
3180
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
316 |
0x80 | direction | transport << 1 /* map5 */ |
0 | 317 |
); |
318 |
||
319 |
/* build the end tile */ |
|
320 |
ModifyTile(ti_end.tile, |
|
321 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
322 |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
323 |
(bridge_type << 4), /* map2 */ |
|
324 |
railtype, /* map3_lo */ |
|
3180
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
325 |
0x80 | 0x20 | direction | transport << 1 /* map5 */ |
0 | 326 |
); |
327 |
} |
|
328 |
||
1781
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
329 |
// position of middle part of the odd bridge (larger than MAX(i) otherwise) |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
330 |
odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len; |
0 | 331 |
|
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
332 |
tile = ti_start.tile; |
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
333 |
delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
1781
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
334 |
for (i = 0; i != bridge_len; i++) { |
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
335 |
uint z; |
0 | 336 |
|
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
337 |
tile += delta; |
0 | 338 |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
339 |
if (GetTileSlope(tile, &z) != 0 && z >= ti_start.z) { |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
340 |
return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
341 |
} |
0 | 342 |
|
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
343 |
switch (GetTileType(tile)) { |
3065 | 344 |
case MP_WATER: |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
345 |
if (!EnsureNoVehicle(tile)) return_cmd_error(STR_980E_SHIP_IN_THE_WAY); |
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
346 |
if (_m[tile].m5 > 1) goto not_valid_below; |
3065 | 347 |
m5 = 0xC8; |
348 |
break; |
|
0 | 349 |
|
3065 | 350 |
case MP_RAILWAY: |
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
351 |
if (_m[tile].m5 != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) { |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
352 |
goto not_valid_below; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
353 |
} |
3065 | 354 |
m5 = 0xE0; |
355 |
break; |
|
356 |
||
357 |
case MP_STREET: |
|
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
358 |
if (GetRoadType(tile) != ROAD_NORMAL || |
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
359 |
GetRoadBits(tile) != (direction == AXIS_X ? ROAD_Y : ROAD_X)) { |
3069
9a1fd047b595
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3065
diff
changeset
|
360 |
goto not_valid_below; |
9a1fd047b595
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3065
diff
changeset
|
361 |
} |
3065 | 362 |
m5 = 0xE8; |
363 |
break; |
|
364 |
||
365 |
default: |
|
0 | 366 |
not_valid_below:; |
3065 | 367 |
/* try and clear the middle landscape */ |
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
368 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
369 |
if (CmdFailed(ret)) return ret; |
3065 | 370 |
cost += ret; |
371 |
m5 = 0xC0; |
|
372 |
break; |
|
0 | 373 |
} |
374 |
||
375 |
/* do middle part of bridge */ |
|
376 |
if (flags & DC_EXEC) { |
|
3180
9c87ee130147
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents:
3178
diff
changeset
|
377 |
_m[tile].m5 = (byte)(m5 | direction | transport << 1); |
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
378 |
SetTileType(tile, MP_TUNNELBRIDGE); |
0 | 379 |
|
380 |
//bridges pieces sequence (middle parts) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
381 |
// bridge len 1: 0 |
0 | 382 |
// bridge len 2: 0 1 |
383 |
// bridge len 3: 0 4 1 |
|
384 |
// bridge len 4: 0 2 3 1 |
|
385 |
// bridge len 5: 0 2 5 3 1 |
|
386 |
// bridge len 6: 0 2 3 2 3 1 |
|
387 |
// bridge len 7: 0 2 3 4 2 3 1 |
|
2639 | 388 |
// #0 - always as first, #1 - always as last (if len>1) |
0 | 389 |
// #2,#3 are to pair in order |
390 |
// for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0) |
|
391 |
||
2639 | 392 |
if (i == 0) { // first tile |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
393 |
m5 = 0; |
2639 | 394 |
} else if (i == bridge_len - 1) { // last tile |
0 | 395 |
m5 = 1; |
2639 | 396 |
} else if (i == odd_middle_part) { // we are on the middle of odd bridge: #5 on even pos, #4 on odd |
397 |
m5 = 5 - (i % 2); |
|
398 |
} else { |
|
0 | 399 |
// generate #2 and #3 in turns [i%2==0], after the middle of odd bridge |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
400 |
// this sequence swaps [... XOR (i>odd_middle_part)], |
0 | 401 |
// for even bridges XOR does not apply as odd_middle_part==bridge_len |
2639 | 402 |
m5 = 2 + ((i % 2 == 0) ^ (i > odd_middle_part)); |
0 | 403 |
} |
404 |
||
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
405 |
_m[tile].m2 = (bridge_type << 4) | m5; |
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
406 |
SB(_m[tile].m3, 4, 4, railtype); |
0 | 407 |
|
3178
f41cd14f6034
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
408 |
MarkTileDirtyByTile(tile); |
0 | 409 |
} |
410 |
} |
|
411 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
412 |
SetSignalsOnBothDir(ti_start.tile, direction == AXIS_X ? TRACK_X : TRACK_Y); |
0 | 413 |
|
414 |
/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST) |
|
415 |
It's unnecessary to execute this command every time for every bridge. So it is done only |
|
416 |
and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated |
|
417 |
*/ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
418 |
if (!(flags & DC_QUERY_COST)) { |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
419 |
const Bridge *b = &_bridge[bridge_type]; |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
420 |
|
0 | 421 |
bridge_len += 2; // begin and end tiles/ramps |
422 |
||
2422
897a01f7c624
(svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents:
2314
diff
changeset
|
423 |
if (_current_player < MAX_PLAYERS && !_is_old_ai_player) |
0 | 424 |
bridge_len = CalcBridgeLenCostFactor(bridge_len); |
425 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
426 |
cost += (int64)bridge_len * _price.build_bridge * b->price >> 8; |
0 | 427 |
} |
428 |
||
429 |
return cost; |
|
430 |
} |
|
431 |
||
432 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
433 |
/** Build Tunnel. |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
434 |
* @param x,y start tile coord of tunnel |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
435 |
* @param p1 railtype, 0x200 for road tunnel |
2639 | 436 |
* @param p2 unused |
0 | 437 |
*/ |
438 |
int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
439 |
{ |
|
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
440 |
TileIndexDiff delta; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
441 |
TileIndex start_tile; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
442 |
TileIndex end_tile; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
443 |
DiagDirection direction; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
444 |
uint start_tileh; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
445 |
uint end_tileh; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
446 |
uint start_z; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
447 |
uint end_z; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
448 |
int32 cost; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
449 |
int32 ret; |
0 | 450 |
|
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
451 |
_build_tunnel_endtile = 0; |
0 | 452 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
453 |
if (p1 != 0x200 && !ValParamRailtype(p1)) return CMD_ERROR; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
454 |
|
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
455 |
start_tile = TileVirtXY(x, y); |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
456 |
start_tileh = GetTileSlope(start_tile, &start_z); |
0 | 457 |
|
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
458 |
switch (start_tileh) { |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
459 |
case 3: direction = DIAGDIR_SW; break; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
460 |
case 6: direction = DIAGDIR_SE; break; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
461 |
case 9: direction = DIAGDIR_NW; break; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
462 |
case 12: direction = DIAGDIR_NE; break; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
463 |
default: return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL); |
2639 | 464 |
} |
0 | 465 |
|
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
466 |
ret = DoCommandByTile(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
467 |
if (CmdFailed(ret)) return ret; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
468 |
cost = _price.build_tunnel + ret; |
0 | 469 |
|
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
470 |
delta = TileOffsByDir(direction); |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
471 |
end_tile = start_tile; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
472 |
for (;;) { |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
473 |
end_tile += delta; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
474 |
end_tileh = GetTileSlope(end_tile, &end_z); |
0 | 475 |
|
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
476 |
if (start_z == end_z) break; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
477 |
|
3156
f4caf4197189
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
478 |
if (!_cheats.crossing_tunnels.value && IsTunnelInWay(end_tile, start_z)) { |
f4caf4197189
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
479 |
return_cmd_error(STR_5003_ANOTHER_TUNNEL_IN_THE_WAY); |
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
480 |
} |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
481 |
|
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
482 |
cost += _price.build_tunnel; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
483 |
cost += cost >> 3; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
484 |
if (cost >= 400000000) cost = 400000000; |
0 | 485 |
} |
486 |
||
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
487 |
// if the command fails from here on we want the end tile to be highlighted |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
488 |
_build_tunnel_endtile = end_tile; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
489 |
|
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
490 |
// slope of end tile must be complementary to the slope of the start tile |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
491 |
if (end_tileh != (15 ^ start_tileh)) { |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
492 |
ret = DoCommandByTile(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND); |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
493 |
if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND); |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
494 |
} else { |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
495 |
ret = DoCommandByTile(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
496 |
if (CmdFailed(ret)) return ret; |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
497 |
} |
3064
960264bcce6f
(svn r3653) -Fix: You didn't pay for terraforming at the end tile when building a tunnel
tron
parents:
3063
diff
changeset
|
498 |
cost += _price.build_tunnel + ret; |
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
499 |
|
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
500 |
if (flags & DC_EXEC) { |
3154 | 501 |
if (GB(p1, 9, 1) == TRANSPORT_RAIL) { |
502 |
MakeRailTunnel(start_tile, _current_player, direction, GB(p1, 0, 4)); |
|
503 |
MakeRailTunnel(end_tile, _current_player, ReverseDiagDir(direction), GB(p1, 0, 4)); |
|
504 |
} else { |
|
505 |
MakeRoadTunnel(start_tile, _current_player, direction); |
|
506 |
MakeRoadTunnel(end_tile, _current_player, ReverseDiagDir(direction)); |
|
507 |
} |
|
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
508 |
|
3172
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
509 |
if (GB(p1, 9, 1) == 0) UpdateSignalsOnSegment(start_tile, direction); |
3063
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
510 |
} |
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
511 |
|
61a07ec0d09e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
512 |
return cost; |
0 | 513 |
} |
514 |
||
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
515 |
TileIndex CheckTunnelBusy(TileIndex tile, uint *length) |
0 | 516 |
{ |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
517 |
uint z = GetTileZ(tile); |
3154 | 518 |
DiagDirection dir = GetTunnelDirection(tile); |
519 |
TileIndexDiff delta = TileOffsByDir(dir); |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
520 |
uint len = 0; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
521 |
TileIndex starttile = tile; |
0 | 522 |
Vehicle *v; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
523 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
524 |
do { |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
525 |
tile += delta; |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
526 |
len++; |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
527 |
} while ( |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
528 |
!IsTileType(tile, MP_TUNNELBRIDGE) || |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
529 |
GB(_m[tile].m5, 4, 4) != 0 || |
3154 | 530 |
ReverseDiagDir(GetTunnelDirection(tile)) != dir || |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
531 |
GetTileZ(tile) != z |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
532 |
); |
0 | 533 |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
534 |
v = FindVehicleBetween(starttile, tile, z); |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
535 |
if (v != NULL) { |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
536 |
_error_message = v->type == VEH_Train ? |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
537 |
STR_5000_TRAIN_IN_TUNNEL : STR_5001_ROAD_VEHICLE_IN_TUNNEL; |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
538 |
return INVALID_TILE; |
0 | 539 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
540 |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
541 |
if (length != NULL) *length = len; |
0 | 542 |
return tile; |
543 |
} |
|
544 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
545 |
static int32 DoClearTunnel(TileIndex tile, uint32 flags) |
0 | 546 |
{ |
547 |
Town *t; |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
548 |
TileIndex endtile; |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
549 |
uint length; |
0 | 550 |
|
551 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
552 |
||
553 |
// in scenario editor you can always destroy tunnels |
|
554 |
if (_game_mode != GM_EDITOR && !CheckTileOwnership(tile)) { |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
555 |
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN)) |
0 | 556 |
return CMD_ERROR; |
557 |
} |
|
558 |
||
559 |
endtile = CheckTunnelBusy(tile, &length); |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
560 |
if (endtile == INVALID_TILE) return CMD_ERROR; |
0 | 561 |
|
562 |
_build_tunnel_endtile = endtile; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
563 |
|
0 | 564 |
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty |
565 |
// check if you're allowed to remove the tunnel owned by a town |
|
566 |
// removal allowal depends on difficulty settings |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
567 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
568 |
if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
511
diff
changeset
|
569 |
SetDParam(0, t->index); |
0 | 570 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
571 |
} |
|
572 |
} |
|
573 |
||
574 |
if (flags & DC_EXEC) { |
|
38
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
575 |
// We first need to request the direction before calling DoClearSquare |
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
576 |
// else the direction is always 0.. dah!! ;) |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
577 |
DiagDirection dir = GetTunnelDirection(tile); |
2870
0dc0bcee256a
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
578 |
|
0dc0bcee256a
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
579 |
// Adjust the town's player rating. Do this before removing the tile owner info. |
0dc0bcee256a
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
580 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) |
0dc0bcee256a
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
581 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
0dc0bcee256a
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
582 |
|
0 | 583 |
DoClearSquare(tile); |
584 |
DoClearSquare(endtile); |
|
3172
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
585 |
UpdateSignalsOnSegment(tile, ReverseDiagDir(dir)); |
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
586 |
UpdateSignalsOnSegment(endtile, dir); |
0 | 587 |
} |
2639 | 588 |
return _price.clear_tunnel * (length + 1); |
0 | 589 |
} |
590 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
591 |
static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile) |
0 | 592 |
{ |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
593 |
Axis direction = GB(_m[tile].m5, 0, 1); |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
594 |
TileIndex start; |
0 | 595 |
|
596 |
// find start of bridge |
|
2952 | 597 |
for (;;) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
598 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0x80) |
0 | 599 |
break; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
600 |
tile += (direction == AXIS_X ? TileDiffXY(-1, 0) : TileDiffXY(0, -1)); |
0 | 601 |
} |
602 |
||
603 |
start = tile; |
|
604 |
||
605 |
// find end of bridge |
|
2952 | 606 |
for (;;) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
607 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0xA0) |
0 | 608 |
break; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
609 |
tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
0 | 610 |
} |
611 |
||
612 |
*endtile = tile; |
|
613 |
||
614 |
return start; |
|
615 |
} |
|
616 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
617 |
static int32 DoClearBridge(TileIndex tile, uint32 flags) |
0 | 618 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
619 |
TileIndex endtile; |
0 | 620 |
Vehicle *v; |
621 |
Town *t; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
622 |
Axis direction; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
623 |
|
0 | 624 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
625 |
||
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
626 |
direction = GB(_m[tile].m5, 0, 1); |
0 | 627 |
|
628 |
/* delete stuff under the middle part if there's a transport route there..? */ |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
629 |
if ((_m[tile].m5 & 0xE0) == 0xE0) { |
0 | 630 |
int32 cost; |
631 |
||
632 |
// check if we own the tile below the bridge.. |
|
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
633 |
if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))) |
0 | 634 |
return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
635 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
636 |
cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail; |
0 | 637 |
|
638 |
if (flags & DC_EXEC) { |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
639 |
_m[tile].m5 = _m[tile].m5 & ~0x38; |
1902 | 640 |
SetTileOwner(tile, OWNER_NONE); |
0 | 641 |
MarkTileDirtyByTile(tile); |
642 |
} |
|
643 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
644 |
|
0 | 645 |
/* delete canal under bridge */ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
646 |
} else if ((_m[tile].m5 & 0xC8) == 0xC8 && TilePixelHeight(tile) != 0) { |
0 | 647 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
648 |
|
0 | 649 |
// check for vehicles under bridge |
2639 | 650 |
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR; |
0 | 651 |
cost = _price.clear_water; |
652 |
if (flags & DC_EXEC) { |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
653 |
_m[tile].m5 = _m[tile].m5 & ~0x38; |
1902 | 654 |
SetTileOwner(tile, OWNER_NONE); |
0 | 655 |
MarkTileDirtyByTile(tile); |
656 |
} |
|
657 |
return cost; |
|
658 |
} |
|
659 |
||
660 |
tile = FindEdgesOfBridge(tile, &endtile); |
|
661 |
||
662 |
// floods, scenario editor can always destroy bridges |
|
663 |
if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) { |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
664 |
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN)) |
0 | 665 |
return CMD_ERROR; |
666 |
} |
|
667 |
||
2639 | 668 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) return CMD_ERROR; |
0 | 669 |
|
670 |
/* Make sure there's no vehicle on the bridge |
|
671 |
Omit tile and endtile, since these are already checked, thus solving the problem |
|
672 |
of bridges over water, or higher bridges, where z is not increased, eg level bridge |
|
673 |
*/ |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
674 |
tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
675 |
endtile -= (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
1082
a83d7ac6fecb
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1073
diff
changeset
|
676 |
/* Bridges on slopes might have their Z-value offset..correct this */ |
2639 | 677 |
v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile)); |
678 |
if (v != NULL) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
679 |
VehicleInTheWayErrMsg(v); |
0 | 680 |
return CMD_ERROR; |
681 |
} |
|
682 |
||
683 |
/* Put the tiles back to start/end position */ |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
684 |
tile -= (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
685 |
endtile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
686 |
|
0 | 687 |
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
688 |
// check if you're allowed to remove the bridge owned by a town. |
0 | 689 |
// removal allowal depends on difficulty settings |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
690 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
691 |
if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) return CMD_ERROR; |
0 | 692 |
} |
693 |
||
694 |
if (flags & DC_EXEC) { |
|
695 |
byte m5; |
|
696 |
uint c = tile; |
|
697 |
uint16 new_data; |
|
698 |
||
1005 | 699 |
//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until |
0 | 700 |
// you have a "Poor" (0) town rating |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
701 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) |
1005 | 702 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
0 | 703 |
|
704 |
do { |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
705 |
m5 = _m[c].m5; |
0 | 706 |
|
707 |
if (m5 & 0x40) { |
|
708 |
if (m5 & 0x20) { |
|
709 |
static const uint16 _new_data_table[] = {0x1002, 0x1001, 0x2005, 0x200A, 0, 0, 0, 0}; |
|
2639 | 710 |
new_data = _new_data_table[((m5 & 0x18) >> 2) | (m5 & 1)]; |
0 | 711 |
} else { |
2635 | 712 |
if (GB(m5, 3, 2) == 0) goto clear_it; |
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
713 |
new_data = (GetTileSlope(c, NULL) == 0) ? 0x6000 : 0x6001; |
0 | 714 |
} |
715 |
||
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
716 |
SetTileType(c, new_data >> 12); |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
717 |
_m[c].m5 = (byte)new_data; |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
718 |
_m[c].m2 = 0; |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
719 |
_m[c].m4 &= 0x0F; |
0 | 720 |
|
721 |
MarkTileDirtyByTile(c); |
|
722 |
||
723 |
} else { |
|
724 |
clear_it:; |
|
725 |
DoClearSquare(c); |
|
726 |
} |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
727 |
c += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
0 | 728 |
} while (c <= endtile); |
729 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
730 |
SetSignalsOnBothDir(tile, direction == AXIS_X ? TRACK_X : TRACK_Y); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
731 |
SetSignalsOnBothDir(endtile, direction == AXIS_X ? TRACK_X : TRACK_Y); |
0 | 732 |
} |
733 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
734 |
if (direction == AXIS_X) { |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
735 |
return (TileX(endtile) - TileX(tile) + 1) * _price.clear_bridge; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
736 |
} else { |
2931
d832ee22696d
(svn r3487) -Fix: Price for demolishing a bridge was dependent on orientation and map size
tron
parents:
2916
diff
changeset
|
737 |
return (TileY(endtile) - TileY(tile) + 1) * _price.clear_bridge; |
d832ee22696d
(svn r3487) -Fix: Price for demolishing a bridge was dependent on orientation and map size
tron
parents:
2916
diff
changeset
|
738 |
} |
0 | 739 |
} |
740 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
741 |
static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags) |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
742 |
{ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
743 |
byte m5 = _m[tile].m5; |
0 | 744 |
|
745 |
if ((m5 & 0xF0) == 0) { |
|
2639 | 746 |
if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST); |
0 | 747 |
return DoClearTunnel(tile, flags); |
748 |
} else if (m5 & 0x80) { |
|
2639 | 749 |
if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
1082
a83d7ac6fecb
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1073
diff
changeset
|
750 |
return DoClearBridge(tile, flags); |
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
751 |
} |
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
752 |
|
1082
a83d7ac6fecb
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1073
diff
changeset
|
753 |
return CMD_ERROR; |
0 | 754 |
} |
755 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
756 |
int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec) |
0 | 757 |
{ |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
758 |
TileIndex endtile; |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
759 |
uint length; |
0 | 760 |
Vehicle *v; |
761 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
762 |
if ((_m[tile].m5 & 0xFC) == 0x00) { |
0 | 763 |
// railway tunnel |
764 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
765 |
||
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
766 |
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
767 |
|
0 | 768 |
endtile = CheckTunnelBusy(tile, &length); |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
769 |
if (endtile == INVALID_TILE) return CMD_ERROR; |
0 | 770 |
|
771 |
if (exec) { |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
772 |
SB(_m[tile].m3, 0, 4, totype); |
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
773 |
SB(_m[endtile].m3, 0, 4, totype); |
0 | 774 |
MarkTileDirtyByTile(tile); |
775 |
MarkTileDirtyByTile(endtile); |
|
776 |
} |
|
777 |
return (length + 1) * (_price.build_rail >> 1); |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
778 |
} else if ((_m[tile].m5 & 0xF8) == 0xE0) { |
0 | 779 |
// bridge middle part with rail below |
780 |
// only check for train under bridge |
|
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
781 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 782 |
return CMD_ERROR; |
783 |
||
784 |
// tile is already of requested type? |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
785 |
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; |
0 | 786 |
// change type. |
787 |
if (exec) { |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
788 |
SB(_m[tile].m3, 0, 4, totype); |
0 | 789 |
MarkTileDirtyByTile(tile); |
790 |
} |
|
791 |
return _price.build_rail >> 1; |
|
2639 | 792 |
} else if ((_m[tile].m5 & 0xC6) == 0x80) { |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
793 |
TileIndex starttile; |
0 | 794 |
int32 cost; |
1073
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
795 |
uint z = TilePixelHeight(tile); |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
796 |
|
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
797 |
z += 8; |
0 | 798 |
|
799 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
800 |
||
801 |
// railway bridge |
|
802 |
starttile = tile = FindEdgesOfBridge(tile, &endtile); |
|
803 |
// Make sure there's no vehicle on the bridge |
|
2639 | 804 |
v = FindVehicleBetween(tile, endtile, z); |
805 |
if (v != NULL) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
806 |
VehicleInTheWayErrMsg(v); |
0 | 807 |
return CMD_ERROR; |
808 |
} |
|
809 |
||
1073
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
810 |
if (!EnsureNoVehicle(starttile) || !EnsureNoVehicle(endtile)) { |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
811 |
_error_message = STR_8803_TRAIN_IN_THE_WAY; |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
812 |
return CMD_ERROR; |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
813 |
} |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
814 |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
815 |
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; |
0 | 816 |
cost = 0; |
817 |
do { |
|
818 |
if (exec) { |
|
819 |
if (tile == starttile || tile == endtile) { |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
820 |
SB(_m[tile].m3, 0, 4, totype); |
0 | 821 |
} else { |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
822 |
SB(_m[tile].m3, 4, 4, totype); |
0 | 823 |
} |
824 |
MarkTileDirtyByTile(tile); |
|
825 |
} |
|
2639 | 826 |
cost += _price.build_rail >> 1; |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
827 |
tile += GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 828 |
} while (tile <= endtile); |
829 |
||
830 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
831 |
} else |
0 | 832 |
return CMD_ERROR; |
833 |
} |
|
834 |
||
835 |
||
836 |
// fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile. |
|
1095 | 837 |
static uint GetBridgeHeight(const TileInfo *ti) |
0 | 838 |
{ |
1981 | 839 |
TileIndexDiff delta; |
1192
2649bd4e556a
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
840 |
TileIndex tile = ti->tile; |
0 | 841 |
|
842 |
// find the end tile of the bridge. |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
843 |
delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 844 |
do { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
845 |
assert((_m[tile].m5 & 0xC0) == 0xC0); // bridge and middle part |
0 | 846 |
tile += delta; |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
847 |
} while (_m[tile].m5 & 0x40); // while bridge middle parts |
0 | 848 |
|
1192
2649bd4e556a
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
849 |
/* Return the height there (the height of the NORTH CORNER) |
2649bd4e556a
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
850 |
* If the end of the bridge is on a tileh 7 (all raised, except north corner), |
2649bd4e556a
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
851 |
* the z coordinate is 1 height level too low. Compensate for that */ |
2649bd4e556a
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
852 |
return TilePixelHeight(tile) + (GetTileSlope(tile, NULL) == 7 ? 8 : 0); |
0 | 853 |
} |
854 |
||
855 |
static const byte _bridge_foundations[2][16] = { |
|
856 |
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
857 |
{1,16,18,3,20,5,0,7,22,0,10,11,12,13,14}, |
|
858 |
{1,15,17,0,19,5,6,7,21,9,10,11, 0,13,14}, |
|
859 |
}; |
|
860 |
||
861 |
extern const byte _road_sloped_sprites[14]; |
|
862 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2422
diff
changeset
|
863 |
static void DrawBridgePillars(const TileInfo *ti, int x, int y, int z) |
0 | 864 |
{ |
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
865 |
const PalSpriteID *b; |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
866 |
PalSpriteID image; |
0 | 867 |
int piece; |
868 |
||
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
869 |
b = _bridge_poles_table[GetBridgeType(ti->tile)]; |
0 | 870 |
|
871 |
// Draw first piece |
|
872 |
// (necessary for cantilever bridges) |
|
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
873 |
|
2642 | 874 |
image = b[12 + GB(ti->map5, 0, 1)]; |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
875 |
piece = GetBridgePiece(ti->tile); |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
876 |
|
333
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
877 |
if (image != 0 && piece != 0) { |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
878 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
333
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
879 |
DrawGroundSpriteAt(image, x, y, z); |
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
880 |
} |
0 | 881 |
|
2642 | 882 |
image = b[GB(ti->map5, 0, 1) * 6 + piece]; |
0 | 883 |
|
884 |
if (image != 0) { |
|
885 |
int back_height, front_height, i=z; |
|
886 |
const byte *p; |
|
887 |
||
888 |
static const byte _tileh_bits[4][8] = { |
|
889 |
{2,1,8,4, 16,11,0,9}, |
|
890 |
{1,8,4,2, 11,16,9,0}, |
|
891 |
{4,8,1,2, 16,11,0,9}, |
|
892 |
{2,4,8,1, 11,16,9,0}, |
|
893 |
}; |
|
894 |
||
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
895 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
333
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
896 |
|
0 | 897 |
p = _tileh_bits[(image & 1) * 2 + (ti->map5&0x01)]; |
898 |
front_height = ti->z + ((ti->tileh & p[0])?8:0); |
|
899 |
back_height = ti->z + ((ti->tileh & p[1])?8:0); |
|
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
900 |
|
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
901 |
if (IsSteepTileh(ti->tileh)) { |
0 | 902 |
if (!(ti->tileh & p[2])) front_height += 8; |
903 |
if (!(ti->tileh & p[3])) back_height += 8; |
|
904 |
} |
|
905 |
||
2952 | 906 |
for (; z >= front_height || z >= back_height; z = z - 8) { |
907 |
if (z >= front_height) { |
|
908 |
// front facing pillar |
|
909 |
AddSortableSpriteToDraw(image, x,y, p[4], p[5], 0x28, z); |
|
910 |
} |
|
911 |
if (z >= back_height && z < i - 8) { |
|
912 |
// back facing pillar |
|
913 |
AddSortableSpriteToDraw(image, x - p[6], y - p[7], p[4], p[5], 0x28, z); |
|
914 |
} |
|
0 | 915 |
} |
916 |
} |
|
917 |
} |
|
918 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
919 |
uint GetBridgeFoundation(uint tileh, Axis axis) |
2639 | 920 |
{ |
0 | 921 |
int i; |
922 |
// normal level sloped building (7, 11, 13, 14) |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
923 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) return tileh; |
0 | 924 |
|
925 |
// inclined sloped building |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
926 |
if (( |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
927 |
(i = 0, tileh == 1) || |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
928 |
(i += 2, tileh == 2) || |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
929 |
(i += 2, tileh == 4) || |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
930 |
(i += 2, tileh == 8) |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
931 |
) && ( |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
932 |
axis == AXIS_X || |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
933 |
(i++, axis == AXIS_Y) |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
934 |
)) { |
0 | 935 |
return i + 15; |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
936 |
} |
0 | 937 |
|
938 |
return 0; |
|
939 |
} |
|
940 |
||
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
941 |
/** |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
942 |
* Draws a tunnel of bridge tile. |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
943 |
* For tunnels, this is rather simple, as you only needa draw the entrance. |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
944 |
* Bridges are a bit more complex. base_offset is where the sprite selection comes into play |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
945 |
* and it works a bit like a bitmask.<p> For bridge heads: |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
946 |
* <ul><li>Bit 0: direction</li> |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
947 |
* <li>Bit 1: northern or southern heads</li> |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
948 |
* <li>Bit 2: Set if the bridge head is sloped</li> |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
949 |
* <li>Bit 3 and more: Railtype Specific subset</li> |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
950 |
* </ul> |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
951 |
* For middle parts: |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
952 |
* <ul><li>Bits 0-1: need to be 0</li> |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
953 |
* <li>Bit 2: direction</li> |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
954 |
* <li>Bit 3 and above: Railtype Specific subset</li> |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
955 |
* </ul> |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
956 |
* Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3 |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
957 |
*/ |
0 | 958 |
static void DrawTile_TunnelBridge(TileInfo *ti) |
959 |
{ |
|
960 |
uint32 image; |
|
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
961 |
const PalSpriteID *b; |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
962 |
bool ice = _m[ti->tile].m4 & 0x80; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
963 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
964 |
// draw tunnel? |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
965 |
if ((ti->map5 & 0xF0) == 0) { |
3154 | 966 |
if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) { |
2511
3eb6cb6b750d
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
967 |
image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel; |
3eb6cb6b750d
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
968 |
} else { |
3eb6cb6b750d
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
969 |
image = SPR_TUNNEL_ENTRY_REAR_ROAD; |
3eb6cb6b750d
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
970 |
} |
0 | 971 |
|
2511
3eb6cb6b750d
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
972 |
if (ice) image += 32; |
0 | 973 |
|
3154 | 974 |
image += GetTunnelDirection(ti->tile) * 2; |
0 | 975 |
DrawGroundSprite(image); |
976 |
||
977 |
AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z); |
|
978 |
// draw bridge? |
|
2644 | 979 |
} else if (ti->map5 & 0x80) { |
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
980 |
RailType rt; |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
981 |
int base_offset; |
0 | 982 |
|
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
983 |
if (HASBIT(ti->map5, 1)) { /* This is a road bridge */ |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
984 |
base_offset = 8; |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
985 |
} else { /* Rail bridge */ |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
986 |
if (HASBIT(ti->map5, 6)) { /* The bits we need depend on the fact whether it is a bridge head or not */ |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
987 |
rt = GB(_m[ti->tile].m3, 4, 3); |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
988 |
} else { |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
989 |
rt = GB(_m[ti->tile].m3, 0, 3); |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
990 |
} |
0 | 991 |
|
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
992 |
base_offset = GetRailTypeInfo(rt)->bridge_offset; |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
993 |
assert(base_offset != 8); /* This one is used for roads */ |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
994 |
} |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
995 |
|
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
996 |
/* as the lower 3 bits are used for other stuff, make sure they are clear */ |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
997 |
assert( (base_offset & 0x07) == 0x00); |
0 | 998 |
|
999 |
if (!(ti->map5 & 0x40)) { // bridge ramps |
|
1000 |
if (!(BRIDGE_NO_FOUNDATION & (1 << ti->tileh))) { // no foundations for 0, 3, 6, 9, 12 |
|
1001 |
int f = GetBridgeFoundation(ti->tileh, ti->map5 & 0x1); // pass direction |
|
1002 |
if (f) DrawFoundation(ti, f); |
|
1003 |
} |
|
1004 |
||
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1005 |
/* Cope for the direction of the bridge */ |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1006 |
if (HASBIT(ti->map5, 0)) base_offset++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1007 |
|
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1008 |
if (ti->map5 & 0x20) base_offset += 2; // which side |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1009 |
if (ti->tileh == 0) base_offset += 4; // sloped bridge head |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1010 |
|
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1011 |
/* Table number 6 always refers to the bridge heads for any bridge type */ |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1012 |
image = GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset]; |
0 | 1013 |
|
1014 |
if (!ice) { |
|
1015 |
DrawClearLandTile(ti, 3); |
|
1016 |
} else { |
|
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2511
diff
changeset
|
1017 |
DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh]); |
0 | 1018 |
} |
1019 |
||
1020 |
// draw ramp |
|
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1021 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1022 |
AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z); |
1023 |
} else { |
|
1024 |
// bridge middle part. |
|
1025 |
uint z; |
|
1026 |
int x,y; |
|
1027 |
||
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1028 |
image = GB(ti->map5, 3, 2); // type of stuff under bridge (only defined for 0,1) |
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1029 |
/** @todo So why do we even WASTE that one bit?! (map5, bit 4) */ |
0 | 1030 |
assert(image <= 1); |
1031 |
||
1032 |
if (!(ti->map5 & 0x20)) { |
|
1033 |
// draw land under bridge |
|
2254
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2187
diff
changeset
|
1034 |
if (ice) image += 2; |
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1035 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1036 |
if (image != 1 || ti->tileh == 0) { |
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1037 |
DrawGroundSprite(_bridge_land_below[image] + _tileh_to_sprite[ti->tileh]); |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1038 |
} else { |
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1039 |
DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1040 |
} |
0 | 1041 |
|
1042 |
// draw canal water? |
|
1043 |
if (ti->map5 & 8 && ti->z != 0) DrawCanalWater(ti->tile); |
|
1044 |
} else { |
|
1045 |
// draw transport route under bridge |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1046 |
|
0 | 1047 |
// draw foundation? |
1048 |
if (ti->tileh) { |
|
1049 |
int f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1050 |
if (f) DrawFoundation(ti, f); |
|
1051 |
} |
|
1052 |
||
1053 |
if (!(image&1)) { |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1054 |
const RailtypeInfo *rti = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4)); |
0 | 1055 |
// railway |
2535 | 1056 |
image = SPR_RAIL_TRACK_Y + (ti->map5 & 1); |
1057 |
if (ti->tileh != 0) image = SPR_RAIL_TRACK_Y + _track_sloped_sprites[ti->tileh - 1]; |
|
2254
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2187
diff
changeset
|
1058 |
image += rti->total_offset; |
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2187
diff
changeset
|
1059 |
if (ice) image += rti->snow_offset; |
0 | 1060 |
} else { |
1061 |
// road |
|
2535 | 1062 |
image = SPR_ROAD_Y + (ti->map5 & 1); |
0 | 1063 |
if (ti->tileh != 0) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1064 |
if (ice) image += 19; |
0 | 1065 |
} |
1066 |
DrawGroundSprite(image); |
|
1067 |
} |
|
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1068 |
|
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1069 |
/* Cope for the direction of the bridge */ |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1070 |
if (HASBIT(ti->map5, 0)) base_offset += 4; |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1071 |
|
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1072 |
/* base_offset needs to be 0 due to the structure of the sprite table see table/bridge_land.h */ |
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1073 |
assert( (base_offset & 0x03) == 0x00); |
0 | 1074 |
// get bridge sprites |
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1075 |
b = GetBridgeSpriteTable(GetBridgeType(ti->tile), GetBridgePiece(ti->tile)) + base_offset; |
0 | 1076 |
|
1077 |
z = GetBridgeHeight(ti) + 5; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1078 |
|
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1079 |
// draw rail or road component |
0 | 1080 |
image = b[0]; |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1081 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1082 |
AddSortableSpriteToDraw(image, ti->x, ti->y, (ti->map5&1)?11:16, (ti->map5&1)?16:11, 1, z); |
1083 |
||
1084 |
x = ti->x; |
|
1085 |
y = ti->y; |
|
1086 |
image = b[1]; |
|
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1087 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1088 |
|
2536
634914d741b4
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1089 |
// draw roof, the component of the bridge which is logically between the vehicle and the camera |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1090 |
if (ti->map5 & 1) { |
0 | 1091 |
x += 12; |
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
1092 |
if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 1, 16, 0x28, z); |
0 | 1093 |
} else { |
1094 |
y += 12; |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
1095 |
if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 16, 1, 0x28, z); |
0 | 1096 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1097 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1098 |
if (ti->z + 5 == z) { |
0 | 1099 |
// draw poles below for small bridges |
1100 |
image = b[2]; |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1101 |
if (image != 0) { |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1102 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1103 |
DrawGroundSpriteAt(image, x, y, z); |
1104 |
} |
|
1105 |
} else if (_patches.bridge_pillars) { |
|
1106 |
// draw pillars below for high bridges |
|
1107 |
DrawBridgePillars(ti, x, y, z); |
|
1108 |
} |
|
1109 |
} |
|
1110 |
} |
|
1111 |
} |
|
1112 |
||
2537 | 1113 |
static uint GetSlopeZ_TunnelBridge(const TileInfo* ti) |
1114 |
{ |
|
0 | 1115 |
uint z = ti->z; |
1116 |
uint x = ti->x & 0xF; |
|
1117 |
uint y = ti->y & 0xF; |
|
2537 | 1118 |
uint tileh = ti->tileh; |
0 | 1119 |
|
1120 |
// swap directions if Y tunnel/bridge to let the code handle the X case only. |
|
1884
804ff5f94ed0
(svn r2390) - Codechange: Fix some warnings on GCC 4.0.0
hackykid
parents:
1784
diff
changeset
|
1121 |
if (ti->map5 & 1) uintswap(x,y); |
0 | 1122 |
|
1123 |
// to the side of the tunnel/bridge? |
|
1124 |
if (IS_INT_INSIDE(y, 5, 10+1)) { |
|
1125 |
// tunnel? |
|
2639 | 1126 |
if ((ti->map5 & 0xF0) == 0) return z; |
0 | 1127 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1128 |
// bridge? |
2639 | 1129 |
if (ti->map5 & 0x80) { |
0 | 1130 |
// bridge ending? |
1131 |
if (!(ti->map5 & 0x40)) { |
|
2537 | 1132 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) // 7, 11, 13, 14 |
0 | 1133 |
z += 8; |
1134 |
||
1135 |
// no ramp for bridge ending |
|
2537 | 1136 |
if ((BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << tileh) || BRIDGE_NO_FOUNDATION & (1 << tileh)) && tileh != 0) { |
0 | 1137 |
return z + 8; |
1138 |
} else if (!(ti->map5 & 0x20)) { // northern / southern ending |
|
1139 |
// ramp |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1140 |
return z + (x >> 1) + 1; |
0 | 1141 |
} else { |
1142 |
// ramp in opposite dir |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1143 |
return z + ((x ^ 0xF) >> 1); |
0 | 1144 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1145 |
|
0 | 1146 |
// bridge middle part |
1147 |
} else { |
|
1148 |
// build on slopes? |
|
2537 | 1149 |
if (tileh != 0) z += 8; |
0 | 1150 |
|
1151 |
// keep the same elevation because we're on the bridge? |
|
2639 | 1152 |
if (_get_z_hint >= z + 8) return _get_z_hint; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1153 |
|
0 | 1154 |
// actually on the bridge, but not yet in the shared area. |
2639 | 1155 |
if (!IS_INT_INSIDE(x, 5, 10 + 1)) return GetBridgeHeight(ti) + 8; |
0 | 1156 |
|
1157 |
// in the shared area, assume that we're below the bridge, cause otherwise the hint would've caught it. |
|
1158 |
// if rail or road below then it means it's possibly build on slope below the bridge. |
|
1159 |
if (ti->map5 & 0x20) { |
|
2537 | 1160 |
uint f = _bridge_foundations[ti->map5 & 1][tileh]; |
0 | 1161 |
// make sure that the slope is not inclined foundation |
1162 |
if (IS_BYTE_INSIDE(f, 1, 15)) return z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1163 |
|
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2422
diff
changeset
|
1164 |
// change foundation type? XXX - should be const; accessor function! |
2537 | 1165 |
if (f != 0) tileh = _inclined_tileh[f - 15]; |
0 | 1166 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1167 |
|
0 | 1168 |
// no transport route, fallback to default |
1169 |
} |
|
1170 |
} |
|
1171 |
} else { |
|
1172 |
// if it's a bridge middle with transport route below, then we need to compensate for build on slopes |
|
2639 | 1173 |
if ((ti->map5 & (0x80 | 0x40 | 0x20)) == (0x80 | 0x40 | 0x20)) { |
0 | 1174 |
uint f; |
2537 | 1175 |
if (tileh != 0) z += 8; |
2639 | 1176 |
f = _bridge_foundations[ti->map5 & 1][tileh]; |
0 | 1177 |
if (IS_BYTE_INSIDE(f, 1, 15)) return z; |
2537 | 1178 |
if (f != 0) tileh = _inclined_tileh[f - 15]; |
0 | 1179 |
} |
1180 |
} |
|
1181 |
||
1182 |
// default case |
|
2639 | 1183 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh) + ti->z; |
0 | 1184 |
} |
1185 |
||
2639 | 1186 |
static uint GetSlopeTileh_TunnelBridge(const TileInfo* ti) |
1187 |
{ |
|
39 | 1188 |
// not accurate, but good enough for slope graphics drawing |
1189 |
return 0; |
|
1190 |
} |
|
1191 |
||
1192 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1193 |
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac) |
0 | 1194 |
{ |
1195 |
/* not used */ |
|
1196 |
} |
|
1197 |
||
1198 |
static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = { |
|
1199 |
STR_501F_WOODEN_RAIL_BRIDGE, |
|
1200 |
STR_5020_CONCRETE_RAIL_BRIDGE, |
|
1201 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1202 |
STR_501E_REINFORCED_CONCRETE_SUSPENSION, |
|
1203 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1204 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1205 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1206 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1207 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1208 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1209 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1210 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1211 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1212 |
0,0,0, |
|
1213 |
||
1214 |
STR_5025_WOODEN_ROAD_BRIDGE, |
|
1215 |
STR_5026_CONCRETE_ROAD_BRIDGE, |
|
1216 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1217 |
STR_5024_REINFORCED_CONCRETE_SUSPENSION, |
|
1218 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1219 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1220 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1221 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1222 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1223 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1224 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1225 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1226 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1227 |
0,0,0, |
|
1228 |
}; |
|
1229 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1230 |
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td) |
0 | 1231 |
{ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1232 |
if ((_m[tile].m5 & 0x80) == 0) { |
3154 | 1233 |
td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ? |
1234 |
STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL; |
|
0 | 1235 |
} else { |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1236 |
td->str = _bridge_tile_str[GB(_m[tile].m5, 1, 2) << 4 | GB(_m[tile].m2, 4, 4)]; |
0 | 1237 |
|
1238 |
/* scan to the end of the bridge, that's where the owner is stored */ |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1239 |
if (_m[tile].m5 & 0x40) { |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1240 |
TileIndexDiff delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); |
1981 | 1241 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1242 |
do tile += delta; while (_m[tile].m5 & 0x40); |
0 | 1243 |
} |
1244 |
} |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1245 |
td->owner = GetTileOwner(tile); |
0 | 1246 |
} |
1247 |
||
1248 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1249 |
static void AnimateTile_TunnelBridge(TileIndex tile) |
0 | 1250 |
{ |
1251 |
/* not used */ |
|
1252 |
} |
|
1253 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1254 |
static void TileLoop_TunnelBridge(TileIndex tile) |
0 | 1255 |
{ |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1256 |
switch (_opt.landscape) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1257 |
case LT_HILLY: |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1258 |
if (GetTileZ(tile) > _opt.snow_line) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1259 |
if (!(_m[tile].m4 & 0x80)) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1260 |
_m[tile].m4 |= 0x80; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1261 |
MarkTileDirtyByTile(tile); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1262 |
} |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1263 |
} else { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1264 |
if (_m[tile].m4 & 0x80) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1265 |
_m[tile].m4 &= ~0x80; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1266 |
MarkTileDirtyByTile(tile); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1267 |
} |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1268 |
} |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1269 |
break; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1270 |
|
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1271 |
case LT_DESERT: |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1272 |
if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1273 |
_m[tile].m4 |= 0x80; |
0 | 1274 |
MarkTileDirtyByTile(tile); |
1275 |
} |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1276 |
break; |
0 | 1277 |
} |
1278 |
||
1279 |
// if it's a bridge with water below, call tileloop_water on it. |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1280 |
if ((_m[tile].m5 & 0xF8) == 0xC8) TileLoop_Water(tile); |
0 | 1281 |
} |
1282 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1283 |
static void ClickTile_TunnelBridge(TileIndex tile) |
0 | 1284 |
{ |
1285 |
/* not used */ |
|
1286 |
} |
|
1287 |
||
1288 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1289 |
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode) |
0 | 1290 |
{ |
1291 |
uint32 result; |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1292 |
byte m5 = _m[tile].m5; |
0 | 1293 |
|
1294 |
if ((m5 & 0xF0) == 0) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1295 |
/* This is a tunnel */ |
3154 | 1296 |
if (GetTunnelTransportType(tile) == mode) { |
1297 |
return DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? 0x101 : 0x202; |
|
0 | 1298 |
} |
1299 |
} else if (m5 & 0x80) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1300 |
/* This is a bridge */ |
0 | 1301 |
result = 0; |
2635 | 1302 |
if (GB(m5, 1, 2) == mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1303 |
/* Transport over the bridge is compatible */ |
2639 | 1304 |
result = m5 & 1 ? 0x202 : 0x101; |
0 | 1305 |
} |
1306 |
if (m5 & 0x40) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1307 |
/* Bridge middle part */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1308 |
if (!(m5 & 0x20)) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1309 |
/* Clear ground or water underneath */ |
2639 | 1310 |
if ((m5 & 0x18) != 8) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1311 |
/* Clear ground */ |
0 | 1312 |
return result; |
2639 | 1313 |
} else { |
1314 |
if (mode != TRANSPORT_WATER) return result; |
|
1315 |
} |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1316 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1317 |
/* Transport underneath */ |
2639 | 1318 |
if (GB(m5, 3, 2) != mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1319 |
/* Incompatible transport underneath */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1320 |
return result; |
2639 | 1321 |
} |
0 | 1322 |
} |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1323 |
/* If we've not returned yet, there is a compatible |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1324 |
* transport or water beneath, so we can add it to |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1325 |
* result */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1326 |
/* Why is this xor'd ? Can't it just be or'd? */ |
2639 | 1327 |
result ^= m5 & 1 ? 0x101 : 0x202; |
0 | 1328 |
} |
1329 |
return result; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1330 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1331 |
assert(0); /* This should never occur */ |
0 | 1332 |
} |
1333 |
return 0; |
|
1334 |
} |
|
1335 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2422
diff
changeset
|
1336 |
static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 1337 |
{ |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1338 |
if (!IsTileOwner(tile, old_player)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1339 |
|
2502 | 1340 |
if (new_player != OWNER_SPECTATOR) { |
1902 | 1341 |
SetTileOwner(tile, new_player); |
0 | 1342 |
} else { |
2639 | 1343 |
if ((_m[tile].m5 & 0xC0) == 0xC0) { |
0 | 1344 |
// the stuff BELOW the middle part is owned by the deleted player. |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1345 |
if (!(_m[tile].m5 & (1 << 4 | 1 << 3))) { |
0 | 1346 |
// convert railway into grass. |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1347 |
_m[tile].m5 &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore.. |
0 | 1348 |
} else { |
1349 |
// for road, change the owner of the road to local authority |
|
1902 | 1350 |
SetTileOwner(tile, OWNER_NONE); |
0 | 1351 |
} |
1352 |
} else { |
|
1353 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1354 |
} |
|
1355 |
} |
|
1356 |
} |
|
1357 |
||
1358 |
||
1359 |
static const byte _tunnel_fractcoord_1[4] = {0x8E,0x18,0x81,0xE8}; |
|
1360 |
static const byte _tunnel_fractcoord_2[4] = {0x81,0x98,0x87,0x38}; |
|
1361 |
static const byte _tunnel_fractcoord_3[4] = {0x82,0x88,0x86,0x48}; |
|
1362 |
static const byte _exit_tunnel_track[4] = {1,2,1,2}; |
|
1363 |
||
1364 |
static const byte _road_exit_tunnel_state[4] = {8, 9, 0, 1}; |
|
1365 |
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4}; |
|
1366 |
||
1367 |
static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29}; |
|
1368 |
static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25}; |
|
1369 |
static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45}; |
|
1370 |
static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49}; |
|
1371 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1372 |
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1373 |
{ |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1374 |
if (GB(_m[tile].m5, 4, 4) == 0) { |
2989 | 1375 |
int z = GetSlopeZ(x, y) - v->z_pos; |
1376 |
byte fc; |
|
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1377 |
DiagDirection dir; |
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1378 |
DiagDirection vdir; |
2989 | 1379 |
|
2951 | 1380 |
if (myabs(z) > 2) return 8; |
0 | 1381 |
|
1382 |
if (v->type == VEH_Train) { |
|
2951 | 1383 |
fc = (x & 0xF) + (y << 4); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1384 |
|
3154 | 1385 |
dir = GetTunnelDirection(tile); |
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1386 |
vdir = DirToDiagDir(v->direction); |
0 | 1387 |
|
1388 |
if (v->u.rail.track != 0x40 && dir == vdir) { |
|
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2663
diff
changeset
|
1389 |
if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) { |
0 | 1390 |
if (v->spritenum < 4) |
541 | 1391 |
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); |
0 | 1392 |
return 0; |
1393 |
} |
|
1394 |
if (fc == _tunnel_fractcoord_2[dir]) { |
|
1395 |
v->tile = tile; |
|
1396 |
v->u.rail.track = 0x40; |
|
1397 |
v->vehstatus |= VS_HIDDEN; |
|
1398 |
return 4; |
|
1399 |
} |
|
1400 |
} |
|
1401 |
||
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1402 |
if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) { |
22 | 1403 |
/* We're at the tunnel exit ?? */ |
0 | 1404 |
v->tile = tile; |
1405 |
v->u.rail.track = _exit_tunnel_track[dir]; |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1209
diff
changeset
|
1406 |
assert(v->u.rail.track); |
0 | 1407 |
v->vehstatus &= ~VS_HIDDEN; |
1408 |
return 4; |
|
1409 |
} |
|
1410 |
} else if (v->type == VEH_Road) { |
|
2951 | 1411 |
fc = (x & 0xF) + (y << 4); |
3154 | 1412 |
dir = GetTunnelDirection(tile); |
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1413 |
vdir = DirToDiagDir(v->direction); |
0 | 1414 |
|
1415 |
// Enter tunnel? |
|
1416 |
if (v->u.road.state != 0xFF && dir == vdir) { |
|
1417 |
if (fc == _tunnel_fractcoord_4[dir] || |
|
1418 |
fc == _tunnel_fractcoord_5[dir]) { |
|
1419 |
v->tile = tile; |
|
1420 |
v->u.road.state = 0xFF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1421 |
v->vehstatus |= VS_HIDDEN; |
0 | 1422 |
return 4; |
1423 |
} else { |
|
1424 |
return 0; |
|
1425 |
} |
|
1426 |
} |
|
1427 |
||
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1428 |
if (dir == ReverseDiagDir(vdir) && ( |
2951 | 1429 |
/* We're at the tunnel exit ?? */ |
1430 |
fc == _tunnel_fractcoord_6[dir] || |
|
1431 |
fc == _tunnel_fractcoord_7[dir] |
|
1432 |
) && |
|
0 | 1433 |
z == 0) { |
1434 |
v->tile = tile; |
|
1435 |
v->u.road.state = _road_exit_tunnel_state[dir]; |
|
1436 |
v->u.road.frame = _road_exit_tunnel_frame[dir]; |
|
1437 |
v->vehstatus &= ~VS_HIDDEN; |
|
1438 |
return 4; |
|
1439 |
} |
|
1440 |
} |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1441 |
} else if (_m[tile].m5 & 0x80) { |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2663
diff
changeset
|
1442 |
if (v->type == VEH_Road || (v->type == VEH_Train && IsFrontEngine(v))) { |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1443 |
uint h; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1444 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1445 |
// Compensate for possible foundation |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1446 |
if (GetTileSlope(tile, &h) != 0) h += 8; |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1447 |
if (!(_m[tile].m5 & 0x40) || // start/end tile of bridge |
334
7e87a24e88b5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1448 |
myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge |
0 | 1449 |
/* modify speed of vehicle */ |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
1450 |
uint16 spd = _bridge[GetBridgeType(tile)].speed; |
2639 | 1451 |
if (v->type == VEH_Road) spd *= 2; |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1452 |
if (v->cur_speed > spd) v->cur_speed = spd; |
0 | 1453 |
} |
1454 |
} |
|
1455 |
} |
|
1456 |
return 0; |
|
1457 |
} |
|
1458 |
||
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1459 |
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v) |
0 | 1460 |
{ |
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1461 |
TileIndex tile; |
1981 | 1462 |
TileIndexDiff delta = (v->direction & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1463 |
byte z = v->z_pos; |
0 | 1464 |
|
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1465 |
for (tile = v->tile;; tile += delta) { |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1466 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0 && |
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1467 |
GetTileZ(tile) == z) |
0 | 1468 |
break; |
1469 |
} |
|
1470 |
return tile; |
|
1471 |
} |
|
1472 |
||
1473 |
const TileTypeProcs _tile_type_tunnelbridge_procs = { |
|
1474 |
DrawTile_TunnelBridge, /* draw_tile_proc */ |
|
1475 |
GetSlopeZ_TunnelBridge, /* get_slope_z_proc */ |
|
1476 |
ClearTile_TunnelBridge, /* clear_tile_proc */ |
|
1477 |
GetAcceptedCargo_TunnelBridge, /* get_accepted_cargo_proc */ |
|
1478 |
GetTileDesc_TunnelBridge, /* get_tile_desc_proc */ |
|
1479 |
GetTileTrackStatus_TunnelBridge,/* get_tile_track_status_proc */ |
|
1480 |
ClickTile_TunnelBridge, /* click_tile_proc */ |
|
1481 |
AnimateTile_TunnelBridge, /* animate_tile_proc */ |
|
1482 |
TileLoop_TunnelBridge, /* tile_loop_clear */ |
|
1483 |
ChangeTileOwner_TunnelBridge, /* change_tile_owner_clear */ |
|
1484 |
NULL, /* get_produced_cargo_proc */ |
|
1485 |
VehicleEnter_TunnelBridge, /* vehicle_enter_tile_proc */ |
|
1486 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1487 |
GetSlopeTileh_TunnelBridge, /* get_slope_tileh_proc */ |
0 | 1488 |
}; |