Changeset - r17113:503067d0eb7e
[Not reviewed]
master
0 8 0
terkhen - 14 years ago 2011-01-19 18:44:13
terkhen@openttd.org
(svn r21860) -Codechange: Rename road vehicle subtype functions to match the train names.
8 files changed with 29 insertions and 29 deletions:
0 comments (0 inline, 0 general)
src/disaster_cmd.cpp
Show inline comments
 
@@ -304,25 +304,25 @@ static bool DisasterTick_Ufo(DisasterVeh
 
			return true;
 
		}
 
		v->current_order.SetDestination(1);
 

	
 
		RoadVehicle *u;
 
		FOR_ALL_ROADVEHICLES(u) {
 
			if (u->IsRoadVehFront()) {
 
			if (u->IsFrontEngine()) {
 
				v->dest_tile = u->index;
 
				v->age = 0;
 
				return true;
 
			}
 
		}
 

	
 
		delete v;
 
		return false;
 
	} else {
 
		/* Target a vehicle */
 
		RoadVehicle *u = RoadVehicle::Get(v->dest_tile);
 
		assert(u != NULL && u->type == VEH_ROAD && u->IsRoadVehFront());
 
		assert(u != NULL && u->type == VEH_ROAD && u->IsFrontEngine());
 

	
 
		uint dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos);
 

	
 
		if (dist < TILE_SIZE && !(u->vehstatus & VS_HIDDEN) && u->breakdown_ctr == 0) {
 
			u->breakdown_ctr = 3;
 
			u->breakdown_delay = 140;
src/roadveh.h
Show inline comments
 
@@ -106,13 +106,13 @@ struct RoadVehicle : public GroundVehicl
 
	friend struct GroundVehicle<RoadVehicle, VEH_ROAD>; // GroundVehicle needs to use the acceleration functions defined at RoadVehicle.
 

	
 
	const char *GetTypeString() const { return "road vehicle"; }
 
	void MarkDirty();
 
	void UpdateDeltaXY(Direction direction);
 
	ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
 
	bool IsPrimaryVehicle() const { return this->IsRoadVehFront(); }
 
	bool IsPrimaryVehicle() const { return this->IsFrontEngine(); }
 
	SpriteID GetImage(Direction direction) const;
 
	int GetDisplaySpeed() const { return this->cur_speed / 2; }
 
	int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed / 2; }
 
	Money GetRunningCost() const;
 
	int GetDisplayImageWidth(Point *offset = NULL) const;
 
	bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
 
@@ -129,18 +129,18 @@ struct RoadVehicle : public GroundVehicl
 
	int GetCurrentMaxSpeed() const;
 

	
 
	/**
 
	 * Check if vehicle is a front engine
 
	 * @return Returns true if vehicle is a front engine
 
	 */
 
	FORCEINLINE bool IsRoadVehFront() const { return this->subtype == RVST_FRONT; }
 
	FORCEINLINE bool IsFrontEngine() const { return this->subtype == RVST_FRONT; }
 

	
 
	/**
 
	 * Set front engine state
 
	 */
 
	FORCEINLINE void SetRoadVehFront() { this->subtype = RVST_FRONT; }
 
	FORCEINLINE void SetFrontEngine() { this->subtype = RVST_FRONT; }
 

	
 
	/**
 
	 * Check if vehicl is an articulated part of an engine
 
	 * @return Returns true if vehicle is an articulated part
 
	 */
 
	FORCEINLINE bool IsArticulatedPart() const { return this->subtype == RVST_ARTIC_PART; }
src/roadveh_cmd.cpp
Show inline comments
 
@@ -82,13 +82,13 @@ static const Trackdir _roadveh_depot_exi
 
/**
 
 * Check whether a roadvehicle is a bus
 
 * @return true if bus
 
 */
 
bool RoadVehicle::IsBus() const
 
{
 
	assert(this->IsRoadVehFront());
 
	assert(this->IsFrontEngine());
 
	return IsCargoInClass(this->cargo_type, CC_PASSENGERS);
 
}
 

	
 
/**
 
 * Get the width of a road vehicle image in the GUI.
 
 * @param offset Additional offset for positioning the sprite; set to NULL if not needed
 
@@ -168,13 +168,13 @@ static uint GetRoadVehLength(const RoadV
 
	return length;
 
}
 

	
 
void RoadVehUpdateCache(RoadVehicle *v)
 
{
 
	assert(v->type == VEH_ROAD);
 
	assert(v->IsRoadVehFront());
 
	assert(v->IsFrontEngine());
 

	
 
	v->InvalidateNewGRFCacheOfChain();
 

	
 
	v->gcache.cached_total_length = 0;
 

	
 
	for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
 
@@ -247,13 +247,13 @@ CommandCost CmdBuildRoadVehicle(TileInde
 

	
 
		v->date_of_last_service = _date;
 
		v->build_year = _cur_year;
 

	
 
		v->cur_image = SPR_IMG_QUERY;
 
		v->random_bits = VehicleRandomBits();
 
		v->SetRoadVehFront();
 
		v->SetFrontEngine();
 

	
 
		v->roadtype = HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
 
		v->compatible_roadtypes = RoadTypeToRoadTypes(v->roadtype);
 
		v->gcache.cached_veh_length = 8;
 

	
 
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
 
@@ -281,13 +281,13 @@ CommandCost CmdBuildRoadVehicle(TileInde
 

	
 
bool RoadVehicle::IsStoppedInDepot() const
 
{
 
	TileIndex tile = this->tile;
 

	
 
	if (!IsRoadDepotTile(tile)) return false;
 
	if (this->IsRoadVehFront() && !(this->vehstatus & VS_STOPPED)) return false;
 
	if (this->IsFrontEngine() && !(this->vehstatus & VS_STOPPED)) return false;
 

	
 
	for (const RoadVehicle *v = this; v != NULL; v = v->Next()) {
 
		if (v->state != RVSB_IN_DEPOT || v->tile != tile) return false;
 
	}
 
	return true;
 
}
 
@@ -458,13 +458,13 @@ static Vehicle *EnumCheckRoadVehCrashTra
 
			abs(v->y_pos - u->y_pos) <= 4) ? v : NULL;
 
}
 

	
 
uint RoadVehicle::Crash(bool flooded)
 
{
 
	uint pass = Vehicle::Crash(flooded);
 
	if (this->IsRoadVehFront()) {
 
	if (this->IsFrontEngine()) {
 
		pass += 1; // driver
 

	
 
		/* If we're in a drive through road stop we ought to leave it */
 
		if (IsInsideMM(this->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END)) {
 
			RoadStop::GetByTile(this->tile, GetRoadStopType(this->tile))->Leave(this);
 
		}
 
@@ -1077,13 +1077,13 @@ static bool IndividualRoadVehicleControl
 
	if (v->IsInDepot()) return true;
 

	
 
	if (v->state == RVSB_WORMHOLE) {
 
		/* Vehicle is entering a depot or is on a bridge or in a tunnel */
 
		GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 

	
 
		if (v->IsRoadVehFront()) {
 
		if (v->IsFrontEngine()) {
 
			const Vehicle *u = RoadVehFindCloseTo(v, gp.x, gp.y, v->direction);
 
			if (u != NULL) {
 
				v->cur_speed = u->First()->cur_speed;
 
				return false;
 
			}
 
		}
 
@@ -1110,21 +1110,21 @@ static bool IndividualRoadVehicleControl
 
		(_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)) ^ v->overtaking][v->frame + 1];
 

	
 
	if (rd.x & RDE_NEXT_TILE) {
 
		TileIndex tile = v->tile + TileOffsByDiagDir((DiagDirection)(rd.x & 3));
 
		Trackdir dir;
 

	
 
		if (v->IsRoadVehFront()) {
 
		if (v->IsFrontEngine()) {
 
			/* If this is the front engine, look for the right path. */
 
			dir = RoadFindPathToDest(v, tile, (DiagDirection)(rd.x & 3));
 
		} else {
 
			dir = FollowPreviousRoadVehicle(v, prev, tile, (DiagDirection)(rd.x & 3), false);
 
		}
 

	
 
		if (dir == INVALID_TRACKDIR) {
 
			if (!v->IsRoadVehFront()) error("Disconnecting road vehicle.");
 
			if (!v->IsFrontEngine()) error("Disconnecting road vehicle.");
 
			v->cur_speed = 0;
 
			return false;
 
		}
 

	
 
again:
 
		uint start_frame = RVC_DEFAULT_START_FRAME;
 
@@ -1139,25 +1139,25 @@ again:
 
					case TRACKDIR_RVREV_NE: needed = ROAD_SW; break;
 
					case TRACKDIR_RVREV_SE: needed = ROAD_NW; break;
 
					case TRACKDIR_RVREV_SW: needed = ROAD_NE; break;
 
					case TRACKDIR_RVREV_NW: needed = ROAD_SE; break;
 
				}
 
				if ((v->Previous() != NULL && v->Previous()->tile == tile) ||
 
						(v->IsRoadVehFront() && IsNormalRoadTile(tile) && !HasRoadWorks(tile) &&
 
						(v->IsFrontEngine() && IsNormalRoadTile(tile) && !HasRoadWorks(tile) &&
 
							(needed & GetRoadBits(tile, ROADTYPE_TRAM)) != ROAD_NONE)) {
 
					/*
 
					 * Taking the 'big' corner for trams only happens when:
 
					 * - The previous vehicle in this (articulated) tram chain is
 
					 *   already on the 'next' tile, we just follow them regardless of
 
					 *   anything. When it is NOT on the 'next' tile, the tram started
 
					 *   doing a reversing turn when the piece of tram track on the next
 
					 *   tile did not exist yet. Do not use the big tram loop as that is
 
					 *   going to cause the tram to split up.
 
					 * - Or the front of the tram can drive over the next tile.
 
					 */
 
				} else if (!v->IsRoadVehFront() || !CanBuildTramTrackOnTile(v->owner, tile, needed) || ((~needed & GetAnyRoadBits(v->tile, ROADTYPE_TRAM, false)) == ROAD_NONE)) {
 
				} else if (!v->IsFrontEngine() || !CanBuildTramTrackOnTile(v->owner, tile, needed) || ((~needed & GetAnyRoadBits(v->tile, ROADTYPE_TRAM, false)) == ROAD_NONE)) {
 
					/*
 
					 * Taking the 'small' corner for trams only happens when:
 
					 * - We are not the from vehicle of an articulated tram.
 
					 * - Or when the company cannot build on the next tile.
 
					 *
 
					 * The 'small' corner means that the vehicle is on the end of a
 
@@ -1185,13 +1185,13 @@ again:
 
		const RoadDriveEntry *rdp = _road_drive_data[v->roadtype][(dir + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)) ^ v->overtaking];
 

	
 
		int x = TileX(tile) * TILE_SIZE + rdp[start_frame].x;
 
		int y = TileY(tile) * TILE_SIZE + rdp[start_frame].y;
 

	
 
		Direction new_dir = RoadVehGetSlidingDirection(v, x, y);
 
		if (v->IsRoadVehFront()) {
 
		if (v->IsFrontEngine()) {
 
			Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
 
			if (u != NULL) {
 
				v->cur_speed = u->First()->cur_speed;
 
				return false;
 
			}
 
		}
 
@@ -1269,13 +1269,13 @@ again:
 
				case DIAGDIR_NW: dir = TRACKDIR_RVREV_SE; break;
 
				case DIAGDIR_NE: dir = TRACKDIR_RVREV_SW; break;
 
				case DIAGDIR_SE: dir = TRACKDIR_RVREV_NW; break;
 
				case DIAGDIR_SW: dir = TRACKDIR_RVREV_NE; break;
 
			}
 
		} else {
 
			if (v->IsRoadVehFront()) {
 
			if (v->IsFrontEngine()) {
 
				/* If this is the front engine, look for the right path. */
 
				dir = RoadFindPathToDest(v, v->tile, (DiagDirection)(rd.x & 3));
 
			} else {
 
				dir = FollowPreviousRoadVehicle(v, prev, v->tile, (DiagDirection)(rd.x & 3), true);
 
			}
 
		}
 
@@ -1288,13 +1288,13 @@ again:
 
		const RoadDriveEntry *rdp = _road_drive_data[v->roadtype][(_settings_game.vehicle.road_side << RVS_DRIVE_SIDE) + dir];
 

	
 
		int x = TileX(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].x;
 
		int y = TileY(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].y;
 

	
 
		Direction new_dir = RoadVehGetSlidingDirection(v, x, y);
 
		if (v->IsRoadVehFront() && RoadVehFindCloseTo(v, x, y, new_dir) != NULL) return false;
 
		if (v->IsFrontEngine() && RoadVehFindCloseTo(v, x, y, new_dir) != NULL) return false;
 

	
 
		uint32 r = VehicleEnterTile(v, v->tile, x, y);
 
		if (HasBit(r, VETS_CANNOT_ENTER)) {
 
			v->cur_speed = 0;
 
			return false;
 
		}
 
@@ -1325,13 +1325,13 @@ again:
 
	/* Calculate new position for the vehicle */
 
	int x = (v->x_pos & ~15) + (rd.x & 15);
 
	int y = (v->y_pos & ~15) + (rd.y & 15);
 

	
 
	Direction new_dir = RoadVehGetSlidingDirection(v, x, y);
 

	
 
	if (v->IsRoadVehFront() && !IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) {
 
	if (v->IsFrontEngine() && !IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) {
 
		/* Vehicle is not in a road stop.
 
		 * Check for another vehicle to overtake */
 
		RoadVehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
 

	
 
		if (u != NULL) {
 
			u = u->First();
 
@@ -1369,13 +1369,13 @@ again:
 

	
 
	/* If the vehicle is in a normal road stop and the frame equals the stop frame OR
 
	 * if the vehicle is in a drive-through road stop and this is the destination station
 
	 * and it's the correct type of stop (bus or truck) and the frame equals the stop frame...
 
	 * (the station test and stop type test ensure that other vehicles, using the road stop as
 
	 * a through route, do not stop) */
 
	if (v->IsRoadVehFront() && ((IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) &&
 
	if (v->IsFrontEngine() && ((IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) &&
 
			_road_stop_stop_frame[v->state - RVSB_IN_ROAD_STOP + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)] == v->frame) ||
 
			(IsInsideMM(v->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) &&
 
			v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile)) &&
 
			v->owner == GetTileOwner(v->tile) &&
 
			GetRoadStopType(v->tile) == (v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
 
			v->frame == RVC_DRIVE_THROUGH_STOP_FRAME))) {
 
@@ -1522,13 +1522,13 @@ Money RoadVehicle::GetRunningCost() cons
 

	
 
	return GetPrice(e->u.road.running_cost_class, cost_factor, e->grf_prop.grffile);
 
}
 

	
 
bool RoadVehicle::Tick()
 
{
 
	if (this->IsRoadVehFront()) {
 
	if (this->IsFrontEngine()) {
 
		if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
 
		return RoadVehController(this);
 
	}
 

	
 
	return true;
 
}
 
@@ -1574,13 +1574,13 @@ static void CheckIfRoadVehNeedsService(R
 
	v->dest_tile = rfdd.tile;
 
	SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
}
 

	
 
void RoadVehicle::OnNewDay()
 
{
 
	if (!this->IsRoadVehFront()) return;
 
	if (!this->IsFrontEngine()) return;
 

	
 
	if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
 
	if (this->blocked_ctr == 0) CheckVehicleBreakdown(this);
 

	
 
	AgeVehicle(this);
 
	CheckIfRoadVehNeedsService(this);
src/saveload/afterload.cpp
Show inline comments
 
@@ -1963,13 +1963,13 @@ bool AfterLoadGame()
 
	if (IsSavegameVersionBefore(121)) {
 
		/* Delete small ufos heading for non-existing vehicles */
 
		Vehicle *v;
 
		FOR_ALL_DISASTERVEHICLES(v) {
 
			if (v->subtype == 2/*ST_SMALL_UFO*/ && v->current_order.GetDestination() != 0) {
 
				const Vehicle *u = Vehicle::GetIfValid(v->dest_tile);
 
				if (u == NULL || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsRoadVehFront()) {
 
				if (u == NULL || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) {
 
					delete v;
 
				}
 
			}
 
		}
 

	
 
		/* We didn't store cargo payment yet, so make them for vehicles that are
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -322,13 +322,13 @@ void AfterLoadVehicles(bool part_of_load
 
				}
 
				break;
 
			}
 

	
 
			case VEH_ROAD: {
 
				RoadVehicle *rv = RoadVehicle::From(v);
 
				if (rv->IsRoadVehFront()) {
 
				if (rv->IsFrontEngine()) {
 
					RoadVehUpdateCache(rv);
 
					if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
 
						rv->CargoChanged();
 
					}
 
				}
 
				break;
src/settings.cpp
Show inline comments
 
@@ -840,13 +840,13 @@ static bool TrainSlopeSteepnessChanged(i
 
 */
 
static bool RoadVehAccelerationModelChanged(int32 p1)
 
{
 
	if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
 
		RoadVehicle *rv;
 
		FOR_ALL_ROADVEHICLES(rv) {
 
			if (rv->IsRoadVehFront()) {
 
			if (rv->IsFrontEngine()) {
 
				rv->CargoChanged();
 
			}
 
		}
 
	}
 

	
 
	/* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
 
@@ -863,13 +863,13 @@ static bool RoadVehAccelerationModelChan
 
 * @return Always true.
 
 */
 
static bool RoadVehSlopeSteepnessChanged(int32 p1)
 
{
 
	RoadVehicle *rv;
 
	FOR_ALL_ROADVEHICLES(rv) {
 
		if (rv->IsRoadVehFront()) rv->CargoChanged();
 
		if (rv->IsFrontEngine()) rv->CargoChanged();
 
	}
 

	
 
	return true;
 
}
 

	
 
static bool DragSignalsDensityChanged(int32)
src/station_cmd.cpp
Show inline comments
 
@@ -2984,13 +2984,13 @@ static VehicleEnterTileStatus VehicleEnt
 
				if (spd < v->cur_speed) v->cur_speed = spd;
 
			}
 
		}
 
	} else if (v->type == VEH_ROAD) {
 
		RoadVehicle *rv = RoadVehicle::From(v);
 
		if (rv->state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)rv->state) && rv->frame == 0) {
 
			if (IsRoadStop(tile) && rv->IsRoadVehFront()) {
 
			if (IsRoadStop(tile) && rv->IsFrontEngine()) {
 
				/* Attempt to allocate a parking bay in a road stop */
 
				return RoadStop::GetByTile(tile, GetRoadStopType(tile))->Enter(rv) ? VETSB_CONTINUE : VETSB_CANNOT_ENTER;
 
			}
 
		}
 
	}
 

	
src/vehicle.cpp
Show inline comments
 
@@ -626,13 +626,13 @@ bool Vehicle::IsEngineCountable() const
 
{
 
	switch (this->type) {
 
		case VEH_AIRCRAFT: return Aircraft::From(this)->IsNormalAircraft(); // don't count plane shadows and helicopter rotors
 
		case VEH_TRAIN:
 
			return !Train::From(this)->IsArticulatedPart() && // tenders and other articulated parts
 
					!Train::From(this)->IsRearDualheaded(); // rear parts of multiheaded engines
 
		case VEH_ROAD: return RoadVehicle::From(this)->IsRoadVehFront();
 
		case VEH_ROAD: return RoadVehicle::From(this)->IsFrontEngine();
 
		case VEH_SHIP: return true;
 
		default: return false; // Only count company buildable vehicles
 
	}
 
}
 

	
 
/**
 
@@ -827,13 +827,13 @@ void CallVehicleTicks()
 
			case VEH_AIRCRAFT:
 
			case VEH_SHIP:
 
				if (_age_cargo_skip_counter == 0) v->cargo.AgeCargo();
 

	
 
				if (v->type == VEH_TRAIN && Train::From(v)->IsWagon()) continue;
 
				if (v->type == VEH_AIRCRAFT && v->subtype != AIR_HELICOPTER) continue;
 
				if (v->type == VEH_ROAD && !RoadVehicle::From(v)->IsRoadVehFront()) continue;
 
				if (v->type == VEH_ROAD && !RoadVehicle::From(v)->IsFrontEngine()) continue;
 

	
 
				v->motion_counter += v->cur_speed;
 
				/* Play a running sound if the motion counter passes 256 (Do we not skip sounds?) */
 
				if (GB(v->motion_counter, 0, 8) < v->cur_speed) PlayVehicleSound(v, VSE_RUNNING);
 

	
 
				/* Play an alterate running sound every 16 ticks */
0 comments (0 inline, 0 general)