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

Function CmdTurnRoadVeh

src/roadveh_cmd.cpp:362–393  ·  view source on GitHub ↗

* Turn a roadvehicle around. * @param flags operation to perform * @param veh_id vehicle ID to turn * @return the cost of this operation or an error */

Source from the content-addressed store, hash-verified

360 * @return the cost of this operation or an error
361 */
362CommandCost CmdTurnRoadVeh(DoCommandFlags flags, VehicleID veh_id)
363{
364 RoadVehicle *v = RoadVehicle::GetIfValid(veh_id);
365 if (v == nullptr) return CMD_ERROR;
366
367 if (!v->IsPrimaryVehicle()) return CMD_ERROR;
368
369 CommandCost ret = CheckOwnership(v->owner);
370 if (ret.Failed()) return ret;
371
372 if (v->vehstatus.Any({VehState::Stopped, VehState::Crashed}) ||
373 v->breakdown_ctr != 0 ||
374 v->overtaking != 0 ||
375 v->state == RVSB_WORMHOLE ||
376 v->IsInDepot() ||
377 v->current_order.IsType(OT_LOADING)) {
378 return CMD_ERROR;
379 }
380
381 if (IsNormalRoadTile(v->tile) && GetDisallowedRoadDirections(v->tile) != DRD_NONE) return CMD_ERROR;
382
383 if (IsTileType(v->tile, MP_TUNNELBRIDGE) && DirToDiagDir(v->direction) == GetTunnelBridgeDirection(v->tile)) return CMD_ERROR;
384
385 if (flags.Test(DoCommandFlag::Execute)) {
386 v->reverse_ctr = 180;
387
388 /* Unbunching data is no longer valid. */
389 v->ResetDepotUnbunching();
390 }
391
392 return CommandCost();
393}
394
395
396void RoadVehicle::MarkDirty()

Callers

nothing calls this directly

Calls 14

CheckOwnershipFunction · 0.85
IsNormalRoadTileFunction · 0.85
IsTileTypeFunction · 0.85
DirToDiagDirFunction · 0.85
GetTunnelBridgeDirectionFunction · 0.85
CommandCostClass · 0.85
FailedMethod · 0.80
AnyMethod · 0.80
IsTypeMethod · 0.80
TestMethod · 0.80
ResetDepotUnbunchingMethod · 0.80

Tested by

no test coverage detected