| 1008 | #include "table/roadveh_movement.h" |
| 1009 | |
| 1010 | bool RoadVehLeaveDepot(RoadVehicle *v, bool first) |
| 1011 | { |
| 1012 | /* Don't leave unless v and following wagons are in the depot. */ |
| 1013 | for (const RoadVehicle *u = v; u != nullptr; u = u->Next()) { |
| 1014 | if (u->state != RVSB_IN_DEPOT || u->tile != v->tile) return false; |
| 1015 | } |
| 1016 | |
| 1017 | DiagDirection dir = GetRoadDepotDirection(v->tile); |
| 1018 | v->direction = DiagDirToDir(dir); |
| 1019 | |
| 1020 | Trackdir tdir = DiagDirToDiagTrackdir(dir); |
| 1021 | const RoadDriveEntry *rdp = _road_drive_data[GetRoadTramType(v->roadtype)][(_settings_game.vehicle.road_side << RVS_DRIVE_SIDE) + tdir]; |
| 1022 | |
| 1023 | int x = TileX(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].x & 0xF); |
| 1024 | int y = TileY(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].y & 0xF); |
| 1025 | |
| 1026 | if (first) { |
| 1027 | /* We are leaving a depot, but have to go to the exact same one; re-enter */ |
| 1028 | if (v->current_order.IsType(OT_GOTO_DEPOT) && v->tile == v->dest_tile) { |
| 1029 | VehicleEnterDepot(v); |
| 1030 | return true; |
| 1031 | } |
| 1032 | |
| 1033 | if (RoadVehFindCloseTo(v, x, y, v->direction, false) != nullptr) return true; |
| 1034 | |
| 1035 | VehicleServiceInDepot(v); |
| 1036 | v->LeaveUnbunchingDepot(); |
| 1037 | |
| 1038 | StartRoadVehSound(v); |
| 1039 | |
| 1040 | /* Vehicle is about to leave a depot */ |
| 1041 | v->cur_speed = 0; |
| 1042 | } |
| 1043 | |
| 1044 | v->vehstatus.Reset(VehState::Hidden); |
| 1045 | v->state = tdir; |
| 1046 | v->frame = RVC_DEPOT_START_FRAME; |
| 1047 | |
| 1048 | v->x_pos = x; |
| 1049 | v->y_pos = y; |
| 1050 | v->UpdatePosition(); |
| 1051 | v->UpdateInclination(true, true); |
| 1052 | |
| 1053 | InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
| 1054 | |
| 1055 | return true; |
| 1056 | } |
| 1057 | |
| 1058 | static Trackdir FollowPreviousRoadVehicle(const RoadVehicle *v, const RoadVehicle *prev, TileIndex tile, DiagDirection entry_dir, bool already_reversed) |
| 1059 | { |
no test coverage detected