(svn r16897) -Codechange: use the 'generic' station spec to station allocation for waypoints too

This commit is contained in:
rubidium 2009-07-21 11:20:34 +00:00
parent 6670fae515
commit 4d3072ec67
6 changed files with 11 additions and 33 deletions

View File

@ -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;

View File

@ -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. */

View File

@ -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;

View File

@ -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();

View File

@ -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

View File

@ -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);