OpenTTD
Macros | Functions
order_func.h File Reference

Functions related to orders. More...

#include "order_type.h"
#include "vehicle_type.h"
#include "company_type.h"

Go to the source code of this file.

Macros

#define MIN_SERVINT_PERCENT   5
 
#define MAX_SERVINT_PERCENT   90
 
#define MIN_SERVINT_DAYS   30
 
#define MAX_SERVINT_DAYS   800
 

Functions

void RemoveOrderFromAllVehicles (OrderType type, DestinationID destination)
 Removes an order from all vehicles. More...
 
void InvalidateVehicleOrder (const Vehicle *v, int data)
 Updates the widgets of a vehicle which contains the order-data. More...
 
void CheckOrders (const Vehicle *)
 Check the orders of a vehicle, to see if there are invalid orders and stuff. More...
 
void DeleteVehicleOrders (Vehicle *v, bool keep_orderlist=false, bool reset_order_indices=true)
 Delete all orders from a vehicle. More...
 
bool ProcessOrders (Vehicle *v)
 Handle the orders of a vehicle and determine the next place to go to if needed. More...
 
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. More...
 
VehicleOrderID ProcessConditionalOrder (const Order *order, const Vehicle *v)
 Process a conditional order and determine the next order. More...
 
uint GetOrderDistance (const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth=0)
 Get the distance between two orders of a vehicle. More...
 
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. More...
 
uint16 GetServiceIntervalClamped (uint interval, bool ispercent)
 Clamp the service interval to the correct min/max. More...
 

Detailed Description

Functions related to orders.

Definition in file order_func.h.

Function Documentation

◆ CheckOrders()

void CheckOrders ( const Vehicle v)

Check the orders of a vehicle, to see if there are invalid orders and stuff.

Definition at line 1762 of file order_cmd.cpp.

References _local_company, _settings_client, Vehicle::day_counter, Vehicle::FirstShared(), ClientSettings::gui, INVALID_STRING_ID, GUISettings::order_review_system, Vehicle::owner, Vehicle::vehstatus, VS_CRASHED, and VS_STOPPED.

Referenced by Aircraft::OnNewDay().

◆ DeleteVehicleOrders()

void DeleteVehicleOrders ( Vehicle v,
bool  keep_orderlist,
bool  reset_order_indices 
)

Delete all orders from a vehicle.

Parameters
vVehicle whose orders to reset
keep_orderlistIf true, do not free the order list, only empty it.
reset_order_indicesIf 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 1925 of file order_cmd.cpp.

References BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::current_order, DeleteOrderWarnings(), OrderList::FreeChain(), Vehicle::IsOrderListShared(), Order::IsType(), Vehicle::list, Vehicle::orders, and Vehicle::RemoveFromShared().

Referenced by CmdSellRailWagon(), and DecloneOrder().

◆ DrawOrderString()

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.

Parameters
vVehicle the order belongs to
orderThe order to draw
order_indexIndex of the order in the orders of the vehicle
yY position for drawing
selectedTrue, if the order is selected
timetableTrue, when drawing in the timetable GUI
leftLeft border for text drawing
middleX position between order index and order text
rightRight border for text drawing

Definition at line 213 of file order_gui.cpp.

◆ GetOrderDistance()

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.

Parameters
prevOrigin order.
curDestination order.
vThe vehicle to get the distance for.
conditional_depthInternal param for resolving conditional orders.
Returns
Maximum distance between the two orders.

Definition at line 697 of file order_cmd.cpp.

References Order::IsType().

◆ GetServiceIntervalClamped()

uint16 GetServiceIntervalClamped ( uint  interval,
bool  ispercent 
)

Clamp the service interval to the correct min/max.

The actual min/max values depend on whether it's in percent or days.

Parameters
intervalproposed service interval
company_idthe owner of the vehicle
Returns
Clamped service interval

Definition at line 1954 of file order_cmd.cpp.

References Clamp().

Referenced by CmdChangeServiceInt(), VehicleDetailsWindow::OnClick(), and VehicleDetailsWindow::OnDropdownSelect().

◆ InvalidateVehicleOrder()

void InvalidateVehicleOrder ( const Vehicle v,
int  data 
)

◆ ProcessConditionalOrder()

VehicleOrderID ProcessConditionalOrder ( const Order order,
const Vehicle v 
)

Process a conditional order and determine the next order.

Parameters
orderthe order the vehicle currently has
vthe vehicle to update
Returns
index of next order to jump to, or INVALID_VEH_ORDER_ID to use the next order

Definition at line 2010 of file order_cmd.cpp.

References Order::GetType().

◆ ProcessOrders()

bool ProcessOrders ( Vehicle v)

Handle the orders of a vehicle and determine the next place to go to if needed.

Parameters
vthe vehicle to do this for.
Returns
true if the vehicle is eligible for reversing (basically only when leaving a station).

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 2160 of file order_cmd.cpp.

References Vehicle::current_order, and Order::GetType().

◆ RemoveOrderFromAllVehicles()

void RemoveOrderFromAllVehicles ( OrderType  type,
DestinationID  destination 
)

Removes an order from all vehicles.

Triggers when, say, a station is removed.

Parameters
typeThe type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]).
destinationThe destination. Can be a StationID, DepotID or WaypointID.

Definition at line 1837 of file order_cmd.cpp.

References Vehicle::current_order, FOR_ALL_VEHICLES, Order::IsType(), BaseVehicle::type, and VEH_AIRCRAFT.

Referenced by Depot::~Depot().

◆ UpdateOrderDest()

bool UpdateOrderDest ( Vehicle v,
const Order order,
int  conditional_depth,
bool  pbs_look_ahead 
)

Update the vehicle's destination tile from an order.

Parameters
orderthe order the vehicle currently has
vthe vehicle to update
conditional_depththe depth (amount of steps) to go with conditional orders. This to prevent infinite loops.
pbs_look_aheadWhether we are forecasting orders for pbs reservations in advance. If true, the order indices must not be modified.

Definition at line 2039 of file order_cmd.cpp.

References Vehicle::current_order, Vehicle::dest_tile, Order::Free(), Vehicle::GetNumOrders(), and Order::GetType().