OpenTTD Source 20241224-master-gee860a5c8e
|
Functions related to orders. More...
Go to the source code of this file.
Functions | |
void | RemoveOrderFromAllVehicles (OrderType type, DestinationID destination, bool hangar=false) |
Removes an order from all vehicles. | |
void | InvalidateVehicleOrder (const Vehicle *v, int data) |
Updates the widgets of a vehicle which contains the order-data. | |
void | CheckOrders (const Vehicle *) |
Check the orders of a vehicle, to see if there are invalid orders and stuff. | |
void | DeleteVehicleOrders (Vehicle *v, bool keep_orderlist=false, bool reset_order_indices=true) |
Delete all orders from a vehicle. | |
bool | ProcessOrders (Vehicle *v) |
Handle the orders of a vehicle and determine the next place to go to if needed. | |
bool | UpdateOrderDest (Vehicle *v, const Order *order, int conditional_depth=0, bool pbs_look_ahead=false) |
Update the vehicle's destination tile from an order. | |
VehicleOrderID | ProcessConditionalOrder (const Order *order, const Vehicle *v) |
Process a conditional order and determine the next order. | |
uint | GetOrderDistance (const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth=0) |
Get the distance between two orders of a vehicle. | |
void | DrawOrderString (const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right) |
Draws an order in order or timetable GUI. | |
uint16_t | GetServiceIntervalClamped (int interval, bool ispercent) |
Clamp the service interval to the correct min/max. | |
Variables | |
static const uint | DEF_SERVINT_DAYS_TRAINS = 150 |
static const uint | DEF_SERVINT_DAYS_ROADVEH = 150 |
static const uint | DEF_SERVINT_DAYS_AIRCRAFT = 100 |
static const uint | DEF_SERVINT_DAYS_SHIPS = 360 |
static const uint | MIN_SERVINT_DAYS = 30 |
static const uint | MAX_SERVINT_DAYS = 800 |
static const uint | DEF_SERVINT_MINUTES_TRAINS = 5 |
static const uint | DEF_SERVINT_MINUTES_ROADVEH = 5 |
static const uint | DEF_SERVINT_MINUTES_AIRCRAFT = 3 |
static const uint | DEF_SERVINT_MINUTES_SHIPS = 12 |
static const uint | MIN_SERVINT_MINUTES = 1 |
static const uint | MAX_SERVINT_MINUTES = 30 |
static const uint | DEF_SERVINT_PERCENT = 50 |
static const uint | MIN_SERVINT_PERCENT = 5 |
static const uint | MAX_SERVINT_PERCENT = 90 |
Functions related to orders.
Definition in file order_func.h.
void CheckOrders | ( | const Vehicle * | v | ) |
Check the orders of a vehicle, to see if there are invalid orders and stuff.
Definition at line 1711 of file order_cmd.cpp.
References _cheats, _local_company, _settings_client, AddVehicleAdviceNewsItem(), Station::airport, CanVehicleUseStation(), Vehicle::day_counter, Vehicle::engine_type, Order::Equals(), Vehicle::FirstShared(), AirportFTAClass::flags, SpecializedStation< Station, false >::Get(), OrderList::GetFirstOrder(), Airport::GetFTA(), Vehicle::GetLastOrder(), Vehicle::GetNumOrders(), ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_STRING_ID, Cheats::no_jetcrash, GUISettings::order_review_system, Vehicle::orders, Vehicle::Orders(), Vehicle::owner, SetDParam(), AirportFTAClass::SHORT_STRIP, AircraftVehicleInfo::subtype, BaseVehicle::type, Cheat::value, VEH_AIRCRAFT, Vehicle::vehstatus, VS_CRASHED, and VS_STOPPED.
Referenced by Aircraft::OnNewEconomyDay(), RoadVehicle::OnNewEconomyDay(), Ship::OnNewEconomyDay(), and Train::OnNewEconomyDay().
void DeleteVehicleOrders | ( | Vehicle * | v, |
bool | keep_orderlist, | ||
bool | reset_order_indices | ||
) |
Delete all orders from a vehicle.
v | Vehicle whose orders to reset |
keep_orderlist | If true, do not free the order list, only empty it. |
reset_order_indices | If true, reset cur_implicit_order_index and cur_real_order_index and cancel the current full load order (if the vehicle is loading). If false, you have to make sure the order indices are valid after your messing with them! |
Definition at line 1869 of file order_cmd.cpp.
References CancelLoadingDueToDeletedOrder(), BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::current_order, DeleteOrderWarnings(), OrderList::FreeChain(), Vehicle::IsOrderListShared(), Order::IsType(), Vehicle::orders, Vehicle::RemoveFromShared(), and BaseConsist::ResetDepotUnbunching().
Referenced by CmdCloneOrder(), CmdMoveRailVehicle(), CmdSellRailWagon(), DecloneOrder(), and Vehicle::PreDestructor().
void DrawOrderString | ( | const Vehicle * | v, |
const Order * | order, | ||
int | order_index, | ||
int | y, | ||
bool | selected, | ||
bool | timetable, | ||
int | left, | ||
int | middle, | ||
int | right | ||
) |
Draws an order in order or timetable GUI.
v | Vehicle the order belongs to |
order | The order to draw |
order_index | Index of the order in the orders of the vehicle |
y | Y position for drawing |
selected | True, if the order is selected |
timetable | True, when drawing in the timetable GUI |
left | Left border for text drawing |
middle | X position between order index and order text |
right | Right border for text drawing |
Definition at line 214 of file order_gui.cpp.
References _current_text_dir, _settings_client, _station_load_types, CanVehicleUseStation(), ConvertSpeedToDisplaySpeed(), BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, DrawSprite(), DrawString(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), FS_NORMAL, SpecializedStation< Station, false >::Get(), CargoSpec::Get(), GetCharacterHeight(), Order::GetConditionComparator(), Order::GetConditionSkipToOrder(), Order::GetConditionValue(), Order::GetConditionVariable(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetDestination(), Vehicle::GetFirstOrder(), Order::GetLoadType(), Order::GetNonStopType(), GetOrderDistance(), Aircraft::GetRange(), Order::GetRefitCargo(), GetSpriteSize(), Order::GetStopLocation(), Order::GetType(), Order::GetUnloadType(), Order::GetWaitTime(), ClientSettings::gui, Order::IsAutoRefit(), Order::IsGotoOrder(), Vehicle::IsGroundVehicle(), Order::IsRefit(), Order::IsType(), Order::IsWaitTimetabled(), CargoSpec::name, Order::next, OCC_IS_FALSE, OCC_IS_TRUE, OCV_MAX_SPEED, OCV_UNCONDITIONALLY, ODATFB_HALT, ODATFB_NEAREST_DEPOT, ODATFB_UNBUNCH, ODTFB_SERVICE, ONSF_NO_STOP_AT_DESTINATION_STATION, ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, SA_FORCE, SA_RIGHT, SetDParam(), SetTimetableParams(), GUISettings::stop_location, TC_NO_SHADE, TD_RTL, BaseVehicle::type, VEH_AIRCRAFT, and VEH_TRAIN.
Referenced by TimetableWindow::DrawTimetablePanel(), and OrdersWindow::DrawWidget().
uint GetOrderDistance | ( | const Order * | prev, |
const Order * | cur, | ||
const Vehicle * | v, | ||
int | conditional_depth | ||
) |
Get the distance between two orders of a vehicle.
Conditional orders are resolved and the bigger distance of the two order branches is returned.
prev | Origin order. |
cur | Destination order. |
v | The vehicle to get the distance for. |
conditional_depth | Internal param for resolving conditional orders. |
Definition at line 669 of file order_cmd.cpp.
References DistanceManhattan(), DistanceSquare(), Order::GetConditionSkipToOrder(), OrderList::GetFirstOrder(), Order::GetLocation(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), GetOrderDistance(), INVALID_TILE, Order::IsType(), Order::next, Vehicle::orders, BaseVehicle::type, and VEH_AIRCRAFT.
Referenced by CheckAircraftOrderDistance(), DrawOrderString(), and GetOrderDistance().
uint16_t GetServiceIntervalClamped | ( | int | interval, |
bool | ispercent | ||
) |
Clamp the service interval to the correct min/max.
The actual min/max values depend on whether it's in days, minutes, or percent.
interval | The proposed service interval. |
ispercent | Whether the interval is a percent. |
Definition at line 1901 of file order_cmd.cpp.
References Clamp(), and TimerGameEconomy::UsingWallclockUnits().
Referenced by CmdChangeServiceInt(), VehicleDetailsWindow::OnClick(), and VehicleDetailsWindow::OnDropdownSelect().
void InvalidateVehicleOrder | ( | const Vehicle * | v, |
int | data | ||
) |
Updates the widgets of a vehicle which contains the order-data.
Definition at line 235 of file order_cmd.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), SetWindowDirty(), WC_VEHICLE_ORDERS, WC_VEHICLE_TIMETABLE, and WC_VEHICLE_VIEW.
Referenced by Vehicle::BeginLoading(), CmdCloneOrder(), CmdModifyOrder(), CmdMoveOrder(), CmdOrderRefit(), CmdSkipToOrder(), DecloneOrder(), DeleteOrder(), Vehicle::DeleteUnreachedImplicitOrders(), Vehicle::IncrementImplicitOrderIndex(), Vehicle::IncrementRealOrderIndex(), InsertOrder(), ProcessOrders(), Vehicle::RemoveFromShared(), and RemoveOrderFromAllVehicles().
VehicleOrderID ProcessConditionalOrder | ( | const Order * | order, |
const Vehicle * | v | ||
) |
Process a conditional order and determine the next order.
order | the order the vehicle currently has |
v | the vehicle to update |
Definition at line 1968 of file order_cmd.cpp.
References Vehicle::age, CalcPercentVehicleFilled(), TimerGame< struct Calendar >::DateToYear(), TimerGameConst< struct Calendar >::DAYS_IN_LEAP_YEAR, Order::GetConditionComparator(), Order::GetConditionSkipToOrder(), Order::GetConditionValue(), Order::GetConditionVariable(), Vehicle::GetDisplayMaxSpeed(), Vehicle::GetEngine(), Order::GetType(), INVALID_VEH_ORDER_ID, Vehicle::max_age, Vehicle::NeedsServicing(), OCV_AGE, OCV_LOAD_PERCENTAGE, OCV_MAX_RELIABILITY, OCV_MAX_SPEED, OCV_RELIABILITY, OCV_REMAINING_LIFETIME, OCV_REQUIRES_SERVICE, OCV_UNCONDITIONALLY, OrderConditionCompare(), Engine::reliability, Vehicle::reliability, and ToPercent16().
Referenced by VehicleOrderSaver::SwitchToNextOrder(), and UpdateOrderDest().
bool ProcessOrders | ( | Vehicle * | v | ) |
Handle the orders of a vehicle and determine the next place to go to if needed.
v | the vehicle to do this for. |
Reversing because of order change is allowed only just after leaving a station (and the difficulty setting to allowed, of course) this can be detected because only after OT_LEAVESTATION, current_order will be reset to nothing. (That also happens if no order, but in that case it won't hit the point in code where may_reverse is checked)
Definition at line 2127 of file order_cmd.cpp.
References CheckForValidOrders(), BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::current_order, Vehicle::DeleteUnreachedImplicitOrders(), Vehicle::dest_tile, Order::Equals(), Order::Free(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedStation< Station, false >::Get(), Order::GetDepotOrderType(), Order::GetDestination(), Order::GetNonStopType(), Vehicle::GetNumManualOrders(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), GetStationIndex(), Order::GetType(), GetWindowClassForVehicleType(), Vehicle::IncrementImplicitOrderIndex(), INVALID_TILE, InvalidateVehicleOrder(), IsTileType(), Order::IsType(), Vehicle::last_station_visited, MP_STATION, ODTFB_PART_OF_ORDERS, ONSF_NO_STOP_AT_DESTINATION_STATION, SetWindowClassesDirty(), Station::ship_station, OrthogonalTileArea::tile, Vehicle::tile, BaseVehicle::type, UpdateOrderDest(), Vehicle::UpdateRealOrderIndex(), UpdateVehicleTimetable(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and VIWD_MODIFY_ORDERS.
Referenced by CheckNextTrainTile().
void RemoveOrderFromAllVehicles | ( | OrderType | type, |
DestinationID | destination, | ||
bool | hangar | ||
) |
Removes an order from all vehicles.
Triggers when, say, a station is removed.
type | The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]). |
destination | The destination. Can be a StationID, DepotID or WaypointID. |
hangar | Only used for airports in the destination. When false, remove airport and hangar orders. When true, remove either airport or hangar order. |
Definition at line 1787 of file order_cmd.cpp.
References DeleteOrder(), Vehicle::FirstShared(), INVALID_VEH_ORDER_ID, InvalidateVehicleOrder(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), ODATFB_NEAREST_DEPOT, OrderBackup::RemoveOrder(), SetWindowDirty(), VEH_AIRCRAFT, and WC_VEHICLE_VIEW.
Referenced by UpdateAirplanesOnNewStation(), Depot::~Depot(), and Station::~Station().
bool UpdateOrderDest | ( | Vehicle * | v, |
const Order * | order, | ||
int | conditional_depth, | ||
bool | pbs_look_ahead | ||
) |
Update the vehicle's destination tile from an order.
order | the order the vehicle currently has |
v | the vehicle to update |
conditional_depth | the depth (amount of steps) to go with conditional orders. This to prevent infinite loops. |
pbs_look_ahead | Whether we are forecasting orders for pbs reservations in advance. If true, the order indices must not be modified. |
Definition at line 1998 of file order_cmd.cpp.
References AircraftNextAirportPos_and_Order(), BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::current_order, BaseConsist::current_order_time, TimerGameEconomy::date_fract, Ticks::DAY_TICKS, DC_EXEC, Vehicle::dest_tile, ClosestDepot::destination, Vehicle::FindClosestDepot(), FLYING, Order::Free(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedStation< Waypoint, true >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_depot_pool >::Get(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetDestination(), Vehicle::GetGroundVehicleFlags(), Vehicle::GetNumManualOrders(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), Vehicle::GetOrderStationLocation(), Aircraft::GetOrderStationLocation(), Order::GetTimetabledTravel(), Order::GetType(), GVF_SUPPRESS_IMPLICIT_ORDERS, Vehicle::IncrementRealOrderIndex(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_VEH_ORDER_ID, Vehicle::IsGroundVehicle(), Order::IsType(), Vehicle::NeedsServicing(), ODATFB_NEAREST_DEPOT, ODTFB_SERVICE, ProcessConditionalOrder(), SetBit(), Order::SetDestination(), Aircraft::state, Aircraft::targetairport, BaseVehicle::type, UpdateOrderDest(), Vehicle::UpdateRealOrderIndex(), UpdateVehicleTimetable(), VEH_AIRCRAFT, VEH_TRAIN, and BaseStation::xy.
Referenced by ProcessOrders(), VehicleOrderSaver::SwitchToNextOrder(), and UpdateOrderDest().
|
static |
Definition at line 31 of file order_func.h.
|
static |
Definition at line 30 of file order_func.h.
|
static |
Definition at line 32 of file order_func.h.
|
static |
Definition at line 29 of file order_func.h.
|
static |
Definition at line 38 of file order_func.h.
|
static |
Definition at line 37 of file order_func.h.
|
static |
Definition at line 39 of file order_func.h.
|
static |
Definition at line 36 of file order_func.h.
|
static |
Definition at line 43 of file order_func.h.
|
static |
Definition at line 34 of file order_func.h.
|
static |
Definition at line 41 of file order_func.h.
|
static |
Definition at line 45 of file order_func.h.
|
static |
Definition at line 33 of file order_func.h.
|
static |
Definition at line 40 of file order_func.h.
|
static |
Definition at line 44 of file order_func.h.