Changeset - r12453:ad72006529c2
[Not reviewed]
master
0 6 0
rubidium - 15 years ago 2009-07-21 11:20:34
rubidium@openttd.org
(svn r16897) -Codechange: use the 'generic' station spec to station allocation for waypoints too
6 files changed with 11 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/newgrf_station.cpp
Show inline comments
 
@@ -945,25 +945,25 @@ bool DrawStationTile(int x, int y, RailT
 
const StationSpec *GetStationSpec(TileIndex t)
 
{
 
	if (IsRailwayStationTile(t)) {
 
		if (!IsCustomStationSpecIndex(t)) return NULL;
 

	
 
		const BaseStation *st = BaseStation::GetByTile(t);
 
		uint specindex = GetCustomStationSpecIndex(t);
 
		return specindex < st->num_specs ? st->speclist[specindex].spec : NULL;
 
	}
 

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

	
 

	
 
/* Check if a rail station tile is traversable.
 
 * XXX This could be cached (during build) in the map array to save on all the dereferencing */
 
bool IsStationTileBlocked(TileIndex tile)
 
{
 
	const StationSpec *statspec = GetStationSpec(tile);
 

	
src/saveload/afterload.cpp
Show inline comments
 
@@ -988,25 +988,25 @@ bool AfterLoadGame()
 
	}
 

	
 
	/* In version 17, ground type is moved from m2 to m4 for depots and
 
	 * waypoints to make way for storing the index in m2. The custom graphics
 
	 * id which was stored in m4 is now saved as a grf/id reference in the
 
	 * waypoint struct. */
 
	if (CheckSavegameVersion(17)) {
 
		Waypoint *wp;
 

	
 
		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. */
 
				_m[wp->xy].m4 = GB(_m[wp->xy].m2, 0, 4);
 
				/* Store waypoint index in the tile. */
 
				_m[wp->xy].m2 = wp->index;
 
			}
 
		}
 
	} else {
 
		/* As of version 17, we recalculate the custom graphic ID of waypoints
 
		 * from the GRF ID / station index. */
 
		AfterLoadWaypoints();
src/saveload/waypoint_sl.cpp
Show inline comments
 
@@ -16,26 +16,26 @@
 
 * Update waypoint graphics id against saved GRFID/localidx.
 
 * This is to ensure the chosen graphics are correct if GRF files are changed.
 
 */
 
void AfterLoadWaypoints()
 
{
 
	Waypoint *wp;
 

	
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->num_specs == 0) continue;
 

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

	
 
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),
 
@@ -56,48 +56,48 @@ static const SaveLoad _waypoint_desc[] =
 

	
 
	SLE_END()
 
};
 

	
 
static void Save_WAYP()
 
{
 
	Waypoint *wp;
 

	
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->num_specs == 0) {
 
			_waypoint_spec.grfid = 0;
 
		} else {
 
			_waypoint_spec = *wp->speclist;
 
			_waypoint_spec = wp->speclist[1];
 
		}
 

	
 
		SlSetArrayIndex(wp->index);
 
		SlObject(wp, _waypoint_desc);
 
	}
 
}
 

	
 
static void Load_WAYP()
 
{
 
	int index;
 

	
 
	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<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;
 
		if (CheckSavegameVersion(122)) wp->town = (Town *)(size_t)_waypoint_town_index;
 
	}
 
}
 

	
 
static void Ptrs_WAYP()
 
{
 
	Waypoint *wp;
 

	
 
	FOR_ALL_WAYPOINTS(wp) {
src/waypoint.cpp
Show inline comments
 
@@ -59,38 +59,16 @@ void Waypoint::GetTileArea(TileArea *ta,
 
	ta->h    = 1;
 
}
 

	
 
Waypoint::~Waypoint()
 
{
 
	if (CleaningPool()) return;
 
	DeleteWindowById(WC_WAYPOINT_VIEW, this->index);
 
	RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
 

	
 
	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();
 
}
src/waypoint.h
Show inline comments
 
@@ -25,26 +25,24 @@ struct Waypoint : WaypointPool::PoolItem
 

	
 
	void UpdateVirtCoord();
 

	
 
	/* virtual */ FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
 
	{
 
		return this->delete_ctr == 0 && this->xy == tile;
 
	}
 

	
 
	/* virtual */ uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const;
 

	
 
	/* virtual */ void GetTileArea(TileArea *ta, StationType type) const;
 

	
 
	void AssignStationSpec(uint index);
 

	
 
	/**
 
	 * Fetch a waypoint by tile
 
	 * @param tile Tile of waypoint
 
	 * @return Waypoint
 
	 */
 
	static FORCEINLINE Waypoint *GetByTile(TileIndex tile)
 
	{
 
		return Waypoint::Get(GetWaypointIndex(tile));
 
	}
 
};
 

	
 
#define FOR_ALL_WAYPOINTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Waypoint, waypoint_index, var, start)
src/waypoint_cmd.cpp
Show inline comments
 
@@ -181,25 +181,25 @@ CommandCost CmdBuildTrainWaypoint(TileIn
 
			}
 

	
 
			wp->xy = tile;
 
			InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
 
		}
 
		wp->owner = owner;
 

	
 
		bool reserved = HasBit(GetTrackReservation(tile), AxisToTrack(axis));
 
		MakeRailWaypoint(tile, owner, axis, GetRailType(tile), wp->index);
 
		SetDepotWaypointReservation(tile, reserved);
 
		MarkTileDirtyByTile(tile);
 

	
 
		wp->AssignStationSpec(p1);
 
		AllocateSpecToStation(GetCustomStationSpec(STAT_CLASS_WAYP, p1), wp, true);
 

	
 
		wp->delete_ctr = 0;
 
		wp->build_date = _date;
 

	
 
		if (wp->town == NULL) MakeDefaultWaypointName(wp);
 

	
 
		wp->UpdateVirtCoord();
 
		YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis));
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_train_depot);
 
}
 
@@ -237,24 +237,26 @@ CommandCost RemoveTrainWaypoint(TileInde
 
			if (reserved) SetTrackReservation(tile, tracks);
 
			MarkTileDirtyByTile(tile);
 
		} else {
 
			if (GetDepotWaypointReservation(tile)) {
 
				v = GetTrainForReservation(tile, track);
 
				if (v != NULL) FreeTrainTrackReservation(v);
 
			}
 
			DoClearSquare(tile);
 
			AddTrackToSignalBuffer(tile, track, wp->owner);
 
		}
 
		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);
 
}
 

	
 
/**
 
 * Delete a waypoint
 
 * @param tile tile where waypoint is to be deleted
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return cost of operation or error
0 comments (0 inline, 0 general)