annotate src/ai/api/ai_order.cpp @ 17152:c62cecf4dade draft

(svn r21890) -Cleanup: remove some unneeded includes
author rubidium <rubidium@openttd.org>
date Sat, 22 Jan 2011 14:52:20 +0000 (2011-01-22)
parents 47d33cf95c70
children 18e173373bb0
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
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12748
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12748
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12748
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12748
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12748
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12748
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12748
diff changeset
9
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
10 /** @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
11
17150
47d33cf95c70 (svn r21888) -Codechange: remove some unneeded (for the AI header) headers from some AI headers, reducing the include tree
rubidium <rubidium@openttd.org>
parents: 16837
diff changeset
12 #include "../../stdafx.h"
17152
c62cecf4dade (svn r21890) -Cleanup: remove some unneeded includes
rubidium <rubidium@openttd.org>
parents: 17150
diff changeset
13 #include "ai_order.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
14 #include "ai_vehicle.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
15 #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
16 #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
17 #include "../../vehicle_base.h"
12225
4f649aa97318 (svn r16640) -Codechange: move roadstop stuff to separate files
smatz <smatz@openttd.org>
parents: 12082
diff changeset
18 #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
19 #include "../../depot_base.h"
12228
240adc64d01a (svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents: 12225
diff changeset
20 #include "../../station_base.h"
12475
c133b51890f4 (svn r16912) -Codechange: split waypoint.h in waypoint_base.h and waypoint_func.h
rubidium <rubidium@openttd.org>
parents: 12472
diff changeset
21 #include "../../waypoint_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
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 /**
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 * 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
25 * @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
26 * @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
27 */
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
28 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
29 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
30 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
31
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 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
33 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
34 case MP_STATION:
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
35 if (IsBuoy(t) || IsRailWaypoint(t)) return OT_GOTO_WAYPOINT;
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
36 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
37 return OT_GOTO_STATION;
16837
0308286cd42f (svn r21571) -Codechange: Having a break after a return is no good.
alberth <alberth@openttd.org>
parents: 15889
diff changeset
38
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
39 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
40 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
41 case MP_RAILWAY:
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
42 if (IsRailDepot(t)) return OT_GOTO_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
43 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
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
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 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
47 }
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 /* 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
50 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
51 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
52 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
53
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
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 * 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
56 * 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
57 * 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
58 */
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 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
60 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
61 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
62 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
63 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
64 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
65 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
66 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
67 }
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
68 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
69 }
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 /* 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
72 {
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 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
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 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
76 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
77 }
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 /* 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
80 {
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 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
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 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
84 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
85 }
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 /* 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
88 {
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 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
90
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
91 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
92 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
93 }
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
94
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
95 /* 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
96 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
97 if (order_position == ORDER_CURRENT) return false;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
98 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
99
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
100 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
101 return order->GetType() == OT_CONDITIONAL;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
102 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
103
15722
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
104 /* static */ bool AIOrder::IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position)
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
105 {
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
106 if (order_position == ORDER_CURRENT) return false;
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
107 if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
108
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
109 const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
110 return order->GetType() == OT_DUMMY;
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
111 }
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
112
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
113 /* 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
114 {
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
115 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
116 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
117
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
118 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
119 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
120 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
121 }
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
122
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
123 /* 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
124 {
10768
0556b96dd731 (svn r15101) -Change [API CHANGE]: more consistant naming for consts:
truebrain <truebrain@openttd.org>
parents: 10696
diff changeset
125 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
126
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
127 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
128 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
129 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
130
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
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
132 /* 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
133 {
13980
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
134 OrderType ot = (order_flags & AIOF_GOTO_NEAREST_DEPOT) ? OT_GOTO_DEPOT : ::GetOrderTypeByTile(destination);
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
135 switch (ot) {
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_STATION:
12082
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11991
diff changeset
137 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
138 /* 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
139 ((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
140 ((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
141 ((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
142 ((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
143 ((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
144 ((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
145
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
146 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
147 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
148 ((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
149
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
150 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
151 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
152 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
153 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
154
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
155 /* 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
156 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
157 switch (condition) {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
158 case OC_LOAD_PERCENTAGE:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
159 case OC_RELIABILITY:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
160 case OC_MAX_SPEED:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
161 case OC_AGE:
11176
924587d9da82 (svn r15527) -Fix (r15526): A ')' too much.
yexo <yexo@openttd.org>
parents: 11175
diff changeset
162 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
163
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
164 case OC_REQUIRES_SERVICE:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
165 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
166
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
167 case OC_UNCONDITIONALLY:
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
168 return true;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
169
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
170 default: return false;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
171 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
172 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
173
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
174 /* 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
175 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
176 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
177 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
178
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
179 /* 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
180 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
181 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
182
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
183 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
184 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
185 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
186
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
187 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
188 case OT_GOTO_DEPOT: {
14120
b1881bbcee28 (svn r18667) -Fix [FS#3454]: [NoAI] crash when trying to get the order destination of a 'nearest depot' order
rubidium <rubidium@openttd.org>
parents: 13980
diff changeset
189 /* We don't know where the nearest depot is... (yet) */
b1881bbcee28 (svn r18667) -Fix [FS#3454]: [NoAI] crash when trying to get the order destination of a 'nearest depot' order
rubidium <rubidium@openttd.org>
parents: 13980
diff changeset
190 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) return INVALID_TILE;
b1881bbcee28 (svn r18667) -Fix [FS#3454]: [NoAI] crash when trying to get the order destination of a 'nearest depot' order
rubidium <rubidium@openttd.org>
parents: 13980
diff changeset
191
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
192 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
193 /* 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
194 const Station *st = ::Station::Get(order->GetDestination());
14867
d2be152e6d09 (svn r19463) -Codechange: add helper function to determine if an airport has at least one hangar
yexo <yexo@openttd.org>
parents: 14859
diff changeset
195 if (!st->airport.HasHangar()) return INVALID_TILE;
14868
9ae8ffb9d4b9 (svn r19464) -Codechange: move GetHangarTile to Airport
yexo <yexo@openttd.org>
parents: 14867
diff changeset
196 return st->airport.GetHangarTile(0);
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
197 }
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
198
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
199 case OT_GOTO_STATION: {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
200 const Station *st = ::Station::Get(order->GetDestination());
12510
3e976121ced2 (svn r16947) -Codechange: use TileArea instead of train_tile, trainst_w and trainst_h.
rubidium <rubidium@openttd.org>
parents: 12475
diff changeset
201 if (st->train_station.tile != INVALID_TILE) {
14367
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
202 TILE_AREA_LOOP(t, st->train_station) {
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
203 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
204 }
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
205 } 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
206 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
207 } 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
208 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
209 } 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
210 return st->truck_stops->xy;
14621
562ed276a7d0 (svn r19198) -Codechange: store the size of stations in savegames
yexo <yexo@openttd.org>
parents: 14455
diff changeset
211 } else if (st->airport.tile != INVALID_TILE) {
562ed276a7d0 (svn r19198) -Codechange: store the size of stations in savegames
yexo <yexo@openttd.org>
parents: 14455
diff changeset
212 TILE_AREA_LOOP(tile, st->airport) {
562ed276a7d0 (svn r19198) -Codechange: store the size of stations in savegames
yexo <yexo@openttd.org>
parents: 14455
diff changeset
213 if (st->TileBelongsToAirport(tile) && !::IsHangar(tile)) return tile;
12529
f24901a2ad84 (svn r16966) -Codechange: BEGIN_TILE_LOOP and END_TILE_LOOP reworked into TILE_LOOP, which means no more duplication of parameters between BEGIN_TILE_LOOP and END_TILE_LOOP
rubidium <rubidium@openttd.org>
parents: 12511
diff changeset
214 }
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
215 }
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
216 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
217 }
14367
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
218
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
219 case OT_GOTO_WAYPOINT: {
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
220 const Waypoint *wp = ::Waypoint::Get(order->GetDestination());
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
221 if (wp->train_station.tile != INVALID_TILE) {
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
222 TILE_AREA_LOOP(t, wp->train_station) {
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
223 if (wp->TileBelongsToRailStation(t)) return t;
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
224 }
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
225 }
14368
c0763b00a33f (svn r18925) -Fix (r18924): a waypoint can have a buoy but no rail waypoint tile
yexo <yexo@openttd.org>
parents: 14367
diff changeset
226 /* If the waypoint has no rail waypoint tiles, it must have a buoy */
c0763b00a33f (svn r18925) -Fix (r18924): a waypoint can have a buoy but no rail waypoint tile
yexo <yexo@openttd.org>
parents: 14367
diff changeset
227 return wp->xy;
14367
de46f55c4e38 (svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
yexo <yexo@openttd.org>
parents: 14308
diff changeset
228 }
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
229 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
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
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 /* 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
234 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
235 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
236
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
237 const Order *order = ::ResolveOrder(vehicle_id, order_position);
15722
3d1ca3435ebb (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents: 14868
diff changeset
238 if (order == NULL || order->GetType() == OT_CONDITIONAL || order->GetType() == OT_DUMMY) 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
239
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
240 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
241 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
242 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
243 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
244 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
245 if (order->GetDepotActionType() & ODATFB_HALT) order_flags |= AIOF_STOP_IN_DEPOT;
13980
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
246 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) order_flags |= AIOF_GOTO_NEAREST_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
247 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
248
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
249 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
250 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
251 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
252 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
253
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
254 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
255 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
256
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
257 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
258 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
259
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
260 /* 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
261 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
262 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
263 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
264
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
265 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
266 return (OrderPosition)order->GetConditionSkipToOrder();
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
267 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
268
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
269 /* 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
270 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
271 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
272 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
273
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
274 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
275 return (OrderCondition)order->GetConditionVariable();
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
276 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
277
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
278 /* 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
279 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
280 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
281 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
282
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
283 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
284 return (CompareFunction)order->GetConditionComparator();
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
285 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
286
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
287 /* 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
288 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
289 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
290 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
291
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
292 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
293 int32 value = order->GetConditionValue();
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
294 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
295 return value;
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
14455
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
298 /* static */ AIOrder::StopLocation AIOrder::GetStopLocation(VehicleID vehicle_id, OrderPosition order_position)
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
299 {
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
300 if (!IsValidVehicleOrder(vehicle_id, order_position)) return STOPLOCATION_INVALID;
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
301 if (AIVehicle::GetVehicleType(vehicle_id) != AIVehicle::VT_RAIL) return STOPLOCATION_INVALID;
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
302 if (!IsGotoStationOrder(vehicle_id, order_position)) return STOPLOCATION_INVALID;
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
303
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
304 const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
305 return (AIOrder::StopLocation)order->GetStopLocation();
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
306 }
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
307
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
308 /* 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
309 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
310 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
311 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
312 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
313
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
314 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), MOF_COND_DESTINATION | (jump_to << 4), CMD_MODIFY_ORDER);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
315 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
316
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
317 /* 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
318 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
319 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
320 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
321 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
322
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
323 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), MOF_COND_VARIABLE | (condition << 4), CMD_MODIFY_ORDER);
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
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
326 /* 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
327 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
328 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
329 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
330 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
331
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
332 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), MOF_COND_COMPARATOR | (compare << 4), CMD_MODIFY_ORDER);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
333 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
334
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
335 /* 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
336 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
337 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
338 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
339 EnforcePrecondition(false, value >= 0 && value < 2048);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
340 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
341
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
342 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), MOF_COND_VALUE | (value << 4), CMD_MODIFY_ORDER);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
343 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
344
14455
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
345 /* static */ bool AIOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
346 {
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
347 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
348 EnforcePrecondition(false, AIVehicle::GetVehicleType(vehicle_id) == AIVehicle::VT_RAIL);
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
349 EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position));
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
350 EnforcePrecondition(false, stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR);
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
351
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
352 uint32 p1 = vehicle_id | (order_position << 20);
14455
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
353 uint32 p2 = MOF_STOP_LOCATION | (stop_location << 4);
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
354 return AIObject::DoCommand(0, p1, p2, CMD_MODIFY_ORDER);
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
355 }
ad8e2f1135ed (svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
yexo <yexo@openttd.org>
parents: 14368
diff changeset
356
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
357 /* 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
358 {
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 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
360 EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
361
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
362 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
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
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
365 /* 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
366 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
367 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
368 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
369
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11849
diff changeset
370 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
371 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
372
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
373 /* 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
374 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
375 /* 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
376 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
377
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
378 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
379 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
380 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
381
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
382 Order order;
13980
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
383 OrderType ot = (order_flags & AIOF_GOTO_NEAREST_DEPOT) ? OT_GOTO_DEPOT : ::GetOrderTypeByTile(destination);
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
384 switch (ot) {
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
385 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
386 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
387 OrderDepotActionFlags odaf = (OrderDepotActionFlags)(ODATF_SERVICE_ONLY | ((order_flags & AIOF_STOP_IN_DEPOT) ? ODATFB_HALT : 0));
13980
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
388 if (order_flags & AIOF_GOTO_NEAREST_DEPOT) odaf |= ODATFB_NEAREST_DEPOT;
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
389 OrderNonStopFlags onsf = (OrderNonStopFlags)((order_flags & AIOF_NON_STOP_INTERMEDIATE) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
13980
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
390 if (order_flags & AIOF_GOTO_NEAREST_DEPOT) {
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
391 order.MakeGoToDepot(0, 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
392 } else {
13980
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
393 /* Check explicitly if the order is to a station (for aircraft) or
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
394 * to a depot (other vehicle types). */
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
395 if (::Vehicle::Get(vehicle_id)->type == VEH_AIRCRAFT) {
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
396 if (!::IsTileType(destination, MP_STATION)) return false;
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
397 order.MakeGoToDepot(::GetStationIndex(destination), odtf, onsf, odaf);
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
398 } else {
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
399 if (::IsTileType(destination, MP_STATION)) return false;
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
400 order.MakeGoToDepot(::GetDepotIndex(destination), odtf, onsf, odaf);
4d50ab271097 (svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents: 13939
diff changeset
401 }
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
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 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
404 }
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
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 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
407 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
408 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
409 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
410 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
411 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
412
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
413 case OT_GOTO_WAYPOINT:
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
414 order.MakeGoToWaypoint(::GetStationIndex(destination));
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
415 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
416
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
417 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
418 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
419 }
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
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 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
422
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
423 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), order.Pack(), CMD_INSERT_ORDER);
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
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
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
426 /* 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
427 {
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
428 /* 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
429 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
430
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
431 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
432 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to));
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
433
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
434 Order order;
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
435 order.MakeConditional(jump_to);
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
436
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
437 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), order.Pack(), CMD_INSERT_ORDER);
11175
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
438 }
5575028fb7e3 (svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents: 10960
diff changeset
439
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
440 /* 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
441 {
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 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
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 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
445
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
446 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
447 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
448
11334
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
449 /* 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
450 {
13939
0a9f4129b777 (svn r18471) -Codechange/Fix: [NoAI] Deduplicate code betweeen AIVehicle::SkipToVehicleOrder and AIOrder::SkipToOrder. They are the same. Also ORDER_CURRENT was not allowed for the latter, but well...
frosch <frosch@openttd.org>
parents: 13186
diff changeset
451 next_order = AIOrder::ResolveOrderPosition(vehicle_id, next_order);
0a9f4129b777 (svn r18471) -Codechange/Fix: [NoAI] Deduplicate code betweeen AIVehicle::SkipToVehicleOrder and AIOrder::SkipToOrder. They are the same. Also ORDER_CURRENT was not allowed for the latter, but well...
frosch <frosch@openttd.org>
parents: 13186
diff changeset
452
11334
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
453 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order));
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
454
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
455 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
456 }
6a22ff18d5a5 (svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents: 11267
diff changeset
457
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
458 /**
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
459 * 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
460 * 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
461 * 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
462 * 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
463 * 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
464 * @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
465 */
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
466 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
467 {
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
468 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
469 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
470 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
471
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
472 /* 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
473 {
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 /* 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
475 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
476 if (retry < 0) {
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
477 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
478 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
479 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
480 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
481
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
482 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
483 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
484 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
485
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 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
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 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
489 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
490
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11922
diff changeset
491 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
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 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
494
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 if ((current & AIOF_NON_STOP_FLAGS) != (order_flags & AIOF_NON_STOP_FLAGS)) {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
496 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), (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
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 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
500 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
501 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
502 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
503 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
504 if (order_flags & AIOF_STOP_IN_DEPOT) data = DA_STOP;
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
505 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), (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
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 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
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 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
510 if ((current & AIOF_UNLOAD_FLAGS) != (order_flags & AIOF_UNLOAD_FLAGS)) {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
511 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), (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
512 }
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 if ((current & AIOF_LOAD_FLAGS) != (order_flags & AIOF_LOAD_FLAGS)) {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
514 return AIObject::DoCommand(0, vehicle_id | (order_position << 20), (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
515 }
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 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
517
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 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
519 }
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
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
521 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
522
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
523 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
524 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
525
11267
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
526 /* 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
527 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
528 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
529 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
530 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
531 /* 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
532 * 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
533 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
534 return AIOrder::_SetOrderFlags();
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
535 }
1d456bf484a1 (svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents: 11176
diff changeset
536
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
537 /* 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
538 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
539 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
540 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
541
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
542 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
543 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
544
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
545 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
546 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
547
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
548 /* 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
549 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
550 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
551 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
552
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
553 return AIObject::DoCommand(0, vehicle_id | CO_COPY << 30, main_vehicle_id, CMD_CLONE_ORDER);
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
554 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
555
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
556 /* 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
557 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
558 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
559 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
560
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
561 return AIObject::DoCommand(0, vehicle_id | CO_SHARE << 30, main_vehicle_id, CMD_CLONE_ORDER);
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
562 }
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
563
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
564 /* 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
565 {
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff changeset
566 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
567
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15722
diff changeset
568 return AIObject::DoCommand(0, vehicle_id | CO_UNSHARE << 30, 0, CMD_CLONE_ORDER);
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
569 }