Mercurial > hg > openttd
annotate src/ai/api/ai_order.cpp @ 17194:b590eca5d805 draft
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
-Fix [FS#4440]: Automatic orders behave now stable wrt. service orders and are not added or removed depending on the need of servicing.
-Fix: Various other issues with automatic orders, e.g. vehicles getting stuck with "no orders" when there are automatic orders at the end of the order list.
author | frosch <frosch@openttd.org> |
---|---|
date | Mon, 31 Jan 2011 20:44:15 +0000 |
parents | 18e173373bb0 |
children | c52379fc5dd0 |
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 { |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
51 return AIVehicle::IsValidVehicle(vehicle_id) && order_position >= 0 && (order_position < ::Vehicle::Get(vehicle_id)->GetNumManualOrders() || 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 } |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
68 const Order *order = v->orders.list->GetFirstOrder(); |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
69 while (order->GetType() == OT_AUTOMATIC) order = order->next; |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
70 while (order_position > 0) { |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
71 order_position = (AIOrder::OrderPosition)(order_position - 1); |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
72 order = order->next; |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
73 while (order->GetType() == OT_AUTOMATIC) order = order->next; |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
74 } |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
75 return 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
|
76 } |
34e40a741e56
(svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents:
11721
diff
changeset
|
77 |
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 /* 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
|
79 { |
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 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
|
81 |
34e40a741e56
(svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents:
11721
diff
changeset
|
82 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
|
83 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
|
84 } |
34e40a741e56
(svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents:
11721
diff
changeset
|
85 |
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 /* 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
|
87 { |
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 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
|
89 |
34e40a741e56
(svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents:
11721
diff
changeset
|
90 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
|
91 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
|
92 } |
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 /* 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
|
95 { |
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
|
96 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
|
97 |
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
|
98 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
|
99 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
|
100 } |
34e40a741e56
(svn r16165) -Add [FS#2801] [NoAI]: several functions to AIOrder to check the what kind of order an order is.
yexo <yexo@openttd.org>
parents:
11721
diff
changeset
|
101 |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
102 /* 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
|
103 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
104 if (order_position == ORDER_CURRENT) return false; |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
105 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
|
106 |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11922
diff
changeset
|
107 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
|
108 return order->GetType() == OT_CONDITIONAL; |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
109 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
110 |
15722
3d1ca3435ebb
(svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents:
14868
diff
changeset
|
111 /* 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
|
112 { |
3d1ca3435ebb
(svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents:
14868
diff
changeset
|
113 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
|
114 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
|
115 |
3d1ca3435ebb
(svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents:
14868
diff
changeset
|
116 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
|
117 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
|
118 } |
3d1ca3435ebb
(svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
rubidium <rubidium@openttd.org>
parents:
14868
diff
changeset
|
119 |
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
|
120 /* 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
|
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 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
|
123 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
|
124 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11849
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 } |
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
|
129 |
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
|
130 /* 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
|
131 { |
10768
0556b96dd731
(svn r15101) -Change [API CHANGE]: more consistant naming for consts:
truebrain <truebrain@openttd.org>
parents:
10696
diff
changeset
|
132 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
|
133 |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
134 if (order_position == ORDER_CURRENT) { |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17162
diff
changeset
|
135 int cur_order_pos = ::Vehicle::Get(vehicle_id)->cur_real_order_index; |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
136 const Order *order = ::Vehicle::Get(vehicle_id)->GetOrder(0); |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
137 if (order == NULL) return ORDER_INVALID; |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
138 int num_automatic_orders = 0; |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
139 for (int i = 0; i < cur_order_pos; i++) { |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
140 if (order->GetType() == OT_AUTOMATIC) num_automatic_orders++; |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
141 order = order->next; |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
142 } |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
143 return (AIOrder::OrderPosition)(cur_order_pos - num_automatic_orders); |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
144 } |
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
145 return (order_position >= 0 && order_position < ::Vehicle::Get(vehicle_id)->GetNumManualOrders()) ? 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
|
146 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
147 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
148 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
149 /* 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
|
150 { |
13980
4d50ab271097
(svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents:
13939
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 /* 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
|
156 ((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
|
157 ((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
|
158 ((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
|
159 ((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
|
160 ((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
|
161 ((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
|
162 |
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
|
163 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
|
164 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
|
165 ((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
|
166 |
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
|
167 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
|
168 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
|
169 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
170 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
171 |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
172 /* 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
|
173 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
174 switch (condition) { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
175 case OC_LOAD_PERCENTAGE: |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
176 case OC_RELIABILITY: |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
177 case OC_MAX_SPEED: |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
178 case OC_AGE: |
11176
924587d9da82
(svn r15527) -Fix (r15526): A ')' too much.
yexo <yexo@openttd.org>
parents:
11175
diff
changeset
|
179 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
|
180 |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
181 case OC_REQUIRES_SERVICE: |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
182 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
|
183 |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
184 case OC_UNCONDITIONALLY: |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
185 return true; |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
186 |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
187 default: return false; |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
188 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
189 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
190 |
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
|
191 /* 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
|
192 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11849
diff
changeset
|
193 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
|
194 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
195 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
196 /* 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
|
197 { |
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 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
|
199 |
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
|
200 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
|
201 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
|
202 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
|
203 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
204 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
|
205 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
|
206 /* 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
|
207 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
|
208 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11849
diff
changeset
|
209 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
|
210 /* 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
|
211 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
|
212 if (!st->airport.HasHangar()) return INVALID_TILE; |
14868
9ae8ffb9d4b9
(svn r19464) -Codechange: move GetHangarTile to Airport
yexo <yexo@openttd.org>
parents:
14867
diff
changeset
|
213 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
|
214 } |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
215 |
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
|
216 case OT_GOTO_STATION: { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11849
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 } |
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
|
222 } 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
|
223 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
|
224 } 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
|
225 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
|
226 } 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
|
227 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
|
228 } 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
|
229 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
|
230 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
|
231 } |
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
|
232 } |
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
|
233 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
|
234 } |
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
|
235 |
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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 } |
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
|
242 } |
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
|
243 /* 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
|
244 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
|
245 } |
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
|
246 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
|
247 } |
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 |
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 /* 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
|
251 { |
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 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
|
253 |
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
|
254 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
|
255 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
|
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 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
266 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
|
267 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
|
268 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
|
269 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
|
270 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
271 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
|
272 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
273 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
274 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
|
275 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
276 |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
277 /* 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
|
278 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
279 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
|
280 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
|
281 |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
282 const Order *order = ::ResolveOrder(vehicle_id, order_position); |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
283 return (OrderPosition)order->GetConditionSkipToOrder(); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
284 } |
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 /* 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
|
287 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
288 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
|
289 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
|
290 |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
291 const Order *order = ::ResolveOrder(vehicle_id, order_position); |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
292 return (OrderCondition)order->GetConditionVariable(); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
293 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
294 |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
295 /* 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
|
296 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
297 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
|
298 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
|
299 |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
300 const Order *order = ::ResolveOrder(vehicle_id, order_position); |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
301 return (CompareFunction)order->GetConditionComparator(); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
302 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
303 |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
304 /* 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
|
305 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
306 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
|
307 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
|
308 |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
309 const Order *order = ::ResolveOrder(vehicle_id, order_position); |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
310 int32 value = order->GetConditionValue(); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
311 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
|
312 return value; |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
313 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
314 |
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
|
315 /* 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
|
316 { |
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
|
317 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
|
318 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
|
319 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
|
320 |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
321 const Order *order = ::ResolveOrder(vehicle_id, order_position); |
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
|
322 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
|
323 } |
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
|
324 |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
325 /* 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
|
326 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
327 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
328 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
|
329 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
|
330 |
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
|
331 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
|
332 } |
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 /* 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
|
335 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
336 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
337 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
|
338 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
|
339 |
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
|
340 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
|
341 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
342 |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
343 /* 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
|
344 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
345 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
346 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
|
347 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
|
348 |
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
|
349 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
|
350 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
351 |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
352 /* 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
|
353 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
354 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
355 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
|
356 EnforcePrecondition(false, value >= 0 && value < 2048); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
357 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
|
358 |
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
|
359 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
|
360 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
361 |
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
|
362 /* 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
|
363 { |
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
|
364 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
|
365 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
|
366 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
|
367 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
|
368 |
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
|
369 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
|
370 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
|
371 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
|
372 } |
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
|
373 |
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
|
374 /* 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
|
375 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
376 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
377 EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags)); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
378 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11849
diff
changeset
|
379 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
|
380 } |
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 |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
382 /* 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
|
383 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
384 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
385 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to)); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
386 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11849
diff
changeset
|
387 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
|
388 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
389 |
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
|
390 /* 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
|
391 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
392 /* 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
|
393 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
|
394 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
395 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
|
396 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
|
397 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
|
398 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
399 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
|
400 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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 } 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
|
410 /* 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
|
411 * 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
|
412 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
|
413 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
|
414 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
|
415 } else { |
4d50ab271097
(svn r18518) -Add [NoAI]: AIOrder::AIOF_GOTO_NEAREST_DEPOT for goto nearest depot orders
yexo <yexo@openttd.org>
parents:
13939
diff
changeset
|
416 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
|
417 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
|
418 } |
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
|
419 } |
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
|
420 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
|
421 } |
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
|
422 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
430 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
|
431 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
|
432 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
|
433 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
434 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
|
435 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
|
436 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
437 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
438 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
|
439 |
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
|
440 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
|
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 |
11175
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
443 /* 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
|
444 { |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
445 /* 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
|
446 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
|
447 |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
448 EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
449 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to)); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
450 |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
451 Order order; |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
452 order.MakeConditional(jump_to); |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
453 |
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
|
454 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
|
455 } |
5575028fb7e3
(svn r15526) -Add [NoAI]: Support for conditional orders.
yexo <yexo@openttd.org>
parents:
10960
diff
changeset
|
456 |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
457 /* 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
|
458 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
459 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
|
460 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
461 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
|
462 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
463 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
|
464 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
465 |
11334
6a22ff18d5a5
(svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents:
11267
diff
changeset
|
466 /* 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
|
467 { |
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
|
468 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
|
469 |
11334
6a22ff18d5a5
(svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents:
11267
diff
changeset
|
470 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order)); |
6a22ff18d5a5
(svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents:
11267
diff
changeset
|
471 |
6a22ff18d5a5
(svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents:
11267
diff
changeset
|
472 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
|
473 } |
6a22ff18d5a5
(svn r15684) -Add [NoAI]: AIOrder::SkipToOrder().
yexo <yexo@openttd.org>
parents:
11267
diff
changeset
|
474 |
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
|
475 /** |
11267
1d456bf484a1
(svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents:
11176
diff
changeset
|
476 * 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
|
477 * 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
|
478 * 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
|
479 * 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
|
480 * 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
|
481 * @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
|
482 */ |
11267
1d456bf484a1
(svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents:
11176
diff
changeset
|
483 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
|
484 { |
11267
1d456bf484a1
(svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents:
11176
diff
changeset
|
485 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
|
486 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
|
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 |
11267
1d456bf484a1
(svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents:
11176
diff
changeset
|
489 /* 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
|
490 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
491 /* 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
|
492 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
|
493 if (retry < 0) { |
11267
1d456bf484a1
(svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents:
11176
diff
changeset
|
494 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
|
495 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
|
496 } |
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 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
|
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 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
|
500 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
|
501 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
|
502 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
503 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
|
504 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
505 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
|
506 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
|
507 |
17162
18e173373bb0
(svn r21900) -Fix: [NoAI] hide automatic orders from AIs as they have no way of dealing with them
yexo <yexo@openttd.org>
parents:
17152
diff
changeset
|
508 const Order *order = ::ResolveOrder(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
|
509 |
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 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
|
511 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
512 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
|
513 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
|
514 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
515 |
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 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
|
517 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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 } |
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 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
|
525 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
526 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
|
527 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
|
528 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
|
529 } |
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 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
|
531 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
|
532 } |
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 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
|
534 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
535 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
|
536 } |
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 |
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 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
|
539 |
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 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
|
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 |
11267
1d456bf484a1
(svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents:
11176
diff
changeset
|
543 /* 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
|
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 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
|
546 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
|
547 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
|
548 /* 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
|
549 * 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
|
550 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
|
551 return AIOrder::_SetOrderFlags(); |
1d456bf484a1
(svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents:
11176
diff
changeset
|
552 } |
1d456bf484a1
(svn r15616) -Change [API CHANGE]: Rename AIOrder::ChangeOrder() to AIOrder::SetOrderFlags().
yexo <yexo@openttd.org>
parents:
11176
diff
changeset
|
553 |
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 /* 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
|
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 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
|
557 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
|
558 |
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, 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
|
560 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
|
561 |
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 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
|
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 |
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 /* 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
|
566 { |
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 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
|
568 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
|
569 |
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
|
570 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
|
571 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
572 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
573 /* 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
|
574 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
575 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
|
576 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
|
577 |
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
|
578 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
|
579 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
580 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
581 /* 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
|
582 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
583 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
|
584 |
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
|
585 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
|
586 } |