From c9cab7ba1967a42b90b44bca865db33c66a20c72 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 17 Jul 2009 20:40:29 +0000 Subject: [PATCH] (svn r16862) -Codechange: make waypoints use the same system of station station spec lists. --- src/rail_cmd.cpp | 6 ++++-- src/saveload/waypoint_sl.cpp | 28 ++++++++++++++++++++-------- src/waypoint.cpp | 15 +++++++++------ src/waypoint.h | 3 ++- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 42e3a6d786..a67b553b1d 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1938,9 +1938,11 @@ static void DrawTile_Track(TileInfo *ti) } } else { /* look for customization */ - const StationSpec *statspec = GetWaypointByTile(ti->tile)->spec.spec; + const Waypoint *wp = GetWaypointByTile(ti->tile); + + if (wp->num_specs != 0) { + const StationSpec *statspec = wp->speclist->spec; - if (statspec != NULL) { /* emulate station tile - open with building */ const Station *st = ComposeWaypointStation(ti->tile); uint gfx = 2; diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp index f51a094850..75c687c803 100644 --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -21,14 +21,12 @@ void AfterLoadWaypoints() Waypoint *wp; FOR_ALL_WAYPOINTS(wp) { - uint i; + if (wp->num_specs == 0) continue; - if (wp->spec.grfid == 0) continue; - - for (i = 0; i < GetNumCustomStations(STAT_CLASS_WAYP); i++) { + for (uint i = 0; i < GetNumCustomStations(STAT_CLASS_WAYP); i++) { const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, i); - if (statspec != NULL && statspec->grffile->grfid == wp->spec.grfid && statspec->localidx == wp->spec.localidx) { - wp->spec.spec = statspec; + if (statspec != NULL && statspec->grffile->grfid == wp->speclist->grfid && statspec->localidx == wp->speclist->localidx) { + wp->speclist->spec = statspec; break; } } @@ -37,6 +35,7 @@ void AfterLoadWaypoints() static uint16 _waypoint_town_index; static StringID _waypoint_string_id; +static StationSpecList _waypoint_spec; static const SaveLoad _waypoint_desc[] = { SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), @@ -51,8 +50,8 @@ static const SaveLoad _waypoint_desc[] = { SLE_CONDVAR(Waypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30), SLE_CONDVAR(Waypoint, build_date, SLE_INT32, 31, SL_MAX_VERSION), - SLE_CONDVAR(Waypoint, spec.localidx, SLE_UINT8, 3, SL_MAX_VERSION), - SLE_CONDVAR(Waypoint, spec.grfid, SLE_UINT32, 17, SL_MAX_VERSION), + SLEG_CONDVAR(_waypoint_spec.localidx, SLE_UINT8, 3, SL_MAX_VERSION), + SLEG_CONDVAR(_waypoint_spec.grfid, SLE_UINT32, 17, SL_MAX_VERSION), SLE_CONDVAR(Waypoint, owner, SLE_UINT8, 101, SL_MAX_VERSION), SLE_END() @@ -63,6 +62,12 @@ static void Save_WAYP() Waypoint *wp; FOR_ALL_WAYPOINTS(wp) { + if (wp->num_specs == 0) { + _waypoint_spec.grfid = 0; + } else { + _waypoint_spec = *wp->speclist; + } + SlSetArrayIndex(wp->index); SlObject(wp, _waypoint_desc); } @@ -75,10 +80,17 @@ static void Load_WAYP() while ((index = SlIterateArray()) != -1) { _waypoint_string_id = 0; _waypoint_town_index = 0; + _waypoint_spec.grfid = 0; Waypoint *wp = new (index) Waypoint(); SlObject(wp, _waypoint_desc); + if (_waypoint_spec.grfid != 0) { + wp->num_specs = 1; + wp->speclist = MallocT(1); + *wp->speclist = _waypoint_spec; + } + if (CheckSavegameVersion(84)) wp->name = (char *)(size_t)_waypoint_string_id; if (CheckSavegameVersion(122)) wp->town = (Town *)(size_t)_waypoint_town_index; } diff --git a/src/waypoint.cpp b/src/waypoint.cpp index 015ca8941e..791822eda1 100644 --- a/src/waypoint.cpp +++ b/src/waypoint.cpp @@ -97,16 +97,19 @@ Waypoint::~Waypoint() */ void Waypoint::AssignStationSpec(uint index) { + free(this->speclist); + 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; + this->speclist = MallocT(1); + this->speclist->spec = statspec; + this->speclist->grfid = statspec->grffile->grfid; + this->speclist->localidx = statspec->localidx; + this->num_specs = 1; } else { - this->spec.spec = NULL; - this->spec.grfid = 0; - this->spec.localidx = 0; + this->speclist = NULL; + this->num_specs = 0; } } diff --git a/src/waypoint.h b/src/waypoint.h index 6e3e241053..7e540ecc27 100644 --- a/src/waypoint.h +++ b/src/waypoint.h @@ -28,7 +28,8 @@ struct Waypoint : WaypointPool::PoolItem<&_waypoint_pool> { Date build_date; ///< Date of construction OwnerByte owner; ///< Whom this waypoint belongs to - StationSpecList spec; ///< NewGRF specification of the station + uint8 num_specs; ///< NOSAVE: Number of specs in the speclist + StationSpecList *speclist; ///< List of station specs of this station byte delete_ctr; ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.