|
1 /* $Id$ */ |
|
2 |
|
3 /** @file ai_order.hpp Everything to query and build Orders */ |
|
4 |
|
5 #ifndef AI_ORDER_HPP |
|
6 #define AI_ORDER_HPP |
|
7 |
|
8 #include "ai_object.hpp" |
|
9 |
|
10 /** |
|
11 * Class that handles all order related functions. |
|
12 */ |
|
13 class AIOrder : public AIObject { |
|
14 public: |
|
15 /** |
|
16 * Flags that can be used to modify the behaviour of orders. |
|
17 */ |
|
18 enum AIOrderFlags { |
|
19 /** Just go to the station/depot, stop unload if possible and load if needed. */ |
|
20 AIOF_NONE = 0, |
|
21 |
|
22 /** Transfer instead of deliver the goods; only for stations. */ |
|
23 AIOF_TRANSFER = 1 << 0, |
|
24 /** Always unload the vehicle; only for stations. */ |
|
25 AIOF_UNLOAD = 1 << 1, |
|
26 /** Wait till the the vehicle is fully loaded; only for stations. */ |
|
27 AIOF_FULL_LOAD = 1 << 2, |
|
28 |
|
29 /** Service the vehicle when needed, otherwise skip this order; only for depots. */ |
|
30 AIOF_SERVICE_IF_NEEDED = 1 << 2, |
|
31 |
|
32 /** Do not stop at the stations that are passed when going to the destination. */ |
|
33 AIOF_NON_STOP = 1 << 3, |
|
34 |
|
35 /** For marking invalid order flags */ |
|
36 AIOF_INVALID = 0xFFFF, |
|
37 }; |
|
38 |
|
39 /** |
|
40 * Checks whether the given order id is valid for the given vehicle. |
|
41 * @param vehicle_id the vehicle to check the order index for. |
|
42 * @param order_id the order index to check. |
|
43 * @pre AIVehicle::IsValidVehicle(vehicle_id). |
|
44 * @return true if and only if the order_id is valid for the given vehicle. |
|
45 */ |
|
46 static bool IsValidVehicleOrder(VehicleID vehicle_id, uint32 order_id); |
|
47 |
|
48 /** |
|
49 * Checks whether the given order flags are valid for the given destination. |
|
50 * @param destination the destination of the order. |
|
51 * @param order_flags the flags given to the order. |
|
52 * @return true if and only if the order_flags are valid for the given location. |
|
53 */ |
|
54 static bool AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags); |
|
55 |
|
56 /** |
|
57 * Returns the number of orders for the given vehicle. |
|
58 * @param vehicle_id the vehicle to get the order count of. |
|
59 * @pre AIVehicle::IsValidVehicle(vehicle_id). |
|
60 * @return the number of orders for the given vehicle or a negative |
|
61 * value when the vehicle does not exist. |
|
62 */ |
|
63 int32 GetNumberOfOrders(VehicleID vehicle_id); |
|
64 |
|
65 /** |
|
66 * Gets the destination of the given order for the given vehicle. |
|
67 * @param vehicle_id the vehicle to get the destination for. |
|
68 * @param order_id the order to get the destination for. |
|
69 * @pre IsValidVehicleOrder(vehicle_id, order_id). |
|
70 * @return the destination tile of the order. |
|
71 */ |
|
72 TileIndex GetOrderDestination(VehicleID vehicle_id, uint32 order_id); |
|
73 |
|
74 /** |
|
75 * Gets the AIOrderFlags of the given order for the given vehicle. |
|
76 * @param vehicle_id the vehicle to get the destination for. |
|
77 * @param order_id the order to get the destination for. |
|
78 * @pre IsValidVehicleOrder(vehicle_id, order_id). |
|
79 * @return the AIOrderFlags of the order. |
|
80 */ |
|
81 AIOrderFlags GetOrderFlags(VehicleID vehicle_id, uint32 order_id); |
|
82 |
|
83 /** |
|
84 * Appends an order to the end of the vehicle's order list. |
|
85 * @param vehicle_id the vehicle to append the order to. |
|
86 * @param destination the destination of the order. |
|
87 * @param order_flags the flags given to the order. |
|
88 * @pre AIVehicle::IsValidVehicle(vehicle_id). |
|
89 * @pre AreOrderFlagsValid(destination, order_flags). |
|
90 * @return true if and only if the order was appended. |
|
91 */ |
|
92 bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags); |
|
93 |
|
94 /** |
|
95 * Inserts an order before the given order_id into the vehicle's order list. |
|
96 * @param vehicle_id the vehicle to add the order to. |
|
97 * @param order_id the order to place the new order before. |
|
98 * @param destination the destination of the order. |
|
99 * @param order_flags the flags given to the order. |
|
100 * @pre IsValidVehicleOrder(vehicle_id, order_id). |
|
101 * @pre AreOrderFlagsValid(destination, order_flags). |
|
102 * @return true if and only if the order was inserted. |
|
103 */ |
|
104 bool InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrderFlags order_flags); |
|
105 |
|
106 /** |
|
107 * Removes an order from the vehicle's order list. |
|
108 * @param vehicle_id the vehicle to remove the order from. |
|
109 * @param order_id the order to remove from the order list. |
|
110 * @pre AIVehicle::IsValidVehicleOrder(vehicle_id, order_id). |
|
111 * @return true if and only if the order was removed. |
|
112 */ |
|
113 bool RemoveOrder(VehicleID vehicle_id, uint32 order_id); |
|
114 |
|
115 /** |
|
116 * Changes the order flags of the given order. |
|
117 * @param vehicle_id the vehicle to change the order of. |
|
118 * @param order_id the order to change. |
|
119 * @param order_flags the new flags given to the order. |
|
120 * @pre IsValidVehicleOrder(vehicle_id, order_id). |
|
121 * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags). |
|
122 * @return true if and only if the order was changed. |
|
123 */ |
|
124 bool ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrderFlags order_flags); |
|
125 |
|
126 /** |
|
127 * Copies the orders from another vehicle. The orders of the main |
|
128 * vehicle are going to be the orders of the changed vehicle. |
|
129 * @param vehicle_id the vehicle to copy the orders to. |
|
130 * @param main_vehicle_id the vehicle to copy the orders from. |
|
131 * @pre AIVehicle::IsValidVehicle(vehicle_id). |
|
132 * @pre AIVehicle::IsValidVehicle(main_vehicle_id). |
|
133 * @return true if and only if the copying succeeded. |
|
134 */ |
|
135 bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); |
|
136 |
|
137 /** |
|
138 * Shares the orders between two vehicles. The orders of the main |
|
139 * vehicle are going to be the orders of the changed vehicle. |
|
140 * @param vehicle_id the vehicle to add to the shared order list. |
|
141 * @param main_vehicle_id the vehicle to share the orders with. |
|
142 * @pre AIVehicle::IsValidVehicle(vehicle_id). |
|
143 * @pre AIVehicle::IsValidVehicle(main_vehicle_id). |
|
144 * @return true if and only if the sharing succeeded. |
|
145 */ |
|
146 bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); |
|
147 |
|
148 /** |
|
149 * Removes the given vehicle from a shared orders list. |
|
150 * @param vehicle_id the vehicle to remove from the shared order list. |
|
151 * @pre AIVehicle::IsValidVehicle(vehicle_id). |
|
152 * @return true if and only if the unsharing succeeded. |
|
153 */ |
|
154 bool UnshareOrders(VehicleID vehicle_id); |
|
155 }; |
|
156 DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags); |
|
157 |
|
158 #ifdef DEFINE_SQUIRREL_CLASS |
|
159 void SQAIOrderRegister(Squirrel *engine) { |
|
160 DefSQClass <AIOrder> SQAIOrder("AIOrder"); |
|
161 SQAIOrder.PreRegister(engine); |
|
162 SQAIOrder.AddConstructor(engine); |
|
163 SQAIOrder.DefSQFunction(engine, &AIOrder::IsValidVehicleOrder, "IsValidVehicleOrder"); |
|
164 SQAIOrder.DefSQFunction(engine, &AIOrder::ShareOrders, "ShareOrders"); |
|
165 SQAIOrder.DefSQFunction(engine, &AIOrder::UnshareOrders, "UnshareOrders"); |
|
166 SQAIOrder.DefSQFunction(engine, &AIOrder::AreOrderFlagsValid, "AreOrderFlagsValid"); |
|
167 SQAIOrder.DefSQFunction(engine, &AIOrder::GetNumberOfOrders, "GetNumberOfOrders"); |
|
168 SQAIOrder.DefSQFunction(engine, &AIOrder::GetOrderDestination, "GetOrderDestination"); |
|
169 SQAIOrder.DefSQFunction(engine, &AIOrder::GetOrderFlags, "GetOrderFlags"); |
|
170 SQAIOrder.DefSQFunction(engine, &AIOrder::AppendOrder, "AppendOrder"); |
|
171 SQAIOrder.DefSQFunction(engine, &AIOrder::InsertOrder, "InsertOrder"); |
|
172 SQAIOrder.DefSQFunction(engine, &AIOrder::RemoveOrder, "RemoveOrder"); |
|
173 SQAIOrder.DefSQFunction(engine, &AIOrder::ChangeOrder, "ChangeOrder"); |
|
174 SQAIOrder.DefSQFunction(engine, &AIOrder::CopyOrders, "CopyOrders"); |
|
175 SQAIOrder.PostRegister(engine); |
|
176 } |
|
177 #endif /* SQUIRREL_CLASS */ |
|
178 |
|
179 #endif /* AI_ORDER_HPP */ |