diff --git a/src/aircraft.h b/src/aircraft.h index a66b3a177e..34c4cdc6a9 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -133,6 +133,8 @@ struct Aircraft : public Vehicle { const char *GetTypeString() { return "aircraft"; } void MarkDirty(); void UpdateDeltaXY(Direction direction); + ExpensesType GetExpenseType(bool income) { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; } + WindowClass GetVehicleListWindowClass() { return WC_AIRCRAFT_LIST; } }; #endif /* AIRCRAFT_H */ diff --git a/src/openttd.h b/src/openttd.h index ca19a04819..187804cf9d 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -473,7 +473,7 @@ enum WindowClass { }; -enum { +enum ExpensesType { EXPENSES_CONSTRUCTION = 0, EXPENSES_NEW_VEHICLES = 1, EXPENSES_TRAIN_RUN = 2, diff --git a/src/roadveh.h b/src/roadveh.h index 340a740764..c3d8cbf942 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -41,6 +41,8 @@ struct RoadVehicle : public Vehicle { const char *GetTypeString() { return "road vehicle"; } void MarkDirty(); void UpdateDeltaXY(Direction direction); + ExpensesType GetExpenseType(bool income) { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; } + WindowClass GetVehicleListWindowClass() { return WC_ROADVEH_LIST; } }; #endif /* ROADVEH_H */ diff --git a/src/ship.h b/src/ship.h index e277f91c42..0d4e324ae2 100644 --- a/src/ship.h +++ b/src/ship.h @@ -42,6 +42,8 @@ struct Ship: public Vehicle { const char *GetTypeString() { return "ship"; } void MarkDirty(); void UpdateDeltaXY(Direction direction); + ExpensesType GetExpenseType(bool income) { return income ? EXPENSES_SHIP_INC : EXPENSES_SHIP_RUN; } + WindowClass GetVehicleListWindowClass() { return WC_SHIPS_LIST; } }; #endif /* SHIP_H */ diff --git a/src/train.h b/src/train.h index 317d93c2d5..eaebf04bc5 100644 --- a/src/train.h +++ b/src/train.h @@ -246,6 +246,8 @@ struct Train : public Vehicle { const char *GetTypeString() { return "train"; } void MarkDirty(); void UpdateDeltaXY(Direction direction); + ExpensesType GetExpenseType(bool income) { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; } + WindowClass GetVehicleListWindowClass() { return WC_TRAINS_LIST; } }; #endif /* TRAIN_H */ diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 143f1fc362..20f67c771f 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2970,13 +2970,9 @@ void Vehicle::BeginLoading() current_order.type = OT_LOADING; GetStation(this->last_station_visited)->loading_vehicles.push_back(this); - static const int expense_type[] = { EXPENSES_TRAIN_INC, EXPENSES_ROADVEH_INC, EXPENSES_SHIP_INC, EXPENSES_AIRCRAFT_INC }; - SET_EXPENSES_TYPE(expense_type[this->type]); - + SET_EXPENSES_TYPE(this->GetExpenseType(true)); if (LoadUnloadVehicle(this, true) != 0) { - static const WindowClass invalidate_windows[] = { WC_TRAINS_LIST, WC_ROADVEH_LIST, WC_SHIPS_LIST, WC_AIRCRAFT_LIST }; - InvalidateWindow(invalidate_windows[this->type], this->owner); - + InvalidateWindow(this->GetVehicleListWindowClass(), this->owner); this->MarkDirty(); } InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, STATUS_BAR); diff --git a/src/vehicle.h b/src/vehicle.h index dd9ca71baa..1b2be2eb1b 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -365,6 +365,17 @@ struct Vehicle { * @param direction the direction the vehicle is facing */ virtual void UpdateDeltaXY(Direction direction) {} + + /** + * Sets the expense type associated to this vehicle type + * @param income whether this is income or (running) expenses of the vehicle + */ + virtual ExpensesType GetExpenseType(bool income) { return EXPENSES_OTHER; } + + /** + * Invalidates the vehicle list window of this type of vehicle + */ + virtual WindowClass GetVehicleListWindowClass() { return WC_NONE; } }; /**