summaryrefslogtreecommitdiff
path: root/src/vehicle_cmd.cpp
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-12-21 13:52:10 +0000
committerterkhen <terkhen@openttd.org>2010-12-21 13:52:10 +0000
commita1ff6859c501dd90152b912f748d2b452d745acc (patch)
tree829b9c33e44e4bf29009bc300a915d1e6579572c /src/vehicle_cmd.cpp
parentd92f29b8221e06d24df0416ae1609e8588e0b2c3 (diff)
downloadopenttd-a1ff6859c501dd90152b912f748d2b452d745acc.tar.xz
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
Diffstat (limited to 'src/vehicle_cmd.cpp')
-rw-r--r--src/vehicle_cmd.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index fad93e5e8..a3fa06048 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -244,20 +244,31 @@ static CommandCost GetRefitCost(EngineID engine_type)
* Refits a vehicle (chain).
* This is the vehicle-type independent part of the CmdRefitXXX functions.
* @param v The vehicle to refit.
- * @param only_this Whether to only refit this vehicle, or the whole chain.
+ * @param only_this Whether to only refit this vehicle, or to check the rest of them.
+ * @param num_vehicles Number of vehicles to refit. Zero means the whole chain.
* @param new_cid Cargotype to refit to
* @param new_subtype Cargo subtype to refit to
* @param flags Command flags
* @return Refit cost.
*/
-static CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags)
+static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles, CargoID new_cid, byte new_subtype, DoCommandFlag flags)
{
CommandCost cost(v->GetExpenseType(false));
uint total_capacity = 0;
uint total_mail_capacity = 0;
+ num_vehicles = num_vehicles == 0 ? UINT8_MAX : num_vehicles;
+
+ VehicleSet vehicles_to_refit;
+ if (!only_this) {
+ GetVehicleSet(vehicles_to_refit, v, num_vehicles);
+ /* In this case, we need to check the whole chain. */
+ v = v->First();
+ }
v->InvalidateNewGRFCacheOfChain();
for (; v != NULL; v = (only_this ? NULL : v->Next())) {
+ if (v->type == VEH_TRAIN && !vehicles_to_refit.Contains(v->index) && !only_this) continue;
+
const Engine *e = Engine::Get(v->engine_type);
if (!e->CanCarryCargo() || !HasBit(e->info.refit_mask, new_cid)) continue;
@@ -305,9 +316,10 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byt
* @param flags type of operation
* @param p1 vehicle ID to refit
* @param p2 various 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
+ * - p2 = (bit 0-7) - New cargo type to refit to.
+ * - p2 = (bit 8-15) - New cargo subtype to refit to.
+ * - p2 = (bit 16) - Refit only this vehicle. Used only for cloning vehicles.
+ * - p2 = (bit 17-24) - Number of vehicles to refit. Zero means all vehicles. Only used if "refit only this vehicle" is false.
* @param text unused
* @return the cost of this operation or an error
*/
@@ -337,8 +349,9 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
/* For ships and aircrafts there is always only one. */
bool only_this = HasBit(p2, 16) || front->type == VEH_SHIP || front->type == VEH_AIRCRAFT;
+ uint8 num_vehicles = GB(p2, 17, 8);
- CommandCost cost = RefitVehicle(v, only_this, new_cid, new_subtype, flags);
+ CommandCost cost = RefitVehicle(v, only_this, num_vehicles, new_cid, new_subtype, flags);
if (flags & DC_EXEC) {
/* Update the cached variables */