changeset 7096:c1b9f000066e draft

(svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
author peter1138 <peter1138@openttd.org>
date Wed, 27 Jun 2007 20:40:20 +0000
parents cfd4d752ab7f
children 5c2889ace3ac
files src/aircraft_cmd.cpp src/autoreplace_gui.cpp src/players.cpp src/roadveh_cmd.cpp src/ship_cmd.cpp src/train_cmd.cpp src/vehicle.cpp src/vehicle.h
diffstat 8 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -451,7 +451,7 @@
 		RebuildVehicleLists();
 		InvalidateWindow(WC_COMPANY, v->owner);
 		if (IsLocalPlayer())
-			InvalidateAutoreplaceWindow(VEH_AIRCRAFT); //updates the replace Aircraft window
+			InvalidateAutoreplaceWindow(VEH_AIRCRAFT, v->group_id); //updates the replace Aircraft window
 
 		GetPlayer(_current_player)->num_engines[p1]++;
 	}
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -38,17 +38,19 @@
 
 /** Rebuild the left autoreplace list if an engine is removed or added
  * @param e Engine to check if it is removed or added
+ * @param id_g The group the engine belongs to
  *  Note: this function only works if it is called either
  *   - when a new vehicle is build, but before it's counted in num_engines
  *   - when a vehicle is deleted and after it's substracted from num_engines
  *   - when not changing the count (used when changing replace orders)
  */
-void InvalidateAutoreplaceWindow(EngineID e)
+void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
 {
 	Player *p = GetPlayer(_local_player);
 	byte type = GetEngine(e)->type;
+	uint num_engines = IsDefaultGroupID(id_g) ? p->num_engines[e] : GetGroup(id_g)->num_engines[e];
 
-	if (p->num_engines[e] == 0) {
+	if (num_engines == 0 || p->num_engines[e] == 0) {
 		/* We don't have any of this engine type.
 		 * Either we just sold the last one, we build a new one or we stopped replacing it.
 		 * In all cases, we need to update the left list */
--- a/src/players.cpp
+++ b/src/players.cpp
@@ -736,7 +736,7 @@
 				cost = RemoveEngineReplacementForPlayer(p, old_engine_type,id_g, flags);
 			}
 
-			if (IsLocalPlayer()) InvalidateAutoreplaceWindow(old_engine_type);
+			if (IsLocalPlayer()) InvalidateAutoreplaceWindow(old_engine_type, id_g);
 
 			return cost;
 		}
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -269,7 +269,7 @@
 		RebuildVehicleLists();
 		InvalidateWindow(WC_COMPANY, v->owner);
 		if (IsLocalPlayer())
-			InvalidateAutoreplaceWindow(VEH_ROAD); // updates the replace Road window
+			InvalidateAutoreplaceWindow(VEH_ROAD, v->group_id); // updates the replace Road window
 
 		GetPlayer(_current_player)->num_engines[p1]++;
 	}
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -894,7 +894,7 @@
 		RebuildVehicleLists();
 		InvalidateWindow(WC_COMPANY, v->owner);
 		if (IsLocalPlayer())
-			InvalidateAutoreplaceWindow(VEH_SHIP); // updates the replace Ship window
+			InvalidateAutoreplaceWindow(VEH_SHIP, v->group_id); // updates the replace Ship window
 
 		GetPlayer(_current_player)->num_engines[p1]++;
 	}
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -587,7 +587,7 @@
 
 			InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 			if (IsLocalPlayer()) {
-				InvalidateAutoreplaceWindow(VEH_TRAIN); // updates the replace Train window
+				InvalidateAutoreplaceWindow(VEH_TRAIN, v->group_id); // updates the replace Train window
 			}
 			GetPlayer(_current_player)->num_engines[engine]++;
 		}
@@ -771,7 +771,7 @@
 			RebuildVehicleLists();
 			InvalidateWindow(WC_COMPANY, v->owner);
 			if (IsLocalPlayer())
-				InvalidateAutoreplaceWindow(VEH_TRAIN); // updates the replace Train window
+				InvalidateAutoreplaceWindow(VEH_TRAIN, v->group_id); // updates the replace Train window
 
 			GetPlayer(_current_player)->num_engines[p1]++;
 		}
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -677,7 +677,7 @@
 
 	if (IsEngineCountable(v)) {
 		GetPlayer(v->owner)->num_engines[v->engine_type]--;
-		if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type);
+		if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type, v->group_id);
 
 		if (IsValidGroupID(v->group_id)) GetGroup(v->group_id)->num_engines[v->engine_type]--;
 		if (v->IsPrimaryVehicle()) DecreaseGroupNumVehicle(v->group_id);
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -567,7 +567,7 @@
 bool IsVehicleInDepot(const Vehicle *v);
 void VehicleEnterDepot(Vehicle *v);
 
-void InvalidateAutoreplaceWindow(EngineID e);
+void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g);
 
 CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs);
 bool CanBuildVehicleInfrastructure(VehicleType type);