summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/airport_gui.cpp31
-rw-r--r--src/newgrf_class.h7
-rw-r--r--src/newgrf_class_func.h26
-rw-r--r--src/newgrf_station.cpp3
-rw-r--r--src/object_gui.cpp34
-rw-r--r--src/rail_gui.cpp34
-rw-r--r--src/saveload/waypoint_sl.cpp7
-rw-r--r--src/station_cmd.cpp6
-rw-r--r--src/waypoint_cmd.cpp4
9 files changed, 72 insertions, 80 deletions
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index 893e3b5fb..8ac038b9c 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -57,7 +57,7 @@ static void PlaceAirport(TileIndex tile)
uint32 p2 = _ctrl_pressed;
SB(p2, 16, 16, INVALID_STATION); // no station to join
- uint32 p1 = AirportClass::Get(_selected_airport_class, _selected_airport_index)->GetIndex();
+ uint32 p1 = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
p1 |= _selected_airport_layout << 8;
CommandContainer cmdcont = { tile, p1, p2, CMD_BUILD_AIRPORT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport, "" };
ShowSelectStationIfNeeded(cmdcont, TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE));
@@ -229,7 +229,7 @@ public:
this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
this->OnInvalidateData();
- this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
+ this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
this->SelectFirstAvailableAirport(true);
}
@@ -248,7 +248,7 @@ public:
case WID_AP_LAYOUT_NUM:
SetDParam(0, STR_EMPTY);
if (_selected_airport_index != -1) {
- const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
+ const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_LAYOUT_NAME);
if (string != STR_UNDEFINED) {
SetDParam(0, string);
@@ -332,8 +332,9 @@ public:
switch (widget) {
case WID_AP_AIRPORT_LIST: {
int y = r.top;
- for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < AirportClass::GetCount(_selected_airport_class); i++) {
- const AirportSpec *as = AirportClass::Get(_selected_airport_class, i);
+ AirportClass *apclass = AirportClass::Get(_selected_airport_class);
+ for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < apclass->GetSpecCount(); i++) {
+ const AirportSpec *as = apclass->GetSpec(i);
if (!as->IsAvailable()) {
GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, PC_BLACK, FILLRECT_CHECKER);
}
@@ -352,7 +353,7 @@ public:
case WID_AP_EXTRA_TEXT:
if (_selected_airport_index != -1) {
- const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
+ const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_ADDITIONAL_TEXT);
if (string != STR_UNDEFINED) {
SetDParam(0, string);
@@ -374,7 +375,7 @@ public:
int bottom = panel_nwi->pos_y + panel_nwi->current_y;
if (_selected_airport_index != -1) {
- const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
+ const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
/* only show the station (airport) noise, if the noise option is activated */
@@ -412,7 +413,7 @@ public:
this->DisableWidget(WID_AP_LAYOUT_DECREASE);
this->DisableWidget(WID_AP_LAYOUT_INCREASE);
} else {
- const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
+ const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
int w = as->size_x;
int h = as->size_y;
Direction rotation = as->rotation[_selected_airport_layout];
@@ -439,7 +440,7 @@ public:
case WID_AP_AIRPORT_LIST: {
int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
if (num_clicked >= this->vscroll->GetCount()) break;
- const AirportSpec *as = AirportClass::Get(_selected_airport_class, num_clicked);
+ const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(num_clicked);
if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
break;
}
@@ -475,8 +476,9 @@ public:
void SelectFirstAvailableAirport(bool change_class)
{
/* First try to select an airport in the selected class. */
- for (uint i = 0; i < AirportClass::GetCount(_selected_airport_class); i++) {
- const AirportSpec *as = AirportClass::Get(_selected_airport_class, i);
+ AirportClass *sel_apclass = AirportClass::Get(_selected_airport_class);
+ for (uint i = 0; i < sel_apclass->GetSpecCount(); i++) {
+ const AirportSpec *as = sel_apclass->GetSpec(i);
if (as->IsAvailable()) {
this->SelectOtherAirport(i);
return;
@@ -486,8 +488,9 @@ public:
/* If that fails, select the first available airport
* from a random class. */
for (AirportClassID j = APC_BEGIN; j < APC_MAX; j++) {
- for (uint i = 0; i < AirportClass::GetCount(j); i++) {
- const AirportSpec *as = AirportClass::Get(j, i);
+ AirportClass *apclass = AirportClass::Get(j);
+ for (uint i = 0; i < apclass->GetSpecCount(); i++) {
+ const AirportSpec *as = apclass->GetSpec(i);
if (as->IsAvailable()) {
_selected_airport_class = j;
this->SelectOtherAirport(i);
@@ -504,7 +507,7 @@ public:
{
assert(widget == WID_AP_CLASS_DROPDOWN);
_selected_airport_class = (AirportClassID)index;
- this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
+ this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
this->SelectFirstAvailableAirport(false);
}
diff --git a/src/newgrf_class.h b/src/newgrf_class.h
index df7734819..94360f459 100644
--- a/src/newgrf_class.h
+++ b/src/newgrf_class.h
@@ -41,14 +41,17 @@ public:
void Insert(Tspec *spec);
+ /** Get the number of allocated specs within the class. */
+ uint GetSpecCount() const { return this->count; }
+
+ const Tspec *GetSpec(uint index) const;
+
static void Reset();
static Tid Allocate(uint32 global_id);
static void Assign(Tspec *spec);
static NewGRFClass *Get(Tid cls_id);
static uint GetCount();
- static uint GetCount(Tid cls_id);
- static const Tspec *Get(Tid cls_id, uint index);
static const Tspec *GetByGrf(uint32 grfid, byte local_id, int *index);
};
diff --git a/src/newgrf_class_func.h b/src/newgrf_class_func.h
index 339e7d7a5..03c82a8d6 100644
--- a/src/newgrf_class_func.h
+++ b/src/newgrf_class_func.h
@@ -117,31 +117,14 @@ DEFINE_NEWGRF_CLASS_METHOD(uint)::GetCount()
}
/**
- * Get the number of allocated specs within a particular class.
- * @param cls_id The class to get the size of.
- * @pre cls_id < GetCount()
- * @return The size of the class.
- */
-DEFINE_NEWGRF_CLASS_METHOD(uint)::GetCount(Tid cls_id)
-{
- assert(cls_id < Tmax);
- return classes[cls_id].count;
-}
-
-/**
- * Get a spec from a particular class at a given index.
- * @param cls_id The class to get the spec from.
+ * Get a spec from the class at a given index.
* @param index The index where to find the spec.
- * @pre index < GetCount(cls_id)
* @return The spec at given location.
*/
-DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::Get(Tid cls_id, uint index)
+DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetSpec(uint index) const
{
- assert(cls_id < Tmax);
- if (index < classes[cls_id].count) return classes[cls_id].spec[index];
-
/* If the custom spec isn't defined any more, then the GRF file probably was not loaded. */
- return NULL;
+ return index < this->GetSpecCount() ? this->spec[index] : NULL;
}
/**
@@ -180,6 +163,5 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetByGrf(uint32 grfid, byte local_id,
template void name::Assign(Tspec *spec); \
template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
template uint name::GetCount(); \
- template uint name::GetCount(Tid cls_id); \
- template const Tspec *name::Get(Tid cls_id, uint index); \
+ template const Tspec *name::GetSpec(uint index) const; \
template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index);
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index 90751cdcb..e48ad935d 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -805,13 +805,12 @@ void DeallocateSpecFromStation(BaseStation *st, byte specindex)
*/
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
{
- const StationSpec *statspec;
const DrawTileSprites *sprites = NULL;
const RailtypeInfo *rti = GetRailTypeInfo(railtype);
PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company);
uint tile = 2;
- statspec = StationClass::Get(sclass, station);
+ const StationSpec *statspec = StationClass::Get(sclass)->GetSpec(station);
if (statspec == NULL) return false;
if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) {
diff --git a/src/object_gui.cpp b/src/object_gui.cpp
index 5813517e9..e907629e4 100644
--- a/src/object_gui.cpp
+++ b/src/object_gui.cpp
@@ -51,7 +51,7 @@ public:
NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX);
matrix->SetScrollbar(this->GetScrollbar(WID_BO_SELECT_SCROLL));
- matrix->SetCount(ObjectClass::GetCount(_selected_object_class));
+ matrix->SetCount(ObjectClass::Get(_selected_object_class)->GetSpecCount());
}
virtual ~BuildObjectWindow()
@@ -62,7 +62,7 @@ public:
{
switch (widget) {
case WID_BO_OBJECT_SIZE: {
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
+ const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
int size = spec == NULL ? 0 : spec->size;
SetDParam(0, GB(size, HasBit(_selected_object_view, 0) ? 4 : 0, 4));
SetDParam(1, GB(size, HasBit(_selected_object_view, 0) ? 0 : 4, 4));
@@ -89,7 +89,7 @@ public:
case WID_BO_OBJECT_MATRIX: {
/* Get the right amount of buttons based on the current spec. */
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
+ const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
if (spec != NULL) {
if (spec->views >= 2) size->width += resize->width;
if (spec->views >= 4) size->height += resize->height;
@@ -129,7 +129,7 @@ public:
}
/* Get the right size for the single widget based on the current spec. */
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
+ const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
if (spec != NULL) {
if (spec->views >= 2) size->width = size->width / 2 - 1;
if (spec->views >= 4) size->height = size->height / 2 - 1;
@@ -165,7 +165,7 @@ public:
}
case WID_BO_OBJECT_SPRITE: {
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
+ const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
if (spec == NULL) break;
DrawPixelInfo tmp_dpi;
@@ -189,7 +189,7 @@ public:
if (_selected_object_index < 0) break;
int obj_index = GB(widget, 16, 16);
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, obj_index);
+ const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(obj_index);
if (spec == NULL) break;
if (!spec->IsAvailable()) {
@@ -214,7 +214,7 @@ public:
}
case WID_BO_INFO: {
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
+ const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
if (spec == NULL) break;
/* Get the extra message for the GUI */
@@ -253,7 +253,7 @@ public:
{
_selected_object_index = object_index;
if (_selected_object_index != -1) {
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
+ const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
_selected_object_view = min(_selected_object_view, spec->views - 1);
this->ReInit();
} else {
@@ -271,7 +271,7 @@ public:
if (_selected_object_index == -1) {
SetTileSelectSize(1, 1);
} else {
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
+ const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
int w = GB(spec->size, HasBit(_selected_object_view, 0) ? 4 : 0, 4);
int h = GB(spec->size, HasBit(_selected_object_view, 0) ? 0 : 4, 4);
SetTileSelectSize(w, h);
@@ -292,14 +292,14 @@ public:
if (num_clicked >= (int)ObjectClass::GetCount()) break;
_selected_object_class = (ObjectClassID)num_clicked;
- this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::GetCount(_selected_object_class));
+ this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetSpecCount());
this->SelectFirstAvailableObject(false);
break;
}
case WID_BO_SELECT_IMAGE: {
int num_clicked = GB(widget, 16, 16);
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, num_clicked);
+ const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(num_clicked);
if (spec->IsAvailable()) this->SelectOtherObject(num_clicked);
break;
}
@@ -323,8 +323,9 @@ public:
void SelectFirstAvailableObject(bool change_class)
{
/* First try to select an object in the selected class. */
- for (uint i = 0; i < ObjectClass::GetCount(_selected_object_class); i++) {
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, i);
+ ObjectClass *sel_objclass = ObjectClass::Get(_selected_object_class);
+ for (uint i = 0; i < sel_objclass->GetSpecCount(); i++) {
+ const ObjectSpec *spec = sel_objclass->GetSpec(i);
if (spec->IsAvailable()) {
this->SelectOtherObject(i);
return;
@@ -334,8 +335,9 @@ public:
/* If that fails, select the first available object
* from a random class. */
for (ObjectClassID j = OBJECT_CLASS_BEGIN; j < OBJECT_CLASS_MAX; j++) {
- for (uint i = 0; i < ObjectClass::GetCount(j); i++) {
- const ObjectSpec *spec = ObjectClass::Get(j, i);
+ ObjectClass *objclass = ObjectClass::Get(j);
+ for (uint i = 0; i < objclass->GetSpecCount(); i++) {
+ const ObjectSpec *spec = objclass->GetSpec(i);
if (spec->IsAvailable()) {
_selected_object_class = j;
this->SelectOtherObject(i);
@@ -418,5 +420,5 @@ void InitializeObjectGui()
*/
void PlaceProc_Object(TileIndex tile)
{
- DoCommandP(tile, ObjectClass::Get(_selected_object_class, _selected_object_index)->Index(), _selected_object_view, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
+ DoCommandP(tile, ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index)->Index(), _selected_object_view, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
}
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index bf8671000..38c7e95b7 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -549,7 +549,7 @@ struct BuildRailToolbarWindow : Window {
case WID_RAT_BUILD_WAYPOINT:
this->last_user_action = widget;
- _waypoint_count = StationClass::GetCount(STAT_CLASS_WAYP);
+ _waypoint_count = StationClass::Get(STAT_CLASS_WAYP)->GetSpecCount();
if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT) && _waypoint_count > 1) {
ShowBuildWaypointPicker(this);
}
@@ -945,7 +945,7 @@ public:
this->vscroll2 = NULL;
}
if (newstation) {
- _railstation.station_count = StationClass::GetCount(_railstation.station_class);
+ _railstation.station_count = StationClass::Get(_railstation.station_class)->GetSpecCount();
_railstation.station_type = min(_railstation.station_type, _railstation.station_count - 1);
int count = 0;
@@ -974,7 +974,7 @@ public:
virtual void OnPaint()
{
bool newstations = _railstation.newstations;
- const StationSpec *statspec = newstations ? StationClass::Get(_railstation.station_class, _railstation.station_type) : NULL;
+ const StationSpec *statspec = newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
if (_settings_client.gui.station_dragdrop) {
SetTileSelectSize(1, 1);
@@ -1048,8 +1048,9 @@ public:
StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
for (StationClassID statclass = STAT_CLASS_BEGIN; statclass < (StationClassID)StationClass::GetCount(); statclass++) {
if (statclass == STAT_CLASS_WAYP) continue;
- for (uint16 j = 0; j < StationClass::GetCount(statclass); j++) {
- const StationSpec *statspec = StationClass::Get(statclass, j);
+ StationClass *stclass = StationClass::Get(statclass);
+ for (uint16 j = 0; j < stclass->GetSpecCount(); j++) {
+ const StationSpec *statspec = stclass->GetSpec(j);
SetDParam(0, (statspec != NULL && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
d = maxdim(d, GetStringBoundingBox(str));
}
@@ -1118,7 +1119,7 @@ public:
byte type = GB(widget, 16, 16);
assert(type < _railstation.station_count);
/* Check station availability callback */
- const StationSpec *statspec = StationClass::Get(_railstation.station_class, type);
+ const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type);
if (!IsStationAvailable(statspec)) {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
}
@@ -1148,7 +1149,7 @@ public:
virtual void SetStringParameters(int widget) const
{
if (widget == WID_BRAS_SHOW_NEWST_TYPE) {
- const StationSpec *statspec = StationClass::Get(_railstation.station_class, _railstation.station_type);
+ const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type);
SetDParam(0, (statspec != NULL && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
}
}
@@ -1181,7 +1182,7 @@ public:
_settings_client.gui.station_dragdrop = false;
- const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class, _railstation.station_type) : NULL;
+ const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
if (statspec != NULL && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
/* The previously selected number of platforms in invalid */
for (uint i = 0; i < 7; i++) {
@@ -1216,7 +1217,7 @@ public:
_settings_client.gui.station_dragdrop = false;
- const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class, _railstation.station_type) : NULL;
+ const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
if (statspec != NULL && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
/* The previously selected number of tracks in invalid */
for (uint i = 0; i < 7; i++) {
@@ -1242,7 +1243,7 @@ public:
this->ToggleWidgetLoweredState(WID_BRAS_PLATFORM_DRAG_N_DROP);
/* get the first allowed length/number of platforms */
- const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class, _railstation.station_type) : NULL;
+ const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
if (statspec != NULL && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
for (uint i = 0; i < 7; i++) {
if (!HasBit(statspec->disallowed_lengths, i)) {
@@ -1288,10 +1289,11 @@ public:
if (y == 0) {
if (_railstation.station_class != (StationClassID)i) {
_railstation.station_class = (StationClassID)i;
- _railstation.station_count = StationClass::GetCount(_railstation.station_class);
+ StationClass *stclass = StationClass::Get(_railstation.station_class);
+ _railstation.station_count = stclass->GetSpecCount();
_railstation.station_type = min((int)_railstation.station_type, max(0, (int)_railstation.station_count - 1));
- this->CheckSelectedSize(StationClass::Get(_railstation.station_class, _railstation.station_type));
+ this->CheckSelectedSize(stclass->GetSpec(_railstation.station_type));
NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX);
matrix->SetCount(_railstation.station_count);
@@ -1312,7 +1314,7 @@ public:
if (y >= _railstation.station_count) return;
/* Check station availability callback */
- const StationSpec *statspec = StationClass::Get(_railstation.station_class, y);
+ const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(y);
if (!IsStationAvailable(statspec)) return;
_railstation.station_type = y;
@@ -1435,7 +1437,7 @@ static const WindowDesc _station_builder_desc(
/** Open station build window */
static void ShowStationBuilder(Window *parent)
{
- bool newstations = StationClass::GetCount() > 2 || StationClass::GetCount(STAT_CLASS_DFLT) != 1;
+ bool newstations = StationClass::GetCount() > 2 || StationClass::Get(STAT_CLASS_DFLT)->GetSpecCount() != 1;
new BuildRailStationWindow(&_station_builder_desc, parent, newstations);
}
@@ -1741,7 +1743,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
switch (GB(widget, 0, 16)) {
case WID_BRW_WAYPOINT: {
byte type = GB(widget, 16, 16);
- const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, type);
+ const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
DrawWaypointSprite(r.left + TILE_PIXELS, r.bottom - TILE_PIXELS, type, _cur_railtype);
if (!IsStationAvailable(statspec)) {
@@ -1759,7 +1761,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(_cur_waypoint_type);
/* Check station availability callback */
- const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, type);
+ const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
if (!IsStationAvailable(statspec)) return;
_cur_waypoint_type = type;
diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp
index 9d1f164b4..6ea72ea6f 100644
--- a/src/saveload/waypoint_sl.cpp
+++ b/src/saveload/waypoint_sl.cpp
@@ -76,15 +76,16 @@ void MoveWaypointsToBaseStations()
_m[wp->xy].m2 = (StationID)wp->index;
if (HasBit(_m[wp->xy].m3, 4)) {
- wp->spec = StationClass::Get(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1);
+ wp->spec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(_m[wp->xy].m4 + 1);
}
}
} else {
/* As of version 17, we recalculate the custom graphic ID of waypoints
* from the GRF ID / station index. */
for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
- for (uint i = 0; i < StationClass::GetCount(STAT_CLASS_WAYP); i++) {
- const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, i);
+ StationClass* stclass = StationClass::Get(STAT_CLASS_WAYP);
+ for (uint i = 0; i < stclass->GetSpecCount(); i++) {
+ const StationSpec *statspec = stclass->GetSpec(i);
if (statspec != NULL && statspec->grf_prop.grffile->grfid == wp->grfid && statspec->grf_prop.local_id == wp->localidx) {
wp->spec = statspec;
break;
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 08b1cad1d..254f0d346 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -744,7 +744,7 @@ static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag fl
int allowed_z = -1;
uint invalid_dirs = 5 << axis;
- const StationSpec *statspec = StationClass::Get(spec_class, spec_index);
+ const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
bool slope_cb = statspec != NULL && HasBit(statspec->callback_mask, CBM_STATION_SLOPE_CHECK);
TILE_AREA_LOOP(tile_cur, tile_area) {
@@ -1106,7 +1106,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
/* Check if the given station class is valid */
if ((uint)spec_class >= StationClass::GetCount() || spec_class == STAT_CLASS_WAYP) return CMD_ERROR;
- if (spec_index >= StationClass::GetCount(spec_class)) return CMD_ERROR;
+ if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
if (plat_len == 0 || numtracks == 0) return CMD_ERROR;
int w_org, h_org;
@@ -1175,7 +1175,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
}
/* Check if we can allocate a custom stationspec to this station */
- const StationSpec *statspec = StationClass::Get(spec_class, spec_index);
+ const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
int specindex = AllocateSpecToStation(statspec, st, (flags & DC_EXEC) != 0);
if (specindex == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS);
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index 74648ae14..35d7745c7 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -170,7 +170,7 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
/* Check if the given station class is valid */
if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR;
- if (spec_index >= StationClass::GetCount(spec_class)) return CMD_ERROR;
+ if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
/* The number of parts to build */
byte count = axis == AXIS_X ? height : width;
@@ -242,7 +242,7 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
wp->UpdateVirtCoord();
- const StationSpec *spec = StationClass::Get(spec_class, spec_index);
+ const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index);
byte *layout_ptr = AllocaM(byte, count);
if (spec == NULL) {
/* The layout must be 0 for the 'normal' waypoints by design. */