mirror of https://github.com/OpenTTD/OpenTTD
(svn r20368) -Codechange: automatically rotate all nodes for airport movement if the airport is rotated
parent
c421b6fef5
commit
7e4bdbbc9d
|
@ -855,8 +855,17 @@ static bool AircraftController(Aircraft *v)
|
||||||
const Station *st = Station::GetIfValid(v->targetairport);
|
const Station *st = Station::GetIfValid(v->targetairport);
|
||||||
/* INVALID_TILE if there is no station */
|
/* INVALID_TILE if there is no station */
|
||||||
TileIndex tile = INVALID_TILE;
|
TileIndex tile = INVALID_TILE;
|
||||||
|
Direction rotation = DIR_N;
|
||||||
|
uint size_x = 1, size_y = 1;
|
||||||
if (st != NULL) {
|
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 */
|
/* DUMMY if there is no station or no airport */
|
||||||
const AirportFTAClass *afc = tile == INVALID_TILE ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
|
const AirportFTAClass *afc = tile == INVALID_TILE ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
|
||||||
|
@ -878,7 +887,7 @@ static bool AircraftController(Aircraft *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get airport moving data */
|
/* 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 x = TileX(tile) * TILE_SIZE;
|
||||||
int y = TileY(tile) * TILE_SIZE;
|
int y = TileY(tile) * TILE_SIZE;
|
||||||
|
|
|
@ -151,6 +151,42 @@ static byte AirportTestFTA(uint nofelements, const AirportFTA *layout, const byt
|
||||||
static void AirportPrintOut(uint nofelements, const AirportFTA *layout, bool full_report);
|
static void AirportPrintOut(uint nofelements, const AirportFTA *layout, bool full_report);
|
||||||
#endif
|
#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(
|
AirportFTAClass::AirportFTAClass(
|
||||||
const AirportMovingData *moving_data_,
|
const AirportMovingData *moving_data_,
|
||||||
|
|
|
@ -136,6 +136,8 @@ struct AirportMovingData {
|
||||||
DirectionByte direction; ///< Direction to turn the aircraft after reaching this position.
|
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;
|
struct AirportFTAbuildup;
|
||||||
|
|
||||||
/** Finite sTate mAchine --> FTA */
|
/** Finite sTate mAchine --> FTA */
|
||||||
|
|
Loading…
Reference in New Issue