MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / RoadVehLeaveDepot

Function RoadVehLeaveDepot

src/roadveh_cmd.cpp:1010–1056  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1008#include "table/roadveh_movement.h"
1009
1010bool 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
1058static Trackdir FollowPreviousRoadVehicle(const RoadVehicle *v, const RoadVehicle *prev, TileIndex tile, DiagDirection entry_dir, bool already_reversed)
1059{

Callers 3

RoadVehControllerFunction · 0.85
AfterLoadGameFunction · 0.85

Calls 15

GetRoadDepotDirectionFunction · 0.85
DiagDirToDirFunction · 0.85
DiagDirToDiagTrackdirFunction · 0.85
GetRoadTramTypeFunction · 0.85
TileXFunction · 0.85
TileYFunction · 0.85
VehicleEnterDepotFunction · 0.85
RoadVehFindCloseToFunction · 0.85
VehicleServiceInDepotFunction · 0.85
StartRoadVehSoundFunction · 0.85
IsTypeMethod · 0.80
LeaveUnbunchingDepotMethod · 0.80

Tested by

no test coverage detected