diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -954,7 +954,7 @@ const StationSpec *GetStationSpec(TileIn if (IsRailWaypointTile(t)) { const BaseStation *st = BaseStation::GetByTile(t); - return st->num_specs != 0 ? st->speclist[0].spec : NULL; + return st->num_specs != 0 ? st->speclist[1].spec : NULL; } return NULL; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -997,7 +997,7 @@ bool AfterLoadGame() FOR_ALL_WAYPOINTS(wp) { if (wp->delete_ctr == 0) { if (HasBit(_m[wp->xy].m3, 4)) { - wp->AssignStationSpec(_m[wp->xy].m4 + 1); + AllocateSpecToStation(GetCustomStationSpec(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1), wp, true); } /* Move ground type bits from m2 to m4. */ diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -25,8 +25,8 @@ void AfterLoadWaypoints() 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->speclist->grfid && statspec->localidx == wp->speclist->localidx) { - wp->speclist->spec = statspec; + if (statspec != NULL && statspec->grffile->grfid == wp->speclist[1].grfid && statspec->localidx == wp->speclist[1].localidx) { + wp->speclist[1].spec = statspec; break; } } @@ -65,7 +65,7 @@ static void Save_WAYP() if (wp->num_specs == 0) { _waypoint_spec.grfid = 0; } else { - _waypoint_spec = *wp->speclist; + _waypoint_spec = wp->speclist[1]; } SlSetArrayIndex(wp->index); @@ -86,9 +86,9 @@ static void Load_WAYP() SlObject(wp, _waypoint_desc); if (_waypoint_spec.grfid != 0) { - wp->num_specs = 1; - wp->speclist = MallocT(1); - *wp->speclist = _waypoint_spec; + wp->num_specs = 2; + wp->speclist = CallocT(2); + wp->speclist[1] = _waypoint_spec; } if (CheckSavegameVersion(84)) wp->name = (char *)(size_t)_waypoint_string_id; diff --git a/src/waypoint.cpp b/src/waypoint.cpp --- a/src/waypoint.cpp +++ b/src/waypoint.cpp @@ -68,28 +68,6 @@ 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) -{ - free(this->speclist); - - const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, index); - - if (statspec != NULL) { - 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->speclist = NULL; - this->num_specs = 0; - } -} - void InitializeWaypoints() { _waypoint_pool.CleanPool(); diff --git a/src/waypoint.h b/src/waypoint.h --- a/src/waypoint.h +++ b/src/waypoint.h @@ -34,8 +34,6 @@ struct Waypoint : WaypointPool::PoolItem /* virtual */ void GetTileArea(TileArea *ta, StationType type) const; - void AssignStationSpec(uint index); - /** * Fetch a waypoint by tile * @param tile Tile of waypoint diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -190,7 +190,7 @@ CommandCost CmdBuildTrainWaypoint(TileIn SetDepotWaypointReservation(tile, reserved); MarkTileDirtyByTile(tile); - wp->AssignStationSpec(p1); + AllocateSpecToStation(GetCustomStationSpec(STAT_CLASS_WAYP, p1), wp, true); wp->delete_ctr = 0; wp->build_date = _date; @@ -246,6 +246,8 @@ CommandCost RemoveTrainWaypoint(TileInde } YapfNotifyTrackLayoutChange(tile, track); if (v != NULL) TryPathReserve(v, true); + + DeallocateSpecFromStation(wp, wp->num_specs > 0 ? 1 : 0); } return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);