annotate src/ai/api/ai_order.cpp @ 12225:4f649aa97318 draft

(svn r16640) -Codechange: move roadstop stuff to separate files
author smatz <smatz@openttd.org>
date Tue, 23 Jun 2009 21:44:48 +0000
parents d092f17a921d
children 240adc64d01a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
1 /* $Id$ */
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
2
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
3 /** @file ai_order.cpp Implementation of AIOrder. */
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
4
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
5 #include "ai_order.hpp"
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
6 #include "ai_vehicle.hpp"
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
7 #include "ai_log.hpp"
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
8 #include "../ai_instance.hpp"
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
9 #include "../../debug.h"
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
10 #include "../../vehicle_base.h"
12225
4f649aa97318 (svn r16640) -Codechange: move roadstop stuff to separate files
smatz <smatz@openttd.org>
parents: 12082
diff changeset
11 #include "../../roadstop_base.h"
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
12 #include "../../depot_base.h"
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
13 #include "../../station_map.h"
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
14 #include "../../waypoint.h"
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
15
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
16 /**
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
17 * Gets the order type given a tile
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
18 * @param t the tile to get the order from
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
19 * @return the order type, or OT_END when there is no order
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
20 */
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
21 static OrderType GetOrderTypeByTile(TileIndex t)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
22 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
23 if (!::IsValidTile(t)) return OT_END;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
24
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
25 switch (::GetTileType(t)) {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
26 default: break;
11720
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
27 case MP_STATION:
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
28 if (IsHangar(t)) return OT_GOTO_DEPOT;
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
29 return OT_GOTO_STATION;
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
30 break;
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
31 case MP_WATER: if (::IsShipDepot(t)) return OT_GOTO_DEPOT; break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
32 case MP_ROAD: if (::GetRoadTileType(t) == ROAD_TILE_DEPOT) return OT_GOTO_DEPOT; break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
33 case MP_RAILWAY:
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
34 switch (::GetRailTileType(t)) {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
35 case RAIL_TILE_DEPOT: return OT_GOTO_DEPOT;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
36 case RAIL_TILE_WAYPOINT: return OT_GOTO_WAYPOINT;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
37 default: break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
38 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
39 break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
40 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
41
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
42 return OT_END;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
43 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
44
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
45 /* static */ bool AIOrder::IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
46 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
47 return AIVehicle::IsValidVehicle(vehicle_id) && order_position >= 0 && (order_position < ::Vehicle::Get(vehicle_id)->GetNumOrders() || order_position == ORDER_CURRENT);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
48 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
49
11775
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
50 /**
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
51 * Get the current order the vehicle is executing. If the current order is in
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
52 * the order list, return the order from the orderlist. If the current order
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
53 * was a manual order, return the current order.
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
54 */
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
55 static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition order_position)
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
56 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
57 const Vehicle *v = ::Vehicle::Get(vehicle_id);
11775
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
58 if (order_position == AIOrder::ORDER_CURRENT) {
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
59 const Order *order = &v->current_order;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
60 if (order->GetType() == OT_GOTO_DEPOT && !(order->GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) return order;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
61 order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
62 if (order_position == AIOrder::ORDER_INVALID) return NULL;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
63 }
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
64 return v->GetOrder(order_position);
11775
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
65 }
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
66
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
67 /* static */ bool AIOrder::IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position)
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
68 {
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
69 if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
70
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
71 const Order *order = ::ResolveOrder(vehicle_id, order_position);
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
72 return order != NULL && order->GetType() == OT_GOTO_STATION;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
73 }
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
74
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
75 /* static */ bool AIOrder::IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position)
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
76 {
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
77 if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
78
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
79 const Order *order = ::ResolveOrder(vehicle_id, order_position);
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
80 return order != NULL && order->GetType() == OT_GOTO_DEPOT;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
81 }
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
82
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
83 /* static */ bool AIOrder::IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position)
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
84 {
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
85 if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
86
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
87 const Order *order = ::ResolveOrder(vehicle_id, order_position);
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
88 return order != NULL && order->GetType() == OT_GOTO_WAYPOINT;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
89 }
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
90
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
91 /* static */ bool AIOrder::IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
92 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
93 if (order_position == ORDER_CURRENT) return false;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
94 if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
95
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
96 const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
97 return order->GetType() == OT_CONDITIONAL;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
98 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
99
11775
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
100 /* static */ bool AIOrder::IsCurrentOrderPartOfOrderList(VehicleID vehicle_id)
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
101 {
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
102 if (AIVehicle::IsValidVehicle(vehicle_id)) return false;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
103 if (GetOrderCount(vehicle_id) == 0) return false;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
104
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
105 const Order *order = &::Vehicle::Get(vehicle_id)->current_order;
11775
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
106 if (order->GetType() != OT_GOTO_DEPOT) return true;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
107 return (order->GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0;
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
108 }
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
109
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
110 /* static */ AIOrder::OrderPosition AIOrder::ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
111 {
10768
0556b96dd731 (svn r15101) -Change [API CHANGE]: more consistant naming for consts:
truebrain <truebrain@openttd.org>
parents: 10696
diff changeset
112 if (!AIVehicle::IsValidVehicle(vehicle_id)) return ORDER_INVALID;
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
113
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
114 if (order_position == ORDER_CURRENT) return (AIOrder::OrderPosition)::Vehicle::Get(vehicle_id)->cur_order_index;
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
115 return (order_position >= 0 && order_position < ::Vehicle::Get(vehicle_id)->GetNumOrders()) ? order_position : ORDER_INVALID;
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
116 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
117
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
118
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
119 /* static */ bool AIOrder::AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
120 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
121 switch (::GetOrderTypeByTile(destination)) {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
122 case OT_GOTO_STATION:
12082
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
123 return (order_flags & ~(AIOF_NON_STOP_FLAGS | AIOF_UNLOAD_FLAGS | AIOF_LOAD_FLAGS)) == 0 &&
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
124 /* Test the different mutual exclusive flags. */
12082
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
125 ((order_flags & AIOF_TRANSFER) == 0 || (order_flags & AIOF_UNLOAD) == 0) &&
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
126 ((order_flags & AIOF_TRANSFER) == 0 || (order_flags & AIOF_NO_UNLOAD) == 0) &&
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
127 ((order_flags & AIOF_UNLOAD) == 0 || (order_flags & AIOF_NO_UNLOAD) == 0) &&
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
128 ((order_flags & AIOF_UNLOAD) == 0 || (order_flags & AIOF_NO_UNLOAD) == 0) &&
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
129 ((order_flags & AIOF_NO_UNLOAD) == 0 || (order_flags & AIOF_NO_LOAD) == 0) &&
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
130 ((order_flags & AIOF_FULL_LOAD_ANY) == 0 || (order_flags & AIOF_NO_LOAD) == 0);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
131
11719
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11718
diff changeset
132 case OT_GOTO_DEPOT:
12082
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
133 return (order_flags & ~(AIOF_NON_STOP_FLAGS | AIOF_DEPOT_FLAGS)) == 0 &&
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
134 ((order_flags & AIOF_SERVICE_IF_NEEDED) == 0 || (order_flags & AIOF_STOP_IN_DEPOT) == 0);
11719
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11718
diff changeset
135
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
136 case OT_GOTO_WAYPOINT: return (order_flags & ~(AIOF_NON_STOP_FLAGS)) == 0;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
137 default: return false;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
138 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
139 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
140
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
141 /* static */ bool AIOrder::IsValidConditionalOrder(OrderCondition condition, CompareFunction compare)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
142 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
143 switch (condition) {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
144 case OC_LOAD_PERCENTAGE:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
145 case OC_RELIABILITY:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
146 case OC_MAX_SPEED:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
147 case OC_AGE:
11176
924587d9da82 (svn r15527) -Fix (r15526): A ')' too much.
yexo <yexo@openttd.org>
parents: 11175
diff changeset
148 return compare >= CF_EQUALS && compare <= CF_MORE_EQUALS;
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
149
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
150 case OC_REQUIRES_SERVICE:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
151 return compare == CF_IS_TRUE || compare == CF_IS_FALSE;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
152
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
153 case OC_UNCONDITIONALLY:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
154 return true;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
155
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
156 default: return false;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
157 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
158 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
159
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
160 /* static */ int32 AIOrder::GetOrderCount(VehicleID vehicle_id)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
161 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
162 return AIVehicle::IsValidVehicle(vehicle_id) ? ::Vehicle::Get(vehicle_id)->GetNumOrders() : -1;
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
163 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
164
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
165 /* static */ TileIndex AIOrder::GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
166 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
167 if (!IsValidVehicleOrder(vehicle_id, order_position)) return INVALID_TILE;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
168
11775
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
169 const Order *order = ::ResolveOrder(vehicle_id, order_position);
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
170 if (order == NULL || order->GetType() == OT_CONDITIONAL) return INVALID_TILE;
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
171 const Vehicle *v = ::Vehicle::Get(vehicle_id);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
172
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
173 switch (order->GetType()) {
11721
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
174 case OT_GOTO_DEPOT: {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
175 if (v->type != VEH_AIRCRAFT) return ::Depot::Get(order->GetDestination())->xy;
11721
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
176 /* Aircraft's hangars are referenced by StationID, not DepotID */
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
177 const Station *st = ::Station::Get(order->GetDestination());
11721
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
178 const AirportFTAClass *airport = st->Airport();
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
179 if (airport == NULL || airport->nof_depots == 0) return INVALID_TILE;
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
180 return st->airport_tile + ::ToTileIndexDiff(st->Airport()->airport_depots[0]);
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
181 }
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
182
11721
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
183 case OT_GOTO_STATION: {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
184 const Station *st = ::Station::Get(order->GetDestination());
11721
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
185 if (st->train_tile != INVALID_TILE) {
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
186 for (uint i = 0; i < st->trainst_w; i++) {
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
187 TileIndex t = st->train_tile + TileDiffXY(i, 0);
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
188 if (st->TileBelongsToRailStation(t)) return t;
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
189 }
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
190 } else if (st->dock_tile != INVALID_TILE) {
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
191 return st->dock_tile;
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
192 } else if (st->bus_stops != NULL) {
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
193 return st->bus_stops->xy;
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
194 } else if (st->truck_stops != NULL) {
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
195 return st->truck_stops->xy;
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
196 } else if (st->airport_tile != INVALID_TILE) {
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
197 const AirportFTAClass *fta = st->Airport();
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
198 BEGIN_TILE_LOOP(tile, fta->size_x, fta->size_y, st->airport_tile) {
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
199 if (!::IsHangar(tile)) return tile;
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
200 } END_TILE_LOOP(tile, fta->size_x, fta->size_y, st->airport_tile)
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
201 }
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
202 return INVALID_TILE;
c92611d86f13 (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
yexo <yexo@openttd.org>
parents: 11720
diff changeset
203 }
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
204 case OT_GOTO_WAYPOINT: return ::Waypoint::Get(order->GetDestination())->xy;
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
205 default: return INVALID_TILE;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
206 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
207 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
208
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
209 /* static */ AIOrder::AIOrderFlags AIOrder::GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
210 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
211 if (!IsValidVehicleOrder(vehicle_id, order_position)) return AIOF_INVALID;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
212
11775
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
213 const Order *order = ::ResolveOrder(vehicle_id, order_position);
34e40a741e56 (svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents: 11721
diff changeset
214 if (order == NULL || order->GetType() == OT_CONDITIONAL) return AIOF_INVALID;
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
215
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
216 AIOrderFlags order_flags = AIOF_NONE;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
217 order_flags |= (AIOrderFlags)order->GetNonStopType();
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
218 switch (order->GetType()) {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
219 case OT_GOTO_DEPOT:
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
220 if (order->GetDepotOrderType() & ODTFB_SERVICE) order_flags |= AIOF_SERVICE_IF_NEEDED;
11719
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11718
diff changeset
221 if (order->GetDepotActionType() & ODATFB_HALT) order_flags |= AIOF_STOP_IN_DEPOT;
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
222 break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
223
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
224 case OT_GOTO_STATION:
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
225 order_flags |= (AIOrderFlags)(order->GetLoadType() << 5);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
226 order_flags |= (AIOrderFlags)(order->GetUnloadType() << 2);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
227 break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
228
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
229 default: break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
230 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
231
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
232 return order_flags;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
233 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
234
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
235 /* static */ AIOrder::OrderPosition AIOrder::GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
236 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
237 if (!IsValidVehicleOrder(vehicle_id, order_position)) return ORDER_INVALID;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
238 if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return ORDER_INVALID;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
239
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
240 const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
241 return (OrderPosition)order->GetConditionSkipToOrder();
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
242 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
243
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
244 /* static */ AIOrder::OrderCondition AIOrder::GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
245 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
246 if (!IsValidVehicleOrder(vehicle_id, order_position)) return OC_INVALID;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
247 if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return OC_INVALID;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
248
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
249 const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
250 return (OrderCondition)order->GetConditionVariable();
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
251 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
252
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
253 /* static */ AIOrder::CompareFunction AIOrder::GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
254 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
255 if (!IsValidVehicleOrder(vehicle_id, order_position)) return CF_INVALID;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
256 if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return CF_INVALID;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
257
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
258 const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
259 return (CompareFunction)order->GetConditionComparator();
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
260 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
261
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
262 /* static */ int32 AIOrder::GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
263 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
264 if (!IsValidVehicleOrder(vehicle_id, order_position)) return -1;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
265 if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return -1;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
266
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
267 const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
268 int32 value = order->GetConditionValue();
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
269 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = value * 16 / 10;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
270 return value;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
271 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
272
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
273 /* static */ bool AIOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
274 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
275 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
276 EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
277 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
278
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
279 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), MOF_COND_DESTINATION | (jump_to << 4), CMD_MODIFY_ORDER);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
280 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
281
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
282 /* static */ bool AIOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
283 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
284 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
285 EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
286 EnforcePrecondition(false, condition >= OC_LOAD_PERCENTAGE && condition <= OC_UNCONDITIONALLY);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
287
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
288 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), MOF_COND_VARIABLE | (condition << 4), CMD_MODIFY_ORDER);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
289 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
290
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
291 /* static */ bool AIOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
292 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
293 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
294 EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
295 EnforcePrecondition(false, compare >= CF_EQUALS && compare <= CF_IS_FALSE);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
296
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
297 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), MOF_COND_COMPARATOR | (compare << 4), CMD_MODIFY_ORDER);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
298 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
299
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
300 /* static */ bool AIOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
301 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
302 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
303 EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
304 EnforcePrecondition(false, value >= 0 && value < 2048);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
305 if (GetOrderCondition(vehicle_id, order_position) == OC_MAX_SPEED) value = value * 10 / 16;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
306
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
307 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), MOF_COND_VALUE | (value << 4), CMD_MODIFY_ORDER);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
308 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
309
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
310 /* static */ bool AIOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
311 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
312 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
313 EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
314
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
315 return InsertOrder(vehicle_id, (AIOrder::OrderPosition)::Vehicle::Get(vehicle_id)->GetNumOrders(), destination, order_flags);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
316 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
317
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
318 /* static */ bool AIOrder::AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
319 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
320 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
321 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
322
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
323 return InsertConditionalOrder(vehicle_id, (AIOrder::OrderPosition)::Vehicle::Get(vehicle_id)->GetNumOrders(), jump_to);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
324 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
325
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
326 /* static */ bool AIOrder::InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrder::AIOrderFlags order_flags)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
327 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
328 /* IsValidVehicleOrder is not good enough because it does not allow appending. */
10768
0556b96dd731 (svn r15101) -Change [API CHANGE]: more consistant naming for consts:
truebrain <truebrain@openttd.org>
parents: 10696
diff changeset
329 if (order_position == ORDER_CURRENT) order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
330
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
331 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
332 EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumOrders());
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
333 EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
334
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
335 Order order;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
336 switch (::GetOrderTypeByTile(destination)) {
11719
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11718
diff changeset
337 case OT_GOTO_DEPOT: {
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11718
diff changeset
338 OrderDepotTypeFlags odtf = (OrderDepotTypeFlags)(ODTFB_PART_OF_ORDERS | ((order_flags & AIOF_SERVICE_IF_NEEDED) ? ODTFB_SERVICE : 0));
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11718
diff changeset
339 OrderDepotActionFlags odaf = (OrderDepotActionFlags)(ODATF_SERVICE_ONLY | ((order_flags & AIOF_STOP_IN_DEPOT) ? ODATFB_HALT : 0));
11849
a90ffc1a219d (svn r16239) -Fix (r16199): Use the stop/non-stop intermediate orderflags AIs can give for goto-depot orders
yexo <yexo@openttd.org>
parents: 11809
diff changeset
340 OrderNonStopFlags onsf = (OrderNonStopFlags)((order_flags & AIOF_NON_STOP_INTERMEDIATE) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
11720
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
341 /* Check explicitly if the order is to a station (for aircraft) or
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
342 * to a depot (other vehicle types). */
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
343 if (::Vehicle::Get(vehicle_id)->type == VEH_AIRCRAFT) {
11720
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
344 if (!::IsTileType(destination, MP_STATION)) return false;
11849
a90ffc1a219d (svn r16239) -Fix (r16199): Use the stop/non-stop intermediate orderflags AIs can give for goto-depot orders
yexo <yexo@openttd.org>
parents: 11809
diff changeset
345 order.MakeGoToDepot(::GetStationIndex(destination), odtf, onsf, odaf);
11720
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
346 } else {
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
347 if (::IsTileType(destination, MP_STATION)) return false;
11849
a90ffc1a219d (svn r16239) -Fix (r16199): Use the stop/non-stop intermediate orderflags AIs can give for goto-depot orders
yexo <yexo@openttd.org>
parents: 11809
diff changeset
348 order.MakeGoToDepot(::GetDepotByTile(destination)->index, odtf, onsf, odaf);
11720
4ffde677f62e (svn r16108) -Fix [NoAI]: When giving an aircraft a goto-hangar order don't let it be a normal goto-station order.
yexo <yexo@openttd.org>
parents: 11719
diff changeset
349 }
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
350 break;
11719
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11718
diff changeset
351 }
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
352
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
353 case OT_GOTO_STATION:
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
354 order.MakeGoToStation(::GetStationIndex(destination));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
355 order.SetLoadType((OrderLoadFlags)GB(order_flags, 5, 3));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
356 order.SetUnloadType((OrderUnloadFlags)GB(order_flags, 2, 3));
11679
af86fa342537 (svn r16062) -Fix (r16037): AIOrder::InsertOrder was broken. Default all AI orders to 'stop at far end'.
frosch <frosch@openttd.org>
parents: 11334
diff changeset
357 order.SetStopLocation(OSL_PLATFORM_FAR_END);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
358 break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
359
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
360 case OT_GOTO_WAYPOINT:
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
361 order.MakeGoToWaypoint(::GetWaypointIndex(destination));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
362 break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
363
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
364 default:
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
365 return false;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
366 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
367
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
368 order.SetNonStopType((OrderNonStopFlags)GB(order_flags, 0, 2));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
369
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
370 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), order.Pack(), CMD_INSERT_ORDER);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
371 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
372
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
373 /* static */ bool AIOrder::InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
374 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
375 /* IsValidVehicleOrder is not good enough because it does not allow appending. */
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
376 if (order_position == ORDER_CURRENT) order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
377
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
378 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
379 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
380
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
381 Order order;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
382 order.MakeConditional(jump_to);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
383
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
384 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), order.Pack(), CMD_INSERT_ORDER);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
385 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
386
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
387 /* static */ bool AIOrder::RemoveOrder(VehicleID vehicle_id, OrderPosition order_position)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
388 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
389 order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
390
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
391 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
392
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
393 return AIObject::DoCommand(0, vehicle_id, order_position, CMD_DELETE_ORDER);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
394 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
395
11334
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
396 /* static */ bool AIOrder::SkipToOrder(VehicleID vehicle_id, OrderPosition next_order)
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
397 {
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
398 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order));
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
399
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
400 return AIObject::DoCommand(0, vehicle_id, next_order, CMD_SKIP_TO_ORDER);
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
401 }
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
402
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
403 /**
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
404 * Callback handler as SetOrderFlags possibly needs multiple DoCommand calls
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
405 * to be able to set all order flags correctly. As we need to wait till the
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
406 * command has completed before we know the next bits to change we need to
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
407 * call the function multiple times. Each time it'll reduce the difference
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
408 * between the wanted and the current order.
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
409 * @param instance The AI we are doing the callback for.
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
410 */
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
411 static void _DoCommandReturnSetOrderFlags(class AIInstance *instance)
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
412 {
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
413 AIObject::SetLastCommandRes(AIOrder::_SetOrderFlags());
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
414 AIInstance::DoCommandReturn(instance);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
415 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
416
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
417 /* static */ bool AIOrder::_SetOrderFlags()
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
418 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
419 /* Make sure we don't go into an infinite loop */
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
420 int retry = AIObject::GetCallbackVariable(3) - 1;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
421 if (retry < 0) {
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
422 DEBUG(ai, 0, "Possible infinite loop in SetOrderFlags() detected");
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
423 return false;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
424 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
425 AIObject::SetCallbackVariable(3, retry);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
426
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
427 VehicleID vehicle_id = (VehicleID)AIObject::GetCallbackVariable(0);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
428 OrderPosition order_position = (OrderPosition)AIObject::GetCallbackVariable(1);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
429 AIOrderFlags order_flags = (AIOrderFlags)AIObject::GetCallbackVariable(2);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
430
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
431 order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
432
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
433 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
434 EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
435
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
436 const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
437
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
438 AIOrderFlags current = GetOrderFlags(vehicle_id, order_position);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
439
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
440 if ((current & AIOF_NON_STOP_FLAGS) != (order_flags & AIOF_NON_STOP_FLAGS)) {
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
441 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnSetOrderFlags);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
442 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
443
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
444 switch (order->GetType()) {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
445 case OT_GOTO_DEPOT:
11719
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11718
diff changeset
446 if ((current & AIOF_DEPOT_FLAGS) != (order_flags & AIOF_DEPOT_FLAGS)) {
11718
411b82321c8c (svn r16106) -Fix [NoAI]: AIOrder::SetOrderFlags always removed "Service if needed" from goto-depot orders.
yexo <yexo@openttd.org>
parents: 11679
diff changeset
447 uint data = DA_ALWAYS_GO;
411b82321c8c (svn r16106) -Fix [NoAI]: AIOrder::SetOrderFlags always removed "Service if needed" from goto-depot orders.
yexo <yexo@openttd.org>
parents: 11679
diff changeset
448 if (order_flags & AIOF_SERVICE_IF_NEEDED) data = DA_SERVICE;
11719
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11718
diff changeset
449 if (order_flags & AIOF_STOP_IN_DEPOT) data = DA_STOP;
11718
411b82321c8c (svn r16106) -Fix [NoAI]: AIOrder::SetOrderFlags always removed "Service if needed" from goto-depot orders.
yexo <yexo@openttd.org>
parents: 11679
diff changeset
450 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (data << 4) | MOF_DEPOT_ACTION, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnSetOrderFlags);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
451 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
452 break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
453
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
454 case OT_GOTO_STATION:
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
455 if ((current & AIOF_UNLOAD_FLAGS) != (order_flags & AIOF_UNLOAD_FLAGS)) {
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
456 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnSetOrderFlags);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
457 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
458 if ((current & AIOF_LOAD_FLAGS) != (order_flags & AIOF_LOAD_FLAGS)) {
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
459 return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnSetOrderFlags);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
460 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
461 break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
462
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
463 default: break;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
464 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
465
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
466 assert(GetOrderFlags(vehicle_id, order_position) == order_flags);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
467
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
468 return true;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
469 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
470
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
471 /* static */ bool AIOrder::SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrder::AIOrderFlags order_flags)
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
472 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
473 AIObject::SetCallbackVariable(0, vehicle_id);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
474 AIObject::SetCallbackVariable(1, order_position);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
475 AIObject::SetCallbackVariable(2, order_flags);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
476 /* In case another client(s) change orders at the same time we could
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
477 * end in an infinite loop. This stops that from happening ever. */
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
478 AIObject::SetCallbackVariable(3, 8);
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
479 return AIOrder::_SetOrderFlags();
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
480 }
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
481
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
482 /* static */ bool AIOrder::ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrder::AIOrderFlags order_flags)
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
483 {
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
484 AILog::Warning("AIOrder::ChangeOrder is deprecated and will be removed soon, please use AIOrder::SetOrderFlags instead.");
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
485 return SetOrderFlags(vehicle_id, order_position, order_flags);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
486 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
487
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
488 /* static */ bool AIOrder::MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
489 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
490 order_position_move = AIOrder::ResolveOrderPosition(vehicle_id, order_position_move);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
491 order_position_target = AIOrder::ResolveOrderPosition(vehicle_id, order_position_target);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
492
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
493 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_move));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
494 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_target));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
495
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
496 return AIObject::DoCommand(0, vehicle_id, order_position_move | (order_position_target << 16), CMD_MOVE_ORDER);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
497 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
498
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
499 /* static */ bool AIOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
500 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
501 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
502 EnforcePrecondition(false, AIVehicle::IsValidVehicle(main_vehicle_id));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
503
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
504 return AIObject::DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_COPY, CMD_CLONE_ORDER);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
505 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
506
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
507 /* static */ bool AIOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
508 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
509 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
510 EnforcePrecondition(false, AIVehicle::IsValidVehicle(main_vehicle_id));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
511
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
512 return AIObject::DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_SHARE, CMD_CLONE_ORDER);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
513 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
514
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
515 /* static */ bool AIOrder::UnshareOrders(VehicleID vehicle_id)
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
516 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
517 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
518
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
519 return AIObject::DoCommand(0, vehicle_id, CO_UNSHARE, CMD_CLONE_ORDER);
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
520 }