mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-26 07:59:09 +00:00
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
- Feature: [newgrf] Implement the 'refit capacity' callback.
This commit is contained in:
60
train_cmd.c
60
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;
|
||||
uint16 amount;
|
||||
CargoID temp_cid = v->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);
|
||||
/* 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 (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);
|
||||
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
|
||||
|
Reference in New Issue
Block a user