annotate src/order_backup.cpp @ 17232:5d82f4101601 draft

(svn r21972) -Fix: Replace 'None' industries in the generation window with more descriptive label.
author alberth <alberth@openttd.org>
date Sat, 05 Feb 2011 11:42:27 +0000
parents b590eca5d805
children 56b8f26888e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
1 /* $Id$ */
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
2
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
3 /*
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
4 * This file is part of OpenTTD.
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
8 */
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
9
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
10 /** @file order_backup.cpp Handling of order backups. */
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
11
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
12 #include "stdafx.h"
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
13 #include "command_func.h"
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
14 #include "core/pool_func.hpp"
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
15 #include "network/network.h"
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
16 #include "network/network_func.h"
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
17 #include "order_backup.h"
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
18 #include "vehicle_base.h"
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
19
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
20 OrderBackupPool _order_backup_pool("BackupOrder");
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
21 INSTANTIATE_POOL_METHODS(OrderBackup)
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
22
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
23 /** Free everything that is allocated. */
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
24 OrderBackup::~OrderBackup()
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
25 {
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
26 free(this->name);
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
27
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
28 if (CleaningPool()) return;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
29
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
30 Order *o = this->orders;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
31 while (o != NULL) {
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
32 Order *next = o->next;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
33 delete o;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
34 o = next;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
35 }
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
36 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
37
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
38 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
39 * Create an order backup for the given vehicle.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
40 * @param v The vehicle to make a backup of.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
41 * @param user The user that is requesting the backup.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
42 */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
43 OrderBackup::OrderBackup(const Vehicle *v, uint32 user)
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
44 {
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
45 this->user = user;
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
46 this->tile = v->tile;
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
47 this->orderindex = v->cur_auto_order_index;
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
48 this->group = v->group_id;
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
49 this->service_interval = v->service_interval;
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
50
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
51 if (v->name != NULL) this->name = strdup(v->name);
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
52
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
53 /* If we have shared orders, store the vehicle we share the order with. */
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
54 if (v->IsOrderListShared()) {
15859
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
55 this->clone = (v->FirstShared() == v) ? v->NextShared() : v->FirstShared();
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
56 } else {
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
57 /* Else copy the orders */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
58 Order **tail = &this->orders;
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
59
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
60 /* Count the number of orders */
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
61 const Order *order;
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
62 FOR_VEHICLE_ORDERS(v, order) {
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
63 Order *copy = new Order();
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
64 copy->AssignOrder(*order);
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
65 *tail = copy;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
66 tail = &copy->next;
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
67 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
68 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
69 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
70
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
71 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
72 * Restore the data of this order to the given vehicle.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
73 * @param v The vehicle to restore to.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
74 */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
75 void OrderBackup::DoRestore(Vehicle *v)
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
76 {
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
77 /* If we have a custom name, process that */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
78 v->name = this->name;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
79 this->name = NULL;
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
80
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
81 /* If we had shared orders, recover that */
15859
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
82 if (this->clone != NULL) {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
83 DoCommand(0, v->index | CO_SHARE << 30, this->clone->index, DC_EXEC, CMD_CLONE_ORDER);
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
84 } else if (this->orders != NULL && OrderList::CanAllocateItem()) {
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
85 v->orders.list = new OrderList(this->orders, v);
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
86 this->orders = NULL;
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
87 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
88
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
89 uint num_orders = v->GetNumOrders();
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
90 if (num_orders != 0) {
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
91 v->cur_real_order_index = v->cur_auto_order_index = this->orderindex % num_orders;
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
92 v->UpdateRealOrderIndex();
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
93 }
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
94 v->service_interval = this->service_interval;
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
95
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
96 /* Restore vehicle group */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
97 DoCommand(0, this->group, v->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP);
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
98 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
99
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
100 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
101 * Create an order backup for the given vehicle.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
102 * @param v The vehicle to make a backup of.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
103 * @param user The user that is requesting the backup.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
104 * @note Will automatically remove any previous backups of this user.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
105 */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
106 /* static */ void OrderBackup::Backup(const Vehicle *v, uint32 user)
15863
4e8143e1afeb (svn r20545) -Codechange: make sure an OrderBackup gets cleared when the depot it belongs to gets removed, the depot window gets closed or when another vehicle gets sold in a depot
rubidium <rubidium@openttd.org>
parents: 15859
diff changeset
107 {
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
108 /* Don't use reset as that broadcasts over the network to reset the variable,
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
109 * which is what we are doing at the moment. */
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
110 OrderBackup *ob;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
111 FOR_ALL_ORDER_BACKUPS(ob) {
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
112 if (ob->user == user) delete ob;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
113 }
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
114 new OrderBackup(v, user);
15863
4e8143e1afeb (svn r20545) -Codechange: make sure an OrderBackup gets cleared when the depot it belongs to gets removed, the depot window gets closed or when another vehicle gets sold in a depot
rubidium <rubidium@openttd.org>
parents: 15859
diff changeset
115 }
4e8143e1afeb (svn r20545) -Codechange: make sure an OrderBackup gets cleared when the depot it belongs to gets removed, the depot window gets closed or when another vehicle gets sold in a depot
rubidium <rubidium@openttd.org>
parents: 15859
diff changeset
116
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
117 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
118 * Restore the data of this order to the given vehicle.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
119 * @param v The vehicle to restore to.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
120 * @param user The user that built the vehicle, thus wants to restore.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
121 * @note After restoration the backup will automatically be removed.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
122 */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
123 /* static */ void OrderBackup::Restore(Vehicle *v, uint32 user)
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
124 {
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
125 OrderBackup *ob;
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
126 FOR_ALL_ORDER_BACKUPS(ob) {
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
127 if (v->tile != ob->tile || ob->user != user) continue;
15863
4e8143e1afeb (svn r20545) -Codechange: make sure an OrderBackup gets cleared when the depot it belongs to gets removed, the depot window gets closed or when another vehicle gets sold in a depot
rubidium <rubidium@openttd.org>
parents: 15859
diff changeset
128
4e8143e1afeb (svn r20545) -Codechange: make sure an OrderBackup gets cleared when the depot it belongs to gets removed, the depot window gets closed or when another vehicle gets sold in a depot
rubidium <rubidium@openttd.org>
parents: 15859
diff changeset
129 ob->DoRestore(v);
4e8143e1afeb (svn r20545) -Codechange: make sure an OrderBackup gets cleared when the depot it belongs to gets removed, the depot window gets closed or when another vehicle gets sold in a depot
rubidium <rubidium@openttd.org>
parents: 15859
diff changeset
130 delete ob;
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
131 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
132 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
133
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
134 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
135 * Reset an OrderBackup given a tile and user.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
136 * @param tile The tile associated with the OrderBackup.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
137 * @param user The user associated with the OrderBackup.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
138 * @note Must not be used from the GUI!
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
139 */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
140 /* static */ void OrderBackup::ResetOfUser(TileIndex tile, uint32 user)
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
141 {
15863
4e8143e1afeb (svn r20545) -Codechange: make sure an OrderBackup gets cleared when the depot it belongs to gets removed, the depot window gets closed or when another vehicle gets sold in a depot
rubidium <rubidium@openttd.org>
parents: 15859
diff changeset
142 OrderBackup *ob;
4e8143e1afeb (svn r20545) -Codechange: make sure an OrderBackup gets cleared when the depot it belongs to gets removed, the depot window gets closed or when another vehicle gets sold in a depot
rubidium <rubidium@openttd.org>
parents: 15859
diff changeset
143 FOR_ALL_ORDER_BACKUPS(ob) {
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
144 if (ob->user == user && (ob->tile == tile || tile == INVALID_TILE)) delete ob;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
145 }
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
146 }
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
147
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
148 /**
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
149 * Clear an OrderBackup
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
150 * @param tile Tile related to the to-be-cleared OrderBackup.
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
151 * @param flags For command.
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
152 * @param p1 Unused.
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
153 * @param p2 User that had the OrderBackup.
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
154 * @param text Unused.
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
155 * @return The cost of this operation or an error.
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
156 */
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
157 CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
158 {
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
159 /* No need to check anything. If the tile or user don't exist we just ignore it. */
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
160 if (flags & DC_EXEC) OrderBackup::ResetOfUser(tile == 0 ? INVALID_TILE : tile, p2);
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
161
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
162 return CommandCost();
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
163 }
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
164
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
165 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
166 * Reset an user's OrderBackup if needed.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
167 * @param user The user associated with the OrderBackup.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
168 * @pre _network_server.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
169 * @note Must not be used from a command.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
170 */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
171 /* static */ void OrderBackup::ResetUser(uint32 user)
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
172 {
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
173 assert(_network_server);
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
174
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
175 OrderBackup *ob;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
176 FOR_ALL_ORDER_BACKUPS(ob) {
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
177 /* If it's not an backup of us, so ignore it. */
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
178 if (ob->user != user) continue;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
179
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
180 DoCommandP(0, 0, user, CMD_CLEAR_ORDER_BACKUP);
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
181 return;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
182 }
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
183 }
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
184
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
185 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
186 * Reset the OrderBackups from GUI/game logic.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
187 * @param tile The tile of the order backup.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
188 * @param from_gui Whether the call came from the GUI, i.e. whether
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
189 * it must be synced over the network.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
190 */
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
191 /* static */ void OrderBackup::Reset(TileIndex t, bool from_gui)
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
192 {
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
193 /* The user has CLIENT_ID_SERVER as default when network play is not active,
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
194 * but compiled it. A network client has its own variable for the unique
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
195 * client/user identifier. Finally if networking isn't compiled in the
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
196 * default is just plain and simple: 0. */
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
197 #ifdef ENABLE_NETWORK
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
198 uint32 user = _networking && !_network_server ? _network_own_client_id : CLIENT_ID_SERVER;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
199 #else
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
200 uint32 user = 0;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
201 #endif
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
202
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
203 OrderBackup *ob;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
204 FOR_ALL_ORDER_BACKUPS(ob) {
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
205 /* If it's not an backup of us, so ignore it. */
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
206 if (ob->user != user) continue;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
207 /* If it's not for our chosen tile either, ignore it. */
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
208 if (t != INVALID_TILE && t != ob->tile) continue;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
209
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
210 if (from_gui) {
16692
f584ca01635e (svn r21424) -Fix: CMD_CLEAR_ORDER_BACKUP might not get executed when the user pressed the shift key
rubidium <rubidium@openttd.org>
parents: 15944
diff changeset
211 /* We need to circumvent the "prevention" from this command being executed
f584ca01635e (svn r21424) -Fix: CMD_CLEAR_ORDER_BACKUP might not get executed when the user pressed the shift key
rubidium <rubidium@openttd.org>
parents: 15944
diff changeset
212 * while the game is paused, so use the internal method. Nor do we want
f584ca01635e (svn r21424) -Fix: CMD_CLEAR_ORDER_BACKUP might not get executed when the user pressed the shift key
rubidium <rubidium@openttd.org>
parents: 15944
diff changeset
213 * this command to get its cost estimated when shift is pressed. */
16705
1b92dbca45cb (svn r21438) -Fix (r21424): fix triggered an assertion when the build did support networking
rubidium <rubidium@openttd.org>
parents: 16692
diff changeset
214 DoCommandPInternal(ob->tile, 0, user, CMD_CLEAR_ORDER_BACKUP, NULL, NULL, true, false);
15865
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
215 } else {
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
216 /* The command came from the game logic, i.e. the clearing of a tile.
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
217 * In that case we have no need to actually sync this, just do it. */
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
218 delete ob;
270f9b0689cc (svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents: 15863
diff changeset
219 }
15863
4e8143e1afeb (svn r20545) -Codechange: make sure an OrderBackup gets cleared when the depot it belongs to gets removed, the depot window gets closed or when another vehicle gets sold in a depot
rubidium <rubidium@openttd.org>
parents: 15859
diff changeset
220 }
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
221 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
222
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
223 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
224 * Clear the group of all backups having this group ID.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
225 * @param group The group to clear.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
226 */
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
227 /* static */ void OrderBackup::ClearGroup(GroupID group)
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
228 {
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
229 OrderBackup *ob;
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
230 FOR_ALL_ORDER_BACKUPS(ob) {
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
231 if (ob->group == group) ob->group = DEFAULT_GROUP;
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
232 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
233 }
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
234
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
235 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
236 * Clear/update the (clone) vehicle from an order backup.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
237 * @param v The vehicle to clear.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
238 * @pre v != NULL
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
239 * @note If it is not possible to set another vehicle as clone
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
240 * "example", then this backed up order will be removed.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 16705
diff changeset
241 */
15859
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
242 /* static */ void OrderBackup::ClearVehicle(const Vehicle *v)
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
243 {
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
244 assert(v != NULL);
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
245 OrderBackup *ob;
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
246 FOR_ALL_ORDER_BACKUPS(ob) {
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
247 if (ob->clone == v) {
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
248 /* Get another item in the shared list. */
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
249 ob->clone = (v->FirstShared() == v) ? v->NextShared() : v->FirstShared();
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
250 /* But if that isn't there, remove it. */
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
251 if (ob->clone == NULL) delete ob;
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
252 }
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
253 }
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
254 }
e4a43875449c (svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents: 15857
diff changeset
255
15857
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
256 void InitializeOrderBackups()
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
257 {
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
258 _order_backup_pool.CleanPool();
9a9ec79c5d25 (svn r20539) -Codechange: make order backups more self-contained.
rubidium <rubidium@openttd.org>
parents:
diff changeset
259 }