Changeset - r5867:de68577800e6
[Not reviewed]
master
0 3 0
tron - 18 years ago 2007-01-28 21:54:40
tron@openttd.org
(svn r8449) -Fix

-Codechange: Remove the superfluous attribute RoadStop::prev
3 files changed with 19 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/station.cpp
Show inline comments
 
@@ -365,8 +365,7 @@ RoadStop::RoadStop(TileIndex tile) :
 
	xy(tile),
 
	status(3), // stop is free
 
	num_vehicles(0),
 
	next(NULL),
 
	prev(NULL)
 
	next(NULL)
 
{
 
	DEBUG(ms, cDebugCtorLevel,  "I+ at %d[0x%x]", tile, tile);
 
}
 
@@ -386,9 +385,6 @@ RoadStop::~RoadStop()
 
	}
 
	assert(num_vehicles == 0);
 

	
 
	if (prev != NULL) prev->next = next;
 
	if (next != NULL) next->prev = prev;
 

	
 
	DEBUG(ms, cDebugCtorLevel , "I- at %d[0x%x]", xy, xy);
 

	
 
	xy = INVALID_TILE;
src/station.h
Show inline comments
 
@@ -51,7 +51,6 @@ struct RoadStop {
 
	byte             status;                ///< Current status of the Stop. Like which spot is taken. TODO - enumify this
 
	byte             num_vehicles;          ///< Number of vehicles currently slotted to this stop
 
	struct RoadStop  *next;                 ///< Next stop of the given type at this station
 
	struct RoadStop  *prev;                 ///< Previous stop of the given type at this station
 

	
 
	RoadStop(TileIndex tile);
 
	~RoadStop();
src/station_cmd.cpp
Show inline comments
 
@@ -1287,7 +1287,7 @@ int32 DoConvertStationRail(TileIndex til
 

	
 
/** Heavy wizardry used to add a roadstop to a station.
 
 * To understand the function, lets first look at what is passed around,
 
 * especially the last two parameters. CmdBuildRoadStop allocates a road
 
 * especially the last parameter. CmdBuildRoadStop allocates a road
 
 * stop and needs to put that stop into the linked list of road stops.
 
 * It (CmdBuildRoadStop) has a **currstop pointer which points to element
 
 * in the linked list of stops (each element in this list being a pointer
 
@@ -1295,28 +1295,23 @@ int32 DoConvertStationRail(TileIndex til
 
 * modify this pointer (**currstop) thus we need to pass by reference,
 
 * obtaining a triple pointer (***currstop). When finished, **currstop
 
 * in CmdBuildRoadStop will contain the address of the pointer which will
 
 * then point into the global roadstop array. *prev (in CmdBuildRoadStop)
 
 * is the pointer tino the global roadstop array which has *currstop in
 
 * its ->next element.
 
 * then point into the global roadstop array.
 
 * @param[in] truck_station Determines whether a stop is RoadStop::BUS or RoadStop::TRUCK
 
 * @param[in] station The station to do the whole procedure for
 
 * @param[out] currstop See the detailed function description
 
 * @param prev See the detailed function description
 
 */
 
static void FindRoadStopSpot(bool truck_station, Station* st, RoadStop*** currstop, RoadStop** prev)
 
static void FindRoadStopSpot(bool truck_station, Station* st, RoadStop*** currstop)
 
{
 
	RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops;
 
	assert(*prev == NULL);
 

	
 
	if (*primary_stop == NULL) {
 
		//we have no roadstop of the type yet, so write a "primary stop"
 
		*currstop = primary_stop;
 
	} else {
 
		//there are stops already, so append to the end of the list
 
		*prev = *primary_stop;
 
		*currstop = &(*primary_stop)->next;
 
		while (**currstop != NULL) {
 
			*prev = (*prev)->next;
 
			*currstop = &(**currstop)->next;
 
		}
 
	}
 
@@ -1332,7 +1327,6 @@ int32 CmdBuildRoadStop(TileIndex tile, u
 
	Station *st;
 
	RoadStop *road_stop;
 
	RoadStop **currstop;
 
	RoadStop *prev = NULL;
 
	int32 cost;
 
	int32 ret;
 
	bool type = !!p2;
 
@@ -1383,7 +1377,7 @@ int32 CmdBuildRoadStop(TileIndex tile, u
 

	
 
		if (!st->rect.BeforeAddTile(tile, StationRect::ADD_TEST)) return CMD_ERROR;
 

	
 
		FindRoadStopSpot(type, st, &currstop, &prev);
 
		FindRoadStopSpot(type, st, &currstop);
 
	} else {
 
		/* allocate and initialize new station */
 
		st = new Station(tile);
 
@@ -1396,7 +1390,7 @@ int32 CmdBuildRoadStop(TileIndex tile, u
 
		Town *t = st->town = ClosestTownFromTile(tile, (uint)-1);
 
		if (!GenerateStationName(st, tile, 0)) return CMD_ERROR;
 

	
 
		FindRoadStopSpot(type, st, &currstop, &prev);
 
		FindRoadStopSpot(type, st, &currstop);
 

	
 
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
 
			SETBIT(t->have_ratings, _current_player);
 
@@ -1412,7 +1406,6 @@ int32 CmdBuildRoadStop(TileIndex tile, u
 
		*currstop = road_stop;
 

	
 
		//initialize an empty station
 
		road_stop->prev = prev;
 
		st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile);
 

	
 
		st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
 
@@ -1454,15 +1447,18 @@ static int32 RemoveRoadStop(Station *st,
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		//we only had one stop left
 
		if (cur_stop->next == NULL && cur_stop->prev == NULL) {
 
			//so we remove ALL stops
 
			*primary_stop = NULL;
 
			st->facilities &= (is_truck) ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP;
 
		} else if (cur_stop == *primary_stop) {
 
			//removed the first stop in the list
 
			//need to set the primary element to the next stop
 
			*primary_stop = (*primary_stop)->next;
 
		if (*primary_stop == cur_stop) {
 
			// removed the first stop in the list
 
			*primary_stop = cur_stop->next;
 
			// removed the only stop?
 
			if (*primary_stop == NULL) {
 
				st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP);
 
			}
 
		} else {
 
			// tell the predecessor in the list to skip this stop
 
			RoadStop *pred = *primary_stop;
 
			while (pred->next != cur_stop) pred = pred->next;
 
			pred->next = cur_stop->next;
 
		}
 

	
 
		delete cur_stop;
 
@@ -2845,7 +2841,7 @@ static const SaveLoad _roadstop_desc[] =
 
	SLE_CONDNULL(1, 0, 25),
 

	
 
	SLE_REF(RoadStop,next,         REF_ROADSTOPS),
 
	SLE_REF(RoadStop,prev,         REF_ROADSTOPS),
 
	SLE_CONDNULL(2, 0, 44),
 

	
 
	SLE_CONDNULL(4, 0, 24),
 
	SLE_CONDNULL(1, 25, 25),
0 comments (0 inline, 0 general)