author | Darkvater |
Sat, 18 Mar 2006 16:00:02 +0000 | |
branch | 0.4.5 |
changeset 9936 | 53d4d464b85c |
parent 2934 | 3b7eef9871f8 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2262
bd59b2d8d75f
(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 |
bd59b2d8d75f
(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) |
bd59b2d8d75f
(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 |
bd59b2d8d75f
(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 |
*/ |
bd59b2d8d75f
(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
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1884
diff
changeset
|
9 |
#include "openttd.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
10 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
11 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
12 |
#include "functions.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
541
diff
changeset
|
13 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
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
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
334
diff
changeset
|
20 |
#include "sound.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
21 |
#include "variables.h" |
2262
bd59b2d8d75f
(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
|
22 |
#include "bridge.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2663
diff
changeset
|
23 |
#include "train.h" |
0 | 24 |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
25 |
#include "table/bridge_land.h" |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
26 |
|
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
27 |
extern const byte _track_sloped_sprites[14]; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
28 |
extern const SpriteID _water_shore_sprites[15]; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2260
diff
changeset
|
29 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
30 |
extern void DrawCanalWater(TileIndex tile); |
0 | 31 |
|
2478
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
32 |
const Bridge orig_bridge[] = { |
2262
bd59b2d8d75f
(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
|
33 |
/* |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2262
diff
changeset
|
34 |
year of availablity |
2262
bd59b2d8d75f
(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 |
| minimum length |
bd59b2d8d75f
(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
|
36 |
| | maximum length |
bd59b2d8d75f
(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 |
| | | price |
bd59b2d8d75f
(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 speed |
bd59b2d8d75f
(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 |
| | | | | sprite to use in GUI string with description |
bd59b2d8d75f
(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 |
| | | | | | | */ |
2478
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
41 |
{ 0, 0, 16, 80, 32, 0xA24 , STR_5012_WOODEN , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
42 |
{ 0, 0, 2, 112, 48, 0xA26 | PALETTE_TO_STRUCT_RED , STR_5013_CONCRETE , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
43 |
{ 10, 0, 5, 144, 64, 0xA25 , STR_500F_GIRDER_STEEL , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
44 |
{ 0, 2, 10, 168, 80, 0xA22 | PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
45 |
{ 10, 3, 16, 185, 96, 0xA22 , STR_500E_SUSPENSION_STEEL , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
46 |
{ 10, 3, 16, 192, 112, 0xA22 | PALETTE_TO_STRUCT_YELLOW , STR_500E_SUSPENSION_STEEL , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
47 |
{ 10, 3, 7, 224, 160, 0xA23 , STR_5010_CANTILEVER_STEEL , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
48 |
{ 10, 3, 8, 232, 208, 0xA23 | PALETTE_TO_STRUCT_BROWN , STR_5010_CANTILEVER_STEEL , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
49 |
{ 10, 3, 9, 248, 240, 0xA23 | PALETTE_TO_STRUCT_RED , STR_5010_CANTILEVER_STEEL , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
50 |
{ 10, 0, 2, 240, 256, 0xA27 , STR_500F_GIRDER_STEEL , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
51 |
{ 75, 2, 16, 255, 320, 0xA28 , STR_5014_TUBULAR_STEEL , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
52 |
{ 85, 2, 32, 380, 512, 0xA28 | PALETTE_TO_STRUCT_YELLOW , STR_5014_TUBULAR_STEEL , NULL, 0 }, |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
53 |
{ 90, 2, 32, 510, 608, 0xA28 | PALETTE_TO_STRUCT_GREY , STR_BRIDGE_TUBULAR_SILICON , NULL, 0 } |
0 | 54 |
}; |
55 |
||
2763 | 56 |
Bridge _bridge[MAX_BRIDGES]; |
57 |
||
58 |
||
0 | 59 |
// calculate the price factor for building a long bridge. |
60 |
// 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, |
|
61 |
int CalcBridgeLenCostFactor(int x) |
|
62 |
{ |
|
2639 | 63 |
int n; |
64 |
int r; |
|
65 |
||
0 | 66 |
if (x < 2) return x; |
67 |
x -= 2; |
|
2639 | 68 |
for (n = 0, r = 2;; n++) { |
0 | 69 |
if (x <= n) return r + x * n; |
70 |
r += n * n; |
|
71 |
x -= n; |
|
72 |
} |
|
73 |
} |
|
74 |
||
75 |
enum { |
|
76 |
// foundation, whole tile is leveled up (tileh's 7, 11, 13, 14) --> 3 corners raised |
|
77 |
BRIDGE_FULL_LEVELED_FOUNDATION = 1 << 7 | 1 << 11 | 1 << 13 | 1 << 14, |
|
78 |
// foundation, tile is partly leveled up (tileh's 1, 2, 4, 8) --> 1 corner raised |
|
79 |
BRIDGE_PARTLY_LEVELED_FOUNDATION = 1 << 1 | 1 << 2 | 1 << 4 | 1 << 8, |
|
80 |
// no foundations (X,Y direction) (tileh's 0, 3, 6, 9, 12) |
|
81 |
BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12, |
|
82 |
}; |
|
83 |
||
2478
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
84 |
static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table) |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
85 |
{ |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
86 |
const Bridge *bridge = &_bridge[index]; |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
87 |
assert(table < 7); |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
88 |
if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) { |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
89 |
return _bridge_sprite_table[index][table]; |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
90 |
} else { |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
91 |
return bridge->sprite_table[table]; |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
92 |
} |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
93 |
} |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
94 |
|
2262
bd59b2d8d75f
(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 |
/** |
bd59b2d8d75f
(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 |
* Determines which piece of a bridge is contained in the current tile |
bd59b2d8d75f
(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 |
* @param tile The tile to analyze |
bd59b2d8d75f
(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 the piece |
bd59b2d8d75f
(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 |
*/ |
bd59b2d8d75f
(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 |
static inline int GetBridgePiece(TileIndex tile) |
bd59b2d8d75f
(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 |
{ |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
102 |
return GB(_m[tile].m2, 0, 4); |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
103 |
} |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
104 |
|
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
105 |
/** |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
106 |
* Determines the type of bridge on a tile |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
107 |
* @param tile The tile to analyze |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
108 |
* @return The bridge type |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
109 |
*/ |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
110 |
static inline int GetBridgeType(TileIndex tile) |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
111 |
{ |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
112 |
return GB(_m[tile].m2, 4, 4); |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
113 |
} |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
114 |
|
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
115 |
/** check if bridge can be built on slope |
0 | 116 |
* direction 0 = X-axis, direction 1 = Y-axis |
117 |
* is_start_tile = false <-- end tile |
|
118 |
* is_start_tile = true <-- start tile |
|
119 |
*/ |
|
120 |
static uint32 CheckBridgeSlope(uint direction, uint tileh, bool is_start_tile) |
|
121 |
{ |
|
2639 | 122 |
if (IsSteepTileh(tileh)) return CMD_ERROR; |
0 | 123 |
|
2639 | 124 |
if (is_start_tile) { |
125 |
/* check slope at start tile |
|
126 |
- no extra cost |
|
127 |
- direction X: tiles 0, 12 |
|
128 |
- direction Y: tiles 0, 9 |
|
129 |
*/ |
|
130 |
if ((direction ? 0x201 : 0x1001) & (1 << tileh)) return 0; |
|
0 | 131 |
|
2639 | 132 |
// disallow certain start tiles to avoid certain crooked bridges |
133 |
if (tileh == 2) return CMD_ERROR; |
|
134 |
} else { |
|
135 |
/* check slope at end tile |
|
136 |
- no extra cost |
|
137 |
- direction X: tiles 0, 3 |
|
138 |
- direction Y: tiles 0, 6 |
|
139 |
*/ |
|
140 |
if ((direction? 0x41 : 0x9) & (1 << tileh)) return 0; |
|
0 | 141 |
|
2639 | 142 |
// disallow certain end tiles to avoid certain crooked bridges |
143 |
if (tileh == 8) return CMD_ERROR; |
|
144 |
} |
|
0 | 145 |
|
2639 | 146 |
/* disallow common start/end tiles to avoid certain crooked bridges e.g. |
147 |
* start-tile: X 2,1 Y 2,4 (2 was disabled before) |
|
148 |
* end-tile: X 8,4 Y 8,1 (8 was disabled before) |
|
149 |
*/ |
|
150 |
if ((tileh == 1 && is_start_tile != (bool)direction) || |
|
151 |
(tileh == 4 && is_start_tile == (bool)direction)) { |
|
152 |
return CMD_ERROR; |
|
0 | 153 |
} |
154 |
||
2639 | 155 |
// slope foundations |
156 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh) || BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << tileh)) |
|
157 |
return _price.terraform; |
|
158 |
||
0 | 159 |
return CMD_ERROR; |
160 |
} |
|
161 |
||
162 |
uint32 GetBridgeLength(TileIndex begin, TileIndex end) |
|
163 |
{ |
|
2639 | 164 |
int x1 = TileX(begin); |
165 |
int y1 = TileY(begin); |
|
166 |
int x2 = TileX(end); |
|
167 |
int y2 = TileY(end); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
168 |
|
2639 | 169 |
return abs(x2 + y2 - x1 - y1) - 1; |
0 | 170 |
} |
171 |
||
2639 | 172 |
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len) |
0 | 173 |
{ |
2262
bd59b2d8d75f
(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 |
const Bridge *b = &_bridge[bridge_type]; |
2639 | 175 |
uint max; // max possible length of a bridge (with patch 100) |
0 | 176 |
|
1781
92e08797c84b
(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
|
177 |
if (bridge_type >= MAX_BRIDGES) return false; |
2262
bd59b2d8d75f
(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 (b->avail_year > _cur_year) return false; |
0 | 179 |
|
2262
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
180 |
max = b->max_length; |
2639 | 181 |
if (max >= 16 && _patches.longbridges) max = 100; |
0 | 182 |
|
2639 | 183 |
return b->min_length <= bridge_len && bridge_len <= max; |
0 | 184 |
} |
185 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
186 |
/** Build a Bridge |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
187 |
* @param x,y end tile coord |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
188 |
* @param p1 packed start tile coords (~ dx) |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
189 |
* @param p2 various bitstuffed elements |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
190 |
* - p2 = (bit 0- 7) - bridge type (hi bh) |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
191 |
* - p2 = (bit 8-..) - rail type. bit15 ((x>>8)&0x80) means road bridge. |
0 | 192 |
*/ |
193 |
int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
194 |
{ |
|
195 |
int bridge_type; |
|
196 |
byte rail_or_road, railtype, m5; |
|
197 |
int sx,sy; |
|
198 |
TileInfo ti_start, ti_end, ti; /* OPT: only 2 of those are ever used */ |
|
2639 | 199 |
uint bridge_len; |
200 |
uint odd_middle_part; |
|
0 | 201 |
uint direction; |
2639 | 202 |
uint i; |
0 | 203 |
int32 cost, terraformcost, ret; |
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
204 |
bool allow_on_slopes; |
0 | 205 |
|
206 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
207 |
|
0 | 208 |
/* unpack parameters */ |
2140
d708eb80ab8b
(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
|
209 |
bridge_type = GB(p2, 0, 8); |
d708eb80ab8b
(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
|
210 |
railtype = GB(p2, 8, 8); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
211 |
|
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2931
diff
changeset
|
212 |
if (p1 >= MapSize()) return CMD_ERROR; |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
213 |
|
0 | 214 |
// type of bridge |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
215 |
if (HASBIT(railtype, 7)) { // bit 15 of original p2 param |
0 | 216 |
railtype = 0; |
217 |
rail_or_road = 2; |
|
218 |
} else { |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
219 |
if (!ValParamRailtype(railtype)) return CMD_ERROR; |
0 | 220 |
rail_or_road = 0; |
221 |
} |
|
222 |
||
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
223 |
sx = TileX(p1) * 16; |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
224 |
sy = TileY(p1) * 16; |
0 | 225 |
|
226 |
direction = 0; |
|
227 |
||
228 |
/* check if valid, and make sure that (x,y) are smaller than (sx,sy) */ |
|
229 |
if (x == sx) { |
|
2639 | 230 |
if (y == sy) return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); |
0 | 231 |
direction = 1; |
232 |
if (y > sy) { |
|
233 |
intswap(y,sy); |
|
234 |
intswap(x,sx); |
|
235 |
} |
|
236 |
} else if (y == sy) { |
|
237 |
if (x > sx) { |
|
238 |
intswap(y,sy); |
|
239 |
intswap(x,sx); |
|
240 |
} |
|
2639 | 241 |
} else { |
0 | 242 |
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); |
2639 | 243 |
} |
0 | 244 |
|
1781
92e08797c84b
(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
|
245 |
/* set and test bridge length, availability */ |
92e08797c84b
(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
|
246 |
bridge_len = ((sx + sy - x - y) >> 4) - 1; |
92e08797c84b
(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
|
247 |
if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE); |
92e08797c84b
(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
|
248 |
|
0 | 249 |
/* retrieve landscape height and ensure it's on land */ |
250 |
if ( |
|
251 |
((FindLandscapeHeight(&ti_end, sx, sy), |
|
252 |
ti_end.type == MP_WATER) && ti_end.map5 == 0) || |
|
253 |
((FindLandscapeHeight(&ti_start, x, y), |
|
254 |
ti_start.type == MP_WATER) && ti_start.map5 == 0)) |
|
255 |
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH); |
|
256 |
||
257 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_start.tileh)) { |
|
258 |
ti_start.z += 8; |
|
259 |
ti_start.tileh = 0; |
|
260 |
} |
|
261 |
||
262 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_end.tileh)) { |
|
263 |
ti_end.z += 8; |
|
264 |
ti_end.tileh = 0; |
|
265 |
} |
|
266 |
||
267 |
if (ti_start.z != ti_end.z) |
|
268 |
return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); |
|
269 |
||
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
270 |
|
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
271 |
// Towns are not allowed to use bridges on slopes. |
2422
914a12dee832
(svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents:
2314
diff
changeset
|
272 |
allow_on_slopes = (!_is_old_ai_player |
1781
92e08797c84b
(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
|
273 |
&& _current_player != OWNER_TOWN && _patches.build_on_slopes); |
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
274 |
|
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
275 |
/* Try and clear the start landscape */ |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
276 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
277 |
if (CmdFailed(ret = DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) |
0 | 278 |
return CMD_ERROR; |
279 |
cost = ret; |
|
280 |
||
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
281 |
// true - bridge-start-tile, false - bridge-end-tile |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
282 |
terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2676
diff
changeset
|
283 |
if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes)) |
0 | 284 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
285 |
cost += terraformcost; |
|
286 |
||
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
287 |
/* Try and clear the end landscape */ |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
288 |
|
2639 | 289 |
ret = DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
290 |
if (CmdFailed(ret)) return CMD_ERROR; |
|
0 | 291 |
cost += ret; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
292 |
|
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
293 |
// false - end tile slope check |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
294 |
terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2676
diff
changeset
|
295 |
if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes)) |
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
296 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
297 |
cost += terraformcost; |
0 | 298 |
|
299 |
||
300 |
/* do the drill? */ |
|
301 |
if (flags & DC_EXEC) { |
|
302 |
/* build the start tile */ |
|
303 |
ModifyTile(ti_start.tile, |
|
304 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
305 |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
306 |
(bridge_type << 4), /* map2 */ |
|
307 |
railtype, /* map3_lo */ |
|
308 |
0x80 | direction | rail_or_road /* map5 */ |
|
309 |
); |
|
310 |
||
311 |
/* build the end tile */ |
|
312 |
ModifyTile(ti_end.tile, |
|
313 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
314 |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
315 |
(bridge_type << 4), /* map2 */ |
|
316 |
railtype, /* map3_lo */ |
|
317 |
0x80 | 0x20 | direction | rail_or_road /* map5 */ |
|
318 |
); |
|
319 |
} |
|
320 |
||
1781
92e08797c84b
(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
|
321 |
// position of middle part of the odd bridge (larger than MAX(i) otherwise) |
92e08797c84b
(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 |
odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len; |
0 | 323 |
|
1781
92e08797c84b
(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 |
for (i = 0; i != bridge_len; i++) { |
92e08797c84b
(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 |
if (direction != 0) { |
92e08797c84b
(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 |
y += 16; |
2639 | 327 |
} else { |
1781
92e08797c84b
(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
|
328 |
x += 16; |
2639 | 329 |
} |
0 | 330 |
|
331 |
FindLandscapeHeight(&ti, x, y); |
|
332 |
||
333 |
_error_message = STR_5009_LEVEL_LAND_OR_WATER_REQUIRED; |
|
2639 | 334 |
if (ti.tileh != 0 && ti.z >= ti_start.z) return CMD_ERROR; |
0 | 335 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
336 |
// Find ship below |
2639 | 337 |
if (ti.type == MP_WATER && !EnsureNoVehicle(ti.tile)) { |
0 | 338 |
_error_message = STR_980E_SHIP_IN_THE_WAY; |
339 |
return CMD_ERROR; |
|
340 |
} |
|
341 |
||
342 |
if (ti.type == MP_WATER) { |
|
1091
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
343 |
if (ti.map5 > 1) goto not_valid_below; |
0 | 344 |
m5 = 0xC8; |
345 |
} else if (ti.type == MP_RAILWAY) { |
|
346 |
if (direction == 0) { |
|
347 |
if (ti.map5 != 2) goto not_valid_below; |
|
348 |
} else { |
|
349 |
if (ti.map5 != 1) goto not_valid_below; |
|
350 |
} |
|
351 |
m5 = 0xE0; |
|
352 |
} else if (ti.type == MP_STREET) { |
|
353 |
if (direction == 0) { |
|
354 |
if (ti.map5 != 5) goto not_valid_below; |
|
355 |
} else { |
|
356 |
if (ti.map5 != 10) goto not_valid_below; |
|
357 |
} |
|
358 |
m5 = 0xE8; |
|
359 |
} else { |
|
360 |
not_valid_below:; |
|
361 |
/* try and clear the middle landscape */ |
|
2639 | 362 |
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
363 |
if (CmdFailed(ret)) return CMD_ERROR; |
|
0 | 364 |
cost += ret; |
365 |
m5 = 0xC0; |
|
366 |
} |
|
367 |
||
368 |
/* do middle part of bridge */ |
|
369 |
if (flags & DC_EXEC) { |
|
2049
ad0d49c916d4
(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
|
370 |
_m[ti.tile].m5 = (byte)(m5 | direction | rail_or_road); |
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
371 |
SetTileType(ti.tile, MP_TUNNELBRIDGE); |
0 | 372 |
|
373 |
//bridges pieces sequence (middle parts) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
374 |
// bridge len 1: 0 |
0 | 375 |
// bridge len 2: 0 1 |
376 |
// bridge len 3: 0 4 1 |
|
377 |
// bridge len 4: 0 2 3 1 |
|
378 |
// bridge len 5: 0 2 5 3 1 |
|
379 |
// bridge len 6: 0 2 3 2 3 1 |
|
380 |
// bridge len 7: 0 2 3 4 2 3 1 |
|
2639 | 381 |
// #0 - always as first, #1 - always as last (if len>1) |
0 | 382 |
// #2,#3 are to pair in order |
383 |
// for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0) |
|
384 |
||
2639 | 385 |
if (i == 0) { // first tile |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
386 |
m5 = 0; |
2639 | 387 |
} else if (i == bridge_len - 1) { // last tile |
0 | 388 |
m5 = 1; |
2639 | 389 |
} else if (i == odd_middle_part) { // we are on the middle of odd bridge: #5 on even pos, #4 on odd |
390 |
m5 = 5 - (i % 2); |
|
391 |
} else { |
|
0 | 392 |
// 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
|
393 |
// this sequence swaps [... XOR (i>odd_middle_part)], |
0 | 394 |
// for even bridges XOR does not apply as odd_middle_part==bridge_len |
2639 | 395 |
m5 = 2 + ((i % 2 == 0) ^ (i > odd_middle_part)); |
0 | 396 |
} |
397 |
||
2049
ad0d49c916d4
(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
|
398 |
_m[ti.tile].m2 = (bridge_type << 4) | m5; |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
399 |
SB(_m[ti.tile].m3, 4, 4, railtype); |
0 | 400 |
|
401 |
MarkTileDirtyByTile(ti.tile); |
|
402 |
} |
|
403 |
} |
|
404 |
||
2639 | 405 |
SetSignalsOnBothDir(ti_start.tile, (direction & 1) ? 1 : 0); |
0 | 406 |
|
407 |
/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST) |
|
408 |
It's unnecessary to execute this command every time for every bridge. So it is done only |
|
409 |
and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated |
|
410 |
*/ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
411 |
if (!(flags & DC_QUERY_COST)) { |
2262
bd59b2d8d75f
(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 |
const Bridge *b = &_bridge[bridge_type]; |
bd59b2d8d75f
(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
|
413 |
|
0 | 414 |
bridge_len += 2; // begin and end tiles/ramps |
415 |
||
2422
914a12dee832
(svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents:
2314
diff
changeset
|
416 |
if (_current_player < MAX_PLAYERS && !_is_old_ai_player) |
0 | 417 |
bridge_len = CalcBridgeLenCostFactor(bridge_len); |
418 |
||
2262
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
419 |
cost += ((int64)bridge_len * _price.build_bridge * b->price) >> 8; |
0 | 420 |
} |
421 |
||
422 |
return cost; |
|
423 |
} |
|
424 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
425 |
static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir) |
0 | 426 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
427 |
TileIndexDiff delta = TileOffsByDir(dir); |
0 | 428 |
TileInfo ti; |
429 |
||
430 |
do { |
|
431 |
tile -= delta; |
|
432 |
FindLandscapeHeightByTile(&ti, tile); |
|
433 |
} while (z < ti.z); |
|
434 |
||
2663 | 435 |
if (z == ti.z && |
436 |
ti.type == MP_TUNNELBRIDGE && |
|
437 |
GB(ti.map5, 4, 4) == 0 && |
|
438 |
GB(ti.map5, 0, 2) == dir) { |
|
0 | 439 |
_error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY; |
440 |
return false; |
|
441 |
} |
|
442 |
||
443 |
return true; |
|
444 |
} |
|
445 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
446 |
bool CheckTunnelInWay(TileIndex tile, int z) |
0 | 447 |
{ |
448 |
return DoCheckTunnelInWay(tile,z,0) && |
|
449 |
DoCheckTunnelInWay(tile,z,1) && |
|
450 |
DoCheckTunnelInWay(tile,z,2) && |
|
451 |
DoCheckTunnelInWay(tile,z,3); |
|
452 |
} |
|
453 |
||
454 |
static byte _build_tunnel_bh; |
|
455 |
static byte _build_tunnel_railtype; |
|
456 |
||
457 |
static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_tile) |
|
458 |
{ |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
459 |
TileIndex end_tile; |
0 | 460 |
int direction; |
461 |
int32 cost, ret; |
|
462 |
TileInfo ti; |
|
463 |
uint z; |
|
464 |
||
856
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
679
diff
changeset
|
465 |
if ((uint)x > MapMaxX() * 16 - 1 || (uint)y > MapMaxY() * 16 - 1) |
0 | 466 |
return CMD_ERROR; |
467 |
||
468 |
/* check if valid, and make sure that (x,y) is smaller than (x2,y2) */ |
|
469 |
direction = 0; |
|
470 |
if (x == x2) { |
|
471 |
if (y == y2) |
|
472 |
return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); |
|
473 |
direction++; |
|
474 |
if (y > y2) { |
|
475 |
intswap(y,y2); |
|
476 |
intswap(x,x2); |
|
477 |
exc_tile|=2; |
|
478 |
} |
|
479 |
} else if (y == y2) { |
|
480 |
if (x > x2) { |
|
481 |
intswap(y,y2); |
|
482 |
intswap(x,x2); |
|
483 |
exc_tile|=2; |
|
484 |
} |
|
485 |
} else |
|
486 |
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); |
|
487 |
||
488 |
cost = 0; |
|
489 |
||
490 |
FindLandscapeHeight(&ti, x2, y2); |
|
491 |
end_tile = ti.tile; |
|
492 |
z = ti.z; |
|
493 |
||
494 |
if (exc_tile != 3) { |
|
2639 | 495 |
if ((direction ? 9U : 12U) != ti.tileh) |
0 | 496 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
497 |
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
498 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 499 |
cost += ret; |
500 |
} |
|
501 |
cost += _price.build_tunnel; |
|
502 |
||
2639 | 503 |
for (;;) { |
0 | 504 |
if (direction) y2-=16; else x2-=16; |
505 |
||
2639 | 506 |
if (x2 == x && y2 == y) break; |
0 | 507 |
|
508 |
FindLandscapeHeight(&ti, x2, y2); |
|
2314
e40125c6fc32
(svn r2840) Remove 3 unnecessary strings (they're empty) and fix the alignment of the musick track display
tron
parents:
2293
diff
changeset
|
509 |
if (ti.z <= z) return CMD_ERROR; |
0 | 510 |
|
511 |
if (!_cheats.crossing_tunnels.value && !CheckTunnelInWay(ti.tile, z)) |
|
512 |
return CMD_ERROR; |
|
513 |
||
514 |
cost += _price.build_tunnel; |
|
515 |
cost += (cost >> 3); |
|
516 |
||
2639 | 517 |
if (cost >= 400000000) cost = 400000000; |
0 | 518 |
} |
519 |
||
520 |
FindLandscapeHeight(&ti, x2, y2); |
|
2314
e40125c6fc32
(svn r2840) Remove 3 unnecessary strings (they're empty) and fix the alignment of the musick track display
tron
parents:
2293
diff
changeset
|
521 |
if (ti.z != z) return CMD_ERROR; |
0 | 522 |
|
523 |
if (exc_tile != 1) { |
|
2639 | 524 |
if ((direction ? 6U : 3U) != ti.tileh) |
0 | 525 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
526 |
||
527 |
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
0ac16ff36293
(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
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
553 |
/** Build Tunnel. |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
554 |
* @param x,y start tile coord of tunnel |
1784
6eb3ab1bc33c
(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 |
2639 | 556 |
* @param p2 unused |
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
0ac16ff36293
(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
6eb3ab1bc33c
(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
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
570 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
571 |
_build_tunnel_railtype = GB(p1, 0, 8); |
010d923a81a9
(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 |
||
2639 | 582 |
if (!(direction=0, tiorg.tileh == 12) && |
583 |
!(direction++, tiorg.tileh == 6) && |
|
584 |
!(direction++, tiorg.tileh == 3) && |
|
585 |
!(direction++, tiorg.tileh == 9)) { |
|
0 | 586 |
return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL); |
2639 | 587 |
} |
0 | 588 |
|
589 |
z = tiorg.z; |
|
590 |
do { |
|
591 |
x += _build_tunnel_coord_mod[direction]; |
|
592 |
y += _build_tunnel_coord_mod[direction+1]; |
|
593 |
FindLandscapeHeight(&ti, x, y); |
|
594 |
} while (z != ti.z); |
|
595 |
_build_tunnel_endtile = ti.tile; |
|
596 |
||
597 |
||
2639 | 598 |
if (!EnsureNoVehicle(ti.tile)) return CMD_ERROR; |
0 | 599 |
|
600 |
if (ti.tileh != _build_tunnel_tileh[direction]) { |
|
1782
0ac16ff36293
(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
0ac16ff36293
(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
68847f67a412
(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
a635854c23b6
(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
ad0d49c916d4
(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
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
614 |
uint len = 0; |
1977
4392ae3d8e31
(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
0a170deb6e33
(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 { |
0a170deb6e33
(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; |
0a170deb6e33
(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++; |
0a170deb6e33
(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 ( |
0a170deb6e33
(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) || |
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
623 |
GB(_m[tile].m5, 4, 4) != 0 || |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
624 |
(_m[tile].m5 ^ 2) != m5 || |
1035
0a170deb6e33
(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 |
0a170deb6e33
(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
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
628 |
v = FindVehicleBetween(starttile, tile, z); |
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
629 |
if (v != NULL) { |
68847f67a412
(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 ? |
68847f67a412
(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; |
68847f67a412
(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
68847f67a412
(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
4392ae3d8e31
(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
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
642 |
TileIndex endtile; |
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
643 |
uint length; |
1782
0ac16ff36293
(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
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
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
68847f67a412
(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
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
662 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
0 | 663 |
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) { |
534
17ab2f22ff74
(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!! ;) |
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
672 |
byte tile_dir = GB(_m[tile].m5, 0, 2); |
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
673 |
byte endtile_dir = GB(_m[endtile].m5, 0, 2); |
2870
32c980d2b8e9
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
674 |
|
32c980d2b8e9
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
675 |
// Adjust the town's player rating. Do this before removing the tile owner info. |
32c980d2b8e9
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
676 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) |
32c980d2b8e9
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
677 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
32c980d2b8e9
(svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents:
2843
diff
changeset
|
678 |
|
0 | 679 |
DoClearSquare(tile); |
680 |
DoClearSquare(endtile); |
|
38
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
681 |
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
|
682 |
UpdateSignalsOnSegment(endtile, _updsignals_tunnel_dir[endtile_dir]); |
0 | 683 |
} |
2639 | 684 |
return _price.clear_tunnel * (length + 1); |
0 | 685 |
} |
686 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
687 |
static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile) |
0 | 688 |
{ |
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
689 |
int direction = GB(_m[tile].m5, 0, 1); |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
690 |
TileIndex start; |
0 | 691 |
|
692 |
// find start of bridge |
|
693 |
for(;;) { |
|
2049
ad0d49c916d4
(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
|
694 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0x80) |
0 | 695 |
break; |
1981 | 696 |
tile += direction ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); |
0 | 697 |
} |
698 |
||
699 |
start = tile; |
|
700 |
||
701 |
// find end of bridge |
|
702 |
for(;;) { |
|
2049
ad0d49c916d4
(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
|
703 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0xA0) |
0 | 704 |
break; |
1981 | 705 |
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 706 |
} |
707 |
||
708 |
*endtile = tile; |
|
709 |
||
710 |
return start; |
|
711 |
} |
|
712 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
713 |
static int32 DoClearBridge(TileIndex tile, uint32 flags) |
0 | 714 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
715 |
TileIndex endtile; |
0 | 716 |
Vehicle *v; |
717 |
Town *t; |
|
718 |
int direction; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
719 |
|
0 | 720 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
721 |
||
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
722 |
direction = GB(_m[tile].m5, 0, 1); |
0 | 723 |
|
724 |
/* delete stuff under the middle part if there's a transport route there..? */ |
|
2049
ad0d49c916d4
(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
|
725 |
if ((_m[tile].m5 & 0xE0) == 0xE0) { |
0 | 726 |
int32 cost; |
727 |
||
728 |
// check if we own the tile below the bridge.. |
|
1041
be151b7bc909
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
729 |
if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))) |
0 | 730 |
return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
731 |
|
2049
ad0d49c916d4
(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 |
cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail; |
0 | 733 |
|
734 |
if (flags & DC_EXEC) { |
|
2049
ad0d49c916d4
(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
|
735 |
_m[tile].m5 = _m[tile].m5 & ~0x38; |
1902 | 736 |
SetTileOwner(tile, OWNER_NONE); |
0 | 737 |
MarkTileDirtyByTile(tile); |
738 |
} |
|
739 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
740 |
|
0 | 741 |
/* delete canal under bridge */ |
2049
ad0d49c916d4
(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
|
742 |
} else if ((_m[tile].m5 & 0xC8) == 0xC8 && TilePixelHeight(tile) != 0) { |
0 | 743 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
744 |
|
0 | 745 |
// check for vehicles under bridge |
2639 | 746 |
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR; |
0 | 747 |
cost = _price.clear_water; |
748 |
if (flags & DC_EXEC) { |
|
2049
ad0d49c916d4
(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
|
749 |
_m[tile].m5 = _m[tile].m5 & ~0x38; |
1902 | 750 |
SetTileOwner(tile, OWNER_NONE); |
0 | 751 |
MarkTileDirtyByTile(tile); |
752 |
} |
|
753 |
return cost; |
|
754 |
} |
|
755 |
||
756 |
tile = FindEdgesOfBridge(tile, &endtile); |
|
757 |
||
758 |
// floods, scenario editor can always destroy bridges |
|
759 |
if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) { |
|
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
760 |
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN)) |
0 | 761 |
return CMD_ERROR; |
762 |
} |
|
763 |
||
2639 | 764 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) return CMD_ERROR; |
0 | 765 |
|
766 |
/* Make sure there's no vehicle on the bridge |
|
767 |
Omit tile and endtile, since these are already checked, thus solving the problem |
|
768 |
of bridges over water, or higher bridges, where z is not increased, eg level bridge |
|
769 |
*/ |
|
1981 | 770 |
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
771 |
endtile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
|
1082
56a4c048c5c3
(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 |
/* Bridges on slopes might have their Z-value offset..correct this */ |
2639 | 773 |
v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile)); |
774 |
if (v != NULL) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
775 |
VehicleInTheWayErrMsg(v); |
0 | 776 |
return CMD_ERROR; |
777 |
} |
|
778 |
||
779 |
/* Put the tiles back to start/end position */ |
|
1981 | 780 |
tile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
781 |
endtile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
|
0 | 782 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
783 |
|
0 | 784 |
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
|
785 |
// check if you're allowed to remove the bridge owned by a town. |
0 | 786 |
// removal allowal depends on difficulty settings |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
787 |
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
|
788 |
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) |
0 | 789 |
return CMD_ERROR; |
790 |
} |
|
791 |
||
792 |
if (flags & DC_EXEC) { |
|
793 |
byte m5; |
|
794 |
uint c = tile; |
|
795 |
uint16 new_data; |
|
796 |
||
1005 | 797 |
//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until |
0 | 798 |
// you have a "Poor" (0) town rating |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
799 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) |
1005 | 800 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
0 | 801 |
|
802 |
do { |
|
2049
ad0d49c916d4
(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
|
803 |
m5 = _m[c].m5; |
0 | 804 |
|
805 |
if (m5 & 0x40) { |
|
9936
53d4d464b85c
(svn r3967) - Fix: Properly set back the owner of a crossing/road-under bridge after removing it. For crossings we can always use .m2 because it is already 0 when not owned by a town. Backport of r3876, r3893 from trunk
Darkvater
parents:
2934
diff
changeset
|
806 |
uint town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0; |
53d4d464b85c
(svn r3967) - Fix: Properly set back the owner of a crossing/road-under bridge after removing it. For crossings we can always use .m2 because it is already 0 when not owned by a town. Backport of r3876, r3893 from trunk
Darkvater
parents:
2934
diff
changeset
|
807 |
|
0 | 808 |
if (m5 & 0x20) { |
809 |
static const uint16 _new_data_table[] = {0x1002, 0x1001, 0x2005, 0x200A, 0, 0, 0, 0}; |
|
2639 | 810 |
new_data = _new_data_table[((m5 & 0x18) >> 2) | (m5 & 1)]; |
0 | 811 |
} else { |
2635 | 812 |
if (GB(m5, 3, 2) == 0) goto clear_it; |
1091
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
813 |
new_data = (GetTileSlope(c, NULL) == 0) ? 0x6000 : 0x6001; |
0 | 814 |
} |
815 |
||
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
816 |
SetTileType(c, new_data >> 12); |
2049
ad0d49c916d4
(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].m5 = (byte)new_data; |
9936
53d4d464b85c
(svn r3967) - Fix: Properly set back the owner of a crossing/road-under bridge after removing it. For crossings we can always use .m2 because it is already 0 when not owned by a town. Backport of r3876, r3893 from trunk
Darkvater
parents:
2934
diff
changeset
|
818 |
_m[c].m2 = town; |
2049
ad0d49c916d4
(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
|
819 |
_m[c].m4 &= 0x0F; |
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 |
||
2931
d9e2973a110f
(svn r3487) -Fix: Price for demolishing a bridge was dependent on orientation and map size
tron
parents:
2916
diff
changeset
|
835 |
if (direction) { |
d9e2973a110f
(svn r3487) -Fix: Price for demolishing a bridge was dependent on orientation and map size
tron
parents:
2916
diff
changeset
|
836 |
return (TileY(endtile) - TileY(tile) + 1) * _price.clear_bridge; |
d9e2973a110f
(svn r3487) -Fix: Price for demolishing a bridge was dependent on orientation and map size
tron
parents:
2916
diff
changeset
|
837 |
} else { |
d9e2973a110f
(svn r3487) -Fix: Price for demolishing a bridge was dependent on orientation and map size
tron
parents:
2916
diff
changeset
|
838 |
return (TileX(endtile) - TileX(tile) + 1) * _price.clear_bridge; |
d9e2973a110f
(svn r3487) -Fix: Price for demolishing a bridge was dependent on orientation and map size
tron
parents:
2916
diff
changeset
|
839 |
} |
0 | 840 |
} |
841 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
842 |
static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
843 |
{ |
2049
ad0d49c916d4
(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
|
844 |
byte m5 = _m[tile].m5; |
0 | 845 |
|
846 |
if ((m5 & 0xF0) == 0) { |
|
2639 | 847 |
if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST); |
1082
56a4c048c5c3
(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
|
848 |
|
0 | 849 |
return DoClearTunnel(tile, flags); |
850 |
} else if (m5 & 0x80) { |
|
2639 | 851 |
if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
0 | 852 |
|
1082
56a4c048c5c3
(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
|
853 |
return DoClearBridge(tile, flags); |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
854 |
} |
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
855 |
|
1082
56a4c048c5c3
(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
|
856 |
return CMD_ERROR; |
0 | 857 |
} |
858 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
859 |
int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec) |
0 | 860 |
{ |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
861 |
TileIndex endtile; |
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
862 |
uint length; |
0 | 863 |
Vehicle *v; |
864 |
||
2049
ad0d49c916d4
(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
|
865 |
if ((_m[tile].m5 & 0xFC) == 0x00) { |
0 | 866 |
// railway tunnel |
867 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
868 |
||
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
869 |
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
870 |
|
0 | 871 |
endtile = CheckTunnelBusy(tile, &length); |
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
872 |
if (endtile == INVALID_TILE) return CMD_ERROR; |
0 | 873 |
|
874 |
if (exec) { |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
875 |
SB(_m[tile].m3, 0, 4, totype); |
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
876 |
SB(_m[endtile].m3, 0, 4, totype); |
0 | 877 |
MarkTileDirtyByTile(tile); |
878 |
MarkTileDirtyByTile(endtile); |
|
879 |
} |
|
880 |
return (length + 1) * (_price.build_rail >> 1); |
|
2049
ad0d49c916d4
(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
|
881 |
} else if ((_m[tile].m5 & 0xF8) == 0xE0) { |
0 | 882 |
// bridge middle part with rail below |
883 |
// only check for train under bridge |
|
1041
be151b7bc909
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
884 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 885 |
return CMD_ERROR; |
886 |
||
887 |
// tile is already of requested type? |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
888 |
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; |
0 | 889 |
// change type. |
890 |
if (exec) { |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
891 |
SB(_m[tile].m3, 0, 4, totype); |
0 | 892 |
MarkTileDirtyByTile(tile); |
893 |
} |
|
894 |
return _price.build_rail >> 1; |
|
2639 | 895 |
} else if ((_m[tile].m5 & 0xC6) == 0x80) { |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
896 |
TileIndex starttile; |
0 | 897 |
int32 cost; |
1073
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
898 |
uint z = TilePixelHeight(tile); |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
899 |
|
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
900 |
z += 8; |
0 | 901 |
|
902 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
903 |
||
904 |
// railway bridge |
|
905 |
starttile = tile = FindEdgesOfBridge(tile, &endtile); |
|
906 |
// Make sure there's no vehicle on the bridge |
|
2639 | 907 |
v = FindVehicleBetween(tile, endtile, z); |
908 |
if (v != NULL) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
909 |
VehicleInTheWayErrMsg(v); |
0 | 910 |
return CMD_ERROR; |
911 |
} |
|
912 |
||
1073
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
913 |
if (!EnsureNoVehicle(starttile) || !EnsureNoVehicle(endtile)) { |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
914 |
_error_message = STR_8803_TRAIN_IN_THE_WAY; |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
915 |
return CMD_ERROR; |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
916 |
} |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
917 |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
918 |
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; |
0 | 919 |
cost = 0; |
920 |
do { |
|
921 |
if (exec) { |
|
922 |
if (tile == starttile || tile == endtile) { |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
923 |
SB(_m[tile].m3, 0, 4, totype); |
0 | 924 |
} else { |
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
925 |
SB(_m[tile].m3, 4, 4, totype); |
0 | 926 |
} |
927 |
MarkTileDirtyByTile(tile); |
|
928 |
} |
|
2639 | 929 |
cost += _price.build_rail >> 1; |
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
930 |
tile += GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 931 |
} while (tile <= endtile); |
932 |
||
933 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
934 |
} else |
0 | 935 |
return CMD_ERROR; |
936 |
} |
|
937 |
||
938 |
||
939 |
// fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile. |
|
1095 | 940 |
static uint GetBridgeHeight(const TileInfo *ti) |
0 | 941 |
{ |
1981 | 942 |
TileIndexDiff delta; |
1192
cd9b8a18a183
(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
|
943 |
TileIndex tile = ti->tile; |
0 | 944 |
|
945 |
// find the end tile of the bridge. |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
946 |
delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 947 |
do { |
2049
ad0d49c916d4
(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
|
948 |
assert((_m[tile].m5 & 0xC0) == 0xC0); // bridge and middle part |
0 | 949 |
tile += delta; |
2049
ad0d49c916d4
(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
|
950 |
} while (_m[tile].m5 & 0x40); // while bridge middle parts |
0 | 951 |
|
1192
cd9b8a18a183
(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 the height there (the height of the NORTH CORNER) |
cd9b8a18a183
(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
|
953 |
* If the end of the bridge is on a tileh 7 (all raised, except north corner), |
cd9b8a18a183
(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
|
954 |
* the z coordinate is 1 height level too low. Compensate for that */ |
cd9b8a18a183
(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
|
955 |
return TilePixelHeight(tile) + (GetTileSlope(tile, NULL) == 7 ? 8 : 0); |
0 | 956 |
} |
957 |
||
958 |
static const byte _bridge_foundations[2][16] = { |
|
959 |
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
960 |
{1,16,18,3,20,5,0,7,22,0,10,11,12,13,14}, |
|
961 |
{1,15,17,0,19,5,6,7,21,9,10,11, 0,13,14}, |
|
962 |
}; |
|
963 |
||
964 |
extern const byte _road_sloped_sprites[14]; |
|
965 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2422
diff
changeset
|
966 |
static void DrawBridgePillars(const TileInfo *ti, int x, int y, int z) |
0 | 967 |
{ |
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
968 |
const PalSpriteID *b; |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
969 |
PalSpriteID image; |
0 | 970 |
int piece; |
971 |
||
2262
bd59b2d8d75f
(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
|
972 |
b = _bridge_poles_table[GetBridgeType(ti->tile)]; |
0 | 973 |
|
974 |
// Draw first piece |
|
975 |
// (necessary for cantilever bridges) |
|
2262
bd59b2d8d75f
(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 |
|
2642 | 977 |
image = b[12 + GB(ti->map5, 0, 1)]; |
2262
bd59b2d8d75f
(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
|
978 |
piece = GetBridgePiece(ti->tile); |
bd59b2d8d75f
(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
|
979 |
|
333
6dee54ed9701
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
980 |
if (image != 0 && piece != 0) { |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
981 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
333
6dee54ed9701
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
982 |
DrawGroundSpriteAt(image, x, y, z); |
6dee54ed9701
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
983 |
} |
0 | 984 |
|
2642 | 985 |
image = b[GB(ti->map5, 0, 1) * 6 + piece]; |
0 | 986 |
|
987 |
if (image != 0) { |
|
988 |
int back_height, front_height, i=z; |
|
989 |
const byte *p; |
|
990 |
||
991 |
static const byte _tileh_bits[4][8] = { |
|
992 |
{2,1,8,4, 16,11,0,9}, |
|
993 |
{1,8,4,2, 11,16,9,0}, |
|
994 |
{4,8,1,2, 16,11,0,9}, |
|
995 |
{2,4,8,1, 11,16,9,0}, |
|
996 |
}; |
|
997 |
||
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
998 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
333
6dee54ed9701
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
999 |
|
0 | 1000 |
p = _tileh_bits[(image & 1) * 2 + (ti->map5&0x01)]; |
1001 |
front_height = ti->z + ((ti->tileh & p[0])?8:0); |
|
1002 |
back_height = ti->z + ((ti->tileh & p[1])?8:0); |
|
2262
bd59b2d8d75f
(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
|
1003 |
|
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
1004 |
if (IsSteepTileh(ti->tileh)) { |
0 | 1005 |
if (!(ti->tileh & p[2])) front_height += 8; |
1006 |
if (!(ti->tileh & p[3])) back_height += 8; |
|
1007 |
} |
|
1008 |
||
1009 |
for(; z>=front_height || z>=back_height; z=z-8) { |
|
1010 |
if (z>=front_height) AddSortableSpriteToDraw(image, x,y, p[4], p[5], 0x28, z); // front facing pillar |
|
1011 |
if (z>=back_height && z<i-8) AddSortableSpriteToDraw(image, x - p[6], y - p[7], p[4], p[5], 0x28, z); // back facing pillar |
|
1012 |
} |
|
1013 |
} |
|
1014 |
} |
|
1015 |
||
2639 | 1016 |
uint GetBridgeFoundation(uint tileh, byte direction) |
1017 |
{ |
|
0 | 1018 |
int i; |
1019 |
// normal level sloped building (7, 11, 13, 14) |
|
1020 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) |
|
1021 |
return tileh; |
|
1022 |
||
1023 |
// inclined sloped building |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1024 |
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && |
0 | 1025 |
( direction == 0 || (i++, direction == 1)) ) |
1026 |
return i + 15; |
|
1027 |
||
1028 |
return 0; |
|
1029 |
} |
|
1030 |
||
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1031 |
/** |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1032 |
* Draws a tunnel of bridge tile. |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1033 |
* For tunnels, this is rather simple, as you only needa draw the entrance. |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1034 |
* Bridges are a bit more complex. base_offset is where the sprite selection comes into play |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1035 |
* and it works a bit like a bitmask.<p> For bridge heads: |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1036 |
* <ul><li>Bit 0: direction</li> |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1037 |
* <li>Bit 1: northern or southern heads</li> |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1038 |
* <li>Bit 2: Set if the bridge head is sloped</li> |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1039 |
* <li>Bit 3 and more: Railtype Specific subset</li> |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1040 |
* </ul> |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1041 |
* For middle parts: |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1042 |
* <ul><li>Bits 0-1: need to be 0</li> |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1043 |
* <li>Bit 2: direction</li> |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1044 |
* <li>Bit 3 and above: Railtype Specific subset</li> |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1045 |
* </ul> |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1046 |
* Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3 |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1047 |
*/ |
0 | 1048 |
static void DrawTile_TunnelBridge(TileInfo *ti) |
1049 |
{ |
|
1050 |
uint32 image; |
|
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1051 |
const PalSpriteID *b; |
2049
ad0d49c916d4
(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
|
1052 |
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
|
1053 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1054 |
// draw tunnel? |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
1055 |
if ((ti->map5 & 0xF0) == 0) { |
2511
0a81d9ca79bc
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
1056 |
if (GB(ti->map5, 2, 2) == 0) { /* Rail tunnel? */ |
0a81d9ca79bc
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
1057 |
image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel; |
0a81d9ca79bc
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
1058 |
} else { |
0a81d9ca79bc
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
1059 |
image = SPR_TUNNEL_ENTRY_REAR_ROAD; |
0a81d9ca79bc
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
1060 |
} |
0 | 1061 |
|
2511
0a81d9ca79bc
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
1062 |
if (ice) image += 32; |
0 | 1063 |
|
2140
d708eb80ab8b
(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
|
1064 |
image += GB(ti->map5, 0, 2) * 2; |
0 | 1065 |
DrawGroundSprite(image); |
1066 |
||
1067 |
AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z); |
|
1068 |
// draw bridge? |
|
2644 | 1069 |
} else if (ti->map5 & 0x80) { |
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1070 |
RailType rt; |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1071 |
int base_offset; |
0 | 1072 |
|
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1073 |
if (HASBIT(ti->map5, 1)) { /* This is a road bridge */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1074 |
base_offset = 8; |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1075 |
} else { /* Rail bridge */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1076 |
if (HASBIT(ti->map5, 6)) { /* The bits we need depend on the fact whether it is a bridge head or not */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1077 |
rt = GB(_m[ti->tile].m3, 4, 3); |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1078 |
} else { |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1079 |
rt = GB(_m[ti->tile].m3, 0, 3); |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1080 |
} |
0 | 1081 |
|
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1082 |
base_offset = GetRailTypeInfo(rt)->bridge_offset; |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1083 |
assert(base_offset != 8); /* This one is used for roads */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1084 |
} |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1085 |
|
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1086 |
/* as the lower 3 bits are used for other stuff, make sure they are clear */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1087 |
assert( (base_offset & 0x07) == 0x00); |
0 | 1088 |
|
1089 |
if (!(ti->map5 & 0x40)) { // bridge ramps |
|
1090 |
if (!(BRIDGE_NO_FOUNDATION & (1 << ti->tileh))) { // no foundations for 0, 3, 6, 9, 12 |
|
1091 |
int f = GetBridgeFoundation(ti->tileh, ti->map5 & 0x1); // pass direction |
|
1092 |
if (f) DrawFoundation(ti, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1093 |
|
0 | 1094 |
// default sloped sprites.. |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2511
diff
changeset
|
1095 |
if (ti->tileh != 0) image = SPR_RAIL_TRACK_Y + _track_sloped_sprites[ti->tileh - 1]; |
0 | 1096 |
} |
1097 |
||
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1098 |
/* Cope for the direction of the bridge */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1099 |
if (HASBIT(ti->map5, 0)) base_offset++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1100 |
|
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1101 |
if (ti->map5 & 0x20) base_offset += 2; // which side |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1102 |
if (ti->tileh == 0) base_offset += 4; // sloped bridge head |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1103 |
|
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1104 |
/* Table number 6 always refers to the bridge heads for any bridge type */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1105 |
image = GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset]; |
0 | 1106 |
|
1107 |
if (!ice) { |
|
1108 |
DrawClearLandTile(ti, 3); |
|
1109 |
} else { |
|
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2511
diff
changeset
|
1110 |
DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh]); |
0 | 1111 |
} |
1112 |
||
1113 |
// draw ramp |
|
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1114 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1115 |
AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z); |
1116 |
} else { |
|
1117 |
// bridge middle part. |
|
1118 |
uint z; |
|
1119 |
int x,y; |
|
1120 |
||
2140
d708eb80ab8b
(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
|
1121 |
image = GB(ti->map5, 3, 2); // type of stuff under bridge (only defined for 0,1) |
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1122 |
/** @todo So why do we even WASTE that one bit?! (map5, bit 4) */ |
0 | 1123 |
assert(image <= 1); |
1124 |
||
1125 |
if (!(ti->map5 & 0x20)) { |
|
1126 |
// draw land under bridge |
|
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2187
diff
changeset
|
1127 |
if (ice) image += 2; |
1091
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1128 |
|
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1129 |
if (image != 1 || ti->tileh == 0) |
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1130 |
DrawGroundSprite(_bridge_land_below[image] + _tileh_to_sprite[ti->tileh]); |
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1131 |
else |
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1132 |
DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
0 | 1133 |
|
1134 |
// draw canal water? |
|
1135 |
if (ti->map5 & 8 && ti->z != 0) DrawCanalWater(ti->tile); |
|
1136 |
} else { |
|
1137 |
// draw transport route under bridge |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1138 |
|
0 | 1139 |
// draw foundation? |
1140 |
if (ti->tileh) { |
|
1141 |
int f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1142 |
if (f) DrawFoundation(ti, f); |
|
1143 |
} |
|
1144 |
||
1145 |
if (!(image&1)) { |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1146 |
const RailtypeInfo *rti = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4)); |
0 | 1147 |
// railway |
2535 | 1148 |
image = SPR_RAIL_TRACK_Y + (ti->map5 & 1); |
1149 |
if (ti->tileh != 0) image = SPR_RAIL_TRACK_Y + _track_sloped_sprites[ti->tileh - 1]; |
|
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2187
diff
changeset
|
1150 |
image += rti->total_offset; |
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2187
diff
changeset
|
1151 |
if (ice) image += rti->snow_offset; |
0 | 1152 |
} else { |
1153 |
// road |
|
2535 | 1154 |
image = SPR_ROAD_Y + (ti->map5 & 1); |
0 | 1155 |
if (ti->tileh != 0) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1156 |
if (ice) image += 19; |
0 | 1157 |
} |
1158 |
DrawGroundSprite(image); |
|
1159 |
} |
|
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1160 |
|
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1161 |
/* Cope for the direction of the bridge */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1162 |
if (HASBIT(ti->map5, 0)) base_offset += 4; |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1163 |
|
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1164 |
/* base_offset needs to be 0 due to the structure of the sprite table see table/bridge_land.h */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1165 |
assert( (base_offset & 0x03) == 0x00); |
0 | 1166 |
// get bridge sprites |
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1167 |
b = GetBridgeSpriteTable(GetBridgeType(ti->tile), GetBridgePiece(ti->tile)) + base_offset; |
0 | 1168 |
|
1169 |
z = GetBridgeHeight(ti) + 5; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1170 |
|
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1171 |
// draw rail or road component |
0 | 1172 |
image = b[0]; |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1173 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1174 |
AddSortableSpriteToDraw(image, ti->x, ti->y, (ti->map5&1)?11:16, (ti->map5&1)?16:11, 1, z); |
1175 |
||
1176 |
x = ti->x; |
|
1177 |
y = ti->y; |
|
1178 |
image = b[1]; |
|
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1179 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1180 |
|
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
1181 |
// draw roof, the component of the bridge which is logically between the vehicle and the camera |
0 | 1182 |
if (ti->map5&1) { |
1183 |
x += 12; |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
1184 |
if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 1, 16, 0x28, z); |
0 | 1185 |
} else { |
1186 |
y += 12; |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
1187 |
if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 16, 1, 0x28, z); |
0 | 1188 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1189 |
|
0 | 1190 |
if (ti->z + 5 == z ) { |
1191 |
// draw poles below for small bridges |
|
1192 |
image = b[2]; |
|
1193 |
if (image) { |
|
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
1194 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 1195 |
DrawGroundSpriteAt(image, x, y, z); |
1196 |
} |
|
1197 |
} else if (_patches.bridge_pillars) { |
|
1198 |
// draw pillars below for high bridges |
|
1199 |
DrawBridgePillars(ti, x, y, z); |
|
1200 |
} |
|
1201 |
} |
|
1202 |
} |
|
1203 |
} |
|
1204 |
||
2537 | 1205 |
static uint GetSlopeZ_TunnelBridge(const TileInfo* ti) |
1206 |
{ |
|
0 | 1207 |
uint z = ti->z; |
1208 |
uint x = ti->x & 0xF; |
|
1209 |
uint y = ti->y & 0xF; |
|
2537 | 1210 |
uint tileh = ti->tileh; |
0 | 1211 |
|
1212 |
// swap directions if Y tunnel/bridge to let the code handle the X case only. |
|
1884
ae1d6213c6dd
(svn r2390) - Codechange: Fix some warnings on GCC 4.0.0
hackykid
parents:
1784
diff
changeset
|
1213 |
if (ti->map5 & 1) uintswap(x,y); |
0 | 1214 |
|
1215 |
// to the side of the tunnel/bridge? |
|
1216 |
if (IS_INT_INSIDE(y, 5, 10+1)) { |
|
1217 |
// tunnel? |
|
2639 | 1218 |
if ((ti->map5 & 0xF0) == 0) return z; |
0 | 1219 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1220 |
// bridge? |
2639 | 1221 |
if (ti->map5 & 0x80) { |
0 | 1222 |
// bridge ending? |
1223 |
if (!(ti->map5 & 0x40)) { |
|
2537 | 1224 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) // 7, 11, 13, 14 |
0 | 1225 |
z += 8; |
1226 |
||
1227 |
// no ramp for bridge ending |
|
2537 | 1228 |
if ((BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << tileh) || BRIDGE_NO_FOUNDATION & (1 << tileh)) && tileh != 0) { |
0 | 1229 |
return z + 8; |
1230 |
} else if (!(ti->map5 & 0x20)) { // northern / southern ending |
|
1231 |
// ramp |
|
1232 |
return (z + (x>>1) + 1); |
|
1233 |
} else { |
|
1234 |
// ramp in opposite dir |
|
1235 |
return (z + ((x^0xF)>>1)); |
|
1236 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1237 |
|
0 | 1238 |
// bridge middle part |
1239 |
} else { |
|
1240 |
// build on slopes? |
|
2537 | 1241 |
if (tileh != 0) z += 8; |
0 | 1242 |
|
1243 |
// keep the same elevation because we're on the bridge? |
|
2639 | 1244 |
if (_get_z_hint >= z + 8) return _get_z_hint; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1245 |
|
0 | 1246 |
// actually on the bridge, but not yet in the shared area. |
2639 | 1247 |
if (!IS_INT_INSIDE(x, 5, 10 + 1)) return GetBridgeHeight(ti) + 8; |
0 | 1248 |
|
1249 |
// in the shared area, assume that we're below the bridge, cause otherwise the hint would've caught it. |
|
1250 |
// if rail or road below then it means it's possibly build on slope below the bridge. |
|
1251 |
if (ti->map5 & 0x20) { |
|
2537 | 1252 |
uint f = _bridge_foundations[ti->map5 & 1][tileh]; |
0 | 1253 |
// make sure that the slope is not inclined foundation |
1254 |
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
|
1255 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2422
diff
changeset
|
1256 |
// change foundation type? XXX - should be const; accessor function! |
2537 | 1257 |
if (f != 0) tileh = _inclined_tileh[f - 15]; |
0 | 1258 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1259 |
|
0 | 1260 |
// no transport route, fallback to default |
1261 |
} |
|
1262 |
} |
|
1263 |
} else { |
|
1264 |
// if it's a bridge middle with transport route below, then we need to compensate for build on slopes |
|
2639 | 1265 |
if ((ti->map5 & (0x80 | 0x40 | 0x20)) == (0x80 | 0x40 | 0x20)) { |
0 | 1266 |
uint f; |
2537 | 1267 |
if (tileh != 0) z += 8; |
2639 | 1268 |
f = _bridge_foundations[ti->map5 & 1][tileh]; |
0 | 1269 |
if (IS_BYTE_INSIDE(f, 1, 15)) return z; |
2537 | 1270 |
if (f != 0) tileh = _inclined_tileh[f - 15]; |
0 | 1271 |
} |
1272 |
} |
|
1273 |
||
1274 |
// default case |
|
2639 | 1275 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh) + ti->z; |
0 | 1276 |
} |
1277 |
||
2639 | 1278 |
static uint GetSlopeTileh_TunnelBridge(const TileInfo* ti) |
1279 |
{ |
|
39 | 1280 |
// not accurate, but good enough for slope graphics drawing |
1281 |
return 0; |
|
1282 |
} |
|
1283 |
||
1284 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1285 |
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac) |
0 | 1286 |
{ |
1287 |
/* not used */ |
|
1288 |
} |
|
1289 |
||
1290 |
static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = { |
|
1291 |
STR_501F_WOODEN_RAIL_BRIDGE, |
|
1292 |
STR_5020_CONCRETE_RAIL_BRIDGE, |
|
1293 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1294 |
STR_501E_REINFORCED_CONCRETE_SUSPENSION, |
|
1295 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1296 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1297 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1298 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1299 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1300 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1301 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1302 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1303 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1304 |
0,0,0, |
|
1305 |
||
1306 |
STR_5025_WOODEN_ROAD_BRIDGE, |
|
1307 |
STR_5026_CONCRETE_ROAD_BRIDGE, |
|
1308 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1309 |
STR_5024_REINFORCED_CONCRETE_SUSPENSION, |
|
1310 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1311 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1312 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1313 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1314 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1315 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1316 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1317 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1318 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1319 |
0,0,0, |
|
1320 |
}; |
|
1321 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1322 |
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td) |
0 | 1323 |
{ |
2049
ad0d49c916d4
(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
|
1324 |
if ((_m[tile].m5 & 0x80) == 0) { |
2260
3e97367f7cbc
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2254
diff
changeset
|
1325 |
td->str = |
3e97367f7cbc
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2254
diff
changeset
|
1326 |
(GB(_m[tile].m5, 2, 2) == 0) ? STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL; |
0 | 1327 |
} else { |
2140
d708eb80ab8b
(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
|
1328 |
td->str = _bridge_tile_str[GB(_m[tile].m5, 1, 2) << 4 | GB(_m[tile].m2, 4, 4)]; |
0 | 1329 |
|
1330 |
/* scan to the end of the bridge, that's where the owner is stored */ |
|
2049
ad0d49c916d4
(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 |
if (_m[tile].m5 & 0x40) { |
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1332 |
TileIndexDiff delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); |
1981 | 1333 |
|
2049
ad0d49c916d4
(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
|
1334 |
do tile += delta; while (_m[tile].m5 & 0x40); |
0 | 1335 |
} |
1336 |
} |
|
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1337 |
td->owner = GetTileOwner(tile); |
0 | 1338 |
} |
1339 |
||
1340 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1341 |
static void AnimateTile_TunnelBridge(TileIndex tile) |
0 | 1342 |
{ |
1343 |
/* not used */ |
|
1344 |
} |
|
1345 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1346 |
static void TileLoop_TunnelBridge(TileIndex tile) |
0 | 1347 |
{ |
1348 |
if (_opt.landscape == LT_HILLY) { |
|
2639 | 1349 |
if (GetTileZ(tile) > _opt.snow_line) { |
2049
ad0d49c916d4
(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
|
1350 |
if (!(_m[tile].m4 & 0x80)) { |
ad0d49c916d4
(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
|
1351 |
_m[tile].m4 |= 0x80; |
0 | 1352 |
MarkTileDirtyByTile(tile); |
1353 |
} |
|
1354 |
} else { |
|
2049
ad0d49c916d4
(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
|
1355 |
if (_m[tile].m4 & 0x80) { |
ad0d49c916d4
(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
|
1356 |
_m[tile].m4 &= ~0x80; |
0 | 1357 |
MarkTileDirtyByTile(tile); |
1358 |
} |
|
1359 |
} |
|
1360 |
} else if (_opt.landscape == LT_DESERT) { |
|
2049
ad0d49c916d4
(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
|
1361 |
if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4&0x80)) { |
ad0d49c916d4
(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
|
1362 |
_m[tile].m4 |= 0x80; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1363 |
MarkTileDirtyByTile(tile); |
0 | 1364 |
} |
1365 |
} |
|
1366 |
||
1367 |
// if it's a bridge with water below, call tileloop_water on it. |
|
2049
ad0d49c916d4
(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
|
1368 |
if ((_m[tile].m5 & 0xF8) == 0xC8) TileLoop_Water(tile); |
0 | 1369 |
} |
1370 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1371 |
static void ClickTile_TunnelBridge(TileIndex tile) |
0 | 1372 |
{ |
1373 |
/* not used */ |
|
1374 |
} |
|
1375 |
||
1376 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1377 |
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode) |
0 | 1378 |
{ |
1379 |
uint32 result; |
|
2049
ad0d49c916d4
(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
|
1380 |
byte m5 = _m[tile].m5; |
0 | 1381 |
|
1382 |
if ((m5 & 0xF0) == 0) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1383 |
/* This is a tunnel */ |
2635 | 1384 |
if (GB(m5, 2, 2) == mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1385 |
/* Tranport in the tunnel is compatible */ |
0 | 1386 |
return m5&1 ? 0x202 : 0x101; |
1387 |
} |
|
1388 |
} else if (m5 & 0x80) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1389 |
/* This is a bridge */ |
0 | 1390 |
result = 0; |
2635 | 1391 |
if (GB(m5, 1, 2) == mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1392 |
/* Transport over the bridge is compatible */ |
2639 | 1393 |
result = m5 & 1 ? 0x202 : 0x101; |
0 | 1394 |
} |
1395 |
if (m5 & 0x40) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1396 |
/* Bridge middle part */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1397 |
if (!(m5 & 0x20)) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1398 |
/* Clear ground or water underneath */ |
2639 | 1399 |
if ((m5 & 0x18) != 8) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1400 |
/* Clear ground */ |
0 | 1401 |
return result; |
2639 | 1402 |
} else { |
1403 |
if (mode != TRANSPORT_WATER) return result; |
|
1404 |
} |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1405 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1406 |
/* Transport underneath */ |
2639 | 1407 |
if (GB(m5, 3, 2) != mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1408 |
/* Incompatible transport underneath */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1409 |
return result; |
2639 | 1410 |
} |
0 | 1411 |
} |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1412 |
/* If we've not returned yet, there is a compatible |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1413 |
* transport or water beneath, so we can add it to |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1414 |
* result */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1415 |
/* Why is this xor'd ? Can't it just be or'd? */ |
2639 | 1416 |
result ^= m5 & 1 ? 0x101 : 0x202; |
0 | 1417 |
} |
1418 |
return result; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1419 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1420 |
assert(0); /* This should never occur */ |
0 | 1421 |
} |
1422 |
return 0; |
|
1423 |
} |
|
1424 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2422
diff
changeset
|
1425 |
static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 1426 |
{ |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1427 |
if (!IsTileOwner(tile, old_player)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1428 |
|
2502 | 1429 |
if (new_player != OWNER_SPECTATOR) { |
1902 | 1430 |
SetTileOwner(tile, new_player); |
0 | 1431 |
} else { |
2639 | 1432 |
if ((_m[tile].m5 & 0xC0) == 0xC0) { |
0 | 1433 |
// the stuff BELOW the middle part is owned by the deleted player. |
2049
ad0d49c916d4
(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
|
1434 |
if (!(_m[tile].m5 & (1 << 4 | 1 << 3))) { |
0 | 1435 |
// convert railway into grass. |
2049
ad0d49c916d4
(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
|
1436 |
_m[tile].m5 &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore.. |
0 | 1437 |
} else { |
1438 |
// for road, change the owner of the road to local authority |
|
1902 | 1439 |
SetTileOwner(tile, OWNER_NONE); |
0 | 1440 |
} |
1441 |
} else { |
|
1442 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1443 |
} |
|
1444 |
} |
|
1445 |
} |
|
1446 |
||
1447 |
||
1448 |
static const byte _tunnel_fractcoord_1[4] = {0x8E,0x18,0x81,0xE8}; |
|
1449 |
static const byte _tunnel_fractcoord_2[4] = {0x81,0x98,0x87,0x38}; |
|
1450 |
static const byte _tunnel_fractcoord_3[4] = {0x82,0x88,0x86,0x48}; |
|
1451 |
static const byte _exit_tunnel_track[4] = {1,2,1,2}; |
|
1452 |
||
1453 |
static const byte _road_exit_tunnel_state[4] = {8, 9, 0, 1}; |
|
1454 |
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4}; |
|
1455 |
||
1456 |
static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29}; |
|
1457 |
static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25}; |
|
1458 |
static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45}; |
|
1459 |
static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49}; |
|
1460 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1461 |
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1462 |
{ |
1463 |
int z; |
|
1464 |
int dir, vdir; |
|
1465 |
byte fc; |
|
1466 |
||
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1467 |
if (GB(_m[tile].m5, 4, 4) == 0) { |
0 | 1468 |
z = GetSlopeZ(x, y) - v->z_pos; |
1469 |
if (myabs(z) > 2) |
|
1470 |
return 8; |
|
1471 |
||
1472 |
if (v->type == VEH_Train) { |
|
1473 |
fc = (x&0xF)+(y<<4); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1474 |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1475 |
dir = GB(_m[tile].m5, 0, 2); |
0 | 1476 |
vdir = v->direction >> 1; |
1477 |
||
1478 |
if (v->u.rail.track != 0x40 && dir == vdir) { |
|
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2663
diff
changeset
|
1479 |
if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) { |
0 | 1480 |
if (v->spritenum < 4) |
541 | 1481 |
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); |
0 | 1482 |
return 0; |
1483 |
} |
|
1484 |
if (fc == _tunnel_fractcoord_2[dir]) { |
|
1485 |
v->tile = tile; |
|
1486 |
v->u.rail.track = 0x40; |
|
1487 |
v->vehstatus |= VS_HIDDEN; |
|
1488 |
return 4; |
|
1489 |
} |
|
1490 |
} |
|
1491 |
||
1492 |
if (dir == (vdir^2) && fc == _tunnel_fractcoord_3[dir] && z == 0) { |
|
22 | 1493 |
/* We're at the tunnel exit ?? */ |
0 | 1494 |
v->tile = tile; |
1495 |
v->u.rail.track = _exit_tunnel_track[dir]; |
|
1330
8a67d04016ce
(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
|
1496 |
assert(v->u.rail.track); |
0 | 1497 |
v->vehstatus &= ~VS_HIDDEN; |
1498 |
return 4; |
|
1499 |
} |
|
1500 |
} else if (v->type == VEH_Road) { |
|
1501 |
fc = (x&0xF)+(y<<4); |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1502 |
dir = GB(_m[tile].m5, 0, 2); |
0 | 1503 |
vdir = v->direction >> 1; |
1504 |
||
1505 |
// Enter tunnel? |
|
1506 |
if (v->u.road.state != 0xFF && dir == vdir) { |
|
1507 |
if (fc == _tunnel_fractcoord_4[dir] || |
|
1508 |
fc == _tunnel_fractcoord_5[dir]) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1509 |
|
0 | 1510 |
v->tile = tile; |
1511 |
v->u.road.state = 0xFF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1512 |
v->vehstatus |= VS_HIDDEN; |
0 | 1513 |
return 4; |
1514 |
} else { |
|
1515 |
return 0; |
|
1516 |
} |
|
1517 |
} |
|
1518 |
||
1519 |
if (dir == (vdir^2) && ( |
|
22 | 1520 |
/* We're at the tunnel exit ?? */ |
0 | 1521 |
fc == _tunnel_fractcoord_6[dir] || |
1522 |
fc == _tunnel_fractcoord_7[dir]) && |
|
1523 |
z == 0) { |
|
1524 |
v->tile = tile; |
|
1525 |
v->u.road.state = _road_exit_tunnel_state[dir]; |
|
1526 |
v->u.road.frame = _road_exit_tunnel_frame[dir]; |
|
1527 |
v->vehstatus &= ~VS_HIDDEN; |
|
1528 |
return 4; |
|
1529 |
} |
|
1530 |
} |
|
2049
ad0d49c916d4
(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
|
1531 |
} else if (_m[tile].m5 & 0x80) { |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2663
diff
changeset
|
1532 |
if (v->type == VEH_Road || (v->type == VEH_Train && IsFrontEngine(v))) { |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1533 |
uint h; |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1534 |
|
334
8fb78c8c10e5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1535 |
if (GetTileSlope(tile, &h) != 0) |
8fb78c8c10e5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1536 |
h += 8; // Compensate for possible foundation |
2049
ad0d49c916d4
(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
|
1537 |
if (!(_m[tile].m5 & 0x40) || // start/end tile of bridge |
334
8fb78c8c10e5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1538 |
myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge |
0 | 1539 |
/* modify speed of vehicle */ |
2262
bd59b2d8d75f
(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
|
1540 |
uint16 spd = _bridge[GetBridgeType(tile)].speed; |
2639 | 1541 |
if (v->type == VEH_Road) spd *= 2; |
1542 |
if (spd < v->cur_speed) v->cur_speed = spd; |
|
0 | 1543 |
} |
1544 |
} |
|
1545 |
} |
|
1546 |
return 0; |
|
1547 |
} |
|
1548 |
||
1587
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1549 |
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v) |
0 | 1550 |
{ |
1587
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1551 |
TileIndex tile; |
1981 | 1552 |
TileIndexDiff delta = (v->direction & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
1587
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1553 |
byte z = v->z_pos; |
0 | 1554 |
|
1587
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1555 |
for (tile = v->tile;; tile += delta) { |
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2478
diff
changeset
|
1556 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0 && |
1587
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1557 |
GetTileZ(tile) == z) |
0 | 1558 |
break; |
1559 |
} |
|
1560 |
return tile; |
|
1561 |
} |
|
1562 |
||
1563 |
const TileTypeProcs _tile_type_tunnelbridge_procs = { |
|
1564 |
DrawTile_TunnelBridge, /* draw_tile_proc */ |
|
1565 |
GetSlopeZ_TunnelBridge, /* get_slope_z_proc */ |
|
1566 |
ClearTile_TunnelBridge, /* clear_tile_proc */ |
|
1567 |
GetAcceptedCargo_TunnelBridge, /* get_accepted_cargo_proc */ |
|
1568 |
GetTileDesc_TunnelBridge, /* get_tile_desc_proc */ |
|
1569 |
GetTileTrackStatus_TunnelBridge,/* get_tile_track_status_proc */ |
|
1570 |
ClickTile_TunnelBridge, /* click_tile_proc */ |
|
1571 |
AnimateTile_TunnelBridge, /* animate_tile_proc */ |
|
1572 |
TileLoop_TunnelBridge, /* tile_loop_clear */ |
|
1573 |
ChangeTileOwner_TunnelBridge, /* change_tile_owner_clear */ |
|
1574 |
NULL, /* get_produced_cargo_proc */ |
|
1575 |
VehicleEnter_TunnelBridge, /* vehicle_enter_tile_proc */ |
|
1576 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1577 |
GetSlopeTileh_TunnelBridge, /* get_slope_tileh_proc */ |
0 | 1578 |
}; |