1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-10 06:52:05 +01:00

Codefix: some coding style improvements

This commit is contained in:
Rubidium
2025-12-06 09:05:31 +01:00
committed by rubidium42
parent 1829f7926d
commit 1445aa9543
2 changed files with 38 additions and 12 deletions

View File

@@ -988,7 +988,7 @@ static bool AircraftController(Aircraft *v)
}
/* 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.flags.Test(AirportMovingDataFlag::ExactPosition) && dist <= (amd.flags.Test(AirportMovingDataFlag::SlowTurn) ? 8U : 4U)) return true;
@@ -1021,10 +1021,21 @@ static bool AircraftController(Aircraft *v)
uint speed_limit = SPEED_LIMIT_TAXI;
bool hard_limit = true;
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; }
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;
@@ -1181,7 +1192,7 @@ static bool HandleCrashedAircraft(Aircraft *v)
Station *st = GetTargetAirportIfValid(v);
/* make aircraft crash down to the ground */
if (v->crashed_counter < 500 && st == nullptr && ((v->crashed_counter % 3) == 0) ) {
if (v->crashed_counter < 500 && st == nullptr && ((v->crashed_counter % 3) == 0)) {
int z = GetSlopePixelZ(Clamp(v->x_pos, 0, Map::MaxX() * TILE_SIZE), Clamp(v->y_pos, 0, Map::MaxY() * TILE_SIZE));
v->z_pos -= 1;
if (v->z_pos <= z) {
@@ -1814,7 +1825,7 @@ static bool AirportMove(Aircraft *v, const AirportFTAClass *apc)
{
/* error handling */
if (v->pos >= apc->nofelements) {
Debug(misc, 0, "[Ap] position {} is not valid for current airport. Max position is {}", v->pos, apc->nofelements-1);
Debug(misc, 0, "[Ap] position {} is not valid for current airport. Max position is {}", v->pos, apc->nofelements - 1);
assert(v->pos < apc->nofelements);
}

View File

@@ -2214,6 +2214,25 @@ static void DrawTrackBitsOverlay(TileInfo *ti, TrackBits track, const RailTypeIn
}
}
/**
* Returns which of the 5 junction-'Rail underlays' to use for the given track bits.
* See https://newgrf-specs.tt-wiki.net/wiki/Action3/Railtypes for the cases.
* @pre The track bits describe a junction, so at least two bits are set.
* @param track The track bits to consider.
* @return The offset in the five junction ground sprites.
*/
static int GetJunctionGroundSpriteOffset(TrackBits track)
{
/* If none of the tracks end up in the NE corner, return the ground sprite
* where the NE of the tile is not covered. Repeat for the other directions.
* What remains are junctions where all directions are covered. */
if ((track & TRACK_BIT_3WAY_NE) == 0) return 0;
if ((track & TRACK_BIT_3WAY_SW) == 0) return 1;
if ((track & TRACK_BIT_3WAY_NW) == 0) return 2;
if ((track & TRACK_BIT_3WAY_SE) == 0) return 3;
return 4;
}
/**
* Draw ground sprite and track bits
* @param ti TileInfo
@@ -2289,11 +2308,7 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track)
/* junction, select only ground sprite, handle track sprite later */
default:
junction = true;
if ((track & TRACK_BIT_3WAY_NE) == 0) { image = rti->base_sprites.ground; break; }
if ((track & TRACK_BIT_3WAY_SW) == 0) { image = rti->base_sprites.ground + 1; break; }
if ((track & TRACK_BIT_3WAY_NW) == 0) { image = rti->base_sprites.ground + 2; break; }
if ((track & TRACK_BIT_3WAY_SE) == 0) { image = rti->base_sprites.ground + 3; break; }
image = rti->base_sprites.ground + 4;
image = rti->base_sprites.ground + GetJunctionGroundSpriteOffset(track);
break;
}
}