Changeset - r15691:324f4145deb0
[Not reviewed]
master
0 1 0
yexo - 14 years ago 2010-08-05 12:02:22
yexo@openttd.org
(svn r20367) -Codechange; don't use a pointer to access the AirportMovingData of the current position
1 file changed with 24 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -875,19 +875,19 @@ static bool AircraftController(Aircraft 
 
			SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlyingAltitude(v));
 
			return false;
 
		}
 
	}
 

	
 
	/*  get airport moving data */
 
	const AirportMovingData *amd = afc->MovingData(v->pos);
 
	const AirportMovingData amd = *afc->MovingData(v->pos);
 

	
 
	int x = TileX(tile) * TILE_SIZE;
 
	int y = TileY(tile) * TILE_SIZE;
 

	
 
	/* Helicopter raise */
 
	if (amd->flag & AMED_HELI_RAISE) {
 
	if (amd.flag & AMED_HELI_RAISE) {
 
		Aircraft *u = v->Next()->Next();
 

	
 
		/* Make sure the rotors don't rotate too fast */
 
		if (u->cur_speed > 32) {
 
			v->cur_speed = 0;
 
			if (--u->cur_speed == 32) {
 
@@ -910,13 +910,13 @@ static bool AircraftController(Aircraft 
 
			}
 
		}
 
		return false;
 
	}
 

	
 
	/* Helicopter landing. */
 
	if (amd->flag & AMED_HELI_LOWER) {
 
	if (amd.flag & AMED_HELI_LOWER) {
 
		if (st == NULL) {
 
			/* FIXME - AircraftController -> if station no longer exists, do not land
 
			 * helicopter will circle until sign disappears, then go to next order
 
			 * what to do when it is the only order left, right now it just stays in 1 place */
 
			v->state = FLYING;
 
			UpdateAircraftCache(v);
 
@@ -947,21 +947,21 @@ static bool AircraftController(Aircraft 
 
			}
 
		}
 
		return false;
 
	}
 

	
 
	/* Get distance from destination pos to current pos. */
 
	uint dist = abs(x + amd->x - v->x_pos) +  abs(y + amd->y - v->y_pos);
 
	uint dist = abs(x + amd.x - v->x_pos) +  abs(y + amd.y - v->y_pos);
 

	
 
	/* Need exact position? */
 
	if (!(amd->flag & AMED_EXACTPOS) && dist <= (amd->flag & AMED_SLOWTURN ? 8U : 4U)) return true;
 
	if (!(amd.flag & AMED_EXACTPOS) && dist <= (amd.flag & AMED_SLOWTURN ? 8U : 4U)) return true;
 

	
 
	/* At final pos? */
 
	if (dist == 0) {
 
		/* Change direction smoothly to final direction. */
 
		DirDiff dirdiff = DirDifference(amd->direction, v->direction);
 
		DirDiff dirdiff = DirDifference(amd.direction, v->direction);
 
		/* if distance is 0, and plane points in right direction, no point in calling
 
		 * UpdateAircraftSpeed(). So do it only afterwards */
 
		if (dirdiff == DIRDIFF_SAME) {
 
			v->cur_speed = 0;
 
			return true;
 
		}
 
@@ -972,52 +972,52 @@ static bool AircraftController(Aircraft 
 
		v->cur_speed >>= 1;
 

	
 
		SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos);
 
		return false;
 
	}
 

	
 
	if (amd->flag & AMED_BRAKE && v->cur_speed > SPEED_LIMIT_TAXI * _settings_game.vehicle.plane_speed) {
 
	if (amd.flag & AMED_BRAKE && v->cur_speed > SPEED_LIMIT_TAXI * _settings_game.vehicle.plane_speed) {
 
		MaybeCrashAirplane(v);
 
		if ((v->vehstatus & VS_CRASHED) != 0) return false;
 
	}
 

	
 
	uint speed_limit = SPEED_LIMIT_TAXI;
 
	bool hard_limit = true;
 

	
 
	if (amd->flag & AMED_NOSPDCLAMP)   speed_limit = SPEED_LIMIT_NONE;
 
	if (amd->flag & AMED_HOLD)       { speed_limit = SPEED_LIMIT_HOLD;     hard_limit = false; }
 
	if (amd->flag & AMED_LAND)       { speed_limit = SPEED_LIMIT_APPROACH; hard_limit = false; }
 
	if (amd->flag & AMED_BRAKE)      { speed_limit = SPEED_LIMIT_TAXI;     hard_limit = false; }
 
	if (amd.flag & AMED_NOSPDCLAMP)   speed_limit = SPEED_LIMIT_NONE;
 
	if (amd.flag & AMED_HOLD)       { speed_limit = SPEED_LIMIT_HOLD;     hard_limit = false; }
 
	if (amd.flag & AMED_LAND)       { speed_limit = SPEED_LIMIT_APPROACH; hard_limit = false; }
 
	if (amd.flag & AMED_BRAKE)      { speed_limit = SPEED_LIMIT_TAXI;     hard_limit = false; }
 

	
 
	count = UpdateAircraftSpeed(v, speed_limit, hard_limit);
 
	if (count == 0) return false;
 

	
 
	if (v->turn_counter != 0) v->turn_counter--;
 

	
 
	do {
 

	
 
		GetNewVehiclePosResult gp;
 

	
 
		if (dist < 4 || (amd->flag & AMED_LAND)) {
 
		if (dist < 4 || (amd.flag & AMED_LAND)) {
 
			/* move vehicle one pixel towards target */
 
			gp.x = (v->x_pos != (x + amd->x)) ?
 
					v->x_pos + ((x + amd->x > v->x_pos) ? 1 : -1) :
 
			gp.x = (v->x_pos != (x + amd.x)) ?
 
					v->x_pos + ((x + amd.x > v->x_pos) ? 1 : -1) :
 
					v->x_pos;
 
			gp.y = (v->y_pos != (y + amd->y)) ?
 
					v->y_pos + ((y + amd->y > v->y_pos) ? 1 : -1) :
 
			gp.y = (v->y_pos != (y + amd.y)) ?
 
					v->y_pos + ((y + amd.y > v->y_pos) ? 1 : -1) :
 
					v->y_pos;
 

	
 
			/* Oilrigs must keep v->tile as st->airport.tile, since the landing pad is in a non-airport tile */
 
			gp.new_tile = (st->airport.type == AT_OILRIG) ? st->airport.tile : TileVirtXY(gp.x, gp.y);
 

	
 
		} else {
 

	
 
			/* Turn. Do it slowly if in the air. */
 
			Direction newdir = GetDirectionTowards(v, x + amd->x, y + amd->y);
 
			Direction newdir = GetDirectionTowards(v, x + amd.x, y + amd.y);
 
			if (newdir != v->direction) {
 
				if (amd->flag & AMED_SLOWTURN && v->number_consecutive_turns < 8 && v->subtype == AIR_AIRCRAFT) {
 
				if (amd.flag & AMED_SLOWTURN && v->number_consecutive_turns < 8 && v->subtype == AIR_AIRCRAFT) {
 
					if (v->turn_counter == 0 || newdir == v->last_direction) {
 
						if (newdir == v->last_direction) {
 
							v->number_consecutive_turns = 0;
 
						} else {
 
							v->number_consecutive_turns++;
 
						}
 
@@ -1047,35 +1047,35 @@ static bool AircraftController(Aircraft 
 
				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;
 
		if (amd.flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) v->tile = 0;
 

	
 
		/* Adjust Z for land or takeoff? */
 
		uint z = v->z_pos;
 

	
 
		if (amd->flag & AMED_TAKEOFF) {
 
		if (amd.flag & AMED_TAKEOFF) {
 
			z = min(z + 2, GetAircraftFlyingAltitude(v));
 
		}
 

	
 
		if ((amd->flag & AMED_HOLD) && (z > 150)) z--;
 
		if ((amd.flag & AMED_HOLD) && (z > 150)) z--;
 

	
 
		if (amd->flag & AMED_LAND) {
 
		if (amd.flag & AMED_LAND) {
 
			if (st->airport.tile == INVALID_TILE) {
 
				/* Airport has been removed, abort the landing procedure */
 
				v->state = FLYING;
 
				UpdateAircraftCache(v);
 
				AircraftNextAirportPos_and_Order(v);
 
				/* get aircraft back on running altitude */
 
				SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
 
				continue;
 
			}
 

	
 
			uint curz = GetSlopeZ(x + amd->x, y + amd->y) + 1;
 
			uint curz = GetSlopeZ(x + amd.x, y + amd.y) + 1;
 

	
 
			/* We're not flying below our destination, right? */
 
			assert(curz <= z);
 
			int t = max(1U, dist - 4);
 
			int delta = z - curz;
 

	
 
@@ -1084,13 +1084,13 @@ static bool AircraftController(Aircraft 
 
				z -= CeilDiv(z - curz, t);
 
			}
 
			if (z < curz) z = curz;
 
		}
 

	
 
		/* We've landed. Decrease speed when we're reaching end of runway. */
 
		if (amd->flag & AMED_BRAKE) {
 
		if (amd.flag & AMED_BRAKE) {
 
			uint curz = GetSlopeZ(x, y) + 1;
 

	
 
			if (z > curz) {
 
				z--;
 
			} else if (z < curz) {
 
				z++;
0 comments (0 inline, 0 general)