diff --git a/train_cmd.c b/train_cmd.c --- a/train_cmd.c +++ b/train_cmd.c @@ -1318,10 +1318,6 @@ int32 CmdRefitRailVehicle(int x, int y, cost = 0; num = 0; - // newgrf stuff can change graphics when refitting - if (!(flags & DC_EXEC)) - InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); - do { /* XXX: We also refit all the attached wagons en-masse if they * can be refitted. This is how TTDPatch does it. TODO: Have @@ -1330,30 +1326,42 @@ int32 CmdRefitRailVehicle(int x, int y, if (v->cargo_cap != 0) { RailVehicleInfo *rvi = RailVehInfo(v->engine_type); - uint16 amount = rvi->capacity; - CargoID old_cid = rvi->cargo_type; - - /* the capacity depends on the cargo type, a rail vehicle - * can carry twice as much mail/goods as normal cargo, - * and four times as much passengers */ - (old_cid == CT_PASSENGERS) || - (amount <<= 1, old_cid == CT_MAIL || old_cid == CT_GOODS) || - (amount <<= 1, true); - (new_cid == CT_PASSENGERS) || - (amount >>= 1, new_cid == CT_MAIL || new_cid == CT_GOODS) || - (amount >>= 1, true); - - if (new_cid != v->cargo_type) - cost += (_price.build_railvehicle >> 8); - num += amount; - if (flags & DC_EXEC) { - //autorefitted train cars wants to keep the cargo - //it will be checked if the cargo is valid in CmdReplaceVehicle - if (!(SkipStoppedInDepotCheck)) - v->cargo_count = 0; - v->cargo_type = new_cid; - v->cargo_cap = amount; - InvalidateWindow(WC_VEHICLE_DETAILS, v->index); + uint16 amount; + CargoID temp_cid = v->cargo_type; + + /* Check the 'refit capacity' callback */ + v->cargo_type = new_cid; + amount = GetCallBackResult(CB_REFIT_CAP, v->engine_type, v); + v->cargo_type = temp_cid; + + if (amount == CALLBACK_FAILED) { // callback failed, use default + CargoID old_cid = rvi->cargo_type; + /* normally, the capacity depends on the cargo type, a rail vehicle + * can carry twice as much mail/goods as normal cargo, + * and four times as much passengers */ + amount = rvi->capacity; + (old_cid == CT_PASSENGERS) || + (amount <<= 1, old_cid == CT_MAIL || old_cid == CT_GOODS) || + (amount <<= 1, true); + (new_cid == CT_PASSENGERS) || + (amount >>= 1, new_cid == CT_MAIL || new_cid == CT_GOODS) || + (amount >>= 1, true); + }; + + if (amount != 0) { + if (new_cid != v->cargo_type) + cost += (_price.build_railvehicle >> 8); + num += amount; + if (flags & DC_EXEC) { + //autorefitted train cars wants to keep the cargo + //it will be checked if the cargo is valid in CmdReplaceVehicle + if (!(SkipStoppedInDepotCheck)) + v->cargo_count = 0; + v->cargo_type = new_cid; + v->cargo_cap = amount; + InvalidateWindow(WC_VEHICLE_DETAILS, v->index); + InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); + } } } // SkipStoppedInDepotCheck is called by CmdReplace and it should only apply to the single car it is called for