(svn r16862) -Codechange: make waypoints use the same system of station station spec lists.

This commit is contained in:
rubidium 2009-07-17 20:40:29 +00:00
parent 72d6c3a9ad
commit c9cab7ba19
4 changed files with 35 additions and 17 deletions

View File

@ -1938,9 +1938,11 @@ static void DrawTile_Track(TileInfo *ti)
} }
} else { } else {
/* look for customization */ /* 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 */ /* emulate station tile - open with building */
const Station *st = ComposeWaypointStation(ti->tile); const Station *st = ComposeWaypointStation(ti->tile);
uint gfx = 2; uint gfx = 2;

View File

@ -21,14 +21,12 @@ void AfterLoadWaypoints()
Waypoint *wp; Waypoint *wp;
FOR_ALL_WAYPOINTS(wp) { FOR_ALL_WAYPOINTS(wp) {
uint i; if (wp->num_specs == 0) continue;
if (wp->spec.grfid == 0) continue; for (uint i = 0; i < GetNumCustomStations(STAT_CLASS_WAYP); i++) {
for (i = 0; i < GetNumCustomStations(STAT_CLASS_WAYP); i++) {
const StationSpec *statspec = GetCustomStationSpec(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) { if (statspec != NULL && statspec->grffile->grfid == wp->speclist->grfid && statspec->localidx == wp->speclist->localidx) {
wp->spec.spec = statspec; wp->speclist->spec = statspec;
break; break;
} }
} }
@ -37,6 +35,7 @@ void AfterLoadWaypoints()
static uint16 _waypoint_town_index; static uint16 _waypoint_town_index;
static StringID _waypoint_string_id; static StringID _waypoint_string_id;
static StationSpecList _waypoint_spec;
static const SaveLoad _waypoint_desc[] = { static const SaveLoad _waypoint_desc[] = {
SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), 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_FILE_U16 | SLE_VAR_I32, 3, 30),
SLE_CONDVAR(Waypoint, build_date, SLE_INT32, 31, SL_MAX_VERSION), SLE_CONDVAR(Waypoint, build_date, SLE_INT32, 31, SL_MAX_VERSION),
SLE_CONDVAR(Waypoint, spec.localidx, SLE_UINT8, 3, SL_MAX_VERSION), SLEG_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.grfid, SLE_UINT32, 17, SL_MAX_VERSION),
SLE_CONDVAR(Waypoint, owner, SLE_UINT8, 101, SL_MAX_VERSION), SLE_CONDVAR(Waypoint, owner, SLE_UINT8, 101, SL_MAX_VERSION),
SLE_END() SLE_END()
@ -63,6 +62,12 @@ static void Save_WAYP()
Waypoint *wp; Waypoint *wp;
FOR_ALL_WAYPOINTS(wp) { FOR_ALL_WAYPOINTS(wp) {
if (wp->num_specs == 0) {
_waypoint_spec.grfid = 0;
} else {
_waypoint_spec = *wp->speclist;
}
SlSetArrayIndex(wp->index); SlSetArrayIndex(wp->index);
SlObject(wp, _waypoint_desc); SlObject(wp, _waypoint_desc);
} }
@ -75,10 +80,17 @@ static void Load_WAYP()
while ((index = SlIterateArray()) != -1) { while ((index = SlIterateArray()) != -1) {
_waypoint_string_id = 0; _waypoint_string_id = 0;
_waypoint_town_index = 0; _waypoint_town_index = 0;
_waypoint_spec.grfid = 0;
Waypoint *wp = new (index) Waypoint(); Waypoint *wp = new (index) Waypoint();
SlObject(wp, _waypoint_desc); SlObject(wp, _waypoint_desc);
if (_waypoint_spec.grfid != 0) {
wp->num_specs = 1;
wp->speclist = MallocT<StationSpecList>(1);
*wp->speclist = _waypoint_spec;
}
if (CheckSavegameVersion(84)) wp->name = (char *)(size_t)_waypoint_string_id; if (CheckSavegameVersion(84)) wp->name = (char *)(size_t)_waypoint_string_id;
if (CheckSavegameVersion(122)) wp->town = (Town *)(size_t)_waypoint_town_index; if (CheckSavegameVersion(122)) wp->town = (Town *)(size_t)_waypoint_town_index;
} }

View File

@ -97,16 +97,19 @@ Waypoint::~Waypoint()
*/ */
void Waypoint::AssignStationSpec(uint index) void Waypoint::AssignStationSpec(uint index)
{ {
free(this->speclist);
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, index); const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, index);
if (statspec != NULL) { if (statspec != NULL) {
this->spec.spec = statspec; this->speclist = MallocT<StationSpecList>(1);
this->spec.grfid = statspec->grffile->grfid; this->speclist->spec = statspec;
this->spec.localidx = statspec->localidx; this->speclist->grfid = statspec->grffile->grfid;
this->speclist->localidx = statspec->localidx;
this->num_specs = 1;
} else { } else {
this->spec.spec = NULL; this->speclist = NULL;
this->spec.grfid = 0; this->num_specs = 0;
this->spec.localidx = 0;
} }
} }

View File

@ -28,7 +28,8 @@ struct Waypoint : WaypointPool::PoolItem<&_waypoint_pool> {
Date build_date; ///< Date of construction Date build_date; ///< Date of construction
OwnerByte owner; ///< Whom this waypoint belongs to 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. byte delete_ctr; ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.