@ -37,15 +37,10 @@ OrderBackup::OrderBackup(const Vehicle *v)
/* If we have shared orders, store the vehicle we share the order with. */
/* If we have shared orders, store the vehicle we share the order with. */
if ( v - > IsOrderListShared ( ) ) {
if ( v - > IsOrderListShared ( ) ) {
const Vehicle * u = ( v - > FirstShared ( ) = = v ) ? v - > NextShared ( ) : v - > FirstShared ( ) ;
this - > clone = ( v - > FirstShared ( ) = = v ) ? v - > NextShared ( ) : v - > FirstShared ( ) ;
this - > clone = u - > index ;
} else {
} else {
/* Else copy the orders */
/* Else copy the orders */
/* We do not have shared orders */
this - > clone = INVALID_VEHICLE ;
/* Count the number of orders */
/* Count the number of orders */
uint cnt = 0 ;
uint cnt = 0 ;
const Order * order ;
const Order * order ;
@ -72,9 +67,9 @@ void OrderBackup::RestoreTo(const Vehicle *v)
if ( this - > name ! = NULL ) DoCommandP ( 0 , v - > index , 0 , CMD_RENAME_VEHICLE , NULL , this - > name ) ;
if ( this - > name ! = NULL ) DoCommandP ( 0 , v - > index , 0 , CMD_RENAME_VEHICLE , NULL , this - > name ) ;
/* If we had shared orders, recover that */
/* If we had shared orders, recover that */
if ( this - > clone ! = INVALID_VEHICLE ) {
if ( this - > clone ! = NULL ) {
DoCommandP ( 0 , v - > index | ( this - > clone < < 16 ) , CO_SHARE , CMD_CLONE_ORDER ) ;
DoCommandP ( 0 , v - > index | ( this - > clone - > index < < 16 ) , CO_SHARE , CMD_CLONE_ORDER ) ;
} else {
} else if ( this - > orders ! = NULL ) {
/* CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the
/* CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the
* order number is one more than the current amount of orders , and because
* order number is one more than the current amount of orders , and because
@ -140,6 +135,20 @@ void OrderBackup::RestoreTo(const Vehicle *v)
}
}
}
}
/* static */ void OrderBackup : : ClearVehicle ( const Vehicle * v )
{
assert ( v ! = NULL ) ;
OrderBackup * ob ;
FOR_ALL_ORDER_BACKUPS ( ob ) {
if ( ob - > clone = = v ) {
/* Get another item in the shared list. */
ob - > clone = ( v - > FirstShared ( ) = = v ) ? v - > NextShared ( ) : v - > FirstShared ( ) ;
/* But if that isn't there, remove it. */
if ( ob - > clone = = NULL ) delete ob ;
}
}
}
void InitializeOrderBackups ( )
void InitializeOrderBackups ( )
{
{
_order_backup_pool . CleanPool ( ) ;
_order_backup_pool . CleanPool ( ) ;