equal
deleted
inserted
replaced
425 |
425 |
426 if (!backup.ContainsBackup()) { |
426 if (!backup.ContainsBackup()) { |
427 /* We are going to try to replace a vehicle but we don't have any backup so we will make one. */ |
427 /* We are going to try to replace a vehicle but we don't have any backup so we will make one. */ |
428 backup.Backup(v, p); |
428 backup.Backup(v, p); |
429 } |
429 } |
430 /* Now replace the vehicle */ |
430 /* Now replace the vehicle. |
|
431 * First we need to cache if it's the front vehicle as we need to update the v pointer if it is. |
|
432 * If the replacement fails then we can't trust the data in the vehicle hence the reason to cache the result. */ |
|
433 bool IsFront = w->type != VEH_TRAIN || w->u.rail.first_engine == INVALID_ENGINE; |
|
434 |
431 cost.AddCost(ReplaceVehicle(&w, DC_EXEC, cost.GetCost(), p, new_engine)); |
435 cost.AddCost(ReplaceVehicle(&w, DC_EXEC, cost.GetCost(), p, new_engine)); |
432 |
436 |
433 if (CmdSucceeded(cost) && (w->type != VEH_TRAIN || w->u.rail.first_engine == INVALID_ENGINE)) { |
437 if (IsFront) { |
434 /* now we bought a new engine and sold the old one. We need to fix the |
438 /* now we bought a new engine and sold the old one. We need to fix the |
435 * pointers in order to avoid pointing to the old one for trains: these |
439 * pointers in order to avoid pointing to the old one for trains: these |
436 * pointers should point to the front engine and not the cars |
440 * pointers should point to the front engine and not the cars |
437 */ |
441 */ |
438 v = w; |
442 v = w; |