48 void PBSReserveTrack(TileIndex tile, Track track) { |
48 void PBSReserveTrack(TileIndex tile, Track track) { |
49 assert(IsValidTile(tile)); |
49 assert(IsValidTile(tile)); |
50 assert(track <= 5); |
50 assert(track <= 5); |
51 switch (GetTileType(tile)) { |
51 switch (GetTileType(tile)) { |
52 case MP_RAILWAY: |
52 case MP_RAILWAY: |
53 if ((_map5[tile] & ~1) == 0xC4) { |
53 if ((_m[tile].m5 & ~1) == 0xC4) { |
54 // waypoint |
54 // waypoint |
55 SETBIT(_map3_lo[tile], 6); |
55 SETBIT(_m[tile].m3, 6); |
56 } else { |
56 } else { |
57 // normal rail track |
57 // normal rail track |
58 byte encrt = (_map3_hi[tile] & 0xF0) >> 4; // get current encoded info (see comments at top of file) |
58 byte encrt = (_m[tile].m4 & 0xF0) >> 4; // get current encoded info (see comments at top of file) |
59 |
59 |
60 if (encrt == 0) // nothing reserved before |
60 if (encrt == 0) // nothing reserved before |
61 encrt = track + 1; |
61 encrt = track + 1; |
62 else if (encrt == (track^1) + 1) // opposite track reserved before |
62 else if (encrt == (track^1) + 1) // opposite track reserved before |
63 encrt |= 8; |
63 encrt |= 8; |
64 |
64 |
65 _map3_hi[tile] &= ~0xF0; |
65 _m[tile].m4 &= ~0xF0; |
66 _map3_hi[tile] |= encrt << 4; |
66 _m[tile].m4 |= encrt << 4; |
67 } |
67 } |
68 break; |
68 break; |
69 case MP_TUNNELBRIDGE: |
69 case MP_TUNNELBRIDGE: |
70 _map3_hi[tile] |= (1 << track) & 3; |
70 _m[tile].m4 |= (1 << track) & 3; |
71 break; |
71 break; |
72 case MP_STATION: |
72 case MP_STATION: |
73 SETBIT(_map3_lo[tile], 6); |
73 SETBIT(_m[tile].m3, 6); |
74 break; |
74 break; |
75 case MP_STREET: |
75 case MP_STREET: |
76 // make sure it is a railroad crossing |
76 // make sure it is a railroad crossing |
77 if (!IsLevelCrossing(tile)) return; |
77 if (!IsLevelCrossing(tile)) return; |
78 SETBIT(_map5[tile], 0); |
78 SETBIT(_m[tile].m5, 0); |
79 break; |
79 break; |
80 default: |
80 default: |
81 return; |
81 return; |
82 }; |
82 }; |
83 // if debugging, mark tile dirty to show reserved status |
83 // if debugging, mark tile dirty to show reserved status |
87 |
87 |
88 byte PBSTileReserved(TileIndex tile) { |
88 byte PBSTileReserved(TileIndex tile) { |
89 assert(IsValidTile(tile)); |
89 assert(IsValidTile(tile)); |
90 switch (GetTileType(tile)) { |
90 switch (GetTileType(tile)) { |
91 case MP_RAILWAY: |
91 case MP_RAILWAY: |
92 if ((_map5[tile] & ~1) == 0xC4) { |
92 if ((_m[tile].m5 & ~1) == 0xC4) { |
93 // waypoint |
93 // waypoint |
94 // check if its reserved |
94 // check if its reserved |
95 if (!HASBIT(_map3_lo[tile], 6)) return 0; |
95 if (!HASBIT(_m[tile].m3, 6)) return 0; |
96 // return the track for the correct direction |
96 // return the track for the correct direction |
97 return HASBIT(_map5[tile], 0) ? 2 : 1; |
97 return HASBIT(_m[tile].m5, 0) ? 2 : 1; |
98 } else { |
98 } else { |
99 // normal track |
99 // normal track |
100 byte res = encrt_to_reserved[(_map3_hi[tile] & 0xF0) >> 4]; |
100 byte res = encrt_to_reserved[(_m[tile].m4 & 0xF0) >> 4]; |
101 assert(res != 0xFF); |
101 assert(res != 0xFF); |
102 return res; |
102 return res; |
103 }; |
103 }; |
104 case MP_TUNNELBRIDGE: |
104 case MP_TUNNELBRIDGE: |
105 return (_map3_hi[tile] & 3); |
105 return (_m[tile].m4 & 3); |
106 case MP_STATION: |
106 case MP_STATION: |
107 // check if its reserved |
107 // check if its reserved |
108 if (!HASBIT(_map3_lo[tile], 6)) return 0; |
108 if (!HASBIT(_m[tile].m3, 6)) return 0; |
109 // return the track for the correct direction |
109 // return the track for the correct direction |
110 return HASBIT(_map5[tile], 0) ? 2 : 1; |
110 return HASBIT(_m[tile].m5, 0) ? 2 : 1; |
111 case MP_STREET: |
111 case MP_STREET: |
112 // make sure its a railroad crossing |
112 // make sure its a railroad crossing |
113 if (!IsLevelCrossing(tile)) return 0; |
113 if (!IsLevelCrossing(tile)) return 0; |
114 // check if its reserved |
114 // check if its reserved |
115 if (!HASBIT(_map5[tile], 0)) return 0; |
115 if (!HASBIT(_m[tile].m5, 0)) return 0; |
116 // return the track for the correct direction |
116 // return the track for the correct direction |
117 return HASBIT(_map5[tile], 3) ? 1 : 2; |
117 return HASBIT(_m[tile].m5, 3) ? 1 : 2; |
118 default: |
118 default: |
119 return 0; |
119 return 0; |
120 }; |
120 }; |
121 }; |
121 }; |
122 |
122 |
123 uint16 PBSTileUnavail(TileIndex tile) { |
123 uint16 PBSTileUnavail(TileIndex tile) { |
124 assert(IsValidTile(tile)); |
124 assert(IsValidTile(tile)); |
125 switch (GetTileType(tile)) { |
125 switch (GetTileType(tile)) { |
126 case MP_RAILWAY: |
126 case MP_RAILWAY: |
127 if ((_map5[tile] & ~1) == 0xC4) { |
127 if ((_m[tile].m5 & ~1) == 0xC4) { |
128 // waypoint |
128 // waypoint |
129 return HASBIT(_map3_lo[tile], 6) ? TRACKDIR_BIT_MASK : 0; |
129 return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0; |
130 } else { |
130 } else { |
131 // normal track |
131 // normal track |
132 uint16 res = encrt_to_unavail[(_map3_hi[tile] & 0xF0) >> 4]; |
132 uint16 res = encrt_to_unavail[(_m[tile].m4 & 0xF0) >> 4]; |
133 assert(res != 0xFFFF); |
133 assert(res != 0xFFFF); |
134 return res; |
134 return res; |
135 }; |
135 }; |
136 case MP_TUNNELBRIDGE: |
136 case MP_TUNNELBRIDGE: |
137 return (_map3_hi[tile] & 3) | ((_map3_hi[tile] & 3) << 8); |
137 return (_m[tile].m4 & 3) | ((_m[tile].m4 & 3) << 8); |
138 case MP_STATION: |
138 case MP_STATION: |
139 return HASBIT(_map3_lo[tile], 6) ? TRACKDIR_BIT_MASK : 0; |
139 return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0; |
140 case MP_STREET: |
140 case MP_STREET: |
141 // make sure its a railroad crossing |
141 // make sure its a railroad crossing |
142 if (!IsLevelCrossing(tile)) return 0; |
142 if (!IsLevelCrossing(tile)) return 0; |
143 // check if its reserved |
143 // check if its reserved |
144 return (HASBIT(_map5[tile], 0)) ? TRACKDIR_BIT_MASK : 0; |
144 return (HASBIT(_m[tile].m5, 0)) ? TRACKDIR_BIT_MASK : 0; |
145 default: |
145 default: |
146 return 0; |
146 return 0; |
147 }; |
147 }; |
148 }; |
148 }; |
149 |
149 |
150 void PBSClearTrack(TileIndex tile, Track track) { |
150 void PBSClearTrack(TileIndex tile, Track track) { |
151 assert(IsValidTile(tile)); |
151 assert(IsValidTile(tile)); |
152 assert(track <= 5); |
152 assert(track <= 5); |
153 switch (GetTileType(tile)) { |
153 switch (GetTileType(tile)) { |
154 case MP_RAILWAY: |
154 case MP_RAILWAY: |
155 if ((_map5[tile] & ~1) == 0xC4) { |
155 if ((_m[tile].m5 & ~1) == 0xC4) { |
156 // waypoint |
156 // waypoint |
157 CLRBIT(_map3_lo[tile], 6); |
157 CLRBIT(_m[tile].m3, 6); |
158 } else { |
158 } else { |
159 // normal rail track |
159 // normal rail track |
160 byte encrt = (_map3_hi[tile] & 0xF0) >> 4; |
160 byte encrt = (_m[tile].m4 & 0xF0) >> 4; |
161 |
161 |
162 if (encrt == track + 1) |
162 if (encrt == track + 1) |
163 encrt = 0; |
163 encrt = 0; |
164 else if (encrt == track + 1 + 8) |
164 else if (encrt == track + 1 + 8) |
165 encrt = (track^1) + 1; |
165 encrt = (track^1) + 1; |
166 else if (encrt == (track^1) + 1 + 8) |
166 else if (encrt == (track^1) + 1 + 8) |
167 encrt &= 7; |
167 encrt &= 7; |
168 |
168 |
169 _map3_hi[tile] &= ~0xF0; |
169 _m[tile].m4 &= ~0xF0; |
170 _map3_hi[tile] |= encrt << 4; |
170 _m[tile].m4 |= encrt << 4; |
171 } |
171 } |
172 break; |
172 break; |
173 case MP_TUNNELBRIDGE: |
173 case MP_TUNNELBRIDGE: |
174 _map3_hi[tile] &= ~((1 << track) & 3); |
174 _m[tile].m4 &= ~((1 << track) & 3); |
175 break; |
175 break; |
176 case MP_STATION: |
176 case MP_STATION: |
177 CLRBIT(_map3_lo[tile], 6); |
177 CLRBIT(_m[tile].m3, 6); |
178 break; |
178 break; |
179 case MP_STREET: |
179 case MP_STREET: |
180 // make sure it is a railroad crossing |
180 // make sure it is a railroad crossing |
181 if (!IsLevelCrossing(tile)) return; |
181 if (!IsLevelCrossing(tile)) return; |
182 CLRBIT(_map5[tile], 0); |
182 CLRBIT(_m[tile].m5, 0); |
183 break; |
183 break; |
184 default: |
184 default: |
185 return; |
185 return; |
186 }; |
186 }; |
187 // if debugging, mark tile dirty to show reserved status |
187 // if debugging, mark tile dirty to show reserved status |