* Get the stop location of (the center) of the front vehicle of a train at * a platform of a station. * @param station_id the ID of the station where we're stopping * @param tile the tile where the vehicle currently is * @param v the vehicle to get the stop location of * @param station_ahead 'return' the amount of 1/16th tiles in front of the train * @param statio
| 261 | * @return the location, calculated from the begin of the station to stop at. |
| 262 | */ |
| 263 | int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length) |
| 264 | { |
| 265 | const Station *st = Station::Get(station_id); |
| 266 | *station_ahead = st->GetPlatformLength(tile, DirToDiagDir(v->direction)) * TILE_SIZE; |
| 267 | *station_length = st->GetPlatformLength(tile) * TILE_SIZE; |
| 268 | |
| 269 | /* Default to the middle of the station for stations stops that are not in |
| 270 | * the order list like intermediate stations when non-stop is disabled */ |
| 271 | OrderStopLocation osl = OrderStopLocation::Middle; |
| 272 | if (v->gcache.cached_total_length >= *station_length) { |
| 273 | /* The train is longer than the station, make it stop at the far end of the platform */ |
| 274 | osl = OrderStopLocation::FarEnd; |
| 275 | } else if (v->current_order.IsType(OT_GOTO_STATION) && v->current_order.GetDestination() == station_id) { |
| 276 | osl = v->current_order.GetStopLocation(); |
| 277 | } |
| 278 | |
| 279 | /* The stop location of the FRONT! of the train */ |
| 280 | int stop; |
| 281 | switch (osl) { |
| 282 | default: NOT_REACHED(); |
| 283 | |
| 284 | case OrderStopLocation::NearEnd: |
| 285 | stop = v->gcache.cached_total_length; |
| 286 | break; |
| 287 | |
| 288 | case OrderStopLocation::Middle: |
| 289 | stop = *station_length - (*station_length - v->gcache.cached_total_length) / 2; |
| 290 | break; |
| 291 | |
| 292 | case OrderStopLocation::FarEnd: |
| 293 | stop = *station_length; |
| 294 | break; |
| 295 | } |
| 296 | |
| 297 | /* Subtract half the front vehicle length of the train so we get the real |
| 298 | * stop location of the train. */ |
| 299 | return stop - (v->gcache.cached_veh_length + 1) / 2; |
| 300 | } |
| 301 | |
| 302 | |
| 303 | /** |
no test coverage detected