author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9807 | 6c47b0584f51 |
child 9937 | 7badd14899f9 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
9090
diff
changeset
|
3 |
/** @file order_cmd.cpp Handling of orders. */ |
6351
8d0b6cce8d6d
(svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents:
6337
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1884
diff
changeset
|
6 |
#include "openttd.h" |
8784
c2e9d649a9ce
(svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents:
8767
diff
changeset
|
7 |
#include "order_base.h" |
c2e9d649a9ce
(svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents:
8767
diff
changeset
|
8 |
#include "order_func.h" |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
9 |
#include "airport.h" |
8962
1b263c69799d
(svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents:
8961
diff
changeset
|
10 |
#include "order_base.h" |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
11 |
#include "waypoint.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
12 |
#include "command_func.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8214
diff
changeset
|
13 |
#include "player_func.h" |
8763
81fadd257f67
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
8679
diff
changeset
|
14 |
#include "news_func.h" |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
15 |
#include "saveload.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1751
diff
changeset
|
16 |
#include "vehicle_gui.h" |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
17 |
#include "cargotype.h" |
7683
13e6fb7baa57
(svn r11214) -Fix [FS#1296]: planes can't use heliports so refuse these orders
glx
parents:
7653
diff
changeset
|
18 |
#include "aircraft.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8064
diff
changeset
|
19 |
#include "strings_func.h" |
8130
d2eb7d04f6e1
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
8116
diff
changeset
|
20 |
#include "core/alloc_func.hpp" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8130
diff
changeset
|
21 |
#include "functions.h" |
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8130
diff
changeset
|
22 |
#include "window_func.h" |
8211
29a8510dfd62
(svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents:
8144
diff
changeset
|
23 |
#include "settings_type.h" |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8211
diff
changeset
|
24 |
#include "string_func.h" |
8787
41d9d5adbe87
(svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium
parents:
8785
diff
changeset
|
25 |
#include "newgrf_cargo.h" |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
26 |
#include "timetable.h" |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
27 |
#include "vehicle_func.h" |
8847
426dd2d582e7
(svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz
parents:
8845
diff
changeset
|
28 |
#include "oldpool_func.h" |
8962
1b263c69799d
(svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents:
8961
diff
changeset
|
29 |
#include "depot_base.h" |
0 | 30 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8258
diff
changeset
|
31 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8258
diff
changeset
|
32 |
|
8767
5b36ebf55150
(svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium
parents:
8763
diff
changeset
|
33 |
/* DestinationID must be at least as large as every these below, because it can |
5b36ebf55150
(svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium
parents:
8763
diff
changeset
|
34 |
* be any of them |
5b36ebf55150
(svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium
parents:
8763
diff
changeset
|
35 |
*/ |
5b36ebf55150
(svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium
parents:
8763
diff
changeset
|
36 |
assert_compile(sizeof(DestinationID) >= sizeof(DepotID)); |
5b36ebf55150
(svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium
parents:
8763
diff
changeset
|
37 |
assert_compile(sizeof(DestinationID) >= sizeof(WaypointID)); |
5b36ebf55150
(svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium
parents:
8763
diff
changeset
|
38 |
assert_compile(sizeof(DestinationID) >= sizeof(StationID)); |
5b36ebf55150
(svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium
parents:
8763
diff
changeset
|
39 |
|
8268
5027ad5e70a0
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8264
diff
changeset
|
40 |
TileIndex _backup_orders_tile; |
5027ad5e70a0
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8264
diff
changeset
|
41 |
BackuppedOrders _backup_orders_data; |
5027ad5e70a0
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8264
diff
changeset
|
42 |
|
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
43 |
DEFINE_OLD_POOL_GENERIC(Order, Order); |
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
44 |
|
8834
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
45 |
void Order::Free() |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
46 |
{ |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
47 |
this->type = OT_NOTHING; |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
48 |
this->flags = 0; |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
49 |
this->dest = 0; |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
50 |
this->next = NULL; |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
51 |
} |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
52 |
|
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
53 |
void Order::MakeGoToStation(StationID destination) |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
54 |
{ |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
55 |
this->type = OT_GOTO_STATION; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
56 |
this->flags = 0; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
57 |
this->dest = destination; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
58 |
} |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
59 |
|
8853
3266f0374302
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium
parents:
8851
diff
changeset
|
60 |
void Order::MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, CargoID cargo, byte subtype) |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
61 |
{ |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
62 |
this->type = OT_GOTO_DEPOT; |
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
63 |
this->flags = 0; |
8853
3266f0374302
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium
parents:
8851
diff
changeset
|
64 |
this->SetDepotOrderType(order); |
3266f0374302
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium
parents:
8851
diff
changeset
|
65 |
if (!(order & ODTFB_PART_OF_ORDERS)) { |
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
66 |
this->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS); |
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
67 |
} |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
68 |
this->dest = destination; |
8838
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8836
diff
changeset
|
69 |
this->SetRefit(cargo, subtype); |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
70 |
} |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
71 |
|
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
72 |
void Order::MakeGoToWaypoint(WaypointID destination) |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
73 |
{ |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
74 |
this->type = OT_GOTO_WAYPOINT; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
75 |
this->flags = 0; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
76 |
this->dest = destination; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
77 |
} |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
78 |
|
8843
45fdf630deaa
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents:
8840
diff
changeset
|
79 |
void Order::MakeLoading(bool ordered) |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
80 |
{ |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
81 |
this->type = OT_LOADING; |
8843
45fdf630deaa
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents:
8840
diff
changeset
|
82 |
if (!ordered) this->flags = 0; |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
83 |
} |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
84 |
|
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
85 |
void Order::MakeLeaveStation() |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
86 |
{ |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
87 |
this->type = OT_LEAVESTATION; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
88 |
this->flags = 0; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
89 |
} |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
90 |
|
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
91 |
void Order::MakeDummy() |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
92 |
{ |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
93 |
this->type = OT_DUMMY; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
94 |
this->flags = 0; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
95 |
} |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
96 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
97 |
void Order::MakeConditional(VehicleOrderID order) |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
98 |
{ |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
99 |
this->type = OT_CONDITIONAL; |
8901
49a09bb12b4a
(svn r12668) -Fix (12667): swapping of variables went wrong.
rubidium
parents:
8900
diff
changeset
|
100 |
this->flags = order; |
49a09bb12b4a
(svn r12668) -Fix (12667): swapping of variables went wrong.
rubidium
parents:
8900
diff
changeset
|
101 |
this->dest = 0; |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
102 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
103 |
|
8838
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8836
diff
changeset
|
104 |
void Order::SetRefit(CargoID cargo, byte subtype) |
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8836
diff
changeset
|
105 |
{ |
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8836
diff
changeset
|
106 |
this->refit_cargo = cargo; |
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8836
diff
changeset
|
107 |
this->refit_subtype = subtype; |
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8836
diff
changeset
|
108 |
} |
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8836
diff
changeset
|
109 |
|
8834
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
110 |
void Order::FreeChain() |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
111 |
{ |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
112 |
if (next != NULL) next->FreeChain(); |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
113 |
delete this; |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
114 |
} |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
115 |
|
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
116 |
bool Order::Equals(const Order &other) const |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
117 |
{ |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
118 |
return |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
119 |
this->type == other.type && |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
120 |
this->flags == other.flags && |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
121 |
this->dest == other.dest; |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
122 |
} |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
123 |
|
8834
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
124 |
static bool HasOrderPoolFree(uint amount) |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
125 |
{ |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
126 |
const Order *order; |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
127 |
|
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
128 |
/* There is always room if not all blocks in the pool are reserved */ |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
129 |
if (_Order_pool.CanAllocateMoreBlocks()) return true; |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
130 |
|
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
131 |
FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true; |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
132 |
|
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
133 |
return false; |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
134 |
} |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
135 |
|
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
136 |
uint32 Order::Pack() const |
8834
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
137 |
{ |
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
138 |
return this->dest << 16 | this->flags << 8 | this->type; |
8834
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
139 |
} |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
140 |
|
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
141 |
Order::Order(uint32 packed) |
8834
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
142 |
{ |
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
143 |
this->type = (OrderType)GB(packed, 0, 8); |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
144 |
this->flags = GB(packed, 8, 8); |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
145 |
this->dest = GB(packed, 16, 16); |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
146 |
this->next = NULL; |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
147 |
this->refit_cargo = CT_NO_REFIT; |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
148 |
this->refit_subtype = 0; |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
149 |
this->wait_time = 0; |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
150 |
this->travel_time = 0; |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
151 |
} |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
152 |
|
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
153 |
void Order::ConvertFromOldSavegame() |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
154 |
{ |
9357
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
155 |
uint8 old_flags = this->flags; |
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
156 |
this->flags = 0; |
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
157 |
|
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
158 |
/* First handle non-stop */ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9390
diff
changeset
|
159 |
if (_settings_client.gui.sg_new_nonstop) { |
9356
3c40312a3b86
(svn r13253) -Codechange: simplify conversion of old orders a bit
smatz
parents:
9355
diff
changeset
|
160 |
/* OFB_NON_STOP */ |
9357
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
161 |
this->SetNonStopType((old_flags & 8) ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS); |
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
162 |
} else { |
9357
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
163 |
this->SetNonStopType((old_flags & 8) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE); |
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
164 |
} |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
165 |
|
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
166 |
switch (this->GetType()) { |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
167 |
/* Only a few types need the other savegame conversions. */ |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
168 |
case OT_GOTO_DEPOT: case OT_GOTO_STATION: case OT_LOADING: break; |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
169 |
default: return; |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
170 |
} |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
171 |
|
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
172 |
if (this->GetType() != OT_GOTO_DEPOT) { |
9357
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
173 |
/* Then the load flags */ |
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
174 |
if ((old_flags & 2) != 0) { // OFB_UNLOAD |
9355
8a3f886cf11a
(svn r13252) -Fix: when converting orders from older savegames, set 'Unload and leave empty' for 'Unload' orders
smatz
parents:
9354
diff
changeset
|
175 |
this->SetLoadType(OLFB_NO_LOAD); |
9357
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
176 |
} else if ((old_flags & 4) == 0) { // !OFB_FULL_LOAD |
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
177 |
this->SetLoadType(OLF_LOAD_IF_POSSIBLE); |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
178 |
} else { |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9390
diff
changeset
|
179 |
this->SetLoadType(_settings_client.gui.sg_full_load_any ? OLF_FULL_LOAD_ANY : OLFB_FULL_LOAD); |
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
180 |
} |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
181 |
|
9357
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
182 |
/* Finally fix the unload flags */ |
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
183 |
if ((old_flags & 1) != 0) { // OFB_TRANSFER |
8885
647cda0e9312
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium
parents:
8883
diff
changeset
|
184 |
this->SetUnloadType(OUFB_TRANSFER); |
9357
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
185 |
} else if ((old_flags & 2) != 0) { // OFB_UNLOAD |
9356
3c40312a3b86
(svn r13253) -Codechange: simplify conversion of old orders a bit
smatz
parents:
9355
diff
changeset
|
186 |
this->SetUnloadType(OUFB_UNLOAD); |
3c40312a3b86
(svn r13253) -Codechange: simplify conversion of old orders a bit
smatz
parents:
9355
diff
changeset
|
187 |
} else { |
3c40312a3b86
(svn r13253) -Codechange: simplify conversion of old orders a bit
smatz
parents:
9355
diff
changeset
|
188 |
this->SetUnloadType(OUF_UNLOAD_IF_POSSIBLE); |
8885
647cda0e9312
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium
parents:
8883
diff
changeset
|
189 |
} |
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
190 |
} else { |
9357
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
191 |
/* Then the depot action flags */ |
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
192 |
this->SetDepotActionType(((old_flags & 6) == 4) ? ODATFB_HALT : ODATF_SERVICE_ONLY); |
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
193 |
|
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
194 |
/* Finally fix the depot type flags */ |
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
195 |
uint t = ((old_flags & 6) == 6) ? ODTFB_SERVICE : ODTF_MANUAL; |
f540f1fb6bd9
(svn r13254) -Fix: waypoint orders could have invalid flags set after conversion
smatz
parents:
9356
diff
changeset
|
196 |
if ((old_flags & 2) != 0) t |= ODTFB_PART_OF_ORDERS; |
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
197 |
this->SetDepotOrderType((OrderDepotTypeFlags)t); |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
198 |
} |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
199 |
} |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
200 |
|
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
201 |
/** |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
202 |
* |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
203 |
* Unpacks a order from savegames with version 4 and lower |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
204 |
* |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
205 |
*/ |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
206 |
static Order UnpackVersion4Order(uint16 packed) |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
207 |
{ |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
208 |
return Order(GB(packed, 8, 8) << 16 | GB(packed, 4, 4) << 8 | GB(packed, 0, 4)); |
8834
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
209 |
} |
136909dfc958
(svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium
parents:
8833
diff
changeset
|
210 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
211 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
212 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
213 |
* Unpacks a order from savegames made with TTD(Patch) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
214 |
* |
0 | 215 |
*/ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
216 |
Order UnpackOldOrder(uint16 packed) |
0 | 217 |
{ |
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
218 |
Order order = UnpackVersion4Order(packed); |
0 | 219 |
|
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
220 |
/* |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
221 |
* Sanity check |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
222 |
* TTD stores invalid orders as OT_NOTHING with non-zero flags/station |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
223 |
*/ |
8926
888a242c523f
(svn r12696) -Fix: loading ancient savegames could result in invalid orders in order lists with all related problems.
rubidium
parents:
8919
diff
changeset
|
224 |
if (!order.IsValid() && packed != 0) order.MakeDummy(); |
0 | 225 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
226 |
return order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
227 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
228 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
229 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
230 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
231 |
* Updates the widgets of a vehicle which contains the order-data |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
232 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
233 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
234 |
void InvalidateVehicleOrder(const Vehicle *v) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
235 |
{ |
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6950
diff
changeset
|
236 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6950
diff
changeset
|
237 |
InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6950
diff
changeset
|
238 |
InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
239 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
240 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
241 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
242 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
243 |
* Swap two orders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
244 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
245 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
246 |
static void SwapOrders(Order *order1, Order *order2) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
247 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
248 |
Order temp_order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
249 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
250 |
temp_order = *order1; |
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
251 |
order1->AssignOrder(*order2); |
1043
44508ede2f92
(svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents:
1024
diff
changeset
|
252 |
order1->next = order2->next; |
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
253 |
order2->AssignOrder(temp_order); |
1043
44508ede2f92
(svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents:
1024
diff
changeset
|
254 |
order2->next = temp_order.next; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
255 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
256 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
257 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
258 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
259 |
* Assign data to an order (from an other order) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
260 |
* This function makes sure that the index is maintained correctly |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
261 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
262 |
*/ |
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
263 |
void Order::AssignOrder(const Order &other) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
264 |
{ |
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
265 |
this->type = other.type; |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
266 |
this->flags = other.flags; |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
267 |
this->dest = other.dest; |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
268 |
|
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
269 |
this->refit_cargo = other.refit_cargo; |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
270 |
this->refit_subtype = other.refit_subtype; |
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6950
diff
changeset
|
271 |
|
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
272 |
this->wait_time = other.wait_time; |
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
273 |
this->travel_time = other.travel_time; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
274 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
275 |
|
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
276 |
|
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
277 |
/** |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
278 |
* Delete all news items regarding defective orders about a vehicle |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
279 |
* This could kill still valid warnings (for example about void order when just |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
280 |
* another order gets added), but assume the player will notice the problems, |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
281 |
* when (s)he's changing the orders. |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
282 |
*/ |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
283 |
static void DeleteOrderWarnings(const Vehicle* v) |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
284 |
{ |
5955
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
285 |
DeleteVehicleNews(v->index, STR_TRAIN_HAS_TOO_FEW_ORDERS + v->type * 4); |
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
286 |
DeleteVehicleNews(v->index, STR_TRAIN_HAS_VOID_ORDER + v->type * 4); |
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
287 |
DeleteVehicleNews(v->index, STR_TRAIN_HAS_DUPLICATE_ENTRY + v->type * 4); |
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
288 |
DeleteVehicleNews(v->index, STR_TRAIN_HAS_INVALID_ENTRY + v->type * 4); |
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
289 |
} |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
290 |
|
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
291 |
|
6071 | 292 |
static TileIndex GetOrderLocation(const Order& o) |
293 |
{ |
|
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
294 |
switch (o.GetType()) { |
6071 | 295 |
default: NOT_REACHED(); |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
296 |
case OT_GOTO_STATION: return GetStation(o.GetDestination())->xy; |
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
297 |
case OT_GOTO_DEPOT: return GetDepot(o.GetDestination())->xy; |
6071 | 298 |
} |
299 |
} |
|
300 |
||
9609
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
301 |
static uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth = 0) |
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
302 |
{ |
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
303 |
if (cur->IsType(OT_CONDITIONAL)) { |
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
304 |
if (conditional_depth > v->num_orders) return 0; |
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
305 |
|
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
306 |
conditional_depth++; |
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
307 |
return max(GetOrderDistance(prev, &v->orders[cur->GetConditionSkipToOrder()], v, conditional_depth), |
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
308 |
GetOrderDistance(prev, (prev + 1 == &v->orders[v->num_orders]) ? v->orders : (prev + 1), v, conditional_depth)); |
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
309 |
} |
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
310 |
|
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
311 |
return DistanceManhattan(GetOrderLocation(*prev), GetOrderLocation(*cur)); |
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
312 |
} |
6071 | 313 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
314 |
/** Add an order to the orderlist of a vehicle. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
315 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
316 |
* @param flags operation to perform |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
317 |
* @param p1 various bitstuffed elements |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
318 |
* - p1 = (bit 0 - 15) - ID of the vehicle |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
319 |
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given, |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
320 |
* the order will be inserted before that one |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
321 |
* only the first 8 bits used currently (bit 16 - 23) (max 255) |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
322 |
* @param p2 packed order to insert |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
323 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6832
diff
changeset
|
324 |
CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
325 |
{ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
326 |
Vehicle *v; |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
327 |
VehicleID veh = GB(p1, 0, 16); |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
328 |
VehicleOrderID sel_ord = GB(p1, 16, 16); |
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
329 |
Order new_order(p2); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
330 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
331 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
332 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
333 |
v = GetVehicle(veh); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
334 |
|
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
335 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
336 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
337 |
/* Check if the inserted order is to the correct destination (owner, type), |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
338 |
* and has the correct flags if any */ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
339 |
switch (new_order.GetType()) { |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
340 |
case OT_GOTO_STATION: { |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
341 |
if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
342 |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
343 |
const Station *st = GetStation(new_order.GetDestination()); |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
344 |
|
6065 | 345 |
if (st->owner != OWNER_NONE && !CheckOwnership(st->owner)) { |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
346 |
return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
347 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
348 |
|
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
349 |
switch (v->type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
350 |
case VEH_TRAIN: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
351 |
if (!(st->facilities & FACIL_TRAIN)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
352 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
353 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
354 |
case VEH_ROAD: |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
355 |
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
356 |
if (!(st->facilities & FACIL_BUS_STOP)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
357 |
} else { |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
358 |
if (!(st->facilities & FACIL_TRUCK_STOP)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
359 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
360 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
361 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
362 |
case VEH_SHIP: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
363 |
if (!(st->facilities & FACIL_DOCK)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
364 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
365 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
366 |
case VEH_AIRCRAFT: |
7683
13e6fb7baa57
(svn r11214) -Fix [FS#1296]: planes can't use heliports so refuse these orders
glx
parents:
7653
diff
changeset
|
367 |
if (!(st->facilities & FACIL_AIRPORT) || !CanAircraftUseStation(v->engine_type, st)) { |
13e6fb7baa57
(svn r11214) -Fix [FS#1296]: planes can't use heliports so refuse these orders
glx
parents:
7653
diff
changeset
|
368 |
return CMD_ERROR; |
13e6fb7baa57
(svn r11214) -Fix [FS#1296]: planes can't use heliports so refuse these orders
glx
parents:
7653
diff
changeset
|
369 |
} |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
370 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
371 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
372 |
default: return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
373 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
374 |
|
8856
6b8adda843c9
(svn r12618) -Codechange: as load and unload type are now split, some case statements got ugly.
rubidium
parents:
8855
diff
changeset
|
375 |
/* Non stop not allowed for non-trains. */ |
8919
403ddceeb879
(svn r12689) -Feature: non-stop(or rather no non-stop) and via orders for road vehicles.
rubidium
parents:
8911
diff
changeset
|
376 |
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR; |
8845
f9ef3bb70e47
(svn r12595) -Codechange: hide Order's flags in the last few cases.
rubidium
parents:
8843
diff
changeset
|
377 |
|
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
378 |
/* No load and no unload are mutual exclusive. */ |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
379 |
if ((new_order.GetLoadType() & OLFB_NO_LOAD) && (new_order.GetUnloadType() & OUFB_NO_UNLOAD)) return CMD_ERROR; |
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
380 |
|
8856
6b8adda843c9
(svn r12618) -Codechange: as load and unload type are now split, some case statements got ugly.
rubidium
parents:
8855
diff
changeset
|
381 |
/* Filter invalid load/unload types. */ |
8873
d66baf98e3eb
(svn r12640) -Codechange: let GetLoadType make a difference between full load and full load any based on the patch setting instead of using the patch setting directly.
rubidium
parents:
8872
diff
changeset
|
382 |
switch (new_order.GetLoadType()) { |
9090
f73a7db3efea
(svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium
parents:
9076
diff
changeset
|
383 |
case OLF_LOAD_IF_POSSIBLE: case OLFB_FULL_LOAD: case OLF_FULL_LOAD_ANY: case OLFB_NO_LOAD: break; |
8873
d66baf98e3eb
(svn r12640) -Codechange: let GetLoadType make a difference between full load and full load any based on the patch setting instead of using the patch setting directly.
rubidium
parents:
8872
diff
changeset
|
384 |
default: return CMD_ERROR; |
d66baf98e3eb
(svn r12640) -Codechange: let GetLoadType make a difference between full load and full load any based on the patch setting instead of using the patch setting directly.
rubidium
parents:
8872
diff
changeset
|
385 |
} |
9090
f73a7db3efea
(svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium
parents:
9076
diff
changeset
|
386 |
switch (new_order.GetUnloadType()) { |
f73a7db3efea
(svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium
parents:
9076
diff
changeset
|
387 |
case OUF_UNLOAD_IF_POSSIBLE: case OUFB_UNLOAD: case OUFB_TRANSFER: case OUFB_NO_UNLOAD: break; |
f73a7db3efea
(svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium
parents:
9076
diff
changeset
|
388 |
default: return CMD_ERROR; |
f73a7db3efea
(svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium
parents:
9076
diff
changeset
|
389 |
} |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
390 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
391 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
392 |
|
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
393 |
case OT_GOTO_DEPOT: { |
8894
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
394 |
if (new_order.GetDepotActionType() != ODATFB_NEAREST_DEPOT) { |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
395 |
if (v->type == VEH_AIRCRAFT) { |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
396 |
if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
397 |
|
8894
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
398 |
const Station *st = GetStation(new_order.GetDestination()); |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
399 |
|
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
400 |
if (!CheckOwnership(st->owner) || |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
401 |
!(st->facilities & FACIL_AIRPORT) || |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
402 |
st->Airport()->nof_depots == 0 || |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
403 |
!CanAircraftUseStation(v->engine_type, st)) { |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
404 |
return CMD_ERROR; |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
405 |
} |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
406 |
} else { |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
407 |
if (!IsValidDepotID(new_order.GetDestination())) return CMD_ERROR; |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
408 |
|
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
409 |
const Depot *dp = GetDepot(new_order.GetDestination()); |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
410 |
|
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
411 |
if (!CheckOwnership(GetTileOwner(dp->xy))) return CMD_ERROR; |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
412 |
|
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
413 |
switch (v->type) { |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
414 |
case VEH_TRAIN: |
8961
fb0848956387
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz
parents:
8954
diff
changeset
|
415 |
if (!IsRailDepotTile(dp->xy)) return CMD_ERROR; |
8894
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
416 |
break; |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
417 |
|
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
418 |
case VEH_ROAD: |
8961
fb0848956387
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz
parents:
8954
diff
changeset
|
419 |
if (!IsRoadDepotTile(dp->xy)) return CMD_ERROR; |
8894
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
420 |
break; |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
421 |
|
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
422 |
case VEH_SHIP: |
8961
fb0848956387
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz
parents:
8954
diff
changeset
|
423 |
if (!IsShipDepotTile(dp->xy)) return CMD_ERROR; |
8894
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
424 |
break; |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
425 |
|
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
426 |
default: return CMD_ERROR; |
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
427 |
} |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
428 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
429 |
} else { |
8894
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
430 |
if (!IsPlayerBuildableVehicleType(v)) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
431 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
432 |
|
8919
403ddceeb879
(svn r12689) -Feature: non-stop(or rather no non-stop) and via orders for road vehicles.
rubidium
parents:
8911
diff
changeset
|
433 |
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR; |
9593
24938c3df0ac
(svn r13633) -Fix: restoring 'service at depot X' orders from the order backup failed.
rubidium
parents:
9559
diff
changeset
|
434 |
if (new_order.GetDepotOrderType() & ~(ODTFB_PART_OF_ORDERS | ((new_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0 ? ODTFB_SERVICE : 0))) return CMD_ERROR; |
8894
66472a0a6eb2
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium
parents:
8885
diff
changeset
|
435 |
if (new_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
436 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
437 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
438 |
|
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
439 |
case OT_GOTO_WAYPOINT: { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
440 |
if (v->type != VEH_TRAIN) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
441 |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
442 |
if (!IsValidWaypointID(new_order.GetDestination())) return CMD_ERROR; |
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
443 |
const Waypoint *wp = GetWaypoint(new_order.GetDestination()); |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
444 |
|
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
445 |
if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
446 |
|
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
447 |
/* Order flags can be any of the following for waypoints: |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
448 |
* [non-stop] |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
449 |
* non-stop orders (if any) are only valid for trains */ |
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8874
diff
changeset
|
450 |
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR; |
8863
8d3d2e9a89be
(svn r12630) -Fix (r12600): Missing 'break' made it impossible to add waypoints to vehicle orders.
maedhros
parents:
8862
diff
changeset
|
451 |
break; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
452 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
453 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
454 |
case OT_CONDITIONAL: { |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
455 |
VehicleOrderID skip_to = new_order.GetConditionSkipToOrder(); |
9666
fa2ee5ae35b5
(svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium
parents:
9665
diff
changeset
|
456 |
if (skip_to != 0 && skip_to >= v->num_orders) return CMD_ERROR; // Always allow jumping to the first (even when there is no order). |
fa2ee5ae35b5
(svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium
parents:
9665
diff
changeset
|
457 |
if (new_order.GetConditionVariable() > OCV_END) return CMD_ERROR; |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
458 |
|
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
459 |
OrderConditionComparator occ = new_order.GetConditionComparator(); |
9666
fa2ee5ae35b5
(svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium
parents:
9665
diff
changeset
|
460 |
if (occ > OCC_END) return CMD_ERROR; |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
461 |
switch (new_order.GetConditionVariable()) { |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
462 |
case OCV_REQUIRES_SERVICE: |
9666
fa2ee5ae35b5
(svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium
parents:
9665
diff
changeset
|
463 |
if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) return CMD_ERROR; |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
464 |
break; |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
465 |
|
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
466 |
case OCV_UNCONDITIONALLY: |
9666
fa2ee5ae35b5
(svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium
parents:
9665
diff
changeset
|
467 |
if (occ != OCC_EQUALS) return CMD_ERROR; |
fa2ee5ae35b5
(svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium
parents:
9665
diff
changeset
|
468 |
if (new_order.GetConditionValue() != 0) return CMD_ERROR; |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
469 |
break; |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
470 |
|
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
471 |
case OCV_LOAD_PERCENTAGE: |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
472 |
case OCV_RELIABILITY: |
9666
fa2ee5ae35b5
(svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium
parents:
9665
diff
changeset
|
473 |
if (new_order.GetConditionValue() > 100) return CMD_ERROR; |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
474 |
/* FALL THROUGH */ |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
475 |
default: |
9666
fa2ee5ae35b5
(svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium
parents:
9665
diff
changeset
|
476 |
if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) return CMD_ERROR; |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
477 |
break; |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
478 |
} |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
479 |
} break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
480 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
481 |
default: return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
482 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
483 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
484 |
if (sel_ord > v->num_orders) return CMD_ERROR; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
485 |
|
5922 | 486 |
if (!HasOrderPoolFree(1)) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
487 |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9390
diff
changeset
|
488 |
if (v->type == VEH_SHIP && IsHumanPlayer(v->owner) && _settings_game.pf.pathfinder_for_ships != VPF_NPF) { |
8551
f0bcd6753287
(svn r12129) -Change [FS#1759]: simplified patch settings for pathfinders (Yorick)
smatz
parents:
8469
diff
changeset
|
489 |
/* Make sure the new destination is not too far away from the previous */ |
6071 | 490 |
const Order *prev = NULL; |
491 |
uint n = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
492 |
|
6071 | 493 |
/* Find the last goto station or depot order before the insert location. |
494 |
* If the order is to be inserted at the beginning of the order list this |
|
495 |
* finds the last order in the list. */ |
|
496 |
for (const Order *o = v->orders; o != NULL; o = o->next) { |
|
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
497 |
if (o->IsType(OT_GOTO_STATION) || o->IsType(OT_GOTO_DEPOT)) prev = o; |
6071 | 498 |
if (++n == sel_ord && prev != NULL) break; |
499 |
} |
|
500 |
if (prev != NULL) { |
|
9609
91e0b517b498
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium
parents:
9593
diff
changeset
|
501 |
uint dist = GetOrderDistance(prev, &new_order, v); |
6071 | 502 |
if (dist >= 130) { |
503 |
return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO); |
|
504 |
} |
|
505 |
} |
|
0 | 506 |
} |
507 |
||
508 |
if (flags & DC_EXEC) { |
|
509 |
Vehicle *u; |
|
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7049
diff
changeset
|
510 |
Order *new_o = new Order(); |
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
511 |
new_o->AssignOrder(new_order); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
512 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
513 |
/* Create new order and link in list */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
514 |
if (v->orders == NULL) { |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
515 |
v->orders = new_o; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
516 |
} else { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
517 |
/* Try to get the previous item (we are inserting above the |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
518 |
selected) */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
519 |
Order *order = GetVehicleOrder(v, sel_ord - 1); |
0 | 520 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
521 |
if (order == NULL && GetVehicleOrder(v, sel_ord) != NULL) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
522 |
/* There is no previous item, so we are altering v->orders itself |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
523 |
But because the orders can be shared, we copy the info over |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
524 |
the v->orders, so we don't have to change the pointers of |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
525 |
all vehicles */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
526 |
SwapOrders(v->orders, new_o); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
527 |
/* Now update the next pointers */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
528 |
v->orders->next = new_o; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
529 |
} else if (order == NULL) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
530 |
/* 'sel' is a non-existing order, add him to the end */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
531 |
order = GetLastVehicleOrder(v); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
532 |
order->next = new_o; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
533 |
} else { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
534 |
/* Put the new order in between */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
535 |
new_o->next = order->next; |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
536 |
order->next = new_o; |
0 | 537 |
} |
538 |
} |
|
588 | 539 |
|
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
540 |
u = GetFirstVehicleFromSharedList(v); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
541 |
DeleteOrderWarnings(u); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
542 |
for (; u != NULL; u = u->next_shared) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
543 |
/* Increase amount of orders */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
544 |
u->num_orders++; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
545 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
546 |
/* If the orderlist was empty, assign it */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
547 |
if (u->orders == NULL) u->orders = v->orders; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
548 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
549 |
assert(v->orders == u->orders); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
550 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
551 |
/* If there is added an order before the current one, we need |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
552 |
to update the selected order */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
553 |
if (sel_ord <= u->cur_order_index) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
554 |
uint cur = u->cur_order_index + 1; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
555 |
/* Check if we don't go out of bound */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
556 |
if (cur < u->num_orders) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
557 |
u->cur_order_index = cur; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
558 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
559 |
/* Update any possible open window of the vehicle */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
560 |
InvalidateVehicleOrder(u); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
561 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
562 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
563 |
/* As we insert an order, the order to skip to will be 'wrong'. */ |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
564 |
VehicleOrderID cur_order_id = 0; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
565 |
Order *order; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
566 |
FOR_VEHICLE_ORDERS(v, order) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
567 |
if (order->IsType(OT_CONDITIONAL)) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
568 |
VehicleOrderID order_id = order->GetConditionSkipToOrder(); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
569 |
if (order_id >= sel_ord) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
570 |
order->SetConditionSkipToOrder(order_id + 1); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
571 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
572 |
if (order_id == cur_order_id) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
573 |
order->SetConditionSkipToOrder((order_id + 1) % v->num_orders); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
574 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
575 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
576 |
cur_order_id++; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
577 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
578 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
579 |
/* Make sure to rebuild the whole list */ |
9297
1cb8d7bbdc8a
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents:
9234
diff
changeset
|
580 |
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); |
0 | 581 |
} |
582 |
||
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
583 |
return CommandCost(); |
0 | 584 |
} |
585 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
586 |
/** Declone an order-list |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
587 |
* @param *dst delete the orders of this vehicle |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
588 |
* @param flags execution flags |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
589 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6832
diff
changeset
|
590 |
static CommandCost DecloneOrder(Vehicle *dst, uint32 flags) |
0 | 591 |
{ |
592 |
if (flags & DC_EXEC) { |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
593 |
DeleteVehicleOrders(dst); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
594 |
InvalidateVehicleOrder(dst); |
9297
1cb8d7bbdc8a
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents:
9234
diff
changeset
|
595 |
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0); |
0 | 596 |
} |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
597 |
return CommandCost(); |
0 | 598 |
} |
599 |
||
6336
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
600 |
/** |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
601 |
* Remove the VehicleList that shows all the vehicles with the same shared |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
602 |
* orders. |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
603 |
*/ |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
604 |
static void RemoveSharedOrderVehicleList(Vehicle *v) |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
605 |
{ |
6370
bcf7979ecc4f
(svn r9429) -Fix r9338: when deleting a vehicle which has shared orders with one more vehicle and no orders, segfaulted
truelight
parents:
6351
diff
changeset
|
606 |
assert(v->orders != NULL); |
6336
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
607 |
WindowClass window_class = WC_NONE; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
608 |
|
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
609 |
switch (v->type) { |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
610 |
default: NOT_REACHED(); |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
611 |
case VEH_TRAIN: window_class = WC_TRAINS_LIST; break; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
612 |
case VEH_ROAD: window_class = WC_ROADVEH_LIST; break; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
613 |
case VEH_SHIP: window_class = WC_SHIPS_LIST; break; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
614 |
case VEH_AIRCRAFT: window_class = WC_AIRCRAFT_LIST; break; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
615 |
} |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
616 |
DeleteWindowById(window_class, (v->orders->index << 16) | (v->type << 11) | VLW_SHARED_ORDERS | v->owner); |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
617 |
} |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
618 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
619 |
/** Delete an order from the orderlist of a vehicle. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
620 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
621 |
* @param flags operation to perform |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
622 |
* @param p1 the ID of the vehicle |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
623 |
* @param p2 the order to delete (max 255) |
0 | 624 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6832
diff
changeset
|
625 |
CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 626 |
{ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
627 |
Vehicle *v, *u; |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
628 |
VehicleID veh_id = p1; |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
629 |
VehicleOrderID sel_ord = p2; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
630 |
Order *order; |
0 | 631 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
632 |
if (!IsValidVehicleID(veh_id)) return CMD_ERROR; |
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
633 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
634 |
v = GetVehicle(veh_id); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
635 |
|
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
636 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
637 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
638 |
/* If we did not select an order, we maybe want to de-clone the orders */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
639 |
if (sel_ord >= v->num_orders) |
0 | 640 |
return DecloneOrder(v, flags); |
641 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
642 |
order = GetVehicleOrder(v, sel_ord); |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
643 |
if (order == NULL) return CMD_ERROR; |
0 | 644 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
645 |
if (flags & DC_EXEC) { |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
646 |
if (GetVehicleOrder(v, sel_ord - 1) == NULL) { |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
647 |
if (GetVehicleOrder(v, sel_ord + 1) != NULL) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
648 |
/* First item, but not the last, so we need to alter v->orders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
649 |
Because we can have shared order, we copy the data |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
650 |
from the next item over the deleted */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
651 |
order = GetVehicleOrder(v, sel_ord + 1); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
652 |
SwapOrders(v->orders, order); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
653 |
} else { |
6336
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
654 |
/* XXX -- The system currently can't handle a shared-order vehicle list |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
655 |
* open when there aren't any orders in the list, so close the window |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
656 |
* in this case. Of course it needs a better fix later */ |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
657 |
RemoveSharedOrderVehicleList(v); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
658 |
/* Last item, so clean the list */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
659 |
v->orders = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
660 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
661 |
} else { |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
662 |
GetVehicleOrder(v, sel_ord - 1)->next = order->next; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
663 |
} |
0 | 664 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
665 |
/* Give the item free */ |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
666 |
order->Free(); |
0 | 667 |
|
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
668 |
u = GetFirstVehicleFromSharedList(v); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
669 |
DeleteOrderWarnings(u); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
670 |
for (; u != NULL; u = u->next_shared) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
671 |
u->num_orders--; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
672 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
673 |
if (sel_ord < u->cur_order_index) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
674 |
u->cur_order_index--; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
675 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
676 |
/* If we removed the last order, make sure the shared vehicles |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
677 |
* also set their orders to NULL */ |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
678 |
if (v->orders == NULL) u->orders = NULL; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
679 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
680 |
assert(v->orders == u->orders); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
681 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
682 |
/* NON-stop flag is misused to see if a train is in a station that is |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
683 |
* on his order list or not */ |
8843
45fdf630deaa
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents:
8840
diff
changeset
|
684 |
if (sel_ord == u->cur_order_index && u->current_order.IsType(OT_LOADING)) { |
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
685 |
u->current_order.SetNonStopType(ONSF_STOP_EVERYWHERE); |
0 | 686 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
687 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
688 |
/* Update any possible open window of the vehicle */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
689 |
InvalidateVehicleOrder(u); |
0 | 690 |
} |
588 | 691 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
692 |
/* As we delete an order, the order to skip to will be 'wrong'. */ |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
693 |
VehicleOrderID cur_order_id = 0; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
694 |
FOR_VEHICLE_ORDERS(v, order) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
695 |
if (order->IsType(OT_CONDITIONAL)) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
696 |
VehicleOrderID order_id = order->GetConditionSkipToOrder(); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
697 |
if (order_id >= sel_ord) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
698 |
order->SetConditionSkipToOrder(max(order_id - 1, 0)); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
699 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
700 |
if (order_id == cur_order_id) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
701 |
order->SetConditionSkipToOrder((order_id + 1) % v->num_orders); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
702 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
703 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
704 |
cur_order_id++; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
705 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
706 |
|
9297
1cb8d7bbdc8a
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents:
9234
diff
changeset
|
707 |
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); |
0 | 708 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
709 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
710 |
return CommandCost(); |
0 | 711 |
} |
712 |
||
6794
feec0fe8e824
(svn r10033) -Feature [FS#760]: skip to the selected order in the order list when clicking on the "skip" button while pressing CTRL.
rubidium
parents:
6638
diff
changeset
|
713 |
/** Goto order of order-list. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
714 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
715 |
* @param flags operation to perform |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
716 |
* @param p1 The ID of the vehicle which order is skipped |
6794
feec0fe8e824
(svn r10033) -Feature [FS#760]: skip to the selected order in the order list when clicking on the "skip" button while pressing CTRL.
rubidium
parents:
6638
diff
changeset
|
717 |
* @param p2 the selected order to which we want to skip |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
718 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6832
diff
changeset
|
719 |
CommandCost CmdSkipToOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 720 |
{ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
721 |
Vehicle *v; |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
722 |
VehicleID veh_id = p1; |
6794
feec0fe8e824
(svn r10033) -Feature [FS#760]: skip to the selected order in the order list when clicking on the "skip" button while pressing CTRL.
rubidium
parents:
6638
diff
changeset
|
723 |
VehicleOrderID sel_ord = p2; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
724 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
725 |
if (!IsValidVehicleID(veh_id)) return CMD_ERROR; |
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
726 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
727 |
v = GetVehicle(veh_id); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
728 |
|
6794
feec0fe8e824
(svn r10033) -Feature [FS#760]: skip to the selected order in the order list when clicking on the "skip" button while pressing CTRL.
rubidium
parents:
6638
diff
changeset
|
729 |
if (!CheckOwnership(v->owner) || sel_ord == v->cur_order_index || |
feec0fe8e824
(svn r10033) -Feature [FS#760]: skip to the selected order in the order list when clicking on the "skip" button while pressing CTRL.
rubidium
parents:
6638
diff
changeset
|
730 |
sel_ord >= v->num_orders || v->num_orders < 2) return CMD_ERROR; |
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
919
diff
changeset
|
731 |
|
0 | 732 |
if (flags & DC_EXEC) { |
6794
feec0fe8e824
(svn r10033) -Feature [FS#760]: skip to the selected order in the order list when clicking on the "skip" button while pressing CTRL.
rubidium
parents:
6638
diff
changeset
|
733 |
v->cur_order_index = sel_ord; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
734 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
735 |
if (v->type == VEH_ROAD) ClearSlot(v); |
0 | 736 |
|
8843
45fdf630deaa
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents:
8840
diff
changeset
|
737 |
if (v->current_order.IsType(OT_LOADING)) v->LeaveStation(); |
0 | 738 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
739 |
InvalidateVehicleOrder(v); |
0 | 740 |
} |
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
919
diff
changeset
|
741 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
742 |
/* We have an aircraft/ship, they have a mini-schedule, so update them all */ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
743 |
if (v->type == VEH_AIRCRAFT) InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
744 |
if (v->type == VEH_SHIP) InvalidateWindowClasses(WC_SHIPS_LIST); |
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
919
diff
changeset
|
745 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
746 |
return CommandCost(); |
0 | 747 |
} |
748 |
||
6832
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
749 |
/** |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
750 |
* Move an order inside the orderlist |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
751 |
* @param tile unused |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
752 |
* @param p1 the ID of the vehicle |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
753 |
* @param p2 order to move and target |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
754 |
* bit 0-15 : the order to move |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
755 |
* bit 16-31 : the target order |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
756 |
* @note The target order will move one place down in the orderlist |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
757 |
* if you move the order upwards else it'll move it one place down |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
758 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6832
diff
changeset
|
759 |
CommandCost CmdMoveOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
6832
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
760 |
{ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
761 |
VehicleID veh = p1; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
762 |
VehicleOrderID moving_order = GB(p2, 0, 16); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
763 |
VehicleOrderID target_order = GB(p2, 16, 16); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
764 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
765 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
766 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
767 |
Vehicle *v = GetVehicle(veh); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
768 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
769 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
770 |
/* Don't make senseless movements */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
771 |
if (moving_order >= v->num_orders || target_order >= v->num_orders || |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
772 |
moving_order == target_order || v->num_orders <= 1) |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
773 |
return CMD_ERROR; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
774 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
775 |
Order *moving_one = GetVehicleOrder(v, moving_order); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
776 |
/* Don't move an empty order */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
777 |
if (moving_one == NULL) return CMD_ERROR; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
778 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
779 |
if (flags & DC_EXEC) { |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
780 |
/* Take the moving order out of the pointer-chain */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
781 |
Order *one_before = GetVehicleOrder(v, moving_order - 1); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
782 |
Order *one_past = GetVehicleOrder(v, moving_order + 1); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
783 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
784 |
if (one_before == NULL) { |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
785 |
/* First order edit */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
786 |
v->orders = moving_one->next; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
787 |
} else { |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
788 |
one_before->next = moving_one->next; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
789 |
} |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
790 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
791 |
/* Insert the moving_order again in the pointer-chain */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
792 |
one_before = GetVehicleOrder(v, target_order - 1); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
793 |
one_past = GetVehicleOrder(v, target_order); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
794 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
795 |
moving_one->next = one_past; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
796 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
797 |
if (one_before == NULL) { |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
798 |
/* first order edit */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
799 |
SwapOrders(v->orders, moving_one); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
800 |
v->orders->next = moving_one; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
801 |
} else { |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
802 |
one_before->next = moving_one; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
803 |
} |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
804 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
805 |
/* Update shared list */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
806 |
Vehicle *u = GetFirstVehicleFromSharedList(v); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
807 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
808 |
DeleteOrderWarnings(u); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
809 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
810 |
for (; u != NULL; u = u->next_shared) { |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
811 |
/* Update the first order */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
812 |
if (u->orders != v->orders) u->orders = v->orders; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
813 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
814 |
/* Update the current order */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
815 |
if (u->cur_order_index == moving_order) { |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
816 |
u->cur_order_index = target_order; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
817 |
} else if(u->cur_order_index > moving_order && u->cur_order_index <= target_order) { |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
818 |
u->cur_order_index--; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
819 |
} else if(u->cur_order_index < moving_order && u->cur_order_index >= target_order) { |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
820 |
u->cur_order_index++; |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
821 |
} |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
822 |
|
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
823 |
assert(v->orders == u->orders); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
824 |
/* Update any possible open window of the vehicle */ |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
825 |
InvalidateVehicleOrder(u); |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
826 |
} |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
827 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
828 |
/* As we move an order, the order to skip to will be 'wrong'. */ |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
829 |
Order *order; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
830 |
FOR_VEHICLE_ORDERS(v, order) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
831 |
if (order->IsType(OT_CONDITIONAL)) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
832 |
VehicleOrderID order_id = order->GetConditionSkipToOrder(); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
833 |
if (order_id == moving_order) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
834 |
order_id = target_order; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
835 |
} else if(order_id > moving_order && order_id <= target_order) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
836 |
order_id--; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
837 |
} else if(order_id < moving_order && order_id >= target_order) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
838 |
order_id++; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
839 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
840 |
order->SetConditionSkipToOrder(order_id); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
841 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
842 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
843 |
|
6832
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
844 |
/* Make sure to rebuild the whole list */ |
9297
1cb8d7bbdc8a
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents:
9234
diff
changeset
|
845 |
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); |
6832
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
846 |
} |
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
847 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
848 |
return CommandCost(); |
6832
fec0caeac27d
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium
parents:
6794
diff
changeset
|
849 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
850 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
851 |
/** Modify an order in the orderlist of a vehicle. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
852 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
853 |
* @param flags operation to perform |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
854 |
* @param p1 various bitstuffed elements |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
855 |
* - p1 = (bit 0 - 15) - ID of the vehicle |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
856 |
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given, |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
857 |
* the order will be inserted before that one |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
858 |
* only the first 8 bits used currently (bit 16 - 23) (max 255) |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
859 |
* @param p2 various bitstuffed elements |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
860 |
* - p2 = (bit 0 - 3) - what data to modify (@see ModifyOrderFlags) |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
861 |
* - p2 = (bit 4 - 15) - the data to modify |
0 | 862 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6832
diff
changeset
|
863 |
CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 864 |
{ |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
865 |
VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits. |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
866 |
VehicleID veh = GB(p1, 0, 16); |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
867 |
ModifyOrderFlags mof = (ModifyOrderFlags)GB(p2, 0, 4); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
868 |
uint16 data = GB(p2, 4, 11); |
0 | 869 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
870 |
if (mof >= MOF_END) return CMD_ERROR; |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
871 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
872 |
|
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
873 |
Vehicle *v = GetVehicle(veh); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
874 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
875 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
876 |
/* Is it a valid order? */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
877 |
if (sel_ord >= v->num_orders) return CMD_ERROR; |
0 | 878 |
|
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
879 |
Order *order = GetVehicleOrder(v, sel_ord); |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
880 |
switch (order->GetType()) { |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
881 |
case OT_GOTO_STATION: |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
882 |
if (mof == MOF_COND_VARIABLE || mof == MOF_COND_COMPARATOR || mof == MOF_DEPOT_ACTION || mof == MOF_COND_VALUE || GetStation(order->GetDestination())->IsBuoy()) return CMD_ERROR; |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
883 |
break; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
884 |
|
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
885 |
case OT_GOTO_DEPOT: |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
886 |
if (mof != MOF_NON_STOP && mof != MOF_DEPOT_ACTION) return CMD_ERROR; |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
887 |
break; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
888 |
|
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
889 |
case OT_GOTO_WAYPOINT: |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
890 |
if (mof != MOF_NON_STOP) return CMD_ERROR; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
891 |
break; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
892 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
893 |
case OT_CONDITIONAL: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
894 |
if (mof != MOF_COND_VARIABLE && mof != MOF_COND_COMPARATOR && mof != MOF_COND_VALUE) return CMD_ERROR; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
895 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
896 |
|
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
897 |
default: |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
898 |
return CMD_ERROR; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
899 |
} |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
900 |
|
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
901 |
switch (mof) { |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
902 |
default: NOT_REACHED(); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
903 |
|
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
904 |
case MOF_NON_STOP: |
8919
403ddceeb879
(svn r12689) -Feature: non-stop(or rather no non-stop) and via orders for road vehicles.
rubidium
parents:
8911
diff
changeset
|
905 |
if (v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR; |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
906 |
if (data >= ONSF_END) return CMD_ERROR; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
907 |
if (data == order->GetNonStopType()) return CMD_ERROR; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
908 |
break; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
909 |
|
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
910 |
case MOF_UNLOAD: |
8883
baee554a9449
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium
parents:
8881
diff
changeset
|
911 |
if ((data & ~(OUFB_UNLOAD | OUFB_TRANSFER | OUFB_NO_UNLOAD)) != 0) return CMD_ERROR; |
baee554a9449
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium
parents:
8881
diff
changeset
|
912 |
/* Unload and no-unload are mutual exclusive and so are transfer and no unload. */ |
baee554a9449
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium
parents:
8881
diff
changeset
|
913 |
if (data != 0 && ((data & (OUFB_UNLOAD | OUFB_TRANSFER)) != 0) == ((data & OUFB_NO_UNLOAD) != 0)) return CMD_ERROR; |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
914 |
if (data == order->GetUnloadType()) return CMD_ERROR; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
915 |
break; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
916 |
|
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
917 |
case MOF_LOAD: |
8883
baee554a9449
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium
parents:
8881
diff
changeset
|
918 |
if (data > OLFB_NO_LOAD || data == 1) return CMD_ERROR; |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
919 |
if (data == order->GetLoadType()) return CMD_ERROR; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
920 |
break; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
921 |
|
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
922 |
case MOF_DEPOT_ACTION: |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
923 |
if (data != 0) return CMD_ERROR; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
924 |
break; |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
925 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
926 |
case MOF_COND_VARIABLE: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
927 |
if (data >= OCV_END) return CMD_ERROR; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
928 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
929 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
930 |
case MOF_COND_COMPARATOR: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
931 |
if (data >= OCC_END) return CMD_ERROR; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
932 |
switch (order->GetConditionVariable()) { |
8903
04bcd0e7d4d6
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium
parents:
8901
diff
changeset
|
933 |
case OCV_UNCONDITIONALLY: return CMD_ERROR; |
04bcd0e7d4d6
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium
parents:
8901
diff
changeset
|
934 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
935 |
case OCV_REQUIRES_SERVICE: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
936 |
if (data != OCC_IS_TRUE && data != OCC_IS_FALSE) return CMD_ERROR; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
937 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
938 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
939 |
default: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
940 |
if (data == OCC_IS_TRUE || data == OCC_IS_FALSE) return CMD_ERROR; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
941 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
942 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
943 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
944 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
945 |
case MOF_COND_VALUE: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
946 |
switch (order->GetConditionVariable()) { |
8903
04bcd0e7d4d6
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium
parents:
8901
diff
changeset
|
947 |
case OCV_UNCONDITIONALLY: return CMD_ERROR; |
04bcd0e7d4d6
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium
parents:
8901
diff
changeset
|
948 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
949 |
case OCV_LOAD_PERCENTAGE: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
950 |
case OCV_RELIABILITY: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
951 |
if (data > 100) return CMD_ERROR; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
952 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
953 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
954 |
default: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
955 |
if (data > 2047) return CMD_ERROR; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
956 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
957 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
958 |
break; |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
959 |
|
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
960 |
case MOF_COND_DESTINATION: |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
961 |
if (data >= v->num_orders) return CMD_ERROR; |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
962 |
break; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
963 |
} |
0 | 964 |
|
965 |
if (flags & DC_EXEC) { |
|
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
966 |
switch (mof) { |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
967 |
case MOF_NON_STOP: |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
968 |
order->SetNonStopType((OrderNonStopFlags)data); |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
969 |
break; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
970 |
|
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
971 |
case MOF_UNLOAD: |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
972 |
order->SetUnloadType((OrderUnloadFlags)data); |
8885
647cda0e9312
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium
parents:
8883
diff
changeset
|
973 |
if ((data & OUFB_NO_UNLOAD) != 0 && (order->GetLoadType() & OLFB_NO_LOAD) != 0) { |
8883
baee554a9449
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium
parents:
8881
diff
changeset
|
974 |
order->SetLoadType((OrderLoadFlags)(order->GetLoadType() & ~OLFB_NO_LOAD)); |
baee554a9449
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium
parents:
8881
diff
changeset
|
975 |
} |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
976 |
break; |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
977 |
|
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
978 |
case MOF_LOAD: |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
979 |
order->SetLoadType((OrderLoadFlags)data); |
8885
647cda0e9312
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium
parents:
8883
diff
changeset
|
980 |
if ((data & OLFB_NO_LOAD) != 0 && (order->GetUnloadType() & OUFB_NO_UNLOAD) != 0) { |
647cda0e9312
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium
parents:
8883
diff
changeset
|
981 |
/* No load + no unload isn't compatible */ |
647cda0e9312
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium
parents:
8883
diff
changeset
|
982 |
order->SetUnloadType((OrderUnloadFlags)(order->GetUnloadType() & ~OUFB_NO_UNLOAD)); |
8883
baee554a9449
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium
parents:
8881
diff
changeset
|
983 |
} |
8845
f9ef3bb70e47
(svn r12595) -Codechange: hide Order's flags in the last few cases.
rubidium
parents:
8843
diff
changeset
|
984 |
break; |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
985 |
|
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
986 |
case MOF_DEPOT_ACTION: |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
987 |
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() ^ ODTFB_SERVICE)); |
8845
f9ef3bb70e47
(svn r12595) -Codechange: hide Order's flags in the last few cases.
rubidium
parents:
8843
diff
changeset
|
988 |
break; |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
989 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
990 |
case MOF_COND_VARIABLE: { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
991 |
order->SetConditionVariable((OrderConditionVariable)data); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
992 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
993 |
OrderConditionComparator occ = order->GetConditionComparator(); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
994 |
switch (order->GetConditionVariable()) { |
8903
04bcd0e7d4d6
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium
parents:
8901
diff
changeset
|
995 |
case OCV_UNCONDITIONALLY: |
04bcd0e7d4d6
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium
parents:
8901
diff
changeset
|
996 |
order->SetConditionComparator(OCC_EQUALS); |
04bcd0e7d4d6
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium
parents:
8901
diff
changeset
|
997 |
order->SetConditionValue(0); |
04bcd0e7d4d6
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium
parents:
8901
diff
changeset
|
998 |
break; |
04bcd0e7d4d6
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium
parents:
8901
diff
changeset
|
999 |
|
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1000 |
case OCV_REQUIRES_SERVICE: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1001 |
if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) order->SetConditionComparator(OCC_IS_TRUE); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1002 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1003 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1004 |
case OCV_LOAD_PERCENTAGE: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1005 |
case OCV_RELIABILITY: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1006 |
if (order->GetConditionValue() > 100) order->SetConditionValue(100); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1007 |
/* FALL THROUGH */ |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1008 |
default: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1009 |
if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) order->SetConditionComparator(OCC_EQUALS); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1010 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1011 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1012 |
} break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1013 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1014 |
case MOF_COND_COMPARATOR: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1015 |
order->SetConditionComparator((OrderConditionComparator)data); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1016 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1017 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1018 |
case MOF_COND_VALUE: |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1019 |
order->SetConditionValue(data); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1020 |
break; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1021 |
|
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1022 |
case MOF_COND_DESTINATION: |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1023 |
order->SetConditionSkipToOrder(data); |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1024 |
break; |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1025 |
|
8845
f9ef3bb70e47
(svn r12595) -Codechange: hide Order's flags in the last few cases.
rubidium
parents:
8843
diff
changeset
|
1026 |
default: NOT_REACHED(); |
0 | 1027 |
} |
1028 |
||
1760
efa84b242ba1
(svn r2264) - Fix: [ 1060686 1187655 ] Changing the full-load flag on the current order doesn't take effect immediately. (glx)
matthijs
parents:
1752
diff
changeset
|
1029 |
/* Update the windows and full load flags, also for vehicles that share the same order list */ |
8869
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
1030 |
Vehicle *u = GetFirstVehicleFromSharedList(v); |
8a3dac8dc505
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium
parents:
8866
diff
changeset
|
1031 |
DeleteOrderWarnings(u); |
8872
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1032 |
for (; u != NULL; u = u->next_shared) { |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1033 |
/* Toggle u->current_order "Full load" flag if it changed. |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1034 |
* However, as the same flag is used for depot orders, check |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1035 |
* whether we are not going to a depot as there are three |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1036 |
* cases where the full load flag can be active and only |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1037 |
* one case where the flag is used for depot orders. In the |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1038 |
* other cases for the OrderTypeByte the flags are not used, |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1039 |
* so do not care and those orders should not be active |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1040 |
* when this function is called. |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1041 |
*/ |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1042 |
if (sel_ord == u->cur_order_index && |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1043 |
(u->current_order.IsType(OT_GOTO_STATION) || u->current_order.IsType(OT_LOADING)) && |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1044 |
u->current_order.GetLoadType() != order->GetLoadType()) { |
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1045 |
u->current_order.SetLoadType(order->GetLoadType()); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1046 |
} |
8872
76d52c12695d
(svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium
parents:
8869
diff
changeset
|
1047 |
InvalidateVehicleOrder(u); |
0 | 1048 |
} |
1049 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1050 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
1051 |
return CommandCost(); |
0 | 1052 |
} |
1053 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1054 |
/** Clone/share/copy an order-list of an other vehicle. |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
1055 |
* @param tile unused |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
1056 |
* @param flags operation to perform |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1057 |
* @param p1 various bitstuffed elements |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1058 |
* - p1 = (bit 0-15) - destination vehicle to clone orders to (p1 & 0xFFFF) |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1059 |
* - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE) |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1060 |
* @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1061 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6832
diff
changeset
|
1062 |
CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1063 |
{ |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1064 |
Vehicle *dst; |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
1065 |
VehicleID veh_src = GB(p1, 16, 16); |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
1066 |
VehicleID veh_dst = GB(p1, 0, 16); |
0 | 1067 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1068 |
if (!IsValidVehicleID(veh_dst)) return CMD_ERROR; |
0 | 1069 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1070 |
dst = GetVehicle(veh_dst); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1071 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1072 |
if (!CheckOwnership(dst->owner)) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1073 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1074 |
switch (p2) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1075 |
case CO_SHARE: { |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1076 |
Vehicle *src; |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1077 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1078 |
if (!IsValidVehicleID(veh_src)) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1079 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1080 |
src = GetVehicle(veh_src); |
588 | 1081 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1082 |
/* Sanity checks */ |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1083 |
if (!CheckOwnership(src->owner) || dst->type != src->type || dst == src) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1084 |
return CMD_ERROR; |
0 | 1085 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1086 |
/* Trucks can't share orders with busses (and visa versa) */ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
1087 |
if (src->type == VEH_ROAD) { |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
1088 |
if (src->cargo_type != dst->cargo_type && (IsCargoInClass(src->cargo_type, CC_PASSENGERS) || IsCargoInClass(dst->cargo_type, CC_PASSENGERS))) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1089 |
return CMD_ERROR; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1090 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1091 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1092 |
/* Is the vehicle already in the shared list? */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1093 |
{ |
2989 | 1094 |
const Vehicle* u; |
1095 |
||
1096 |
for (u = GetFirstVehicleFromSharedList(src); u != NULL; u = u->next_shared) { |
|
1097 |
if (u == dst) return CMD_ERROR; |
|
29
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
1098 |
} |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
1099 |
} |
0 | 1100 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1101 |
if (flags & DC_EXEC) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1102 |
/* If the destination vehicle had a OrderList, destroy it */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1103 |
DeleteVehicleOrders(dst); |
0 | 1104 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1105 |
dst->orders = src->orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1106 |
dst->num_orders = src->num_orders; |
588 | 1107 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1108 |
/* Link this vehicle in the shared-list */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1109 |
dst->next_shared = src->next_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1110 |
dst->prev_shared = src; |
2951 | 1111 |
if (src->next_shared != NULL) src->next_shared->prev_shared = dst; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1112 |
src->next_shared = dst; |
0 | 1113 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1114 |
InvalidateVehicleOrder(dst); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1115 |
InvalidateVehicleOrder(src); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1116 |
|
9297
1cb8d7bbdc8a
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents:
9234
diff
changeset
|
1117 |
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1118 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1119 |
} break; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1120 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1121 |
case CO_COPY: { |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1122 |
Vehicle *src; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1123 |
int delta; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1124 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1125 |
if (!IsValidVehicleID(veh_src)) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1126 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1127 |
src = GetVehicle(veh_src); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1128 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1129 |
/* Sanity checks */ |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1130 |
if (!CheckOwnership(src->owner) || dst->type != src->type || dst == src) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1131 |
return CMD_ERROR; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1132 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1133 |
/* Trucks can't copy all the orders from busses (and visa versa) */ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
1134 |
if (src->type == VEH_ROAD) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1135 |
const Order *order; |
1297
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
1136 |
TileIndex required_dst = INVALID_TILE; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1137 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1138 |
FOR_VEHICLE_ORDERS(src, order) { |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1139 |
if (order->IsType(OT_GOTO_STATION)) { |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
1140 |
const Station *st = GetStation(order->GetDestination()); |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
1141 |
if (IsCargoInClass(dst->cargo_type, CC_PASSENGERS)) { |
1297
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
1142 |
if (st->bus_stops != NULL) required_dst = st->bus_stops->xy; |
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
1143 |
} else { |
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
1144 |
if (st->truck_stops != NULL) required_dst = st->truck_stops->xy; |
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
1145 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1146 |
/* This station has not the correct road-bay, so we can't copy! */ |
1297
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
1147 |
if (required_dst == INVALID_TILE) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1148 |
return CMD_ERROR; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1149 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1150 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1151 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1152 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1153 |
/* make sure there are orders available */ |
8469
c3621b1a6454
(svn r12040) -Codechange: Change IsOrderListShared from a simple function to a class member(MagicBuzz).
belugas
parents:
8373
diff
changeset
|
1154 |
delta = dst->IsOrderListShared() ? src->num_orders + 1 : src->num_orders - dst->num_orders; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1155 |
if (!HasOrderPoolFree(delta)) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1156 |
return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1157 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1158 |
if (flags & DC_EXEC) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1159 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1160 |
Order **order_dst; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1161 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1162 |
/* If the destination vehicle had a OrderList, destroy it */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1163 |
DeleteVehicleOrders(dst); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1164 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1165 |
order_dst = &dst->orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1166 |
FOR_VEHICLE_ORDERS(src, order) { |
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7049
diff
changeset
|
1167 |
*order_dst = new Order(); |
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
1168 |
(*order_dst)->AssignOrder(*order); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1169 |
order_dst = &(*order_dst)->next; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1170 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1171 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1172 |
dst->num_orders = src->num_orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1173 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1174 |
InvalidateVehicleOrder(dst); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1175 |
|
9297
1cb8d7bbdc8a
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents:
9234
diff
changeset
|
1176 |
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1177 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1178 |
} break; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1179 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
1180 |
case CO_UNSHARE: return DecloneOrder(dst, flags); |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1181 |
default: return CMD_ERROR; |
0 | 1182 |
} |
1183 |
||
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
1184 |
return CommandCost(); |
0 | 1185 |
} |
1186 |
||
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1187 |
/** Add/remove refit orders from an order |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1188 |
* @param tile Not used |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
1189 |
* @param flags operation to perform |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1190 |
* @param p1 VehicleIndex of the vehicle having the order |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1191 |
* @param p2 bitmask |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1192 |
* - bit 0-7 CargoID |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1193 |
* - bit 8-15 Cargo subtype |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1194 |
* - bit 16-23 number of order to modify |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1195 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6832
diff
changeset
|
1196 |
CommandCost CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1197 |
{ |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1198 |
const Vehicle *v; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1199 |
Order *order; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1200 |
VehicleID veh = GB(p1, 0, 16); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1201 |
VehicleOrderID order_number = GB(p2, 16, 8); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1202 |
CargoID cargo = GB(p2, 0, 8); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1203 |
byte subtype = GB(p2, 8, 8); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1204 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1205 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1206 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1207 |
v = GetVehicle(veh); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1208 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1209 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1210 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1211 |
order = GetVehicleOrder(v, order_number); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1212 |
if (order == NULL) return CMD_ERROR; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1213 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1214 |
if (flags & DC_EXEC) { |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1215 |
Vehicle *u; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1216 |
|
8838
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8836
diff
changeset
|
1217 |
order->SetRefit(cargo, subtype); |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1218 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1219 |
u = GetFirstVehicleFromSharedList(v); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1220 |
for (; u != NULL; u = u->next_shared) { |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1221 |
/* Update any possible open window of the vehicle */ |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1222 |
InvalidateVehicleOrder(u); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1223 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1224 |
/* If the vehicle already got the current depot set as current order, then update current order as well */ |
8853
3266f0374302
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium
parents:
8851
diff
changeset
|
1225 |
if (u->cur_order_index == order_number && u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) { |
8838
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8836
diff
changeset
|
1226 |
u->current_order.SetRefit(cargo, subtype); |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1227 |
} |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1228 |
} |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1229 |
} |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1230 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
1231 |
return CommandCost(); |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1232 |
} |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1233 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1234 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1235 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1236 |
* Backup a vehicle order-list, so you can replace a vehicle |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1237 |
* without loosing the order-list |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1238 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1239 |
*/ |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1240 |
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak) |
0 | 1241 |
{ |
7653
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1242 |
/* Make sure we always have freed the stuff */ |
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1243 |
free(bak->order); |
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1244 |
bak->order = NULL; |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
1245 |
free(bak->name); |
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
1246 |
bak->name = NULL; |
7653
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1247 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1248 |
/* Save general info */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1249 |
bak->orderindex = v->cur_order_index; |
8650
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1250 |
bak->group = v->group_id; |
0 | 1251 |
bak->service_interval = v->service_interval; |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
1252 |
if (v->name != NULL) bak->name = strdup(v->name); |
0 | 1253 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1254 |
/* If we have shared orders, store it on a special way */ |
8469
c3621b1a6454
(svn r12040) -Codechange: Change IsOrderListShared from a simple function to a class member(MagicBuzz).
belugas
parents:
8373
diff
changeset
|
1255 |
if (v->IsOrderListShared()) { |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1256 |
const Vehicle *u = (v->next_shared) ? v->next_shared : v->prev_shared; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1257 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1258 |
bak->clone = u->index; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1259 |
} else { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1260 |
/* Else copy the orders */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1261 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1262 |
/* We do not have shared orders */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1263 |
bak->clone = INVALID_VEHICLE; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1264 |
|
7653
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1265 |
|
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1266 |
/* Count the number of orders */ |
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1267 |
uint cnt = 0; |
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1268 |
const Order *order; |
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1269 |
FOR_VEHICLE_ORDERS(v, order) cnt++; |
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1270 |
|
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1271 |
/* Allocate memory for the orders plus an end-of-orders marker */ |
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1272 |
bak->order = MallocT<Order>(cnt + 1); |
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1273 |
|
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1274 |
Order *dest = bak->order; |
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1275 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1276 |
/* Copy the orders */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1277 |
FOR_VEHICLE_ORDERS(v, order) { |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1278 |
memcpy(dest, order, sizeof(Order)); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1279 |
dest++; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1280 |
} |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1281 |
/* End the list with an empty order */ |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1282 |
dest->Free(); |
0 | 1283 |
} |
1284 |
} |
|
1285 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1286 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1287 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1288 |
* Restore vehicle orders that are backupped via BackupVehicleOrders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1289 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1290 |
*/ |
7653
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7401
diff
changeset
|
1291 |
void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *bak) |
0 | 1292 |
{ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1293 |
/* If we have a custom name, process that */ |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
1294 |
if (bak->name != NULL) { |
1820
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1796
diff
changeset
|
1295 |
_cmd_text = bak->name; |
0 | 1296 |
DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE); |
1297 |
} |
|
1298 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1299 |
/* If we had shared orders, recover that */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1300 |
if (bak->clone != INVALID_VEHICLE) { |
8064
fef5cd447a5a
(svn r11625) -Codechange: add CO_* enum at some places, add includes of order.h too
smatz
parents:
8057
diff
changeset
|
1301 |
DoCommandP(0, v->index | (bak->clone << 16), CO_SHARE, NULL, CMD_CLONE_ORDER); |
7820
d4b13c0cae8d
(svn r11370) -Fix [FS1384]: manually replacing a vehicle with shared orders makes it lose it's order index and service interval. Patch by jthill.
rubidium
parents:
7683
diff
changeset
|
1302 |
} else { |
0 | 1303 |
|
7820
d4b13c0cae8d
(svn r11370) -Fix [FS1384]: manually replacing a vehicle with shared orders makes it lose it's order index and service interval. Patch by jthill.
rubidium
parents:
7683
diff
changeset
|
1304 |
/* CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the |
d4b13c0cae8d
(svn r11370) -Fix [FS1384]: manually replacing a vehicle with shared orders makes it lose it's order index and service interval. Patch by jthill.
rubidium
parents:
7683
diff
changeset
|
1305 |
* order number is one more than the current amount of orders, and because |
d4b13c0cae8d
(svn r11370) -Fix [FS1384]: manually replacing a vehicle with shared orders makes it lose it's order index and service interval. Patch by jthill.
rubidium
parents:
7683
diff
changeset
|
1306 |
* in network the commands are queued before send, the second insert always |
d4b13c0cae8d
(svn r11370) -Fix [FS1384]: manually replacing a vehicle with shared orders makes it lose it's order index and service interval. Patch by jthill.
rubidium
parents:
7683
diff
changeset
|
1307 |
* fails in test mode. By bypassing the test-mode, that no longer is a problem. */ |
d4b13c0cae8d
(svn r11370) -Fix [FS1384]: manually replacing a vehicle with shared orders makes it lose it's order index and service interval. Patch by jthill.
rubidium
parents:
7683
diff
changeset
|
1308 |
for (uint i = 0; bak->order[i].IsValid(); i++) { |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1309 |
Order o = bak->order[i]; |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1310 |
/* Conditional orders need to have their destination to be valid on insertion. */ |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1311 |
if (o.IsType(OT_CONDITIONAL)) o.SetConditionSkipToOrder(0); |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1312 |
|
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1313 |
if (!DoCommandP(0, v->index + (i << 16), o.Pack(), NULL, |
8650
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1314 |
CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) { |
7820
d4b13c0cae8d
(svn r11370) -Fix [FS1384]: manually replacing a vehicle with shared orders makes it lose it's order index and service interval. Patch by jthill.
rubidium
parents:
7683
diff
changeset
|
1315 |
break; |
8650
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1316 |
} |
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1317 |
|
8679
b6f6430cc619
(svn r12345) -Fix [FS#1828](r12296): don't try to restore backupped timetable when timetabling is disabled
glx
parents:
8650
diff
changeset
|
1318 |
/* Copy timetable if enabled */ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9390
diff
changeset
|
1319 |
if (_settings_game.order.timetabling && !DoCommandP(0, v->index | (i << 16) | (1 << 25), |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1320 |
o.wait_time << 16 | o.travel_time, NULL, |
8650
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1321 |
CMD_CHANGE_TIMETABLE | CMD_NO_TEST_IF_IN_NETWORK)) { |
9665
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1322 |
break; |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1323 |
} |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1324 |
} |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1325 |
|
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1326 |
/* Fix the conditional orders' destination. */ |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1327 |
for (uint i = 0; bak->order[i].IsValid(); i++) { |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1328 |
if (!bak->order[i].IsType(OT_CONDITIONAL)) continue; |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1329 |
|
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1330 |
if (!DoCommandP(0, v->index + (i << 16), MOF_LOAD | (bak->order[i].GetConditionSkipToOrder() << 4), NULL, |
dd6c07db9d32
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium
parents:
9641
diff
changeset
|
1331 |
CMD_MODIFY_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) { |
8650
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1332 |
break; |
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1333 |
} |
7820
d4b13c0cae8d
(svn r11370) -Fix [FS1384]: manually replacing a vehicle with shared orders makes it lose it's order index and service interval. Patch by jthill.
rubidium
parents:
7683
diff
changeset
|
1334 |
} |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1335 |
} |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1336 |
|
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1337 |
/* Restore vehicle order-index and service interval */ |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1338 |
DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16) , NULL, CMD_RESTORE_ORDER_INDEX); |
8650
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1339 |
|
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1340 |
/* Restore vehicle group */ |
9a9c905deaa5
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8551
diff
changeset
|
1341 |
DoCommandP(0, bak->group, v->index, NULL, CMD_ADD_VEHICLE_GROUP); |
0 | 1342 |
} |
1343 |
||
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1344 |
/** Restores vehicle orders that was previously backed up by BackupVehicleOrders() |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1345 |
* This will restore to the point where it was at the time of the backup meaning |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1346 |
* it will presume the same order indexes can be used. |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1347 |
* This is needed when restoring a backed up vehicle |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1348 |
* @param v The vehicle that should gain the orders |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1349 |
* @param bak the backup of the orders |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1350 |
*/ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1351 |
void RestoreVehicleOrdersBruteForce(Vehicle *v, const BackuppedOrders *bak) |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1352 |
{ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1353 |
if (bak->name != NULL) { |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1354 |
/* Restore the name. */ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1355 |
v->name = strdup(bak->name); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1356 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1357 |
|
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1358 |
/* If we had shared orders, recover that */ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1359 |
if (bak->clone != INVALID_VEHICLE) { |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1360 |
/* We will place it at the same location in the linked list as it previously was. */ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1361 |
if (v->prev_shared != NULL) { |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1362 |
assert(v->prev_shared->next_shared == v->next_shared); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1363 |
v->prev_shared->next_shared = v; |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1364 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1365 |
if (v->next_shared != NULL) { |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1366 |
assert(v->next_shared->prev_shared == v->prev_shared); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1367 |
v->next_shared->prev_shared = v; |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1368 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1369 |
} else { |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1370 |
/* Restore the orders at the indexes they originally were. */ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1371 |
for (Order *order = bak->order; order->IsValid(); order++) { |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1372 |
Order *dst = GetOrder(order->index); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1373 |
/* Since we are restoring something we removed a moment ago all the orders should be free. */ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1374 |
assert(!dst->IsValid()); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1375 |
memcpy(dst, order, sizeof(Order)); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1376 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1377 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1378 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9043
diff
changeset
|
1379 |
|
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1380 |
/** Restore the current order-index of a vehicle and sets service-interval. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
1381 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
1382 |
* @param flags operation to perform |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1383 |
* @param p1 the ID of the vehicle |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1384 |
* @param p2 various bistuffed elements |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1385 |
* - p2 = (bit 0-15) - current order-index (p2 & 0xFFFF) |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1386 |
* - p2 = (bit 16-31) - service interval (p2 >> 16) |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1387 |
* @todo Unfortunately you cannot safely restore the unitnumber or the old vehicle |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1388 |
* as far as I can see. We can store it in BackuppedOrders, and restore it, but |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1389 |
* but we have no way of seeing it has been tampered with or not, as we have no |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1390 |
* legit way of knowing what that ID was.@n |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1391 |
* If we do want to backup/restore it, just add UnitID uid to BackuppedOrders, and |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1392 |
* restore it as parameter 'y' (ugly hack I know) for example. "v->unitnumber = y;" |
0 | 1393 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6832
diff
changeset
|
1394 |
CommandCost CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1395 |
{ |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1396 |
Vehicle *v; |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
1397 |
VehicleOrderID cur_ord = GB(p2, 0, 16); |
2635 | 1398 |
uint16 serv_int = GB(p2, 16, 16); |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
1399 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1400 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1401 |
|
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1402 |
v = GetVehicle(p1); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1403 |
|
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1404 |
/* Check the vehicle type and ownership, and if the service interval and order are in range */ |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1405 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1406 |
if (serv_int != GetServiceIntervalClamped(serv_int) || cur_ord >= v->num_orders) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
1407 |
|
0 | 1408 |
if (flags & DC_EXEC) { |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1409 |
v->cur_order_index = cur_ord; |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1410 |
v->service_interval = serv_int; |
0 | 1411 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1412 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
1413 |
return CommandCost(); |
0 | 1414 |
} |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1415 |
|
4177
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1416 |
|
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1417 |
static TileIndex GetStationTileForVehicle(const Vehicle* v, const Station* st) |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1418 |
{ |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1419 |
switch (v->type) { |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1420 |
default: NOT_REACHED(); |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
1421 |
case VEH_TRAIN: return st->train_tile; |
7683
13e6fb7baa57
(svn r11214) -Fix [FS#1296]: planes can't use heliports so refuse these orders
glx
parents:
7653
diff
changeset
|
1422 |
case VEH_AIRCRAFT: return CanAircraftUseStation(v->engine_type, st) ? st->airport_tile : 0; |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
1423 |
case VEH_SHIP: return st->dock_tile; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
1424 |
case VEH_ROAD: |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
1425 |
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { |
4177
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1426 |
return (st->bus_stops != NULL) ? st->bus_stops->xy : 0; |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1427 |
} else { |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1428 |
return (st->truck_stops != NULL) ? st->truck_stops->xy : 0; |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1429 |
} |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1430 |
} |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1431 |
} |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1432 |
|
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1433 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1434 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1435 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1436 |
* Check the orders of a vehicle, to see if there are invalid orders and stuff |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1437 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1438 |
*/ |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1439 |
void CheckOrders(const Vehicle* v) |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1440 |
{ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1441 |
/* Does the user wants us to check things? */ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9390
diff
changeset
|
1442 |
if (_settings_client.gui.order_review_system == 0) return; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1443 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1444 |
/* Do nothing for crashed vehicles */ |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1445 |
if (v->vehstatus & VS_CRASHED) return; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1446 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1447 |
/* Do nothing for stopped vehicles if setting is '1' */ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9390
diff
changeset
|
1448 |
if (_settings_client.gui.order_review_system == 1 && v->vehstatus & VS_STOPPED) |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1449 |
return; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1450 |
|
1053
8d90844ddc2e
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1043
diff
changeset
|
1451 |
/* do nothing we we're not the first vehicle in a share-chain */ |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1452 |
if (v->next_shared != NULL) return; |
1053
8d90844ddc2e
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1043
diff
changeset
|
1453 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1454 |
/* Only check every 20 days, so that we don't flood the message log */ |
2549 | 1455 |
if (v->owner == _local_player && v->day_counter % 20 == 0) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1456 |
int n_st, problem_type = -1; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1457 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1458 |
int message = 0; |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1459 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1460 |
/* Check the order list */ |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1461 |
n_st = 0; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1462 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1463 |
FOR_VEHICLE_ORDERS(v, order) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1464 |
/* Dummy order? */ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1465 |
if (order->IsType(OT_DUMMY)) { |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1466 |
problem_type = 1; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1467 |
break; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1468 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1469 |
/* Does station have a load-bay for this vehicle? */ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1470 |
if (order->IsType(OT_GOTO_STATION)) { |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
1471 |
const Station* st = GetStation(order->GetDestination()); |
4177
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1472 |
TileIndex required_tile = GetStationTileForVehicle(v, st); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1473 |
|
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1474 |
n_st++; |
2639 | 1475 |
if (required_tile == 0) problem_type = 3; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1476 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1477 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1478 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1479 |
/* Check if the last and the first order are the same */ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1480 |
if (v->num_orders > 1) { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1481 |
const Order* last = GetLastVehicleOrder(v); |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1482 |
|
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
1483 |
if (v->orders->Equals(*last)) { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1484 |
problem_type = 2; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1485 |
} |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1486 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1487 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1488 |
/* Do we only have 1 station in our order list? */ |
2639 | 1489 |
if (n_st < 2 && problem_type == -1) problem_type = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1490 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1491 |
/* We don't have a problem */ |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1492 |
if (problem_type < 0) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1493 |
|
5955
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
1494 |
message = STR_TRAIN_HAS_TOO_FEW_ORDERS + (v->type << 2) + problem_type; |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5374
diff
changeset
|
1495 |
//DEBUG(misc, 3, "Triggered News Item for vehicle %d", v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1496 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1497 |
SetDParam(0, v->unitnumber); |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1498 |
AddNewsItem( |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1499 |
message, |
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9111
diff
changeset
|
1500 |
NS_ADVICE, |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1501 |
v->index, |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1502 |
0 |
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1503 |
); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1504 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1505 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1506 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1507 |
/** |
4351
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4350
diff
changeset
|
1508 |
* Removes an order from all vehicles. Triggers when, say, a station is removed. |
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4350
diff
changeset
|
1509 |
* @param type The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]). |
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4350
diff
changeset
|
1510 |
* @param destination The destination. Can be a StationID, DepotID or WaypointID. |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1511 |
*/ |
4389
18d6ccfb5335
(svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents:
4384
diff
changeset
|
1512 |
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1513 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1514 |
Vehicle *v; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1515 |
|
4528
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1516 |
/* Aircraft have StationIDs for depot orders and never use DepotIDs |
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1517 |
* This fact is handled specially below |
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1518 |
*/ |
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1519 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1520 |
/* Go through all vehicles */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1521 |
FOR_ALL_VEHICLES(v) { |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1522 |
Order *order; |
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1523 |
bool invalidate; |
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1524 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1525 |
/* Forget about this station if this station is removed */ |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1526 |
if (v->last_station_visited == destination && type == OT_GOTO_STATION) { |
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
1527 |
v->last_station_visited = INVALID_STATION; |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1528 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1529 |
|
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1530 |
order = &v->current_order; |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1531 |
if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) ? OT_GOTO_STATION : order->GetType()) == type && |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
1532 |
v->current_order.GetDestination() == destination) { |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1533 |
order->MakeDummy(); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1534 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1535 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1536 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1537 |
/* Clear the order from the order-list */ |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1538 |
invalidate = false; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1539 |
FOR_VEHICLE_ORDERS(v, order) { |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1540 |
if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) ? OT_GOTO_STATION : order->GetType()) == type && |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
1541 |
order->GetDestination() == destination) { |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1542 |
order->MakeDummy(); |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1543 |
invalidate = true; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1544 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1545 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1546 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1547 |
/* Only invalidate once, and if needed */ |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1548 |
if (invalidate) InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1549 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1550 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1551 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1552 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1553 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1554 |
* Checks if a vehicle has a GOTO_DEPOT in his order list |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1555 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1556 |
* @return True if this is true (lol ;)) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1557 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1558 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1559 |
bool VehicleHasDepotOrders(const Vehicle *v) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1560 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1561 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1562 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1563 |
FOR_VEHICLE_ORDERS(v, order) { |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1564 |
if (order->IsType(OT_GOTO_DEPOT)) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1565 |
return true; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1566 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1567 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1568 |
return false; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1569 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1570 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1571 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1572 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1573 |
* Delete all orders from a vehicle |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1574 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1575 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1576 |
void DeleteVehicleOrders(Vehicle *v) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1577 |
{ |
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
1578 |
DeleteOrderWarnings(v); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
1579 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1580 |
/* If we have a shared order-list, don't delete the list, but just |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1581 |
remove our pointer */ |
8469
c3621b1a6454
(svn r12040) -Codechange: Change IsOrderListShared from a simple function to a class member(MagicBuzz).
belugas
parents:
8373
diff
changeset
|
1582 |
if (v->IsOrderListShared()) { |
6337
2da03fc77b33
(svn r9338) -Fix: close the Shared Order Vehicle List if you remove the shared link with only 2 vehicles
truelight
parents:
6336
diff
changeset
|
1583 |
Vehicle *u = v; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1584 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1585 |
v->orders = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1586 |
v->num_orders = 0; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1587 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1588 |
/* Unlink ourself */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1589 |
if (v->prev_shared != NULL) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1590 |
v->prev_shared->next_shared = v->next_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1591 |
u = v->prev_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1592 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1593 |
if (v->next_shared != NULL) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1594 |
v->next_shared->prev_shared = v->prev_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1595 |
u = v->next_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1596 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1597 |
v->prev_shared = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1598 |
v->next_shared = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1599 |
|
6337
2da03fc77b33
(svn r9338) -Fix: close the Shared Order Vehicle List if you remove the shared link with only 2 vehicles
truelight
parents:
6336
diff
changeset
|
1600 |
/* If we are the only one left in the Shared Order Vehicle List, |
2da03fc77b33
(svn r9338) -Fix: close the Shared Order Vehicle List if you remove the shared link with only 2 vehicles
truelight
parents:
6336
diff
changeset
|
1601 |
* remove it, as we are no longer a Shared Order Vehicle */ |
6370
bcf7979ecc4f
(svn r9429) -Fix r9338: when deleting a vehicle which has shared orders with one more vehicle and no orders, segfaulted
truelight
parents:
6351
diff
changeset
|
1602 |
if (u->prev_shared == NULL && u->next_shared == NULL && u->orders != NULL) RemoveSharedOrderVehicleList(u); |
6337
2da03fc77b33
(svn r9338) -Fix: close the Shared Order Vehicle List if you remove the shared link with only 2 vehicles
truelight
parents:
6336
diff
changeset
|
1603 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1604 |
/* We only need to update this-one, because if there is a third |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
1605 |
* vehicle which shares the same order-list, nothing will change. If |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
1606 |
* this is the last vehicle, the last line of the order-window |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
1607 |
* will change from Shared order list, to Order list, so it needs |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
1608 |
* an update */ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1609 |
InvalidateVehicleOrder(u); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1610 |
return; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1611 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1612 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1613 |
/* Remove the orders */ |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1614 |
Order *cur = v->orders; |
6336
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
1615 |
/* Delete the vehicle list of shared orders, if any */ |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
1616 |
if (cur != NULL) RemoveSharedOrderVehicleList(v); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1617 |
v->orders = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1618 |
v->num_orders = 0; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1619 |
|
4735
632bb67a4c50
(svn r6647) -Fix: [vehicle list windows] Lists of shared orders are now no longer closed by a window event if the list is empty
bjarni
parents:
4715
diff
changeset
|
1620 |
if (cur != NULL) { |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1621 |
cur->FreeChain(); // Free the orders. |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1622 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1623 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1624 |
|
8211
29a8510dfd62
(svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents:
8144
diff
changeset
|
1625 |
Date GetServiceIntervalClamped(uint index) |
29a8510dfd62
(svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents:
8144
diff
changeset
|
1626 |
{ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9390
diff
changeset
|
1627 |
return (_settings_game.vehicle.servint_ispercent) ? Clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS); |
8211
29a8510dfd62
(svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents:
8144
diff
changeset
|
1628 |
} |
29a8510dfd62
(svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents:
8144
diff
changeset
|
1629 |
|
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1630 |
/** |
8830
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1631 |
* |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1632 |
* Check if a vehicle has any valid orders |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1633 |
* |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1634 |
* @return false if there are no valid orders |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1635 |
* |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1636 |
*/ |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1637 |
static bool CheckForValidOrders(const Vehicle *v) |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1638 |
{ |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1639 |
const Order *order; |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1640 |
|
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1641 |
FOR_VEHICLE_ORDERS(v, order) if (!order->IsType(OT_DUMMY)) return true; |
8830
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1642 |
|
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1643 |
return false; |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1644 |
} |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1645 |
|
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1646 |
/** |
8900
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1647 |
* Compare the variable and value based on the given comparator. |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1648 |
*/ |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1649 |
static bool OrderConditionCompare(OrderConditionComparator occ, int variable, int value) |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1650 |
{ |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1651 |
switch (occ) { |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1652 |
case OCC_EQUALS: return variable == value; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1653 |
case OCC_NOT_EQUALS: return variable != value; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1654 |
case OCC_LESS_THAN: return variable < value; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1655 |
case OCC_LESS_EQUALS: return variable <= value; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1656 |
case OCC_MORE_THAN: return variable > value; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1657 |
case OCC_MORE_EQUALS: return variable >= value; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1658 |
case OCC_IS_TRUE: return variable != 0; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1659 |
case OCC_IS_FALSE: return variable == 0; |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1660 |
default: NOT_REACHED(); |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1661 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1662 |
} |
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1663 |
|
a49f442299b8
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium
parents:
8894
diff
changeset
|
1664 |
/** |
9440
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1665 |
* Process a conditional order and determine the next order. |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1666 |
* @param order the order the vehicle currently has |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1667 |
* @param v the vehicle to update |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1668 |
* @return index of next order to jump to, or INVALID_VEH_ORDER_ID to use the next order |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1669 |
*/ |
9807
6c47b0584f51
(svn r13949) -Codechange [YAPP]: Declare the functions for processing conditional orders as non-static. (michi_cc)
rubidium
parents:
9666
diff
changeset
|
1670 |
VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v) |
9440
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1671 |
{ |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1672 |
if (order->GetType() != OT_CONDITIONAL) return INVALID_VEH_ORDER_ID; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1673 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1674 |
bool skip_order = false; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1675 |
OrderConditionComparator occ = order->GetConditionComparator(); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1676 |
uint16 value = order->GetConditionValue(); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1677 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1678 |
switch (order->GetConditionVariable()) { |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1679 |
case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, NULL), value); break; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1680 |
case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, v->reliability * 100 >> 16, value); break; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1681 |
case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed(), value); break; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1682 |
case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / 366, value); break; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1683 |
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1684 |
case OCV_UNCONDITIONALLY: skip_order = true; break; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1685 |
default: NOT_REACHED(); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1686 |
} |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1687 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1688 |
return skip_order ? order->GetConditionSkipToOrder() : (VehicleOrderID)INVALID_VEH_ORDER_ID; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1689 |
} |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1690 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1691 |
/** |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1692 |
* Update the vehicle's destination tile from an order. |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1693 |
* @param order the order the vehicle currently has |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1694 |
* @param v the vehicle to update |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1695 |
*/ |
9807
6c47b0584f51
(svn r13949) -Codechange [YAPP]: Declare the functions for processing conditional orders as non-static. (michi_cc)
rubidium
parents:
9666
diff
changeset
|
1696 |
bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth) |
9440
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1697 |
{ |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1698 |
switch (order->GetType()) { |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1699 |
case OT_GOTO_STATION: |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1700 |
v->dest_tile = v->GetOrderStationLocation(order->GetDestination()); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1701 |
break; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1702 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1703 |
case OT_GOTO_DEPOT: |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1704 |
if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) { |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1705 |
/* We need to search for the nearest depot (hangar). */ |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1706 |
TileIndex location; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1707 |
DestinationID destination; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1708 |
bool reverse; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1709 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1710 |
if (v->FindClosestDepot(&location, &destination, &reverse)) { |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1711 |
v->dest_tile = location; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1712 |
v->current_order.MakeGoToDepot(destination, ODTFB_PART_OF_ORDERS); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1713 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1714 |
/* If there is no depot in front, reverse automatically (trains only) */ |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1715 |
if (v->type == VEH_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1716 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1717 |
if (v->type == VEH_AIRCRAFT && v->u.air.state == FLYING && v->u.air.targetairport != destination) { |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1718 |
/* The aircraft is now heading for a different hangar than the next in the orders */ |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1719 |
extern void AircraftNextAirportPos_and_Order(Vehicle *v); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1720 |
AircraftNextAirportPos_and_Order(v); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1721 |
} |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1722 |
} else { |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1723 |
UpdateVehicleTimetable(v, true); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1724 |
v->cur_order_index++; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1725 |
} |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1726 |
} else if (v->type != VEH_AIRCRAFT) { |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1727 |
v->dest_tile = GetDepot(order->GetDestination())->xy; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1728 |
} |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1729 |
break; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1730 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1731 |
case OT_GOTO_WAYPOINT: |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1732 |
v->dest_tile = GetWaypoint(order->GetDestination())->xy; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1733 |
break; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1734 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1735 |
case OT_CONDITIONAL: { |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1736 |
VehicleOrderID next_order = ProcessConditionalOrder(order, v); |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1737 |
if (next_order != INVALID_VEH_ORDER_ID) { |
9641
a854c7cf6af5
(svn r13704) -Fix: make timetables work more sensible when used in conjunction with conditional orders, i.e. make it possibly to tell how long to travel to the next destination if you jump.
rubidium
parents:
9609
diff
changeset
|
1738 |
UpdateVehicleTimetable(v, false); |
9440
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1739 |
v->cur_order_index = next_order; |
9641
a854c7cf6af5
(svn r13704) -Fix: make timetables work more sensible when used in conjunction with conditional orders, i.e. make it possibly to tell how long to travel to the next destination if you jump.
rubidium
parents:
9609
diff
changeset
|
1740 |
v->current_order_time += GetVehicleOrder(v, next_order)->travel_time; |
9440
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1741 |
} else { |
9641
a854c7cf6af5
(svn r13704) -Fix: make timetables work more sensible when used in conjunction with conditional orders, i.e. make it possibly to tell how long to travel to the next destination if you jump.
rubidium
parents:
9609
diff
changeset
|
1742 |
UpdateVehicleTimetable(v, true); |
9440
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1743 |
v->cur_order_index++; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1744 |
} |
9559
cb49ef39913f
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
rubidium
parents:
9440
diff
changeset
|
1745 |
|
cb49ef39913f
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
rubidium
parents:
9440
diff
changeset
|
1746 |
if (conditional_depth > v->num_orders) return false; |
cb49ef39913f
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
rubidium
parents:
9440
diff
changeset
|
1747 |
|
cb49ef39913f
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
rubidium
parents:
9440
diff
changeset
|
1748 |
/* Get the current order */ |
cb49ef39913f
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
rubidium
parents:
9440
diff
changeset
|
1749 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
cb49ef39913f
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
rubidium
parents:
9440
diff
changeset
|
1750 |
|
cb49ef39913f
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
rubidium
parents:
9440
diff
changeset
|
1751 |
return UpdateOrderDest(v, GetVehicleOrder(v, v->cur_order_index), conditional_depth + 1); |
9440
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1752 |
} |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1753 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1754 |
default: |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1755 |
v->dest_tile = 0; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1756 |
return false; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1757 |
} |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1758 |
return true; |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1759 |
} |
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1760 |
|
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1761 |
/** |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1762 |
* Handle the orders of a vehicle and determine the next place |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1763 |
* to go to if needed. |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1764 |
* @param v the vehicle to do this for. |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1765 |
* @return true *if* the vehicle is eligible for reversing |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1766 |
* (basically only when leaving a station). |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1767 |
*/ |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1768 |
bool ProcessOrders(Vehicle *v) |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1769 |
{ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1770 |
switch (v->current_order.GetType()) { |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1771 |
case OT_GOTO_DEPOT: |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1772 |
/* Let a depot order in the orderlist interrupt. */ |
8853
3266f0374302
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium
parents:
8851
diff
changeset
|
1773 |
if (!(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) return false; |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1774 |
|
8862
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8861
diff
changeset
|
1775 |
if ((v->current_order.GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) { |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1776 |
UpdateVehicleTimetable(v, true); |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1777 |
v->cur_order_index++; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1778 |
} |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1779 |
break; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1780 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1781 |
case OT_LOADING: |
8830
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1782 |
return false; |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1783 |
|
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1784 |
case OT_LEAVESTATION: |
8830
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1785 |
if (v->type != VEH_AIRCRAFT) return false; |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1786 |
break; |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1787 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1788 |
default: break; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1789 |
} |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1790 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1791 |
/** |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1792 |
* Reversing because of order change is allowed only just after leaving a |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1793 |
* station (and the difficulty setting to allowed, of course) |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1794 |
* this can be detected because only after OT_LEAVESTATION, current_order |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1795 |
* will be reset to nothing. (That also happens if no order, but in that case |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1796 |
* it won't hit the point in code where may_reverse is checked) |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1797 |
*/ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1798 |
bool may_reverse = v->current_order.IsType(OT_NOTHING); |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1799 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1800 |
/* Check if we've reached the waypoint? */ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1801 |
if (v->current_order.IsType(OT_GOTO_WAYPOINT) && v->tile == v->dest_tile) { |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1802 |
UpdateVehicleTimetable(v, true); |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1803 |
v->cur_order_index++; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1804 |
} |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1805 |
|
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
1806 |
/* Check if we've reached a non-stop station.. */ |
8941
daf347ea7a17
(svn r12716) -Fix: Do not compare StationIDs with DepotIDs or WaypointIDs.
frosch
parents:
8926
diff
changeset
|
1807 |
if (v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) && |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1808 |
IsTileType(v->tile, MP_STATION) && |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
1809 |
v->current_order.GetDestination() == GetStationIndex(v->tile)) { |
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
1810 |
v->last_station_visited = v->current_order.GetDestination(); |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1811 |
UpdateVehicleTimetable(v, true); |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1812 |
v->cur_order_index++; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1813 |
} |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1814 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1815 |
/* Get the current order */ |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1816 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1817 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1818 |
const Order *order = GetVehicleOrder(v, v->cur_order_index); |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1819 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1820 |
/* If no order, do nothing. */ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1821 |
if (order == NULL || (v->type == VEH_AIRCRAFT && order->IsType(OT_DUMMY) && !CheckForValidOrders(v))) { |
8830
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1822 |
if (v->type == VEH_AIRCRAFT) { |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1823 |
/* Aircraft do something vastly different here, so handle separately */ |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1824 |
extern void HandleMissingAircraftOrders(Vehicle *v); |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1825 |
HandleMissingAircraftOrders(v); |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1826 |
return false; |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1827 |
} |
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1828 |
|
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1829 |
v->current_order.Free(); |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1830 |
v->dest_tile = 0; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1831 |
if (v->type == VEH_ROAD) ClearSlot(v); |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1832 |
return false; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1833 |
} |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1834 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1835 |
/* If it is unchanged, keep it. */ |
8911
e986cdff87a7
(svn r12681) -Fix [FS#1921]: aircraft stopping mid-air.
rubidium
parents:
8909
diff
changeset
|
1836 |
if (order->Equals(v->current_order) && (v->type == VEH_AIRCRAFT || v->dest_tile != 0) && |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8839
diff
changeset
|
1837 |
(v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || GetStation(order->GetDestination())->dock_tile != 0)) { |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1838 |
return false; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1839 |
} |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1840 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1841 |
/* Otherwise set it, and determine the destination tile. */ |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1842 |
v->current_order = *order; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1843 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1844 |
InvalidateVehicleOrder(v); |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1845 |
switch (v->type) { |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1846 |
default: |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1847 |
NOT_REACHED(); |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1848 |
|
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1849 |
case VEH_ROAD: |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1850 |
case VEH_TRAIN: |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1851 |
break; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1852 |
|
8830
b288359ab100
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents:
8827
diff
changeset
|
1853 |
case VEH_AIRCRAFT: |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1854 |
case VEH_SHIP: |
9043
eb4f06b99146
(svn r12862) -Codechange: reduce code duplication for VehicleType -> WindowClass lookup
smatz
parents:
8962
diff
changeset
|
1855 |
InvalidateWindowClasses(GetWindowClassForVehicleType(v->type)); |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1856 |
break; |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1857 |
} |
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1858 |
|
9440
33764c3f920c
(svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium
parents:
9413
diff
changeset
|
1859 |
return UpdateOrderDest(v, order) && may_reverse; |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8787
diff
changeset
|
1860 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1861 |
|
8832
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1862 |
/** |
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1863 |
* Check whether the given vehicle should stop at the given station |
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1864 |
* based on this order and the non-stop settings. |
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1865 |
* @param v the vehicle that might be stopping. |
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1866 |
* @param station the station to stop at. |
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1867 |
* @return true if the vehicle should stop. |
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1868 |
*/ |
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1869 |
bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const |
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1870 |
{ |
8941
daf347ea7a17
(svn r12716) -Fix: Do not compare StationIDs with DepotIDs or WaypointIDs.
frosch
parents:
8926
diff
changeset
|
1871 |
bool is_dest_station = this->IsType(OT_GOTO_STATION) && this->dest == station; |
8832
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1872 |
return |
9076
30574351a0ad
(svn r12935) -Fix [FS#1975]: vehicles forget their manual depot order when stopping at a station. Now we just pass through the station without stopping when a vehicle has been given a depot order.
rubidium
parents:
9061
diff
changeset
|
1873 |
(!this->IsType(OT_GOTO_DEPOT) || (this->GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0) && |
8832
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1874 |
v->last_station_visited != station && // Do stop only when we've not just been there |
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
1875 |
/* Finally do stop when there is no non-stop flag set for this type of station. */ |
8941
daf347ea7a17
(svn r12716) -Fix: Do not compare StationIDs with DepotIDs or WaypointIDs.
frosch
parents:
8926
diff
changeset
|
1876 |
!(this->GetNonStopType() & (is_dest_station ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS)); |
8832
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1877 |
} |
6d8cc04d39a4
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents:
8830
diff
changeset
|
1878 |
|
6247 | 1879 |
void InitializeOrders() |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1880 |
{ |
7401
7a72cc2a1196
(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents:
7391
diff
changeset
|
1881 |
_Order_pool.CleanPool(); |
7a72cc2a1196
(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents:
7391
diff
changeset
|
1882 |
_Order_pool.AddBlockToPool(); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1883 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1884 |
_backup_orders_tile = 0; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1885 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1886 |
|
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1887 |
const SaveLoad *GetOrderDescription() { |
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1820
diff
changeset
|
1888 |
static const SaveLoad _order_desc[] = { |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1889 |
SLE_VAR(Order, type, SLE_UINT8), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1890 |
SLE_VAR(Order, flags, SLE_UINT8), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1891 |
SLE_VAR(Order, dest, SLE_UINT16), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1892 |
SLE_REF(Order, next, REF_ORDER), |
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6950
diff
changeset
|
1893 |
SLE_CONDVAR(Order, refit_cargo, SLE_UINT8, 36, SL_MAX_VERSION), |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6950
diff
changeset
|
1894 |
SLE_CONDVAR(Order, refit_subtype, SLE_UINT8, 36, SL_MAX_VERSION), |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6950
diff
changeset
|
1895 |
SLE_CONDVAR(Order, wait_time, SLE_UINT16, 67, SL_MAX_VERSION), |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6950
diff
changeset
|
1896 |
SLE_CONDVAR(Order, travel_time, SLE_UINT16, 67, SL_MAX_VERSION), |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1897 |
|
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1898 |
/* Leftover from the minor savegame version stuff |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1899 |
* We will never use those free bytes, but we have to keep this line to allow loading of old savegames */ |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1900 |
SLE_CONDNULL(10, 5, 35), |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1901 |
SLE_END() |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1902 |
}; |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1903 |
return _order_desc; |
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1904 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1905 |
|
6247 | 1906 |
static void Save_ORDR() |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1907 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1908 |
Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1909 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1910 |
FOR_ALL_ORDERS(order) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1911 |
SlSetArrayIndex(order->index); |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1912 |
SlObject(order, GetOrderDescription()); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1913 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1914 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1915 |
|
6247 | 1916 |
static void Load_ORDR() |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1917 |
{ |
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2645
diff
changeset
|
1918 |
if (CheckSavegameVersionOldStyle(5, 2)) { |
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2645
diff
changeset
|
1919 |
/* Version older than 5.2 did not have a ->next pointer. Convert them |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1920 |
(in the old days, the orderlist was 5000 items big) */ |
9390
88d36f907e96
(svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents:
9357
diff
changeset
|
1921 |
size_t len = SlGetFieldLength(); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1922 |
uint i; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1923 |
|
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2645
diff
changeset
|
1924 |
if (CheckSavegameVersion(5)) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1925 |
/* Pre-version 5 had an other layout for orders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1926 |
(uint16 instead of uint32) */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1927 |
len /= sizeof(uint16); |
8373
7431d91527f2
(svn r11939) -Codechange: some type fixes and very initial steps into supporting NDS by default. Based on work by Dominik.
rubidium
parents:
8302
diff
changeset
|
1928 |
uint16 *orders = MallocT<uint16>(len + 1); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1929 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1930 |
SlArray(orders, len, SLE_UINT16); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1931 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1932 |
for (i = 0; i < len; ++i) { |
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7049
diff
changeset
|
1933 |
Order *order = new (i) Order(); |
8835
8fa962d90b63
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents:
8834
diff
changeset
|
1934 |
order->AssignOrder(UnpackVersion4Order(orders[i])); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1935 |
} |
8373
7431d91527f2
(svn r11939) -Codechange: some type fixes and very initial steps into supporting NDS by default. Based on work by Dominik.
rubidium
parents:
8302
diff
changeset
|
1936 |
|
7431d91527f2
(svn r11939) -Codechange: some type fixes and very initial steps into supporting NDS by default. Based on work by Dominik.
rubidium
parents:
8302
diff
changeset
|
1937 |
free(orders); |
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2645
diff
changeset
|
1938 |
} else if (CheckSavegameVersionOldStyle(5, 2)) { |
8373
7431d91527f2
(svn r11939) -Codechange: some type fixes and very initial steps into supporting NDS by default. Based on work by Dominik.
rubidium
parents:
8302
diff
changeset
|
1939 |
len /= sizeof(uint16); |
7431d91527f2
(svn r11939) -Codechange: some type fixes and very initial steps into supporting NDS by default. Based on work by Dominik.
rubidium
parents:
8302
diff
changeset
|
1940 |
uint16 *orders = MallocT<uint16>(len + 1); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1941 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1942 |
SlArray(orders, len, SLE_UINT32); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1943 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1944 |
for (i = 0; i < len; ++i) { |
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8838
diff
changeset
|
1945 |
new (i) Order(orders[i]); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1946 |
} |
8373
7431d91527f2
(svn r11939) -Codechange: some type fixes and very initial steps into supporting NDS by default. Based on work by Dominik.
rubidium
parents:
8302
diff
changeset
|
1947 |
|
7431d91527f2
(svn r11939) -Codechange: some type fixes and very initial steps into supporting NDS by default. Based on work by Dominik.
rubidium
parents:
8302
diff
changeset
|
1948 |
free(orders); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1949 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1950 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1951 |
/* Update all the next pointer */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1952 |
for (i = 1; i < len; ++i) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1953 |
/* The orders were built like this: |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1954 |
* While the order is valid, set the previous will get it's next pointer set |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1955 |
* We start with index 1 because no order will have the first in it's next pointer */ |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1956 |
if (GetOrder(i)->IsValid()) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1957 |
GetOrder(i - 1)->next = GetOrder(i); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1958 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1959 |
} else { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1960 |
int index; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1961 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1962 |
while ((index = SlIterateArray()) != -1) { |
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7049
diff
changeset
|
1963 |
Order *order = new (index) Order(); |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8835
diff
changeset
|
1964 |
SlObject(order, GetOrderDescription()); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1965 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1966 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1967 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1968 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1969 |
extern const ChunkHandler _order_chunk_handlers[] = { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1970 |
{ 'ORDR', Save_ORDR, Load_ORDR, CH_ARRAY | CH_LAST}, |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1971 |
}; |