1316 SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN); |
1316 SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN); |
1317 |
1317 |
1318 cost = 0; |
1318 cost = 0; |
1319 num = 0; |
1319 num = 0; |
1320 |
1320 |
1321 // newgrf stuff can change graphics when refitting |
|
1322 if (!(flags & DC_EXEC)) |
|
1323 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1324 |
|
1325 do { |
1321 do { |
1326 /* XXX: We also refit all the attached wagons en-masse if they |
1322 /* XXX: We also refit all the attached wagons en-masse if they |
1327 * can be refitted. This is how TTDPatch does it. TODO: Have |
1323 * can be refitted. This is how TTDPatch does it. TODO: Have |
1328 * some nice [Refit] button near each wagon. --pasky */ |
1324 * some nice [Refit] button near each wagon. --pasky */ |
1329 if (!CanRefitTo(v, new_cid)) continue; |
1325 if (!CanRefitTo(v, new_cid)) continue; |
1330 |
1326 |
1331 if (v->cargo_cap != 0) { |
1327 if (v->cargo_cap != 0) { |
1332 RailVehicleInfo *rvi = RailVehInfo(v->engine_type); |
1328 RailVehicleInfo *rvi = RailVehInfo(v->engine_type); |
1333 uint16 amount = rvi->capacity; |
1329 uint16 amount; |
1334 CargoID old_cid = rvi->cargo_type; |
1330 CargoID temp_cid = v->cargo_type; |
1335 |
1331 |
1336 /* the capacity depends on the cargo type, a rail vehicle |
1332 /* Check the 'refit capacity' callback */ |
1337 * can carry twice as much mail/goods as normal cargo, |
1333 v->cargo_type = new_cid; |
1338 * and four times as much passengers */ |
1334 amount = GetCallBackResult(CB_REFIT_CAP, v->engine_type, v); |
1339 (old_cid == CT_PASSENGERS) || |
1335 v->cargo_type = temp_cid; |
1340 (amount <<= 1, old_cid == CT_MAIL || old_cid == CT_GOODS) || |
1336 |
1341 (amount <<= 1, true); |
1337 if (amount == CALLBACK_FAILED) { // callback failed, use default |
1342 (new_cid == CT_PASSENGERS) || |
1338 CargoID old_cid = rvi->cargo_type; |
1343 (amount >>= 1, new_cid == CT_MAIL || new_cid == CT_GOODS) || |
1339 /* normally, the capacity depends on the cargo type, a rail vehicle |
1344 (amount >>= 1, true); |
1340 * can carry twice as much mail/goods as normal cargo, |
1345 |
1341 * and four times as much passengers */ |
1346 if (new_cid != v->cargo_type) |
1342 amount = rvi->capacity; |
1347 cost += (_price.build_railvehicle >> 8); |
1343 (old_cid == CT_PASSENGERS) || |
1348 num += amount; |
1344 (amount <<= 1, old_cid == CT_MAIL || old_cid == CT_GOODS) || |
1349 if (flags & DC_EXEC) { |
1345 (amount <<= 1, true); |
1350 //autorefitted train cars wants to keep the cargo |
1346 (new_cid == CT_PASSENGERS) || |
1351 //it will be checked if the cargo is valid in CmdReplaceVehicle |
1347 (amount >>= 1, new_cid == CT_MAIL || new_cid == CT_GOODS) || |
1352 if (!(SkipStoppedInDepotCheck)) |
1348 (amount >>= 1, true); |
1353 v->cargo_count = 0; |
1349 }; |
1354 v->cargo_type = new_cid; |
1350 |
1355 v->cargo_cap = amount; |
1351 if (amount != 0) { |
1356 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1352 if (new_cid != v->cargo_type) |
|
1353 cost += (_price.build_railvehicle >> 8); |
|
1354 num += amount; |
|
1355 if (flags & DC_EXEC) { |
|
1356 //autorefitted train cars wants to keep the cargo |
|
1357 //it will be checked if the cargo is valid in CmdReplaceVehicle |
|
1358 if (!(SkipStoppedInDepotCheck)) |
|
1359 v->cargo_count = 0; |
|
1360 v->cargo_type = new_cid; |
|
1361 v->cargo_cap = amount; |
|
1362 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1363 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1364 } |
1357 } |
1365 } |
1358 } |
1366 } |
1359 // SkipStoppedInDepotCheck is called by CmdReplace and it should only apply to the single car it is called for |
1367 // SkipStoppedInDepotCheck is called by CmdReplace and it should only apply to the single car it is called for |
1360 } while ( (v=v->next) != NULL || SkipStoppedInDepotCheck ); |
1368 } while ( (v=v->next) != NULL || SkipStoppedInDepotCheck ); |
1361 |
1369 |