author | bjarni |
Sat, 06 Aug 2005 16:07:22 +0000 | |
changeset 2293 | b48192aec903 |
parent 2262 | 252cfd94c54d |
child 2314 | 82775d31c045 |
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" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
10 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
11 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
12 |
#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
|
13 |
#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
|
14 |
#include "tile.h" |
0 | 15 |
#include "vehicle.h" |
16 |
#include "viewport.h" |
|
17 |
#include "command.h" |
|
18 |
#include "player.h" |
|
19 |
#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
|
20 |
#include "sound.h" |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
21 |
#include "pbs.h" |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
22 |
#include "debug.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" |
0 | 25 |
|
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
26 |
#include "table/bridge_land.h" |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
27 |
#include "table/tunnel_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 |
|
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
|
34 |
const Bridge _bridge[] = { |
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 |
| | | | | | | */ |
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
|
43 |
{ 0, 0, 16, 80, 32, 0xA24 , STR_5012_WOODEN }, |
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
|
44 |
{ 0, 0, 2, 112, 48, 0xA26 | PALETTE_TO_STRUCT_RED , STR_5013_CONCRETE }, |
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
|
45 |
{ 10, 0, 5, 144, 64, 0xA25 , STR_500F_GIRDER_STEEL }, |
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
|
46 |
{ 0, 2, 10, 168, 80, 0xA22 | PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE }, |
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
|
47 |
{ 10, 3, 16, 185, 96, 0xA22 , STR_500E_SUSPENSION_STEEL }, |
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
|
48 |
{ 10, 3, 16, 192, 112, 0xA22 | PALETTE_TO_STRUCT_YELLOW , STR_500E_SUSPENSION_STEEL }, |
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
|
49 |
{ 10, 3, 7, 224, 160, 0xA23 , STR_5010_CANTILEVER_STEEL }, |
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
|
50 |
{ 10, 3, 8, 232, 208, 0xA23 | PALETTE_TO_STRUCT_BROWN , STR_5010_CANTILEVER_STEEL }, |
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
|
51 |
{ 10, 3, 9, 248, 240, 0xA23 | PALETTE_TO_STRUCT_RED , STR_5010_CANTILEVER_STEEL }, |
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
|
52 |
{ 10, 0, 2, 240, 256, 0xA27 , STR_500F_GIRDER_STEEL }, |
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
|
53 |
{ 75, 2, 16, 255, 320, 0xA28 , STR_5014_TUBULAR_STEEL }, |
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
|
54 |
{ 85, 2, 32, 380, 512, 0xA28 | PALETTE_TO_STRUCT_YELLOW , STR_5014_TUBULAR_STEEL }, |
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
|
55 |
{ 90, 2, 32, 510, 608, 0xA28 | PALETTE_TO_STRUCT_GREY , STR_BRIDGE_TUBULAR_SILICON } |
0 | 56 |
}; |
57 |
||
58 |
// calculate the price factor for building a long bridge. |
|
59 |
// 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, |
|
60 |
int CalcBridgeLenCostFactor(int x) |
|
61 |
{ |
|
62 |
int n,r; |
|
63 |
if (x < 2) return x; |
|
64 |
x -= 2; |
|
65 |
for(n=0,r=2;;n++) { |
|
66 |
if (x <= n) return r + x * n; |
|
67 |
r += n * n; |
|
68 |
x -= n; |
|
69 |
} |
|
70 |
} |
|
71 |
||
72 |
enum { |
|
73 |
// foundation, whole tile is leveled up (tileh's 7, 11, 13, 14) --> 3 corners raised |
|
74 |
BRIDGE_FULL_LEVELED_FOUNDATION = 1 << 7 | 1 << 11 | 1 << 13 | 1 << 14, |
|
75 |
// foundation, tile is partly leveled up (tileh's 1, 2, 4, 8) --> 1 corner raised |
|
76 |
BRIDGE_PARTLY_LEVELED_FOUNDATION = 1 << 1 | 1 << 2 | 1 << 4 | 1 << 8, |
|
77 |
// no foundations (X,Y direction) (tileh's 0, 3, 6, 9, 12) |
|
78 |
BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12, |
|
79 |
}; |
|
80 |
||
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
|
81 |
/** |
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
|
82 |
* 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
|
83 |
* @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
|
84 |
* @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
|
85 |
*/ |
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
|
86 |
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
|
87 |
{ |
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
|
88 |
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
|
89 |
} |
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
|
90 |
|
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
|
91 |
/** |
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
|
92 |
* 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
|
93 |
* @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
|
94 |
* @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
|
95 |
*/ |
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
|
96 |
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
|
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 |
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
|
99 |
} |
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 |
|
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 |
/** check if bridge can be built on slope |
0 | 102 |
* direction 0 = X-axis, direction 1 = Y-axis |
103 |
* is_start_tile = false <-- end tile |
|
104 |
* is_start_tile = true <-- start tile |
|
105 |
*/ |
|
106 |
static uint32 CheckBridgeSlope(uint direction, uint tileh, bool is_start_tile) |
|
107 |
{ |
|
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
108 |
if (!IsSteepTileh(tileh)) { // disable building on very steep slopes |
0 | 109 |
|
110 |
if (is_start_tile) { |
|
111 |
/* check slope at start tile |
|
112 |
- no extra cost |
|
113 |
- direction X: tiles 0,12 |
|
114 |
- direction Y: tiles 0, 9 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
115 |
*/ |
0 | 116 |
if ((direction?0x201:0x1001) & (1 << tileh)) |
117 |
return 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
118 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
119 |
// disallow certain start tiles to avoid certain crooked bridges |
0 | 120 |
if (tileh == 2) |
121 |
return CMD_ERROR; |
|
122 |
||
123 |
} |
|
124 |
else { |
|
125 |
/* check slope at end tile |
|
126 |
- no extra cost |
|
127 |
- direction X: tiles 0, 3 |
|
128 |
- direction Y: tiles 0, 6 |
|
129 |
*/ |
|
130 |
if ((direction?0x41:0x9) & (1 << tileh)) |
|
131 |
return 0; |
|
132 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
133 |
// disallow certain end tiles to avoid certain crooked bridges |
0 | 134 |
if (tileh == 8) |
135 |
return CMD_ERROR; |
|
136 |
||
137 |
} |
|
138 |
||
139 |
/* disallow common start/end tiles to avoid certain crooked bridges e.g. |
|
140 |
* start-tile: X 2,1 Y 2,4 (2 was disabled before) |
|
141 |
* end-tile: X 8,4 Y 8,1 (8 was disabled before) |
|
142 |
*/ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
143 |
if ( (tileh == 1 && (is_start_tile != (bool)direction)) || |
0 | 144 |
(tileh == 4 && (is_start_tile == (bool)direction)) ) |
145 |
return CMD_ERROR; |
|
146 |
||
147 |
// slope foundations |
|
148 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh) || BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << tileh)) |
|
149 |
return _price.terraform; |
|
150 |
} |
|
151 |
||
152 |
return CMD_ERROR; |
|
153 |
} |
|
154 |
||
155 |
uint32 GetBridgeLength(TileIndex begin, TileIndex end) |
|
156 |
{ |
|
157 |
int x1, y1, x2, y2; // coordinates of starting and end tiles |
|
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
|
158 |
x1 = TileX(begin); |
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
|
159 |
y1 = TileY(begin); |
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
|
160 |
x2 = TileX(end); |
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
|
161 |
y2 = TileY(end); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
162 |
|
0 | 163 |
return abs((x2 + y2 - x1 - y1)) - 1; |
164 |
} |
|
165 |
||
166 |
bool CheckBridge_Stuff(byte bridge_type, int bridge_len) |
|
167 |
{ |
|
168 |
int max; // max possible length of a bridge (with patch 100) |
|
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
|
169 |
const Bridge *b = &_bridge[bridge_type]; |
0 | 170 |
|
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
|
171 |
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
|
172 |
if (b->avail_year > _cur_year) return false; |
0 | 173 |
|
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
|
174 |
max = b->max_length; |
0 | 175 |
if (max >= 16 && _patches.longbridges) |
176 |
max = 100; |
|
177 |
||
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
|
178 |
if (bridge_len < b->min_length || bridge_len > max) return false; |
0 | 179 |
|
180 |
return true; |
|
181 |
} |
|
182 |
||
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
|
183 |
/** 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
|
184 |
* @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
|
185 |
* @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
|
186 |
* @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
|
187 |
* - 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
|
188 |
* - p2 = (bit 8-..) - rail type. bit15 ((x>>8)&0x80) means road bridge. |
0 | 189 |
*/ |
190 |
int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
191 |
{ |
|
192 |
int bridge_type; |
|
193 |
byte rail_or_road, railtype, m5; |
|
194 |
int sx,sy; |
|
195 |
TileInfo ti_start, ti_end, ti; /* OPT: only 2 of those are ever used */ |
|
196 |
int bridge_len, odd_middle_part; |
|
197 |
uint direction; |
|
198 |
int i; |
|
199 |
int32 cost, terraformcost, ret; |
|
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
200 |
bool allow_on_slopes; |
0 | 201 |
|
202 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
203 |
|
0 | 204 |
/* 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
|
205 |
bridge_type = GB(p2, 0, 8); |
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
|
206 |
railtype = GB(p2, 8, 8); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
207 |
|
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
|
208 |
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
|
209 |
|
0 | 210 |
// type of bridge |
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
|
211 |
if (HASBIT(railtype, 7)) { // bit 15 of original p2 param |
0 | 212 |
railtype = 0; |
213 |
rail_or_road = 2; |
|
214 |
} else { |
|
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
|
215 |
if (!ValParamRailtype(railtype)) return CMD_ERROR; |
0 | 216 |
rail_or_road = 0; |
217 |
} |
|
218 |
||
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
|
219 |
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
|
220 |
sy = TileY(p1) * 16; |
0 | 221 |
|
222 |
direction = 0; |
|
223 |
||
224 |
/* check if valid, and make sure that (x,y) are smaller than (sx,sy) */ |
|
225 |
if (x == sx) { |
|
226 |
if (y == sy) |
|
227 |
return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); |
|
228 |
direction = 1; |
|
229 |
if (y > sy) { |
|
230 |
intswap(y,sy); |
|
231 |
intswap(x,sx); |
|
232 |
} |
|
233 |
} else if (y == sy) { |
|
234 |
if (x > sx) { |
|
235 |
intswap(y,sy); |
|
236 |
intswap(x,sx); |
|
237 |
} |
|
238 |
} else |
|
239 |
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); |
|
240 |
||
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
|
241 |
/* 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
|
242 |
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
|
243 |
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
|
244 |
|
0 | 245 |
/* retrieve landscape height and ensure it's on land */ |
246 |
if ( |
|
247 |
((FindLandscapeHeight(&ti_end, sx, sy), |
|
248 |
ti_end.type == MP_WATER) && ti_end.map5 == 0) || |
|
249 |
((FindLandscapeHeight(&ti_start, x, y), |
|
250 |
ti_start.type == MP_WATER) && ti_start.map5 == 0)) |
|
251 |
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH); |
|
252 |
||
253 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_start.tileh)) { |
|
254 |
ti_start.z += 8; |
|
255 |
ti_start.tileh = 0; |
|
256 |
} |
|
257 |
||
258 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_end.tileh)) { |
|
259 |
ti_end.z += 8; |
|
260 |
ti_end.tileh = 0; |
|
261 |
} |
|
262 |
||
263 |
if (ti_start.z != ti_end.z) |
|
264 |
return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); |
|
265 |
||
266 |
_error_message = STR_500C; |
|
267 |
||
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
268 |
|
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
269 |
// Towns are not allowed to use bridges on slopes. |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
270 |
allow_on_slopes = ((!_is_ai_player || _patches.ainew_active) |
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
|
271 |
&& _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
|
272 |
|
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
273 |
/* 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
|
274 |
|
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
|
275 |
if (CmdFailed(ret = DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) |
0 | 276 |
return CMD_ERROR; |
277 |
cost = ret; |
|
278 |
||
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
279 |
// 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
|
280 |
terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true); |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
281 |
if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes)) |
0 | 282 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
283 |
cost += terraformcost; |
|
284 |
||
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
285 |
/* 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
|
286 |
|
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
|
287 |
if (CmdFailed(ret = DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) |
0 | 288 |
return CMD_ERROR; |
289 |
cost += ret; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
290 |
|
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
291 |
// false - end tile slope check |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
292 |
terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false); |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
293 |
if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes)) |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
294 |
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
|
295 |
cost += terraformcost; |
0 | 296 |
|
297 |
||
298 |
/* do the drill? */ |
|
299 |
if (flags & DC_EXEC) { |
|
300 |
/* build the start tile */ |
|
301 |
ModifyTile(ti_start.tile, |
|
302 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
303 |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
304 |
(bridge_type << 4), /* map2 */ |
|
305 |
railtype, /* map3_lo */ |
|
306 |
0x80 | direction | rail_or_road /* map5 */ |
|
307 |
); |
|
308 |
||
309 |
/* build the end tile */ |
|
310 |
ModifyTile(ti_end.tile, |
|
311 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
312 |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
313 |
(bridge_type << 4), /* map2 */ |
|
314 |
railtype, /* map3_lo */ |
|
315 |
0x80 | 0x20 | direction | rail_or_road /* map5 */ |
|
316 |
); |
|
317 |
} |
|
318 |
||
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
|
319 |
// 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
|
320 |
odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len; |
0 | 321 |
|
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
|
322 |
for (i = 0; i != bridge_len; i++) { |
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
|
323 |
if (direction != 0) { |
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
|
324 |
y += 16; |
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
|
325 |
} else |
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
|
326 |
x += 16; |
0 | 327 |
|
328 |
FindLandscapeHeight(&ti, x, y); |
|
329 |
||
330 |
_error_message = STR_5009_LEVEL_LAND_OR_WATER_REQUIRED; |
|
331 |
if (ti.tileh != 0 && ti.z >= ti_start.z) |
|
332 |
return CMD_ERROR; |
|
333 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
334 |
// Find ship below |
0 | 335 |
if ( ti.type == MP_WATER && !EnsureNoVehicle(ti.tile) ) |
336 |
{ |
|
337 |
_error_message = STR_980E_SHIP_IN_THE_WAY; |
|
338 |
return CMD_ERROR; |
|
339 |
} |
|
340 |
||
341 |
if (ti.type == MP_WATER) { |
|
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
342 |
if (ti.map5 > 1) goto not_valid_below; |
0 | 343 |
m5 = 0xC8; |
344 |
} else if (ti.type == MP_RAILWAY) { |
|
345 |
if (direction == 0) { |
|
346 |
if (ti.map5 != 2) goto not_valid_below; |
|
347 |
} else { |
|
348 |
if (ti.map5 != 1) goto not_valid_below; |
|
349 |
} |
|
350 |
m5 = 0xE0; |
|
351 |
} else if (ti.type == MP_STREET) { |
|
352 |
if (direction == 0) { |
|
353 |
if (ti.map5 != 5) goto not_valid_below; |
|
354 |
} else { |
|
355 |
if (ti.map5 != 10) goto not_valid_below; |
|
356 |
} |
|
357 |
m5 = 0xE8; |
|
358 |
} else { |
|
359 |
not_valid_below:; |
|
360 |
/* try and clear the middle landscape */ |
|
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
|
361 |
if (CmdFailed(ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) |
0 | 362 |
return CMD_ERROR; |
363 |
cost += ret; |
|
364 |
m5 = 0xC0; |
|
365 |
} |
|
366 |
||
367 |
/* do middle part of bridge */ |
|
368 |
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
|
369 |
_m[ti.tile].m5 = (byte)(m5 | direction | rail_or_road); |
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
370 |
SetTileType(ti.tile, MP_TUNNELBRIDGE); |
0 | 371 |
|
372 |
//bridges pieces sequence (middle parts) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
373 |
// bridge len 1: 0 |
0 | 374 |
// bridge len 2: 0 1 |
375 |
// bridge len 3: 0 4 1 |
|
376 |
// bridge len 4: 0 2 3 1 |
|
377 |
// bridge len 5: 0 2 5 3 1 |
|
378 |
// bridge len 6: 0 2 3 2 3 1 |
|
379 |
// bridge len 7: 0 2 3 4 2 3 1 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
380 |
// #0 - alwats as first, #1 - always as last (if len>1) |
0 | 381 |
// #2,#3 are to pair in order |
382 |
// for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0) |
|
383 |
||
384 |
if(i==0) //first tile |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
385 |
m5 = 0; |
0 | 386 |
else if (i==bridge_len-1) //last tile |
387 |
m5 = 1; |
|
388 |
else if(i==odd_middle_part) //we are on the middle of odd bridge: #5 on even pos, #4 on odd |
|
389 |
m5 = 5 - (i%2); |
|
390 |
else { |
|
391 |
// 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
|
392 |
// this sequence swaps [... XOR (i>odd_middle_part)], |
0 | 393 |
// for even bridges XOR does not apply as odd_middle_part==bridge_len |
394 |
m5 = 2 + ((i%2==0)^(i>odd_middle_part)); |
|
395 |
} |
|
396 |
||
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
|
397 |
_m[ti.tile].m2 = (bridge_type << 4) | m5; |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
398 |
SB(_m[ti.tile].m3, 4, 4, railtype); |
0 | 399 |
|
400 |
MarkTileDirtyByTile(ti.tile); |
|
401 |
} |
|
402 |
} |
|
403 |
||
404 |
SetSignalsOnBothDir(ti_start.tile, (direction&1) ? 1 : 0); |
|
405 |
||
406 |
/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST) |
|
407 |
It's unnecessary to execute this command every time for every bridge. So it is done only |
|
408 |
and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated |
|
409 |
*/ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
410 |
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
|
411 |
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
|
412 |
|
0 | 413 |
bridge_len += 2; // begin and end tiles/ramps |
414 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
39
diff
changeset
|
415 |
if (_current_player < MAX_PLAYERS && !(_is_ai_player && !_patches.ainew_active)) |
0 | 416 |
bridge_len = CalcBridgeLenCostFactor(bridge_len); |
417 |
||
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
|
418 |
cost += ((int64)bridge_len * _price.build_bridge * b->price) >> 8; |
0 | 419 |
} |
420 |
||
421 |
return cost; |
|
422 |
} |
|
423 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
424 |
static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir) |
0 | 425 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
426 |
TileIndexDiff delta = TileOffsByDir(dir); |
0 | 427 |
TileInfo ti; |
428 |
||
429 |
do { |
|
430 |
tile -= delta; |
|
431 |
FindLandscapeHeightByTile(&ti, tile); |
|
432 |
} while (z < ti.z); |
|
433 |
||
434 |
if (z == ti.z && ti.type == MP_TUNNELBRIDGE && (ti.map5&0xF0) == 0 && (ti.map5&3) == dir) { |
|
435 |
_error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY; |
|
436 |
return false; |
|
437 |
} |
|
438 |
||
439 |
return true; |
|
440 |
} |
|
441 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
442 |
bool CheckTunnelInWay(TileIndex tile, int z) |
0 | 443 |
{ |
444 |
return DoCheckTunnelInWay(tile,z,0) && |
|
445 |
DoCheckTunnelInWay(tile,z,1) && |
|
446 |
DoCheckTunnelInWay(tile,z,2) && |
|
447 |
DoCheckTunnelInWay(tile,z,3); |
|
448 |
} |
|
449 |
||
450 |
static byte _build_tunnel_bh; |
|
451 |
static byte _build_tunnel_railtype; |
|
452 |
||
453 |
static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_tile) |
|
454 |
{ |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
455 |
TileIndex end_tile; |
0 | 456 |
int direction; |
457 |
int32 cost, ret; |
|
458 |
TileInfo ti; |
|
459 |
uint z; |
|
460 |
||
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
679
diff
changeset
|
461 |
if ((uint)x > MapMaxX() * 16 - 1 || (uint)y > MapMaxY() * 16 - 1) |
0 | 462 |
return CMD_ERROR; |
463 |
||
464 |
/* check if valid, and make sure that (x,y) is smaller than (x2,y2) */ |
|
465 |
direction = 0; |
|
466 |
if (x == x2) { |
|
467 |
if (y == y2) |
|
468 |
return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); |
|
469 |
direction++; |
|
470 |
if (y > y2) { |
|
471 |
intswap(y,y2); |
|
472 |
intswap(x,x2); |
|
473 |
exc_tile|=2; |
|
474 |
} |
|
475 |
} else if (y == y2) { |
|
476 |
if (x > x2) { |
|
477 |
intswap(y,y2); |
|
478 |
intswap(x,x2); |
|
479 |
exc_tile|=2; |
|
480 |
} |
|
481 |
} else |
|
482 |
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); |
|
483 |
||
484 |
cost = 0; |
|
485 |
||
486 |
FindLandscapeHeight(&ti, x2, y2); |
|
487 |
end_tile = ti.tile; |
|
488 |
z = ti.z; |
|
489 |
||
490 |
if (exc_tile != 3) { |
|
491 |
if ( (direction ? 9U : 12U) != ti.tileh) |
|
492 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
493 |
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
494 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 495 |
cost += ret; |
496 |
} |
|
497 |
cost += _price.build_tunnel; |
|
498 |
||
499 |
for(;;) { |
|
500 |
if (direction) y2-=16; else x2-=16; |
|
501 |
||
502 |
if (x2 == x && y2 == y) |
|
503 |
break; |
|
504 |
||
505 |
FindLandscapeHeight(&ti, x2, y2); |
|
506 |
if (ti.z <= z) |
|
507 |
return_cmd_error(STR_5002); |
|
508 |
||
509 |
if (!_cheats.crossing_tunnels.value && !CheckTunnelInWay(ti.tile, z)) |
|
510 |
return CMD_ERROR; |
|
511 |
||
512 |
cost += _price.build_tunnel; |
|
513 |
cost += (cost >> 3); |
|
514 |
||
515 |
if (cost >= 400000000) |
|
516 |
cost = 400000000; |
|
517 |
} |
|
518 |
||
519 |
FindLandscapeHeight(&ti, x2, y2); |
|
520 |
if (ti.z != z) |
|
521 |
return_cmd_error(STR_5004); |
|
522 |
||
523 |
if (exc_tile != 1) { |
|
524 |
if ( (direction ? 6U : 3U) != ti.tileh) |
|
525 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
526 |
||
527 |
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
528 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 529 |
cost += ret; |
530 |
} |
|
531 |
||
532 |
if (flags & DC_EXEC) { |
|
533 |
ModifyTile(ti.tile, |
|
534 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
535 |
MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
536 |
_build_tunnel_railtype, /* map3lo */ |
|
537 |
((_build_tunnel_bh << 1) | 2) - direction /* map5 */ |
|
538 |
); |
|
539 |
||
540 |
ModifyTile(end_tile, |
|
541 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
542 |
MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
543 |
_build_tunnel_railtype, /* map3lo */ |
|
544 |
(_build_tunnel_bh << 1) | (direction ? 3:0)/* map5 */ |
|
545 |
); |
|
546 |
||
547 |
UpdateSignalsOnSegment(end_tile, direction?7:1); |
|
548 |
} |
|
549 |
||
550 |
return cost + _price.build_tunnel; |
|
551 |
} |
|
552 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
553 |
/** Build Tunnel. |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
554 |
* @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
|
555 |
* @param p1 railtype, 0x200 for road tunnel |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
556 |
* @param p2 unused (XXX - ptr to uint that recieves end tile; wtf?????) |
0 | 557 |
*/ |
558 |
int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
559 |
{ |
|
560 |
TileInfo ti, tiorg; |
|
561 |
int direction; |
|
562 |
uint z; |
|
563 |
static const int8 _build_tunnel_coord_mod[4+1] = { -16, 0, 16, 0, -16 }; |
|
564 |
static const byte _build_tunnel_tileh[4] = {3, 9, 12, 6}; |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
565 |
TileIndex excavated_tile; |
0 | 566 |
|
567 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
568 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
569 |
if (p1 != 0x200 && !ValParamRailtype(p1)) return CMD_ERROR; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
570 |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
571 |
_build_tunnel_railtype = GB(p1, 0, 8); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
572 |
_build_tunnel_bh = GB(p1, 8, 8); |
0 | 573 |
|
574 |
_build_tunnel_endtile = 0; |
|
575 |
excavated_tile = 0; |
|
576 |
||
577 |
FindLandscapeHeight(&tiorg, x, y); |
|
578 |
||
579 |
if (!EnsureNoVehicle(tiorg.tile)) |
|
580 |
return CMD_ERROR; |
|
581 |
||
582 |
if (!(direction=0, tiorg.tileh==12) && |
|
583 |
!(direction++, tiorg.tileh==6) && |
|
584 |
!(direction++, tiorg.tileh==3) && |
|
585 |
!(direction++, tiorg.tileh==9) ) |
|
586 |
return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL); |
|
587 |
||
588 |
z = tiorg.z; |
|
589 |
do { |
|
590 |
x += _build_tunnel_coord_mod[direction]; |
|
591 |
y += _build_tunnel_coord_mod[direction+1]; |
|
592 |
FindLandscapeHeight(&ti, x, y); |
|
593 |
} while (z != ti.z); |
|
594 |
_build_tunnel_endtile = ti.tile; |
|
595 |
||
596 |
||
597 |
if (!EnsureNoVehicle(ti.tile)) |
|
598 |
return CMD_ERROR; |
|
599 |
||
600 |
if (ti.tileh != _build_tunnel_tileh[direction]) { |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
601 |
if (CmdFailed(DoCommandByTile(ti.tile, ti.tileh & ~_build_tunnel_tileh[direction], 0, flags, CMD_TERRAFORM_LAND))) |
0 | 602 |
return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND); |
603 |
excavated_tile = 1; |
|
604 |
} |
|
605 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
606 |
return DoBuildTunnel(x, y, tiorg.x, tiorg.y, flags, excavated_tile); |
0 | 607 |
} |
608 |
||
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
609 |
TileIndex CheckTunnelBusy(TileIndex tile, uint *length) |
0 | 610 |
{ |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
611 |
uint z = GetTileZ(tile); |
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
|
612 |
byte m5 = _m[tile].m5; |
900 | 613 |
int delta = TileOffsByDir(m5 & 3); |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
614 |
uint len = 0; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
615 |
TileIndex starttile = tile; |
0 | 616 |
Vehicle *v; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
617 |
|
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
|
618 |
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
|
619 |
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
|
620 |
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
|
621 |
} 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
|
622 |
!IsTileType(tile, MP_TUNNELBRIDGE) || |
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
|
623 |
(_m[tile].m5 & 0xF0) != 0 || |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
624 |
(_m[tile].m5 ^ 2) != m5 || |
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
|
625 |
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
|
626 |
); |
0 | 627 |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
628 |
v = FindVehicleBetween(starttile, tile, z); |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
629 |
if (v != NULL) { |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
630 |
_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
|
631 |
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
|
632 |
return INVALID_TILE; |
0 | 633 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
634 |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
635 |
if (length != NULL) *length = len; |
0 | 636 |
return tile; |
637 |
} |
|
638 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
639 |
static int32 DoClearTunnel(TileIndex tile, uint32 flags) |
0 | 640 |
{ |
641 |
Town *t; |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
642 |
TileIndex endtile; |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
643 |
uint length; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
644 |
static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3}; |
0 | 645 |
|
646 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
647 |
||
648 |
// in scenario editor you can always destroy tunnels |
|
649 |
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
|
650 |
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN)) |
0 | 651 |
return CMD_ERROR; |
652 |
} |
|
653 |
||
654 |
endtile = CheckTunnelBusy(tile, &length); |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
655 |
if (endtile == INVALID_TILE) return CMD_ERROR; |
0 | 656 |
|
657 |
_build_tunnel_endtile = endtile; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
658 |
|
0 | 659 |
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty |
660 |
// check if you're allowed to remove the tunnel owned by a town |
|
661 |
// 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
|
662 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
0 | 663 |
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
511
diff
changeset
|
664 |
SetDParam(0, t->index); |
0 | 665 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
666 |
} |
|
667 |
} |
|
668 |
||
669 |
if (flags & DC_EXEC) { |
|
38
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
670 |
// 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
|
671 |
// else the direction is always 0.. dah!! ;) |
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
|
672 |
byte tile_dir = _m[tile].m5&3; |
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
|
673 |
byte endtile_dir = _m[endtile].m5&3; |
0 | 674 |
DoClearSquare(tile); |
675 |
DoClearSquare(endtile); |
|
38
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
676 |
UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]); |
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
677 |
UpdateSignalsOnSegment(endtile, _updsignals_tunnel_dir[endtile_dir]); |
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
|
678 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) |
1005 | 679 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
0 | 680 |
} |
681 |
return _price.clear_tunnel * (length + 1); |
|
682 |
} |
|
683 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
684 |
static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile) |
0 | 685 |
{ |
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
|
686 |
int direction = _m[tile].m5 & 1; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
687 |
TileIndex start; |
0 | 688 |
|
689 |
// find start of bridge |
|
690 |
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
|
691 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0x80) |
0 | 692 |
break; |
1981 | 693 |
tile += direction ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); |
0 | 694 |
} |
695 |
||
696 |
start = tile; |
|
697 |
||
698 |
// find end of bridge |
|
699 |
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
|
700 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0xA0) |
0 | 701 |
break; |
1981 | 702 |
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 703 |
} |
704 |
||
705 |
*endtile = tile; |
|
706 |
||
707 |
return start; |
|
708 |
} |
|
709 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
710 |
static int32 DoClearBridge(TileIndex tile, uint32 flags) |
0 | 711 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
712 |
TileIndex endtile; |
0 | 713 |
Vehicle *v; |
714 |
Town *t; |
|
715 |
int direction; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
716 |
|
0 | 717 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
718 |
||
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
|
719 |
direction = _m[tile].m5&1; |
0 | 720 |
|
721 |
/* 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
|
722 |
if ((_m[tile].m5 & 0xE0) == 0xE0) { |
0 | 723 |
int32 cost; |
724 |
||
725 |
// 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
|
726 |
if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))) |
0 | 727 |
return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
728 |
|
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
|
729 |
cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail; |
0 | 730 |
|
731 |
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
|
732 |
_m[tile].m5 = _m[tile].m5 & ~0x38; |
1902 | 733 |
SetTileOwner(tile, OWNER_NONE); |
0 | 734 |
MarkTileDirtyByTile(tile); |
735 |
} |
|
736 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
737 |
|
0 | 738 |
/* 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
|
739 |
} else if ((_m[tile].m5 & 0xC8) == 0xC8 && TilePixelHeight(tile) != 0) { |
0 | 740 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
741 |
|
0 | 742 |
// check for vehicles under bridge |
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
743 |
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 744 |
return CMD_ERROR; |
745 |
cost = _price.clear_water; |
|
746 |
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
|
747 |
_m[tile].m5 = _m[tile].m5 & ~0x38; |
1902 | 748 |
SetTileOwner(tile, OWNER_NONE); |
0 | 749 |
MarkTileDirtyByTile(tile); |
750 |
} |
|
751 |
return cost; |
|
752 |
} |
|
753 |
||
754 |
tile = FindEdgesOfBridge(tile, &endtile); |
|
755 |
||
756 |
// floods, scenario editor can always destroy bridges |
|
757 |
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
|
758 |
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN)) |
0 | 759 |
return CMD_ERROR; |
760 |
} |
|
761 |
||
762 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) |
|
763 |
return CMD_ERROR; |
|
764 |
||
765 |
/* Make sure there's no vehicle on the bridge |
|
766 |
Omit tile and endtile, since these are already checked, thus solving the problem |
|
767 |
of bridges over water, or higher bridges, where z is not increased, eg level bridge |
|
768 |
*/ |
|
1981 | 769 |
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
770 |
endtile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
|
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
|
771 |
/* Bridges on slopes might have their Z-value offset..correct this */ |
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
|
772 |
if ((v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile))) != NULL) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
773 |
VehicleInTheWayErrMsg(v); |
0 | 774 |
return CMD_ERROR; |
775 |
} |
|
776 |
||
777 |
/* Put the tiles back to start/end position */ |
|
1981 | 778 |
tile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
779 |
endtile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
|
0 | 780 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
781 |
|
0 | 782 |
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
|
783 |
// check if you're allowed to remove the bridge owned by a town. |
0 | 784 |
// 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
|
785 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
786 |
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) |
0 | 787 |
return CMD_ERROR; |
788 |
} |
|
789 |
||
790 |
if (flags & DC_EXEC) { |
|
791 |
byte m5; |
|
792 |
uint c = tile; |
|
793 |
uint16 new_data; |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
794 |
byte pbs; |
0 | 795 |
|
1005 | 796 |
//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until |
0 | 797 |
// 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
|
798 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) |
1005 | 799 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
0 | 800 |
|
801 |
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
|
802 |
m5 = _m[c].m5; |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
803 |
pbs = PBSTileReserved(c); |
0 | 804 |
|
805 |
if (m5 & 0x40) { |
|
806 |
if (m5 & 0x20) { |
|
807 |
static const uint16 _new_data_table[] = {0x1002, 0x1001, 0x2005, 0x200A, 0, 0, 0, 0}; |
|
808 |
new_data = _new_data_table[((m5 & 0x18) >> 2) | (m5&1)]; |
|
809 |
} else { |
|
810 |
if (!(m5 & 0x18)) goto clear_it; |
|
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
811 |
new_data = (GetTileSlope(c, NULL) == 0) ? 0x6000 : 0x6001; |
0 | 812 |
} |
813 |
||
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
814 |
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
|
815 |
_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
|
816 |
_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
|
817 |
_m[c].m4 &= 0x0F; |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
818 |
if (direction ? HASBIT(pbs,0) : HASBIT(pbs,1)) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
819 |
PBSReserveTrack(c, direction ? 0 : 1); |
0 | 820 |
|
821 |
MarkTileDirtyByTile(c); |
|
822 |
||
823 |
} else { |
|
824 |
clear_it:; |
|
825 |
DoClearSquare(c); |
|
826 |
} |
|
1981 | 827 |
c += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 828 |
} while (c <= endtile); |
829 |
||
830 |
SetSignalsOnBothDir(tile, direction); |
|
831 |
SetSignalsOnBothDir(endtile, direction); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
832 |
|
0 | 833 |
} |
834 |
||
835 |
return ((((endtile - tile) >> (direction?8:0))&0xFF)+1) * _price.clear_bridge; |
|
836 |
} |
|
837 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
838 |
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
|
839 |
{ |
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
|
840 |
byte m5 = _m[tile].m5; |
0 | 841 |
|
842 |
if ((m5 & 0xF0) == 0) { |
|
843 |
if (flags & DC_AUTO) |
|
844 |
return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_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
|
845 |
|
0 | 846 |
return DoClearTunnel(tile, flags); |
847 |
} else if (m5 & 0x80) { |
|
848 |
if (flags & DC_AUTO) |
|
849 |
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
|
850 |
||
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
|
851 |
return DoClearBridge(tile, flags); |
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
852 |
} |
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
853 |
|
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
|
854 |
return CMD_ERROR; |
0 | 855 |
} |
856 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
857 |
int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec) |
0 | 858 |
{ |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
859 |
TileIndex endtile; |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
860 |
uint length; |
0 | 861 |
Vehicle *v; |
862 |
||
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
|
863 |
if ((_m[tile].m5 & 0xFC) == 0x00) { |
0 | 864 |
// railway tunnel |
865 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
866 |
||
2133 | 867 |
if ((_m[tile].m3 & 0xFU) == totype) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
868 |
|
0 | 869 |
endtile = CheckTunnelBusy(tile, &length); |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
870 |
if (endtile == INVALID_TILE) return CMD_ERROR; |
0 | 871 |
|
872 |
if (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
|
873 |
_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype; |
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
|
874 |
_m[endtile].m3 = (_m[endtile].m3 & 0xF0) + totype; |
0 | 875 |
MarkTileDirtyByTile(tile); |
876 |
MarkTileDirtyByTile(endtile); |
|
877 |
} |
|
878 |
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
|
879 |
} else if ((_m[tile].m5 & 0xF8) == 0xE0) { |
0 | 880 |
// bridge middle part with rail below |
881 |
// 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
|
882 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 883 |
return CMD_ERROR; |
884 |
||
885 |
// tile is already of requested type? |
|
2133 | 886 |
if ((_m[tile].m3 & 0xFU) == totype) return CMD_ERROR; |
0 | 887 |
// change type. |
888 |
if (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
|
889 |
_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype; |
0 | 890 |
MarkTileDirtyByTile(tile); |
891 |
} |
|
892 |
return _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
|
893 |
} else if ((_m[tile].m5&0xC6) == 0x80) { |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
894 |
TileIndex starttile; |
0 | 895 |
int32 cost; |
1073
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
896 |
uint z = TilePixelHeight(tile); |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
897 |
|
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
898 |
z += 8; |
0 | 899 |
|
900 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
901 |
||
902 |
// railway bridge |
|
903 |
starttile = tile = FindEdgesOfBridge(tile, &endtile); |
|
904 |
// Make sure there's no vehicle on the bridge |
|
1073
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
905 |
if ((v=FindVehicleBetween(tile, endtile, z)) != NULL) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
906 |
VehicleInTheWayErrMsg(v); |
0 | 907 |
return CMD_ERROR; |
908 |
} |
|
909 |
||
1073
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
910 |
if (!EnsureNoVehicle(starttile) || !EnsureNoVehicle(endtile)) { |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
911 |
_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
|
912 |
return CMD_ERROR; |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
913 |
} |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
914 |
|
2133 | 915 |
if ((_m[tile].m3 & 0xFU) == totype) return CMD_ERROR; |
0 | 916 |
cost = 0; |
917 |
do { |
|
918 |
if (exec) { |
|
919 |
if (tile == starttile || tile == endtile) { |
|
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
|
920 |
_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype; |
0 | 921 |
} else { |
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
|
922 |
_m[tile].m3 = (_m[tile].m3 & 0x0F) + (totype << 4); |
0 | 923 |
} |
924 |
MarkTileDirtyByTile(tile); |
|
925 |
} |
|
926 |
cost += (_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
|
927 |
tile += _m[tile].m5 & 1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 928 |
} while (tile <= endtile); |
929 |
||
930 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
931 |
} else |
0 | 932 |
return CMD_ERROR; |
933 |
} |
|
934 |
||
935 |
||
936 |
// fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile. |
|
1095 | 937 |
static uint GetBridgeHeight(const TileInfo *ti) |
0 | 938 |
{ |
1981 | 939 |
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
|
940 |
TileIndex tile = ti->tile; |
0 | 941 |
|
942 |
// find the end tile of the 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
|
943 |
delta = (_m[tile].m5 & 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 944 |
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
|
945 |
assert((_m[tile].m5 & 0xC0) == 0xC0); // bridge and middle part |
0 | 946 |
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
|
947 |
} while (_m[tile].m5 & 0x40); // while bridge middle parts |
0 | 948 |
|
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
|
949 |
/* 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
|
950 |
* 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
|
951 |
* 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
|
952 |
return TilePixelHeight(tile) + (GetTileSlope(tile, NULL) == 7 ? 8 : 0); |
0 | 953 |
} |
954 |
||
955 |
static const byte _bridge_foundations[2][16] = { |
|
956 |
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
957 |
{1,16,18,3,20,5,0,7,22,0,10,11,12,13,14}, |
|
958 |
{1,15,17,0,19,5,6,7,21,9,10,11, 0,13,14}, |
|
959 |
}; |
|
960 |
||
961 |
extern const byte _road_sloped_sprites[14]; |
|
962 |
||
963 |
static void DrawBridgePillars(TileInfo *ti, int x, int y, int z) |
|
964 |
{ |
|
965 |
const uint32 *b; |
|
966 |
uint32 image; |
|
967 |
int piece; |
|
968 |
||
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
|
969 |
b = _bridge_poles_table[GetBridgeType(ti->tile)]; |
0 | 970 |
|
971 |
// Draw first piece |
|
972 |
// (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
|
973 |
|
0 | 974 |
image = b[12 + (ti->map5&0x01)]; |
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
|
975 |
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
|
976 |
|
333
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
977 |
if (image != 0 && piece != 0) { |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
978 |
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
|
979 |
DrawGroundSpriteAt(image, x, y, z); |
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
980 |
} |
0 | 981 |
|
982 |
image = b[(ti->map5&0x01)*6 + piece]; |
|
983 |
||
984 |
if (image != 0) { |
|
985 |
int back_height, front_height, i=z; |
|
986 |
const byte *p; |
|
987 |
||
988 |
static const byte _tileh_bits[4][8] = { |
|
989 |
{2,1,8,4, 16,11,0,9}, |
|
990 |
{1,8,4,2, 11,16,9,0}, |
|
991 |
{4,8,1,2, 16,11,0,9}, |
|
992 |
{2,4,8,1, 11,16,9,0}, |
|
993 |
}; |
|
994 |
||
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
995 |
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
|
996 |
|
0 | 997 |
p = _tileh_bits[(image & 1) * 2 + (ti->map5&0x01)]; |
998 |
front_height = ti->z + ((ti->tileh & p[0])?8:0); |
|
999 |
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
|
1000 |
|
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
1001 |
if (IsSteepTileh(ti->tileh)) { |
0 | 1002 |
if (!(ti->tileh & p[2])) front_height += 8; |
1003 |
if (!(ti->tileh & p[3])) back_height += 8; |
|
1004 |
} |
|
1005 |
||
1006 |
for(; z>=front_height || z>=back_height; z=z-8) { |
|
1007 |
if (z>=front_height) AddSortableSpriteToDraw(image, x,y, p[4], p[5], 0x28, z); // front facing pillar |
|
1008 |
if (z>=back_height && z<i-8) AddSortableSpriteToDraw(image, x - p[6], y - p[7], p[4], p[5], 0x28, z); // back facing pillar |
|
1009 |
} |
|
1010 |
} |
|
1011 |
} |
|
1012 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
39
diff
changeset
|
1013 |
uint GetBridgeFoundation(uint tileh, byte direction) { |
0 | 1014 |
int i; |
1015 |
// normal level sloped building (7, 11, 13, 14) |
|
1016 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) |
|
1017 |
return tileh; |
|
1018 |
||
1019 |
// inclined sloped building |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1020 |
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && |
0 | 1021 |
( direction == 0 || (i++, direction == 1)) ) |
1022 |
return i + 15; |
|
1023 |
||
1024 |
return 0; |
|
1025 |
} |
|
1026 |
||
1027 |
static void DrawTile_TunnelBridge(TileInfo *ti) |
|
1028 |
{ |
|
1029 |
uint32 image; |
|
1030 |
uint tmp; |
|
1031 |
const uint32 *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
|
1032 |
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
|
1033 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1034 |
// draw tunnel? |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
1035 |
if ((ti->map5 & 0xF0) == 0) { |
0 | 1036 |
/* railway type */ |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
1037 |
image = GB(_m[ti->tile].m3, 0, 4) * 8; |
0 | 1038 |
|
1039 |
if (ice) |
|
1040 |
image += 32; |
|
1041 |
||
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
|
1042 |
image += _draw_tunnel_table_1[GB(ti->map5, 2, 2)]; |
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
|
1043 |
image += GB(ti->map5, 0, 2) * 2; |
0 | 1044 |
DrawGroundSprite(image); |
1045 |
||
1046 |
AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z); |
|
1047 |
// draw bridge? |
|
1048 |
} else if ((byte)ti->map5 & 0x80) { |
|
1049 |
// get type of track on the 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
|
1050 |
tmp = _m[ti->tile].m3; |
0 | 1051 |
if (ti->map5 & 0x40) tmp >>= 4; |
1052 |
tmp &= 0xF; |
|
1053 |
||
1054 |
// 0 = rail bridge |
|
1055 |
// 1 = road bridge |
|
1056 |
// 2 = monorail bridge |
|
1057 |
// 3 = maglev bridge |
|
1058 |
||
1059 |
// add direction and fix stuff. |
|
1060 |
if (tmp != 0) tmp++; |
|
1061 |
tmp = (ti->map5&3) + (tmp*2); |
|
1062 |
||
1063 |
if (!(ti->map5 & 0x40)) { // bridge ramps |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1064 |
|
0 | 1065 |
if (!(BRIDGE_NO_FOUNDATION & (1 << ti->tileh))) { // no foundations for 0, 3, 6, 9, 12 |
1066 |
int f = GetBridgeFoundation(ti->tileh, ti->map5 & 0x1); // pass direction |
|
1067 |
if (f) DrawFoundation(ti, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1068 |
|
0 | 1069 |
// default sloped sprites.. |
1070 |
if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3; |
|
1071 |
} |
|
1072 |
||
1073 |
// bridge ending. |
|
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
|
1074 |
b = _bridge_sprite_table[GB(_m[ti->tile].m2, 4, 4)][6]; |
0 | 1075 |
b += (tmp&(3<<1))*4; /* actually ((tmp>>2)&3)*8 */ |
1076 |
b += (tmp&1); // direction |
|
1077 |
if (ti->tileh == 0) b += 4; // sloped "entrance" ? |
|
1078 |
if (ti->map5 & 0x20) b += 2; // which side |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1079 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1080 |
image = *b; |
0 | 1081 |
|
1082 |
if (!ice) { |
|
1083 |
DrawClearLandTile(ti, 3); |
|
1084 |
} else { |
|
1085 |
DrawGroundSprite(0x11C6 + _tileh_to_sprite[ti->tileh]); |
|
1086 |
} |
|
1087 |
||
1088 |
// draw ramp |
|
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1089 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1090 |
AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z); |
1091 |
} else { |
|
1092 |
// bridge middle part. |
|
1093 |
uint z; |
|
1094 |
int x,y; |
|
1095 |
||
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
|
1096 |
image = GB(ti->map5, 3, 2); // type of stuff under bridge (only defined for 0,1) |
0 | 1097 |
assert(image <= 1); |
1098 |
||
1099 |
if (!(ti->map5 & 0x20)) { |
|
1100 |
// 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
|
1101 |
if (ice) image += 2; |
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1102 |
|
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1103 |
if (image != 1 || ti->tileh == 0) |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1104 |
DrawGroundSprite(_bridge_land_below[image] + _tileh_to_sprite[ti->tileh]); |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1105 |
else |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1106 |
DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
0 | 1107 |
|
1108 |
// draw canal water? |
|
1109 |
if (ti->map5 & 8 && ti->z != 0) DrawCanalWater(ti->tile); |
|
1110 |
} else { |
|
1111 |
// draw transport route under bridge |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1112 |
|
0 | 1113 |
// draw foundation? |
1114 |
if (ti->tileh) { |
|
1115 |
int f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1116 |
if (f) DrawFoundation(ti, f); |
|
1117 |
} |
|
1118 |
||
1119 |
if (!(image&1)) { |
|
2254
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2187
diff
changeset
|
1120 |
const RailtypeInfo *rti = GetRailTypeInfo(_m[ti->tile].m3 & 0xF); |
0 | 1121 |
// railway |
1122 |
image = 0x3F3 + (ti->map5 & 1); |
|
1123 |
if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3; |
|
2254
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2187
diff
changeset
|
1124 |
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
|
1125 |
if (ice) image += rti->snow_offset; |
0 | 1126 |
} else { |
1127 |
// road |
|
1128 |
image = 1332 + (ti->map5 & 1); |
|
1129 |
if (ti->tileh != 0) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
|
1130 |
if (ice) image += 19; // ice? |
|
1131 |
} |
|
1132 |
DrawGroundSprite(image); |
|
1133 |
} |
|
1134 |
// get bridge sprites |
|
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
|
1135 |
b = _bridge_sprite_table[GB(_m[ti->tile].m2, 4, 4)][GB(_m[ti->tile].m2, 0, 4)] + tmp * 4; |
0 | 1136 |
|
1137 |
z = GetBridgeHeight(ti) + 5; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1138 |
|
0 | 1139 |
// draw rail |
1140 |
image = b[0]; |
|
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1141 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1142 |
AddSortableSpriteToDraw(image, ti->x, ti->y, (ti->map5&1)?11:16, (ti->map5&1)?16:11, 1, z); |
1143 |
||
1144 |
x = ti->x; |
|
1145 |
y = ti->y; |
|
1146 |
image = b[1]; |
|
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1147 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1148 |
|
1149 |
// draw roof |
|
1150 |
if (ti->map5&1) { |
|
1151 |
x += 12; |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
1152 |
if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 1, 16, 0x28, z); |
0 | 1153 |
} else { |
1154 |
y += 12; |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
1155 |
if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 16, 1, 0x28, z); |
0 | 1156 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1157 |
|
0 | 1158 |
if (ti->z + 5 == z ) { |
1159 |
// draw poles below for small bridges |
|
1160 |
image = b[2]; |
|
1161 |
if (image) { |
|
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1162 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1163 |
DrawGroundSpriteAt(image, x, y, z); |
1164 |
} |
|
1165 |
} else if (_patches.bridge_pillars) { |
|
1166 |
// draw pillars below for high bridges |
|
1167 |
DrawBridgePillars(ti, x, y, z); |
|
1168 |
} |
|
1169 |
} |
|
1170 |
} |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1171 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1172 |
if (_debug_pbs_level >= 1) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1173 |
byte pbs = PBSTileReserved(ti->tile); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1174 |
if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite(0x3ED | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1175 |
if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite(0x3EE | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1176 |
if (pbs & TRACK_BIT_UPPER) DrawGroundSprite(0x3EF | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1177 |
if (pbs & TRACK_BIT_LOWER) DrawGroundSprite(0x3F0 | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1178 |
if (pbs & TRACK_BIT_LEFT) DrawGroundSprite(0x3F2 | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1179 |
if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite(0x3F1 | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1180 |
} |
0 | 1181 |
} |
1182 |
||
1183 |
static uint GetSlopeZ_TunnelBridge(TileInfo *ti) { |
|
1184 |
uint z = ti->z; |
|
1185 |
uint x = ti->x & 0xF; |
|
1186 |
uint y = ti->y & 0xF; |
|
1187 |
||
1188 |
// 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
|
1189 |
if (ti->map5 & 1) uintswap(x,y); |
0 | 1190 |
|
1191 |
// to the side of the tunnel/bridge? |
|
1192 |
if (IS_INT_INSIDE(y, 5, 10+1)) { |
|
1193 |
// tunnel? |
|
1194 |
if ( (ti->map5 & 0xF0) == 0) |
|
1195 |
return z; |
|
1196 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1197 |
// bridge? |
0 | 1198 |
if ( ti->map5 & 0x80 ) { |
1199 |
// bridge ending? |
|
1200 |
if (!(ti->map5 & 0x40)) { |
|
1201 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti->tileh)) // 7, 11, 13, 14 |
|
1202 |
z += 8; |
|
1203 |
||
1204 |
// no ramp for bridge ending |
|
1205 |
if ((BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << ti->tileh) || BRIDGE_NO_FOUNDATION & (1 << ti->tileh)) && ti->tileh != 0) { |
|
1206 |
return z + 8; |
|
1207 |
||
1208 |
} else if (!(ti->map5 & 0x20)) { // northern / southern ending |
|
1209 |
// ramp |
|
1210 |
return (z + (x>>1) + 1); |
|
1211 |
} else { |
|
1212 |
// ramp in opposite dir |
|
1213 |
return (z + ((x^0xF)>>1)); |
|
1214 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1215 |
|
0 | 1216 |
// bridge middle part |
1217 |
} else { |
|
1218 |
// build on slopes? |
|
1219 |
if (ti->tileh) z+=8; |
|
1220 |
||
1221 |
// keep the same elevation because we're on the bridge? |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1222 |
if (_get_z_hint >= z + 8) |
0 | 1223 |
return _get_z_hint; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1224 |
|
0 | 1225 |
// actually on the bridge, but not yet in the shared area. |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1226 |
if (!IS_INT_INSIDE(x, 5, 10+1)) |
0 | 1227 |
return GetBridgeHeight(ti) + 8; |
1228 |
||
1229 |
// in the shared area, assume that we're below the bridge, cause otherwise the hint would've caught it. |
|
1230 |
// if rail or road below then it means it's possibly build on slope below the bridge. |
|
1231 |
if (ti->map5 & 0x20) { |
|
1232 |
uint f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1233 |
// make sure that the slope is not inclined foundation |
|
1234 |
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
|
1235 |
|
0 | 1236 |
// change foundation type? |
1237 |
if (f) ti->tileh = _inclined_tileh[f - 15]; |
|
1238 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1239 |
|
0 | 1240 |
// no transport route, fallback to default |
1241 |
} |
|
1242 |
} |
|
1243 |
} else { |
|
1244 |
// if it's a bridge middle with transport route below, then we need to compensate for build on slopes |
|
1245 |
if ( (ti->map5 & (0x80 + 0x40 + 0x20)) == (0x80 + 0x40 + 0x20)) { |
|
1246 |
uint f; |
|
1247 |
if (ti->tileh) z += 8; |
|
1248 |
f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1249 |
if (IS_BYTE_INSIDE(f, 1, 15)) return z; |
|
1250 |
if (f) ti->tileh = _inclined_tileh[f - 15]; |
|
1251 |
} |
|
1252 |
} |
|
1253 |
||
1254 |
// default case |
|
1255 |
z = ti->z; |
|
1256 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + z; |
|
1257 |
} |
|
1258 |
||
39 | 1259 |
static uint GetSlopeTileh_TunnelBridge(TileInfo *ti) { |
1260 |
// not accurate, but good enough for slope graphics drawing |
|
1261 |
return 0; |
|
1262 |
} |
|
1263 |
||
1264 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1265 |
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac) |
0 | 1266 |
{ |
1267 |
/* not used */ |
|
1268 |
} |
|
1269 |
||
1270 |
static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = { |
|
1271 |
STR_501F_WOODEN_RAIL_BRIDGE, |
|
1272 |
STR_5020_CONCRETE_RAIL_BRIDGE, |
|
1273 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1274 |
STR_501E_REINFORCED_CONCRETE_SUSPENSION, |
|
1275 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1276 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1277 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1278 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1279 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1280 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1281 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1282 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1283 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1284 |
0,0,0, |
|
1285 |
||
1286 |
STR_5025_WOODEN_ROAD_BRIDGE, |
|
1287 |
STR_5026_CONCRETE_ROAD_BRIDGE, |
|
1288 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1289 |
STR_5024_REINFORCED_CONCRETE_SUSPENSION, |
|
1290 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1291 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1292 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1293 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1294 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1295 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1296 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1297 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1298 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1299 |
0,0,0, |
|
1300 |
}; |
|
1301 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1302 |
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td) |
0 | 1303 |
{ |
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
|
1304 |
if ((_m[tile].m5 & 0x80) == 0) { |
2260
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2254
diff
changeset
|
1305 |
td->str = |
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2254
diff
changeset
|
1306 |
(GB(_m[tile].m5, 2, 2) == 0) ? STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL; |
0 | 1307 |
} 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
|
1308 |
td->str = _bridge_tile_str[GB(_m[tile].m5, 1, 2) << 4 | GB(_m[tile].m2, 4, 4)]; |
0 | 1309 |
|
1310 |
/* 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
|
1311 |
if (_m[tile].m5 & 0x40) { |
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
|
1312 |
TileIndexDiff delta = _m[tile].m5 & 1 ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); |
1981 | 1313 |
|
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
|
1314 |
do tile += delta; while (_m[tile].m5 & 0x40); |
0 | 1315 |
} |
1316 |
} |
|
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
|
1317 |
td->owner = GetTileOwner(tile); |
0 | 1318 |
} |
1319 |
||
1320 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1321 |
static void AnimateTile_TunnelBridge(TileIndex tile) |
0 | 1322 |
{ |
1323 |
/* not used */ |
|
1324 |
} |
|
1325 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1326 |
static void TileLoop_TunnelBridge(TileIndex tile) |
0 | 1327 |
{ |
1328 |
if (_opt.landscape == LT_HILLY) { |
|
1329 |
if ( GetTileZ(tile) > _opt.snow_line) { |
|
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
|
1330 |
if (!(_m[tile].m4 & 0x80)) { |
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
|
1331 |
_m[tile].m4 |= 0x80; |
0 | 1332 |
MarkTileDirtyByTile(tile); |
1333 |
} |
|
1334 |
} else { |
|
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
|
1335 |
if (_m[tile].m4 & 0x80) { |
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
|
1336 |
_m[tile].m4 &= ~0x80; |
0 | 1337 |
MarkTileDirtyByTile(tile); |
1338 |
} |
|
1339 |
} |
|
1340 |
} else if (_opt.landscape == LT_DESERT) { |
|
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
|
1341 |
if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4&0x80)) { |
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
|
1342 |
_m[tile].m4 |= 0x80; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1343 |
MarkTileDirtyByTile(tile); |
0 | 1344 |
} |
1345 |
} |
|
1346 |
||
1347 |
// 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
|
1348 |
if ((_m[tile].m5 & 0xF8) == 0xC8) TileLoop_Water(tile); |
0 | 1349 |
} |
1350 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1351 |
static void ClickTile_TunnelBridge(TileIndex tile) |
0 | 1352 |
{ |
1353 |
/* not used */ |
|
1354 |
} |
|
1355 |
||
1356 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1357 |
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode) |
0 | 1358 |
{ |
1359 |
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
|
1360 |
byte m5 = _m[tile].m5; |
0 | 1361 |
|
1362 |
if ((m5 & 0xF0) == 0) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1363 |
/* This is a tunnel */ |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1364 |
if (((m5 & 0xCU) >> 2) == mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1365 |
/* Tranport in the tunnel is compatible */ |
0 | 1366 |
return m5&1 ? 0x202 : 0x101; |
1367 |
} |
|
1368 |
} else if (m5 & 0x80) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1369 |
/* This is a bridge */ |
0 | 1370 |
result = 0; |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1371 |
if (((m5 & 0x6U) >> 1) == mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1372 |
/* Transport over the bridge is compatible */ |
0 | 1373 |
result = m5&1 ? 0x202 : 0x101; |
1374 |
} |
|
1375 |
if (m5 & 0x40) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1376 |
/* Bridge middle part */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1377 |
if (!(m5 & 0x20)) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1378 |
/* Clear ground or water underneath */ |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
203
diff
changeset
|
1379 |
if ((m5 & 0x18) != 8) |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1380 |
/* Clear ground */ |
0 | 1381 |
return result; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1382 |
else |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1383 |
if (mode != TRANSPORT_WATER) |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1384 |
return result; |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1385 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1386 |
/* Transport underneath */ |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1387 |
if ((m5 & 0x18U) >> 3 != mode) |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1388 |
/* Incompatible transport underneath */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1389 |
return result; |
0 | 1390 |
} |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1391 |
/* If we've not returned yet, there is a compatible |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1392 |
* transport or water beneath, so we can add it to |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1393 |
* result */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1394 |
/* Why is this xor'd ? Can't it just be or'd? */ |
0 | 1395 |
result ^= m5&1 ? 0x101 : 0x202; |
1396 |
} |
|
1397 |
return result; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1398 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1399 |
assert(0); /* This should never occur */ |
0 | 1400 |
} |
1401 |
return 0; |
|
1402 |
} |
|
1403 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1404 |
static void ChangeTileOwner_TunnelBridge(TileIndex tile, byte old_player, byte new_player) |
0 | 1405 |
{ |
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
|
1406 |
if (!IsTileOwner(tile, old_player)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1407 |
|
0 | 1408 |
if (new_player != 255) { |
1902 | 1409 |
SetTileOwner(tile, new_player); |
0 | 1410 |
} else { |
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
|
1411 |
if((_m[tile].m5 & 0xC0)==0xC0) { |
0 | 1412 |
// 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
|
1413 |
if (!(_m[tile].m5 & (1 << 4 | 1 << 3))) { |
0 | 1414 |
// 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
|
1415 |
_m[tile].m5 &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore.. |
0 | 1416 |
} else { |
1417 |
// for road, change the owner of the road to local authority |
|
1902 | 1418 |
SetTileOwner(tile, OWNER_NONE); |
0 | 1419 |
} |
1420 |
} else { |
|
1421 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1422 |
} |
|
1423 |
} |
|
1424 |
} |
|
1425 |
||
1426 |
||
1427 |
static const byte _tunnel_fractcoord_1[4] = {0x8E,0x18,0x81,0xE8}; |
|
1428 |
static const byte _tunnel_fractcoord_2[4] = {0x81,0x98,0x87,0x38}; |
|
1429 |
static const byte _tunnel_fractcoord_3[4] = {0x82,0x88,0x86,0x48}; |
|
1430 |
static const byte _exit_tunnel_track[4] = {1,2,1,2}; |
|
1431 |
||
1432 |
static const byte _road_exit_tunnel_state[4] = {8, 9, 0, 1}; |
|
1433 |
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4}; |
|
1434 |
||
1435 |
static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29}; |
|
1436 |
static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25}; |
|
1437 |
static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45}; |
|
1438 |
static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49}; |
|
1439 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1440 |
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1441 |
{ |
1442 |
int z; |
|
1443 |
int dir, vdir; |
|
1444 |
byte fc; |
|
1445 |
||
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
|
1446 |
if ((_m[tile].m5 & 0xF0) == 0) { |
0 | 1447 |
z = GetSlopeZ(x, y) - v->z_pos; |
1448 |
if (myabs(z) > 2) |
|
1449 |
return 8; |
|
1450 |
||
1451 |
if (v->type == VEH_Train) { |
|
1452 |
fc = (x&0xF)+(y<<4); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1453 |
|
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
|
1454 |
dir = _m[tile].m5 & 3; |
0 | 1455 |
vdir = v->direction >> 1; |
1456 |
||
1457 |
if (v->u.rail.track != 0x40 && dir == vdir) { |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1059
diff
changeset
|
1458 |
if (v->subtype == TS_Front_Engine && fc == _tunnel_fractcoord_1[dir]) { |
0 | 1459 |
if (v->spritenum < 4) |
541 | 1460 |
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); |
0 | 1461 |
return 0; |
1462 |
} |
|
1463 |
if (fc == _tunnel_fractcoord_2[dir]) { |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1464 |
if (v->next == NULL) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
1465 |
PBSClearTrack(v->tile, FIND_FIRST_BIT(v->u.rail.track)); |
0 | 1466 |
v->tile = tile; |
1467 |
v->u.rail.track = 0x40; |
|
1468 |
v->vehstatus |= VS_HIDDEN; |
|
1469 |
return 4; |
|
1470 |
} |
|
1471 |
} |
|
1472 |
||
1473 |
if (dir == (vdir^2) && fc == _tunnel_fractcoord_3[dir] && z == 0) { |
|
22 | 1474 |
/* We're at the tunnel exit ?? */ |
0 | 1475 |
v->tile = tile; |
1476 |
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
|
1477 |
assert(v->u.rail.track); |
0 | 1478 |
v->vehstatus &= ~VS_HIDDEN; |
1479 |
return 4; |
|
1480 |
} |
|
1481 |
} else if (v->type == VEH_Road) { |
|
1482 |
fc = (x&0xF)+(y<<4); |
|
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
|
1483 |
dir = _m[tile].m5 & 3; |
0 | 1484 |
vdir = v->direction >> 1; |
1485 |
||
1486 |
// Enter tunnel? |
|
1487 |
if (v->u.road.state != 0xFF && dir == vdir) { |
|
1488 |
if (fc == _tunnel_fractcoord_4[dir] || |
|
1489 |
fc == _tunnel_fractcoord_5[dir]) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1490 |
|
0 | 1491 |
v->tile = tile; |
1492 |
v->u.road.state = 0xFF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1493 |
v->vehstatus |= VS_HIDDEN; |
0 | 1494 |
return 4; |
1495 |
} else { |
|
1496 |
return 0; |
|
1497 |
} |
|
1498 |
} |
|
1499 |
||
1500 |
if (dir == (vdir^2) && ( |
|
22 | 1501 |
/* We're at the tunnel exit ?? */ |
0 | 1502 |
fc == _tunnel_fractcoord_6[dir] || |
1503 |
fc == _tunnel_fractcoord_7[dir]) && |
|
1504 |
z == 0) { |
|
1505 |
v->tile = tile; |
|
1506 |
v->u.road.state = _road_exit_tunnel_state[dir]; |
|
1507 |
v->u.road.frame = _road_exit_tunnel_frame[dir]; |
|
1508 |
v->vehstatus &= ~VS_HIDDEN; |
|
1509 |
return 4; |
|
1510 |
} |
|
1511 |
} |
|
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
|
1512 |
} else if (_m[tile].m5 & 0x80) { |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1059
diff
changeset
|
1513 |
if (v->type == VEH_Road || (v->type == VEH_Train && v->subtype == TS_Front_Engine)) { |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1514 |
uint h; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1515 |
|
334
7e87a24e88b5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1516 |
if (GetTileSlope(tile, &h) != 0) |
7e87a24e88b5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1517 |
h += 8; // Compensate for possible foundation |
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
|
1518 |
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
|
1519 |
myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge |
0 | 1520 |
/* 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
|
1521 |
uint16 spd = _bridge[GetBridgeType(tile)].speed; |
0 | 1522 |
if (v->type == VEH_Road) spd<<=1; |
1523 |
if (spd < v->cur_speed) |
|
1524 |
v->cur_speed = spd; |
|
1525 |
} |
|
1526 |
} |
|
1527 |
} |
|
1528 |
return 0; |
|
1529 |
} |
|
1530 |
||
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1531 |
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v) |
0 | 1532 |
{ |
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1533 |
TileIndex tile; |
1981 | 1534 |
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
|
1535 |
byte z = v->z_pos; |
0 | 1536 |
|
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1537 |
for (tile = v->tile;; 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
|
1538 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0) == 0 && |
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1539 |
GetTileZ(tile) == z) |
0 | 1540 |
break; |
1541 |
} |
|
1542 |
return tile; |
|
1543 |
} |
|
1544 |
||
1545 |
const TileTypeProcs _tile_type_tunnelbridge_procs = { |
|
1546 |
DrawTile_TunnelBridge, /* draw_tile_proc */ |
|
1547 |
GetSlopeZ_TunnelBridge, /* get_slope_z_proc */ |
|
1548 |
ClearTile_TunnelBridge, /* clear_tile_proc */ |
|
1549 |
GetAcceptedCargo_TunnelBridge, /* get_accepted_cargo_proc */ |
|
1550 |
GetTileDesc_TunnelBridge, /* get_tile_desc_proc */ |
|
1551 |
GetTileTrackStatus_TunnelBridge,/* get_tile_track_status_proc */ |
|
1552 |
ClickTile_TunnelBridge, /* click_tile_proc */ |
|
1553 |
AnimateTile_TunnelBridge, /* animate_tile_proc */ |
|
1554 |
TileLoop_TunnelBridge, /* tile_loop_clear */ |
|
1555 |
ChangeTileOwner_TunnelBridge, /* change_tile_owner_clear */ |
|
1556 |
NULL, /* get_produced_cargo_proc */ |
|
1557 |
VehicleEnter_TunnelBridge, /* vehicle_enter_tile_proc */ |
|
1558 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1559 |
GetSlopeTileh_TunnelBridge, /* get_slope_tileh_proc */ |
0 | 1560 |
}; |