(svn r9764) -Codechange: replace some lookup tables by functions.
--- a/src/aircraft.h Tue May 01 18:17:52 2007 +0000
+++ b/src/aircraft.h Wed May 02 09:29:41 2007 +0000
@@ -133,6 +133,8 @@
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 */
--- a/src/openttd.h Tue May 01 18:17:52 2007 +0000
+++ b/src/openttd.h Wed May 02 09:29:41 2007 +0000
@@ -473,7 +473,7 @@
};
-enum {
+enum ExpensesType {
EXPENSES_CONSTRUCTION = 0,
EXPENSES_NEW_VEHICLES = 1,
EXPENSES_TRAIN_RUN = 2,
--- a/src/roadveh.h Tue May 01 18:17:52 2007 +0000
+++ b/src/roadveh.h Wed May 02 09:29:41 2007 +0000
@@ -41,6 +41,8 @@
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 */
--- a/src/ship.h Tue May 01 18:17:52 2007 +0000
+++ b/src/ship.h Wed May 02 09:29:41 2007 +0000
@@ -42,6 +42,8 @@
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 */
--- a/src/train.h Tue May 01 18:17:52 2007 +0000
+++ b/src/train.h Wed May 02 09:29:41 2007 +0000
@@ -246,6 +246,8 @@
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 */
--- a/src/vehicle.cpp Tue May 01 18:17:52 2007 +0000
+++ b/src/vehicle.cpp Wed May 02 09:29:41 2007 +0000
@@ -2970,13 +2970,9 @@
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);
--- a/src/vehicle.h Tue May 01 18:17:52 2007 +0000
+++ b/src/vehicle.h Wed May 02 09:29:41 2007 +0000
@@ -365,6 +365,17 @@
* @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; }
};
/**