changeset 11983:6fae1efe3ae2 draft

(svn r16389) -Codechange: use RoadVehicle instead of Vehicle where appropriate
author rubidium <rubidium@openttd.org>
date Fri, 22 May 2009 20:18:45 +0000
parents 9add5306a01e
children b6d3e583be86
files src/openttd.cpp src/order_cmd.cpp src/roadveh.h src/roadveh_cmd.cpp src/saveload/vehicle_sl.cpp src/station.cpp src/station_base.h src/station_func.h src/vehicle.cpp
diffstat 9 files changed, 68 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -30,6 +30,7 @@
 #include "fileio_func.h"
 #include "fios.h"
 #include "aircraft.h"
+#include "roadveh.h"
 #include "console_func.h"
 #include "screenshot.h"
 #include "network/network.h"
@@ -1117,8 +1118,8 @@
 
 				switch (v->type) {
 					case VEH_ROAD: {
-						extern byte GetRoadVehLength(const Vehicle *v);
-						if (GetRoadVehLength(v) != v->u.road.cached_veh_length) {
+						extern byte GetRoadVehLength(const RoadVehicle *v);
+						if (GetRoadVehLength((RoadVehicle *)v) != v->u.road.cached_veh_length) {
 							DEBUG(desync, 2, "cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
 						}
 					} break;
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -734,7 +734,7 @@
 	if (flags & DC_EXEC) {
 		v->cur_order_index = sel_ord;
 
-		if (v->type == VEH_ROAD) ClearSlot(v);
+		if (v->type == VEH_ROAD) ClearSlot((RoadVehicle *)v);
 
 		if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
 
@@ -1360,7 +1360,7 @@
 		case VEH_TRAIN:     return st->train_tile;
 		case VEH_AIRCRAFT:  return st->airport_tile;
 		case VEH_SHIP:      return st->dock_tile;
-		case VEH_ROAD:      return st->GetPrimaryRoadStop(v)->xy;
+		case VEH_ROAD:      return st->GetPrimaryRoadStop((RoadVehicle *)v)->xy;
 	}
 }
 
@@ -1739,7 +1739,7 @@
 
 		v->current_order.Free();
 		v->dest_tile = 0;
-		if (v->type == VEH_ROAD) ClearSlot(v);
+		if (v->type == VEH_ROAD) ClearSlot((RoadVehicle *)v);
 		return false;
 	}
 
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -10,6 +10,8 @@
 #include "engine_base.h"
 #include "economy_func.h"
 
+struct RoadVehicle;
+
 /** State information about the Road Vehicle controller */
 enum {
 	RDE_NEXT_TILE = 0x80, ///< We should enter the next tile
@@ -68,9 +70,9 @@
 
 void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
-byte GetRoadVehLength(const Vehicle *v);
+byte GetRoadVehLength(const RoadVehicle *v);
 
-void RoadVehUpdateCache(Vehicle *v);
+void RoadVehUpdateCache(RoadVehicle *v);
 
 
 /**
@@ -104,6 +106,9 @@
 	Trackdir GetVehicleTrackdir() const;
 	TileIndex GetOrderStationLocation(StationID station);
 	bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
+	RoadVehicle *First() { return (RoadVehicle *)this->Vehicle::First(); }
+	RoadVehicle *Next() { return (RoadVehicle *)this->Vehicle::Next(); }
+	const RoadVehicle *Next() const { return (const RoadVehicle *)this->Vehicle::Next(); }
 };
 
 #endif /* ROADVEH_H */
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -120,7 +120,7 @@
 	DrawSprite(GetRoadVehIcon(engine), pal, x, y);
 }
 
-byte GetRoadVehLength(const Vehicle *v)
+byte GetRoadVehLength(const RoadVehicle *v)
 {
 	byte length = 8;
 
@@ -132,12 +132,12 @@
 	return length;
 }
 
-void RoadVehUpdateCache(Vehicle *v)
+void RoadVehUpdateCache(RoadVehicle *v)
 {
 	assert(v->type == VEH_ROAD);
 	assert(IsRoadVehFront(v));
 
-	for (Vehicle *u = v; u != NULL; u = u->Next()) {
+	for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
 		/* Check the v->first cache. */
 		assert(u->First() == v);
 
@@ -192,7 +192,7 @@
 	if (flags & DC_EXEC) {
 		const RoadVehicleInfo *rvi = RoadVehInfo(p1);
 
-		Vehicle *v = new RoadVehicle();
+		RoadVehicle *v = new RoadVehicle();
 		v->unitnumber = unit_num;
 		v->direction = DiagDirToDir(GetRoadDepotDirection(tile));
 		v->owner = _current_company;
@@ -254,7 +254,7 @@
 		AddArticulatedParts(v, VEH_ROAD);
 
 		/* Call various callbacks after the whole consist has been constructed */
-		for (Vehicle *u = v; u != NULL; u = u->Next()) {
+		for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
 			u->u.road.cached_veh_length = GetRoadVehLength(u);
 			/* Cargo capacity is zero if and only if the vehicle cannot carry anything */
 			if (u->cargo_cap != 0) u->cargo_cap = GetVehicleProperty(u, 0x0F, u->cargo_cap);
@@ -277,7 +277,7 @@
 	return cost;
 }
 
-void ClearSlot(Vehicle *v)
+void ClearSlot(RoadVehicle *v)
 {
 	RoadStop *rs = v->u.road.slot;
 	if (v->u.road.slot == NULL) return;
@@ -298,7 +298,7 @@
 	if (!IsRoadDepotTile(tile)) return false;
 	if (IsRoadVehFront(this) && !(this->vehstatus & VS_STOPPED)) return false;
 
-	for (const Vehicle *v = this; v != NULL; v = v->Next()) {
+	for (const RoadVehicle *v = this; v != NULL; v = v->Next()) {
 		if (v->u.road.state != RVSB_IN_DEPOT || v->tile != tile) return false;
 	}
 	return true;
@@ -356,7 +356,7 @@
 	return false;
 }
 
-static const Depot *FindClosestRoadDepot(const Vehicle *v)
+static const Depot *FindClosestRoadDepot(const RoadVehicle *v)
 {
 	switch (_settings_game.pf.pathfinder_for_roadvehs) {
 		case VPF_YAPF: // YAPF
@@ -486,7 +486,7 @@
 	this->z_extent      = 6;
 }
 
-static void ClearCrashedStation(Vehicle *v)
+static void ClearCrashedStation(RoadVehicle *v)
 {
 	RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
 
@@ -497,7 +497,7 @@
 	rs->FreeBay(HasBit(v->u.road.state, RVS_USING_SECOND_BAY));
 }
 
-static void DeleteLastRoadVeh(Vehicle *v)
+static void DeleteLastRoadVeh(RoadVehicle *v)
 {
 	Vehicle *u = v;
 	for (; v->Next() != NULL; v = v->Next()) u = v;
@@ -508,7 +508,7 @@
 	delete v;
 }
 
-static byte SetRoadVehPosition(Vehicle *v, int x, int y)
+static byte SetRoadVehPosition(RoadVehicle *v, int x, int y)
 {
 	byte new_z, old_z;
 
@@ -524,7 +524,7 @@
 	return old_z;
 }
 
-static void RoadVehSetRandomDirection(Vehicle *v)
+static void RoadVehSetRandomDirection(RoadVehicle *v)
 {
 	static const DirDiff delta[] = {
 		DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT
@@ -540,7 +540,7 @@
 	} while ((v = v->Next()) != NULL);
 }
 
-static bool RoadVehIsCrashed(Vehicle *v)
+static bool RoadVehIsCrashed(RoadVehicle *v)
 {
 	v->u.road.crashed_ctr++;
 	if (v->u.road.crashed_ctr == 2) {
@@ -568,7 +568,7 @@
 			v : NULL;
 }
 
-static void RoadVehCrash(Vehicle *v)
+static void RoadVehCrash(RoadVehicle *v)
 {
 	uint16 pass = 1;
 
@@ -601,9 +601,9 @@
 	SndPlayVehicleFx(SND_12_EXPLOSION, v);
 }
 
-static bool RoadVehCheckTrainCrash(Vehicle *v)
+static bool RoadVehCheckTrainCrash(RoadVehicle *v)
 {
-	for (Vehicle *u = v; u != NULL; u = u->Next()) {
+	for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
 		if (u->u.road.state == RVSB_WORMHOLE) continue;
 
 		TileIndex tile = u->tile;
@@ -619,7 +619,7 @@
 	return false;
 }
 
-static void HandleBrokenRoadVeh(Vehicle *v)
+static void HandleBrokenRoadVeh(RoadVehicle *v)
 {
 	if (v->breakdown_ctr != 1) {
 		v->breakdown_ctr = 1;
@@ -678,7 +678,7 @@
 	}
 }
 
-static void StartRoadVehSound(const Vehicle *v)
+static void StartRoadVehSound(const RoadVehicle *v)
 {
 	if (!PlayVehicleSound(v, VSE_START)) {
 		SoundID s = RoadVehInfo(v->engine_type)->sfx;
@@ -727,10 +727,10 @@
 	return NULL;
 }
 
-static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, Direction dir)
+static RoadVehicle *RoadVehFindCloseTo(RoadVehicle *v, int x, int y, Direction dir)
 {
 	RoadVehFindData rvf;
-	Vehicle *front = v->First();
+	RoadVehicle *front = v->First();
 
 	if (front->u.road.reverse_ctr != 0) return NULL;
 
@@ -758,10 +758,10 @@
 
 	if (++front->u.road.blocked_ctr > 1480) return NULL;
 
-	return rvf.best;
+	return (RoadVehicle *)rvf.best;
 }
 
-static void RoadVehArrivesAt(const Vehicle *v, Station *st)
+static void RoadVehArrivesAt(const RoadVehicle *v, Station *st)
 {
 	if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
 		/* Check if station was ever visited before */
@@ -792,7 +792,7 @@
 	}
 }
 
-static int RoadVehAccelerate(Vehicle *v)
+static int RoadVehAccelerate(RoadVehicle *v)
 {
 	uint oldspeed = v->cur_speed;
 	uint accel = 256 + (v->u.road.overtaking != 0 ? 256 : 0);
@@ -827,7 +827,7 @@
 	return scaled_spd;
 }
 
-static Direction RoadVehGetNewDirection(const Vehicle *v, int x, int y)
+static Direction RoadVehGetNewDirection(const RoadVehicle *v, int x, int y)
 {
 	static const Direction _roadveh_new_dir[] = {
 		DIR_N , DIR_NW, DIR_W , INVALID_DIR,
@@ -842,7 +842,7 @@
 	return _roadveh_new_dir[y * 4 + x];
 }
 
-static Direction RoadVehGetSlidingDirection(const Vehicle *v, int x, int y)
+static Direction RoadVehGetSlidingDirection(const RoadVehicle *v, int x, int y)
 {
 	Direction new_dir = RoadVehGetNewDirection(v, x, y);
 	Direction old_dir = v->direction;
@@ -854,8 +854,8 @@
 }
 
 struct OvertakeData {
-	const Vehicle *u;
-	const Vehicle *v;
+	const RoadVehicle *u;
+	const RoadVehicle *v;
 	TileIndex tile;
 	Trackdir trackdir;
 };
@@ -889,7 +889,7 @@
 	return HasVehicleOnPos(od->tile, od, EnumFindVehBlockingOvertake);
 }
 
-static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
+static void RoadVehCheckOvertake(RoadVehicle *v, RoadVehicle *u)
 {
 	OvertakeData od;
 
@@ -941,7 +941,7 @@
 	}
 }
 
-static void RoadZPosAffectSpeed(Vehicle *v, byte old_z)
+static void RoadZPosAffectSpeed(RoadVehicle *v, byte old_z)
 {
 	if (old_z == v->z_pos) return;
 
@@ -1000,7 +1000,7 @@
  * @param enterdir the direction the vehicle enters the tile from
  * @return the Trackdir to take
  */
-static Trackdir RoadFindPathToDest(Vehicle *v, TileIndex tile, DiagDirection enterdir)
+static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection enterdir)
 {
 #define return_track(x) { best_track = (Trackdir)x; goto found_best_track; }
 
@@ -1166,7 +1166,7 @@
 	return best_track;
 }
 
-static uint RoadFindPathToStop(const Vehicle *v, TileIndex tile)
+static uint RoadFindPathToStop(const RoadVehicle *v, TileIndex tile)
 {
 	if (_settings_game.pf.pathfinder_for_roadvehs == VPF_YAPF) {
 		/* use YAPF */
@@ -1201,10 +1201,10 @@
 	15, 15, 11, 11
 };
 
-static bool RoadVehLeaveDepot(Vehicle *v, bool first)
+static bool RoadVehLeaveDepot(RoadVehicle *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 RoadVehicle *u = v; u != NULL; u = u->Next()) {
 		if (u->u.road.state != RVSB_IN_DEPOT || u->tile != v->tile) return false;
 	}
 
@@ -1240,7 +1240,7 @@
 	return true;
 }
 
-static Trackdir FollowPreviousRoadVehicle(const Vehicle *v, const Vehicle *prev, TileIndex tile, DiagDirection entry_dir, bool already_reversed)
+static Trackdir FollowPreviousRoadVehicle(const RoadVehicle *v, const RoadVehicle *prev, TileIndex tile, DiagDirection entry_dir, bool already_reversed)
 {
 	if (prev->tile == v->tile && !already_reversed) {
 		/* If the previous vehicle is on the same tile as this vehicle is
@@ -1325,7 +1325,7 @@
 	return CmdSucceeded(ret);
 }
 
-static bool IndividualRoadVehicleController(Vehicle *v, const Vehicle *prev)
+static bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
 {
 	if (v->u.road.overtaking != 0)  {
 		if (IsTileType(v->tile, MP_STATION)) {
@@ -1594,7 +1594,7 @@
 	if (IsRoadVehFront(v) && !IsInsideMM(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) {
 		/* Vehicle is not in a road stop.
 		 * Check for another vehicle to overtake */
-		Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
+		RoadVehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
 
 		if (u != NULL) {
 			u = u->First();
@@ -1739,7 +1739,7 @@
 	return true;
 }
 
-static bool RoadVehController(Vehicle *v)
+static bool RoadVehController(RoadVehicle *v)
 {
 	/* decrease counters */
 	v->tick_counter++;
@@ -1778,8 +1778,8 @@
 	while (j >= adv_spd) {
 		j -= adv_spd;
 
-		Vehicle *u = v;
-		for (Vehicle *prev = NULL; u != NULL; prev = u, u = u->Next()) {
+		RoadVehicle *u = v;
+		for (RoadVehicle *prev = NULL; u != NULL; prev = u, u = u->Next()) {
 			if (!IndividualRoadVehicleController(u, prev)) break;
 		}
 
@@ -1790,7 +1790,7 @@
 		if (j >= adv_spd && RoadVehCheckTrainCrash(v)) break;
 	}
 
-	for (Vehicle *u = v; u != NULL; u = u->Next()) {
+	for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
 		if ((u->vehstatus & VS_HIDDEN) != 0) continue;
 
 		uint16 old_image = u->cur_image;
@@ -1803,7 +1803,7 @@
 	return true;
 }
 
-static void AgeRoadVehCargo(Vehicle *v)
+static void AgeRoadVehCargo(RoadVehicle *v)
 {
 	if (_age_cargo_skip_counter != 0) return;
 	v->cargo.AgeCargo();
@@ -1821,7 +1821,7 @@
 	return true;
 }
 
-static void CheckIfRoadVehNeedsService(Vehicle *v)
+static void CheckIfRoadVehNeedsService(RoadVehicle *v)
 {
 	/* If we already got a slot at a stop, use that FIRST, and go to a depot later */
 	if (v->u.road.slot != NULL || _settings_game.vehicle.servint_roadveh == 0 || !v->NeedsAutomaticServicing()) return;
@@ -2064,7 +2064,7 @@
 		}
 	}
 
-	if (flags & DC_EXEC) RoadVehUpdateCache(Vehicle::Get(p1)->First());
+	if (flags & DC_EXEC) RoadVehUpdateCache((RoadVehicle *)Vehicle::Get(p1)->First());
 
 	_returned_refit_capacity = total_capacity;
 
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -321,7 +321,7 @@
 			if (IsFrontEngine(v)) v->u.rail.last_speed = v->cur_speed; // update displayed train speed
 			TrainConsistChanged(v, false);
 		} else if (v->type == VEH_ROAD && IsRoadVehFront(v)) {
-			RoadVehUpdateCache(v);
+			RoadVehUpdateCache((RoadVehicle *)v);
 		}
 	}
 
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -108,7 +108,7 @@
  * @param v the vehicle to get the first road stop for
  * @return the first roadstop that this vehicle can load at
  */
-RoadStop *Station::GetPrimaryRoadStop(const Vehicle *v) const
+RoadStop *Station::GetPrimaryRoadStop(const RoadVehicle *v) const
 {
 	RoadStop *rs = this->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK);
 
@@ -459,7 +459,10 @@
 		Vehicle *v;
 
 		FOR_ALL_VEHICLES(v) {
-			if (v->type == VEH_ROAD && v->u.road.slot == this) ClearSlot(v);
+			if (v->type != VEH_ROAD) continue;
+			RoadVehicle *rv = (RoadVehicle *)v;
+
+			if (rv->u.road.slot == this) ClearSlot(rv);
 		}
 	}
 	assert(num_vehicles == 0);
@@ -535,7 +538,7 @@
  * @param v the vehicle to get the next road stop for.
  * @return the next road stop accessible.
  */
-RoadStop *RoadStop::GetNextRoadStop(const Vehicle *v) const
+RoadStop *RoadStop::GetNextRoadStop(const RoadVehicle *v) const
 {
 	for (RoadStop *rs = this->next; rs != NULL; rs = rs->next) {
 		/* The vehicle cannot go to this roadstop (different roadtype) */
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -73,7 +73,7 @@
 	bool IsEntranceBusy() const;
 	void SetEntranceBusy(bool busy);
 
-	RoadStop *GetNextRoadStop(const Vehicle *v) const;
+	RoadStop *GetNextRoadStop(const struct RoadVehicle *v) const;
 };
 
 struct StationSpecList {
@@ -113,7 +113,7 @@
 		return type == ROADSTOP_BUS ? bus_stops : truck_stops;
 	}
 
-	RoadStop *GetPrimaryRoadStop(const Vehicle *v) const;
+	RoadStop *GetPrimaryRoadStop(const struct RoadVehicle *v) const;
 
 	const AirportFTAClass *Airport() const
 	{
--- a/src/station_func.h
+++ b/src/station_func.h
@@ -34,7 +34,7 @@
 uint GetNumRoadStops(const Station *st, RoadStopType type);
 RoadStop * AllocateRoadStop();
 
-void ClearSlot(Vehicle *v);
+void ClearSlot(struct RoadVehicle *v);
 
 void DeleteOilRig(TileIndex t);
 
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -524,7 +524,7 @@
 		if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id);
 	}
 
-	if (this->type == VEH_ROAD) ClearSlot(this);
+	if (this->type == VEH_ROAD) ClearSlot((RoadVehicle *)this);
 	if (this->type == VEH_AIRCRAFT && this->IsPrimaryVehicle()) {
 		Aircraft *a = (Aircraft *)this;
 		Station *st = GetTargetAirportIfValid(a);
@@ -1742,7 +1742,7 @@
  */
 bool CanVehicleUseStation(const Vehicle *v, const Station *st)
 {
-	if (v->type == VEH_ROAD) return st->GetPrimaryRoadStop(v) != NULL;
+	if (v->type == VEH_ROAD) return st->GetPrimaryRoadStop((RoadVehicle *)v) != NULL;
 
 	return CanVehicleUseStation(v->engine_type, st);
 }