1846 total_cost += cost; |
1846 total_cost += cost; |
1847 |
1847 |
1848 if (flags & DC_EXEC) { |
1848 if (flags & DC_EXEC) { |
1849 w = GetVehicle(_new_vehicle_id); |
1849 w = GetVehicle(_new_vehicle_id); |
1850 |
1850 |
1851 if (v->cargo_type != w->cargo_type || v->cargo_subtype != w->cargo_subtype) { |
1851 Vehicle *w2 = w; |
1852 // we can't pay for refitting because we can't estimate refitting costs for a vehicle before it's build |
1852 Vehicle *v2 = v; |
1853 // if we pay for it anyway, the cost and the estimated cost will not be the same and we will have an assert |
1853 do { |
1854 DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8), flags, GetCmdRefitVeh(v)); |
1854 if (v2->cargo_type != w2->cargo_type || v2->cargo_subtype != w2->cargo_subtype) { |
1855 } |
1855 /* We can't pay for refitting because we can't estimate refitting costs for a vehicle before it's build. |
|
1856 * If we pay for it anyway, the cost and the estimated cost will not be the same and we will have an assert. |
|
1857 * We need to check the whole chain if it is a train because some newgrf articulated engines can refit some units only (and not the front) */ |
|
1858 DoCommand(0, w->index, v2->cargo_type | (v2->cargo_subtype << 8), flags, GetCmdRefitVeh(v)); |
|
1859 break; // We learned that the engine in question needed a refit. No need to check anymore |
|
1860 } |
|
1861 } while (v->type == VEH_Train && (w2 = w2->next) != NULL && (v2 = v2->next) != NULL); |
|
1862 |
1856 if (v->type == VEH_Train && HASBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION)) { |
1863 if (v->type == VEH_Train && HASBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION)) { |
1857 SETBIT(w->u.rail.flags, VRF_REVERSE_DIRECTION); |
1864 SETBIT(w->u.rail.flags, VRF_REVERSE_DIRECTION); |
1858 } |
1865 } |
1859 |
1866 |
1860 if (v->type == VEH_Train && !IsFrontEngine(v)) { |
1867 if (v->type == VEH_Train && !IsFrontEngine(v)) { |