summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-01-23 14:58:54 +0000
committerfrosch <frosch@openttd.org>2011-01-23 14:58:54 +0000
commit9a1c0f139aeafd3ff550d0689e3a4c227927f0e5 (patch)
tree45c8b5f0450ca60560286502972b4c507494a0a5
parent3f103c35a6af62993cc01d53d9fd4554f353bf60 (diff)
downloadopenttd-9a1c0f139aeafd3ff550d0689e3a4c227927f0e5.tar.xz
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
-rw-r--r--src/vehicle.cpp31
-rw-r--r--src/vehicle_cmd.cpp5
-rw-r--r--src/vehicle_gui.cpp7
3 files changed, 21 insertions, 22 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 19c11eae2..d5b2b5c60 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2359,7 +2359,7 @@ const GroundVehicleCache *Vehicle::GetGroundVehicleCache() const
* Calculates the set of vehicles that will be affected by a given selection.
* @param set Set of affected vehicles.
* @param v First vehicle of the selection.
- * @param num_vehicles Number of vehicles in the selection.
+ * @param num_vehicles Number of vehicles in the selection (not counting articulated parts).
* @pre \c set must be empty.
* @post \c set will contain the vehicles that will be refitted.
*/
@@ -2367,27 +2367,20 @@ void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles)
{
if (v->type == VEH_TRAIN) {
Train *u = Train::From(v);
- /* If the first vehicle in the selection is part of an articulated vehicle, add the previous parts of the vehicle. */
- if (u->IsArticulatedPart()) {
- u = u->GetFirstEnginePart();
- while (u->index != v->index) {
- set.Include(u->index);
- u = u->GetNextArticulatedPart();
- }
- }
+ /* Only include whole vehicles, so start with the first articulated part */
+ u = u->GetFirstEnginePart();
- for (;u != NULL && num_vehicles > 0; num_vehicles--, u = u->Next()) {
- /* Include current vehicle in the selection. */
- set.Include(u->index);
+ /* Include num_vehicles vehicles, not counting articulated parts */
+ for (; u != NULL && num_vehicles > 0; num_vehicles--) {
+ do {
+ /* Include current vehicle in the selection. */
+ set.Include(u->index);
- /* If the vehicle is multiheaded, add the other part too. */
- if (u->IsMultiheaded()) set.Include(u->other_multiheaded_part->index);
- }
+ /* If the vehicle is multiheaded, add the other part too. */
+ if (u->IsMultiheaded()) set.Include(u->other_multiheaded_part->index);
- /* If the last vehicle is part of an articulated vehicle, add the following parts of the vehicle. */
- while (u != NULL && u->IsArticulatedPart()) {
- set.Include(u->index);
- u = u->Next();
+ u = u->Next();
+ } while (u != NULL && u->IsArticulatedPart());
}
}
}
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 0c3ec7f34..a083a40a0 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -245,7 +245,7 @@ static CommandCost GetRefitCost(EngineID engine_type)
* 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 to check the rest of them.
- * @param num_vehicles Number of vehicles to refit. Zero means the whole chain.
+ * @param num_vehicles Number of vehicles to refit (not counting articulated parts). Zero means the whole chain.
* @param new_cid Cargotype to refit to
* @param new_subtype Cargo subtype to refit to
* @param flags Command flags
@@ -319,7 +319,8 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles,
* - p2 = (bit 0-4) - New cargo type to refit to.
* - p2 = (bit 7) - Refit only this vehicle. Used only for cloning vehicles.
* - p2 = (bit 8-15) - New cargo subtype to refit to.
- * - p2 = (bit 16-23) - Number of vehicles to refit. Zero means all vehicles. Only used if "refit only this vehicle" is false.
+ * - p2 = (bit 16-23) - Number of vehicles to refit (not counting articulated parts). 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
*/
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 5bd5f18ef..9c94fea4b 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -758,9 +758,14 @@ struct RefitWindow : public Window {
if (left_x < 0 && !start_counting) {
this->selected_vehicle = u->index;
start_counting = true;
+
+ /* Count the first vehicle, even if articulated part */
+ this->num_vehicles++;
+ } else if (start_counting && !u->IsArticulatedPart()) {
+ /* Do not count articulated parts */
+ this->num_vehicles++;
}
- if (start_counting) this->num_vehicles++;
if (right_x < 0) break;
}
}