summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-07 22:07:07 +0000
committerrubidium <rubidium@openttd.org>2010-08-07 22:07:07 +0000
commitedbadde301d04264110b1b923ba80af367f6651c (patch)
treee9f8998e89b9811d9bc0febd58272339a63951c9
parentcb4ab6a23158163e848ab2b5887d1eb449b86a4c (diff)
downloadopenttd-edbadde301d04264110b1b923ba80af367f6651c.tar.xz
(svn r20406) -Codechange: make StationClass use the new generic class
-rw-r--r--src/ai/api/ai_rail.cpp2
-rw-r--r--src/newgrf.cpp8
-rw-r--r--src/newgrf_station.cpp170
-rw-r--r--src/newgrf_station.h24
-rw-r--r--src/rail_gui.cpp44
-rw-r--r--src/saveload/station_sl.cpp2
-rw-r--r--src/saveload/waypoint_sl.cpp6
-rw-r--r--src/station_cmd.cpp8
-rw-r--r--src/waypoint_cmd.cpp4
9 files changed, 60 insertions, 208 deletions
diff --git a/src/ai/api/ai_rail.cpp b/src/ai/api/ai_rail.cpp
index 592d6ddd4..e10cdb4df 100644
--- a/src/ai/api/ai_rail.cpp
+++ b/src/ai/api/ai_rail.cpp
@@ -171,7 +171,7 @@
uint32 p2 = (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
if (res != CALLBACK_FAILED) {
int index = 0;
- const StationSpec *spec = GetCustomStationSpecByGrf(file->grfid, res, &index);
+ const StationSpec *spec = StationClass::GetByGrf(file->grfid, res, &index);
if (spec == NULL) {
DEBUG(grf, 1, "%s returned an invalid station ID for 'AI construction/purchase selection (18)' callback", file->filename);
} else {
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 6009d91b6..dbae29585 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -1151,7 +1151,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte
/* Swap classid because we read it in BE meaning WAYP or DFLT */
uint32 classid = buf->ReadDWord();
- (*spec)->cls_id = AllocateStationClass(BSWAP32(classid));
+ (*spec)->cls_id = StationClass::Allocate(BSWAP32(classid));
break;
}
@@ -3893,7 +3893,7 @@ static void StationMapSpriteGroup(ByteReader *buf, uint8 idcount)
statspec->spritegroup[CT_DEFAULT] = _cur_grffile->spritegroups[groupid];
statspec->grf_prop.grffile = _cur_grffile;
statspec->grf_prop.local_id = stations[i];
- SetCustomStationSpec(statspec);
+ StationClass::Assign(statspec);
}
}
@@ -4276,7 +4276,7 @@ static void FeatureNewName(ByteReader *buf)
grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
} else {
StationClassID cls_id = _cur_grffile->stations[GB(id, 0, 8)]->cls_id;
- SetStationClassName(cls_id, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
+ StationClass::SetName(cls_id, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
}
break;
@@ -6764,7 +6764,7 @@ static void ResetNewGRFData()
ResetIndustries();
/* Reset station classes */
- ResetStationClasses();
+ StationClass::Reset();
ResetCustomStations();
/* Reset airport-related structures */
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index 921c1e128..c04c0665a 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -29,10 +29,28 @@
#include "tunnelbridge_map.h"
#include "newgrf.h"
#include "core/random_func.hpp"
+#include "newgrf_class_func.h"
#include "table/strings.h"
-static StationClass _station_classes[STAT_CLASS_MAX];
+template <typename Tspec, typename Tid, Tid Tmax>
+/* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults()
+{
+ /* Set up initial data */
+ classes[0].global_id = 'DFLT';
+ classes[0].name = STR_STATION_CLASS_DFLT;
+ classes[0].count = 1;
+ classes[0].spec = MallocT<StationSpec*>(1);
+ classes[0].spec[0] = NULL;
+
+ classes[1].global_id = 'WAYP';
+ classes[1].name = STR_STATION_CLASS_WAYP;
+ classes[1].count = 1;
+ classes[1].spec = MallocT<StationSpec*>(1);
+ classes[1].spec[0] = NULL;
+}
+
+INSTANTIATE_NEWGRF_CLASS_METHODS(StationClass, StationSpec, StationClassID, STAT_CLASS_MAX)
static const uint MAX_SPECLIST = 255;
@@ -76,154 +94,6 @@ struct ETileArea : TileArea {
};
-/**
- * Reset station classes to their default state.
- * This includes initialising the Default and Waypoint classes with an empty
- * entry, for standard stations and waypoints.
- */
-void ResetStationClasses()
-{
- for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
- _station_classes[i].id = 0;
- _station_classes[i].name = STR_EMPTY;
- _station_classes[i].stations = 0;
-
- free(_station_classes[i].spec);
- _station_classes[i].spec = NULL;
- }
-
- /* Set up initial data */
- _station_classes[0].id = 'DFLT';
- _station_classes[0].name = STR_STATION_CLASS_DFLT;
- _station_classes[0].stations = 1;
- _station_classes[0].spec = MallocT<StationSpec*>(1);
- _station_classes[0].spec[0] = NULL;
-
- _station_classes[1].id = 'WAYP';
- _station_classes[1].name = STR_STATION_CLASS_WAYP;
- _station_classes[1].stations = 1;
- _station_classes[1].spec = MallocT<StationSpec*>(1);
- _station_classes[1].spec[0] = NULL;
-}
-
-/**
- * Allocate a station class for the given class id.
- * @param cls A 32 bit value identifying the class.
- * @return Index into _station_classes of allocated class.
- */
-StationClassID AllocateStationClass(uint32 cls)
-{
- for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
- if (_station_classes[i].id == cls) {
- /* ClassID is already allocated, so reuse it. */
- return i;
- } else if (_station_classes[i].id == 0) {
- /* This class is empty, so allocate it to the ClassID. */
- _station_classes[i].id = cls;
- return i;
- }
- }
-
- grfmsg(2, "StationClassAllocate: already allocated %d classes, using default", STAT_CLASS_MAX);
- return STAT_CLASS_DFLT;
-}
-
-/** Set the name of a custom station class */
-void SetStationClassName(StationClassID sclass, StringID name)
-{
- assert(sclass < STAT_CLASS_MAX);
- _station_classes[sclass].name = name;
-}
-
-/** Retrieve the name of a custom station class */
-StringID GetStationClassName(StationClassID sclass)
-{
- assert(sclass < STAT_CLASS_MAX);
- return _station_classes[sclass].name;
-}
-
-/**
- * Get the number of station classes in use.
- * @return Number of station classes.
- */
-uint GetNumStationClasses()
-{
- uint i;
- for (i = 0; i < STAT_CLASS_MAX && _station_classes[i].id != 0; i++) {}
- return i;
-}
-
-/**
- * Return the number of stations for the given station class.
- * @param sclass Index of the station class.
- * @return Number of stations in the class.
- */
-uint GetNumCustomStations(StationClassID sclass)
-{
- assert(sclass < STAT_CLASS_MAX);
- return _station_classes[sclass].stations;
-}
-
-/**
- * Tie a station spec to its station class.
- * @param statspec The station spec.
- */
-void SetCustomStationSpec(StationSpec *statspec)
-{
- StationClass *station_class;
- int i;
-
- assert(statspec->cls_id < STAT_CLASS_MAX);
- station_class = &_station_classes[statspec->cls_id];
-
- i = station_class->stations++;
- station_class->spec = ReallocT(station_class->spec, station_class->stations);
-
- station_class->spec[i] = statspec;
-}
-
-/**
- * Retrieve a station spec from a class.
- * @param sclass Index of the station class.
- * @param station The station index with the class.
- * @return The station spec.
- */
-const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station)
-{
- assert(sclass < STAT_CLASS_MAX);
- if (station < _station_classes[sclass].stations) return _station_classes[sclass].spec[station];
-
- /* If the custom station isn't defined any more, then the GRF file
- * probably was not loaded. */
- return NULL;
-}
-
-/**
- * Retrieve a station spec by GRF location.
- * @param grfid GRF ID of station spec.
- * @param localidx Index within GRF file of station spec.
- * @param index Pointer to return the index of the station spec in its station class. If NULL then not used.
- * @return The station spec.
- */
-const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx, int *index)
-{
- uint j;
-
- for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
- for (j = 0; j < _station_classes[i].stations; j++) {
- const StationSpec *statspec = _station_classes[i].spec[j];
- if (statspec == NULL) continue;
- if (statspec->grf_prop.grffile->grfid == grfid && statspec->grf_prop.local_id == localidx) {
- if (index != NULL) *index = j;
- return statspec;
- }
- }
- }
-
- return NULL;
-}
-
-
/* Evaluate a tile's position within a station, and return the result a bit-stuffed format.
* if not centered: .TNLcCpP, if centered: .TNL..CP
* T = Tile layout number (#GetStationGfx), N = Number of platforms, L = Length of platforms
@@ -877,7 +747,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID
PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company);
uint tile = 2;
- statspec = GetCustomStationSpec(sclass, station);
+ statspec = StationClass::Get(sclass, station);
if (statspec == NULL) return false;
uint relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE);
diff --git a/src/newgrf_station.h b/src/newgrf_station.h
index 1c49dde18..523f72f0c 100644
--- a/src/newgrf_station.h
+++ b/src/newgrf_station.h
@@ -13,11 +13,11 @@
#define NEWGRF_STATION_H
#include "newgrf_callbacks.h"
+#include "newgrf_class.h"
#include "newgrf_commons.h"
#include "sprite.h"
#include "direction_type.h"
#include "cargo_type.h"
-#include "strings_type.h"
#include "station_type.h"
#include "rail_type.h"
@@ -108,29 +108,11 @@ struct StationSpec {
const struct SpriteGroup *spritegroup[NUM_CARGO + 3];
};
-/**
- * Struct containing information relating to station classes.
- */
-struct StationClass {
- uint32 id; ///< ID of this class, e.g. 'DFLT', 'WAYP', etc.
- StringID name; ///< Name of this class.
- uint stations; ///< Number of stations in this class.
- StationSpec **spec; ///< Array of station specifications.
-};
+/** Struct containing information relating to station classes. */
+typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
-void ResetStationClasses();
-StationClassID AllocateStationClass(uint32 cls);
-void SetStationClassName(StationClassID sclass, StringID name);
-StringID GetStationClassName(StationClassID sclass);
const StationSpec *GetStationSpec(TileIndex t);
-uint GetNumStationClasses();
-uint GetNumCustomStations(StationClassID sclass);
-
-void SetCustomStationSpec(StationSpec *statspec);
-const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station);
-const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx, int *index);
-
/* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index bdfd2fddd..cbd51c35e 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -54,7 +54,7 @@ struct RailStationGUISettings {
Axis orientation; ///< Currently selected rail station orientation
bool newstations; ///< Are custom station definitions available?
- StationClassIDByte station_class; ///< Currently selected custom station class (if newstations is \c true )
+ StationClassID station_class; ///< Currently selected custom station class (if newstations is \c true )
byte station_type; ///< Station type within the currently selected custom station class (if newstations is \c true )
byte station_count; ///< Number of custom stations (if newstations is \c true )
};
@@ -433,7 +433,7 @@ static void BuildRailClick_Depot(Window *w)
*/
static void BuildRailClick_Waypoint(Window *w)
{
- _waypoint_count = GetNumCustomStations(STAT_CLASS_WAYP);
+ _waypoint_count = StationClass::GetCount(STAT_CLASS_WAYP);
if (HandlePlacePushButton(w, RTW_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT, PlaceRail_Waypoint) &&
_waypoint_count > 1) {
ShowBuildWaypointPicker(w);
@@ -1029,9 +1029,9 @@ private:
{
DropDownList *list = new DropDownList();
- for (uint i = 0; i < GetNumStationClasses(); i++) {
+ for (uint i = 0; i < StationClass::GetCount(); i++) {
if (i == STAT_CLASS_WAYP) continue;
- list->push_back(new DropDownListStringItem(GetStationClassName((StationClassID)i), i, false));
+ list->push_back(new DropDownListStringItem(StationClass::GetName((StationClassID)i), i, false));
}
return list;
@@ -1058,7 +1058,7 @@ public:
_railstation.newstations = newstation;
if (newstation) {
- _railstation.station_count = GetNumCustomStations(_railstation.station_class);
+ _railstation.station_count = StationClass::GetCount(_railstation.station_class);
this->vscroll.SetCount(_railstation.station_count);
this->vscroll.SetCapacity(GB(this->GetWidget<NWidgetCore>(BRSW_NEWST_LIST)->widget_data, MAT_ROW_START, MAT_ROW_BITS));
@@ -1079,7 +1079,7 @@ public:
virtual void OnPaint()
{
bool newstations = _railstation.newstations;
- const StationSpec *statspec = newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
+ const StationSpec *statspec = newstations ? StationClass::Get(_railstation.station_class, _railstation.station_type) : NULL;
if (_settings_client.gui.station_dragdrop) {
SetTileSelectSize(1, 1);
@@ -1127,9 +1127,9 @@ public:
switch (widget) {
case BRSW_NEWST_DROPDOWN: {
Dimension d = {0, 0};
- for (uint i = 0; i < GetNumStationClasses(); i++) {
+ for (uint i = 0; i < StationClass::GetCount(); i++) {
if (i == STAT_CLASS_WAYP) continue;
- SetDParam(0, GetStationClassName((StationClassID)i));
+ SetDParam(0, StationClass::GetName((StationClassID)i));
d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
}
d.width += padding.width;
@@ -1139,10 +1139,10 @@ public:
}
case BRSW_NEWST_LIST: {
Dimension d = GetStringBoundingBox(STR_STATION_CLASS_DFLT);
- for (StationClassID statclass = STAT_CLASS_BEGIN; statclass < (StationClassID)GetNumStationClasses(); statclass++) {
+ for (StationClassID statclass = STAT_CLASS_BEGIN; statclass < (StationClassID)StationClass::GetCount(); statclass++) {
if (statclass == STAT_CLASS_WAYP) continue;
- for (uint16 j = 0; j < GetNumCustomStations(statclass); j++) {
- const StationSpec *statspec = GetCustomStationSpec(statclass, j);
+ for (uint16 j = 0; j < StationClass::GetCount(statclass); j++) {
+ const StationSpec *statspec = StationClass::Get(statclass, j);
if (statspec != NULL && statspec->name != 0) d = maxdim(d, GetStringBoundingBox(statspec->name));
}
}
@@ -1187,7 +1187,7 @@ public:
case BRSW_NEWST_LIST: {
uint y = r.top;
for (uint16 i = this->vscroll.GetPosition(); i < _railstation.station_count && this->vscroll.IsVisible(i); i++) {
- const StationSpec *statspec = GetCustomStationSpec(_railstation.station_class, i);
+ const StationSpec *statspec = StationClass::Get(_railstation.station_class, i);
StringID str = STR_STATION_CLASS_DFLT;
if (statspec != NULL && statspec->name != 0) {
@@ -1207,7 +1207,7 @@ public:
virtual void SetStringParameters(int widget) const
{
- if (widget == BRSW_NEWST_DROPDOWN) SetDParam(0, GetStationClassName(_railstation.station_class));
+ if (widget == BRSW_NEWST_DROPDOWN) SetDParam(0, StationClass::GetName(_railstation.station_class));
}
virtual void OnClick(Point pt, int widget, int click_count)
@@ -1238,7 +1238,7 @@ public:
_settings_client.gui.station_dragdrop = false;
- const StationSpec *statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
+ const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class, _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++) {
@@ -1273,7 +1273,7 @@ public:
_settings_client.gui.station_dragdrop = false;
- const StationSpec *statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
+ const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class, _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++) {
@@ -1299,7 +1299,7 @@ public:
this->ToggleWidgetLoweredState(BRSW_PLATFORM_DRAG_N_DROP);
/* get the first allowed length/number of platforms */
- const StationSpec *statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
+ const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class, _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)) {
@@ -1346,7 +1346,7 @@ public:
if (y >= _railstation.station_count) return;
/* Check station availability callback */
- const StationSpec *statspec = GetCustomStationSpec(_railstation.station_class, y);
+ const StationSpec *statspec = StationClass::Get(_railstation.station_class, y);
if (statspec != NULL && HasBit(statspec->callback_mask, CBM_STATION_AVAIL) &&
GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) return;
@@ -1367,9 +1367,9 @@ public:
if (_railstation.station_class != index) {
_railstation.station_class = (StationClassID)index;
_railstation.station_type = 0;
- _railstation.station_count = GetNumCustomStations(_railstation.station_class);
+ _railstation.station_count = StationClass::GetCount(_railstation.station_class);
- this->CheckSelectedSize(GetCustomStationSpec(_railstation.station_class, _railstation.station_type));
+ this->CheckSelectedSize(StationClass::Get(_railstation.station_class, _railstation.station_type));
this->vscroll.SetCount(_railstation.station_count);
this->vscroll.SetPosition(_railstation.station_type);
@@ -1466,7 +1466,7 @@ static const WindowDesc _station_builder_desc(
/** Open station build window */
static void ShowStationBuilder(Window *parent)
{
- bool newstations = GetNumStationClasses() > 2 || GetNumCustomStations(STAT_CLASS_DFLT) != 1;
+ bool newstations = StationClass::GetCount() > 2 || StationClass::GetCount(STAT_CLASS_DFLT) != 1;
new BuildRailStationWindow(&_station_builder_desc, parent, newstations);
}
@@ -1788,7 +1788,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
for (uint i = 0; i < this->hscroll.GetCapacity(); i++) {
if (this->hscroll.GetPosition() + i < this->hscroll.GetCount()) {
- const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, this->hscroll.GetPosition() + i);
+ const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, this->hscroll.GetPosition() + i);
NWidgetBase *nw = this->GetWidget<NWidgetBase>(BRWW_WAYPOINT_1 + i);
int bottom = nw->pos_y + nw->current_y;
@@ -1814,7 +1814,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
byte type = widget - BRWW_WAYPOINT_1 + this->hscroll.GetPosition();
/* Check station availability callback */
- const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, type);
+ const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, type);
if (statspec != NULL &&
HasBit(statspec->callback_mask, CBM_STATION_AVAIL) &&
GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) return;
diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp
index e2488e779..72d7c7ecf 100644
--- a/src/saveload/station_sl.cpp
+++ b/src/saveload/station_sl.cpp
@@ -95,7 +95,7 @@ void AfterLoadStations()
for (uint i = 0; i < st->num_specs; i++) {
if (st->speclist[i].grfid == 0) continue;
- st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx, NULL);
+ st->speclist[i].spec = StationClass::GetByGrf(st->speclist[i].grfid, st->speclist[i].localidx, NULL);
}
if (Station::IsExpected(st)) {
diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp
index 3cdafd990..501aa86c5 100644
--- a/src/saveload/waypoint_sl.cpp
+++ b/src/saveload/waypoint_sl.cpp
@@ -76,15 +76,15 @@ void MoveWaypointsToBaseStations()
_m[wp->xy].m2 = (StationID)wp->index;
if (HasBit(_m[wp->xy].m3, 4)) {
- wp->spec = GetCustomStationSpec(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1);
+ wp->spec = StationClass::Get(STAT_CLASS_WAYP, _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 < GetNumCustomStations(STAT_CLASS_WAYP); i++) {
- const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, i);
+ for (uint i = 0; i < StationClass::GetCount(STAT_CLASS_WAYP); i++) {
+ const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, 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 25e456062..67db95643 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1134,8 +1134,8 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
if (!ValParamRailtype(rt)) return CMD_ERROR;
/* Check if the given station class is valid */
- if ((uint)spec_class >= GetNumStationClasses() || spec_class == STAT_CLASS_WAYP) return CMD_ERROR;
- if (spec_index >= GetNumCustomStations(spec_class)) return CMD_ERROR;
+ 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 (plat_len == 0 || numtracks == 0) return CMD_ERROR;
int w_org, h_org;
@@ -1207,7 +1207,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
}
/* Check if we can allocate a custom stationspec to this station */
- const StationSpec *statspec = GetCustomStationSpec(spec_class, spec_index);
+ const StationSpec *statspec = StationClass::Get(spec_class, spec_index);
int specindex = AllocateSpecToStation(statspec, st, (flags & DC_EXEC) != 0);
if (specindex == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS);
@@ -2801,7 +2801,7 @@ static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
const StationSpec *spec = GetStationSpec(tile);
if (spec != NULL) {
- td->station_class = GetStationClassName(spec->cls_id);
+ td->station_class = StationClass::GetName(spec->cls_id);
td->station_name = spec->name;
if (spec->grf_prop.grffile != NULL) {
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index 2d832c924..4d2520c25 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -169,7 +169,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 >= GetNumCustomStations(spec_class)) return CMD_ERROR;
+ if (spec_index >= StationClass::GetCount(spec_class)) return CMD_ERROR;
/* The number of parts to build */
byte count = axis == AXIS_X ? height : width;
@@ -241,7 +241,7 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
wp->UpdateVirtCoord();
- const StationSpec *spec = GetCustomStationSpec(spec_class, spec_index);
+ const StationSpec *spec = StationClass::Get(spec_class, spec_index);
byte *layout_ptr = AllocaM(byte, count);
if (spec == NULL) {
/* The layout must be 0 for the 'normal' waypoints by design. */