summaryrefslogtreecommitdiff
path: root/src/roadveh_cmd.cpp
diff options
context:
space:
mode:
authormaedhros <maedhros@openttd.org>2007-08-06 13:05:45 +0000
committermaedhros <maedhros@openttd.org>2007-08-06 13:05:45 +0000
commit8c4a4baac1d452dd572a756ba1cef7aaac587c9f (patch)
tree8691ebb6af7bb197fedb1ff2bc26116ed8896e06 /src/roadveh_cmd.cpp
parenta43370bf1cc0de1804a226cfda6966580e6a5fb8 (diff)
downloadopenttd-8c4a4baac1d452dd572a756ba1cef7aaac587c9f.tar.xz
(svn r10811) -Fix (r10097): Refit all the parts of an articulated road vehicle, not just the first part.
Diffstat (limited to 'src/roadveh_cmd.cpp')
-rw-r--r--src/roadveh_cmd.cpp118
1 files changed, 68 insertions, 50 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 0e4a5751d..a8420fc80 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -2009,7 +2009,7 @@ void RoadVehiclesYearlyLoop()
* @param p2 Bitstuffed elements
* - p2 = (bit 0-7) - the new cargo type to refit to
* - p2 = (bit 8-15) - the new cargo subtype to refit to
- * - p2 = (bit 16) - refit only this vehicle (ignored)
+ * - p2 = (bit 16) - refit only this vehicle
* @return cost of refit or error
*/
CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
@@ -2018,7 +2018,9 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
CommandCost cost;
CargoID new_cid = GB(p2, 0, 8);
byte new_subtype = GB(p2, 8, 8);
+ bool only_this = HASBIT(p2, 16);
uint16 capacity = CALLBACK_FAILED;
+ uint total_capacity = 0;
if (!IsValidVehicleID(p1)) return CMD_ERROR;
@@ -2027,63 +2029,79 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR;
if (!CheckRoadVehInDepotStopped(v)) return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE);
- if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
+ if (new_cid >= NUM_CARGO) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN);
- if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) {
- /* Back up the 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 */
- capacity = 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;
- }
-
- if (capacity == CALLBACK_FAILED) {
- /* callback failed or not used, use default capacity */
- const RoadVehicleInfo *rvi = RoadVehInfo(v->engine_type);
-
- CargoID old_cid = rvi->cargo_type;
- /* normally, the capacity depends on the cargo type, a vehicle can
- * carry twice as much mail/goods as normal cargo, and four times as
- * many passengers
- */
- capacity = GetVehicleProperty(v, 0x0F, rvi->capacity);
- switch (old_cid) {
- case CT_PASSENGERS: break;
- case CT_MAIL:
- case CT_GOODS: capacity *= 2; break;
- default: capacity *= 4; break;
+ for (; v != NULL; v = v->next) {
+ /* XXX: We refit all the attached wagons en-masse if they can be
+ * refitted. This is how TTDPatch does it. TODO: Have some nice
+ * [Refit] button near each wagon. */
+ if (!CanRefitTo(v->engine_type, new_cid)) continue;
+
+ if (v->cargo_cap == 0) continue;
+
+ if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) {
+ /* Back up the 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 */
+ capacity = 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;
}
- switch (new_cid) {
- case CT_PASSENGERS: break;
- case CT_MAIL:
- case CT_GOODS: capacity /= 2; break;
- default: capacity /= 4; break;
+
+ if (capacity == CALLBACK_FAILED) {
+ /* callback failed or not used, use default capacity */
+ const RoadVehicleInfo *rvi = RoadVehInfo(v->engine_type);
+
+ CargoID old_cid = rvi->cargo_type;
+ /* normally, the capacity depends on the cargo type, a vehicle can
+ * carry twice as much mail/goods as normal cargo, and four times as
+ * many passengers
+ */
+ capacity = GetVehicleProperty(v, 0x0F, rvi->capacity);
+ switch (old_cid) {
+ case CT_PASSENGERS: break;
+ case CT_MAIL:
+ case CT_GOODS: capacity *= 2; break;
+ default: capacity *= 4; break;
+ }
+ switch (new_cid) {
+ case CT_PASSENGERS: break;
+ case CT_MAIL:
+ case CT_GOODS: capacity /= 2; break;
+ default: capacity /= 4; break;
+ }
}
- }
- _returned_refit_capacity = capacity;
- if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) {
- cost = GetRefitCost(v->engine_type);
- }
+ if (capacity == 0) continue;
- if (flags & DC_EXEC) {
- v->cargo_cap = capacity;
- v->cargo.Truncate((v->cargo_type == new_cid) ? capacity : 0);
- v->cargo_type = new_cid;
- v->cargo_subtype = new_subtype;
- InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
- InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
- RebuildVehicleLists();
+ total_capacity += capacity;
+
+ if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) {
+ cost.AddCost(GetRefitCost(v->engine_type));
+ }
+
+ if (flags & DC_EXEC) {
+ v->cargo_cap = capacity;
+ v->cargo.Truncate((v->cargo_type == new_cid) ? capacity : 0);
+ v->cargo_type = new_cid;
+ v->cargo_subtype = new_subtype;
+ InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
+ InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
+ RebuildVehicleLists();
+ }
+
+ if (only_this) break;
}
+ _returned_refit_capacity = total_capacity;
+
return cost;
}