diff options
author | smatz <smatz@openttd.org> | 2008-04-24 09:55:20 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2008-04-24 09:55:20 +0000 |
commit | 9fc355fca5d80a7d38d4a35dd6ec00e6adb1391a (patch) | |
tree | 425b0f3d08a6a6ba4e8c57af527383861642e162 | |
parent | 48eda2b6ef4ac2b29bb007218b162207658d70a5 (diff) | |
download | openttd-9fc355fca5d80a7d38d4a35dd6ec00e6adb1391a.tar.xz |
(svn r12862) -Codechange: reduce code duplication for VehicleType -> WindowClass lookup
-rw-r--r-- | src/aircraft.h | 1 | ||||
-rw-r--r-- | src/economy.cpp | 2 | ||||
-rw-r--r-- | src/group_cmd.cpp | 26 | ||||
-rw-r--r-- | src/order_cmd.cpp | 2 | ||||
-rw-r--r-- | src/roadveh.h | 1 | ||||
-rw-r--r-- | src/ship.h | 1 | ||||
-rw-r--r-- | src/station.cpp | 1 | ||||
-rw-r--r-- | src/train.h | 1 | ||||
-rw-r--r-- | src/vehicle.cpp | 2 | ||||
-rw-r--r-- | src/vehicle_base.h | 6 | ||||
-rw-r--r-- | src/vehicle_gui.h | 16 |
11 files changed, 27 insertions, 32 deletions
diff --git a/src/aircraft.h b/src/aircraft.h index 671463b69..bfb8c3b93 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -117,7 +117,6 @@ struct Aircraft : public Vehicle { void MarkDirty(); void UpdateDeltaXY(Direction direction); ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; } - WindowClass GetVehicleListWindowClass() const { return WC_AIRCRAFT_LIST; } bool IsPrimaryVehicle() const { return IsNormalAircraft(this); } SpriteID GetImage(Direction direction) const; int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } diff --git a/src/economy.cpp b/src/economy.cpp index a6dbea987..380a000ba 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1781,7 +1781,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) } if (result != 0) { - InvalidateWindow(v->GetVehicleListWindowClass(), v->owner); + InvalidateWindow(GetWindowClassForVehicleType(v->type), v->owner); InvalidateWindow(WC_VEHICLE_DETAILS, v->index); st->MarkTilesDirty(true); diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 685a9e53b..8696b017e 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -70,18 +70,6 @@ void InitializeGroup(void) } -static WindowClass GetWCForVT(VehicleType vt) -{ - switch (vt) { - default: - case VEH_TRAIN: return WC_TRAINS_LIST; - case VEH_ROAD: return WC_ROADVEH_LIST; - case VEH_SHIP: return WC_SHIPS_LIST; - case VEH_AIRCRAFT: return WC_AIRCRAFT_LIST; - } -} - - /** * Create a new vehicle group. * @param tile unused @@ -100,7 +88,7 @@ CommandCost CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) g->replace_protection = false; g->vehicle_type = vt; - InvalidateWindowData(GetWCForVT(vt), (vt << 11) | VLW_GROUP_LIST | _current_player); + InvalidateWindowData(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | _current_player); } return CommandCost(); @@ -149,7 +137,7 @@ CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) DeleteWindowById(WC_REPLACE_VEHICLE, g->vehicle_type); delete g; - InvalidateWindowData(GetWCForVT(vt), (vt << 11) | VLW_GROUP_LIST | _current_player); + InvalidateWindowData(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | _current_player); } return CommandCost(); @@ -191,7 +179,7 @@ CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) /* Assign the new one */ g->name = strdup(_cmd_text); - InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player); + InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player); } return CommandCost(); @@ -240,7 +228,7 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p /* Update the Replace Vehicle Windows */ InvalidateWindow(WC_REPLACE_VEHICLE, v->type); - InvalidateWindowData(GetWCForVT(v->type), (v->type << 11) | VLW_GROUP_LIST | _current_player); + InvalidateWindowData(GetWindowClassForVehicleType(v->type), (v->type << 11) | VLW_GROUP_LIST | _current_player); } return CommandCost(); @@ -276,7 +264,7 @@ CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, ui } } - InvalidateWindowData(GetWCForVT(type), (type << 11) | VLW_GROUP_LIST | _current_player); + InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_player); } return CommandCost(); @@ -312,7 +300,7 @@ CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, u } } - InvalidateWindowData(GetWCForVT(type), (type << 11) | VLW_GROUP_LIST | _current_player); + InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_player); } return CommandCost(); @@ -337,7 +325,7 @@ CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1 if (flags & DC_EXEC) { g->replace_protection = HasBit(p2, 0); - InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player); + InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player); } return CommandCost(); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 60ec9311d..59fb9a01f 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1663,7 +1663,7 @@ bool ProcessOrders(Vehicle *v) case VEH_AIRCRAFT: case VEH_SHIP: - InvalidateWindowClasses(v->GetVehicleListWindowClass()); + InvalidateWindowClasses(GetWindowClassForVehicleType(v->type)); break; } diff --git a/src/roadveh.h b/src/roadveh.h index a89b73197..3dd20c7c3 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -71,7 +71,6 @@ struct RoadVehicle : public Vehicle { void MarkDirty(); void UpdateDeltaXY(Direction direction); ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; } - WindowClass GetVehicleListWindowClass() const { return WC_ROADVEH_LIST; } bool IsPrimaryVehicle() const { return IsRoadVehFront(this); } SpriteID GetImage(Direction direction) const; int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; } diff --git a/src/ship.h b/src/ship.h index 3d2e3cc02..7f7353642 100644 --- a/src/ship.h +++ b/src/ship.h @@ -32,7 +32,6 @@ struct Ship: public Vehicle { void MarkDirty(); void UpdateDeltaXY(Direction direction); ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_SHIP_INC : EXPENSES_SHIP_RUN; } - WindowClass GetVehicleListWindowClass() const { return WC_SHIPS_LIST; } void PlayLeaveStationSound() const; bool IsPrimaryVehicle() const { return true; } SpriteID GetImage(Direction direction) const; diff --git a/src/station.cpp b/src/station.cpp index ecca12b02..f0c7c3694 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -21,6 +21,7 @@ #include "yapf/yapf.h" #include "cargotype.h" #include "roadveh.h" +#include "window_type.h" #include "station_gui.h" #include "zoom_func.h" #include "functions.h" diff --git a/src/train.h b/src/train.h index cc1882919..7086aedda 100644 --- a/src/train.h +++ b/src/train.h @@ -293,7 +293,6 @@ struct Train : public Vehicle { void MarkDirty(); void UpdateDeltaXY(Direction direction); ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; } - WindowClass GetVehicleListWindowClass() const { return WC_TRAINS_LIST; } void PlayLeaveStationSound() const; bool IsPrimaryVehicle() const { return IsFrontEngine(this); } SpriteID GetImage(Direction direction) const; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 092ef72e7..d8acda4ab 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2546,7 +2546,7 @@ void Vehicle::BeginLoading() VehiclePayment(this); - InvalidateWindow(this->GetVehicleListWindowClass(), this->owner); + InvalidateWindow(GetWindowClassForVehicleType(this->type), this->owner); InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); InvalidateWindow(WC_VEHICLE_DETAILS, this->index); InvalidateWindow(WC_STATION_VIEW, this->last_station_visited); diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 283b743c9..f89fd9458 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -11,7 +11,6 @@ #include "road_type.h" #include "cargo_type.h" #include "direction_type.h" -#include "window_type.h" #include "gfx_type.h" #include "command_type.h" #include "date_type.h" @@ -371,11 +370,6 @@ public: virtual ExpensesType GetExpenseType(bool income) const { return EXPENSES_OTHER; } /** - * Invalidates the vehicle list window of this type of vehicle - */ - virtual WindowClass GetVehicleListWindowClass() const { return WC_NONE; } - - /** * Play the sound associated with leaving the station */ virtual void PlayLeaveStationSound() const {} diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h index d9e4ff173..e10ed2c18 100644 --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -99,6 +99,22 @@ static inline uint GetVehicleListHeight(VehicleType type) return (type == VEH_TRAIN || type == VEH_ROAD) ? 14 : 24; } +/** Get WindowClass for vehicle list of given vehicle type + * @param vt vehicle type to check + * @return corresponding window class + * @note works only for player buildable vehicle types + */ +static inline WindowClass GetWindowClassForVehicleType(VehicleType vt) +{ + switch (vt) { + default: NOT_REACHED(); + case VEH_TRAIN: return WC_TRAINS_LIST; + case VEH_ROAD: return WC_ROADVEH_LIST; + case VEH_SHIP: return WC_SHIPS_LIST; + case VEH_AIRCRAFT: return WC_AIRCRAFT_LIST; + } +} + /* Unified window procedure */ void ShowVehicleViewWindow(const Vehicle *v); |