From 799e1f5c50662cfa334e2b759925badf70bf5b0d Mon Sep 17 00:00:00 2001 From: hackykid Date: Wed, 1 Jun 2005 11:34:37 +0000 Subject: (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks. - Feature: [newgrf] Implement the 'refit capacity' callback. --- train_cmd.c | 64 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'train_cmd.c') diff --git a/train_cmd.c b/train_cmd.c index 25ec0c8e4..483eb7370 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -1318,10 +1318,6 @@ int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) 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, uint32 flags, uint32 p1, uint32 p2) 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 -- cgit v1.2.3-54-g00ecf