160 Station *st = NULL; |
160 Station *st = NULL; |
161 |
161 |
162 /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
162 /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
163 * TODO - This is just a temporary stage, this will be removed. */ |
163 * TODO - This is just a temporary stage, this will be removed. */ |
164 for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) { |
164 for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) { |
165 if (!IsValidStation(st)) { |
165 if (!st->IsValid()) { |
166 StationID index = st->index; |
166 StationID index = st->index; |
167 |
167 |
168 memset(st, 0, sizeof(Station)); |
168 memset(st, 0, sizeof(Station)); |
169 st->index = index; |
169 st->index = index; |
170 return st; |
170 return st; |
177 _error_message = STR_3008_TOO_MANY_STATIONS_LOADING; |
177 _error_message = STR_3008_TOO_MANY_STATIONS_LOADING; |
178 return NULL; |
178 return NULL; |
179 } |
179 } |
180 |
180 |
181 |
181 |
|
182 /** Obtain the length of a platform |
|
183 * @pre tile must be a railway station tile |
|
184 * @param tile A tile that contains the platform in question |
|
185 * @returns The length of the platform |
|
186 */ |
|
187 uint Station::GetPlatformLength(TileIndex tile) const |
|
188 { |
|
189 TileIndex t; |
|
190 TileIndexDiff delta; |
|
191 uint len = 0; |
|
192 assert(TileBelongsToRailStation(tile)); |
|
193 |
|
194 delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
|
195 |
|
196 t = tile; |
|
197 do { |
|
198 t -= delta; |
|
199 len++; |
|
200 } while (IsCompatibleTrainStationTile(t, tile)); |
|
201 |
|
202 t = tile; |
|
203 do { |
|
204 t += delta; |
|
205 len++; |
|
206 } while (IsCompatibleTrainStationTile(t, tile)); |
|
207 |
|
208 return len - 1; |
|
209 } |
|
210 |
|
211 /** Determines the REMAINING length of a platform, starting at (and including) |
|
212 * the given tile. |
|
213 * @param tile the tile from which to start searching. Must be a railway station tile |
|
214 * @param dir The direction in which to search. |
|
215 * @return The platform length |
|
216 */ |
|
217 uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const |
|
218 { |
|
219 TileIndex start_tile = tile; |
|
220 uint length = 0; |
|
221 assert(IsRailwayStationTile(tile)); |
|
222 assert(dir < DIAGDIR_END); |
|
223 |
|
224 do { |
|
225 length ++; |
|
226 tile += TileOffsByDiagDir(dir); |
|
227 } while (IsCompatibleTrainStationTile(tile, start_tile)); |
|
228 |
|
229 return length; |
|
230 } |
|
231 |
182 /** Determines whether a station is a buoy only. |
232 /** Determines whether a station is a buoy only. |
183 * @todo Ditch this encoding of buoys |
233 * @todo Ditch this encoding of buoys |
184 */ |
234 */ |
185 bool Station::IsBuoy() const |
235 bool Station::IsBuoy() const |
186 { |
236 { |
187 return (this->had_vehicle_of_type & HVOT_BUOY) != 0; |
237 return (had_vehicle_of_type & HVOT_BUOY) != 0; |
|
238 } |
|
239 |
|
240 /** Determines whether a station exists |
|
241 * @todo replace 0 by INVALID_TILE |
|
242 */ |
|
243 bool Station::IsValid() const |
|
244 { |
|
245 return xy != 0; |
188 } |
246 } |
189 |
247 |
190 |
248 |
191 /************************************************************************/ |
249 /************************************************************************/ |
192 /* StationRect implementation */ |
250 /* StationRect implementation */ |
435 /** Determines whether a RoadStop is a valid (i.e. existing) one */ |
493 /** Determines whether a RoadStop is a valid (i.e. existing) one */ |
436 bool RoadStop::IsValid() const |
494 bool RoadStop::IsValid() const |
437 { |
495 { |
438 return xy != INVALID_TILE; |
496 return xy != INVALID_TILE; |
439 } |
497 } |
|
498 |
|
499 /** Checks whether there is a free bay in this road stop */ |
|
500 bool RoadStop::HasFreeBay() const |
|
501 { |
|
502 return GB(status, 0, MAX_BAY_COUNT) != 0; |
|
503 } |
|
504 |
|
505 /** |
|
506 * Allocates a bay |
|
507 * @return the allocated bay number |
|
508 * @pre this->HasFreeBay() |
|
509 */ |
|
510 uint RoadStop::AllocateBay() |
|
511 { |
|
512 assert(HasFreeBay()); |
|
513 |
|
514 /* Find the first free bay. If the bit is set, the bay is free. */ |
|
515 uint bay_nr = 0; |
|
516 while (!HASBIT(status, bay_nr)) bay_nr++; |
|
517 |
|
518 CLRBIT(status, bay_nr); |
|
519 return bay_nr; |
|
520 } |
|
521 |
|
522 /** |
|
523 * Frees the given bay |
|
524 * @param nr the number of the bay to free |
|
525 */ |
|
526 void RoadStop::FreeBay(uint nr) |
|
527 { |
|
528 assert(nr < MAX_BAY_COUNT); |
|
529 SETBIT(status, nr); |
|
530 } |
|
531 |
|
532 |
|
533 /** Checks whether the entrance of the road stop is occupied by a vehicle */ |
|
534 bool RoadStop::IsEntranceBusy() const |
|
535 { |
|
536 return HASBIT(status, 7); |
|
537 } |
|
538 |
|
539 /** Makes an entrance occupied or free */ |
|
540 void RoadStop::SetEntranceBusy(bool busy) |
|
541 { |
|
542 SB(status, 7, 1, busy); |
|
543 } |