Changeset - r15692:f9728a8c5d5d
[Not reviewed]
master
0 3 0
yexo - 14 years ago 2010-08-05 12:03:06
yexo@openttd.org
(svn r20368) -Codechange: automatically rotate all nodes for airport movement if the airport is rotated
3 files changed with 49 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -855,8 +855,17 @@ static bool AircraftController(Aircraft 
 
	const Station *st = Station::GetIfValid(v->targetairport);
 
	/* INVALID_TILE if there is no station */
 
	TileIndex tile = INVALID_TILE;
 
	Direction rotation = DIR_N;
 
	uint size_x = 1, size_y = 1;
 
	if (st != NULL) {
 
		tile = (st->airport.tile != INVALID_TILE) ? st->airport.tile : st->xy;
 
		if (st->airport.tile != INVALID_TILE) {
 
			tile = st->airport.tile;
 
			rotation = st->airport.rotation;
 
			size_x = st->airport.w;
 
			size_y = st->airport.h;
 
		} else {
 
			tile = st->xy;
 
		}
 
	}
 
	/* DUMMY if there is no station or no airport */
 
	const AirportFTAClass *afc = tile == INVALID_TILE ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
 
@@ -878,7 +887,7 @@ static bool AircraftController(Aircraft 
 
	}
 

	
 
	/*  get airport moving data */
 
	const AirportMovingData amd = *afc->MovingData(v->pos);
 
	const AirportMovingData amd = RotateAirportMovingData(afc->MovingData(v->pos), rotation, size_x, size_y);
 

	
 
	int x = TileX(tile) * TILE_SIZE;
 
	int y = TileY(tile) * TILE_SIZE;
src/airport.cpp
Show inline comments
 
@@ -151,6 +151,42 @@ static byte AirportTestFTA(uint nofeleme
 
static void AirportPrintOut(uint nofelements, const AirportFTA *layout, bool full_report);
 
#endif
 

	
 
/**
 
 * Rotate the airport moving data to another rotation.
 
 * @param orig Pointer to the moving data to rotate.
 
 * @param rotation How to rotate the moving data.
 
 * @return The rotated moving data.
 
 */
 
AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y)
 
{
 
	AirportMovingData amd;
 
	amd.flag = orig->flag;
 
	amd.direction = ChangeDir(orig->direction, (DirDiff)rotation);
 
	switch (rotation) {
 
		case DIR_N:
 
			amd.x = orig->x;
 
			amd.y = orig->y;
 
			break;
 

	
 
		case DIR_E:
 
			amd.x = orig->y;
 
			amd.y = num_tiles_y * TILE_SIZE - orig->x - 1;
 
			break;
 

	
 
		case DIR_S:
 
			amd.x = num_tiles_x * TILE_SIZE - orig->x - 1;
 
			amd.y = num_tiles_y * TILE_SIZE - orig->y - 1;
 
			break;
 

	
 
		case DIR_W:
 
			amd.x = num_tiles_x * TILE_SIZE - orig->y - 1;
 
			amd.y = orig->x;
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
	return amd;
 
}
 

	
 
AirportFTAClass::AirportFTAClass(
 
	const AirportMovingData *moving_data_,
src/airport.h
Show inline comments
 
@@ -136,6 +136,8 @@ struct AirportMovingData {
 
	DirectionByte direction; ///< Direction to turn the aircraft after reaching this position.
 
};
 

	
 
AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y);
 

	
 
struct AirportFTAbuildup;
 

	
 
/** Finite sTate mAchine --> FTA */
0 comments (0 inline, 0 general)