Changeset - r6153:c45b80eecb6a
[Not reviewed]
master
0 7 0
tron - 17 years ago 2007-02-25 10:49:13
tron@openttd.org
(svn r8897) -Fix

Change the signature of GetNewVehiclePos():
-void GetNewVehiclePos(const Vehicle *v, GetNewVehiclePosResult *gp);
+GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
7 files changed with 23 insertions and 37 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1043,14 +1043,13 @@ static bool AircraftController(Vehicle *
 
			v->cur_speed >>= 1;
 
			v->direction = newdir;
 
		}
 
	}
 

	
 
	/* Move vehicle. */
 
	GetNewVehiclePosResult gp;
 
	GetNewVehiclePos(v, &gp);
 
	GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
	v->tile = gp.new_tile;
 

	
 
	/* If vehicle is in the air, use tile coordinate 0. */
 
	if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) v->tile = 0;
 

	
 
	/* Adjust Z for land or takeoff? */
 
@@ -2069,14 +2068,13 @@ void UpdateOldAircraft(void)
 
			}
 

	
 
			AircraftLeaveHangar(v_oldstyle); // make airplane visible if it was in a depot for example
 
			v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving
 
			v_oldstyle->u.air.state = FLYING;
 
			AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport
 
			GetNewVehiclePosResult gp;
 
			GetNewVehiclePos(v_oldstyle, &gp); // get the position of the plane (to be used for setting)
 
			GetNewVehiclePosResult gp = GetNewVehiclePos(v_oldstyle);
 
			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;
 

	
 
			/* set new position x,y,z */
 
@@ -2098,14 +2096,13 @@ void UpdateAirplanesOnNewStation(const S
 
				 *you cannot delete airport, so it doesn't matter */
 
				if (v->u.air.state >= FLYING) { // circle around
 
					v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, ap);
 
					v->u.air.state = FLYING;
 
					/* landing plane needs to be reset to flying height (only if in pause mode upgrade,
 
					 * in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING */
 
					GetNewVehiclePosResult gp;
 
					GetNewVehiclePos(v, &gp);
 
					GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
					/* set new position x,y,z */
 
					SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
 
				} else {
 
					assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF);
 
					byte takeofftype = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : ENDTAKEOFF;
 
					/* search in airportdata for that heading
src/disaster_cmd.cpp
Show inline comments
 
@@ -197,24 +197,23 @@ static void SetDisasterVehiclePos(Vehicl
 
 * 2: Create more smoke and leave debris on ground
 
 * 2: Clear the runway after some time and remove crashed zeppeliner
 
 * If not airport was found, only state 0 is reached until zeppeliner leaves map
 
 */
 
static void DisasterTick_Zeppeliner(Vehicle *v)
 
{
 
	GetNewVehiclePosResult gp;
 
	Station *st;
 
	int x, y;
 
	byte z;
 
	TileIndex tile;
 

	
 
	v->tick_counter++;
 

	
 
	if (v->current_order.dest < 2) {
 
		if (HASBIT(v->tick_counter, 0)) return;
 

	
 
		GetNewVehiclePos(v, &gp);
 
		GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 

	
 
		SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 

	
 
		if (v->current_order.dest == 1) {
 
			if (++v->age == 38) {
 
				v->current_order.dest = 2;
 
@@ -305,26 +304,25 @@ static void DisasterTick_Zeppeliner(Vehi
 
 * 0: Fly around to the middle of the map, then randomly, after a while target a road vehicle
 
 * 1: Home in on a road vehicle and crash it >:)
 
 * If not road vehicle was found, only state 0 is used and Ufo disappears after a while
 
 */
 
static void DisasterTick_Ufo(Vehicle *v)
 
{
 
	GetNewVehiclePosResult gp;
 
	Vehicle *u;
 
	uint dist;
 
	byte z;
 

	
 
	v->u.disaster.image_override = (HASBIT(++v->tick_counter, 3)) ? SPR_UFO_SMALL_SCOUT_DARKER : SPR_UFO_SMALL_SCOUT;
 

	
 
	if (v->current_order.dest == 0) {
 
		/* Fly around randomly */
 
		int x = TileX(v->dest_tile) * TILE_SIZE;
 
		int y = TileY(v->dest_tile) * TILE_SIZE;
 
		if (delta(x, v->x_pos) + delta(y, v->y_pos) >= TILE_SIZE) {
 
			v->direction = GetDirectionTowards(v, x, y);
 
			GetNewVehiclePos(v, &gp);
 
			GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 
			return;
 
		}
 
		if (++v->age < 6) {
 
			v->dest_tile = RandomTile();
 
			return;
 
@@ -353,13 +351,13 @@ static void DisasterTick_Ufo(Vehicle *v)
 
		if (dist < TILE_SIZE && !(u->vehstatus & VS_HIDDEN) && u->breakdown_ctr == 0) {
 
			u->breakdown_ctr = 3;
 
			u->breakdown_delay = 140;
 
		}
 

	
 
		v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos);
 
		GetNewVehiclePos(v, &gp);
 
		GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 

	
 
		z = v->z_pos;
 
		if (dist <= TILE_SIZE && z > u->z_pos) z--;
 
		SetDisasterVehiclePos(v, gp.x, gp.y, z);
 

	
 
		if (z <= u->z_pos && (u->vehstatus & VS_HIDDEN)==0) {
 
@@ -403,19 +401,17 @@ static void DestructIndustry(Industry *i
 
 * 2: Refinery explosions
 
 * 3: Fly out of the map
 
 * If the industry was removed in the meantime just fly to the end of the map
 
 */
 
static void DisasterTick_Airplane(Vehicle *v)
 
{
 
	GetNewVehiclePosResult gp;
 

	
 
	v->tick_counter++;
 
	v->u.disaster.image_override =
 
		(v->current_order.dest == 1 && HASBIT(v->tick_counter, 2)) ? SPR_F_15_FIRING : 0;
 

	
 
	GetNewVehiclePos(v, &gp);
 
	GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
	SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 

	
 
	if (gp.x < (-10 * TILE_SIZE)) {
 
		DeleteDisasterVeh(v);
 
		return;
 
	}
 
@@ -478,19 +474,17 @@ static void DisasterTick_Airplane(Vehicl
 
 * 1: If within 15 tiles, fire away rockets and destroy industry
 
 * 2: Factory explosions
 
 * 3: Fly out of the map
 
 */
 
static void DisasterTick_Helicopter(Vehicle *v)
 
{
 
	GetNewVehiclePosResult gp;
 

	
 
	v->tick_counter++;
 
	v->u.disaster.image_override =
 
		(v->current_order.dest == 1 && HASBIT(v->tick_counter, 2)) ? SPR_AH_64A_FIRING : 0;
 

	
 
	GetNewVehiclePos(v, &gp);
 
	GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
	SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 

	
 
	if (gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1) {
 
		DeleteDisasterVeh(v);
 
		return;
 
	}
 
@@ -565,13 +559,12 @@ static void DisasterTick_Helicopter_Roto
 
 * 0: Fly around to the middle of the map, then randomly for a while and home in on a piece of rail
 
 * 1: Land there and breakdown all trains in a radius of 12 tiles; and now we wait...
 
 *    because as soon as the Ufo lands, a fighter jet, a Skyranger, is called to clear up the mess
 
 */
 
static void DisasterTick_Big_Ufo(Vehicle *v)
 
{
 
	GetNewVehiclePosResult gp;
 
	byte z;
 
	Vehicle *u, *w;
 
	Town *t;
 
	TileIndex tile;
 
	TileIndex tile_org;
 

	
 
@@ -580,13 +573,13 @@ static void DisasterTick_Big_Ufo(Vehicle
 
	if (v->current_order.dest == 1) {
 
		int x = TileX(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
 
		int y = TileY(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
 
		if (delta(v->x_pos, x) + delta(v->y_pos, y) >= 8) {
 
			v->direction = GetDirectionTowards(v, x, y);
 

	
 
			GetNewVehiclePos(v, &gp);
 
			GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 
			return;
 
		}
 

	
 
		z = GetSlopeZ(v->x_pos, v->y_pos);
 
		if (z < v->z_pos) {
 
@@ -629,13 +622,13 @@ static void DisasterTick_Big_Ufo(Vehicle
 
		w->vehstatus |= VS_SHADOW;
 
	} else if (v->current_order.dest == 0) {
 
		int x = TileX(v->dest_tile) * TILE_SIZE;
 
		int y = TileY(v->dest_tile) * TILE_SIZE;
 
		if (delta(x, v->x_pos) + delta(y, v->y_pos) >= TILE_SIZE) {
 
			v->direction = GetDirectionTowards(v, x, y);
 
			GetNewVehiclePos(v, &gp);
 
			GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 
			return;
 
		}
 

	
 
		if (++v->age < 6) {
 
			v->dest_tile = RandomTile();
 
@@ -662,19 +655,18 @@ static void DisasterTick_Big_Ufo(Vehicle
 
/**
 
 * Skyranger destroying (Big) Ufo handling, v->current_order.dest states:
 
 * 0: Home in on landed Ufo and shoot it down
 
 */
 
static void DisasterTick_Big_Ufo_Destroyer(Vehicle *v)
 
{
 
	GetNewVehiclePosResult gp;
 
	Vehicle *u;
 
	int i;
 

	
 
	v->tick_counter++;
 

	
 
	GetNewVehiclePos(v, &gp);
 
	GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
	SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 

	
 
	if (gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1) {
 
		DeleteDisasterVeh(v);
 
		return;
 
	}
 
@@ -708,13 +700,12 @@ static void DisasterTick_Big_Ufo_Destroy
 
/**
 
 * Submarine, v->current_order.dest states:
 
 * Unused, just float around aimlessly and pop up at different places, turning around
 
 */
 
static void DisasterTick_Submarine(Vehicle *v)
 
{
 
	GetNewVehiclePosResult gp;
 
	TileIndex tile;
 

	
 
	v->tick_counter++;
 

	
 
	if (++v->age > 8880) {
 
		VehiclePositionChanged(v);
 
@@ -728,13 +719,13 @@ static void DisasterTick_Submarine(Vehic
 

	
 
	tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
 
	if (IsValidTile(tile)) {
 
		TrackdirBits r = (TrackdirBits)GetTileTrackStatus(tile, TRANSPORT_WATER);
 

	
 
		if (TrackdirBitsToTrackBits(r) == TRACK_BIT_ALL && !CHANCE16(1, 90)) {
 
			GetNewVehiclePos(v, &gp);
 
			GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 
			return;
 
		}
 
	}
 

	
 
	v->direction = ChangeDir(v->direction, GB(Random(), 0, 1) ? DIRDIFF_90RIGHT : DIRDIFF_90LEFT);
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1354,15 +1354,13 @@ static void RoadVehController(Vehicle *v
 

	
 
	/* Save old vehicle position to use at end of move to set viewport area dirty */
 
	BeginVehicleMove(v);
 

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

	
 
		GetNewVehiclePos(v, &gp);
 
		GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 

	
 
		const Vehicle *u = RoadVehFindCloseTo(v, gp.x, gp.y, v->direction);
 
		if (u != NULL && u->cur_speed < v->cur_speed) {
 
			v->cur_speed = u->cur_speed;
 
			return;
 
		}
src/ship_cmd.cpp
Show inline comments
 
@@ -659,13 +659,12 @@ static const byte _ship_subcoord[4][6][3
 
		{ 7,15, 0},
 
	}
 
};
 

	
 
static void ShipController(Vehicle *v)
 
{
 
	GetNewVehiclePosResult gp;
 
	uint32 r;
 
	const byte *b;
 
	Direction dir;
 
	Track track;
 
	TrackBits tracks;
 

	
 
@@ -689,13 +688,13 @@ static void ShipController(Vehicle *v)
 
	CheckShipLeaveDepot(v);
 

	
 
	if (!ShipAccelerate(v)) return;
 

	
 
	BeginVehicleMove(v);
 

	
 
	GetNewVehiclePos(v, &gp);
 
	GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
	if (gp.old_tile == gp.new_tile) {
 
		/* Staying in tile */
 
		if (IsShipInDepot(v)) {
 
			gp.x = v->x_pos;
 
			gp.y = v->y_pos;
 
		} else {
src/train_cmd.cpp
Show inline comments
 
@@ -2883,14 +2883,13 @@ static void TrainController(Vehicle *v, 
 
	Vehicle *prev;
 

	
 
	/* For every vehicle after and including the given vehicle */
 
	for (prev = GetPrevVehicleInChain(v); v != NULL; prev = v, v = v->next) {
 
		BeginVehicleMove(v);
 

	
 
		GetNewVehiclePosResult gp;
 
		GetNewVehiclePos(v, &gp);
 
		GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
		if (v->u.rail.track != TRACK_BIT_WORMHOLE) {
 
			/* Not inside tunnel */
 
			if (gp.old_tile == gp.new_tile) {
 
				/* Staying in the old tile */
 
				if (v->u.rail.track == TRACK_BIT_DEPOT) {
 
					/* Inside depot */
src/vehicle.cpp
Show inline comments
 
@@ -2689,26 +2689,28 @@ void EndVehicleMove(Vehicle *v)
 
		max(_old_vehicle_coords.right,v->right_coord)+1,
 
		max(_old_vehicle_coords.bottom,v->bottom_coord)+1
 
	);
 
}
 

	
 
/* returns true if staying in the same tile */
 
void GetNewVehiclePos(const Vehicle *v, GetNewVehiclePosResult *gp)
 
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
 
{
 
	static const int8 _delta_coord[16] = {
 
		-1,-1,-1, 0, 1, 1, 1, 0, /* x */
 
		-1, 0, 1, 1, 1, 0,-1,-1, /* y */
 
	};
 

	
 
	int x = v->x_pos + _delta_coord[v->direction];
 
	int y = v->y_pos + _delta_coord[v->direction + 8];
 

	
 
	gp->x = x;
 
	gp->y = y;
 
	gp->old_tile = v->tile;
 
	gp->new_tile = TileVirtXY(x, y);
 
	GetNewVehiclePosResult gp;
 
	gp.x = x;
 
	gp.y = y;
 
	gp.old_tile = v->tile;
 
	gp.new_tile = TileVirtXY(x, y);
 
	return gp;
 
}
 

	
 
static const Direction _new_direction_table[] = {
 
	DIR_N , DIR_NW, DIR_W ,
 
	DIR_NE, DIR_SE, DIR_SW,
 
	DIR_E , DIR_SE, DIR_S
src/vehicle.h
Show inline comments
 
@@ -424,13 +424,13 @@ typedef struct GetNewVehiclePosResult {
 
 * For other vehicles types, or vehicles with no clear trackdir (such as those
 
 * in depots), returns 0xFF.
 
 */
 
Trackdir GetVehicleTrackdir(const Vehicle* v);
 

	
 
/* returns true if staying in the same tile */
 
void GetNewVehiclePos(const Vehicle *v, GetNewVehiclePosResult *gp);
 
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
 
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);
 

	
 
DECLARE_OLD_POOL(Vehicle, Vehicle, 9, 125)
0 comments (0 inline, 0 general)