summaryrefslogtreecommitdiff
path: root/src/train_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-10-28 18:31:16 +0000
committerfrosch <frosch@openttd.org>2009-10-28 18:31:16 +0000
commit83894809d0bf63f5375cf546f3d353f5299a6442 (patch)
treee5bc6eae133e4d7d043c01575a691812798c353e /src/train_cmd.cpp
parent2a3c797138b988a4c836215a8d98b8f85244c48e (diff)
downloadopenttd-83894809d0bf63f5375cf546f3d353f5299a6442.tar.xz
(svn r17897) -Fix [FS#3255]: CB15 and CB36 (capacity) were not always called when they should.
-Codechange: Move capacity calculation to a single function for all vehicle types, so the behaviour can be kept consistent easier.
Diffstat (limited to 'src/train_cmd.cpp')
-rw-r--r--src/train_cmd.cpp49
1 files changed, 12 insertions, 37 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index e0e32efd5..be4c66f3e 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -316,10 +316,7 @@ void TrainConsistChanged(Train *v, bool same_length)
}
}
- if (e_u->CanCarryCargo() && u->cargo_type == e_u->GetDefaultCargoType() && u->cargo_subtype == 0) {
- /* Set cargo capacity if we've not been refitted */
- u->cargo_cap = GetVehicleProperty(u, PROP_TRAIN_CARGO_CAPACITY, rvi_u->capacity);
- }
+ u->cargo_cap = GetVehicleCapacity(u);
/* check the vehicle length (callback) */
uint16 veh_len = CALLBACK_FAILED;
@@ -2119,6 +2116,7 @@ CommandCost CmdRefitRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
CommandCost cost(EXPENSES_TRAIN_RUN);
uint num = 0;
+ v->InvalidateNewGRFCacheOfChain();
do {
/* XXX: We also refit all the attached wagons en-masse if they
* can be refitted. This is how TTDPatch does it. TODO: Have
@@ -2128,40 +2126,17 @@ CommandCost CmdRefitRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
const Engine *e = Engine::Get(v->engine_type);
if (!e->CanCarryCargo()) continue;
- uint16 amount = CALLBACK_FAILED;
- if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
- /* Back up the vehicle's cargo type */
- CargoID temp_cid = v->cargo_type;
- byte temp_subtype = v->cargo_subtype;
- v->cargo_type = new_cid;
- v->cargo_subtype = new_subtype;
- /* Check the refit capacity callback */
- amount = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
- /* Restore the original cargo type */
- v->cargo_type = temp_cid;
- v->cargo_subtype = temp_subtype;
- }
+ /* Back up the vehicle's cargo type */
+ CargoID temp_cid = v->cargo_type;
+ byte temp_subtype = v->cargo_subtype;
+ v->cargo_type = new_cid;
+ v->cargo_subtype = new_subtype;
- if (amount == CALLBACK_FAILED) { // callback failed or not used, use default
- CargoID old_cid = e->GetDefaultCargoType();
- /* 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
- * many passengers
- */
- amount = e->u.rail.capacity;
- switch (old_cid) {
- case CT_PASSENGERS: break;
- case CT_MAIL:
- case CT_GOODS: amount *= 2; break;
- default: amount *= 4; break;
- }
- switch (new_cid) {
- case CT_PASSENGERS: break;
- case CT_MAIL:
- case CT_GOODS: amount /= 2; break;
- default: amount /= 4; break;
- }
- }
+ uint amount = GetVehicleCapacity(v);
+
+ /* Restore the original cargo type */
+ v->cargo_type = temp_cid;
+ v->cargo_subtype = temp_subtype;
if (new_cid != v->cargo_type) {
cost.AddCost(GetRefitCost(v->engine_type));