summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-07-17 20:21:24 +0000
committerrubidium <rubidium@openttd.org>2009-07-17 20:21:24 +0000
commit06ea681b5fa361b34000351bcd248ee46c2a939e (patch)
treebcda240773c51bf9617fea6bf60e11631c74e150
parent84df3ba2b40054b751fd9d39c3a9b3a7589422b8 (diff)
downloadopenttd-06ea681b5fa361b34000351bcd248ee46c2a939e.tar.xz
(svn r16860) -Codechange: introduce a helper to assign a station spec to Waypoints
-rw-r--r--src/saveload/afterload.cpp15
-rw-r--r--src/waypoint.cpp19
-rw-r--r--src/waypoint.h2
-rw-r--r--src/waypoint_cmd.cpp13
4 files changed, 23 insertions, 26 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 7879af4e7..798503f2c 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -997,21 +997,8 @@ bool AfterLoadGame()
FOR_ALL_WAYPOINTS(wp) {
if (wp->delete_ctr == 0) {
- const StationSpec *statspec = NULL;
-
if (HasBit(_m[wp->xy].m3, 4)) {
- statspec = GetCustomStationSpec(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1);
- }
-
- if (statspec != NULL) {
- wp->spec.spec = statspec;
- wp->spec.grfid = statspec->grffile->grfid;
- wp->spec.localidx = statspec->localidx;
- } else {
- /* No custom graphics set, so set to default. */
- wp->spec.spec = NULL;
- wp->spec.grfid = 0;
- wp->spec.localidx = 0;
+ wp->AssignStationSpec(_m[wp->xy].m4 + 1);
}
/* Move ground type bits from m2 to m4. */
diff --git a/src/waypoint.cpp b/src/waypoint.cpp
index e245627e5..015ca8941 100644
--- a/src/waypoint.cpp
+++ b/src/waypoint.cpp
@@ -91,6 +91,25 @@ Waypoint::~Waypoint()
this->sign.MarkDirty();
}
+/**
+ * Assign a station spec to this waypoint.
+ * @param index the index of the spec from the waypoint specs
+ */
+void Waypoint::AssignStationSpec(uint index)
+{
+ const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, index);
+
+ if (statspec != NULL) {
+ this->spec.spec = statspec;
+ this->spec.grfid = statspec->grffile->grfid;
+ this->spec.localidx = statspec->localidx;
+ } else {
+ this->spec.spec = NULL;
+ this->spec.grfid = 0;
+ this->spec.localidx = 0;
+ }
+}
+
void InitializeWaypoints()
{
_waypoint_pool.CleanPool();
diff --git a/src/waypoint.h b/src/waypoint.h
index 18fc2a33c..6e3e24105 100644
--- a/src/waypoint.h
+++ b/src/waypoint.h
@@ -36,6 +36,8 @@ struct Waypoint : WaypointPool::PoolItem<&_waypoint_pool> {
~Waypoint();
void UpdateVirtCoord();
+
+ void AssignStationSpec(uint index);
};
#define FOR_ALL_WAYPOINTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Waypoint, waypoint_index, var, start)
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index cddd4a7ac..1e8094162 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -190,18 +190,7 @@ CommandCost CmdBuildTrainWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1
SetDepotWaypointReservation(tile, reserved);
MarkTileDirtyByTile(tile);
- const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, p1);
-
- if (statspec != NULL) {
- wp->spec.spec = statspec;
- wp->spec.grfid = statspec->grffile->grfid;
- wp->spec.localidx = statspec->localidx;
- } else {
- /* Specified custom graphics do not exist, so use default. */
- wp->spec.spec = NULL;
- wp->spec.grfid = 0;
- wp->spec.localidx = 0;
- }
+ wp->AssignStationSpec(p1);
wp->delete_ctr = 0;
wp->build_date = _date;