1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 17:32:45 +01:00

Codechange: Use EnumBitSet for AirportMovingDataFlags. (#13754)

This commit is contained in:
Peter Nelson
2025-03-06 19:03:41 +00:00
committed by GitHub
parent 84f093fc72
commit 3fde611012
5 changed files with 366 additions and 366 deletions

View File

@@ -908,7 +908,7 @@ static bool AircraftController(Aircraft *v)
int y = TileY(tile) * TILE_SIZE;
/* Helicopter raise */
if (amd.flag & AMED_HELI_RAISE) {
if (amd.flags.Test(AirportMovingDataFlag::HeliRaise)) {
Aircraft *u = v->Next()->Next();
/* Make sure the rotors don't rotate too fast */
@@ -944,7 +944,7 @@ static bool AircraftController(Aircraft *v)
}
/* Helicopter landing. */
if (amd.flag & AMED_HELI_LOWER) {
if (amd.flags.Test(AirportMovingDataFlag::HeliLower)) {
SetBit(v->flags, VAF_HELI_DIRECT_DESCENT);
if (st == nullptr) {
@@ -996,7 +996,7 @@ static bool AircraftController(Aircraft *v)
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.flags.Test(AirportMovingDataFlag::ExactPosition) && dist <= (amd.flags.Test(AirportMovingDataFlag::SlowTurn) ? 8U : 4U)) return true;
/* At final pos? */
if (dist == 0) {
@@ -1018,7 +1018,7 @@ static bool AircraftController(Aircraft *v)
return false;
}
if (amd.flag & AMED_BRAKE && v->cur_speed > SPEED_LIMIT_TAXI * _settings_game.vehicle.plane_speed) {
if (amd.flags.Test(AirportMovingDataFlag::Brake) && v->cur_speed > SPEED_LIMIT_TAXI * _settings_game.vehicle.plane_speed) {
MaybeCrashAirplane(v);
if ((v->vehstatus & VS_CRASHED) != 0) return false;
}
@@ -1026,10 +1026,10 @@ static bool AircraftController(Aircraft *v)
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.flags.Test(AirportMovingDataFlag::NoSpeedClamp)) speed_limit = SPEED_LIMIT_NONE;
if (amd.flags.Test(AirportMovingDataFlag::Hold)) { speed_limit = SPEED_LIMIT_HOLD; hard_limit = false; }
if (amd.flags.Test(AirportMovingDataFlag::Land)) { speed_limit = SPEED_LIMIT_APPROACH; hard_limit = false; }
if (amd.flags.Test(AirportMovingDataFlag::Brake)) { speed_limit = SPEED_LIMIT_TAXI; hard_limit = false; }
int count = UpdateAircraftSpeed(v, speed_limit, hard_limit);
if (count == 0) return false;
@@ -1047,7 +1047,7 @@ static bool AircraftController(Aircraft *v)
GetNewVehiclePosResult gp;
if (nudge_towards_target || (amd.flag & AMED_LAND)) {
if (nudge_towards_target || amd.flags.Test(AirportMovingDataFlag::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) :
@@ -1064,7 +1064,7 @@ static bool AircraftController(Aircraft *v)
/* Turn. Do it slowly if in the air. */
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.flags.Test(AirportMovingDataFlag::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;
@@ -1100,17 +1100,17 @@ static bool AircraftController(Aircraft *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 = TileIndex{};
if (amd.flags.Any({AirportMovingDataFlag::Takeoff, AirportMovingDataFlag::SlowTurn, AirportMovingDataFlag::Land})) v->tile = TileIndex{};
/* Adjust Z for land or takeoff? */
int z = v->z_pos;
if (amd.flag & AMED_TAKEOFF) {
if (amd.flags.Test(AirportMovingDataFlag::Takeoff)) {
z = GetAircraftFlightLevel(v, true);
} else if (amd.flag & AMED_HOLD) {
} else if (amd.flags.Test(AirportMovingDataFlag::Hold)) {
/* Let the plane drop from normal flight altitude to holding pattern altitude */
if (z > GetAircraftHoldMaxAltitude(v)) z--;
} else if ((amd.flag & AMED_SLOWTURN) && (amd.flag & AMED_NOSPDCLAMP)) {
} else if (amd.flags.All({AirportMovingDataFlag::SlowTurn, AirportMovingDataFlag::NoSpeedClamp})) {
z = GetAircraftFlightLevel(v);
}
@@ -1121,13 +1121,13 @@ static bool AircraftController(Aircraft *v)
* We also know that the airport itself has to be completely flat (otherwise it is not a valid airport).
* Therefore, use the height of this hangar to calculate our z-value. */
int airport_z = v->z_pos;
if ((amd.flag & (AMED_LAND | AMED_BRAKE)) && st != nullptr) {
if (amd.flags.Any({AirportMovingDataFlag::Land, AirportMovingDataFlag::Brake}) && st != nullptr) {
assert(st->airport.HasHangar());
TileIndex hangar_tile = st->airport.GetHangarTile(0);
airport_z = GetTileMaxPixelZ(hangar_tile) + 1; // To avoid clashing with the shadow
}
if (amd.flag & AMED_LAND) {
if (amd.flags.Test(AirportMovingDataFlag::Land)) {
if (st->airport.tile == INVALID_TILE) {
/* Airport has been removed, abort the landing procedure */
v->state = FLYING;
@@ -1151,7 +1151,7 @@ static bool AircraftController(Aircraft *v)
}
/* We've landed. Decrease speed when we're reaching end of runway. */
if (amd.flag & AMED_BRAKE) {
if (amd.flags.Test(AirportMovingDataFlag::Brake)) {
if (z > airport_z) {
z--;