author | rubidium |
Mon, 26 Mar 2007 12:58:47 +0000 | |
branch | noai |
changeset 9548 | 9f9f003dd9b5 |
parent 9534 | 72cd7f3a32d9 |
child 9599 | 949374e83b78 |
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 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
3 |
/** @file ai_order.cpp handles the functions of the AIOrder class */ |
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" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
8 |
#include "../../command.h" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
9 |
#include "../../order.h" |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
10 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
11 |
#include "../../depot.h" |
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; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
31 |
case MP_STREET: if (::GetRoadTileType(t) == ROAD_TILE_DEPOT) return OT_GOTO_DEPOT; break; |
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 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
59 |
int32 AIOrder::GetNumberOfOrders(VehicleID vehicle_id) |
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 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
64 |
TileIndex AIOrder::GetOrderDestination(VehicleID vehicle_id, uint32 order_id) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
65 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
66 |
if (!AIOrder::IsValidVehicleOrder(vehicle_id, order_id)) return INVALID_TILE; |
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 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
71 |
switch (order->type) { |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
72 |
case OT_GOTO_DEPOT: return ::GetDepot(order->dest)->xy; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
73 |
case OT_GOTO_STATION: return ::GetStation(order->dest)->xy; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
74 |
case OT_GOTO_WAYPOINT: return ::GetWaypoint(order->dest)->xy; |
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 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
79 |
AIOrder::AIOrderFlags AIOrder::GetOrderFlags(VehicleID vehicle_id, uint32 order_id) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
80 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
81 |
if (!AIOrder::IsValidVehicleOrder(vehicle_id, order_id)) return AIOF_INVALID; |
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 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
86 |
return (AIOrder::AIOrderFlags)order->flags; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
87 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
88 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
89 |
bool AIOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
90 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
91 |
if (!AIVehicle::IsValidVehicle(vehicle_id)) return false; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
92 |
return this->InsertOrder(vehicle_id, GetVehicle(vehicle_id)->num_orders, destination, order_flags); |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
93 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
94 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
95 |
bool AIOrder::InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrder::AIOrderFlags order_flags) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
96 |
{ |
9534
72cd7f3a32d9
(svn r9456) [NoAI] -Fix: creation of new orders failed.
rubidium
parents:
9500
diff
changeset
|
97 |
/* IsValidVehicleOrder is not good enough because it does not allow appending. */ |
72cd7f3a32d9
(svn r9456) [NoAI] -Fix: creation of new orders failed.
rubidium
parents:
9500
diff
changeset
|
98 |
if (!AIVehicle::IsValidVehicle(vehicle_id) || order_id > ::GetVehicle(vehicle_id)->num_orders || |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
99 |
!this->AreOrderFlagsValid(destination, order_flags)) return false; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
100 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
101 |
Order order; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
102 |
order.type = ::GetOrderTypeByTile(destination); |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
103 |
order.flags = order_flags; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
104 |
switch (order.type) { |
9534
72cd7f3a32d9
(svn r9456) [NoAI] -Fix: creation of new orders failed.
rubidium
parents:
9500
diff
changeset
|
105 |
case OT_GOTO_DEPOT: order.dest = ::GetDepotByTile(destination)->index; break; |
72cd7f3a32d9
(svn r9456) [NoAI] -Fix: creation of new orders failed.
rubidium
parents:
9500
diff
changeset
|
106 |
case OT_GOTO_STATION: order.dest = ::GetStationIndex(destination); break; |
72cd7f3a32d9
(svn r9456) [NoAI] -Fix: creation of new orders failed.
rubidium
parents:
9500
diff
changeset
|
107 |
case OT_GOTO_WAYPOINT: order.dest = ::GetWaypointIndex(destination); break; |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
108 |
default: NOT_REACHED(); return false; |
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 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
111 |
return this->DoCommand(0, vehicle_id | (order_id << 16), PackOrder(&order), CMD_INSERT_ORDER); |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
112 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
113 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
114 |
bool AIOrder::RemoveOrder(VehicleID vehicle_id, uint32 order_id) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
115 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
116 |
if (!IsValidVehicleOrder(vehicle_id, order_id)) return false; |
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 |
return this->DoCommand(0, vehicle_id, order_id, CMD_DELETE_ORDER); |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
119 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
120 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
121 |
bool AIOrder::ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrder::AIOrderFlags order_flags) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
122 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
123 |
if (!IsValidVehicleOrder(vehicle_id, order_id) || |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
124 |
!this->AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags)) return false; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
125 |
|
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
|
126 |
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
|
127 |
/* 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
|
128 |
* the current orders of the vehicle. */ |
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
129 |
AIOrderFlags current = this->GetOrderFlags(vehicle_id, order_id); |
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
130 |
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
|
131 |
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
|
132 |
|
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
133 |
bool res = this->DoCommand(0, vehicle_id | (order_id << 16), FIND_FIRST_BIT(diff), CMD_MODIFY_ORDER); |
9f9f003dd9b5
(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
rubidium
parents:
9534
diff
changeset
|
134 |
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
|
135 |
} |
9500
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
136 |
} |
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 |
bool AIOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
139 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
140 |
if (!AIVehicle::IsValidVehicle(vehicle_id) || !AIVehicle::IsValidVehicle(main_vehicle_id)) return false; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
141 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
142 |
return this->DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_COPY, CMD_CLONE_ORDER); |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
143 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
144 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
145 |
bool AIOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
146 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
147 |
if (!AIVehicle::IsValidVehicle(vehicle_id) || !AIVehicle::IsValidVehicle(main_vehicle_id)) return false; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
148 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
149 |
return this->DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_SHARE, CMD_CLONE_ORDER); |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
150 |
} |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
151 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
152 |
bool AIOrder::UnshareOrders(VehicleID vehicle_id) |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
153 |
{ |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
154 |
if (!AIVehicle::IsValidVehicle(vehicle_id)) return false; |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
155 |
|
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
156 |
return this->DoCommand(0, vehicle_id, CO_UNSHARE, CMD_CLONE_ORDER); |
d67653613da4
(svn r9374) [NoAI] -Add: functionality to modify orders.
rubidium
parents:
diff
changeset
|
157 |
} |