(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
authorrubidium
Thu, 30 Aug 2007 13:03:56 +0000
changeset 7988 6075538f6111
parent 7987 b3627df3493a
child 7989 116c8f9769af
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
src/ai/default/default.cpp
src/aircraft_cmd.cpp
src/aircraft_gui.cpp
src/articulated_vehicles.cpp
src/autoreplace_cmd.cpp
src/depot_gui.cpp
src/disaster_cmd.cpp
src/economy.cpp
src/group_cmd.cpp
src/newgrf_engine.cpp
src/rail_cmd.cpp
src/road_cmd.cpp
src/roadveh.h
src/roadveh_cmd.cpp
src/roadveh_gui.cpp
src/train.h
src/train_cmd.cpp
src/train_gui.cpp
src/vehicle.cpp
src/vehicle.h
src/vehicle_gui.cpp
--- a/src/ai/default/default.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/ai/default/default.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -261,8 +261,8 @@
 	const Vehicle* u = v;
 	int num = 0;
 
-	while (++num, u->next != NULL) {
-		u = u->next;
+	while (++num, u->Next() != NULL) {
+		u = u->Next();
 	}
 
 	// XXX: check if a wagon
@@ -2496,7 +2496,7 @@
 
 	// Sell a vehicle if the train is double headed.
 	v = GetVehicle(loco_id);
-	if (v->next != NULL) {
+	if (v->Next() != NULL) {
 		i = p->ai.wagon_list[p->ai.num_wagons * 2 - 2];
 		p->ai.wagon_list[p->ai.num_wagons * 2 - 2] = INVALID_VEHICLE;
 		DoCommand(tile, i, 0, DC_EXEC, CMD_SELL_RAIL_WAGON);
--- a/src/aircraft_cmd.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/aircraft_cmd.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -171,7 +171,7 @@
 {
 	assert(v->subtype == AIR_HELICOPTER);
 
-	const Vehicle *w = v->next->next;
+	const Vehicle *w = v->Next()->Next();
 	if (is_custom_sprite(v->spritenum)) {
 		SpriteID spritenum = GetCustomRotorSprite(v, false);
 		if (spritenum != 0) return spritenum;
@@ -678,7 +678,7 @@
 	if (flags & DC_EXEC) {
 		v->cargo_cap = pass;
 
-		Vehicle *u = v->next;
+		Vehicle *u = v->Next();
 		uint mail = IsCargoInClass(new_cid, CC_PASSENGERS) ? avi->mail_capacity : 0;
 		u->cargo_cap = mail;
 		v->cargo.Truncate(v->cargo_type == new_cid ? pass : 0);
@@ -771,13 +771,13 @@
 
 	do {
 		v->cargo.AgeCargo();
-		v = v->next;
+		v = v->Next();
 	} while (v != NULL);
 }
 
 static void HelicopterTickHandler(Vehicle *v)
 {
-	Vehicle *u = v->next->next;
+	Vehicle *u = v->Next()->Next();
 
 	if (u->vehstatus & VS_HIDDEN) return;
 
@@ -829,13 +829,13 @@
 	v->z_pos = z;
 
 	v->cur_image = v->GetImage(v->direction);
-	if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v);
+	if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v);
 
 	BeginVehicleMove(v);
 	VehiclePositionChanged(v);
 	EndVehicleMove(v);
 
-	Vehicle *u = v->next;
+	Vehicle *u = v->Next();
 
 	int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE);
 	int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
@@ -850,7 +850,7 @@
 	VehiclePositionChanged(u);
 	EndVehicleMove(u);
 
-	u = u->next;
+	u = u->Next();
 	if (u != NULL) {
 		u->x_pos = x;
 		u->y_pos = y;
@@ -870,9 +870,9 @@
 	v->subspeed = 0;
 	v->progress = 0;
 
-	Vehicle *u = v->next;
+	Vehicle *u = v->Next();
 	u->vehstatus |= VS_HIDDEN;
-	u = u->next;
+	u = u->Next();
 	if (u != NULL) {
 		u->vehstatus |= VS_HIDDEN;
 		u->cur_speed = 0;
@@ -1057,7 +1057,7 @@
 
 	/* Helicopter raise */
 	if (amd->flag & AMED_HELI_RAISE) {
-		Vehicle *u = v->next->next;
+		Vehicle *u = v->Next()->Next();
 
 		/* Make sure the rotors don't rotate too fast */
 		if (u->cur_speed > 32) {
@@ -1101,7 +1101,7 @@
 			int z = GetSlopeZ(x, y) + 1 + afc->delta_z;
 
 			if (z == v->z_pos) {
-				Vehicle *u = v->next->next;
+				Vehicle *u = v->Next()->Next();
 
 				/*  Increase speed of rotors. When speed is 80, we've landed. */
 				if (u->cur_speed >= 80) return true;
@@ -1411,7 +1411,7 @@
 void Aircraft::MarkDirty()
 {
 		this->cur_image = this->GetImage(this->direction);
-		if (this->subtype == AIR_HELICOPTER) this->next->next->cur_image = GetRotorImage(this);
+		if (this->subtype == AIR_HELICOPTER) this->Next()->Next()->cur_image = GetRotorImage(this);
 		MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
 }
 
@@ -1429,7 +1429,7 @@
 	SetDParam(0, amt);
 
 	v->cargo.Truncate(0);
-	v->next->cargo.Truncate(0);
+	v->Next()->cargo.Truncate(0);
 	const Station *st = GetStation(v->u.air.targetairport);
 	StringID newsitem;
 	if (st->airport_tile == 0) {
@@ -1527,11 +1527,11 @@
 	v->direction = DIR_SE;
 	v->vehstatus &= ~VS_HIDDEN;
 	{
-		Vehicle *u = v->next;
+		Vehicle *u = v->Next();
 		u->vehstatus &= ~VS_HIDDEN;
 
 		/* Rotor blades */
-		u = u->next;
+		u = u->Next();
 		if (u != NULL) {
 			u->vehstatus &= ~VS_HIDDEN;
 			u->cur_speed = 80;
@@ -2155,7 +2155,7 @@
 			v_oldstyle->tile = 0; // aircraft in air is tile=0
 
 			/* correct speed of helicopter-rotors */
-			if (v_oldstyle->subtype == AIR_HELICOPTER) v_oldstyle->next->next->cur_speed = 32;
+			if (v_oldstyle->subtype == AIR_HELICOPTER) v_oldstyle->Next()->Next()->cur_speed = 32;
 
 			/* set new position x,y,z */
 			SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle));
--- a/src/aircraft_gui.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/aircraft_gui.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -133,7 +133,7 @@
 
 					SetDParam(0, v->cargo_type);
 					SetDParam(1, v->cargo_cap);
-					u = v->next;
+					u = v->Next();
 					SetDParam(2, u->cargo_type);
 					SetDParam(3, u->cargo_cap);
 					DrawString(60, y, (u->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, 0);
@@ -151,7 +151,7 @@
 
 					y += 10;
 				}
-			} while ( (v=v->next) != NULL);
+			} while ((v = v->Next()) != NULL);
 		}
 	} break;
 
--- a/src/articulated_vehicles.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/articulated_vehicles.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -41,11 +41,11 @@
 
 		/* Attempt to use pre-allocated vehicles until they run out. This can happen
 		 * if the callback returns different values depending on the cargo type. */
-		u->next = vl[i];
-		if (u->next == NULL) u->next = new InvalidVehicle();
-		if (u->next == NULL) return;
+		u->SetNext(vl[i]);
+		if (u->Next() == NULL) u->SetNext(new InvalidVehicle());
+		if (u->Next() == NULL) return;
 
-		u = u->next;
+		u = u->Next();
 
 		EngineID engine_type = GetFirstEngineOfType(type) + GB(callback, 0, 7);
 		bool flip_image = HASBIT(callback, 7);
--- a/src/autoreplace_cmd.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/autoreplace_cmd.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -42,9 +42,9 @@
 			dest->day_counter  = source->day_counter;
 			dest->tick_counter = source->tick_counter;
 
-		} while (source->cargo.Count() > 0 && (dest = dest->next) != NULL);
+		} while (source->cargo.Count() > 0 && (dest = dest->Next()) != NULL);
 		dest = v;
-	} while ((source = source->next) != NULL);
+	} while ((source = source->Next()) != NULL);
 
 	/*
 	 * The of the train will be incorrect at this moment. This is due
@@ -110,7 +110,7 @@
 		/* Now we found a cargo type being carried on the train and we will see if it is possible to carry to this one */
 		if (v->cargo_type == new_cargo_type) return CT_NO_REFIT;
 		if (CanRefitTo(engine_type, v->cargo_type)) return v->cargo_type;
-	} while ((v = v->next) != NULL);
+	} while ((v = v->Next()) != NULL);
 	return CT_NO_REFIT; // We failed to find a cargo type on the old vehicle and we will not refit the new one
 }
 
@@ -189,7 +189,7 @@
 			}
 		}
 
-		if (new_v->type == VEH_TRAIN && HASBIT(old_v->u.rail.flags, VRF_REVERSE_DIRECTION) && !IsMultiheaded(new_v) && !(new_v->next != NULL && IsArticulatedPart(new_v->next))) {
+		if (new_v->type == VEH_TRAIN && HASBIT(old_v->u.rail.flags, VRF_REVERSE_DIRECTION) && !IsMultiheaded(new_v) && !(new_v->Next() != NULL && IsArticulatedPart(new_v->Next()))) {
 			// we are autorenewing to a single engine, so we will turn it as the old one was turned as well
 			SETBIT(new_v->u.rail.flags, VRF_REVERSE_DIRECTION);
 		}
@@ -247,12 +247,12 @@
 		}
 	} else { // flags & DC_EXEC not set
 		CommandCost tmp_move;
-		if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v) && old_v->next != NULL) {
+		if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v) && old_v->Next() != NULL) {
 			/* Verify that the wagons can be placed on the engine in question.
 			 * This is done by building an engine, test if the wagons can be added and then sell the test engine. */
 			DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v));
 			Vehicle *temp = GetVehicle(_new_vehicle_id);
-			tmp_move = DoCommand(0, (temp->index << 16) | old_v->next->index, 1, 0, CMD_MOVE_RAIL_VEHICLE);
+			tmp_move = DoCommand(0, (temp->index << 16) | old_v->Next()->index, 1, 0, CMD_MOVE_RAIL_VEHICLE);
 			DoCommand(0, temp->index, 0, DC_EXEC, GetCmdSellVeh(old_v));
 		}
 
--- a/src/depot_gui.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/depot_gui.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -279,7 +279,7 @@
 		/*Draw the train counter */
 		i = 0;
 		u = v;
-		do i++; while ( (u=u->next) != NULL); // Determine length of train
+		do i++; while ((u = u->Next()) != NULL); // Determine length of train
 		SetDParam(0, i);                      // Set the counter
 		DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
 	}
@@ -356,7 +356,7 @@
 			x += skip;
 
 			/* find the vehicle in this row that was clicked */
-			while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->next;
+			while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->Next();
 
 			/* if an articulated part was selected, find its parent */
 			while (v != NULL && IsArticulatedPart(v)) v = GetPrevVehicleInChain(v);
--- a/src/disaster_cmd.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/disaster_cmd.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -158,7 +158,7 @@
 	VehiclePositionChanged(v);
 	EndVehicleMove(v);
 
-	if ((u = v->next) != NULL) {
+	if ((u = v->Next()) != NULL) {
 		int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE);
 		int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
 		BeginVehicleMove(u);
@@ -173,7 +173,7 @@
 		VehiclePositionChanged(u);
 		EndVehicleMove(u);
 
-		if ((u = u->next) != NULL) {
+		if ((u = u->Next()) != NULL) {
 			BeginVehicleMove(u);
 			u->x_pos = x;
 			u->y_pos = y;
--- a/src/economy.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/economy.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -1412,7 +1412,7 @@
 	/* Start unloading in at the first possible moment */
 	front_v->load_unload_time_rem = 1;
 
-	for (Vehicle *v = front_v; v != NULL; v = v->next) {
+	for (Vehicle *v = front_v; v != NULL; v = v->Next()) {
 		/* No cargo to unload */
 		if (v->cargo_cap == 0 || v->cargo.Empty()) continue;
 
@@ -1499,7 +1499,7 @@
 	if (--v->load_unload_time_rem != 0) {
 		if (_patches.improved_load && HASBIT(v->current_order.flags, OFB_FULL_LOAD)) {
 			/* 'Reserve' this cargo for this vehicle, because we were first. */
-			for (; v != NULL; v = v->next) {
+			for (; v != NULL; v = v->Next()) {
 				if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo.Count();
 			}
 		}
@@ -1529,7 +1529,7 @@
 	StationID last_visited = v->last_station_visited;
 	Station *st = GetStation(last_visited);
 
-	for (; v != NULL; v = v->next) {
+	for (; v != NULL; v = v->Next()) {
 		if (v->cargo_cap == 0) continue;
 
 		byte load_amount = EngInfo(v->engine_type)->load_amount;
@@ -1651,7 +1651,7 @@
 	 * enough to fill the previous wagons) */
 	if (_patches.improved_load && HASBIT(u->current_order.flags, OFB_FULL_LOAD)) {
 		/* Update left cargo */
-		for (v = u; v != NULL; v = v->next) {
+		for (v = u; v != NULL; v = v->Next()) {
 			if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo.Count();
 		}
 	}
--- a/src/group_cmd.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/group_cmd.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -371,7 +371,7 @@
 
 	assert(v->IsValid() && v->type == VEH_TRAIN && IsFrontEngine(v));
 
-	for (Vehicle *u = v; u != NULL; u = u->next) {
+	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 		if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g);
 
 		u->group_id = new_g;
@@ -394,7 +394,7 @@
 	assert(v->IsValid() && v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v)));
 
 	GroupID new_g = IsFrontEngine(v) ? v->group_id : (GroupID)DEFAULT_GROUP;
-	for (Vehicle *u = v; u != NULL; u = u->next) {
+	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 		if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g);
 
 		u->group_id = new_g;
--- a/src/newgrf_engine.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/newgrf_engine.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -516,14 +516,14 @@
 				byte chain_before = 0;
 				byte chain_after  = 0;
 
-				for (u = GetFirstVehicleInChain(v); u != v; u = u->next) {
+				for (u = GetFirstVehicleInChain(v); u != v; u = u->Next()) {
 					chain_before++;
 					if (variable == 0x41 && u->engine_type != v->engine_type) chain_before = 0;
 				}
 
-				while (u->next != NULL && (variable == 0x40 || u->next->engine_type == v->engine_type)) {
+				while (u->Next() != NULL && (variable == 0x40 || u->Next()->engine_type == v->engine_type)) {
 					chain_after++;
-					u = u->next;
+					u = u->Next();
 				}
 
 				return chain_before | chain_after << 8 | (chain_before + chain_after + (variable == 0x41)) << 16;
@@ -544,7 +544,7 @@
 			memset(common_cargos, 0, sizeof(common_cargos));
 			memset(common_subtypes, 0, sizeof(common_subtypes));
 
-			for (u = v; u != NULL; u = u->next) {
+			for (u = v; u != NULL; u = u->Next()) {
 				/* Skip empty engines */
 				if (u->cargo_cap == 0) continue;
 
@@ -579,7 +579,7 @@
 			if (v->type != VEH_AIRCRAFT) return UINT_MAX;
 
 			{
-				const Vehicle *w = v->next;
+				const Vehicle *w = v->Next();
 				uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height
 				byte airporttype;
 
@@ -611,7 +611,7 @@
 			if (v->type != VEH_TRAIN) return 0;
 
 			const Vehicle *u_p = GetPrevVehicleInChain(v);
-			const Vehicle *u_n = v->next;
+			const Vehicle *u_n = v->Next();
 			DirDiff f = (u_p == NULL) ?  DIRDIFF_SAME : DirDifference(u_p->direction, v->direction);
 			DirDiff b = (u_n == NULL) ?  DIRDIFF_SAME : DirDifference(v->direction, u_n->direction);
 			DirDiff t = ChangeDirDiff(f, b);
@@ -644,7 +644,7 @@
 
 			{
 				uint count = 0;
-				for (; v != NULL; v = v->next) {
+				for (; v != NULL; v = v->Next()) {
 					if (v->engine_type == parameter) count++;
 				}
 				return count;
@@ -735,7 +735,7 @@
 		case 0x57: return GB(ClampToI32(v->profit_last_year),  8, 24);
 		case 0x58: return GB(ClampToI32(v->profit_last_year), 16, 16);
 		case 0x59: return GB(ClampToI32(v->profit_last_year), 24,  8);
-		case 0x5A: return v->next == NULL ? INVALID_VEHICLE : v->next->index;
+		case 0x5A: return v->Next() == NULL ? INVALID_VEHICLE : v->Next()->index;
 		case 0x5C: return ClampToI32(v->value);
 		case 0x5D: return GB(ClampToI32(v->value),  8, 24);
 		case 0x5E: return GB(ClampToI32(v->value), 16, 16);
@@ -914,7 +914,7 @@
 
 	if (v == NULL) return group->g.result.sprite;
 
-	return group->g.result.sprite + (info_view ? 0 : (v->next->next->u.air.state % group->g.result.num_sprites));
+	return group->g.result.sprite + (info_view ? 0 : (v->Next()->Next()->u.air.state % group->g.result.num_sprites));
 }
 
 
@@ -1040,7 +1040,7 @@
 			/* We now trigger the next vehicle in chain recursively.
 			 * The random bits portions may be different for each
 			 * vehicle in chain. */
-			if (v->next != NULL) DoTriggerVehicle(v->next, trigger, 0, true);
+			if (v->Next() != NULL) DoTriggerVehicle(v->Next(), trigger, 0, true);
 			break;
 
 		case VEHICLE_TRIGGER_EMPTY:
@@ -1048,14 +1048,14 @@
 			 * recursively.  The random bits portions must be same
 			 * for each vehicle in chain, so we give them all
 			 * first chained vehicle's portion of random bits. */
-			if (v->next != NULL) DoTriggerVehicle(v->next, trigger, first ? new_random_bits : base_random_bits, false);
+			if (v->Next() != NULL) DoTriggerVehicle(v->Next(), trigger, first ? new_random_bits : base_random_bits, false);
 			break;
 
 		case VEHICLE_TRIGGER_ANY_NEW_CARGO:
 			/* Now pass the trigger recursively to the next vehicle
 			 * in chain. */
 			assert(!first);
-			if (v->next != NULL) DoTriggerVehicle(v->next, VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false);
+			if (v->Next() != NULL) DoTriggerVehicle(v->Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false);
 			break;
 	}
 }
--- a/src/rail_cmd.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/rail_cmd.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -2156,7 +2156,7 @@
 			v->u.rail.track = TRACK_BIT_DEPOT,
 			v->vehstatus |= VS_HIDDEN; /* hide it */
 			v->direction = ReverseDir(v->direction);
-			if (v->next == NULL) VehicleEnterDepot(v);
+			if (v->Next() == NULL) VehicleEnterDepot(v);
 			v->tile = tile;
 
 			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@@ -2165,7 +2165,7 @@
 	} else if (fract_coord_leave == fract_coord) {
 		if (DiagDirToDir(dir) == v->direction) {
 			/* leave the depot? */
-			if ((v = v->next) != NULL) {
+			if ((v = v->Next()) != NULL) {
 				v->vehstatus &= ~VS_HIDDEN;
 				v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
 			}
--- a/src/road_cmd.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/road_cmd.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -1342,7 +1342,7 @@
 				v->u.road.state = RVSB_IN_DEPOT;
 				v->vehstatus |= VS_HIDDEN;
 				v->direction = ReverseDir(v->direction);
-				if (v->next == NULL) VehicleEnterDepot(v);
+				if (v->Next() == NULL) VehicleEnterDepot(v);
 				v->tile = tile;
 
 				InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
--- a/src/roadveh.h	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/roadveh.h	Thu Aug 30 13:03:56 2007 +0000
@@ -41,7 +41,7 @@
 static inline bool RoadVehHasArticPart(const Vehicle *v)
 {
 	assert(v->type == VEH_ROAD);
-	return v->next != NULL && IsRoadVehArticPart(v->next);
+	return v->Next() != NULL && IsRoadVehArticPart(v->Next());
 }
 
 
--- a/src/roadveh_cmd.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/roadveh_cmd.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -140,7 +140,7 @@
 	assert(v->type == VEH_ROAD);
 	assert(IsRoadVehFront(v));
 
-	for (Vehicle *u = v; u != NULL; u = u->next) {
+	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 		/* Update the v->first cache. */
 		if (u->first == NULL) u->first = v;
 
@@ -338,7 +338,7 @@
 	if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return false;
 	if (IsRoadVehFront(v) && !(v->vehstatus & VS_STOPPED)) return false;
 
-	for (; v != NULL; v = v->next) {
+	for (; v != NULL; v = v->Next()) {
 		if (v->u.road.state != RVSB_IN_DEPOT || v->tile != tile) return false;
 	}
 	return true;
@@ -556,7 +556,7 @@
 
 void RoadVehicle::MarkDirty()
 {
-	for (Vehicle *v = this; v != NULL; v = v->next) {
+	for (Vehicle *v = this; v != NULL; v = v->Next()) {
 		v->cur_image = v->GetImage(v->direction);
 		MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
 	}
@@ -599,8 +599,8 @@
 static void DeleteLastRoadVeh(Vehicle *v)
 {
 	Vehicle *u = v;
-	for (; v->next != NULL; v = v->next) u = v;
-	u->next = NULL;
+	for (; v->Next() != NULL; v = v->Next()) u = v;
+	u->SetNext(NULL);
 
 	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
 
@@ -646,7 +646,7 @@
 		v->UpdateDeltaXY(v->direction);
 		v->cur_image = v->GetImage(v->direction);
 		SetRoadVehPosition(v, v->x_pos, v->y_pos);
-	} while ((v = v->next) != NULL);
+	} while ((v = v->Next()) != NULL);
 }
 
 static void RoadVehIsCrashed(Vehicle *v)
@@ -679,7 +679,7 @@
 
 	v->u.road.crashed_ctr++;
 
-	for (Vehicle *u = v; u != NULL; u = u->next) {
+	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 		if (IsCargoInClass(u->cargo_type, CC_PASSENGERS)) pass += u->cargo.Count();
 
 		u->vehstatus |= VS_CRASHED;
@@ -706,7 +706,7 @@
 
 static void RoadVehCheckTrainCrash(Vehicle *v)
 {
-	for (Vehicle *u = v; u != NULL; u = u->next) {
+	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 		if (u->u.road.state == RVSB_WORMHOLE) continue;
 
 		TileIndex tile = u->tile;
@@ -1333,7 +1333,7 @@
 static bool RoadVehLeaveDepot(Vehicle *v, bool first)
 {
 	/* Don't leave if not all the wagons are in the depot. */
-	for (const Vehicle *u = v; u != NULL; u = u->next) {
+	for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 		if (u->u.road.state != RVSB_IN_DEPOT || u->tile != v->tile) return false;
 	}
 
@@ -1627,11 +1627,11 @@
 	/* This vehicle is not in a wormhole and it hasn't entered a new tile. If
 	 * it's on a depot tile, check if it's time to activate the next vehicle in
 	 * the chain yet. */
-	if (v->next != NULL &&
+	if (v->Next() != NULL &&
 			IsTileType(v->tile, MP_ROAD) && GetRoadTileType(v->tile) == ROAD_TILE_DEPOT) {
 
 		if (v->u.road.frame == v->u.road.cached_veh_length + RVC_DEPOT_START_FRAME) {
-			RoadVehLeaveDepot(v->next, false);
+			RoadVehLeaveDepot(v->Next(), false);
 		}
 	}
 
@@ -1822,7 +1822,7 @@
 	/* Check if vehicle needs to proceed, return if it doesn't */
 	if (!RoadVehAccelerate(v)) return;
 
-	for (Vehicle *prev = NULL; v != NULL; prev = v, v = v->next) {
+	for (Vehicle *prev = NULL; v != NULL; prev = v, v = v->Next()) {
 		if (!IndividualRoadVehicleController(v, prev)) break;
 	}
 }
@@ -2029,7 +2029,7 @@
 
 	SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN);
 
-	for (; v != NULL; v = v->next) {
+	for (; v != NULL; v = v->Next()) {
 		/* XXX: We refit all the attached wagons en-masse if they can be
 		 * refitted. This is how TTDPatch does it.  TODO: Have some nice
 		 * [Refit] button near each wagon. */
--- a/src/roadveh_gui.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/roadveh_gui.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -46,7 +46,7 @@
 		}
 
 		dx += length;
-		v = v->next;
+		v = v->Next();
 	} while (v != NULL && dx < max_length);
 }
 
@@ -65,7 +65,7 @@
 		/* Add space for the cargo amount for each part. */
 		do {
 			height_extension += 11;
-		} while ((v = v->next) != NULL);
+		} while ((v = v->Next()) != NULL);
 
 		ResizeWindow(w, 0, height_extension);
 	} break;
@@ -128,7 +128,7 @@
 
 			memset(max_cargo, 0, sizeof(max_cargo));
 
-			for (const Vehicle *u = v; u != NULL; u = u->next) {
+			for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 				max_cargo[u->cargo_type] += u->cargo_cap;
 			}
 
@@ -153,7 +153,7 @@
 			SetDParamStr(0, capacity);
 			DrawStringTruncated(34, 67 + y_offset, STR_JUST_STRING, 0, w->width - 34);
 
-			for (const Vehicle *u = v; u != NULL; u = u->next) {
+			for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 				str = STR_8812_EMPTY;
 				if (!u->cargo.Empty()) {
 					SetDParam(0, u->cargo_type);
--- a/src/train.h	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/train.h	Thu Aug 30 13:03:56 2007 +0000
@@ -200,7 +200,7 @@
 static inline bool EngineHasArticPart(const Vehicle *v)
 {
 	assert(v->type == VEH_TRAIN);
-	return (v->next != NULL && IsArticulatedPart(v->next));
+	return (v->Next() != NULL && IsArticulatedPart(v->Next()));
 }
 
 /**
@@ -211,7 +211,7 @@
 static inline Vehicle *GetNextArticPart(const Vehicle *v)
 {
 	assert(EngineHasArticPart(v));
-	return v->next;
+	return v->Next();
 }
 
 /** Get the last part of a multi-part engine.
@@ -235,7 +235,7 @@
 	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
 
 	/* v now contains the last artic part in the engine */
-	return v->next;
+	return v->Next();
 }
 
 void ConvertOldMultiheadToNew();
--- a/src/train_cmd.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/train_cmd.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -70,7 +70,7 @@
 	uint32 total_power = 0;
 	uint32 max_te = 0;
 
-	for (const Vehicle *u = v; u != NULL; u = u->next) {
+	for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 		/* Power is not added for articulated parts */
 		if (IsArticulatedPart(u)) continue;
 
@@ -112,7 +112,7 @@
 {
 	uint32 weight = 0;
 
-	for (Vehicle *u = v; u != NULL; u = u->next) {
+	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 		uint32 vweight = GetCargo(u->cargo_type)->weight * u->cargo.Count() * FreightWagonMult(u->cargo_type) / 16;
 
 		/* Vehicle weight is not added for articulated parts. */
@@ -158,7 +158,7 @@
 	v->u.rail.cached_total_length = 0;
 	v->u.rail.compatible_railtypes = 0;
 
-	for (Vehicle *u = v; u != NULL; u = u->next) {
+	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 		const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
 
 		/* Update the v->first cache. This is faster than having to brute force it later. */
@@ -235,7 +235,7 @@
 			veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u);
 		}
 		if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor;
-		veh_len = clamp(veh_len, 0, u->next == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code
+		veh_len = clamp(veh_len, 0, u->Next() == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code
 		u->u.rail.cached_veh_length = 8 - veh_len;
 		v->u.rail.cached_total_length += u->u.rail.cached_veh_length;
 	}
@@ -309,9 +309,9 @@
 	int sum = 0;
 	int pos = 0;
 	int lastpos = -1;
-	for (const Vehicle *u = v; u->next != NULL; u = u->next, pos++) {
+	for (const Vehicle *u = v; u->Next() != NULL; u = u->Next(), pos++) {
 		Direction dir = u->direction;
-		Direction ndir = u->next->direction;
+		Direction ndir = u->Next()->direction;
 		int i;
 
 		for (i = 0; i < 2; i++) {
@@ -371,7 +371,7 @@
 	int num = 0; //number of vehicles, change this into the number of axles later
 	int incl = 0;
 	int drag_coeff = 20; //[1e-4]
-	for (const Vehicle *u = v; u != NULL; u = u->next) {
+	for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 		num++;
 		drag_coeff += 3;
 
@@ -792,7 +792,7 @@
 	if (!IsTileDepotType(tile, TRANSPORT_RAIL) || v->cur_speed != 0) return -1;
 
 	int count = 0;
-	for (; v != NULL; v = v->next) {
+	for (; v != NULL; v = v->Next()) {
 		/* This count is used by the depot code to determine the number of engines
 		 * in the consist. Exclude articulated parts so that autoreplacing to
 		 * engines with more articulated parts than before works correctly.
@@ -857,7 +857,7 @@
 			Vehicle *v = dst;
 
 			while (v->engine_type == eng) {
-				v = v->next;
+				v = v->Next();
 				if (v == NULL) return dst;
 			}
 		}
@@ -875,8 +875,8 @@
 	UnlinkWagon(v, GetFirstVehicleInChain(v));
 	if (dest == NULL) return;
 
-	v->next = dest->next;
-	dest->next = v;
+	v->SetNext(dest->Next());
+	dest->SetNext(v);
 	ClearFreeWagon(v);
 	ClearFrontEngine(v);
 }
@@ -896,7 +896,7 @@
 
 		/* make sure that there are no free cars before next engine */
 		Vehicle *u;
-		for (u = v; u->next != NULL && !IsTrainEngine(u->next); u = u->next) {}
+		for (u = v; u->Next() != NULL && !IsTrainEngine(u->Next()); u = u->Next()) {}
 
 		if (u == v->u.rail.other_multiheaded_part) continue;
 		AddWagonToConsist(v->u.rail.other_multiheaded_part, u);
@@ -1023,8 +1023,8 @@
 	/* do it? */
 	if (flags & DC_EXEC) {
 		/* clear the ->first cache */
-		for (Vehicle *u = src_head; u != NULL; u = u->next) u->first = NULL;
-		for (Vehicle *u = dst_head; u != NULL; u = u->next) u->first = NULL;
+		for (Vehicle *u = src_head; u != NULL; u = u->Next()) u->first = NULL;
+		for (Vehicle *u = dst_head; u != NULL; u = u->Next()) u->first = NULL;
 
 		/* If we move the front Engine and if the second vehicle is not an engine
 		   add the whole vehicle to the DEFAULT_GROUP */
@@ -1097,13 +1097,13 @@
 				Vehicle *v;
 
 				for (v = src; GetNextVehicle(v) != NULL; v = GetNextVehicle(v));
-				GetLastEnginePart(v)->next = dst->next;
+				GetLastEnginePart(v)->SetNext(dst->Next());
 			}
-			dst->next = src;
+			dst->SetNext(src);
 		}
 		if (src->u.rail.other_multiheaded_part != NULL) {
 			if (src->u.rail.other_multiheaded_part == src_head) {
-				src_head = src_head->next;
+				src_head = src_head->Next();
 			}
 			AddWagonToConsist(src->u.rail.other_multiheaded_part, src);
 			/* previous line set the front engine to the old front. We need to clear that */
@@ -1263,7 +1263,7 @@
 				Vehicle *new_f = GetNextVehicle(first);
 
 				/* 2.1 If the first wagon is sold, update the first-> pointers to NULL */
-				for (Vehicle *tmp = first; tmp != NULL; tmp = tmp->next) tmp->first = NULL;
+				for (Vehicle *tmp = first; tmp != NULL; tmp = tmp->Next()) tmp->first = NULL;
 
 				/* 2.2 If there are wagons present after the deleted front engine, check
 				 * if the second wagon (which will be first) is an engine. If it is one,
@@ -1470,8 +1470,8 @@
 	Vehicle *a, *b;
 
 	/* locate vehicles to swap */
-	for (a = v; l != 0; l--) a = a->next;
-	for (b = v; r != 0; r--) b = b->next;
+	for (a = v; l != 0; l--) a = a->Next();
+	for (b = v; r != 0; r--) b = b->Next();
 
 	if (a != b) {
 		/* swap the hidden bits */
@@ -1539,30 +1539,30 @@
 static void AdvanceWagons(Vehicle *v, bool before)
 {
 	Vehicle *base = v;
-	Vehicle *first = base->next;
+	Vehicle *first = base->Next();
 	uint length = CountVehiclesInChain(v);
 
 	while (length > 2) {
 		/* find pairwise matching wagon
 		 * start<>end, start+1<>end-1, ... */
 		Vehicle *last = first;
-		for (uint i = length - 3; i > 0; i--) last = last->next;
+		for (uint i = length - 3; i > 0; i--) last = last->Next();
 
 		int differential = last->u.rail.cached_veh_length - base->u.rail.cached_veh_length;
 		if (before) differential *= -1;
 
 		if (differential > 0) {
 			/* disconnect last car to make sure only this subset moves */
-			Vehicle *tempnext = last->next;
-			last->next = NULL;
+			Vehicle *tempnext = last->Next();
+			last->SetNext(NULL);
 
 			for (int i = 0; i < differential; i++) TrainController(first, false);
 
-			last->next = tempnext;
+			last->SetNext(tempnext);
 		}
 
 		base = first;
-		first = first->next;
+		first = first->Next();
 		length -= 2;
 	}
 }
@@ -1593,7 +1593,7 @@
 	/* count number of vehicles */
 	int r = -1;
 	const Vehicle *u = v;
-	do r++; while ( (u = u->next) != NULL );
+	do r++; while ((u = u->Next()) != NULL);
 
 	AdvanceWagons(v, true);
 
@@ -1772,7 +1772,7 @@
 				}
 			}
 		}
-	} while ((v = v->next) != NULL && !only_this);
+	} while ((v = v->Next()) != NULL && !only_this);
 
 	_returned_refit_capacity = num;
 
@@ -2017,7 +2017,7 @@
 			}
 			break;
 		}
-	} while ((v = v->next) != NULL);
+	} while ((v = v->Next()) != NULL);
 
 	if (sound) PlayVehicleSound(u, VSE_TRAIN_EFFECT);
 }
@@ -2046,7 +2046,7 @@
 static bool CheckTrainStayInDepot(Vehicle *v)
 {
 	/* bail out if not all wagons are in the same depot or not in a depot at all */
-	for (const Vehicle *u = v; u != NULL; u = u->next) {
+	for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 		if (u->u.rail.track != TRACK_BIT_DEPOT || u->tile != v->tile) return false;
 	}
 
@@ -2470,7 +2470,7 @@
 	do {
 		v->cur_image = v->GetImage(v->direction);
 		MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
-	} while ((v = v->next) != NULL);
+	} while ((v = v->Next()) != NULL);
 
 	/* need to update acceleration and cached values since the goods on the train changed. */
 	TrainCargoChanged(this);
@@ -2756,7 +2756,7 @@
 
 	TrainCollideChecker tcc;
 	tcc.v = v;
-	tcc.v_skip = v->next;
+	tcc.v_skip = v->Next();
 	tcc.num = 0;
 
 	/* find colliding vehicles */
@@ -2807,7 +2807,7 @@
 	Vehicle *prev;
 
 	/* For every vehicle after and including the given vehicle */
-	for (prev = GetPrevVehicleInChain(v); v != NULL; prev = v, v = v->next) {
+	for (prev = GetPrevVehicleInChain(v); v != NULL; prev = v, v = v->Next()) {
 		DiagDirection enterdir = DIAGDIR_BEGIN;
 		bool update_signals = false;
 		BeginVehicleMove(v);
@@ -2934,7 +2934,7 @@
 					goto invalid_rail;
 				}
 
-				if (IsLevelCrossingTile(v->tile) && v->next == NULL) {
+				if (IsLevelCrossingTile(v->tile) && v->Next() == NULL) {
 					UnbarCrossing(v->tile);
 					MarkTileDirtyByTile(v->tile);
 				}
@@ -2997,7 +2997,7 @@
 
 			/* Signals can only change when the first
 			 * (above) or the last vehicle moves. */
-			if (v->next == NULL) TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir));
+			if (v->Next() == NULL) TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir));
 		}
 	}
 	return;
@@ -3028,8 +3028,8 @@
 	 * *u is then the one-before-last wagon, and *v the last
 	 * one which will physicially be removed */
 	Vehicle *u = v;
-	for (; v->next != NULL; v = v->next) u = v;
-	u->next = NULL;
+	for (; v->Next() != NULL; v = v->Next()) u = v;
+	u->SetNext(NULL);
 
 	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
@@ -3090,7 +3090,7 @@
 			   the bridge in that case */
 			if (v->u.rail.track != TRACK_BIT_WORMHOLE) AfterSetTrainPos(v, false);
 		}
-	} while ((v = v->next) != NULL);
+	} while ((v = v->Next()) != NULL);
 }
 
 static void HandleCrashedTrain(Vehicle *v)
@@ -3117,7 +3117,7 @@
 					EV_EXPLOSION_SMALL);
 				break;
 			}
-		} while ((u = u->next) != NULL);
+		} while ((u = u->Next()) != NULL);
 	}
 
 	if (state <= 240 && !(v->tick_counter & 3)) ChangeTrainDirRandomly(v);
@@ -3498,7 +3498,7 @@
 					}
 
 					Vehicle *w;
-					for (w = u->next; w != NULL && (w->engine_type != u->engine_type || w->u.rail.other_multiheaded_part != NULL); w = GetNextVehicle(w));
+					for (w = u->Next(); w != NULL && (w->engine_type != u->engine_type || w->u.rail.other_multiheaded_part != NULL); w = GetNextVehicle(w));
 					if (w != NULL) {
 						/* we found a car to partner with this engine. Now we will make sure it face the right way */
 						if (IsTrainEngine(w)) {
--- a/src/train_gui.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/train_gui.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -100,7 +100,7 @@
 		}
 		dx += width;
 
-		v = v->next;
+		v = v->Next();
 	} while (dx < count && v != NULL);
 
 	if (highlight_l != highlight_r) {
@@ -176,7 +176,7 @@
 		do {
 			act_cargo[u->cargo_type] += u->cargo.Count();
 			max_cargo[u->cargo_type] += u->cargo_cap;
-		} while ((u = u->next) != NULL);
+		} while ((u = u->Next()) != NULL);
 
 		/* Set scroll-amount seperately from counting, as to not compute num double
 		 * for more carriages of the same type
@@ -188,7 +188,7 @@
 	} else {
 		do {
 			if (!IsArticulatedPart(u) || u->cargo_cap != 0) num++;
-		} while ((u = u->next) != NULL);
+		} while ((u = u->Next()) != NULL);
 	}
 
 	SetVScrollCount(w, num);
@@ -249,7 +249,7 @@
 					SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
 					DrawSprite(u->GetImage(DIR_W), pal, x + WagonLengthToPixels(4 + dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
 					dx += u->u.rail.cached_veh_length;
-					u = u->next;
+					u = u->Next();
 				} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
 
 				px = x + WagonLengthToPixels(dx) + 2;
@@ -271,7 +271,7 @@
 			} else {
 				/* Move to the next line */
 				do {
-					v = v->next;
+					v = v->Next();
 				} while (v != NULL && IsArticulatedPart(v) && v->cargo_cap == 0);
 			}
 			if (v == NULL) return;
--- a/src/vehicle.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/vehicle.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -243,12 +243,12 @@
 					v->cur_image = v->GetImage(v->direction);
 
 					/* The plane's shadow will have the same image as the plane */
-					Vehicle *shadow = v->next;
+					Vehicle *shadow = v->Next();
 					shadow->cur_image = v->cur_image;
 
 					/* In the case of a helicopter we will update the rotor sprites */
 					if (v->subtype == AIR_HELICOPTER) {
-						Vehicle *rotor = shadow->next;
+						Vehicle *rotor = shadow->Next();
 						rotor->cur_image = GetRotorImage(v);
 					}
 
@@ -462,7 +462,7 @@
 
 Vehicle *GetLastVehicleInChain(Vehicle *v)
 {
-	while (v->next != NULL) v = v->next;
+	while (v->Next() != NULL) v = v->Next();
 	return v;
 }
 
@@ -476,7 +476,7 @@
 {
 	Vehicle *u;
 
-	FOR_ALL_VEHICLES(u) if (u->type == v->type && u->next == v) return u;
+	FOR_ALL_VEHICLES(u) if (u->type == v->type && u->Next() == v) return u;
 
 	return NULL;
 }
@@ -495,7 +495,7 @@
 	/* Check to see if this is the first */
 	if (v == u) return NULL;
 
-	for (; u->next != v; u = u->next) assert(u->next != NULL);
+	for (; u->Next() != v; u = u->Next()) assert(u->Next() != NULL);
 
 	return u;
 }
@@ -532,7 +532,7 @@
 	/* Set the first pointer of all vehicles in that chain to the first wagon */
 	if ((v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) ||
 			(v->type == VEH_ROAD && IsRoadVehFront(v))) {
-		for (u = (Vehicle *)v; u != NULL; u = u->next) u->first = (Vehicle *)v;
+		for (u = (Vehicle *)v; u != NULL; u = u->Next()) u->first = (Vehicle *)v;
 	}
 
 	return (Vehicle*)v;
@@ -541,7 +541,7 @@
 uint CountVehiclesInChain(const Vehicle* v)
 {
 	uint count = 0;
-	do count++; while ((v = v->next) != NULL);
+	do count++; while ((v = v->Next()) != NULL);
 	return count;
 }
 
@@ -594,7 +594,7 @@
 	 *  destroy vehicle, which on his turn can remove any
 	 *  other artic parts. */
 	if ((this->type == VEH_TRAIN && EngineHasArticPart(this)) || (this->type == VEH_ROAD && RoadVehHasArticPart(this))) {
-		delete this->next;
+		delete this->Next();
 	}
 }
 
@@ -626,7 +626,7 @@
 
 	do {
 		Vehicle *u = v;
-		v = v->next;
+		v = v->Next();
 		delete u;
 	} while (v != NULL);
 }
@@ -1777,7 +1777,7 @@
 		int veh_counter = 0;
 		do {
 			veh_counter++;
-		} while ((v = v->next) != NULL);
+		} while ((v = v->Next()) != NULL);
 
 		if (!Vehicle::AllocateList(NULL, veh_counter)) {
 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
@@ -1861,7 +1861,7 @@
 				if (w->type == VEH_TRAIN && EngineHasArticPart(w)) {
 					w = GetNextArticPart(w);
 				} else if (w->type == VEH_ROAD && RoadVehHasArticPart(w)) {
-					w = w->next;
+					w = w->Next();
 				} else {
 					break;
 				}
@@ -1876,7 +1876,7 @@
 			if (v->type == VEH_TRAIN && EngineHasArticPart(v)) {
 				v = GetNextArticPart(v);
 			} else if (v->type == VEH_ROAD && RoadVehHasArticPart(v)) {
-				v = v->next;
+				v = v->Next();
 			} else {
 				break;
 			}
@@ -2153,7 +2153,7 @@
 	const Station *st = GetStation(v->last_station_visited);
 
 	/* Count up max and used */
-	for (; v != NULL; v = v->next) {
+	for (; v != NULL; v = v->Next()) {
 		count += v->cargo.Count();
 		max += v->cargo_cap;
 		if (v->cargo_cap != 0) {
--- a/src/vehicle.h	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/vehicle.h	Thu Aug 30 13:03:56 2007 +0000
@@ -222,9 +222,9 @@
 	VehicleTypeByte type;    ///< Type of vehicle
 	byte subtype;            // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
 
-	Vehicle *next;           // next
+	Vehicle *next;           // pointer to the next vehicle in the chain
 	Vehicle *first;          // NOSAVE: pointer to the first vehicle in the chain
-	Vehicle *depot_list;     //NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
+	Vehicle *depot_list;     // NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
 
 	StringID string_id;      // Displayed string
 
@@ -455,7 +455,24 @@
 	 */
 	Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
 
-	bool IsValid() const { return this->type != VEH_INVALID; }
+	/**
+	 * Is this vehicle a valid vehicle?
+	 * @return true if and only if the vehicle is valid.
+	 */
+	inline bool IsValid() const { return this->type != VEH_INVALID; }
+
+	/**
+	 * Set the next vehicle of this vehicle.
+	 * @param next the next vehicle. NULL removes the next vehicle.
+	 */
+	void SetNext(Vehicle *next) { this->next = next; }
+
+	/**
+	 * Get the next vehicle of this vehicle.
+	 * @note articulated parts are also counted as vehicles.
+	 * @return the next vehicle or NULL when there isn't a next vehicle.
+	 */
+	inline Vehicle *Next() const { return this->next; }
 };
 
 /**
@@ -632,7 +649,7 @@
 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
 
 #define BEGIN_ENUM_WAGONS(v) do {
-#define END_ENUM_WAGONS(v) } while ((v = v->next) != NULL);
+#define END_ENUM_WAGONS(v) } while ((v = v->Next()) != NULL);
 
 static inline VehicleID GetMaxVehicleIndex()
 {
--- a/src/vehicle_gui.cpp	Thu Aug 30 12:10:32 2007 +0000
+++ b/src/vehicle_gui.cpp	Thu Aug 30 13:03:56 2007 +0000
@@ -261,7 +261,7 @@
 				}
 			}
 		}
-	} while (v->type == VEH_TRAIN && (u = u->next) != NULL && num_lines < max_lines);
+	} while (v->type == VEH_TRAIN && (u = u->Next()) != NULL && num_lines < max_lines);
 
 	list->num_lines = num_lines;
 	list->items = refit;
@@ -617,8 +617,8 @@
 
 	memset(cargoa, 0, sizeof(cargoa));
 	memset(cargob, 0, sizeof(cargob));
-	for (v = va; v != NULL; v = v->next) cargoa[v->cargo_type] += v->cargo_cap;
-	for (v = vb; v != NULL; v = v->next) cargob[v->cargo_type] += v->cargo_cap;
+	for (v = va; v != NULL; v = v->Next()) cargoa[v->cargo_type] += v->cargo_cap;
+	for (v = vb; v != NULL; v = v->Next()) cargob[v->cargo_type] += v->cargo_cap;
 
 	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		r = cargoa[i] - cargob[i];
@@ -653,12 +653,12 @@
 		do {
 			if (RailVehInfo(ua->engine_type)->max_speed != 0)
 				max_speed_a = min(max_speed_a, RailVehInfo(ua->engine_type)->max_speed);
-		} while ((ua = ua->next) != NULL);
+		} while ((ua = ua->Next()) != NULL);
 
 		do {
 			if (RailVehInfo(ub->engine_type)->max_speed != 0)
 				max_speed_b = min(max_speed_b, RailVehInfo(ub->engine_type)->max_speed);
-		} while ((ub = ub->next) != NULL);
+		} while ((ub = ub->Next()) != NULL);
 
 		r = max_speed_a - max_speed_b;
 	} else {
@@ -688,8 +688,8 @@
 	const Vehicle *u;
 	Money valuea = 0, valueb = 0;
 
-	for (u = va; u != NULL; u = u->next) valuea += u->value;
-	for (u = vb; u != NULL; u = u->next) valueb += u->value;
+	for (u = va; u != NULL; u = u->Next()) valuea += u->value;
+	for (u = vb; u != NULL; u = u->Next()) valueb += u->value;
 
 	int r = ClampToI32(valuea - valueb);
 
@@ -1590,7 +1590,7 @@
 
 		if (is_localplayer) {
 			/* See if any vehicle can be refitted */
-			for (const Vehicle *u = v; u != NULL; u = u->next) {
+			for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 				if (EngInfo(u->engine_type)->refit_mask != 0 ||
 						(RailVehInfo(v->engine_type)->railveh_type != RAILVEH_WAGON && v->cargo_cap != 0)) {
 					EnableWindowWidget(w, VVW_WIDGET_REFIT_VEH);