changeset 14228:7d6dcc991a43 draft

(svn r18779) -Codechange: merge the command callbacks of the primary vehicles; they are identical
author rubidium <rubidium@openttd.org>
date Mon, 11 Jan 2010 18:34:02 +0000
parents d04c38c339fb
children 3e2f1f02f08b
files src/aircraft.h src/aircraft_gui.cpp src/build_vehicle_gui.cpp src/callback_table.cpp src/command_func.h src/roadveh.h src/roadveh_gui.cpp src/ship.h src/ship_gui.cpp src/train.h src/train_gui.cpp src/vehicle_gui.cpp
diffstat 12 files changed, 48 insertions(+), 115 deletions(-) [+]
line wrap: on
line diff
--- a/src/aircraft.h
+++ b/src/aircraft.h
@@ -28,15 +28,6 @@
 };
 
 
-/**
- * This is the Callback method after the construction attempt of an aircraft
- * @param success indicates completion (or not) of the operation
- * @param tile of depot where aircraft is built
- * @param p1 unused
- * @param p2 unused
- */
-void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2);
-
 /** Handle Aircraft specific tasks when a an Aircraft enters a hangar
  * @param *v Vehicle that enters the hangar
  */
--- a/src/aircraft_gui.cpp
+++ b/src/aircraft_gui.cpp
@@ -102,23 +102,3 @@
 		DrawFrameRect(x - 1, y - 1, x + real_sprite->width + 1, y + real_sprite->height + (helicopter ? 5 : 0) + 1, COLOUR_WHITE, FR_BORDERONLY);
 	}
 }
-
-/**
- * This is the Callback method after the construction attempt of an aircraft
- * @param success indicates completion (or not) of the operation
- * @param tile of depot where aircraft is built
- * @param p1 unused
- * @param p2 unused
- */
-void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
-{
-	if (success) {
-		const Vehicle *v = Vehicle::Get(_new_vehicle_id);
-
-		if (v->tile == _backup_orders_tile) {
-			_backup_orders_tile = 0;
-			RestoreVehicleOrders(v);
-		}
-		ShowVehicleViewWindow(v);
-	}
-}
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -1034,14 +1034,7 @@
 			case BUILD_VEHICLE_WIDGET_BUILD: {
 				EngineID sel_eng = this->sel_engine;
 				if (sel_eng != INVALID_ENGINE) {
-					CommandCallback *callback;
-					switch (this->vehicle_type) {
-						default: NOT_REACHED();
-						case VEH_TRAIN:    callback = (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco; break;
-						case VEH_ROAD:     callback = CcBuildRoadVeh; break;
-						case VEH_SHIP:     callback = CcBuildShip; break;
-						case VEH_AIRCRAFT: callback = CcBuildAircraft; break;
-					}
+					CommandCallback *callback = (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildPrimaryVehicle;
 					DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback);
 				}
 				break;
--- a/src/callback_table.cpp
+++ b/src/callback_table.cpp
@@ -17,8 +17,8 @@
  *   see below for the full list!
  * If you don't do it, it won't work across the network!! */
 
-/* aircraft_gui.cpp */
-CommandCallback CcBuildAircraft;
+/* ai/ai_core.cpp */
+CommandCallback CcAI;
 
 /* airport_gui.cpp */
 CommandCallback CcBuildAirport;
@@ -33,6 +33,9 @@
 /* depot_gui.cpp */
 CommandCallback CcCloneVehicle;
 
+/* group_gui.cpp */
+CommandCallback CcCreateGroup;
+
 /* main_gui.cpp */
 CommandCallback CcPlaySound10;
 CommandCallback CcPlaceSign;
@@ -50,53 +53,40 @@
 CommandCallback CcBuildRoadTunnel;
 CommandCallback CcRoadDepot;
 
-/* roadveh_gui.cpp */
-CommandCallback CcBuildRoadVeh;
-
-/* ship_gui.cpp */
-CommandCallback CcBuildShip;
-
 /* train_gui.cpp */
 CommandCallback CcBuildWagon;
-CommandCallback CcBuildLoco;
 
 /* town_gui.cpp */
 CommandCallback CcFoundTown;
 CommandCallback CcFoundRandomTown;
 
-/* group_gui.cpp */
-CommandCallback CcCreateGroup;
-
-/* ai/ai_core.cpp */
-CommandCallback CcAI;
+/* vehicle_gui.cpp */
+CommandCallback CcBuildPrimaryVehicle;
 
 CommandCallback * const _callback_table[] = {
 	/* 0x00 */ NULL,
-	/* 0x01 */ CcBuildAircraft,
+	/* 0x01 */ CcBuildPrimaryVehicle,
 	/* 0x02 */ CcBuildAirport,
 	/* 0x03 */ CcBuildBridge,
 	/* 0x04 */ CcBuildCanal,
 	/* 0x05 */ CcBuildDocks,
-	/* 0x06 */ CcBuildLoco,
-	/* 0x07 */ CcBuildRoadVeh,
-	/* 0x08 */ CcBuildShip,
-	/* 0x09 */ CcFoundTown,
-	/* 0x0A */ CcBuildRoadTunnel,
-	/* 0x0B */ CcBuildRailTunnel,
-	/* 0x0C */ CcBuildWagon,
-	/* 0x0D */ CcRoadDepot,
-	/* 0x0E */ CcRailDepot,
-	/* 0x0F */ CcPlaceSign,
-	/* 0x10 */ CcPlaySound10,
-	/* 0x11 */ CcPlaySound1D,
-	/* 0x12 */ CcPlaySound1E,
-	/* 0x13 */ CcStation,
-	/* 0x14 */ CcTerraform,
-	/* 0x15 */ CcAI,
-	/* 0x16 */ CcCloneVehicle,
-	/* 0x17 */ CcGiveMoney,
-	/* 0x18 */ CcCreateGroup,
-	/* 0x19 */ CcFoundRandomTown,
+	/* 0x06 */ CcFoundTown,
+	/* 0x07 */ CcBuildRoadTunnel,
+	/* 0x08 */ CcBuildRailTunnel,
+	/* 0x09 */ CcBuildWagon,
+	/* 0x0A */ CcRoadDepot,
+	/* 0x0B */ CcRailDepot,
+	/* 0x0C */ CcPlaceSign,
+	/* 0x0D */ CcPlaySound10,
+	/* 0x0E */ CcPlaySound1D,
+	/* 0x0F */ CcPlaySound1E,
+	/* 0x10 */ CcStation,
+	/* 0x11 */ CcTerraform,
+	/* 0x12 */ CcAI,
+	/* 0x13 */ CcCloneVehicle,
+	/* 0x14 */ CcGiveMoney,
+	/* 0x15 */ CcCreateGroup,
+	/* 0x16 */ CcFoundRandomTown,
 };
 
 const int _callback_table_count = lengthof(_callback_table);
--- a/src/command_func.h
+++ b/src/command_func.h
@@ -107,4 +107,6 @@
 	return flags;
 }
 
+CommandCallback CcBuildPrimaryVehicle;
+
 #endif /* COMMAND_FUNC_H */
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -79,8 +79,6 @@
 };
 
 
-void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2);
-
 void RoadVehUpdateCache(RoadVehicle *v);
 
 /** Cached oftenly queried (NewGRF) values */
--- a/src/roadveh_gui.cpp
+++ b/src/roadveh_gui.cpp
@@ -154,17 +154,3 @@
 		DrawFrameRect((rtl ? pos : left) - 1, y - 1, (rtl ? pos : right) - 1, y + 12, COLOUR_WHITE, FR_BORDERONLY);
 	}
 }
-
-void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2)
-{
-	const Vehicle *v;
-
-	if (!success) return;
-
-	v = Vehicle::Get(_new_vehicle_id);
-	if (v->tile == _backup_orders_tile) {
-		_backup_orders_tile = 0;
-		RestoreVehicleOrders(v);
-	}
-	ShowVehicleViewWindow(v);
-}
--- a/src/ship.h
+++ b/src/ship.h
@@ -17,7 +17,6 @@
 #include "engine_base.h"
 #include "economy_func.h"
 
-void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2);
 void RecalcShipStuff(Vehicle *v);
 void GetShipSpriteSize(EngineID engine, uint &width, uint &height);
 
--- a/src/ship_gui.cpp
+++ b/src/ship_gui.cpp
@@ -46,19 +46,6 @@
 	}
 }
 
-void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2)
-{
-	const Vehicle *v;
-	if (!success) return;
-
-	v = Vehicle::Get(_new_vehicle_id);
-	if (v->tile == _backup_orders_tile) {
-		_backup_orders_tile = 0;
-		RestoreVehicleOrders(v);
-	}
-	ShowVehicleViewWindow(v);
-}
-
 /**
  * Draw the details for the given vehicle at the given position
  *
--- a/src/train.h
+++ b/src/train.h
@@ -44,7 +44,6 @@
 	VRF_TRAIN_STUCK    = 8,
 };
 
-void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2);
 void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
 byte FreightWagonMult(CargoID cargo);
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -47,18 +47,6 @@
 	}
 }
 
-void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
-{
-	if (!success) return;
-
-	const Vehicle *v = Vehicle::Get(_new_vehicle_id);
-	if (tile == _backup_orders_tile) {
-		_backup_orders_tile = 0;
-		RestoreVehicleOrders(v);
-	}
-	ShowVehicleViewWindow(v);
-}
-
 /**
  * Draws an image of a whole train
  * @param v         Front vehicle
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -2141,3 +2141,23 @@
 		w->viewport->follow_vehicle = INVALID_VEHICLE;
 	}
 }
+
+
+/**
+ * This is the Callback method after the construction attempt of a primary vehicle
+ * @param success indicates completion (or not) of the operation
+ * @param tile unused
+ * @param p1 unused
+ * @param p2 unused
+ */
+void CcBuildPrimaryVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2)
+{
+	if (!success) return;
+
+	const Vehicle *v = Vehicle::Get(_new_vehicle_id);
+	if (v->tile == _backup_orders_tile) {
+		_backup_orders_tile = 0;
+		RestoreVehicleOrders(v);
+	}
+	ShowVehicleViewWindow(v);
+}