summaryrefslogtreecommitdiff
path: root/train_cmd.c
diff options
context:
space:
mode:
authorhackykid <hackykid@openttd.org>2005-06-01 11:34:37 +0000
committerhackykid <hackykid@openttd.org>2005-06-01 11:34:37 +0000
commit799e1f5c50662cfa334e2b759925badf70bf5b0d (patch)
tree09bec4a6bd097d4449f7cfdff13cc475960d9703 /train_cmd.c
parent80cbf3a0ee154d76592b5c7e9b1f8c997cfc60d4 (diff)
downloadopenttd-799e1f5c50662cfa334e2b759925badf70bf5b0d.tar.xz
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
- Feature: [newgrf] Implement the 'refit capacity' callback.
Diffstat (limited to 'train_cmd.c')
-rw-r--r--train_cmd.c64
1 files changed, 36 insertions, 28 deletions
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