annotate rail_cmd.c @ 3486:d2940b03b6ba draft

(svn r4337) -Fix: A problem where GetRailType was called instead of GetRailTileType. Thanks to glx for noticing
author celestar <celestar@openttd.org>
date Sun, 09 Apr 2006 17:50:00 +0000
parents 67144af97951
children 6aef91e18846
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2186
042e6d005cb0 (svn r2701) Insert Id tags into all source files
tron <tron@openttd.org>
parents: 2163
diff changeset
1 /* $Id$ */
042e6d005cb0 (svn r2701) Insert Id tags into all source files
tron <tron@openttd.org>
parents: 2163
diff changeset
2
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
3 #include "stdafx.h"
1891
81b2cb2fc036 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater <Darkvater@openttd.org>
parents: 1818
diff changeset
4 #include "openttd.h"
3189
a2a7c1925a02 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron <tron@openttd.org>
parents: 3185
diff changeset
5 #include "bridge_map.h"
1922
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
6 #include "debug.h"
2163
acad95b3c4a2 (svn r2673) Include functions.h directly, not globally via openttd.h
tron <tron@openttd.org>
parents: 2148
diff changeset
7 #include "functions.h"
3101
fb7adbb60fda (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron <tron@openttd.org>
parents: 3099
diff changeset
8 #include "rail_map.h"
3144
7020c2e78c6f (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron <tron@openttd.org>
parents: 3142
diff changeset
9 #include "road_map.h"
1363
b454e702374d (svn r1867) Include tables/sprites.h only in files which need it
tron <tron@openttd.org>
parents: 1330
diff changeset
10 #include "table/sprites.h"
507
9dcc34b8887e (svn r815) Include strings.h only in the files which need it.
tron <tron@openttd.org>
parents: 497
diff changeset
11 #include "table/strings.h"
679
21e658645b32 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron <tron@openttd.org>
parents: 555
diff changeset
12 #include "map.h"
1209
58e3ba05003c (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 <tron@openttd.org>
parents: 1123
diff changeset
13 #include "tile.h"
3319
b94c4a903699 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron <tron@openttd.org>
parents: 3286
diff changeset
14 #include "town_map.h"
3154
c655b0fa9fa6 (svn r3777) Add some functions to handle tunnels
tron <tron@openttd.org>
parents: 3153
diff changeset
15 #include "tunnel_map.h"
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
16 #include "vehicle.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
17 #include "viewport.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
18 #include "command.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
19 #include "pathfind.h"
1922
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
20 #include "engine.h"
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
21 #include "town.h"
337
c88b35750799 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron <tron@openttd.org>
parents: 283
diff changeset
22 #include "sound.h"
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
23 #include "station.h"
405
709649248c03 (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater <darkvater@openttd.org>
parents: 403
diff changeset
24 #include "sprite.h"
1313
cc5956ea3da8 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight <truelight@openttd.org>
parents: 1247
diff changeset
25 #include "depot.h"
1542
c7c10abeede3 (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight <truelight@openttd.org>
parents: 1536
diff changeset
26 #include "waypoint.h"
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
27 #include "rail.h"
2236
8feebb438ade (svn r2756) Renamed railtypes into _railtypes
ludde <ludde@openttd.org>
parents: 2233
diff changeset
28 #include "railtypes.h" // include table for railtypes
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
29
415
88e0ffa216fe (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik <dominik@openttd.org>
parents: 413
diff changeset
30 extern uint16 _custom_sprites_base;
88e0ffa216fe (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik <dominik@openttd.org>
parents: 413
diff changeset
31
2261
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
32 const byte _track_sloped_sprites[14] = {
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
33 14, 15, 22, 13,
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
34 0, 21, 17, 12,
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
35 23, 0, 18, 20,
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
36 19, 16
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
37 };
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
38
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
39 void ShowTrainDepotWindow(TileIndex tile);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
40
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
41 /* 4
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
42 * ---------
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
43 * |\ /|
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
44 * | \ 1/ |
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
45 * | \ / |
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
46 * | \ / |
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
47 * 16| \ |32
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
48 * | / \2 |
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
49 * | / \ |
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
50 * | / \ |
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
51 * |/ \|
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
52 * ---------
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
53 * 8
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
54 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
55
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
56
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
57 // Constants for lower part of Map2 byte.
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
58 enum RailMap2Lower4 {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
59 RAIL_MAP2LO_GROUND_MASK = 0xF,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
60 RAIL_GROUND_BROWN = 0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
61 RAIL_GROUND_GREEN = 1,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
62 RAIL_GROUND_FENCE_NW = 2,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
63 RAIL_GROUND_FENCE_SE = 3,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
64 RAIL_GROUND_FENCE_SENW = 4,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
65 RAIL_GROUND_FENCE_NE = 5,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
66 RAIL_GROUND_FENCE_SW = 6,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
67 RAIL_GROUND_FENCE_NESW = 7,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
68 RAIL_GROUND_FENCE_VERT1 = 8,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
69 RAIL_GROUND_FENCE_VERT2 = 9,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
70 RAIL_GROUND_FENCE_HORIZ1 = 10,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
71 RAIL_GROUND_FENCE_HORIZ2 = 11,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
72 RAIL_GROUND_ICE_DESERT = 12,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
73 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
74
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
75
22
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
76 /* MAP2 byte: abcd???? => Signal On? Same coding as map3lo
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
77 * MAP3LO byte: abcd???? => Signal Exists?
22
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
78 * a and b are for diagonals, upper and left,
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
79 * one for each direction. (ie a == NE->SW, b ==
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
80 * SW->NE, or v.v., I don't know. b and c are
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
81 * similar for lower and right.
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
82 * MAP2 byte: ????abcd => Type of ground.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
83 * MAP3LO byte: ????abcd => Type of rail.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
84 * MAP5: 00abcdef => rail
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
85 * 01abcdef => rail w/ signals
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
86 * 10uuuuuu => unused
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
87 * 11uuuudd => rail depot
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
88 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
89
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
90 static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
91 {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
92 RailTileType type = GetRailTileType(tile);
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
93 TrackBits current; /* The current track layout */
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
94 TrackBits future; /* The track layout we want to build */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
95 _error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
96
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
97 if (type != RAIL_TYPE_NORMAL && type != RAIL_TYPE_SIGNALS)
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
98 return false; /* Cannot build anything on depots and checkpoints */
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
99
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
100 /* So, we have a tile with tracks on it (and possibly signals). Let's see
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
101 * what tracks first */
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
102 current = GetTrackBits(tile);
1946
235eb7ff07b0 (svn r2452) Fix defect in r2448 which caused building tracks unexpectedly fail or succeed
tron <tron@openttd.org>
parents: 1942
diff changeset
103 future = current | to_build;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
104
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
105 /* Are we really building something new? */
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
106 if (current == future) {
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
107 /* Nothing new is being built */
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
108 _error_message = STR_1007_ALREADY_BUILT;
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
109 return false;
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
110 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
111
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
112 /* Let's see if we may build this */
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
113 if ((flags & DC_NO_RAIL_OVERLAP) || type == RAIL_TYPE_SIGNALS) {
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
114 /* If we are not allowed to overlap (flag is on for ai players or we have
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
115 * signals on the tile), check that */
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
116 return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT;
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
117 } else {
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
118 /* Normally, we may overlap and any combination is valid */
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
119 return true;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
120 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
121 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
122
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
123
3279
bcbd6efdcc89 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar <celestar@openttd.org>
parents: 3276
diff changeset
124 const TrackBits _valid_tileh_slopes[2][15] = {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
125
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
126 // set of normal ones
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
127 {
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
128 TRACK_BIT_ALL,
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
129 TRACK_BIT_RIGHT,
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
130 TRACK_BIT_UPPER,
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
131 TRACK_BIT_X,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
132
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
133 TRACK_BIT_LEFT,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
134 0,
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
135 TRACK_BIT_Y,
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
136 TRACK_BIT_LOWER,
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
137
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
138 TRACK_BIT_LOWER,
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
139 TRACK_BIT_Y,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
140 0,
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
141 TRACK_BIT_LEFT,
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
142
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
143 TRACK_BIT_X,
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
144 TRACK_BIT_UPPER,
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
145 TRACK_BIT_RIGHT,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
146 },
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
147
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
148 // allowed rail for an evenly raised platform
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
149 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
150 0,
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
151 TRACK_BIT_LEFT,
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
152 TRACK_BIT_LOWER,
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
153 TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_LEFT,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
154
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
155 TRACK_BIT_RIGHT,
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
156 TRACK_BIT_ALL,
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
157 TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
158 TRACK_BIT_ALL,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
159
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
160 TRACK_BIT_UPPER,
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
161 TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_LEFT,
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
162 TRACK_BIT_ALL,
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
163 TRACK_BIT_ALL,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
164
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
165 TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
166 TRACK_BIT_ALL,
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
167 TRACK_BIT_ALL
3276
1b23f0985ef1 (svn r3988) Remove the info about valid rails on shore tiles. It's the same as for any other sloped tile
tron <tron@openttd.org>
parents: 3274
diff changeset
168 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
169 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
170
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
171 uint GetRailFoundation(uint tileh, TrackBits bits)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
172 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
173 int i;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
174
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
175 if ((~_valid_tileh_slopes[0][tileh] & bits) == 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
176 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
177
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
178 if ((~_valid_tileh_slopes[1][tileh] & bits) == 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
179 return tileh;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
180
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
181 if ((
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
182 (i = 0, tileh == 1) ||
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
183 (i += 2, tileh == 2) ||
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
184 (i += 2, tileh == 4) ||
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
185 (i += 2, tileh == 8)
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
186 ) && (
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
187 bits == TRACK_BIT_X ||
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
188 (i++, bits == TRACK_BIT_Y)
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
189 )) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
190 return i + 15;
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
191 } else {
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
192 return 0;
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
193 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
194 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
195
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
196
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
197 static uint32 CheckRailSlope(uint tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
198 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
199 // never allow building on top of steep tiles
2085
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
200 if (!IsSteepTileh(tileh)) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
201 rail_bits |= existing;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
202
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
203 // don't allow building on the lower side of a coast
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
204 if (IsTileType(tile, MP_WATER) &&
3276
1b23f0985ef1 (svn r3988) Remove the info about valid rails on shore tiles. It's the same as for any other sloped tile
tron <tron@openttd.org>
parents: 3274
diff changeset
205 ~_valid_tileh_slopes[1][tileh] & rail_bits) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
206 return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
207 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
208
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
209 // no special foundation
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
210 if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
211 return 0;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
212
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
213 if ((~_valid_tileh_slopes[1][tileh] & rail_bits) == 0 || ( // whole tile is leveled up
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
214 (rail_bits == TRACK_BIT_X || rail_bits == TRACK_BIT_Y) &&
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
215 (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8)
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
216 )) { // partly up
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
217 if (existing != 0) {
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
218 return 0;
2422
79876044778e (svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight <truelight@openttd.org>
parents: 2364
diff changeset
219 } else if (!_patches.build_on_slopes || _is_old_ai_player) {
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
220 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
221 } else {
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
222 return _price.terraform;
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
223 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
224 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
225 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
226 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
227 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
228
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
229 /* Validate functions for rail building */
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
230 static inline bool ValParamTrackOrientation(Track track) {return IsValidTrack(track);}
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
231
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
232 /** Build a single piece of rail
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
233 * @param x,y coordinates on where to build
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
234 * @param p1 railtype of being built piece (normal, mono, maglev)
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
235 * @param p2 rail track to build
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
236 */
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
237 int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
238 {
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
239 TileIndex tile;
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
240 uint tileh;
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
241 Track track = (Track)p2;
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
242 TrackBits trackbit;
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
243 int32 cost = 0;
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
244 int32 ret;
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
245
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
246 if (!ValParamRailtype(p1) || !ValParamTrackOrientation(track)) return CMD_ERROR;
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
247
1980
e7a647ab6cb1 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron <tron@openttd.org>
parents: 1977
diff changeset
248 tile = TileVirtXY(x, y);
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
249 tileh = GetTileSlope(tile, NULL);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
250 trackbit = TrackToTrackBits(track);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
251
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
252 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
253
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
254 switch (GetTileType(tile)) {
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
255 case MP_TUNNELBRIDGE:
3234
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
256 if (!IsBridge(tile) ||
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
257 !IsBridgeMiddle(tile) ||
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
258 (GetBridgeAxis(tile) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) != trackbit) {
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
259 // Get detailed error message
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
260 return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
261 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
262
3234
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
263 if (IsClearUnderBridge(tile)) {
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
264 ret = CheckRailSlope(tileh, trackbit, 0, tile);
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
265 if (CmdFailed(ret)) return ret;
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
266 cost += ret;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
267
3234
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
268 if (flags & DC_EXEC) SetRailUnderBridge(tile, _current_player, p1);
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
269 } else if (IsTransportUnderBridge(tile) &&
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
270 GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
271 return_cmd_error(STR_1007_ALREADY_BUILT);
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
272 } else {
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
273 // Get detailed error message
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
274 return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
275 }
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
276 break;
13
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
277
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
278 case MP_RAILWAY:
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
279 if (!CheckTrackCombination(tile, trackbit, flags) ||
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
280 !EnsureNoVehicle(tile)) {
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
281 return CMD_ERROR;
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
282 }
3253
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
283 if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT ||
1903
26e95cd38b15 (svn r2409) Missed one _map_owner -> IsTileOwner()
tron <tron@openttd.org>
parents: 1902
diff changeset
284 !IsTileOwner(tile, _current_player) ||
3242
2aed0a741a25 (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron <tron@openttd.org>
parents: 3238
diff changeset
285 GetRailType(tile) != p1) {
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
286 // Get detailed error message
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
287 return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
288 }
13
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
289
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
290 ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
1691
681b5e560269 (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron <tron@openttd.org>
parents: 1669
diff changeset
291 if (CmdFailed(ret)) return ret;
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
292 cost += ret;
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
293
1719
5b52d0e4d0cb (svn r2223) When adding tracks to a railway tile reset the ground to bare land, fix for a glitch in r2131
tron <tron@openttd.org>
parents: 1691
diff changeset
294 if (flags & DC_EXEC) {
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
295 _m[tile].m2 &= ~RAIL_MAP2LO_GROUND_MASK; // Bare land
3271
217d3924d48d (svn r3983) Use existing functions to access tree and road info
tron <tron@openttd.org>
parents: 3270
diff changeset
296 _m[tile].m5 |= trackbit;
1719
5b52d0e4d0cb (svn r2223) When adding tracks to a railway tile reset the ground to bare land, fix for a glitch in r2131
tron <tron@openttd.org>
parents: 1691
diff changeset
297 }
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
298 break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
299
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
300 case MP_STREET:
3142
8096637a944a (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron <tron@openttd.org>
parents: 3103
diff changeset
301 #define M(x) (1 << (x))
8096637a944a (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron <tron@openttd.org>
parents: 3103
diff changeset
302 /* Level crossings may only be built on these slopes */
8096637a944a (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron <tron@openttd.org>
parents: 3103
diff changeset
303 if (!HASBIT(M(14) | M(13) | M(11) | M(10) | M(7) | M(5) | M(0), tileh)) {
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
304 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
3142
8096637a944a (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron <tron@openttd.org>
parents: 3103
diff changeset
305 }
8096637a944a (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron <tron@openttd.org>
parents: 3103
diff changeset
306 #undef M
8096637a944a (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron <tron@openttd.org>
parents: 3103
diff changeset
307
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
308 if (!EnsureNoVehicle(tile)) return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
309
3069
a7c09d88896f (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron <tron@openttd.org>
parents: 3017
diff changeset
310 if (GetRoadType(tile) == ROAD_NORMAL && (
3271
217d3924d48d (svn r3983) Use existing functions to access tree and road info
tron <tron@openttd.org>
parents: 3270
diff changeset
311 (track == TRACK_X && GetRoadBits(tile) == ROAD_Y) ||
217d3924d48d (svn r3983) Use existing functions to access tree and road info
tron <tron@openttd.org>
parents: 3270
diff changeset
312 (track == TRACK_Y && GetRoadBits(tile) == ROAD_X)
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
313 )) {
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
314 if (flags & DC_EXEC) {
3319
b94c4a903699 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron <tron@openttd.org>
parents: 3286
diff changeset
315 MakeRoadCrossing(tile, GetTileOwner(tile), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), p1, GetTownIndex(tile));
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
316 }
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
317 break;
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
318 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
319
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
320 if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) {
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
321 return_cmd_error(STR_1007_ALREADY_BUILT);
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
322 }
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
323 /* FALLTHROUGH */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
324
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
325 default:
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
326 ret = CheckRailSlope(tileh, trackbit, 0, tile);
1691
681b5e560269 (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron <tron@openttd.org>
parents: 1669
diff changeset
327 if (CmdFailed(ret)) return ret;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
328 cost += ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
329
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
330 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1691
681b5e560269 (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron <tron@openttd.org>
parents: 1669
diff changeset
331 if (CmdFailed(ret)) return ret;
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
332 cost += ret;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
333
3101
fb7adbb60fda (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron <tron@openttd.org>
parents: 3099
diff changeset
334 if (flags & DC_EXEC) MakeRailNormal(tile, _current_player, trackbit, p1);
1627
8d5fc87ed011 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron <tron@openttd.org>
parents: 1609
diff changeset
335 break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
336 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
337
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
338 if (flags & DC_EXEC) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
339 MarkTileDirtyByTile(tile);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
340 SetSignalsOnBothDir(tile, track);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
341 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
342
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
343 return cost + _price.build_rail;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
344 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
345
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
346 /** Remove a single piece of track
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
347 * @param x,y coordinates for removal of track
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
348 * @param p1 unused
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
349 * @param p2 rail orientation
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
350 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
351 int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
352 {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
353 Track track = (Track)p2;
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
354 TrackBits trackbit;
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
355 TileIndex tile;
1963
951df2dcf752 (svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid <hackykid@openttd.org>
parents: 1954
diff changeset
356 int32 cost = _price.remove_rail;
3284
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
357 bool crossing = false;
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
358
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
359 if (!ValParamTrackOrientation(p2)) return CMD_ERROR;
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
360 trackbit = TrackToTrackBits(track);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
361
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
362 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
363
1980
e7a647ab6cb1 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron <tron@openttd.org>
parents: 1977
diff changeset
364 tile = TileVirtXY(x, y);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
365
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
366 switch (GetTileType(tile)) {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
367 case MP_TUNNELBRIDGE:
3234
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
368 if (!IsBridge(tile) ||
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
369 !IsBridgeMiddle(tile) ||
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
370 !IsTransportUnderBridge(tile) ||
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
371 GetTransportTypeUnderBridge(tile) != TRANSPORT_RAIL ||
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
372 GetRailBitsUnderBridge(tile) != trackbit ||
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
373 (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
3234
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
374 !EnsureNoVehicleZ(tile, TilePixelHeight(tile))) {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
375 return CMD_ERROR;
3234
e0489bce2ee3 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron <tron@openttd.org>
parents: 3220
diff changeset
376 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
377
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
378 if (flags & DC_EXEC) SetClearUnderBridge(tile);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
379 break;
2548
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
380
3071
d1a65c954e58 (svn r3660) Convert further road bits and type references to the functions/enums
tron <tron@openttd.org>
parents: 3069
diff changeset
381 case MP_STREET: {
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
382 if (!IsLevelCrossing(tile) ||
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
383 GetCrossingRailBits(tile) != trackbit ||
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
384 (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
385 !EnsureNoVehicle(tile)) {
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
386 return CMD_ERROR;
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
387 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
388
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
389 if (flags & DC_EXEC) {
3319
b94c4a903699 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron <tron@openttd.org>
parents: 3286
diff changeset
390 MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), GetTownIndex(tile));
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
391 }
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
392 break;
3071
d1a65c954e58 (svn r3660) Convert further road bits and type references to the functions/enums
tron <tron@openttd.org>
parents: 3069
diff changeset
393 }
2548
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
394
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
395 case MP_RAILWAY: {
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
396 TrackBits present;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
397
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
398 if (!IsPlainRailTile(tile) ||
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
399 (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
400 !EnsureNoVehicle(tile)) {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
401 return CMD_ERROR;
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
402 }
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
403
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
404 present = GetTrackBits(tile);
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
405 if ((present & trackbit) == 0) return CMD_ERROR;
3284
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
406 if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
407
1963
951df2dcf752 (svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid <hackykid@openttd.org>
parents: 1954
diff changeset
408 /* Charge extra to remove signals on the track, if they are there */
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
409 if (HasSignalOnTrack(tile, track))
1963
951df2dcf752 (svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid <hackykid@openttd.org>
parents: 1954
diff changeset
410 cost += DoCommand(x, y, track, 0, flags, CMD_REMOVE_SIGNALS);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
411
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
412 if (flags & DC_EXEC) {
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
413 present ^= trackbit;
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
414 if (present == 0) {
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
415 DoClearSquare(tile);
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
416 } else {
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
417 SetTrackBits(tile, present);
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
418 }
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
419 }
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
420 break;
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
421 }
2548
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
422
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
423 default: return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
424 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
425
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
426 if (flags & DC_EXEC) {
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
427 MarkTileDirtyByTile(tile);
3284
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
428 if (crossing) {
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
429 /* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
430 * are removing one of these pieces, we'll need to update signals for
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
431 * both directions explicitly, as after the track is removed it won't
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
432 * 'connect' with the other piece. */
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
433 SetSignalsOnBothDir(tile, TRACK_X);
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
434 SetSignalsOnBothDir(tile, TRACK_Y);
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
435 } else {
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
436 SetSignalsOnBothDir(tile, track);
25e7c5bdcbba (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138 <peter1138@openttd.org>
parents: 3279
diff changeset
437 }
3273
992d04811671 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron <tron@openttd.org>
parents: 3271
diff changeset
438 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
439
1963
951df2dcf752 (svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid <hackykid@openttd.org>
parents: 1954
diff changeset
440 return cost;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
441 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
442
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
443 static const struct {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
444 int8 xinc[16];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
445 int8 yinc[16];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
446 } _railbit = {{
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
447 // 0 1 2 3 4 5
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
448 -16, 0,-16, 0, 16, 0, 0, 0,
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
449 16, 0, 0, 16, 0,-16, 0, 0,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
450 },{
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
451 0, 16, 0, 16, 0, 16, 0, 0,
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
452 0,-16,-16, 0,-16, 0, 0, 0,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
453 }};
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
454
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
455 static int32 ValidateAutoDrag(Trackdir *trackdir, int x, int y, int ex, int ey)
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
456 {
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
457 int dx, dy, trdx, trdy;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
458
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
459 if (!ValParamTrackOrientation(*trackdir)) return CMD_ERROR;
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
460
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
461 // calculate delta x,y from start to end tile
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
462 dx = ex - x;
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
463 dy = ey - y;
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
464
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
465 // calculate delta x,y for the first direction
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
466 trdx = _railbit.xinc[*trackdir];
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
467 trdy = _railbit.yinc[*trackdir];
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
468
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
469 if (!IsDiagonalTrackdir(*trackdir)) {
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
470 trdx += _railbit.xinc[*trackdir ^ 1];
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
471 trdy += _railbit.yinc[*trackdir ^ 1];
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
472 }
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
473
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
474 // validate the direction
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
475 while (
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
476 (trdx <= 0 && dx > 0) ||
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
477 (trdx >= 0 && dx < 0) ||
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
478 (trdy <= 0 && dy > 0) ||
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
479 (trdy >= 0 && dy < 0)
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
480 ) {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
481 if (!HASBIT(*trackdir, 3)) { // first direction is invalid, try the other
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
482 SETBIT(*trackdir, 3); // reverse the direction
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
483 trdx = -trdx;
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
484 trdy = -trdy;
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
485 } else // other direction is invalid too, invalid drag
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
486 return CMD_ERROR;
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
487 }
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
488
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
489 // (for diagonal tracks, this is already made sure of by above test), but:
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
490 // for non-diagonal tracks, check if the start and end tile are on 1 line
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
491 if (!IsDiagonalTrackdir(*trackdir)) {
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
492 trdx = _railbit.xinc[*trackdir];
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
493 trdy = _railbit.yinc[*trackdir];
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
494 if (abs(dx) != abs(dy) && abs(dx) + abs(trdy) != abs(dy) + abs(trdx))
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
495 return CMD_ERROR;
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
496 }
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
497
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
498 return 0;
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
499 }
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
500
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
501 /** Build a stretch of railroad tracks.
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
502 * @param x,y start tile of drag
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
503 * @param p1 end tile of drag
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
504 * @param p2 various bitstuffed elements
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
505 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
506 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
507 * - p2 = (bit 7) - 0 = build, 1 = remove tracks
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
508 */
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
509 static int32 CmdRailTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32 p2)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
510 {
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
511 int ex, ey;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
512 int32 ret, total_cost = 0;
2140
33f2b4754779 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron <tron@openttd.org>
parents: 2111
diff changeset
513 Track track = (Track)GB(p2, 4, 3);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
514 Trackdir trackdir;
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
515 byte mode = HASBIT(p2, 7);
2604
bc9279c4ac9e (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138 <peter1138@openttd.org>
parents: 2549
diff changeset
516 RailType railtype = (RailType)GB(p2, 0, 4);
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
517
2604
bc9279c4ac9e (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138 <peter1138@openttd.org>
parents: 2549
diff changeset
518 if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
2934
137d6aa34f0e (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron <tron@openttd.org>
parents: 2916
diff changeset
519 if (p1 >= MapSize()) return CMD_ERROR;
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
520 trackdir = TrackToTrackdir(track);
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
521
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
522 /* unpack end point */
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
523 ex = TileX(p1) * TILE_SIZE;
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
524 ey = TileY(p1) * TILE_SIZE;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
525
889
8a7301b5aa5b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater <darkvater@openttd.org>
parents: 826
diff changeset
526 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
8a7301b5aa5b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater <darkvater@openttd.org>
parents: 826
diff changeset
527
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
528 if (CmdFailed(ValidateAutoDrag(&trackdir, x, y, ex, ey))) return CMD_ERROR;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
529
1980
e7a647ab6cb1 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron <tron@openttd.org>
parents: 1977
diff changeset
530 if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, TileVirtXY(x, y));
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
531
2952
1d16b8a5c9a1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron <tron@openttd.org>
parents: 2951
diff changeset
532 for (;;) {
2604
bc9279c4ac9e (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138 <peter1138@openttd.org>
parents: 2549
diff changeset
533 ret = DoCommand(x, y, railtype, TrackdirToTrack(trackdir), flags, (mode == 0) ? CMD_BUILD_SINGLE_RAIL : CMD_REMOVE_SINGLE_RAIL);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
534
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
535 if (CmdFailed(ret)) {
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
536 if ((_error_message != STR_1007_ALREADY_BUILT) && (mode == 0))
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
537 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
538 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
539 total_cost += ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
540
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
541 if (x == ex && y == ey)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
542 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
543
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
544 x += _railbit.xinc[trackdir];
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
545 y += _railbit.yinc[trackdir];
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
546
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
547 // toggle railbit for the non-diagonal tracks
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
548 if (!IsDiagonalTrackdir(trackdir)) trackdir ^= 1;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
549 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
550
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
551 return (total_cost == 0) ? CMD_ERROR : total_cost;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
552 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
553
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
554 /** Build rail on a stretch of track.
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
555 * Stub for the unified rail builder/remover
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
556 * @see CmdRailTrackHelper
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
557 */
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
558 int32 CmdBuildRailroadTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
559 {
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
560 return CmdRailTrackHelper(x, y, flags, p1, CLRBIT(p2, 7));
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
561 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
562
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
563 /** Build rail on a stretch of track.
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
564 * Stub for the unified rail builder/remover
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
565 * @see CmdRailTrackHelper
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
566 */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
567 int32 CmdRemoveRailroadTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
568 {
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
569 return CmdRailTrackHelper(x, y, flags, p1, SETBIT(p2, 7));
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
570 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
571
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
572 /** Build a train depot
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
573 * @param x,y position of the train depot
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
574 * @param p1 rail type
3333
9a85f8785fff (svn r4111) Fix/Remove some stale comments
tron <tron@openttd.org>
parents: 3319
diff changeset
575 * @param p2 entrance direction (DiagDirection)
2085
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
576 *
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
577 * @todo When checking for the tile slope,
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
578 * distingush between "Flat land required" and "land sloped in wrong direction"
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
579 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
580 int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
581 {
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
582 Depot *d;
1980
e7a647ab6cb1 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron <tron@openttd.org>
parents: 1977
diff changeset
583 TileIndex tile = TileVirtXY(x, y);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
584 int32 cost, ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
585 uint tileh;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
586
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
587 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
588
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
589 if (!EnsureNoVehicle(tile)) return CMD_ERROR;
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
590 /* check railtype and valid direction for depot (0 through 3), 4 in total */
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
591 if (!ValParamRailtype(p1) || p2 > 3) return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
592
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
593 tileh = GetTileSlope(tile, NULL);
2085
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
594
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
595 /* Prohibit construction if
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
596 The tile is non-flat AND
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
597 1) The AI is "old-school"
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
598 2) build-on-slopes is disabled
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
599 3) the tile is steep i.e. spans two height levels
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
600 4) the exit points in the wrong direction
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
601
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
602 */
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
603
2030f1108564 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar <celestar@openttd.org>
parents: 2049
diff changeset
604 if (tileh != 0 && (
2548
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
605 _is_old_ai_player ||
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
606 !_patches.build_on_slopes ||
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
607 IsSteepTileh(tileh) ||
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
608 !CanBuildDepotByTileh(p2, tileh)
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
609 )) {
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
610 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
611 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
612
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
613 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
614 if (CmdFailed(ret)) return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
615 cost = ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
616
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
617 d = AllocateDepot();
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
618 if (d == NULL) return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
619
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
620 if (flags & DC_EXEC) {
2425
b79a84f8df2c (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater <Darkvater@openttd.org>
parents: 2422
diff changeset
621 if (IsLocalPlayer()) _last_built_train_depot_tile = tile;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
622
3101
fb7adbb60fda (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron <tron@openttd.org>
parents: 3099
diff changeset
623 MakeRailDepot(tile, _current_player, p2, p1);
fb7adbb60fda (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron <tron@openttd.org>
parents: 3099
diff changeset
624 MarkTileDirtyByTile(tile);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
625
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
626 d->xy = tile;
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
627 d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
628
3191
ce099c2f5321 (svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron <tron@openttd.org>
parents: 3189
diff changeset
629 UpdateSignalsOnSegment(tile, p2);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
630 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
631
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
632 return cost + _price.build_train_depot;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
633 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
634
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
635 /** Build signals, alternate between double/single, signal/semaphore,
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
636 * pre/exit/combo-signals, and what-else not
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
637 * @param x,y coordinates where signals is being built
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
638 * @param p1 various bitstuffed elements
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
639 * - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum)
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
640 * - p1 = (bit 3) - choose semaphores/signals or cycle normal/pre/exit/combo depending on context
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
641 * @param p2 used for CmdBuildManySignals() to copy direction of first signal
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
642 * TODO: p2 should be replaced by two bits for "along" and "against" the track.
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
643 */
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
644 int32 CmdBuildSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
645 {
1980
e7a647ab6cb1 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron <tron@openttd.org>
parents: 1977
diff changeset
646 TileIndex tile = TileVirtXY(x, y);
3237
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
647 SignalVariant sigvar;
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
648 bool pre_signal;
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
649 Track track = (Track)(p1 & 0x7);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
650 int32 cost;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
651
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
652 // Same bit, used in different contexts
3237
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
653 sigvar = HASBIT(p1, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC;
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
654 pre_signal = HASBIT(p1, 3);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
655
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
656 if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile))
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
657 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
658
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
659 /* Protect against invalid signal copying */
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
660 if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
661
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
662 /* You can only build signals on plain rail tiles, and the selected track must exist */
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
663 if (!IsPlainRailTile(tile) || !HasTrack(tile, track)) return CMD_ERROR;
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
664
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
665 if (!CheckTileOwnership(tile)) return CMD_ERROR;
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
666
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
667 _error_message = STR_1005_NO_SUITABLE_RAILROAD_TRACK;
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
668
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
669 {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
670 /* See if this is a valid track combination for signals, (ie, no overlap) */
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
671 TrackBits trackbits = GetTrackBits(tile);
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
672 if (KILL_FIRST_BIT(trackbits) != 0 && /* More than one track present */
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
673 trackbits != TRACK_BIT_HORZ &&
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
674 trackbits != TRACK_BIT_VERT
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
675 )
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
676 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
677 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
678
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
679 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
680
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
681 if (!HasSignalOnTrack(tile, track)) {
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
682 // build new signals
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
683 cost = _price.build_signals;
1066
bda4fedf3a03 (svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater <darkvater@openttd.org>
parents: 1059
diff changeset
684 } else {
3237
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
685 if (p2 != 0 && sigvar != GetSignalVariant(tile)) {
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
686 // convert signals <-> semaphores
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
687 cost = _price.build_signals + _price.remove_signals;
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
688 } else {
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
689 // it is free to change orientation/pre-exit-combo signals
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
690 cost = 0;
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
691 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
692 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
693
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
694 if (flags & DC_EXEC) {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
695 if (GetRailTileType(tile) != RAIL_TYPE_SIGNALS) {
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
696 // there are no signals at all on this tile yet
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
697 _m[tile].m5 |= RAIL_TYPE_SIGNALS; // change into signals
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
698 _m[tile].m2 |= 0xF0; // all signals are on
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
699 _m[tile].m3 &= ~0xF0; // no signals built by default
3237
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
700 _m[tile].m4 = 0;
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
701 SetSignalVariant(tile, sigvar);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
702 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
703
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
704 if (p2 == 0) {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
705 if (!HasSignalOnTrack(tile, track)) {
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
706 // build new signals
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
707 _m[tile].m3 |= SignalOnTrack(track);
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
708 } else {
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
709 if (pre_signal) {
2916
9f16688176a1 (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater <Darkvater@openttd.org>
parents: 2911
diff changeset
710 // cycle between normal -> pre -> exit -> combo -> ...
3238
9b75d6e4b9d4 (svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron <tron@openttd.org>
parents: 3237
diff changeset
711 SignalType type = GetSignalType(tile);
9b75d6e4b9d4 (svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron <tron@openttd.org>
parents: 3237
diff changeset
712
9b75d6e4b9d4 (svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron <tron@openttd.org>
parents: 3237
diff changeset
713 SetSignalType(tile, type == SIGTYPE_COMBO ? SIGTYPE_NORMAL : type + 1);
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
714 } else {
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
715 // cycle between two-way -> one-way -> one-way -> ...
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
716 /* TODO: Rewrite switch into something more general */
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
717 switch (track) {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
718 case TRACK_LOWER:
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
719 case TRACK_RIGHT: {
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
720 byte signal = (_m[tile].m3 - 0x10) & 0x30;
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
721 if (signal == 0) signal = 0x30;
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
722 _m[tile].m3 &= ~0x30;
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
723 _m[tile].m3 |= signal;
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
724 break;
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
725 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
726
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
727 default: {
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
728 byte signal = (_m[tile].m3 - 0x40) & 0xC0;
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
729 if (signal == 0) signal = 0xC0;
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
730 _m[tile].m3 &= ~0xC0;
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
731 _m[tile].m3 |= signal;
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
732 break;
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
733 }
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
734 }
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
735 }
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
736 }
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
737 } else {
1084
6227108bcab4 (svn r1585) Rewrite CmdBuildSignals()
tron <tron@openttd.org>
parents: 1066
diff changeset
738 /* If CmdBuildManySignals is called with copying signals, just copy the
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
739 * direction of the first signal given as parameter by CmdBuildManySignals */
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
740 _m[tile].m3 &= ~SignalOnTrack(track);
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
741 _m[tile].m3 |= p2 & SignalOnTrack(track);
3237
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
742 SetSignalVariant(tile, sigvar);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
743 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
744
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
745 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
746 SetSignalsOnBothDir(tile, track);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
747 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
748
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
749 return cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
750 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
751
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
752 /** Build many signals by dragging; AutoSignals
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
753 * @param x,y start tile of drag
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
754 * @param p1 end tile of drag
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
755 * @param p2 various bitstuffed elements
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
756 * - p2 = (bit 0) - 0 = build, 1 = remove signals
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
757 * - p2 = (bit 3) - 0 = signals, 1 = semaphores
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
758 * - p2 = (bit 4- 6) - track-orientation, valid values: 0-5 (Track enum)
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
759 * - p2 = (bit 24-31) - user defined signals_density
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
760 */
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
761 static int32 CmdSignalTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32 p2)
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
762 {
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
763 int ex, ey;
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
764 int32 ret, total_cost, signal_ctr;
1954
33916fc46768 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid <hackykid@openttd.org>
parents: 1946
diff changeset
765 byte signals;
1980
e7a647ab6cb1 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron <tron@openttd.org>
parents: 1977
diff changeset
766 TileIndex tile = TileVirtXY(x, y);
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
767 bool error = true;
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
768
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
769 int mode = p2 & 0x1;
2140
33f2b4754779 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron <tron@openttd.org>
parents: 2111
diff changeset
770 Track track = GB(p2, 4, 3);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
771 Trackdir trackdir = TrackToTrackdir(track);
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
772 byte semaphores = (HASBIT(p2, 3)) ? 8 : 0;
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
773 byte signal_density = (p2 >> 24);
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
774
2934
137d6aa34f0e (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron <tron@openttd.org>
parents: 2916
diff changeset
775 if (p1 >= MapSize()) return CMD_ERROR;
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
776 if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
777
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
778 if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR;
1954
33916fc46768 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid <hackykid@openttd.org>
parents: 1946
diff changeset
779
889
8a7301b5aa5b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater <darkvater@openttd.org>
parents: 826
diff changeset
780 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
8a7301b5aa5b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater <darkvater@openttd.org>
parents: 826
diff changeset
781
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
782 /* for vertical/horizontal tracks, double the given signals density
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
783 * since the original amount will be too dense (shorter tracks) */
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
784 if (!IsDiagonalTrack(track))
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
785 signal_density *= 2;
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
786
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
787 // unpack end tile
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
788 ex = TileX(p1) * TILE_SIZE;
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
789 ey = TileY(p1) * TILE_SIZE;
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
790
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
791 if (CmdFailed(ValidateAutoDrag(&trackdir, x, y, ex, ey))) return CMD_ERROR;
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
792
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
793 track = TrackdirToTrack(trackdir); /* trackdir might have changed, keep track in sync */
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
794
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
795 // copy the signal-style of the first rail-piece if existing
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
796 if (GetRailTileType(tile) == RAIL_TYPE_SIGNALS && GetTrackBits(tile) != 0) { /* XXX: GetTrackBits check useless? */
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
797 signals = _m[tile].m3 & SignalOnTrack(track);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
798 if (signals == 0) signals = SignalOnTrack(track); /* Can this actually occur? */
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
799
3237
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
800 // copy signal/semaphores style (independent of CTRL)
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
801 semaphores = (GetSignalVariant(tile) == SIG_ELECTRIC ? 0 : 8);
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
802 } else // no signals exist, drag a two-way signal stretch
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
803 signals = SignalOnTrack(track);
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
804
1954
33916fc46768 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid <hackykid@openttd.org>
parents: 1946
diff changeset
805 /* signal_ctr - amount of tiles already processed
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
806 * signals_density - patch setting to put signal on every Nth tile (double space on |, -- tracks)
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
807 **********
1954
33916fc46768 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid <hackykid@openttd.org>
parents: 1946
diff changeset
808 * trackdir - trackdir to build with autorail
33916fc46768 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid <hackykid@openttd.org>
parents: 1946
diff changeset
809 * semaphores - semaphores or signals
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
810 * signals - is there a signal/semaphore on the first tile, copy its style (two-way/single-way)
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
811 and convert all others to semaphore/signal
1954
33916fc46768 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid <hackykid@openttd.org>
parents: 1946
diff changeset
812 * mode - 1 remove signals, 0 build signals */
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
813 signal_ctr = total_cost = 0;
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
814 for (;;) {
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
815 // only build/remove signals with the specified density
1954
33916fc46768 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid <hackykid@openttd.org>
parents: 1946
diff changeset
816 if ((signal_ctr % signal_density) == 0 ) {
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
817 ret = DoCommand(x, y, TrackdirToTrack(trackdir) | semaphores, signals, flags, (mode == 1) ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
818
826
f0bdeb9778ab (svn r1297) Language fixes in the source.. (ln-)
miham <miham@openttd.org>
parents: 817
diff changeset
819 /* Abort placement for any other error than NOT_SUITABLE_TRACK
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
820 * This includes vehicles on track, competitor's tracks, etc. */
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
821 if (CmdFailed(ret)) {
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
822 if (_error_message != STR_1005_NO_SUITABLE_RAILROAD_TRACK && mode != 1) return CMD_ERROR;
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
823 } else {
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
824 error = false;
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
825 total_cost += ret;
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
826 }
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
827 }
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
828
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
829 if (ex == x && ey == y) break; // reached end of drag
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
830
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
831 x += _railbit.xinc[trackdir];
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
832 y += _railbit.yinc[trackdir];
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
833 signal_ctr++;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
834
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
835 // toggle railbit for the non-diagonal tracks (|, -- tracks)
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
836 if (!IsDiagonalTrackdir(trackdir)) trackdir ^= 1;
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
837 }
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
838
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
839 return error ? CMD_ERROR : total_cost;
58
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
840 }
9c9aa1db223f (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
841
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
842 /** Build signals on a stretch of track.
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
843 * Stub for the unified signal builder/remover
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
844 * @see CmdSignalTrackHelper
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
845 */
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
846 int32 CmdBuildSignalTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
847 {
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
848 return CmdSignalTrackHelper(x, y, flags, p1, p2);
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
849 }
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
850
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
851 /** Remove signals
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
852 * @param x,y coordinates where signal is being deleted from
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
853 * @param p1 track to remove signal from (Track enum)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
854 */
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
855 int32 CmdRemoveSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
856 {
1980
e7a647ab6cb1 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron <tron@openttd.org>
parents: 1977
diff changeset
857 TileIndex tile = TileVirtXY(x, y);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
858 Track track = (Track)(p1 & 0x7);
1518
2e4fdef5fce6 (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron <tron@openttd.org>
parents: 1477
diff changeset
859
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
860 if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile))
1518
2e4fdef5fce6 (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron <tron@openttd.org>
parents: 1477
diff changeset
861 return CMD_ERROR;
2e4fdef5fce6 (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron <tron@openttd.org>
parents: 1477
diff changeset
862
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
863 if (!HasSignalOnTrack(tile, track)) // no signals on track?
1518
2e4fdef5fce6 (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron <tron@openttd.org>
parents: 1477
diff changeset
864 return CMD_ERROR;
2e4fdef5fce6 (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron <tron@openttd.org>
parents: 1477
diff changeset
865
1775
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
866 /* Only water can remove signals from anyone */
1551f4b0e0e0 (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 <Darkvater@openttd.org>
parents: 1719
diff changeset
867 if (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
868
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
869 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
870
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
871 /* Do it? */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
872 if (flags & DC_EXEC) {
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
873 _m[tile].m3 &= ~SignalOnTrack(track);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
874
1066
bda4fedf3a03 (svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater <darkvater@openttd.org>
parents: 1059
diff changeset
875 /* removed last signal from tile? */
2493
8ed4d837329f (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron <tron@openttd.org>
parents: 2472
diff changeset
876 if (GB(_m[tile].m3, 4, 4) == 0) {
8ed4d837329f (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron <tron@openttd.org>
parents: 2472
diff changeset
877 SB(_m[tile].m2, 4, 4, 0);
8ed4d837329f (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron <tron@openttd.org>
parents: 2472
diff changeset
878 SB(_m[tile].m5, 6, 2, RAIL_TYPE_NORMAL >> 6); // XXX >> because the constant is meant for direct application, not use with SB
3237
e34f863b480b (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron <tron@openttd.org>
parents: 3234
diff changeset
879 SetSignalVariant(tile, SIG_ELECTRIC); // remove any possible semaphores
1066
bda4fedf3a03 (svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater <darkvater@openttd.org>
parents: 1059
diff changeset
880 }
1109
aa09f0ca9ea0 (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron <tron@openttd.org>
parents: 1095
diff changeset
881
1066
bda4fedf3a03 (svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater <darkvater@openttd.org>
parents: 1059
diff changeset
882 SetSignalsOnBothDir(tile, track);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
883
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
884 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
885 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
886
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
887 return _price.remove_signals;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
888 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
889
1796
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
890 /** Remove signals on a stretch of track.
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
891 * Stub for the unified signal builder/remover
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
892 * @see CmdSignalTrackHelper
80af8ed2ebd8 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater <Darkvater@openttd.org>
parents: 1782
diff changeset
893 */
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
894 int32 CmdRemoveSignalTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
895 {
1229
db8295bc6859 (svn r1733) - Fix: oops "| 1" is SETBIT(x, 0), not 1 :(. Now you can remove signals again
darkvater <darkvater@openttd.org>
parents: 1227
diff changeset
896 return CmdSignalTrackHelper(x, y, flags, p1, SETBIT(p2, 0));
1227
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
897 }
259e7dab9c80 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater <darkvater@openttd.org>
parents: 1209
diff changeset
898
3355
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
899 typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
900
3355
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
901 static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
902 {
3355
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
903 if (!CheckTileOwnership(tile)) return CMD_ERROR;
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
904
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
905 if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
906
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
907 // tile is already of requested type?
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
908 if (GetRailType(tile) == totype) return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
909
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
910 // change type.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
911 if (exec) {
3242
2aed0a741a25 (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron <tron@openttd.org>
parents: 3238
diff changeset
912 SetRailType(tile, totype);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
913 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
914 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
915
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
916 return _price.build_rail / 2;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
917 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
918
3435
f609f81f1396 (svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater <Darkvater@openttd.org>
parents: 3418
diff changeset
919 extern int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec);
f609f81f1396 (svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater <Darkvater@openttd.org>
parents: 3418
diff changeset
920 extern int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec);
f609f81f1396 (svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater <Darkvater@openttd.org>
parents: 3418
diff changeset
921 extern int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
922
1782
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
923 /** Convert one rail type to the other. You can convert normal rail to
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
924 * monorail/maglev easily or vice-versa.
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
925 * @param ex,ey end tile of rail conversion drag
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
926 * @param p1 start tile of drag
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
927 * @param p2 new railtype to convert to
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
928 */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
929 int32 CmdConvertRail(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
930 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
931 int32 ret, cost, money;
1782
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
932 int sx, sy, x, y;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
933
889
8a7301b5aa5b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater <darkvater@openttd.org>
parents: 826
diff changeset
934 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
8a7301b5aa5b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater <darkvater@openttd.org>
parents: 826
diff changeset
935
1782
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
936 if (!ValParamRailtype(p2)) return CMD_ERROR;
2934
137d6aa34f0e (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron <tron@openttd.org>
parents: 2916
diff changeset
937 if (p1 >= MapSize()) return CMD_ERROR;
1782
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
938
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
939 // make sure sx,sy are smaller than ex,ey
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
940 sx = TileX(p1) * TILE_SIZE;
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
941 sy = TileY(p1) * TILE_SIZE;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
942 if (ex < sx) intswap(ex, sx);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
943 if (ey < sy) intswap(ey, sy);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
944
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
945 money = GetAvailableMoneyForCommand();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
946 cost = 0;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
947
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
948 for (x = sx; x <= ex; x += TILE_SIZE) {
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
949 for (y = sy; y <= ey; y += TILE_SIZE) {
1980
e7a647ab6cb1 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron <tron@openttd.org>
parents: 1977
diff changeset
950 TileIndex tile = TileVirtXY(x, y);
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
951 DoConvertRailProc* proc;
1782
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
952
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
953 switch (GetTileType(tile)) {
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
954 case MP_RAILWAY: proc = DoConvertRail; break;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
955 case MP_STATION: proc = DoConvertStationRail; break;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
956 case MP_STREET: proc = DoConvertStreetRail; break;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
957 case MP_TUNNELBRIDGE: proc = DoConvertTunnelBridgeRail; break;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
958 default: continue;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
959 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
960
1782
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
961 ret = proc(tile, p2, false);
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
962 if (CmdFailed(ret)) continue;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
963 cost += ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
964
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
965 if (flags & DC_EXEC) {
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
966 money -= ret;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
967 if (money < 0) {
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
968 _additional_cash_required = ret;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
969 return cost - ret;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
970 }
1782
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
971 proc(tile, p2, true);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
972 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
973 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
974 }
1782
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
975
dd56c2d77d1c (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater <Darkvater@openttd.org>
parents: 1781
diff changeset
976 return (cost == 0) ? CMD_ERROR : cost;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
977 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
978
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
979 static int32 RemoveTrainDepot(TileIndex tile, uint32 flags)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
980 {
149
811875caee5f (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater <darkvater@openttd.org>
parents: 84
diff changeset
981 if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
982 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
983
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
984 if (!EnsureNoVehicle(tile))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
985 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
986
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
987 if (flags & DC_EXEC) {
3191
ce099c2f5321 (svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron <tron@openttd.org>
parents: 3189
diff changeset
988 DiagDirection dir = GetRailDepotDirection(tile);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
989
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
990 DoDeleteDepot(tile);
3191
ce099c2f5321 (svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron <tron@openttd.org>
parents: 3189
diff changeset
991 UpdateSignalsOnSegment(tile, dir);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
992 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
993
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
994 return _price.remove_train_depot;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
995 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
996
1534
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
997 static int32 ClearTile_Track(TileIndex tile, byte flags)
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
998 {
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
999 int32 cost;
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1000 int32 ret;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1001 byte m5;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1002
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
1003 m5 = _m[tile].m5;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1004
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1005 if (flags & DC_AUTO) {
3253
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
1006 if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1007 return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
3253
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
1008 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1009
1901
74e0d3101dfb (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron <tron@openttd.org>
parents: 1891
diff changeset
1010 if (!IsTileOwner(tile, _current_player))
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1011 return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1012
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1013 return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1014 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1015
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1016 cost = 0;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1017
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
1018 switch (GetRailTileType(tile)) {
2821
2341ec1cfe9d (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs <matthijs@openttd.org>
parents: 2817
diff changeset
1019 /* XXX: Why the fuck do we remove these thow signals first? */
1534
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1020 case RAIL_TYPE_SIGNALS:
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1021 if (HasSignalOnTrack(tile, TRACK_X)) {
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1022 ret = DoCommandByTile(tile, TRACK_X, 0, flags, CMD_REMOVE_SIGNALS);
2737
9e5a26fdab58 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138 <peter1138@openttd.org>
parents: 2670
diff changeset
1023 if (CmdFailed(ret)) return CMD_ERROR;
1534
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1024 cost += ret;
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1025 }
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1026 if (HasSignalOnTrack(tile, TRACK_LOWER)) {
2821
2341ec1cfe9d (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs <matthijs@openttd.org>
parents: 2817
diff changeset
1027 ret = DoCommandByTile(tile, TRACK_LOWER, 0, flags, CMD_REMOVE_SIGNALS);
2737
9e5a26fdab58 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138 <peter1138@openttd.org>
parents: 2670
diff changeset
1028 if (CmdFailed(ret)) return CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1029 cost += ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1030 }
1534
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1031
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
1032 m5 &= TRACK_BIT_MASK;
1598
6dd1bf286622 (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron <tron@openttd.org>
parents: 1591
diff changeset
1033 if (!(flags & DC_EXEC)) {
6dd1bf286622 (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron <tron@openttd.org>
parents: 1591
diff changeset
1034 for (; m5 != 0; m5 >>= 1) if (m5 & 1) cost += _price.remove_rail;
6dd1bf286622 (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron <tron@openttd.org>
parents: 1591
diff changeset
1035 return cost;
6dd1bf286622 (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron <tron@openttd.org>
parents: 1591
diff changeset
1036 }
1534
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1037 /* FALLTHROUGH */
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1038
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1039 case RAIL_TYPE_NORMAL: {
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1040 uint i;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1041
1534
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1042 for (i = 0; m5 != 0; i++, m5 >>= 1) {
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1043 if (m5 & 1) {
1598
6dd1bf286622 (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron <tron@openttd.org>
parents: 1591
diff changeset
1044 ret = DoCommandByTile(tile, 0, i, flags, CMD_REMOVE_SINGLE_RAIL);
2737
9e5a26fdab58 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138 <peter1138@openttd.org>
parents: 2670
diff changeset
1045 if (CmdFailed(ret)) return CMD_ERROR;
1534
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1046 cost += ret;
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1047 }
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1048 }
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1049 return cost;
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1050 }
1109
aa09f0ca9ea0 (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron <tron@openttd.org>
parents: 1095
diff changeset
1051
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
1052 case RAIL_TYPE_DEPOT_WAYPOINT:
3269
9f6f208b2ff6 (svn r3981) More work for the rail accessing functions and enums
tron <tron@openttd.org>
parents: 3267
diff changeset
1053 if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
9f6f208b2ff6 (svn r3981) More work for the rail accessing functions and enums
tron <tron@openttd.org>
parents: 3267
diff changeset
1054 return RemoveTrainDepot(tile, flags);
9f6f208b2ff6 (svn r3981) More work for the rail accessing functions and enums
tron <tron@openttd.org>
parents: 3267
diff changeset
1055 } else {
9f6f208b2ff6 (svn r3981) More work for the rail accessing functions and enums
tron <tron@openttd.org>
parents: 3267
diff changeset
1056 return RemoveTrainWaypoint(tile, flags, false);
1534
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1057 }
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1058
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1059 default:
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1060 return CMD_ERROR;
5013d51ff600 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron <tron@openttd.org>
parents: 1518
diff changeset
1061 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1062 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1063
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1064
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1065
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1066 #include "table/track_land.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1067
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1068 // used for presignals
2916
9f16688176a1 (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater <Darkvater@openttd.org>
parents: 2911
diff changeset
1069 static const SpriteID _signal_base_sprites[16] = {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1070 0x4FB,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1071 0x1323,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1072 0x1333,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1073 0x1343,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1074
2008
9e0f41852bf8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid <hackykid@openttd.org>
parents: 2007
diff changeset
1075 // semaphores
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1076 0x1353,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1077 0x1363,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1078 0x1373,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1079 0x1383,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1080
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1081 // mirrored versions
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1082 0x4FB,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1083 0x1323,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1084 0x1333,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1085 0x1343,
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1086
2008
9e0f41852bf8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid <hackykid@openttd.org>
parents: 2007
diff changeset
1087 // semaphores
9e0f41852bf8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid <hackykid@openttd.org>
parents: 2007
diff changeset
1088 0x1446,
9e0f41852bf8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid <hackykid@openttd.org>
parents: 2007
diff changeset
1089 0x1456,
9e0f41852bf8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid <hackykid@openttd.org>
parents: 2007
diff changeset
1090 0x1466,
9e0f41852bf8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid <hackykid@openttd.org>
parents: 2007
diff changeset
1091 0x1476,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1092 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1093
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1094 // used to determine the side of the road for the signal
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1095 static const byte _signal_position[24] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1096 /* original: left side position */
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1097 0x58, 0x1E, 0xE1, 0xB9, 0x01, 0xA3, 0x4B, 0xEE, 0x3B, 0xD4, 0x43, 0xBD,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1098 /* patch: ride side position */
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1099 0x1E, 0xAC, 0x64, 0xE1, 0x4A, 0x10, 0xEE, 0xC5, 0xDB, 0x34, 0x4D, 0xB3
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1100 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1101
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1102 static void DrawSignalHelper(const TileInfo *ti, byte condition, uint32 image_and_pos)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1103 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1104 bool otherside = _opt.road_side & _patches.signal_side;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1105
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1106 uint v = _signal_position[(image_and_pos & 0xF) + (otherside ? 12 : 0)];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1107 uint x = ti->x | (v&0xF);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1108 uint y = ti->y | (v>>4);
2916
9f16688176a1 (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater <Darkvater@openttd.org>
parents: 2911
diff changeset
1109 uint sprite = _signal_base_sprites[(_m[ti->tile].m4 & 0x7) + (otherside ? 8 : 0)] + (image_and_pos>>4) + ((condition != 0) ? 1 : 0);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1110 AddSortableSpriteToDraw(sprite, x, y, 1, 1, 10, GetSlopeZ(x,y));
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1111 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1112
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1113 static uint32 _drawtile_track_palette;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1114
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1115
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1116 static void DrawTrackFence_NW(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1117 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1118 uint32 image = 0x515;
2645
b086d6d1b76d (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron <tron@openttd.org>
parents: 2642
diff changeset
1119 if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1120 AddSortableSpriteToDraw(image | _drawtile_track_palette,
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1121 ti->x, ti->y + 1, 16, 1, 4, ti->z);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1122 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1123
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1124 static void DrawTrackFence_SE(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1125 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1126 uint32 image = 0x515;
2645
b086d6d1b76d (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron <tron@openttd.org>
parents: 2642
diff changeset
1127 if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1128 AddSortableSpriteToDraw(image | _drawtile_track_palette,
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1129 ti->x, ti->y + 15, 16, 1, 4, ti->z);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1130 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1131
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1132 static void DrawTrackFence_NW_SE(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1133 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1134 DrawTrackFence_NW(ti);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1135 DrawTrackFence_SE(ti);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1136 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1137
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1138 static void DrawTrackFence_NE(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1139 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1140 uint32 image = 0x516;
2645
b086d6d1b76d (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron <tron@openttd.org>
parents: 2642
diff changeset
1141 if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1142 AddSortableSpriteToDraw(image | _drawtile_track_palette,
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1143 ti->x + 1, ti->y, 1, 16, 4, ti->z);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1144 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1145
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1146 static void DrawTrackFence_SW(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1147 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1148 uint32 image = 0x516;
2645
b086d6d1b76d (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron <tron@openttd.org>
parents: 2642
diff changeset
1149 if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1150 AddSortableSpriteToDraw(image | _drawtile_track_palette,
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1151 ti->x + 15, ti->y, 1, 16, 4, ti->z);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1152 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1153
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1154 static void DrawTrackFence_NE_SW(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1155 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1156 DrawTrackFence_NE(ti);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1157 DrawTrackFence_SW(ti);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1158 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1159
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1160 static void DrawTrackFence_NS_1(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1161 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1162 int z = ti->z;
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1163 if (ti->tileh & 1) z += 8;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1164 AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1165 ti->x + 8, ti->y + 8, 1, 1, 4, z);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1166 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1167
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1168 static void DrawTrackFence_NS_2(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1169 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1170 int z = ti->z;
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1171 if (ti->tileh & 4) z += 8;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1172 AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1173 ti->x + 8, ti->y + 8, 1, 1, 4, z);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1174 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1175
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1176 static void DrawTrackFence_WE_1(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1177 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1178 int z = ti->z;
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1179 if (ti->tileh & 8) z += 8;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1180 AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1181 ti->x + 8, ti->y + 8, 1, 1, 4, z);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1182 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1183
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1184 static void DrawTrackFence_WE_2(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1185 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1186 int z = ti->z;
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1187 if (ti->tileh & 2) z += 8;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1188 AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1189 ti->x + 8, ti->y + 8, 1, 1, 4, z);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1190 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1191
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1192 static void DetTrackDrawProc_Null(const TileInfo *ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1193 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1194 /* nothing should be here */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1195 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1196
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1197 typedef void DetailedTrackProc(const TileInfo *ti);
2752
100b11236310 (svn r3297) Staticise
tron <tron@openttd.org>
parents: 2737
diff changeset
1198 static DetailedTrackProc* const _detailed_track_proc[] = {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1199 DetTrackDrawProc_Null,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1200 DetTrackDrawProc_Null,
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1201
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1202 DrawTrackFence_NW,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1203 DrawTrackFence_SE,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1204 DrawTrackFence_NW_SE,
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1205
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1206 DrawTrackFence_NE,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1207 DrawTrackFence_SW,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1208 DrawTrackFence_NE_SW,
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1209
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1210 DrawTrackFence_NS_1,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1211 DrawTrackFence_NS_2,
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1212
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1213 DrawTrackFence_WE_1,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1214 DrawTrackFence_WE_2,
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1215
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1216 DetTrackDrawProc_Null,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1217 DetTrackDrawProc_Null,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1218 DetTrackDrawProc_Null,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1219 DetTrackDrawProc_Null,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1220 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1221
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1222 static void DrawSpecialBuilding(
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1223 uint32 image, uint32 offset,
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1224 const TileInfo* ti,
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1225 byte x, byte y, byte z,
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1226 byte xsize, byte ysize, byte zsize)
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1227 {
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1228 if (image & PALETTE_MODIFIER_COLOR) image |= _drawtile_track_palette;
2254
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1229 image += offset;
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1230 if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1231 AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z);
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1232 }
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1233
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1234 /**
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1235 * Draw ground sprite and track bits
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1236 * @param ti TileInfo
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1237 * @param track TrackBits to draw
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1238 * @param earth Draw as earth
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1239 * @param snow Draw as snow
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1240 * @param flat Always draw foundation
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1241 */
2817
6109c518dc4f (svn r3365) Staticise 36 functions
tron <tron@openttd.org>
parents: 2753
diff changeset
1242 static void DrawTrackBits(TileInfo* ti, TrackBits track, bool earth, bool snow, bool flat)
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1243 {
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1244 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1245 PalSpriteID image;
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1246 bool junction = false;
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1247
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1248 // Select the sprite to use.
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1249 (image = rti->base_sprites.track_y, track == TRACK_BIT_Y) ||
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1250 (image++, track == TRACK_BIT_X) ||
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1251 (image++, track == TRACK_BIT_UPPER) ||
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1252 (image++, track == TRACK_BIT_LOWER) ||
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1253 (image++, track == TRACK_BIT_RIGHT) ||
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1254 (image++, track == TRACK_BIT_LEFT) ||
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1255 (image++, track == TRACK_BIT_CROSS) ||
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1256
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1257 (image = rti->base_sprites.track_ns, track == TRACK_BIT_HORZ) ||
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1258 (image++, track == TRACK_BIT_VERT) ||
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1259
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1260 (junction = true, false) ||
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1261 (image = rti->base_sprites.ground, (track & TRACK_BIT_3WAY_NE) == 0) ||
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1262 (image++, (track & TRACK_BIT_3WAY_SW) == 0) ||
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1263 (image++, (track & TRACK_BIT_3WAY_NW) == 0) ||
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1264 (image++, (track & TRACK_BIT_3WAY_SE) == 0) ||
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1265 (image++, true);
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1266
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1267 if (ti->tileh != 0) {
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1268 int foundation;
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1269
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1270 if (flat) {
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1271 foundation = ti->tileh;
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1272 } else {
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1273 foundation = GetRailFoundation(ti->tileh, track);
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1274 }
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1275
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1276 if (foundation != 0)
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1277 DrawFoundation(ti, foundation);
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1278
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1279 // DrawFoundation() modifies ti.
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1280 // Default sloped sprites..
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1281 if (ti->tileh != 0)
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1282 image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y;
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1283 }
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1284
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1285 if (earth) {
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1286 image = (image & SPRITE_MASK) | PALETTE_TO_BARE_LAND; // Use brown palette
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1287 } else if (snow) {
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1288 image += rti->snow_offset;
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1289 }
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1290
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1291 DrawGroundSprite(image);
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1292
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1293 // Draw track pieces individually for junction tiles
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1294 if (junction) {
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1295 if (track & TRACK_BIT_X) DrawGroundSprite(rti->base_sprites.single_y);
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1296 if (track & TRACK_BIT_Y) DrawGroundSprite(rti->base_sprites.single_x);
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1297 if (track & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n);
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1298 if (track & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s);
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1299 if (track & TRACK_BIT_LEFT) DrawGroundSprite(rti->base_sprites.single_w);
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1300 if (track & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e);
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1301 }
3355
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
1302
3361
6a9e01c30788 (svn r4156) CodeChange : Little cleanup after Celestar's elrail merge
belugas <belugas@openttd.org>
parents: 3355
diff changeset
1303 if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
3355
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
1304
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1305 }
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1306
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1307 static void DrawTile_Track(TileInfo *ti)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1308 {
2233
1631045675f5 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar <celestar@openttd.org>
parents: 2187
diff changeset
1309 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1310 PalSpriteID image;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1311
1901
74e0d3101dfb (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron <tron@openttd.org>
parents: 1891
diff changeset
1312 _drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1313
3253
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
1314 if (GetRailTileType(ti->tile) != RAIL_TYPE_DEPOT_WAYPOINT) {
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1315 TrackBits rails = GetTrackBits(ti->tile);
2472
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1316 bool earth = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_BROWN;
76629e9a1546 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138 <peter1138@openttd.org>
parents: 2436
diff changeset
1317 bool snow = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1318
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1319 DrawTrackBits(ti, rails, earth, snow, false);
2008
9e0f41852bf8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid <hackykid@openttd.org>
parents: 2007
diff changeset
1320
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1321 if (_display_opt & DO_FULL_DETAIL) {
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
1322 _detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1323 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1324
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1325 /* draw signals also? */
3253
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
1326 if (GetRailTileType(ti->tile) != RAIL_TYPE_SIGNALS) return;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1327
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1328 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1329 byte m23;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1330
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
1331 m23 = (_m[ti->tile].m3 >> 4) | (_m[ti->tile].m2 & 0xF0);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1332
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1333 #define HAS_SIGNAL(x) (m23 & (byte)(0x1 << (x)))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1334 #define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x)))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1335 #define MAYBE_DRAW_SIGNAL(x,y,z) if (HAS_SIGNAL(x)) DrawSignalHelper(ti, ISON_SIGNAL(x), ((y-0x4FB) << 4)|(z))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1336
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1337 if (!(rails & TRACK_BIT_Y)) {
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1338 if (!(rails & TRACK_BIT_X)) {
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1339 if (rails & TRACK_BIT_LEFT) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1340 MAYBE_DRAW_SIGNAL(2, 0x509, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1341 MAYBE_DRAW_SIGNAL(3, 0x507, 1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1342 }
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1343 if (rails & TRACK_BIT_RIGHT) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1344 MAYBE_DRAW_SIGNAL(0, 0x509, 2);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1345 MAYBE_DRAW_SIGNAL(1, 0x507, 3);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1346 }
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1347 if (rails & TRACK_BIT_UPPER) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1348 MAYBE_DRAW_SIGNAL(3, 0x505, 4);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1349 MAYBE_DRAW_SIGNAL(2, 0x503, 5);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1350 }
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1351 if (rails & TRACK_BIT_LOWER) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1352 MAYBE_DRAW_SIGNAL(1, 0x505, 6);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1353 MAYBE_DRAW_SIGNAL(0, 0x503, 7);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1354 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1355 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1356 MAYBE_DRAW_SIGNAL(3, 0x4FB, 8);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1357 MAYBE_DRAW_SIGNAL(2, 0x4FD, 9);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1358 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1359 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1360 MAYBE_DRAW_SIGNAL(3, 0x4FF, 10);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1361 MAYBE_DRAW_SIGNAL(2, 0x501, 11);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1362 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1363 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1364 } else {
395
9566850ffa0d (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater <darkvater@openttd.org>
parents: 393
diff changeset
1365 /* draw depots / waypoints */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1366 const DrawTrackSeqStruct *drss;
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1367 byte type = ti->map5 & 0x3F; // 0-3: depots, 4-5: waypoints
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1368
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1369 if (ti->tileh != 0) DrawFoundation(ti, ti->tileh);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1370
2668
fff094d64d05 (svn r3210) -Codechange: use IsRailWaypoint where possible (instead of magicnumbers)
truelight <truelight@openttd.org>
parents: 2667
diff changeset
1371 if (IsRailWaypoint(ti->tile) && HASBIT(_m[ti->tile].m3, 4)) {
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1372 // look for customization
2670
91c99ca703f7 (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138 <peter1138@openttd.org>
parents: 2668
diff changeset
1373 byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
91c99ca703f7 (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138 <peter1138@openttd.org>
parents: 2668
diff changeset
1374 const StationSpec *stat = GetCustomStation(STAT_CLASS_WAYP, stat_id);
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1375
2624
2b406842cad4 (svn r3166) Constify read-only accesses of custom stations
peter1138 <peter1138@openttd.org>
parents: 2604
diff changeset
1376 if (stat != NULL) {
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1377 DrawTileSeqStruct const *seq;
403
264c16156063 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater <darkvater@openttd.org>
parents: 399
diff changeset
1378 // emulate station tile - open with building
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1379 const DrawTileSprites *cust = &stat->renderdata[2 + (ti->map5 & 0x1)];
413
93bd4a7b763b (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater <darkvater@openttd.org>
parents: 412
diff changeset
1380 uint32 relocation = GetCustomStationRelocation(stat, ComposeWaypointStation(ti->tile), 0);
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1381
447
4e6b8aca032b (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar <celestar@openttd.org>
parents: 438
diff changeset
1382 /* We don't touch the 0x8000 bit. In all this
4e6b8aca032b (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar <celestar@openttd.org>
parents: 438
diff changeset
1383 * waypoint code, it is used to indicate that
4e6b8aca032b (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar <celestar@openttd.org>
parents: 438
diff changeset
1384 * we should offset by railtype, but we always
4e6b8aca032b (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar <celestar@openttd.org>
parents: 438
diff changeset
1385 * do that for custom ground sprites and never
4e6b8aca032b (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar <celestar@openttd.org>
parents: 438
diff changeset
1386 * for station sprites. And in the drawing
4e6b8aca032b (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar <celestar@openttd.org>
parents: 438
diff changeset
1387 * code, it is used to indicate that the sprite
4e6b8aca032b (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar <celestar@openttd.org>
parents: 438
diff changeset
1388 * should be drawn in company colors, and it's
4e6b8aca032b (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar <celestar@openttd.org>
parents: 438
diff changeset
1389 * up to the GRF file to decide that. */
4e6b8aca032b (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar <celestar@openttd.org>
parents: 438
diff changeset
1390
417
721e9310944e (svn r614) [newgrf] Some minor code fixes
dominik <dominik@openttd.org>
parents: 415
diff changeset
1391 image = cust->ground_sprite;
2254
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1392 image += (image < _custom_sprites_base) ? rti->total_offset : GetRailType(ti->tile);
415
88e0ffa216fe (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik <dominik@openttd.org>
parents: 413
diff changeset
1393
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1394 DrawGroundSprite(image);
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1395
3355
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
1396 if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
1397
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1398 foreach_draw_tile_seq(seq, cust->seq) {
2989
00a81ec78145 (svn r3564) Several smaller changes:
tron <tron@openttd.org>
parents: 2952
diff changeset
1399 DrawSpecialBuilding(
00a81ec78145 (svn r3564) Several smaller changes:
tron <tron@openttd.org>
parents: 2952
diff changeset
1400 seq->image + relocation, 0, ti,
00a81ec78145 (svn r3564) Several smaller changes:
tron <tron@openttd.org>
parents: 2952
diff changeset
1401 seq->delta_x, seq->delta_y, seq->delta_z,
00a81ec78145 (svn r3564) Several smaller changes:
tron <tron@openttd.org>
parents: 2952
diff changeset
1402 seq->width, seq->height, seq->unk
00a81ec78145 (svn r3564) Several smaller changes:
tron <tron@openttd.org>
parents: 2952
diff changeset
1403 );
389
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1404 }
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1405 return;
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1406 }
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1407 }
3f9699778ddd (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar <celestar@openttd.org>
parents: 337
diff changeset
1408
1399
cccaaabb04ec (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron <tron@openttd.org>
parents: 1363
diff changeset
1409 drss = _track_depot_layout_table[type];
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1410
1399
cccaaabb04ec (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron <tron@openttd.org>
parents: 1363
diff changeset
1411 image = drss++->image;
2254
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1412 /* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1413 * whether the sprite is railtype dependent. Rewrite this asap */
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1414 if (image & PALETTE_MODIFIER_COLOR) image = (image & SPRITE_MASK) + rti->total_offset;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1415
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1416 // adjust ground tile for desert
283
e43e92b918ce (svn r289) Fix: Checkpoints on snow have correct ground now
dominik <dominik@openttd.org>
parents: 282
diff changeset
1417 // (don't adjust for arctic depots, because snow in depots looks weird)
2254
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1418 // type >= 4 means waypoints
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1419 if ((_m[ti->tile].m4 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT &&
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1420 (_opt.landscape == LT_DESERT || type >= 4)) {
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1421 if (image != SPR_FLAT_GRASS_TILE) {
2254
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1422 image += rti->snow_offset; // tile with tracks
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1423 } else {
2254
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1424 image = SPR_FLAT_SNOWY_TILE; // flat ground
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1425 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1426 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1427
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1428 DrawGroundSprite(image);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1429
3355
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
1430 if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
e8f5a792019b (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar <celestar@openttd.org>
parents: 3333
diff changeset
1431
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1432 for (; drss->image != 0; drss++) {
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1433 DrawSpecialBuilding(
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1434 drss->image, type < 4 ? rti->total_offset : 0, ti,
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1435 drss->subcoord_x, drss->subcoord_y, 0,
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1436 drss->width, drss->height, 0x17
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1437 );
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1438 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1439 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1440 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1441
2520
f5a86c2fa9a5 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron <tron@openttd.org>
parents: 2502
diff changeset
1442 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1443 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1444 uint32 ormod, img;
2254
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1445 const RailtypeInfo *rti = GetRailTypeInfo(railtype);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1446 const DrawTrackSeqStruct *dtss;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1447
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1448 ormod = PLAYER_SPRITE_COLOR(_local_player);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1449
1399
cccaaabb04ec (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron <tron@openttd.org>
parents: 1363
diff changeset
1450 dtss = _track_depot_layout_table[image];
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1451
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1452 x += 33;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1453 y += 17;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1454
1399
cccaaabb04ec (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron <tron@openttd.org>
parents: 1363
diff changeset
1455 img = dtss++->image;
2254
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1456 /* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1457 * whether the sprite is railtype dependent. Rewrite this asap */
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1458 if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1459 DrawSprite(img, x, y);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1460
1399
cccaaabb04ec (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron <tron@openttd.org>
parents: 1363
diff changeset
1461 for (; dtss->image != 0; dtss++) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1462 Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1463 image = dtss->image;
2187
ec59060e9c43 (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar <celestar@openttd.org>
parents: 2186
diff changeset
1464 if (image & PALETTE_MODIFIER_COLOR) image |= ormod;
2254
6ef9eb88013e (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar <celestar@openttd.org>
parents: 2236
diff changeset
1465 DrawSprite(image + rti->total_offset, x + pt.x, y + pt.y);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1466 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1467 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1468
2520
f5a86c2fa9a5 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron <tron@openttd.org>
parents: 2502
diff changeset
1469 void DrawDefaultWaypointSprite(int x, int y, RailType railtype)
2261
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1470 {
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1471 const DrawTrackSeqStruct *dtss = _track_depot_layout_table[4];
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1472 const RailtypeInfo *rti = GetRailTypeInfo(railtype);
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1473 uint32 img;
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1474
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1475 img = dtss++->image;
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1476 if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset;
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1477 DrawSprite(img, x, y);
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1478
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1479 for (; dtss->image != 0; dtss++) {
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1480 Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1481 img = dtss->image;
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1482 if (img & PALETTE_MODIFIER_COLOR) img |= PLAYER_SPRITE_COLOR(_local_player);
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1483 DrawSprite(img, x + pt.x, y + pt.y);
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1484 }
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1485 }
f51e788f7b9c (svn r2781) Fix some of the issues with variables in .h files.
ludde <ludde@openttd.org>
parents: 2254
diff changeset
1486
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1487 typedef struct SetSignalsData {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1488 int cur;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1489 int cur_stack;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1490 bool stop;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1491 bool has_presignal;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1492
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1493 // presignal info
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1494 int presignal_exits;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1495 int presignal_exits_free;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1496
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1497 // these are used to keep track of the signals that change.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1498 byte bit[NUM_SSD_ENTRY];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1499 TileIndex tile[NUM_SSD_ENTRY];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1500
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1501 // these are used to keep track of the stack that modifies presignals recursively
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1502 TileIndex next_tile[NUM_SSD_STACK];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1503 byte next_dir[NUM_SSD_STACK];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1504
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1505 } SetSignalsData;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1506
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
1507 static bool SetSignalsEnumProc(TileIndex tile, SetSignalsData *ssd, int track, uint length, byte *state)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1508 {
3017
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1509 if (!IsTileType(tile, MP_RAILWAY)) return false;
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1510
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1511 // the tile has signals?
3017
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1512 if (HasSignalOnTrack(tile, TrackdirToTrack(track))) {
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1513 if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) {
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1514 // yes, add the signal to the list of signals
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1515 if (ssd->cur != NUM_SSD_ENTRY) {
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1516 ssd->tile[ssd->cur] = tile; // remember the tile index
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1517 ssd->bit[ssd->cur] = track; // and the controlling bit number
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1518 ssd->cur++;
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
1519 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1520
3017
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1521 // remember if this block has a presignal.
3361
6a9e01c30788 (svn r4156) CodeChange : Little cleanup after Celestar's elrail merge
belugas <belugas@openttd.org>
parents: 3355
diff changeset
1522 ssd->has_presignal |= (_m[tile].m4 & 1);
3017
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1523 }
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
1524
3017
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1525 if (HasSignalOnTrackdir(tile, track) && _m[tile].m4 & 2) {
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1526 // this is an exit signal that points out from the segment
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1527 ssd->presignal_exits++;
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1528 if (GetSignalState(tile, track) != SIGNAL_STATE_RED)
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1529 ssd->presignal_exits_free++;
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1530 }
3017
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1531
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1532 return true;
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1533 } else if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1534 return true; // don't look further if the tile is a depot
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1535 }
3017
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1536
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1537 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1538 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1539
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1540 /* Struct to parse data from VehicleFromPos to SignalVehicleCheckProc */
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1541 typedef struct SignalVehicleCheckStruct {
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1542 TileIndex tile;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1543 uint track;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1544 } SignalVehicleCheckStruct;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1545
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1546 static void *SignalVehicleCheckProc(Vehicle *v, void *data)
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1547 {
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1548 const SignalVehicleCheckStruct* dest = data;
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1549 TileIndex tile;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1550
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1551 if (v->type != VEH_Train) return NULL;
1609
d978d08693e0 (svn r2113) -Fix: first check if a vehicle is a train, before accessing u.rail
truelight <truelight@openttd.org>
parents: 1598
diff changeset
1552
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1553 /* Find the tile outside the tunnel, for signalling */
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1554 if (v->u.rail.track == 0x40) {
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1555 tile = GetVehicleOutOfTunnelTile(v);
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1556 } else {
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1557 tile = v->tile;
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1558 }
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1559
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1560 /* Wrong tile, or no train? Not a match */
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1561 if (tile != dest->tile) return NULL;
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1562
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1563 /* Are we on the same piece of track? */
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1564 if (dest->track & (v->u.rail.track + (v->u.rail.track << 8))) return v;
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1565
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1566 return NULL;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1567 }
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1568
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1569 /* Special check for SetSignalsAfterProc, to see if there is a vehicle on this tile */
2752
100b11236310 (svn r3297) Staticise
tron <tron@openttd.org>
parents: 2737
diff changeset
1570 static bool SignalVehicleCheck(TileIndex tile, uint track)
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1571 {
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1572 SignalVehicleCheckStruct dest;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1573
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1574 dest.tile = tile;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1575 dest.track = track;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1576
1818
ca56201cd1c3 (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater <Darkvater@openttd.org>
parents: 1816
diff changeset
1577 /** @todo "Hackish" fix for the tunnel problems. This is needed because a tunnel
ca56201cd1c3 (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater <Darkvater@openttd.org>
parents: 1816
diff changeset
1578 * is some kind of invisible black hole, and there is some special magic going
ca56201cd1c3 (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater <Darkvater@openttd.org>
parents: 1816
diff changeset
1579 * on in there. This 'workaround' can be removed once the maprewrite is done.
ca56201cd1c3 (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater <Darkvater@openttd.org>
parents: 1816
diff changeset
1580 */
3184
c28b2713d696 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron <tron@openttd.org>
parents: 3172
diff changeset
1581 if (IsTunnelTile(tile)) {
1816
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1582 // It is a tunnel we're checking, we need to do some special stuff
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1583 // because VehicleFromPos will not find the vihicle otherwise
3154
c655b0fa9fa6 (svn r3777) Add some functions to handle tunnels
tron <tron@openttd.org>
parents: 3153
diff changeset
1584 TileIndex end = GetOtherTunnelEnd(tile);
c655b0fa9fa6 (svn r3777) Add some functions to handle tunnels
tron <tron@openttd.org>
parents: 3153
diff changeset
1585 DiagDirection direction = GetTunnelDirection(tile);
c655b0fa9fa6 (svn r3777) Add some functions to handle tunnels
tron <tron@openttd.org>
parents: 3153
diff changeset
1586
1816
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1587 dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible)
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1588
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1589 // check for a vehicle with that trackdir on the start tile of the tunnel
1818
ca56201cd1c3 (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater <Darkvater@openttd.org>
parents: 1816
diff changeset
1590 if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) return true;
1816
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1591
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1592 // check for a vehicle with that trackdir on the end tile of the tunnel
3154
c655b0fa9fa6 (svn r3777) Add some functions to handle tunnels
tron <tron@openttd.org>
parents: 3153
diff changeset
1593 if (VehicleFromPos(end, &dest, SignalVehicleCheckProc) != NULL) return true;
1816
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1594
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1595 // now check all tiles from start to end for a "hidden" vehicle
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1596 // NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile?
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1597 dest.track = 0x40; // trackbit for vehicles "hidden" inside a tunnel
3154
c655b0fa9fa6 (svn r3777) Add some functions to handle tunnels
tron <tron@openttd.org>
parents: 3153
diff changeset
1598 for (; tile != end; tile += TileOffsByDir(direction)) {
1816
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1599 if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL)
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1600 return true;
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1601 }
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1602
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1603 // no vehicle found
822304ded8d0 (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs <matthijs@openttd.org>
parents: 1813
diff changeset
1604 return false;
1818
ca56201cd1c3 (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater <Darkvater@openttd.org>
parents: 1816
diff changeset
1605 }
ca56201cd1c3 (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater <Darkvater@openttd.org>
parents: 1816
diff changeset
1606
ca56201cd1c3 (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater <Darkvater@openttd.org>
parents: 1816
diff changeset
1607 return VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL;
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1608 }
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1609
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1610 static void SetSignalsAfterProc(TrackPathFinder *tpf)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1611 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1612 SetSignalsData *ssd = tpf->userdata;
2548
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
1613 const TrackPathFinderLink* link;
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1614 uint offs;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1615 uint i;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1616
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1617 ssd->stop = false;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1618
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1619 /* Go through all the PF tiles */
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1620 for (i = 0; i < lengthof(tpf->hash_head); i++) {
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1621 /* Empty hash item */
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1622 if (tpf->hash_head[i] == 0) continue;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1623
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1624 /* If 0x8000 is not set, there is only 1 item */
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1625 if (!(tpf->hash_head[i] & 0x8000)) {
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1626 /* Check if there is a vehicle on this tile */
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1627 if (SignalVehicleCheck(tpf->hash_tile[i], tpf->hash_head[i])) {
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1628 ssd->stop = true;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1629 return;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1630 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1631 } else {
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1632 /* There are multiple items, where hash_tile points to the first item in the list */
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1633 offs = tpf->hash_tile[i];
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1634 do {
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1635 /* Find the next item */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1636 link = PATHFIND_GET_LINK_PTR(tpf, offs);
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1637 /* Check if there is a vehicle on this tile */
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1638 if (SignalVehicleCheck(link->tile, link->flags)) {
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1639 ssd->stop = true;
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1640 return;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1641 }
1555
5e28cb7ab511 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight <truelight@openttd.org>
parents: 1542
diff changeset
1642 /* Goto the next item */
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1643 } while ((offs = link->next) != 0xFFFF);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1644 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1645 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1646 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1647
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1648 static const byte _dir_from_track[14] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1649 0,1,0,1,2,1, 0,0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1650 2,3,3,2,3,0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1651 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1652
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1653
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1654 static void ChangeSignalStates(SetSignalsData *ssd)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1655 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1656 int i;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1657
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1658 // thinking about presignals...
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1659 // the presignal is green if,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1660 // if no train is in the segment AND
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1661 // there is at least one green exit signal OR
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1662 // there are no exit signals in the segment
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1663
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1664 // then mark the signals in the segment accordingly
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1665 for (i = 0; i != ssd->cur; i++) {
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
1666 TileIndex tile = ssd->tile[i];
2821
2341ec1cfe9d (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs <matthijs@openttd.org>
parents: 2817
diff changeset
1667 byte bit = SignalAgainstTrackdir(ssd->bit[i]);
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
1668 uint16 m2 = _m[tile].m2;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1669
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1670 // presignals don't turn green if there is at least one presignal exit and none are free
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
1671 if (_m[tile].m4 & 1) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1672 int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1673
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1674 // subtract for dual combo signals so they don't count themselves
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1675 if (_m[tile].m4 & 2 && HasSignalOnTrackdir(tile, ssd->bit[i])) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1676 ex--;
2821
2341ec1cfe9d (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs <matthijs@openttd.org>
parents: 2817
diff changeset
1677 if (GetSignalState(tile, ssd->bit[i]) != SIGNAL_STATE_RED) exfree--;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1678 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1679
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1680 // if we have exits and none are free, make red.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1681 if (ex && !exfree) goto make_red;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1682 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1683
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1684 // check if the signal is unaffected.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1685 if (ssd->stop) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1686 make_red:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1687 // turn red
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1688 if ((bit & m2) == 0) continue;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1689 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1690 // turn green
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1691 if ((bit & m2) != 0) continue;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1692 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1693
1813
032b0f070592 (svn r2317) - Fix: [ 1193048 ] Pre-signal stays red when there is only a single exit signal (dinno)
Darkvater <Darkvater@openttd.org>
parents: 1796
diff changeset
1694 /* Update signals on the other side of this exit-combo signal; it changed. */
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1695 if (_m[tile].m4 & 2) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1696 if (ssd->cur_stack != NUM_SSD_STACK) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1697 ssd->next_tile[ssd->cur_stack] = tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1698 ssd->next_dir[ssd->cur_stack] = _dir_from_track[ssd->bit[i]];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1699 ssd->cur_stack++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1700 } else {
1813
032b0f070592 (svn r2317) - Fix: [ 1193048 ] Pre-signal stays red when there is only a single exit signal (dinno)
Darkvater <Darkvater@openttd.org>
parents: 1796
diff changeset
1701 printf("NUM_SSD_STACK too small\n"); /// @todo WTF is this???
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1702 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1703 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1704
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1705 // it changed, so toggle it
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
1706 _m[tile].m2 = m2 ^ bit;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1707 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1708 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1709 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1710
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1711
3172
6782e202eb5e (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron <tron@openttd.org>
parents: 3157
diff changeset
1712 bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection direction)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1713 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1714 SetSignalsData ssd;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1715 int result = -1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1716
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1717 ssd.cur_stack = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1718
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1719 for (;;) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1720 // go through one segment and update all signals pointing into that segment.
2916
9f16688176a1 (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater <Darkvater@openttd.org>
parents: 2911
diff changeset
1721 ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1722 ssd.has_presignal = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1723
159
a4e15430335b (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight <truelight@openttd.org>
parents: 149
diff changeset
1724 FollowTrack(tile, 0xC000 | TRANSPORT_RAIL, direction, (TPFEnumProc*)SetSignalsEnumProc, SetSignalsAfterProc, &ssd);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1725 ChangeSignalStates(&ssd);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1726
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1727 // remember the result only for the first iteration.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1728 if (result < 0) result = ssd.stop;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1729
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1730 // if any exit signals were changed, we need to keep going to modify the stuff behind those.
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1731 if (ssd.cur_stack == 0) break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1732
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1733 // one or more exit signals were changed, so we need to update another segment too.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1734 tile = ssd.next_tile[--ssd.cur_stack];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1735 direction = ssd.next_dir[ssd.cur_stack];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1736 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1737
3017
0fa53a121447 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron <tron@openttd.org>
parents: 2989
diff changeset
1738 return result != 0;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1739 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1740
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
1741 void SetSignalsOnBothDir(TileIndex tile, byte track)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1742 {
3172
6782e202eb5e (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron <tron@openttd.org>
parents: 3157
diff changeset
1743 static const DiagDirection _search_dir_1[] = {
6782e202eb5e (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron <tron@openttd.org>
parents: 3157
diff changeset
1744 DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE
6782e202eb5e (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron <tron@openttd.org>
parents: 3157
diff changeset
1745 };
6782e202eb5e (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron <tron@openttd.org>
parents: 3157
diff changeset
1746 static const DiagDirection _search_dir_2[] = {
6782e202eb5e (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron <tron@openttd.org>
parents: 3157
diff changeset
1747 DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE
6782e202eb5e (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron <tron@openttd.org>
parents: 3157
diff changeset
1748 };
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1749
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1750 UpdateSignalsOnSegment(tile, _search_dir_1[track]);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1751 UpdateSignalsOnSegment(tile, _search_dir_2[track]);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1752 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1753
2537
0b275faf5387 (svn r3066) Constify the parameter of GetSlopeZ_*()
tron <tron@openttd.org>
parents: 2520
diff changeset
1754 static uint GetSlopeZ_Track(const TileInfo* ti)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1755 {
3286
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1756 uint tileh = ti->tileh;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1757 uint z = ti->z;
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
1758
3286
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1759 if (tileh == 0) return z;
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1760 if (GetRailTileType(ti->tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1761 return z + 8;
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1762 } else {
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1763 uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile));
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1764
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1765 if (f != 0) {
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1766 if (f < 15) return z + 8; // leveled foundation
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1767 tileh = _inclined_tileh[f - 15]; // inclined foundation
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1768 }
3286
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1769 return z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1770 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1771 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1772
3418
395cab721c3d (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron <tron@openttd.org>
parents: 3379
diff changeset
1773 static uint GetSlopeTileh_Track(TileIndex tile, uint tileh)
39
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
1774 {
3418
395cab721c3d (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron <tron@openttd.org>
parents: 3379
diff changeset
1775 if (tileh == 0) return 0;
395cab721c3d (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron <tron@openttd.org>
parents: 3379
diff changeset
1776 if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
3286
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1777 return 0;
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1778 } else {
3418
395cab721c3d (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron <tron@openttd.org>
parents: 3379
diff changeset
1779 uint f = GetRailFoundation(tileh, GetTrackBits(tile));
3286
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1780
3418
395cab721c3d (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron <tron@openttd.org>
parents: 3379
diff changeset
1781 if (f == 0) return tileh;
3286
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1782 if (f < 15) return 0; // leveled foundation
f1891d3b1d7c (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron <tron@openttd.org>
parents: 3284
diff changeset
1783 return _inclined_tileh[f - 15]; // inclined foundation
39
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
1784 }
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
1785 }
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
1786
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
1787 static void GetAcceptedCargo_Track(TileIndex tile, AcceptedCargo ac)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1788 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1789 /* not used */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1790 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1791
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
1792 static void AnimateTile_Track(TileIndex tile)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1793 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1794 /* not used */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1795 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1796
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
1797 static void TileLoop_Track(TileIndex tile)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1798 {
2667
ae35b513ff1b (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138 <peter1138@openttd.org>
parents: 2645
diff changeset
1799 byte old_ground;
ae35b513ff1b (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138 <peter1138@openttd.org>
parents: 2645
diff changeset
1800 byte new_ground;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1801
3486
d2940b03b6ba (svn r4337) -Fix: A problem where GetRailType was called instead of GetRailTileType. Thanks to glx for noticing
celestar <celestar@openttd.org>
parents: 3483
diff changeset
1802 if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
3253
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
1803 old_ground = GB(_m[tile].m4, 0, 4);
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
1804 } else {
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
1805 old_ground = GB(_m[tile].m2, 0, 4);
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
1806 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1807
2631
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1808 switch (_opt.landscape) {
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1809 case LT_HILLY:
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1810 if (GetTileZ(tile) > _opt.snow_line) { /* convert into snow? */
2667
ae35b513ff1b (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138 <peter1138@openttd.org>
parents: 2645
diff changeset
1811 new_ground = RAIL_GROUND_ICE_DESERT;
2631
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1812 goto modify_me;
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1813 }
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1814 break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1815
2631
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1816 case LT_DESERT:
3379
2a321b899920 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas <belugas@openttd.org>
parents: 3361
diff changeset
1817 if (GetTropicZone(tile) == TROPICZONE_DESERT) { /* convert into desert? */
2667
ae35b513ff1b (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138 <peter1138@openttd.org>
parents: 2645
diff changeset
1818 new_ground = RAIL_GROUND_ICE_DESERT;
2631
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1819 goto modify_me;
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1820 }
185528afe5bf (svn r3173) Use the trinary operator and switch to improve readability
tron <tron@openttd.org>
parents: 2626
diff changeset
1821 break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1822 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1823
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1824 // Don't continue tile loop for depots
3486
d2940b03b6ba (svn r4337) -Fix: A problem where GetRailType was called instead of GetRailTileType. Thanks to glx for noticing
celestar <celestar@openttd.org>
parents: 3483
diff changeset
1825 if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) return;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1826
2667
ae35b513ff1b (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138 <peter1138@openttd.org>
parents: 2645
diff changeset
1827 new_ground = RAIL_GROUND_GREEN;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1828
2667
ae35b513ff1b (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138 <peter1138@openttd.org>
parents: 2645
diff changeset
1829 if (old_ground != RAIL_GROUND_BROWN) { /* wait until bottom is green */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1830 /* determine direction of fence */
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1831 TrackBits rail = GetTrackBits(tile);
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1832
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1833 switch (rail) {
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1834 case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1835 case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1836 case TRACK_BIT_LEFT: new_ground = RAIL_GROUND_FENCE_VERT1; break;
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1837 case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2; break;
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1838
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1839 default: {
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1840 PlayerID owner = GetTileOwner(tile);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1841
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1842 if (rail == (TRACK_BIT_LOWER | TRACK_BIT_RIGHT) || (
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1843 (rail & TRACK_BIT_3WAY_NW) == 0 &&
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1844 (rail & TRACK_BIT_X)
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1845 )) {
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1846 TileIndex n = tile + TileDiffXY(0, -1);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1847
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1848 if (!IsTileType(n, MP_RAILWAY) ||
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1849 !IsTileOwner(n, owner) ||
2841
03a4b5997078 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron <tron@openttd.org>
parents: 2839
diff changeset
1850 (_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_UPPER ||
03a4b5997078 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron <tron@openttd.org>
parents: 2839
diff changeset
1851 (_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LEFT) {
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1852 new_ground = RAIL_GROUND_FENCE_NW;
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1853 }
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1854 }
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1855
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1856 if (rail == (TRACK_BIT_UPPER | TRACK_BIT_LEFT) || (
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1857 (rail & TRACK_BIT_3WAY_SE) == 0 &&
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1858 (rail & TRACK_BIT_X)
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1859 )) {
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1860 TileIndex n = tile + TileDiffXY(0, 1);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1861
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1862 if (!IsTileType(n, MP_RAILWAY) ||
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1863 !IsTileOwner(n, owner) ||
2841
03a4b5997078 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron <tron@openttd.org>
parents: 2839
diff changeset
1864 (_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LOWER ||
03a4b5997078 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron <tron@openttd.org>
parents: 2839
diff changeset
1865 (_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_RIGHT) {
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1866 new_ground = (new_ground == RAIL_GROUND_FENCE_NW) ?
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1867 RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1868 }
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1869 }
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1870
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1871 if (rail == (TRACK_BIT_LOWER | TRACK_BIT_LEFT) || (
3258
124bcfb458ac (svn r3946) Add short hand names for common track combinations
tron <tron@openttd.org>
parents: 3254
diff changeset
1872 (rail & TRACK_BIT_3WAY_NE) == 0 &&
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1873 (rail & TRACK_BIT_Y)
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1874 )) {
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1875 TileIndex n = tile + TileDiffXY(-1, 0);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1876
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1877 if (!IsTileType(n, MP_RAILWAY) ||
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1878 !IsTileOwner(n, owner) ||
2841
03a4b5997078 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron <tron@openttd.org>
parents: 2839
diff changeset
1879 (_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_UPPER ||
03a4b5997078 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron <tron@openttd.org>
parents: 2839
diff changeset
1880 (_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_RIGHT) {
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1881 new_ground = RAIL_GROUND_FENCE_NE;
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1882 }
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1883 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1884
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1885 if (rail == (TRACK_BIT_UPPER | TRACK_BIT_RIGHT) || (
3265
1a85116cb8f8 (svn r3976) Fix typo in r3946
tron <tron@openttd.org>
parents: 3258
diff changeset
1886 (rail & TRACK_BIT_3WAY_SW) == 0 &&
3102
bef483a4087b (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron <tron@openttd.org>
parents: 3101
diff changeset
1887 (rail & TRACK_BIT_Y)
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1888 )) {
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1889 TileIndex n = tile + TileDiffXY(1, 0);
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1890
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1891 if (!IsTileType(n, MP_RAILWAY) ||
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1892 !IsTileOwner(n, owner) ||
2841
03a4b5997078 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron <tron@openttd.org>
parents: 2839
diff changeset
1893 (_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LOWER ||
03a4b5997078 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron <tron@openttd.org>
parents: 2839
diff changeset
1894 (_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LEFT) {
2839
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1895 new_ground = (new_ground == RAIL_GROUND_FENCE_NE) ?
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1896 RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1897 }
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1898 }
dc3fa77c706e (svn r3387) Restructure the code, which places fences along railroad tracks.
tron <tron@openttd.org>
parents: 2821
diff changeset
1899 break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1900 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1901 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1902 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1903
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1904 modify_me:;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1905 /* tile changed? */
2667
ae35b513ff1b (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138 <peter1138@openttd.org>
parents: 2645
diff changeset
1906 if (old_ground != new_ground) {
3253
b9f606f8e4e2 (svn r3941) Get rid of RAIL_TYPE_SPECIAL
tron <tron@openttd.org>
parents: 3242
diff changeset
1907 if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
2670
91c99ca703f7 (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138 <peter1138@openttd.org>
parents: 2668
diff changeset
1908 SB(_m[tile].m4, 0, 4, new_ground);
91c99ca703f7 (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138 <peter1138@openttd.org>
parents: 2668
diff changeset
1909 } else {
91c99ca703f7 (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138 <peter1138@openttd.org>
parents: 2668
diff changeset
1910 SB(_m[tile].m2, 0, 4, new_ground);
91c99ca703f7 (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138 <peter1138@openttd.org>
parents: 2668
diff changeset
1911 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1912 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1913 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1914 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1915
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1916
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
1917 static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
1918 {
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1919 byte a;
817
a3fae649752e (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight <truelight@openttd.org>
parents: 679
diff changeset
1920 uint16 b;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1921
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1922 if (mode != TRANSPORT_RAIL) return 0;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1923
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1924 if (GetRailTileType(tile) != RAIL_TYPE_DEPOT_WAYPOINT) {
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1925 TrackBits rails = GetTrackBits(tile);
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1926 uint32 ret = rails * 0x101;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1927
3254
a37df42306fa (svn r3942) GetRailType() != GetRailTileType(), fix r3941
tron <tron@openttd.org>
parents: 3253
diff changeset
1928 if (GetRailTileType(tile) != RAIL_TYPE_SIGNALS) {
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1929 if (rails == TRACK_BIT_CROSS) ret |= 0x40;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1930 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1931 /* has_signals */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1932
2049
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
1933 a = _m[tile].m3;
bdf8cbd61542 (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 <tron@openttd.org>
parents: 2020
diff changeset
1934 b = _m[tile].m2;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1935
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1936 b &= a;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1937
22
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
1938 /* When signals are not present (in neither
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
1939 * direction), we pretend them to be green. (So if
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
1940 * signals are only one way, the other way will
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
1941 * implicitely become `red' */
2549
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1942 if ((a & 0xC0) == 0) b |= 0xC0;
9f3bb9a2c335 (svn r3078) Some more stuff, which piled up:
tron <tron@openttd.org>
parents: 2548
diff changeset
1943 if ((a & 0x30) == 0) b |= 0x30;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1944
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1945 if ((b & 0x80) == 0) ret |= 0x10070000;
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1946 if ((b & 0x40) == 0) ret |= 0x07100000;
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1947 if ((b & 0x20) == 0) ret |= 0x20080000;
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
1948 if ((b & 0x10) == 0) ret |= 0x08200000;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1949 }
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1950 return ret;
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1951 } else {
3269
9f6f208b2ff6 (svn r3981) More work for the rail accessing functions and enums
tron <tron@openttd.org>
parents: 3267
diff changeset
1952 if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
3270
8ffc69611786 (svn r3982) Fix last commit. I got confused by some strange test, which did nothing
tron <tron@openttd.org>
parents: 3269
diff changeset
1953 return (DiagDirToAxis(GetRailDepotDirection(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
3269
9f6f208b2ff6 (svn r3981) More work for the rail accessing functions and enums
tron <tron@openttd.org>
parents: 3267
diff changeset
1954 } else {
3267
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1955 return GetRailWaypointBits(tile) * 0x101;
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1956 }
da7cf76701b2 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron <tron@openttd.org>
parents: 3265
diff changeset
1957 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1958 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1959
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
1960 static void ClickTile_Track(TileIndex tile)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1961 {
2548
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
1962 if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1963 ShowTrainDepotWindow(tile);
2668
fff094d64d05 (svn r3210) -Codechange: use IsRailWaypoint where possible (instead of magicnumbers)
truelight <truelight@openttd.org>
parents: 2667
diff changeset
1964 } else if (IsRailWaypoint(tile)) {
1542
c7c10abeede3 (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight <truelight@openttd.org>
parents: 1536
diff changeset
1965 ShowRenameWaypointWindow(GetWaypointByTile(tile));
2548
1628110c9dcf (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron <tron@openttd.org>
parents: 2544
diff changeset
1966 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1967 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1968
1590
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1969 static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1970 {
1901
74e0d3101dfb (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron <tron@openttd.org>
parents: 1891
diff changeset
1971 td->owner = GetTileOwner(tile);
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
1972 switch (GetRailTileType(tile)) {
1590
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1973 case RAIL_TYPE_NORMAL:
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1974 td->str = STR_1021_RAILROAD_TRACK;
1590
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1975 break;
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1976
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1977 case RAIL_TYPE_SIGNALS: {
2916
9f16688176a1 (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater <Darkvater@openttd.org>
parents: 2911
diff changeset
1978 const StringID signal_type[] = {
1590
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1979 STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS,
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1980 STR_RAILROAD_TRACK_WITH_PRESIGNALS,
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1981 STR_RAILROAD_TRACK_WITH_EXITSIGNALS,
2916
9f16688176a1 (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater <Darkvater@openttd.org>
parents: 2911
diff changeset
1982 STR_RAILROAD_TRACK_WITH_COMBOSIGNALS
1590
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1983 };
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1984
3238
9b75d6e4b9d4 (svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron <tron@openttd.org>
parents: 3237
diff changeset
1985 td->str = signal_type[GetSignalType(tile)];
1590
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1986 break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1987 }
1590
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1988
1942
1e42db2f8fbe (svn r2448) General cleanup of rail related code, more to follow.
matthijs <matthijs@openttd.org>
parents: 1928
diff changeset
1989 case RAIL_TYPE_DEPOT_WAYPOINT:
1590
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1990 default:
3269
9f6f208b2ff6 (svn r3981) More work for the rail accessing functions and enums
tron <tron@openttd.org>
parents: 3267
diff changeset
1991 td->str = (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) ?
1590
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1992 STR_1023_RAILROAD_TRAIN_DEPOT : STR_LANDINFO_WAYPOINT;
e571260c00e6 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron <tron@openttd.org>
parents: 1555
diff changeset
1993 break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1994 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1995 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1996
2436
027bdc04f0ed (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater <Darkvater@openttd.org>
parents: 2425
diff changeset
1997 static void ChangeTileOwner_Track(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1998 {
1901
74e0d3101dfb (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron <tron@openttd.org>
parents: 1891
diff changeset
1999 if (!IsTileOwner(tile, old_player)) return;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
2000
2502
60a6c14d4460 (svn r3028) s/255/OWNER_SPECTATOR/
tron <tron@openttd.org>
parents: 2499
diff changeset
2001 if (new_player != OWNER_SPECTATOR) {
1902
8088638e7d4f (svn r2408) Introduce SetTileOwner() and use it
tron <tron@openttd.org>
parents: 1901
diff changeset
2002 SetTileOwner(tile, new_player);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2003 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2004 DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2005 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2006 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2007
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2008 static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2009 static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
1922
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2010 static const byte _deltacoord_leaveoffset[8] = {
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2011 -1, 0, 1, 0, /* x */
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2012 0, 1, 0, -1 /* y */
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2013 };
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2014
1977
77a4977c3286 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron <tron@openttd.org>
parents: 1963
diff changeset
2015 static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2016 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2017 byte fract_coord;
1922
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2018 byte fract_coord_leave;
3157
c4114a2e86c5 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron <tron@openttd.org>
parents: 3154
diff changeset
2019 DiagDirection dir;
1922
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2020 int length;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
2021
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2022 // this routine applies only to trains in depot tiles
2639
b66c6908e22b (svn r3181) -Bracing
tron <tron@openttd.org>
parents: 2631
diff changeset
2023 if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2024
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2025 /* depot direction */
3185
a3376cc074ba (svn r3831) Add and use GetRailDepotDirection()
tron <tron@openttd.org>
parents: 3184
diff changeset
2026 dir = GetRailDepotDirection(tile);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
2027
1922
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2028 /* calculate the point where the following wagon should be activated */
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2029 /* this depends on the length of the current vehicle */
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2030 length = v->u.rail.cached_veh_length;
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2031
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2032 fract_coord_leave =
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2033 ((_fractcoords_enter[dir] & 0x0F) + // x
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2034 (length + 1) * _deltacoord_leaveoffset[dir]) +
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2035 (((_fractcoords_enter[dir] >> 4) + // y
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2036 ((length + 1) * _deltacoord_leaveoffset[dir+4])) << 4);
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2037
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2038 fract_coord = (x & 0xF) + ((y & 0xF) << 4);
1922
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2039
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2040 if (_fractcoords_behind[dir] == fract_coord) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2041 /* make sure a train is not entering the tile from behind */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2042 return 8;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2043 } else if (_fractcoords_enter[dir] == fract_coord) {
3157
c4114a2e86c5 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron <tron@openttd.org>
parents: 3154
diff changeset
2044 if (DiagDirToDir(ReverseDiagDir(dir)) == v->direction) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2045 /* enter the depot */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2046 v->u.rail.track = 0x80,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2047 v->vehstatus |= VS_HIDDEN; /* hide it */
3157
c4114a2e86c5 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron <tron@openttd.org>
parents: 3154
diff changeset
2048 v->direction = ReverseDir(v->direction);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2049 if (v->next == NULL)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2050 TrainEnterDepot(v, tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2051 v->tile = tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2052 InvalidateWindow(WC_VEHICLE_DEPOT, tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2053 return 4;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2054 }
1922
71fe89d907bf (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid <hackykid@openttd.org>
parents: 1903
diff changeset
2055 } else if (fract_coord_leave == fract_coord) {
3157
c4114a2e86c5 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron <tron@openttd.org>
parents: 3154
diff changeset
2056 if (DiagDirToDir(dir) == v->direction) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2057 /* leave the depot? */
2951
e7117f7ca7e6 (svn r3510) Fiddle with whitespace and parentheses
tron <tron@openttd.org>
parents: 2934
diff changeset
2058 if ((v = v->next) != NULL) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2059 v->vehstatus &= ~VS_HIDDEN;
3483
67144af97951 (svn r4332) Turn a table lookup into a ternary operator
tron <tron@openttd.org>
parents: 3435
diff changeset
2060 v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2061 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2062 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2063 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2064
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2065 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2066 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2067
1093
5029c37a31c0 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron <tron@openttd.org>
parents: 1084
diff changeset
2068 void InitializeRail(void)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2069 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2070 _last_built_train_depot_tile = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2071 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2072
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2073 const TileTypeProcs _tile_type_rail_procs = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2074 DrawTile_Track, /* draw_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2075 GetSlopeZ_Track, /* get_slope_z_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2076 ClearTile_Track, /* clear_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2077 GetAcceptedCargo_Track, /* get_accepted_cargo_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2078 GetTileDesc_Track, /* get_tile_desc_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2079 GetTileTrackStatus_Track, /* get_tile_track_status_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2080 ClickTile_Track, /* click_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2081 AnimateTile_Track, /* animate_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2082 TileLoop_Track, /* tile_loop_clear */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2083 ChangeTileOwner_Track, /* change_tile_owner_clear */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2084 NULL, /* get_produced_cargo_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2085 VehicleEnter_Track, /* vehicle_enter_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2086 NULL, /* vehicle_leave_tile_proc */
39
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
2087 GetSlopeTileh_Track, /* get_slope_tileh_proc */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2088 };