author | rubidium |
Sat, 12 Apr 2008 21:38:49 +0000 | |
branch | noai |
changeset 10142 | 56ee7da4ad56 |
parent 10095 | 7483ad241067 |
child 10146 | ddbb8d2ae3ea |
permissions | -rw-r--r-- |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
2 |
|
9833
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9737
diff
changeset
|
3 |
/** @file ai_order.cpp Implementation of AIOrder. */ |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
4 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
5 |
#include "ai_order.hpp" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
6 |
#include "ai_map.hpp" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
7 |
#include "ai_vehicle.hpp" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9707
diff
changeset
|
8 |
#include "../../command_type.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9707
diff
changeset
|
9 |
#include "../../vehicle_base.h" |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
10 |
#include "../../depot.h" |
9599 | 11 |
#include "../../landscape.h" |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
12 |
#include "../../rail_map.h" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
13 |
#include "../../road_map.h" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
14 |
#include "../../station_map.h" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
15 |
#include "../../water_map.h" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
16 |
#include "../../waypoint.h" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
17 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
18 |
/** |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
19 |
* Gets the order type given a tile |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
20 |
* @param t the tile to get the order from |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
21 |
* @return the order type, or OT_END when there is no order |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
22 |
*/ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
23 |
static OrderType GetOrderTypeByTile(TileIndex t) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
24 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
25 |
if (!::IsValidTile(t)) return OT_END; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
26 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
27 |
switch (::GetTileType(t)) { |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
28 |
default: break; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
29 |
case MP_STATION: return OT_GOTO_STATION; break; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
30 |
case MP_WATER: if (::IsShipDepot(t)) return OT_GOTO_DEPOT; break; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9624
diff
changeset
|
31 |
case MP_ROAD: if (::GetRoadTileType(t) == ROAD_TILE_DEPOT) return OT_GOTO_DEPOT; break; |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
32 |
case MP_RAILWAY: |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
33 |
switch (::GetRailTileType(t)) { |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
34 |
case RAIL_TILE_DEPOT: return OT_GOTO_DEPOT; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
35 |
case RAIL_TILE_WAYPOINT: return OT_GOTO_WAYPOINT; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
36 |
default: break; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
37 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
38 |
break; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
39 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
40 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
41 |
return OT_END; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
42 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
43 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
44 |
/* static */ bool AIOrder::IsValidVehicleOrder(VehicleID vehicle_id, uint32 order_id) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
45 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
46 |
return AIVehicle::IsValidVehicle(vehicle_id) && order_id < ::GetVehicle(vehicle_id)->num_orders; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
47 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
48 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
49 |
/* static */ bool AIOrder::AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
50 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
51 |
switch (::GetOrderTypeByTile(destination)) { |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
52 |
case OT_GOTO_DEPOT: return (order_flags & ~(AIOF_NON_STOP | AIOF_SERVICE_IF_NEEDED)) == 0; |
9548
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
53 |
case OT_GOTO_STATION: return (order_flags & ~(AIOF_NON_STOP | AIOF_TRANSFER | AIOF_UNLOAD | AIOF_FULL_LOAD)) == 0 && ((order_flags & AIOF_UNLOAD) == 0 || (order_flags & AIOF_FULL_LOAD) == 0); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
54 |
case OT_GOTO_WAYPOINT: return (order_flags & ~(AIOF_NON_STOP)) == 0; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
55 |
default: return false; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
56 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
57 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
58 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
59 |
/* static */ int32 AIOrder::GetNumberOfOrders(VehicleID vehicle_id) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
60 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
61 |
return AIVehicle::IsValidVehicle(vehicle_id) ? ::GetVehicle(vehicle_id)->num_orders : -1; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
62 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
63 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
64 |
/* static */ TileIndex AIOrder::GetOrderDestination(VehicleID vehicle_id, uint32 order_id) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
65 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9723
diff
changeset
|
66 |
if (!IsValidVehicleOrder(vehicle_id, order_id)) return INVALID_TILE; |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
67 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
68 |
Order *order = ::GetVehicle(vehicle_id)->orders; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
69 |
for (uint i = 0; i < order_id; i++) order = order->next; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
70 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
71 |
switch (order->GetType()) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
72 |
case OT_GOTO_DEPOT: return ::GetDepot(order->GetDestination())->xy; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
73 |
case OT_GOTO_STATION: return ::GetStation(order->GetDestination())->xy; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
74 |
case OT_GOTO_WAYPOINT: return ::GetWaypoint(order->GetDestination())->xy; |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
75 |
default: return INVALID_TILE; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
76 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
77 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
78 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
79 |
/* static */ AIOrder::AIOrderFlags AIOrder::GetOrderFlags(VehicleID vehicle_id, uint32 order_id) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
80 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9723
diff
changeset
|
81 |
if (!IsValidVehicleOrder(vehicle_id, order_id)) return AIOF_INVALID; |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
82 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
83 |
Order *order = ::GetVehicle(vehicle_id)->orders; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
84 |
for (uint i = 0; i < order_id; i++) order = order->next; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
85 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
86 |
AIOrderFlags order_flags= AIOF_NONE; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
87 |
if (order->GetNonStopType() != ONSF_STOP_EVERYWHERE) order_flags |= AIOF_NON_STOP; |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
88 |
switch (order->GetType()) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
89 |
case OT_GOTO_DEPOT: |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
90 |
if (order->GetDepotOrderType() & ODTFB_SERVICE) order_flags |= AIOF_SERVICE_IF_NEEDED; |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
91 |
break; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
92 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
93 |
case OT_GOTO_STATION: |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
94 |
if (order->GetLoadType() & OLFB_FULL_LOAD) order_flags |= AIOF_FULL_LOAD; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
95 |
if (order->GetUnloadType() & OUFB_UNLOAD) order_flags |= AIOF_UNLOAD; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
96 |
if (order->GetUnloadType() & OUFB_TRANSFER) order_flags |= AIOF_TRANSFER; |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
97 |
break; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
98 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
99 |
default: break; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
100 |
} |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
101 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
102 |
return order_flags; |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
103 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
104 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
105 |
/* static */ bool AIOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
106 |
{ |
10093
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
107 |
EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
108 |
return InsertOrder(vehicle_id, ::GetVehicle(vehicle_id)->num_orders, destination, order_flags); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
109 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
110 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
111 |
/* static */ bool AIOrder::InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrder::AIOrderFlags order_flags) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
112 |
{ |
9534
72cd7f3a32d9
(svn r9456) [NoAI] -Fix: creation of new orders failed.
rubidium
parents:
9500
diff
changeset
|
113 |
/* IsValidVehicleOrder is not good enough because it does not allow appending. */ |
10093
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
114 |
EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); |
10095
7483ad241067
(svn r12626) [NoAI] -Fix r12623: use tabs in front of lines, not spaces
truebrain
parents:
10093
diff
changeset
|
115 |
EnforcePrecondition(false, order_id <= ::GetVehicle(vehicle_id)->num_orders); |
10093
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
116 |
EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags)); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
117 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
118 |
Order order; |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
119 |
switch (::GetOrderTypeByTile(destination)) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
120 |
case OT_GOTO_DEPOT: |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
121 |
order.MakeGoToDepot(::GetDepotByTile(destination)->index, ODTFB_PART_OF_ORDERS); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
122 |
if (order_flags & AIOF_SERVICE_IF_NEEDED) order.SetDepotOrderType(ODTFB_SERVICE); |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
123 |
break; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
124 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
125 |
case OT_GOTO_STATION: |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
126 |
order.MakeGoToStation(::GetStationIndex(destination)); |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
127 |
if (order_flags & AIOF_FULL_LOAD) order.SetLoadType(OLFB_FULL_LOAD); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
128 |
order.SetUnloadType((OrderUnloadFlags)(((order_flags & AIOF_TRANSFER) ? OUFB_TRANSFER : 0) | ((order_flags & AIOF_UNLOAD) ? OUFB_UNLOAD : 0))); |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
129 |
break; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
130 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
131 |
case OT_GOTO_WAYPOINT: |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
132 |
order.MakeGoToWaypoint(::GetWaypointIndex(destination)); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
133 |
break; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
134 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
135 |
default: |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
136 |
return false; |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
137 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
138 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
10095
diff
changeset
|
139 |
if (order_flags & AIOF_NON_STOP) order.SetNonStopType(ONSF_NO_STOP_AT_DESTINATION_STATION); |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
140 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
141 |
return AIObject::DoCommand(0, vehicle_id | (order_id << 16), order.Pack(), CMD_INSERT_ORDER); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
142 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
143 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
144 |
/* static */ bool AIOrder::RemoveOrder(VehicleID vehicle_id, uint32 order_id) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
145 |
{ |
10093
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
146 |
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_id)); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
147 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
148 |
return AIObject::DoCommand(0, vehicle_id, order_id, CMD_DELETE_ORDER); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
149 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
150 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
151 |
/* static */ bool AIOrder::ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrder::AIOrderFlags order_flags) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
152 |
{ |
10093
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
153 |
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_id)); |
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
154 |
EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags)); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
155 |
|
9548
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
156 |
for (;;) { |
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
157 |
/* Loop as long as there is a difference between the requested and |
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
158 |
* the current orders of the vehicle. */ |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
159 |
AIOrderFlags current = GetOrderFlags(vehicle_id, order_id); |
9548
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
160 |
AIOrderFlags diff = current ^ order_flags; |
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
161 |
if (diff == 0) return true; |
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
162 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
163 |
bool res = AIObject::DoCommand(0, vehicle_id | (order_id << 16), FIND_FIRST_BIT(diff), CMD_MODIFY_ORDER); |
9548
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
164 |
if (!res) return false; |
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
165 |
} |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
166 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
167 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
168 |
/* static */ bool AIOrder::MoveOrder(VehicleID vehicle_id, uint32 order_id_move, uint32 order_id_target) |
9707
a5f233287295
(svn r11273) [NoAI] -Add: added AIOrder::MoveOrder (dynaxo)
truelight
parents:
9694
diff
changeset
|
169 |
{ |
10093
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
170 |
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_id_move)); |
10095
7483ad241067
(svn r12626) [NoAI] -Fix r12623: use tabs in front of lines, not spaces
truebrain
parents:
10093
diff
changeset
|
171 |
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_id_target)); |
9707
a5f233287295
(svn r11273) [NoAI] -Add: added AIOrder::MoveOrder (dynaxo)
truelight
parents:
9694
diff
changeset
|
172 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
173 |
return AIObject::DoCommand(0, vehicle_id, order_id_move | (order_id_target << 16), CMD_MOVE_ORDER); |
9707
a5f233287295
(svn r11273) [NoAI] -Add: added AIOrder::MoveOrder (dynaxo)
truelight
parents:
9694
diff
changeset
|
174 |
} |
a5f233287295
(svn r11273) [NoAI] -Add: added AIOrder::MoveOrder (dynaxo)
truelight
parents:
9694
diff
changeset
|
175 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
176 |
/* static */ bool AIOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
177 |
{ |
10093
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
178 |
EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); |
10095
7483ad241067
(svn r12626) [NoAI] -Fix r12623: use tabs in front of lines, not spaces
truebrain
parents:
10093
diff
changeset
|
179 |
EnforcePrecondition(false, AIVehicle::IsValidVehicle(main_vehicle_id)); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
180 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
181 |
return AIObject::DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_COPY, CMD_CLONE_ORDER); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
182 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
183 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
184 |
/* static */ bool AIOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
185 |
{ |
10093
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
186 |
EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); |
10095
7483ad241067
(svn r12626) [NoAI] -Fix r12623: use tabs in front of lines, not spaces
truebrain
parents:
10093
diff
changeset
|
187 |
EnforcePrecondition(false, AIVehicle::IsValidVehicle(main_vehicle_id)); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
188 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
189 |
return AIObject::DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_SHARE, CMD_CLONE_ORDER); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
190 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
191 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
192 |
/* static */ bool AIOrder::UnshareOrders(VehicleID vehicle_id) |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
193 |
{ |
10093
b3849a19d137
(svn r12623) [NoAI] -Add: support for GetLastError in AIOrder.
rubidium
parents:
9869
diff
changeset
|
194 |
EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
195 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
196 |
return AIObject::DoCommand(0, vehicle_id, CO_UNSHARE, CMD_CLONE_ORDER); |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
197 |
} |