summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-06-27 20:40:20 +0000
committerpeter1138 <peter1138@openttd.org>2007-06-27 20:40:20 +0000
commitde357c74c1ac4df582f32849bfbc5681c3552171 (patch)
tree30e7a8bb576d442ce724911974f73d059b2ee6b3 /src
parent2a96ca698380b003d1e68f82b1d3fdc4b4df0e44 (diff)
downloadopenttd-de357c74c1ac4df582f32849bfbc5681c3552171.tar.xz
(svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp2
-rw-r--r--src/autoreplace_gui.cpp6
-rw-r--r--src/players.cpp2
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/train_cmd.cpp4
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle.h2
8 files changed, 12 insertions, 10 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index e3045be0a..fa16ab26b 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -451,7 +451,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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]++;
}
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index f77428dda..159c21824 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -38,17 +38,19 @@ void InitializeVehiclesGuiList()
/** 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 */
diff --git a/src/players.cpp b/src/players.cpp
index 109f5c71d..1d529872a 100644
--- a/src/players.cpp
+++ b/src/players.cpp
@@ -736,7 +736,7 @@ CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
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;
}
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 3ca03686a..9fa95b8e0 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -269,7 +269,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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]++;
}
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 2a76c8d8c..f98fde144 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -894,7 +894,7 @@ CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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]++;
}
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index cbd3548f4..ad71a7f39 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -587,7 +587,7 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 fla
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 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
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]++;
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 79e10a1e0..e7080e1a5 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -677,7 +677,7 @@ void DestroyVehicle(Vehicle *v)
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);
diff --git a/src/vehicle.h b/src/vehicle.h
index c51b49f05..df587b84b 100644
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -567,7 +567,7 @@ CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service,
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);