* 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 */
| 360 | * @return the cost of this operation or an error |
| 361 | */ |
| 362 | CommandCost 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 | |
| 396 | void RoadVehicle::MarkDirty() |
nothing calls this directly
no test coverage detected