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

@@ -183,7 +183,7 @@ static bool CDECL CargoFilter(const Vehicle * const *vid, const CargoID cid)
if (cid == BaseVehicleListWindow::CF_ANY) {
return true;
} else if (cid == BaseVehicleListWindow::CF_NONE) {
for (const Vehicle *w = (*vid); w != NULL; w = w->Next()) {
for (const Vehicle *w = (*vid); w != nullptr; w = w->Next()) {
if (w->cargo_cap > 0) {
return false;
}
@@ -191,7 +191,7 @@ static bool CDECL CargoFilter(const Vehicle * const *vid, const CargoID cid)
return true;
} else if (cid == BaseVehicleListWindow::CF_FREIGHT) {
bool have_capacity = false;
for (const Vehicle *w = (*vid); w != NULL; w = w->Next()) {
for (const Vehicle *w = (*vid); w != nullptr; w = w->Next()) {
if (w->cargo_cap) {
if (IsCargoInClass(w->cargo_type, CC_PASSENGERS)) {
return false;
@@ -202,7 +202,7 @@ static bool CDECL CargoFilter(const Vehicle * const *vid, const CargoID cid)
}
return have_capacity;
} else {
for (const Vehicle *w = (*vid); w != NULL; w = w->Next()) {
for (const Vehicle *w = (*vid); w != nullptr; w = w->Next()) {
if (w->cargo_cap > 0 && w->cargo_type == cid) {
return true;
}
@@ -371,14 +371,14 @@ DropDownList BaseVehicleListWindow::BuildActionDropdownList(bool show_autoreplac
}
/* cached values for VehicleNameSorter to spare many GetString() calls */
static const Vehicle *_last_vehicle[2] = { NULL, NULL };
static const Vehicle *_last_vehicle[2] = { nullptr, nullptr };
void BaseVehicleListWindow::SortVehicleList()
{
if (this->vehicles.Sort()) return;
/* invalidate cached values for name sorter - vehicle names could change */
_last_vehicle[0] = _last_vehicle[1] = NULL;
_last_vehicle[0] = _last_vehicle[1] = nullptr;
}
void DepotSortList(VehicleList *list)
@@ -425,7 +425,7 @@ byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_t
/* Create a list of subtypes used by the various parts of v_for */
static std::vector<StringID> subtypes;
subtypes.clear();
for (; v_from != NULL; v_from = v_from->HasArticulatedPart() ? v_from->GetNextArticulatedPart() : NULL) {
for (; v_from != nullptr; v_from = v_from->HasArticulatedPart() ? v_from->GetNextArticulatedPart() : nullptr) {
const Engine *e_from = v_from->GetEngine();
if (!e_from->CanCarryCargo() || !HasBit(e_from->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue;
include(subtypes, GetCargoSubtypeText(v_from));
@@ -435,7 +435,7 @@ byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_t
bool success = false;
if (subtypes.size() > 0) {
/* Check whether any articulated part is refittable to 'dest_cargo_type' with a subtype listed in 'subtypes' */
for (Vehicle *v = v_for; v != NULL; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : NULL) {
for (Vehicle *v = v_for; v != nullptr; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr) {
const Engine *e = v->GetEngine();
if (!e->CanCarryCargo() || !HasBit(e->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue;
if (!HasBit(e->info.refit_mask, dest_cargo_type) && v->cargo_type != dest_cargo_type) continue;
@@ -492,7 +492,7 @@ const Vehicle *GetMostSeverelyBrokenEngine(const Train *v)
assert(v->IsFrontEngine());
const Vehicle *w = v;
byte most_severe_type = 255;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
if (u->breakdown_ctr == 1) {
if (u->breakdown_type < most_severe_type) {
most_severe_type = u->breakdown_type;
@@ -723,7 +723,7 @@ struct RefitWindow : public Window {
}
current_index++;
}
} while (v->IsGroundVehicle() && (v = v->Next()) != NULL);
} while (v->IsGroundVehicle() && (v = v->Next()) != nullptr);
}
/**
@@ -786,10 +786,10 @@ struct RefitWindow : public Window {
*/
RefitOption *GetRefitOption()
{
if (this->sel[0] < 0) return NULL;
if (this->sel[0] < 0) return nullptr;
SubtypeList &l = this->list[this->sel[0]];
if ((uint)this->sel[1] >= l.size()) return NULL;
if ((uint)this->sel[1] >= l.size()) return nullptr;
return &l[this->sel[1]];
}
@@ -804,7 +804,7 @@ struct RefitWindow : public Window {
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_VR_SCROLLBAR);
this->hscroll = (v->IsGroundVehicle() ? this->GetScrollbar(WID_VR_HSCROLLBAR) : NULL);
this->hscroll = (v->IsGroundVehicle() ? this->GetScrollbar(WID_VR_HSCROLLBAR) : nullptr);
this->GetWidget<NWidgetCore>(WID_VR_SELECT_HEADER)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
this->GetWidget<NWidgetCore>(WID_VR_MATRIX)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_VR_REFIT);
@@ -856,7 +856,7 @@ struct RefitWindow : public Window {
void OnInit() override
{
if (this->cargo != NULL) {
if (this->cargo != nullptr) {
/* Store the RefitOption currently in use. */
RefitOption current_refit_option = *(this->cargo);
@@ -864,8 +864,8 @@ struct RefitWindow : public Window {
this->BuildRefitList();
this->sel[0] = -1;
this->sel[1] = 0;
this->cargo = NULL;
for (uint i = 0; this->cargo == NULL && i < NUM_CARGO; i++) {
this->cargo = nullptr;
for (uint i = 0; this->cargo == nullptr && i < NUM_CARGO; i++) {
for (uint j = 0; j < list[i].size(); j++) {
if (list[i][j] == current_refit_option) {
this->sel[0] = i;
@@ -887,7 +887,7 @@ struct RefitWindow : public Window {
void OnPaint() override
{
/* Determine amount of items for scroller. */
if (this->hscroll != NULL) this->hscroll->SetCount(this->vehicle_width);
if (this->hscroll != nullptr) this->hscroll->SetCount(this->vehicle_width);
/* Calculate sprite position. */
NWidgetCore *vehicle_panel_display = this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY);
@@ -981,7 +981,7 @@ struct RefitWindow : public Window {
case WID_VR_VEHICLE_PANEL_DISPLAY: {
Vehicle *v = Vehicle::Get(this->window_number);
DrawVehicleImage(v, this->sprite_left + WD_FRAMERECT_LEFT, this->sprite_right - WD_FRAMERECT_RIGHT,
r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, EIT_IN_DETAILS, this->hscroll != NULL ? this->hscroll->GetPosition() : 0);
r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, EIT_IN_DETAILS, this->hscroll != nullptr ? this->hscroll->GetPosition() : 0);
/* Highlight selected vehicles. */
if (this->order != INVALID_VEH_ORDER_ID) break;
@@ -994,7 +994,7 @@ struct RefitWindow : public Window {
int left = INT32_MIN;
int width = 0;
for (Train *u = Train::From(v); u != NULL; u = u->Next()) {
for (Train *u = Train::From(v); u != nullptr; u = u->Next()) {
/* Start checking. */
const bool contained = std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), u->index) != vehicles_to_refit.end();
if (contained && left == INT32_MIN) {
@@ -1003,8 +1003,8 @@ struct RefitWindow : public Window {
}
/* Draw a selection. */
if ((!contained || u->Next() == NULL) && left != INT32_MIN) {
if (u->Next() == NULL && contained) {
if ((!contained || u->Next() == nullptr) && left != INT32_MIN) {
if (u->Next() == nullptr && contained) {
int current_width = u->GetDisplayImageWidth();
width += current_width;
x += current_width;
@@ -1042,7 +1042,7 @@ struct RefitWindow : public Window {
break;
case WID_VR_INFO:
if (this->cargo != NULL) {
if (this->cargo != nullptr) {
StringID string = this->GetCapacityString(this->cargo);
if (string != INVALID_STRING_ID) {
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT,
@@ -1109,7 +1109,7 @@ struct RefitWindow : public Window {
const NWidgetCore *matrix_widget = this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY);
if (_current_text_dir == TD_RTL) click_x = matrix_widget->current_x - click_x;
click_x -= this->vehicle_margin;
if (this->hscroll != NULL) click_x += this->hscroll->GetPosition();
if (this->hscroll != nullptr) click_x += this->hscroll->GetPosition();
return click_x;
}
@@ -1130,7 +1130,7 @@ struct RefitWindow : public Window {
if (left_x >= 0) {
const Train *u = Train::From(v);
bool start_counting = false;
for (; u != NULL; u = u->Next()) {
for (; u != nullptr; u = u->Next()) {
int current_width = u->GetDisplayImageWidth();
left_x -= current_width;
right_x -= current_width;
@@ -1194,7 +1194,7 @@ struct RefitWindow : public Window {
}
case WID_VR_REFIT: // refit button
if (this->cargo != NULL) {
if (this->cargo != nullptr) {
const Vehicle *v = Vehicle::Get(this->window_number);
if (this->order == INVALID_VEH_ORDER_ID) {
@@ -1241,7 +1241,7 @@ struct RefitWindow : public Window {
{
this->vehicle_width = GetVehicleWidth(Vehicle::Get(this->window_number), EIT_IN_DETAILS);
this->vscroll->SetCapacityFromWidget(this, WID_VR_MATRIX);
if (this->hscroll != NULL) this->hscroll->SetCapacityFromWidget(this, WID_VR_VEHICLE_PANEL_DISPLAY);
if (this->hscroll != nullptr) this->hscroll->SetCapacityFromWidget(this, WID_VR_VEHICLE_PANEL_DISPLAY);
}
};
@@ -1399,8 +1399,8 @@ static int CDECL VehicleCargoSorter(const Vehicle * const *a, const Vehicle * co
CargoArray diff;
/* Append the cargo of the connected waggons */
for (v = *a; v != NULL; v = v->Next()) diff[v->cargo_type] += v->cargo_cap;
for (v = *b; v != NULL; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap;
for (v = *a; v != nullptr; v = v->Next()) diff[v->cargo_type] += v->cargo_cap;
for (v = *b; v != nullptr; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap;
int r = 0;
for (CargoID i = 0; i < NUM_CARGO; i++) {
@@ -1438,8 +1438,8 @@ static int CDECL VehicleValueSorter(const Vehicle * const *a, const Vehicle * co
const Vehicle *u;
Money diff = 0;
for (u = *a; u != NULL; u = u->Next()) diff += u->value;
for (u = *b; u != NULL; u = u->Next()) diff -= u->value;
for (u = *a; u != nullptr; u = u->Next()) diff += u->value;
for (u = *b; u != nullptr; u = u->Next()) diff -= u->value;
int r = ClampToI32(diff);
return (r != 0) ? r : VehicleNumberSorter(a, b);
@@ -1487,10 +1487,10 @@ void InitializeGUI()
static inline void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
{
Window *w = FindWindowById(window_class, from_index);
if (w != NULL) {
if (w != nullptr) {
/* Update window_number */
w->window_number = to_index;
if (w->viewport != NULL) w->viewport->follow_vehicle = to_index;
if (w->viewport != nullptr) w->viewport->follow_vehicle = to_index;
/* Update vehicle drag data */
if (_thd.window_class == window_class && _thd.window_number == (WindowNumber)from_index) {
@@ -1563,7 +1563,7 @@ static const NWidgetPart _nested_vehicle_list[] = {
static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, VehicleOrderID start = 0)
{
const Order *order = v->GetOrder(start);
if (order == NULL) return;
if (order == nullptr) return;
bool rtl = _current_text_dir == TD_RTL;
int l_offset = rtl ? 0 : ScaleGUITrad(6);
@@ -1584,7 +1584,7 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, Veh
oid++;
order = order->next;
if (order == NULL) {
if (order == nullptr) {
order = v->orders.list->GetFirstOrder();
oid = 0;
}
@@ -1677,7 +1677,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
case VST_CARGO: {
CargoTypes cargoes = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
if (u->cargo_cap > 0) SetBit(cargoes, u->cargo_type);
}
str = STR_VEHICLE_LIST_CARGO;
@@ -1706,7 +1706,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
case VST_VALUE: {
Money total_value = 0;
for (const Vehicle *u = v; u != NULL; u = u->GetNextVehicle()) {
for (const Vehicle *u = v; u != nullptr; u = u->GetNextVehicle()) {
total_value += u->value;
}
str = STR_VEHICLE_LIST_VALUE;
@@ -1770,13 +1770,13 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
if (_settings_client.gui.show_vehicle_list_company_colour && v->owner != this->vli.company) {
byte ccolour = 0;
Company *c = Company::Get(v->owner);
if (c != NULL) {
if (c != nullptr) {
ccolour = _colour_gradient[c->colour][6];
}
GfxFillRect((text_right - 1) - (FONT_HEIGHT_SMALL - 2), y + 1, text_right - 1, (y + 1) + (FONT_HEIGHT_SMALL - 2), ccolour, FILLRECT_OPAQUE);
}
if (v->name != NULL) {
if (v->name != nullptr) {
/* The vehicle got a name so we will print it */
SetDParam(0, v->index);
DrawString(text_left, text_right, y, STR_TINY_BLACK_VEHICLE);
@@ -2110,7 +2110,7 @@ public:
void OnQueryTextFinished(char *str) override
{
DoCommandP(0, this->window_number, 0, CMD_CREATE_GROUP_FROM_LIST | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), NULL, str);
DoCommandP(0, this->window_number, 0, CMD_CREATE_GROUP_FROM_LIST | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), nullptr, str);
}
virtual void OnPlaceObject(Point pt, TileIndex tile)
@@ -2362,7 +2362,7 @@ struct VehicleDetailsWindow : Window {
const Vehicle *v = Vehicle::Get(window_number);
this->CreateNestedTree();
this->vscroll = (v->type == VEH_TRAIN ? this->GetScrollbar(WID_VD_SCROLLBAR) : NULL);
this->vscroll = (v->type == VEH_TRAIN ? this->GetScrollbar(WID_VD_SCROLLBAR) : nullptr);
this->FinishInitNested(window_number);
this->GetWidget<NWidgetCore>(WID_VD_RENAME_VEHICLE)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->type;
@@ -2425,7 +2425,7 @@ struct VehicleDetailsWindow : Window {
/* An articulated RV has its text drawn under the sprite instead of after it, hence 15 pixels extra. */
desired_height = WD_FRAMERECT_TOP + ScaleGUITrad(15) + 4 * FONT_HEIGHT_NORMAL + 3 + WD_FRAMERECT_BOTTOM;
/* Add space for the cargo amount for each part. */
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
if (u->cargo_cap != 0) desired_height += FONT_HEIGHT_NORMAL + 1;
}
} else {
@@ -2669,7 +2669,7 @@ struct VehicleDetailsWindow : Window {
/* we want to draw the average reliability and total number of breakdowns */
uint32 total_reliability = 0;
uint16 total_breakdowns = 0;
for (const Vehicle *w = v; w != NULL; w = w->Next()) {
for (const Vehicle *w = v; w != nullptr; w = w->Next()) {
if (Train::From(w)->IsEngine() || Train::From(w)->IsMultiheaded()) {
total_reliability += w->reliability;
total_breakdowns += w->breakdowns_since_last_service;
@@ -2847,15 +2847,15 @@ struct VehicleDetailsWindow : Window {
void OnQueryTextFinished(char *str) override
{
if (str == NULL) return;
if (str == nullptr) return;
DoCommandP(0, this->window_number, 0, CMD_RENAME_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type), NULL, str);
DoCommandP(0, this->window_number, 0, CMD_RENAME_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type), nullptr, str);
}
void OnResize() override
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_VD_MATRIX);
if (nwi != NULL) {
if (nwi != nullptr) {
this->vscroll->SetCapacityFromWidget(this, WID_VD_MATRIX);
}
}
@@ -3032,7 +3032,7 @@ void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, ui
if (result.Failed()) return;
const Vehicle *v = Vehicle::GetIfValid(p1);
if (v == NULL || !v->IsPrimaryVehicle() || v->owner != _local_company) return;
if (v == nullptr || !v->IsPrimaryVehicle() || v->owner != _local_company) return;
StringID msg = (v->vehstatus & VS_STOPPED) ? STR_VEHICLE_COMMAND_STOPPED : STR_VEHICLE_COMMAND_STARTED;
Point pt = RemapCoords(v->x_pos, v->y_pos, v->z_pos);
@@ -3047,7 +3047,7 @@ void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, ui
void StartStopVehicle(const Vehicle *v, bool texteffect)
{
assert(v->IsPrimaryVehicle());
DoCommandP(v->tile, v->index, 0, _vehicle_command_translation_table[VCT_CMD_START_STOP][v->type], texteffect ? CcStartStopVehicle : NULL);
DoCommandP(v->tile, v->index, 0, _vehicle_command_translation_table[VCT_CMD_START_STOP][v->type], texteffect ? CcStartStopVehicle : nullptr);
}
/** Strings for aircraft breakdown types */
@@ -3064,7 +3064,7 @@ static bool IsVehicleRefitable(const Vehicle *v)
do {
if (IsEngineRefittable(v->engine_type)) return true;
} while (v->IsGroundVehicle() && (v = v->Next()) != NULL);
} while (v->IsGroundVehicle() && (v = v->Next()) != nullptr);
return false;
}
@@ -3470,7 +3470,7 @@ public:
* most likely already open, but is also visible in the vehicle viewport. */
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0,
_vehicle_command_translation_table[VCT_CMD_CLONE_VEH][v->type],
_ctrl_pressed ? NULL : CcCloneVehicle);
_ctrl_pressed ? nullptr : CcCloneVehicle);
break;
case WID_VV_TURN_AROUND: // turn around
assert(v->IsGroundVehicle());
@@ -3550,7 +3550,7 @@ public:
void OnResize() override
{
if (this->viewport != NULL) {
if (this->viewport != nullptr) {
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT);
nvp->UpdateViewportCoordinates(this);
}
@@ -3627,7 +3627,7 @@ void ShowVehicleViewWindow(const Vehicle *v)
*/
bool VehicleClicked(const Vehicle *v)
{
assert(v != NULL);
assert(v != nullptr);
if (!(_thd.place_mode & HT_VEHICLE)) return false;
v = v->First();
@@ -3639,7 +3639,7 @@ bool VehicleClicked(const Vehicle *v)
void StopGlobalFollowVehicle(const Vehicle *v)
{
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
if (w != NULL && w->viewport->follow_vehicle == v->index) {
if (w != nullptr && w->viewport->follow_vehicle == v->index) {
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos, true); // lock the main view on the vehicle's last position
w->viewport->follow_vehicle = INVALID_VEHICLE;
}
@@ -3693,7 +3693,7 @@ int GetVehicleWidth(const Vehicle *v, EngineImageType image_type)
{
if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
int vehicle_width = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
vehicle_width += GetSingleVehicleWidth(u, image_type);
}
return vehicle_width;
@@ -3713,7 +3713,7 @@ void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
_cursor.sprite_count = 0;
int total_width = 0;
for (; v != NULL; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : NULL) {
for (; v != nullptr; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr) {
if (total_width >= 2 * (int)VEHICLEINFO_FULL_VEHICLE_WIDTH) break;
PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);