diff options
author | Henry Wilson <m3henry@googlemail.com> | 2019-04-10 22:07:06 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-10 23:22:20 +0200 |
commit | 7c8e7c6b6e16d4a26259a676db32d8776b99817e (patch) | |
tree | 99f134b7e66367cf11e10bc5061896eab4a3264f /src/depot_gui.cpp | |
parent | 3b4f224c0bc50e7248050d4bcbb6d83fd510c1cc (diff) | |
download | openttd-7c8e7c6b6e16d4a26259a676db32d8776b99817e.tar.xz |
Codechange: Use null pointer literal instead of the NULL macro
Diffstat (limited to 'src/depot_gui.cpp')
-rw-r--r-- | src/depot_gui.cpp | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index ffab68536..021195127 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -133,16 +133,16 @@ static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Veh if (v == wagon) return; - if (wagon == NULL) { - if (head != NULL) wagon = head->Last(); + if (wagon == nullptr) { + if (head != nullptr) wagon = head->Last(); } else { wagon = wagon->Previous(); - if (wagon == NULL) return; + if (wagon == nullptr) return; } if (wagon == v) return; - DoCommandP(v->tile, v->index | (_ctrl_pressed ? 1 : 0) << 20, wagon == NULL ? INVALID_VEHICLE : wagon->index, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_MOVE_VEHICLE)); + DoCommandP(v->tile, v->index | (_ctrl_pressed ? 1 : 0) << 20, wagon == nullptr ? INVALID_VEHICLE : wagon->index, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_MOVE_VEHICLE)); } static VehicleCellSize _base_block_sizes_depot[VEH_COMPANY_END]; ///< Cell size for vehicle images in the depot view. @@ -228,7 +228,7 @@ void InitDepotWindowBlockSizes() if (!e->IsEnabled()) continue; uint w = TRAININFO_DEFAULT_VEHICLE_WIDTH; - if (e->GetGRF() != NULL && is_custom_sprite(e->u.rail.image_index)) { + if (e->GetGRF() != nullptr && is_custom_sprite(e->u.rail.image_index)) { w = e->GetGRF()->traininfo_vehicle_width; if (w != VEHICLEINFO_FULL_VEHICLE_WIDTH) { /* Hopeless. @@ -279,7 +279,7 @@ struct DepotWindow : Window { this->unitnumber_digits = 2; this->CreateNestedTree(); - this->hscroll = (this->type == VEH_TRAIN ? this->GetScrollbar(WID_D_H_SCROLL) : NULL); + this->hscroll = (this->type == VEH_TRAIN ? this->GetScrollbar(WID_D_H_SCROLL) : nullptr); this->vscroll = this->GetScrollbar(WID_D_V_SCROLL); /* Don't show 'rename button' of aircraft hangar */ this->GetWidget<NWidgetStacked>(WID_D_SHOW_RENAME)->SetDisplayedPlane(type == VEH_AIRCRAFT ? SZSP_NONE : 0); @@ -469,8 +469,8 @@ struct DepotWindow : Window { /* Clicking on 'line' / 'block' without a vehicle */ if (this->type == VEH_TRAIN) { /* End the dragging */ - d->head = NULL; - d->wagon = NULL; + d->head = nullptr; + d->wagon = nullptr; return MODE_DRAG_VEHICLE; } else { return MODE_ERROR; // empty block, so no vehicle is selected @@ -490,7 +490,7 @@ struct DepotWindow : Window { wagon = true; } - const Train *v = NULL; + const Train *v = nullptr; if (this->type == VEH_TRAIN) { v = Train::From(*veh); d->head = d->wagon = v; @@ -525,12 +525,12 @@ struct DepotWindow : Window { x -= this->header_width; /* find the vehicle in this row that was clicked */ - for (; v != NULL; v = v->Next()) { + for (; v != nullptr; v = v->Next()) { x -= v->GetDisplayImageWidth(); if (x < 0) break; } - d->wagon = (v != NULL ? v->GetFirstEnginePart() : NULL); + d->wagon = (v != nullptr ? v->GetFirstEnginePart() : nullptr); return MODE_DRAG_VEHICLE; } @@ -542,8 +542,8 @@ struct DepotWindow : Window { */ void DepotClick(int x, int y) { - GetDepotVehiclePtData gdvp = { NULL, NULL }; - const Vehicle *v = NULL; + GetDepotVehiclePtData gdvp = { nullptr, nullptr }; + const Vehicle *v = nullptr; DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp); if (this->type == VEH_TRAIN) v = gdvp.wagon; @@ -553,14 +553,14 @@ struct DepotWindow : Window { return; case MODE_DRAG_VEHICLE: { // start dragging of vehicle - if (v != NULL && VehicleClicked(v)) return; + if (v != nullptr && VehicleClicked(v)) return; VehicleID sel = this->sel; if (this->type == VEH_TRAIN && sel != INVALID_VEHICLE) { this->sel = INVALID_VEHICLE; TrainDepotMoveVehicle(v, sel, gdvp.head); - } else if (v != NULL) { + } else if (v != nullptr) { SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this); SetMouseCursorVehicle(v, EIT_IN_DEPOT); _cursor.vehchain = _ctrl_pressed; @@ -728,7 +728,7 @@ struct DepotWindow : Window { uint max_width = ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH); for (uint num = 0; num < this->vehicle_list.size(); num++) { uint width = 0; - for (const Train *v = Train::From(this->vehicle_list[num]); v != NULL; v = v->Next()) { + for (const Train *v = Train::From(this->vehicle_list[num]); v != nullptr; v = v->Next()) { width += v->GetDisplayImageWidth(); } max_width = max(max_width, width); @@ -839,24 +839,24 @@ struct DepotWindow : Window { void OnQueryTextFinished(char *str) override { - if (str == NULL) return; + if (str == nullptr) return; /* Do depot renaming */ - DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), NULL, str); + DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), nullptr, str); } bool OnRightClick(Point pt, int widget) override { if (widget != WID_D_MATRIX) return false; - GetDepotVehiclePtData gdvp = { NULL, NULL }; - const Vehicle *v = NULL; + GetDepotVehiclePtData gdvp = { nullptr, nullptr }; + const Vehicle *v = nullptr; NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX); DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp); if (this->type == VEH_TRAIN) v = gdvp.wagon; - if (v == NULL || mode != MODE_DRAG_VEHICLE) return false; + if (v == nullptr || mode != MODE_DRAG_VEHICLE) return false; CargoArray capacity, loaded; @@ -865,7 +865,7 @@ struct DepotWindow : Window { /* loop through vehicle chain and collect cargoes */ uint num = 0; - for (const Vehicle *w = v; w != NULL; w = w->Next()) { + for (const Vehicle *w = v; w != nullptr; w = w->Next()) { if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) { capacity[w->cargo_type] += w->cargo_cap; loaded [w->cargo_type] += w->cargo.StoredCount(); @@ -910,7 +910,7 @@ struct DepotWindow : Window { { if (_ctrl_pressed) { /* Share-clone, do not open new viewport, and keep tool active */ - DoCommandP(this->window_number, v->index, 1, CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN + v->type), NULL); + DoCommandP(this->window_number, v->index, 1, CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN + v->type), nullptr); } else { /* Copy-clone, open viewport for new vehicle, and deselect the tool (assume player wants to changs things on new vehicle) */ if (DoCommandP(this->window_number, v->index, 0, CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN + v->type), CcCloneVehicle)) { @@ -965,20 +965,20 @@ struct DepotWindow : Window { } NWidgetBase *matrix = this->GetWidget<NWidgetBase>(widget); - const Vehicle *v = NULL; - GetDepotVehiclePtData gdvp = {NULL, NULL}; + const Vehicle *v = nullptr; + GetDepotVehiclePtData gdvp = {nullptr, nullptr}; if (this->GetVehicleFromDepotWndPt(pt.x - matrix->pos_x, pt.y - matrix->pos_y, &v, &gdvp) != MODE_DRAG_VEHICLE) return; VehicleID new_vehicle_over = INVALID_VEHICLE; - if (gdvp.head != NULL) { - if (gdvp.wagon == NULL && gdvp.head->Last()->index != this->sel) { // ..at the end of the train. + if (gdvp.head != nullptr) { + if (gdvp.wagon == nullptr && gdvp.head->Last()->index != this->sel) { // ..at the end of the train. /* NOTE: As a wagon can't be moved at the begin of a train, head index isn't used to mark a drag-and-drop * destination inside a train. This head index is then used to indicate that a wagon is inserted at * the end of the train. */ new_vehicle_over = gdvp.head->index; - } else if (gdvp.wagon != NULL && gdvp.head != gdvp.wagon && + } else if (gdvp.wagon != nullptr && gdvp.head != gdvp.wagon && gdvp.wagon->index != this->sel && gdvp.wagon->Previous()->index != this->sel) { // ..over an existing wagon. new_vehicle_over = gdvp.wagon->index; @@ -995,7 +995,7 @@ struct DepotWindow : Window { { switch (widget) { case WID_D_MATRIX: { - const Vehicle *v = NULL; + const Vehicle *v = nullptr; VehicleID sel = this->sel; this->sel = INVALID_VEHICLE; @@ -1003,20 +1003,20 @@ struct DepotWindow : Window { NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX); if (this->type == VEH_TRAIN) { - GetDepotVehiclePtData gdvp = { NULL, NULL }; + GetDepotVehiclePtData gdvp = { nullptr, nullptr }; if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) { - if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) { + if (gdvp.wagon != nullptr && gdvp.wagon->index == sel && _ctrl_pressed) { DoCommandP(Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE)); - } else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { + } else if (gdvp.wagon == nullptr || gdvp.wagon->index != sel) { this->vehicle_over = INVALID_VEHICLE; TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); - } else if (gdvp.head != NULL && gdvp.head->IsFrontEngine()) { + } else if (gdvp.head != nullptr && gdvp.head->IsFrontEngine()) { ShowVehicleViewWindow(gdvp.head); } } - } else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, NULL) == MODE_DRAG_VEHICLE && v != NULL && sel == v->index) { + } else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, nullptr) == MODE_DRAG_VEHICLE && v != nullptr && sel == v->index) { ShowVehicleViewWindow(v); } break; @@ -1052,7 +1052,7 @@ struct DepotWindow : Window { this->RaiseWidget(WID_D_SELL); this->SetWidgetDirty(WID_D_SELL); } - if (this->nested_array[WID_D_SELL] != NULL && !this->IsWidgetDisabled(WID_D_SELL_CHAIN)) { + if (this->nested_array[WID_D_SELL] != nullptr && !this->IsWidgetDisabled(WID_D_SELL_CHAIN)) { this->RaiseWidget(WID_D_SELL_CHAIN); this->SetWidgetDirty(WID_D_SELL_CHAIN); } @@ -1098,7 +1098,7 @@ static void DepotSellAllConfirmationCallback(Window *win, bool confirmed) */ void ShowDepotWindow(TileIndex tile, VehicleType type) { - if (BringWindowToFrontById(WC_VEHICLE_DEPOT, tile) != NULL) return; + if (BringWindowToFrontById(WC_VEHICLE_DEPOT, tile) != nullptr) return; WindowDesc *desc; switch (type) { @@ -1126,7 +1126,7 @@ void DeleteDepotHighlightOfVehicle(const Vehicle *v) if (_special_mouse_mode != WSM_DRAGDROP) return; w = dynamic_cast<DepotWindow*>(FindWindowById(WC_VEHICLE_DEPOT, v->tile)); - if (w != NULL) { + if (w != nullptr) { if (w->sel == v->index) ResetObjectToPlace(); } } |