summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-11-16 12:52:01 +0000
committertron <tron@openttd.org>2005-11-16 12:52:01 +0000
commit8cebe2f607d65de4df376bb5bc4f3caac62a2616 (patch)
tree6a81d9964315da3bfab1a7f95113437645b8207b
parent272d63b0621c0d6fad5e117fab67061c8ae4ac2f (diff)
downloadopenttd-8cebe2f607d65de4df376bb5bc4f3caac62a2616.tar.xz
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
-rw-r--r--aircraft_cmd.c4
-rw-r--r--disaster_cmd.c4
-rw-r--r--roadveh_cmd.c4
-rw-r--r--ship_cmd.c4
-rw-r--r--train_cmd.c5
-rw-r--r--viewport.c34
6 files changed, 19 insertions, 36 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index 207793621..c30cf1a5d 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -538,10 +538,6 @@ int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return cost;
}
-void HandleClickOnAircraft(Vehicle *v)
-{
- ShowAircraftViewWindow(v);
-}
static void CheckIfAircraftNeedsService(Vehicle *v)
{
diff --git a/disaster_cmd.c b/disaster_cmd.c
index 12fc40b4f..c83c03920 100644
--- a/disaster_cmd.c
+++ b/disaster_cmd.c
@@ -690,10 +690,6 @@ void DisasterVehicle_Tick(Vehicle *v)
_disastervehicle_tick_procs[v->subtype](v);
}
-void HandleClickOnDisasterVeh(Vehicle *v)
-{
- // not used
-}
void OnNewDay_DisasterVehicle(Vehicle *v)
{
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index bc29715a9..c1d4dd4b0 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -1733,10 +1733,6 @@ void OnNewDay_RoadVeh(Vehicle *v)
InvalidateWindowClasses(WC_ROADVEH_LIST);
}
-void HandleClickOnRoadVeh(Vehicle *v)
-{
- ShowRoadVehViewWindow(v);
-}
void RoadVehiclesYearlyLoop(void)
{
diff --git a/ship_cmd.c b/ship_cmd.c
index b153c5ccc..c029a04b6 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -801,10 +801,6 @@ void Ship_Tick(Vehicle *v)
ShipController(v);
}
-void HandleClickOnShip(Vehicle *v)
-{
- ShowShipViewWindow(v);
-}
void ShipsYearlyLoop(void)
{
diff --git a/train_cmd.c b/train_cmd.c
index 5a6fc9feb..31e74ee75 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -3630,11 +3630,6 @@ void TrainsYearlyLoop(void)
}
}
-void HandleClickOnTrain(Vehicle *v)
-{
- if (v->subtype != TS_Front_Engine) v = GetFirstVehicleInChain(v);
- ShowTrainViewWindow(v);
-}
void InitializeTrains(void)
{
diff --git a/viewport.c b/viewport.c
index c3cc10834..c807a3965 100644
--- a/viewport.c
+++ b/viewport.c
@@ -4,6 +4,7 @@
#include "openttd.h"
#include "debug.h"
#include "functions.h"
+#include "gui.h"
#include "spritecache.h"
#include "strings.h"
#include "table/sprites.h"
@@ -1696,25 +1697,28 @@ static void CheckClickOnLandscape(const ViewPort *vp, int x, int y)
if (pt.x != -1) ClickTile(TileVirtXY(pt.x, pt.y));
}
-void HandleClickOnTrain(Vehicle *v);
-void HandleClickOnRoadVeh(Vehicle *v);
-void HandleClickOnAircraft(Vehicle *v);
-void HandleClickOnShip(Vehicle *v);
-static void HandleClickOnSpecialVeh(Vehicle *v) {}
-void HandleClickOnDisasterVeh(Vehicle *v);
-typedef void OnVehicleClickProc(Vehicle *v);
-static OnVehicleClickProc * const _on_vehicle_click_proc[6] = {
- HandleClickOnTrain,
- HandleClickOnRoadVeh,
- HandleClickOnShip,
- HandleClickOnAircraft,
- HandleClickOnSpecialVeh,
- HandleClickOnDisasterVeh,
+
+static void SafeShowTrainViewWindow(const Vehicle* v)
+{
+ if (v->subtype != TS_Front_Engine) v = GetFirstVehicleInChain(v);
+ ShowTrainViewWindow(v);
+}
+
+static void Nop(const Vehicle* v) {}
+
+typedef void OnVehicleClickProc(const Vehicle* v);
+static OnVehicleClickProc* const _on_vehicle_click_proc[] = {
+ SafeShowTrainViewWindow,
+ ShowRoadVehViewWindow,
+ ShowShipViewWindow,
+ ShowAircraftViewWindow,
+ Nop, // Special vehicles
+ Nop // Disaster vehicles
};
void HandleViewportClicked(const ViewPort *vp, int x, int y)
{
- Vehicle* v;
+ const Vehicle* v;
if (CheckClickOnTown(vp, x, y)) return;
if (CheckClickOnStation(vp, x, y)) return;