Changeset - r14746:8e3f2ad7663e
[Not reviewed]
master
0 2 0
terkhen - 15 years ago 2010-03-06 12:55:56
terkhen@openttd.org
(svn r19344) -Codechange: RoadVehicle uses UpdateInclination instead of its own function.
2 files changed with 24 insertions and 30 deletions:
0 comments (0 inline, 0 general)
src/roadveh.h
Show inline comments
 
@@ -278,16 +278,16 @@ protected: // These functions should not
 
	/**
 
	 * Checks if the vehicle is at a tile that can be sloped.
 
	 * @return True if the tile can be sloped.
 
	 */
 
	FORCEINLINE bool TileMayHaveSlopedTrack() const
 
	{
 
		if (!IsNormalRoadTile(this->tile)) return false;
 
		RoadBits cur_road = GetAllRoadBits(this->tile);
 
		/* Any road that isn't ROAD_X or ROAD_Y cannot be sloped. */
 
		return cur_road == ROAD_X || cur_road == ROAD_Y;
 
		TrackStatus ts = GetTileTrackStatus(this->tile, TRANSPORT_ROAD, this->compatible_roadtypes);
 
		TrackBits trackbits = TrackStatusToTrackBits(ts);
 

	
 
		return trackbits == TRACK_BIT_X || trackbits == TRACK_BIT_Y;
 
	}
 
};
 

	
 
#define FOR_ALL_ROADVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(RoadVehicle, var)
 

	
 
#endif /* ROADVEH_H */
src/roadveh_cmd.cpp
Show inline comments
 
@@ -465,39 +465,23 @@ static void DeleteLastRoadVeh(RoadVehicl
 
	/* Only leave the road stop when we're really gone. */
 
	if (IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile))->Leave(v);
 

	
 
	delete v;
 
}
 

	
 
static byte SetRoadVehPosition(RoadVehicle *v, int x, int y, bool turned)
 
{
 
	byte new_z, old_z;
 

	
 
	/* need this hint so it returns the right z coordinate on bridges. */
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	new_z = GetSlopeZ(x, y);
 

	
 
	old_z = v->z_pos;
 
	v->z_pos = new_z;
 

	
 
	v->UpdateViewport(true, turned);
 
	return old_z;
 
}
 

	
 
static void RoadVehSetRandomDirection(RoadVehicle *v)
 
{
 
	static const DirDiff delta[] = {
 
		DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT
 
	};
 

	
 
	do {
 
		uint32 r = Random();
 

	
 
		v->direction = ChangeDir(v->direction, delta[r & 3]);
 
		SetRoadVehPosition(v, v->x_pos, v->y_pos, true);
 
		v->UpdateInclination(false, true);
 
	} while ((v = v->Next()) != NULL);
 
}
 

	
 
static bool RoadVehIsCrashed(RoadVehicle *v)
 
{
 
	v->crashed_ctr++;
 
@@ -1051,13 +1035,15 @@ static bool RoadVehLeaveDepot(RoadVehicl
 
	}
 

	
 
	v->vehstatus &= ~VS_HIDDEN;
 
	v->state = tdir;
 
	v->frame = RVC_DEPOT_START_FRAME;
 

	
 
	SetRoadVehPosition(v, x, y, true);
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	v->UpdateInclination(true, true);
 

	
 
	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 

	
 
	return true;
 
}
 

	
 
@@ -1178,13 +1164,15 @@ static bool IndividualRoadVehicleControl
 
				return false;
 
			}
 
		}
 

	
 
		if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
 
			/* Vehicle has just entered a bridge or tunnel */
 
			SetRoadVehPosition(v, gp.x, gp.y, true);
 
			v->x_pos = gp.x;
 
			v->y_pos = gp.y;
 
			v->UpdateInclination(true, true);
 
			return true;
 
		}
 

	
 
		v->x_pos = gp.x;
 
		v->y_pos = gp.y;
 
		VehicleMove(v, !(v->vehstatus & VS_HIDDEN));
 
@@ -1328,14 +1316,15 @@ again:
 
			v->frame = start_frame;
 
		}
 
		if (new_dir != v->direction) {
 
			v->direction = new_dir;
 
			v->cur_speed -= v->cur_speed >> 2;
 
		}
 

	
 
		RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y, true));
 
		v->x_pos = x;
 
		v->y_pos = y;
 
		RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
 
		return true;
 
	}
 

	
 
	if (rd.x & RDE_TURNED) {
 
		/* Vehicle has finished turning around, it will now head back onto the same tile */
 
		Trackdir dir;
 
@@ -1393,13 +1382,15 @@ again:
 

	
 
		if (new_dir != v->direction) {
 
			v->direction = new_dir;
 
			v->cur_speed -= v->cur_speed >> 2;
 
		}
 

	
 
		RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y, true));
 
		v->x_pos = x;
 
		v->y_pos = y;
 
		RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
 
		return true;
 
	}
 

	
 
	/* 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. */
 
@@ -1443,13 +1434,13 @@ again:
 
	Direction old_dir = v->direction;
 
	if (new_dir != old_dir) {
 
		v->direction = new_dir;
 
		v->cur_speed -= (v->cur_speed >> 2);
 
		if (old_dir != v->state) {
 
			/* The vehicle is in a road stop */
 
			SetRoadVehPosition(v, v->x_pos, v->y_pos, true);
 
			v->UpdateInclination(false, true);
 
			/* Note, return here means that the frame counter is not incremented
 
			 * for vehicles changing direction in a road stop. This causes frames to
 
			 * be repeated. (XXX) Is this intended? */
 
			return true;
 
		}
 
	}
 
@@ -1479,13 +1470,15 @@ again:
 
			if (IsDriveThroughStopTile(v->tile)) {
 
				TileIndex next_tile = TILE_ADD(v->tile, TileOffsByDir(v->direction));
 

	
 
				/* Check if next inline bay is free and has compatible road. */
 
				if (RoadStop::IsDriveThroughRoadStopContinuation(v->tile, next_tile) && (GetRoadTypes(next_tile) & v->compatible_roadtypes) != 0) {
 
					v->frame++;
 
					RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y, false));
 
					v->x_pos = x;
 
					v->y_pos = y;
 
					RoadZPosAffectSpeed(v, v->UpdateInclination(true, false));
 
					return true;
 
				}
 
			}
 

	
 
			rs->SetEntranceBusy(false);
 

	
 
@@ -1524,14 +1517,15 @@ again:
 
		v->current_order.Free();
 
	}
 

	
 
	/* Move to next frame unless vehicle arrived at a stop position
 
	 * in a depot or entered a tunnel/bridge */
 
	if (!HasBit(r, VETS_ENTERED_WORMHOLE)) v->frame++;
 

	
 
	RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y, true));
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	RoadZPosAffectSpeed(v, v->UpdateInclination(false, true));
 
	return true;
 
}
 

	
 
static bool RoadVehController(RoadVehicle *v)
 
{
 
	/* decrease counters */
0 comments (0 inline, 0 general)