(svn r12912) -Codechange: overloaded ChangeVehicleViewWindow() so each argument can be either a Vehicle pointer or a VehicleID
authorbjarni
Sun, 27 Apr 2008 18:05:48 +0000
changeset 10371 f4ebcb863ad6
parent 10369 8bae708345df
child 10372 93844492fdd9
(svn r12912) -Codechange: overloaded ChangeVehicleViewWindow() so each argument can be either a Vehicle pointer or a VehicleID
src/vehicle_gui.cpp
src/vehicle_gui.h
--- a/src/vehicle_gui.cpp	Sun Apr 27 10:20:39 2008 +0000
+++ b/src/vehicle_gui.cpp	Sun Apr 27 18:05:48 2008 +0000
@@ -731,40 +731,39 @@
 /** Assigns an already open vehicle window to a new vehicle.
  * Assigns an already open vehicle window to a new vehicle. If the vehicle got
  * any sub window open (orders and so on) it will change owner too.
- * @param *from_v the current owner of the window
- * @param *to_v the new owner of the window
+ * @param from_index the current owner of the window
+ * @param to_index the new owner of the window
  */
-void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v)
+void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index)
 {
-	Window *w;
+	Window *w = FindWindowById(WC_VEHICLE_VIEW, from_index);
 
-	w = FindWindowById(WC_VEHICLE_VIEW, from_v->index);
 	if (w != NULL) {
-		w->window_number = to_v->index;
-		WP(w, vp_d).follow_vehicle = to_v->index;
+		w->window_number = to_index;
+		WP(w, vp_d).follow_vehicle = to_index;
 		SetWindowDirty(w);
 
-		w = FindWindowById(WC_VEHICLE_ORDERS, from_v->index);
+		w = FindWindowById(WC_VEHICLE_ORDERS, from_index);
 		if (w != NULL) {
-			w->window_number = to_v->index;
+			w->window_number = to_index;
 			SetWindowDirty(w);
 		}
 
-		w = FindWindowById(WC_VEHICLE_REFIT, from_v->index);
+		w = FindWindowById(WC_VEHICLE_REFIT, from_index);
 		if (w != NULL) {
-			w->window_number = to_v->index;
+			w->window_number = to_index;
 			SetWindowDirty(w);
 		}
 
-		w = FindWindowById(WC_VEHICLE_DETAILS, from_v->index);
+		w = FindWindowById(WC_VEHICLE_DETAILS, from_index);
 		if (w != NULL) {
-			w->window_number = to_v->index;
+			w->window_number = to_index;
 			SetWindowDirty(w);
 		}
 
-		w = FindWindowById(WC_VEHICLE_TIMETABLE, from_v->index);
+		w = FindWindowById(WC_VEHICLE_TIMETABLE, from_index);
 		if (w != NULL) {
-			w->window_number = to_v->index;
+			w->window_number = to_index;
 			SetWindowDirty(w);
 		}
 	}
--- a/src/vehicle_gui.h	Sun Apr 27 10:20:39 2008 +0000
+++ b/src/vehicle_gui.h	Sun Apr 27 18:05:48 2008 +0000
@@ -10,6 +10,7 @@
 #include "order_type.h"
 #include "station_type.h"
 #include "engine_type.h"
+#include "vehicle_base.h"
 
 void DrawVehicleProfitButton(const Vehicle *v, int x, int y);
 void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order);
@@ -80,8 +81,6 @@
 
 void ShowBuildVehicleWindow(TileIndex tile, VehicleType type);
 
-void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v);
-
 uint ShowAdditionalText(int x, int y, uint w, EngineID engine);
 uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine);
 
@@ -94,6 +93,26 @@
 
 void DrawVehicleImage(const Vehicle *v, int x, int y, VehicleID selection, int count, int skip);
 
+
+/* ChangeVehicleViewWindow() moves all windows for one vehicle to another vehicle.
+ * For ease of use it can be called with both Vehicle pointers and VehicleIDs. */
+void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index);
+
+static inline void ChangeVehicleViewWindow(const Vehicle *from_v, VehicleID to_index)
+{
+	ChangeVehicleViewWindow(from_v->index, to_index);
+}
+
+static inline void ChangeVehicleViewWindow(VehicleID from_index, const Vehicle *to_v)
+{
+	ChangeVehicleViewWindow(from_index, to_v->index);
+}
+
+static inline void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v)
+{
+	ChangeVehicleViewWindow(from_v->index, to_v->index);
+}
+
 static inline uint GetVehicleListHeight(VehicleType type)
 {
 	return (type == VEH_TRAIN || type == VEH_ROAD) ? 14 : 24;