diff options
author | rubidium <rubidium@openttd.org> | 2009-07-21 11:20:34 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-07-21 11:20:34 +0000 |
commit | ed5ced71c852387aec030acc19ad096e55bcbd82 (patch) | |
tree | 087c8bed10e5e62eeed8052eaf781f1ec60c544c | |
parent | 43eda3dfbf45a8f5060aaca3da9b8cad59a1aad8 (diff) | |
download | openttd-ed5ced71c852387aec030acc19ad096e55bcbd82.tar.xz |
(svn r16897) -Codechange: use the 'generic' station spec to station allocation for waypoints too
-rw-r--r-- | src/newgrf_station.cpp | 2 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 2 | ||||
-rw-r--r-- | src/saveload/waypoint_sl.cpp | 12 | ||||
-rw-r--r-- | src/waypoint.cpp | 22 | ||||
-rw-r--r-- | src/waypoint.h | 2 | ||||
-rw-r--r-- | src/waypoint_cmd.cpp | 4 |
6 files changed, 11 insertions, 33 deletions
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index f34012359..54c68d13d 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -954,7 +954,7 @@ const StationSpec *GetStationSpec(TileIndex t) 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 index 5831479cd..35337866d 100644 --- 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 index 75c687c80..e759dc7f8 100644 --- 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<StationSpecList>(1); - *wp->speclist = _waypoint_spec; + wp->num_specs = 2; + wp->speclist = CallocT<StationSpecList>(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 index 70ec5c3f5..f669570ba 100644 --- 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<StationSpecList>(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 index f6d5a317d..3dfcdac1e 100644 --- a/src/waypoint.h +++ b/src/waypoint.h @@ -34,8 +34,6 @@ struct Waypoint : WaypointPool::PoolItem<&_waypoint_pool>, SpecializedStation<Wa /* 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 index 2f10c7dea..882ba6097 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -190,7 +190,7 @@ CommandCost CmdBuildTrainWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1 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(TileIndex tile, DoCommandFlag flags, bool justre } 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); |