OpenTTD
|
Handling of orders. More...
#include "stdafx.h"
#include "debug.h"
#include "cmd_helper.h"
#include "command_func.h"
#include "company_func.h"
#include "news_func.h"
#include "strings_func.h"
#include "timetable.h"
#include "vehicle_func.h"
#include "depot_base.h"
#include "core/pool_func.hpp"
#include "core/random_func.hpp"
#include "aircraft.h"
#include "roadveh.h"
#include "station_base.h"
#include "waypoint_base.h"
#include "company_base.h"
#include "order_backup.h"
#include "cheat_type.h"
#include "table/strings.h"
#include "safeguards.h"
Go to the source code of this file.
Functions | |
assert_compile (sizeof(DestinationID) >=sizeof(DepotID)) | |
void | InvalidateVehicleOrder (const Vehicle *v, int data) |
Updates the widgets of a vehicle which contains the order-data. More... | |
static bool | OrderGoesToStation (const Vehicle *v, const Order *o) |
Checks whether the order goes to a station or not, i.e. More... | |
static void | DeleteOrderWarnings (const Vehicle *v) |
Delete all news items regarding defective orders about a vehicle This could kill still valid warnings (for example about void order when just another order gets added), but assume the company will notice the problems, when (s)he's changing the orders. | |
uint | GetOrderDistance (const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth) |
Get the distance between two orders of a vehicle. More... | |
CommandCost | CmdInsertOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Add an order to the orderlist of a vehicle. More... | |
void | InsertOrder (Vehicle *v, Order *new_o, VehicleOrderID sel_ord) |
Insert a new order but skip the validation. More... | |
static CommandCost | DecloneOrder (Vehicle *dst, DoCommandFlag flags) |
Declone an order-list. More... | |
CommandCost | CmdDeleteOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Delete an order from the orderlist of a vehicle. More... | |
static void | CancelLoadingDueToDeletedOrder (Vehicle *v) |
Cancel the current loading order of the vehicle as the order was deleted. More... | |
void | DeleteOrder (Vehicle *v, VehicleOrderID sel_ord) |
Delete an order but skip the parameter validation. More... | |
CommandCost | CmdSkipToOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Goto order of order-list. More... | |
CommandCost | CmdMoveOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Move an order inside the orderlist. More... | |
CommandCost | CmdModifyOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Modify an order in the orderlist of a vehicle. More... | |
static bool | CheckAircraftOrderDistance (const Aircraft *v_new, const Vehicle *v_order, const Order *first) |
Check if an aircraft has enough range for an order list. More... | |
CommandCost | CmdCloneOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Clone/share/copy an order-list of another vehicle. More... | |
CommandCost | CmdOrderRefit (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Add/remove refit orders from an order. More... | |
void | CheckOrders (const Vehicle *v) |
Check the orders of a vehicle, to see if there are invalid orders and stuff. More... | |
void | RemoveOrderFromAllVehicles (OrderType type, DestinationID destination) |
Removes an order from all vehicles. More... | |
void | DeleteVehicleOrders (Vehicle *v, bool keep_orderlist, bool reset_order_indices) |
Delete all orders from a vehicle. More... | |
uint16 | GetServiceIntervalClamped (uint interval, bool ispercent) |
Clamp the service interval to the correct min/max. More... | |
static bool | CheckForValidOrders (const Vehicle *v) |
Check if a vehicle has any valid orders. More... | |
static bool | OrderConditionCompare (OrderConditionComparator occ, int variable, int value) |
Compare the variable and value based on the given comparator. | |
VehicleOrderID | ProcessConditionalOrder (const Order *order, const Vehicle *v) |
Process a conditional order and determine the next order. More... | |
bool | UpdateOrderDest (Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead) |
Update the vehicle's destination tile from an order. More... | |
bool | ProcessOrders (Vehicle *v) |
Handle the orders of a vehicle and determine the next place to go to if needed. More... | |
Variables | |
OrderPool | _order_pool ("Order") |
OrderListPool | _orderlist_pool ("OrderList") |
Handling of orders.
Definition in file order_cmd.cpp.
|
static |
Cancel the current loading order of the vehicle as the order was deleted.
v | the vehicle |
Definition at line 1065 of file order_cmd.cpp.
|
static |
Check if an aircraft has enough range for an order list.
v_new | Aircraft to check. |
v_order | Vehicle currently holding the order list. |
first | First order in the source order list. |
Definition at line 1527 of file order_cmd.cpp.
References AircraftCache::cached_max_range, and Order::next.
|
static |
Check if a vehicle has any valid orders.
Definition at line 1967 of file order_cmd.cpp.
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().
CommandCost CmdCloneOrder | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Clone/share/copy an order-list of another vehicle.
tile | unused |
flags | operation to perform |
p1 | various bitstuffed elements
|
p2 | source vehicle to clone orders from, if any (none for CO_UNSHARE) |
text | unused |
Definition at line 1560 of file order_cmd.cpp.
References CheckOwnership(), CMD_ERROR, CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::IsPrimaryVehicle(), and Vehicle::owner.
CommandCost CmdDeleteOrder | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Delete an order from the orderlist of a vehicle.
tile | unused |
flags | operation to perform |
p1 | the ID of the vehicle |
p2 | the order to delete (max 255) |
text | unused |
Definition at line 1040 of file order_cmd.cpp.
References CheckOwnership(), CMD_ERROR, DC_EXEC, DecloneOrder(), DeleteOrder(), CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), Vehicle::IsPrimaryVehicle(), and Vehicle::owner.
CommandCost CmdInsertOrder | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Add an order to the orderlist of a vehicle.
tile | unused |
flags | operation to perform |
p1 | various bitstuffed elements
|
p2 | packed order to insert |
text | unused |
Definition at line 728 of file order_cmd.cpp.
References CheckOwnership(), CMD_ERROR, CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Order::GetType(), Vehicle::IsPrimaryVehicle(), and Vehicle::owner.
CommandCost CmdModifyOrder | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Modify an order in the orderlist of a vehicle.
tile | unused |
flags | operation to perform |
p1 | various bitstuffed elements
|
p2 | various bitstuffed elements
|
text | unused |
Definition at line 1291 of file order_cmd.cpp.
References GB().
CommandCost CmdMoveOrder | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Move an order inside the orderlist.
tile | unused |
flags | operation to perform |
p1 | the ID of the vehicle |
p2 | order to move and target bit 0-15 : the order to move bit 16-31 : the target order |
text | unused |
Definition at line 1187 of file order_cmd.cpp.
References CheckOwnership(), CMD_ERROR, BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, DC_EXEC, DeleteOrderWarnings(), CommandCost::Failed(), Vehicle::FirstShared(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), Vehicle::IsPrimaryVehicle(), Vehicle::list, OrderList::MoveOrder(), Vehicle::NextShared(), Vehicle::orders, and Vehicle::owner.
CommandCost CmdOrderRefit | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Add/remove refit orders from an order.
tile | Not used |
flags | operation to perform |
p1 | VehicleIndex of the vehicle having the order |
p2 | bitmask
|
text | unused |
Definition at line 1711 of file order_cmd.cpp.
References CheckOwnership(), CMD_ERROR, CT_AUTO_REFIT, CT_NO_REFIT, CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetOrder(), Vehicle::IsPrimaryVehicle(), Order::IsType(), NUM_CARGO, and Vehicle::owner.
CommandCost CmdSkipToOrder | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Goto order of order-list.
tile | unused |
flags | operation to perform |
p1 | The ID of the vehicle which order is skipped |
p2 | the selected order to which we want to skip |
text | unused |
Definition at line 1146 of file order_cmd.cpp.
References CheckOwnership(), CMD_ERROR, BaseConsist::cur_implicit_order_index, Vehicle::current_order, DC_EXEC, CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNumOrders(), Vehicle::IsPrimaryVehicle(), Order::IsType(), and Vehicle::owner.
|
static |
Declone an order-list.
*dst | delete the orders of this vehicle |
flags | execution flags |
Definition at line 1021 of file order_cmd.cpp.
References DC_EXEC, DeleteVehicleOrders(), GetWindowClassForVehicleType(), InvalidateVehicleOrder(), InvalidateWindowClassesData(), BaseVehicle::type, and VIWD_REMOVE_ALL_ORDERS.
Referenced by CmdDeleteOrder().
void DeleteOrder | ( | Vehicle * | v, |
VehicleOrderID | sel_ord | ||
) |
Delete an order but skip the parameter validation.
v | The vehicle to delete the order from. |
sel_ord | The id of the order to be deleted. |
Definition at line 1081 of file order_cmd.cpp.
References OrderList::DeleteOrderAt(), DeleteOrderWarnings(), Vehicle::FirstShared(), Vehicle::list, Vehicle::NextShared(), and Vehicle::orders.
Referenced by CmdDeleteOrder().
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 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().
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 697 of file order_cmd.cpp.
References Order::IsType().
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.
interval | proposed service interval |
company_id | the owner of the vehicle |
Definition at line 1954 of file order_cmd.cpp.
References Clamp().
Referenced by CmdChangeServiceInt(), VehicleDetailsWindow::OnClick(), and VehicleDetailsWindow::OnDropdownSelect().
void InsertOrder | ( | Vehicle * | v, |
Order * | new_o, | ||
VehicleOrderID | sel_ord | ||
) |
Insert a new order but skip the validation.
v | The vehicle to insert the order to. |
new_o | The new order. |
sel_ord | The position the order should be inserted at. |
Definition at line 953 of file order_cmd.cpp.
References DeleteOrderWarnings(), Vehicle::FirstShared(), OrderList::InsertOrderAt(), Vehicle::list, Vehicle::NextShared(), and Vehicle::orders.
void InvalidateVehicleOrder | ( | const Vehicle * | v, |
int | data | ||
) |
Updates the widgets of a vehicle which contains the order-data.
Definition at line 252 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 DecloneOrder(), Vehicle::DeleteUnreachedImplicitOrders(), and Vehicle::IncrementRealOrderIndex().
Checks whether the order goes to a station or not, i.e.
whether the destination is a station
v | the vehicle to check for |
o | the order to check |
Definition at line 643 of file order_cmd.cpp.
References Order::IsType().
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 2010 of file order_cmd.cpp.
References Order::GetType().
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 2160 of file order_cmd.cpp.
References Vehicle::current_order, and Order::GetType().
void RemoveOrderFromAllVehicles | ( | OrderType | type, |
DestinationID | destination | ||
) |
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. |
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().
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 2039 of file order_cmd.cpp.
References Vehicle::current_order, Vehicle::dest_tile, Order::Free(), Vehicle::GetNumOrders(), and Order::GetType().