src/train_cmd.cpp
changeset 6648 fe5626842ec1
parent 6642 2e690e6fdc03
child 6660 da97dfc6ef5f
equal deleted inserted replaced
6647:d565fde8d0f5 6648:fe5626842ec1
  1332 
  1332 
  1333 				/* 2.1 If the first wagon is sold, update the first-> pointers to NULL */
  1333 				/* 2.1 If the first wagon is sold, update the first-> pointers to NULL */
  1334 				for (Vehicle *tmp = first; tmp != NULL; tmp = tmp->next) tmp->first = NULL;
  1334 				for (Vehicle *tmp = first; tmp != NULL; tmp = tmp->next) tmp->first = NULL;
  1335 
  1335 
  1336 				/* 2.2 If there are wagons present after the deleted front engine, check
  1336 				/* 2.2 If there are wagons present after the deleted front engine, check
  1337          * if the second wagon (which will be first) is an engine. If it is one,
  1337 				 * if the second wagon (which will be first) is an engine. If it is one,
  1338          * promote it as a new train, retaining the unitnumber, orders */
  1338 				 * promote it as a new train, retaining the unitnumber, orders */
  1339 				if (new_f != NULL) {
  1339 				if (new_f != NULL && IsTrainEngine(new_f)) {
  1340 					if (IsTrainEngine(new_f)) {
  1340 					switch_engine = true;
  1341 						switch_engine = true;
  1341 					/* Copy important data from the front engine */
  1342 						/* Copy important data from the front engine */
  1342 					new_f->unitnumber      = first->unitnumber;
  1343 						new_f->unitnumber = first->unitnumber;
  1343 					new_f->current_order   = first->current_order;
  1344 						new_f->current_order = first->current_order;
  1344 					new_f->cur_order_index = first->cur_order_index;
  1345 						new_f->cur_order_index = first->cur_order_index;
  1345 					new_f->orders          = first->orders;
  1346 						new_f->orders = first->orders;
  1346 					new_f->num_orders      = first->num_orders;
  1347 						if (first->prev_shared != NULL) {
  1347 
  1348 							first->prev_shared->next_shared = new_f;
  1348 					if (first->prev_shared != NULL) {
  1349 							new_f->prev_shared = first->prev_shared;
  1349 						first->prev_shared->next_shared = new_f;
  1350 						}
  1350 						new_f->prev_shared = first->prev_shared;
  1351 
       
  1352 						if (first->next_shared != NULL) {
       
  1353 							first->next_shared->prev_shared = new_f;
       
  1354 							new_f->next_shared = first->next_shared;
       
  1355 						}
       
  1356 
       
  1357 						new_f->num_orders = first->num_orders;
       
  1358 						first->orders = NULL; // XXX - to not to delete the orders */
       
  1359 						if (IsLocalPlayer()) ShowTrainViewWindow(new_f);
       
  1360 					}
  1351 					}
       
  1352 
       
  1353 					if (first->next_shared != NULL) {
       
  1354 						first->next_shared->prev_shared = new_f;
       
  1355 						new_f->next_shared = first->next_shared;
       
  1356 					}
       
  1357 
       
  1358 					/*
       
  1359 					 * Remove all order information from the front train, to
       
  1360 					 * prevent the order and the shared order list to be
       
  1361 					 * destroyed by Destroy/DeleteVehicle.
       
  1362 					 */
       
  1363 					first->orders      = NULL;
       
  1364 					first->prev_shared = NULL;
       
  1365 					first->next_shared = NULL;
       
  1366 
       
  1367 					if (IsLocalPlayer()) ShowTrainViewWindow(new_f);
  1361 				}
  1368 				}
  1362 			}
  1369 			}
  1363 
  1370 
  1364 			/* 3. Delete the requested wagon */
  1371 			/* 3. Delete the requested wagon */
  1365 			cost -= v->value;
  1372 			cost -= v->value;