Merge: Codechange: Use null pointer literal instead of the NULL macro

This commit is contained in:
Jonathan G Rennison
2019-04-11 18:14:13 +01:00
585 changed files with 6604 additions and 6604 deletions

View File

@@ -144,7 +144,7 @@ static StationID FindNearestHangar(const Aircraft *v)
if (v->acache.cached_max_range_sqr != 0) {
/* Check if our current destination can be reached from the depot airport. */
const Station *cur_dest = GetTargetAirportIfValid(v);
if (cur_dest != NULL && DistanceSquare(st->airport.tile, cur_dest->airport.tile) > v->acache.cached_max_range_sqr) continue;
if (cur_dest != nullptr && DistanceSquare(st->airport.tile, cur_dest->airport.tile) > v->acache.cached_max_range_sqr) continue;
}
if (distance < best || index == INVALID_STATION) {
best = distance;
@@ -294,7 +294,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
v->cargo_type = e->GetDefaultCargoType();
u->cargo_type = CT_MAIL;
v->name = NULL;
v->name = nullptr;
v->last_station_visited = INVALID_STATION;
v->last_loading_station = INVALID_STATION;
@@ -386,7 +386,7 @@ bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination,
{
const Station *st = GetTargetAirportIfValid(this);
/* If the station is not a valid airport or if it has no hangars */
if (st == NULL || !CanVehicleUseStation(this, st) || !st->airport.HasHangar()) {
if (st == nullptr || !CanVehicleUseStation(this, st) || !st->airport.HasHangar()) {
/* the aircraft has to search for a hangar on its own */
StationID station = FindNearestHangar(this);
@@ -395,8 +395,8 @@ bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination,
st = Station::Get(station);
}
if (location != NULL) *location = st->xy;
if (destination != NULL) *destination = st->index;
if (location != nullptr) *location = st->xy;
if (destination != nullptr) *destination = st->index;
return true;
}
@@ -415,7 +415,7 @@ static void CheckIfAircraftNeedsService(Aircraft *v)
const Station *st = Station::Get(v->current_order.GetDestination());
assert(st != NULL);
assert(st != nullptr);
/* only goto depot if the target airport has a depot */
if (st->airport.HasHangar() && CanVehicleUseStation(v, st)) {
@@ -542,7 +542,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
u->UpdatePositionAndViewport();
u = u->Next();
if (u != NULL) {
if (u != nullptr) {
u->x_pos = x;
u->y_pos = y;
u->z_pos = z + ROTOR_Z_OFFSET;
@@ -563,7 +563,7 @@ void HandleAircraftEnterHangar(Aircraft *v)
Aircraft *u = v->Next();
u->vehstatus |= VS_HIDDEN;
u = u->Next();
if (u != NULL) {
if (u != nullptr) {
u->vehstatus |= VS_HIDDEN;
u->cur_speed = 0;
}
@@ -737,8 +737,8 @@ void GetAircraftFlightLevelBounds(const Vehicle *v, int *min_level, int *max_lev
/* Make faster planes fly higher so that they can overtake slower ones */
base_altitude += min(20 * (v->vcache.cached_max_speed / 200) - 90, 0);
if (min_level != NULL) *min_level = base_altitude + AIRCRAFT_MIN_FLYING_ALTITUDE;
if (max_level != NULL) *max_level = base_altitude + AIRCRAFT_MAX_FLYING_ALTITUDE;
if (min_level != nullptr) *min_level = base_altitude + AIRCRAFT_MIN_FLYING_ALTITUDE;
if (max_level != nullptr) *max_level = base_altitude + AIRCRAFT_MAX_FLYING_ALTITUDE;
}
/**
@@ -813,8 +813,8 @@ template int GetAircraftFlightLevel(Aircraft *v, bool takeoff);
*/
static byte AircraftGetEntryPoint(const Aircraft *v, const AirportFTAClass *apc, Direction rotation)
{
assert(v != NULL);
assert(apc != NULL);
assert(v != nullptr);
assert(apc != nullptr);
/* In the case the station doesn't exit anymore, set target tile 0.
* It doesn't hurt much, aircraft will go to next order, nearest hangar
@@ -822,7 +822,7 @@ static byte AircraftGetEntryPoint(const Aircraft *v, const AirportFTAClass *apc,
TileIndex tile = 0;
const Station *st = Station::GetIfValid(v->targetairport);
if (st != NULL) {
if (st != nullptr) {
/* Make sure we don't go to INVALID_TILE if the airport has been removed. */
tile = (st->airport.tile != INVALID_TILE) ? st->airport.tile : st->xy;
}
@@ -856,13 +856,13 @@ static bool AircraftController(Aircraft *v)
{
int count;
/* NULL if station is invalid */
/* nullptr if station is invalid */
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) {
if (st != nullptr) {
if (st->airport.tile != INVALID_TILE) {
tile = st->airport.tile;
rotation = st->airport.rotation;
@@ -876,7 +876,7 @@ static bool AircraftController(Aircraft *v)
const AirportFTAClass *afc = tile == INVALID_TILE ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
/* prevent going to INVALID_TILE if airport is deleted. */
if (st == NULL || st->airport.tile == INVALID_TILE) {
if (st == nullptr || st->airport.tile == INVALID_TILE) {
/* Jump into our "holding pattern" state machine if possible */
if (v->pos >= afc->nofelements) {
v->pos = v->previous_pos = AircraftGetEntryPoint(v, afc, DIR_N);
@@ -916,7 +916,7 @@ static bool AircraftController(Aircraft *v)
v->tile = 0;
int z_dest;
GetAircraftFlightLevelBounds(v, &z_dest, NULL);
GetAircraftFlightLevelBounds(v, &z_dest, nullptr);
/* Reached altitude? */
if (v->z_pos >= z_dest) {
@@ -933,7 +933,7 @@ static bool AircraftController(Aircraft *v)
if (amd.flag & AMED_HELI_LOWER) {
SetBit(v->flags, VAF_HELI_DIRECT_DESCENT);
if (st == NULL) {
if (st == nullptr) {
/* 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 */
@@ -1139,7 +1139,7 @@ void FindBreakdownDestination(Aircraft *v)
DestinationID destination = INVALID_STATION;
if (v->breakdown_type == BREAKDOWN_AIRCRAFT_DEPOT) {
/* Go to a hangar, if possible at our current destination */
v->FindClosestDepot(NULL, &destination, NULL);
v->FindClosestDepot(nullptr, &destination, nullptr);
} else if (v->breakdown_type == BREAKDOWN_AIRCRAFT_EM_LANDING) {
/* Go to the nearest airport with a hangar */
destination = FindNearestHangar(v);
@@ -1184,7 +1184,7 @@ static bool HandleCrashedAircraft(Aircraft *v)
Station *st = GetTargetAirportIfValid(v);
/* make aircraft crash down to the ground */
if (v->crashed_counter < 500 && st == NULL && ((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, MapMaxX() * TILE_SIZE), Clamp(v->y_pos, 0, MapMaxY() * TILE_SIZE));
v->z_pos -= 1;
if (v->z_pos == z) {
@@ -1215,7 +1215,7 @@ static bool HandleCrashedAircraft(Aircraft *v)
/* clear runway-in on all airports, set by crashing plane
* small airports use AIRPORT_BUSY, city airports use RUNWAY_IN_OUT_block, etc.
* but they all share the same number */
if (st != NULL) {
if (st != nullptr) {
CLRBITS(st->airport.flags, RUNWAY_IN_block);
CLRBITS(st->airport.flags, RUNWAY_IN_OUT_block); // commuter airport
CLRBITS(st->airport.flags, RUNWAY_IN2_block); // intercontinental
@@ -1290,7 +1290,7 @@ void HandleMissingAircraftOrders(Aircraft *v)
* actually stops.
*/
const Station *st = GetTargetAirportIfValid(v);
if (st == NULL) {
if (st == nullptr) {
Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
CommandCost ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
cur_company.Restore();
@@ -1349,17 +1349,17 @@ static void CrashAirplane(Aircraft *v)
v->Next()->cargo.Truncate();
const Station *st = GetTargetAirportIfValid(v);
StringID newsitem;
if (st == NULL) {
if (st == nullptr) {
newsitem = STR_NEWS_PLANE_CRASH_OUT_OF_FUEL;
} else {
SetDParam(1, st->index);
newsitem = STR_NEWS_AIRCRAFT_CRASH;
}
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
AddVehicleNewsItem(newsitem, NT_ACCIDENT, v->index, st != NULL ? st->index : INVALID_STATION);
AddVehicleNewsItem(newsitem, NT_ACCIDENT, v->index, st != nullptr ? st->index : INVALID_STATION);
ModifyStationRatingAround(v->tile, v->owner, -160, 30);
if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
@@ -1457,8 +1457,8 @@ void AircraftNextAirportPos_and_Order(Aircraft *v)
}
const Station *st = GetTargetAirportIfValid(v);
const AirportFTAClass *apc = st == NULL ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
Direction rotation = st == NULL ? DIR_N : st->airport.rotation;
const AirportFTAClass *apc = st == nullptr ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
Direction rotation = st == nullptr ? DIR_N : st->airport.rotation;
v->pos = v->previous_pos = AircraftGetEntryPoint(v, apc, rotation);
}
@@ -1483,7 +1483,7 @@ void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
/* Rotor blades */
u = u->Next();
if (u != NULL) {
if (u != nullptr) {
u->vehstatus &= ~VS_HIDDEN;
u->cur_speed = 80;
}
@@ -1677,7 +1677,7 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
* it is possible to choose from multiple landing runways, so loop until a free one is found */
byte landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING;
const AirportFTA *current = apc->layout[v->pos].next;
while (current != NULL) {
while (current != nullptr) {
if (current->heading == landingtype) {
/* save speed before, since if AirportHasBlock is false, it resets them to 0
* we don't want that for plane in air
@@ -1833,7 +1833,7 @@ static bool AirportMove(Aircraft *v, const AirportFTAClass *apc)
v->previous_pos = v->pos; // save previous location
/* there is only one choice to move to */
if (current->next == NULL) {
if (current->next == nullptr) {
if (AirportSetBlocks(v, current, apc)) {
v->pos = current->next_position;
UpdateAircraftCache(v);
@@ -1852,7 +1852,7 @@ static bool AirportMove(Aircraft *v, const AirportFTAClass *apc)
return false;
}
current = current->next;
} while (current != NULL);
} while (current != nullptr);
DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d) for vehicle %d", v->pos, v->state, v->index);
NOT_REACHED();
@@ -1902,7 +1902,7 @@ static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const A
* this means more blocks should be checked/set */
const AirportFTA *current = current_pos;
if (current == reference) current = current->next;
while (current != NULL) {
while (current != nullptr) {
if (current->heading == current_pos->heading && current->block != 0) {
airport_flags |= current->block;
break;
@@ -2010,7 +2010,7 @@ static bool AirportFindFreeTerminal(Aircraft *v, const AirportFTAClass *apc)
const Station *st = Station::Get(v->targetairport);
const AirportFTA *temp = apc->layout[v->pos].next;
while (temp != NULL) {
while (temp != nullptr) {
if (temp->heading == 255) {
if (!(st->airport.flags & temp->block)) {
/* read which group do we want to go to?
@@ -2109,9 +2109,9 @@ static bool AircraftEventHandler(Aircraft *v, int loop)
/* Check the distance to the next destination. This code works because the target
* airport is only updated after take off and not on the ground. */
Station *cur_st = Station::GetIfValid(v->targetairport);
Station *next_st = v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_DEPOT) ? Station::GetIfValid(v->current_order.GetDestination()) : NULL;
Station *next_st = v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_DEPOT) ? Station::GetIfValid(v->current_order.GetDestination()) : nullptr;
if (cur_st != NULL && cur_st->airport.tile != INVALID_TILE && next_st != NULL && next_st->airport.tile != INVALID_TILE) {
if (cur_st != nullptr && cur_st->airport.tile != INVALID_TILE && next_st != nullptr && next_st->airport.tile != INVALID_TILE) {
uint dist = DistanceSquare(cur_st->airport.tile, next_st->airport.tile);
AircraftHandleDestTooFar(v, dist > v->acache.cached_max_range_sqr);
}
@@ -2147,16 +2147,16 @@ bool Aircraft::Tick()
* Returns aircraft's target station if v->target_airport
* is a valid station with airport.
* @param v vehicle to get target airport for
* @return pointer to target station, NULL if invalid
* @return pointer to target station, nullptr if invalid
*/
Station *GetTargetAirportIfValid(const Aircraft *v)
{
assert(v->type == VEH_AIRCRAFT);
Station *st = Station::GetIfValid(v->targetairport);
if (st == NULL) return NULL;
if (st == nullptr) return nullptr;
return st->airport.tile == INVALID_TILE ? NULL : st;
return st->airport.tile == INVALID_TILE ? nullptr : st;
}
/**