Changeset - r22237:4b9f3d9200bb
[Not reviewed]
master
0 1 0
frosch - 9 years ago 2015-10-30 16:18:39
frosch@openttd.org
(svn r27419) -Fix [FS#6369]: CmdSellRailWagon did not revert all actions properly when no orderlist could be allocated. (Juanjo)
1 file changed with 6 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/train_cmd.cpp
Show inline comments
 
@@ -1377,31 +1377,33 @@ CommandCost CmdSellRailWagon(DoCommandFl
 

	
 
	/* Split the train in the wanted way. */
 
	ArrangeTrains(&sell_head, NULL, &new_head, v, sell_chain);
 

	
 
	/* We don't need to validate the second train; it's going to be sold. */
 
	CommandCost ret = ValidateTrains(NULL, NULL, first, new_head, (flags & DC_AUTOREPLACE) == 0);
 
	if (ret.Failed()) {
 
		/* Restore the train we had. */
 
		RestoreTrainBackup(original);
 
		return ret;
 
	}
 

	
 
	if (first->orders.list == NULL && !OrderList::CanAllocateItem()) {
 
		/* Restore the train we had. */
 
		RestoreTrainBackup(original);
 
		return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
 
	}
 

	
 
	CommandCost cost(EXPENSES_NEW_VEHICLES);
 
	for (Train *t = sell_head; t != NULL; t = t->Next()) cost.AddCost(-t->value);
 

	
 
	if (first->orders.list == NULL && !OrderList::CanAllocateItem()) {
 
		return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
 
	}
 

	
 
	/* do it? */
 
	if (flags & DC_EXEC) {
 
		/* First normalise the sub types of the chain. */
 
		NormaliseSubtypes(new_head);
 

	
 
		if (v == first && v->IsEngine() && !sell_chain && new_head != NULL && new_head->IsFrontEngine()) {
 
			/* We are selling the front engine. In this case we want to
 
			 * 'give' the order, unit number and such to the new head. */
 
			new_head->orders.list = first->orders.list;
 
			new_head->AddToShared(first);
 
			DeleteVehicleOrders(first);
 

	
0 comments (0 inline, 0 general)