File diff r19520:2f25138b0538 → r19521:9abf5bbcc05a
src/order_backup.cpp
Show inline comments
 
@@ -41,97 +41,97 @@ OrderBackup::~OrderBackup()
 
 * @param user The user that is requesting the backup.
 
 */
 
OrderBackup::OrderBackup(const Vehicle *v, uint32 user)
 
{
 
	this->user             = user;
 
	this->tile             = v->tile;
 
	this->group            = v->group_id;
 

	
 
	this->CopyConsistPropertiesFrom(v);
 

	
 
	/* If we have shared orders, store the vehicle we share the order with. */
 
	if (v->IsOrderListShared()) {
 
		this->clone = (v->FirstShared() == v) ? v->NextShared() : v->FirstShared();
 
	} else {
 
		/* Else copy the orders */
 
		Order **tail = &this->orders;
 

	
 
		/* Count the number of orders */
 
		const Order *order;
 
		FOR_VEHICLE_ORDERS(v, order) {
 
			Order *copy = new Order();
 
			copy->AssignOrder(*order);
 
			*tail = copy;
 
			tail = &copy->next;
 
		}
 
	}
 
}
 

	
 
/**
 
 * Restore the data of this order to the given vehicle.
 
 * @param v The vehicle to restore to.
 
 */
 
void OrderBackup::DoRestore(Vehicle *v)
 
{
 
	/* If we had shared orders, recover that */
 
	if (this->clone != NULL) {
 
		DoCommand(0, v->index | CO_SHARE << 30, this->clone->index, DC_EXEC, CMD_CLONE_ORDER);
 
	} else if (this->orders != NULL && OrderList::CanAllocateItem()) {
 
		v->orders.list = new OrderList(this->orders, v);
 
		this->orders = NULL;
 
		/* Make sure buoys/oil rigs are updated in the station list. */
 
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
 
	}
 

	
 
	v->CopyConsistPropertiesFrom(this);
 

	
 
	/* Make sure orders are in range */
 
	v->UpdateRealOrderIndex();
 
	v->cur_implicit_order_index = v->cur_real_order_index;
 
	if (v->cur_implicit_order_index >= v->GetNumOrders()) v->cur_implicit_order_index = v->cur_real_order_index;
 

	
 
	/* Restore vehicle group */
 
	DoCommand(0, this->group, v->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP);
 
}
 

	
 
/**
 
 * Create an order backup for the given vehicle.
 
 * @param v    The vehicle to make a backup of.
 
 * @param user The user that is requesting the backup.
 
 * @note Will automatically remove any previous backups of this user.
 
 */
 
/* static */ void OrderBackup::Backup(const Vehicle *v, uint32 user)
 
{
 
	/* Don't use reset as that broadcasts over the network to reset the variable,
 
	 * which is what we are doing at the moment. */
 
	OrderBackup *ob;
 
	FOR_ALL_ORDER_BACKUPS(ob) {
 
		if (ob->user == user) delete ob;
 
	}
 
	if (OrderBackup::CanAllocateItem()) {
 
		new OrderBackup(v, user);
 
	}
 
}
 

	
 
/**
 
 * Restore the data of this order to the given vehicle.
 
 * @param v    The vehicle to restore to.
 
 * @param user The user that built the vehicle, thus wants to restore.
 
 * @note After restoration the backup will automatically be removed.
 
 */
 
/* static */ void OrderBackup::Restore(Vehicle *v, uint32 user)
 
{
 
	OrderBackup *ob;
 
	FOR_ALL_ORDER_BACKUPS(ob) {
 
		if (v->tile != ob->tile || ob->user != user) continue;
 

	
 
		ob->DoRestore(v);
 
		delete ob;
 
	}
 
}
 

	
 
/**
 
 * Reset an OrderBackup given a tile and user.
 
 * @param tile The tile associated with the OrderBackup.
 
 * @param user The user associated with the OrderBackup.
 
 * @note Must not be used from the GUI!
 
 */
 
/* static */ void OrderBackup::ResetOfUser(TileIndex tile, uint32 user)