From ece3cc68d59f052d744ca33fcfe29d1063b41a8c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 24 Sep 2023 12:48:34 +0300 Subject: [PATCH 41/41] Replace all NULLs with nullptr in C++ code See osdn #48620 Signed-off-by: Marko Lindqvist --- client/gui-qt/canvas.cpp | 14 +- client/gui-qt/chatline.cpp | 4 +- client/gui-qt/citydlg.cpp | 160 ++++++++------- client/gui-qt/cityrep.cpp | 27 +-- client/gui-qt/dialogs.cpp | 362 +++++++++++++++++---------------- client/gui-qt/diplodlg.cpp | 18 +- client/gui-qt/fc_client.cpp | 86 ++++---- client/gui-qt/gotodlg.cpp | 12 +- client/gui-qt/gui_main.cpp | 2 +- client/gui-qt/helpdlg.cpp | 44 ++-- client/gui-qt/hudwidget.cpp | 2 +- client/gui-qt/mapctrl.cpp | 8 +- client/gui-qt/mapview.cpp | 6 +- client/gui-qt/menu.cpp | 70 ++++--- client/gui-qt/messagewin.cpp | 6 +- client/gui-qt/optiondlg.cpp | 10 +- client/gui-qt/pages.cpp | 64 +++--- client/gui-qt/plrdlg.cpp | 30 +-- client/gui-qt/repodlgs.cpp | 45 ++-- client/gui-qt/sidebar.cpp | 2 +- client/gui-qt/sprite.cpp | 8 +- client/gui-qt/voteinfo_bar.cpp | 26 +-- tools/fcmp/mpgui_qt.cpp | 2 +- tools/fcmp/mpgui_qt.h | 2 +- tools/fcmp/mpgui_qt_worker.h | 2 +- tools/ruledit/effect_edit.cpp | 12 +- tools/ruledit/req_edit.cpp | 4 +- tools/ruledit/ruledit.cpp | 6 +- tools/ruledit/ruledit_qt.cpp | 12 +- tools/ruledit/tab_enablers.cpp | 8 +- tools/ruledit/tab_misc.cpp | 10 +- tools/ruledit/tab_nation.cpp | 8 +- 32 files changed, 552 insertions(+), 520 deletions(-) diff --git a/client/gui-qt/canvas.cpp b/client/gui-qt/canvas.cpp index cc73f38dfc..68837a290f 100644 --- a/client/gui-qt/canvas.cpp +++ b/client/gui-qt/canvas.cpp @@ -324,9 +324,9 @@ void qtg_canvas_put_curved_line(struct canvas *pcanvas, struct color *pcolor, } /************************************************************************//** - Return the size of the given text in the given font. This size should - include the ascent and descent of the text. Either of width or height - may be NULL in which case those values simply shouldn't be filled out. + Return the size of the given text in the given font. This size should + include the ascent and descent of the text. Either of width or height + may be nullptr in which case those values simply shouldn't be filled out. ****************************************************************************/ void qtg_get_text_size(int *width, int *height, enum client_font font, const char *text) @@ -347,9 +347,9 @@ void qtg_get_text_size(int *width, int *height, } /************************************************************************//** - Draw the text onto the canvas in the given color and font. The canvas + Draw the text onto the canvas in the given color and font. The canvas position does not account for the ascent of the text; this function must - take care of this manually. The text will not be NULL but may be empty. + take care of this manually. The text will not be nullptr but may be empty. ****************************************************************************/ void qtg_canvas_put_text(struct canvas *pcanvas, int canvas_x, int canvas_y, enum client_font font, struct color *pcolor, @@ -404,10 +404,10 @@ QFont *get_font(client_font font) qf = fc_font::instance()->get_font(fonts::reqtree_text); break; case FONT_COUNT: - qf = NULL; + qf = nullptr; break; default: - qf = NULL; + qf = nullptr; break; } return qf; diff --git a/client/gui-qt/chatline.cpp b/client/gui-qt/chatline.cpp index abcb6c42d4..02783f1fd9 100644 --- a/client/gui-qt/chatline.cpp +++ b/client/gui-qt/chatline.cpp @@ -773,7 +773,7 @@ void qtg_real_output_window_append(const char *astring, if (str.contains(wakeup) && client_state() < C_S_RUNNING && !wakeup.isEmpty()) { qapp->alert(gui()->central_wdg); - audio_play_sound("e_player_wake", NULL); + audio_play_sound("e_player_wake", nullptr); } chat_listener::update_word_list(); @@ -788,7 +788,7 @@ void qtg_real_output_window_append(const char *astring, void log_output_window(void) { // PORTME - write_chatline_content(NULL); + write_chatline_content(nullptr); } /***********************************************************************//** diff --git a/client/gui-qt/citydlg.cpp b/client/gui-qt/citydlg.cpp index 54d12cadb5..4ee2065d35 100644 --- a/client/gui-qt/citydlg.cpp +++ b/client/gui-qt/citydlg.cpp @@ -808,20 +808,20 @@ void unit_item::create_actions() sentry = new QAction(_("Sentry unit"), this); connect(sentry, &QAction::triggered, this, &unit_item::sentry_unit); } else { - sentry = NULL; + sentry = nullptr; } if (can_unit_do_activity(qunit, ACTIVITY_FORTIFYING)) { fortify = new QAction(_("Fortify unit"), this); connect(fortify, &QAction::triggered, this, &unit_item::fortify_unit); } else { - fortify = NULL; + fortify = nullptr; } if (unit_can_do_action(qunit, ACTION_DISBAND_UNIT)) { disband_action = new QAction(_("Disband unit"), this); connect(disband_action, &QAction::triggered, this, &unit_item::disband); } else { - disband_action = NULL; + disband_action = nullptr; } if (can_unit_change_homecity(qunit)) { @@ -829,35 +829,35 @@ void unit_item::create_actions() this); connect(change_home, &QAction::triggered, this, &unit_item::change_homecity); } else { - change_home = NULL; + change_home = nullptr; } if (units_can_load(qunits)) { load = new QAction(_("Load"), this); connect(load, &QAction::triggered, this, &unit_item::load_unit); } else { - load = NULL; + load = nullptr; } if (units_can_unload(&(wld.map), qunits)) { unload = new QAction(_("Unload"), this); connect(unload, &QAction::triggered, this, &unit_item::unload_unit); } else { - unload = NULL; + unload = nullptr; } if (units_are_occupied(qunits)) { unload_trans = new QAction(_("Unload All From Transporter"), this); connect(unload_trans, &QAction::triggered, this, &unit_item::unload_all); } else { - unload_trans = NULL; + unload_trans = nullptr; } if (units_can_upgrade(qunits)) { upgrade = new QAction(_("Upgrade Unit"), this); connect(upgrade, &QAction::triggered, this, &unit_item::upgrade_unit); } else { - upgrade = NULL; + upgrade = nullptr; } unit_list_destroy(qunits); @@ -1173,7 +1173,7 @@ void city_label::mousePressEvent(QMouseEvent *event) int w = tileset_small_sprite_width(tileset) / gui()->map_scale; int num_citizens = pcity->size; - if (cma_is_city_under_agent(pcity, NULL)) { + if (cma_is_city_under_agent(pcity, nullptr)) { return; } @@ -1238,7 +1238,7 @@ void city_map::paintEvent(QPaintEvent *event) painter.begin(this); painter.drawPixmap(0, 0, zoomed_pixmap); - if (cma_is_city_under_agent(mcity, NULL)) { + if (cma_is_city_under_agent(mcity, nullptr)) { painter.fillRect(0, 0, zoomed_pixmap.width(), zoomed_pixmap.height(), QBrush(QColor(60, 60 , 60 , 110))); painter.setPen(QColor(255, 255, 255)); @@ -1372,38 +1372,38 @@ void city_map::context_menu(QPoint point) con_menu = new QMenu(this); con_menu->addAction(wid_act); - if (pterr->plant_result != NULL - && action_id_univs_not_blocking(ACTION_PLANT, NULL, &for_terr)) { + if (pterr->plant_result != nullptr + && action_id_univs_not_blocking(ACTION_PLANT, nullptr, &for_terr)) { con_plant = con_menu->addAction(_("Plant")); } - if (action_id_univs_not_blocking(ACTION_MINE, NULL, &for_terr)) { + if (action_id_univs_not_blocking(ACTION_MINE, nullptr, &for_terr)) { con_mine = con_menu->addAction(Q_("?act:Mine")); } - if (pterr->cultivate_result != NULL - && action_id_univs_not_blocking(ACTION_CULTIVATE, NULL, &for_terr)) { + if (pterr->cultivate_result != nullptr + && action_id_univs_not_blocking(ACTION_CULTIVATE, nullptr, &for_terr)) { con_cultivate = con_menu->addAction(_("Cultivate")); } - if (action_id_univs_not_blocking(ACTION_IRRIGATE, NULL, &for_terr)) { + if (action_id_univs_not_blocking(ACTION_IRRIGATE, nullptr, &for_terr)) { con_irrig = con_menu->addAction(_("Irrigate")); } - if (pterr->transform_result != pterr && pterr->transform_result != NULL + if (pterr->transform_result != pterr && pterr->transform_result != nullptr && action_id_univs_not_blocking(ACTION_TRANSFORM_TERRAIN, - NULL, &for_terr)) { + nullptr, &for_terr)) { con_trfrm = con_menu->addAction(_("Transform")); } - if (next_extra_for_tile(ptile, EC_ROAD, city_owner(mcity), NULL) != NULL) { + if (next_extra_for_tile(ptile, EC_ROAD, city_owner(mcity), nullptr) != nullptr) { con_road = con_menu->addAction(_("Road")); } if (prev_extra_in_tile(ptile, ERM_CLEAN, - city_owner(mcity), NULL) != NULL) { + city_owner(mcity), nullptr) != nullptr) { con_clean = con_menu->addAction(_("Clean")); } - if (ptask != NULL) { + if (ptask != nullptr) { con_clear = con_menu->addAction(_("Clear")); } @@ -1452,14 +1452,14 @@ void city_map::context_menu(QPoint point) struct extra_type *tgt; if (cause != EC_NONE) { - tgt = next_extra_for_tile(ptile, cause, city_owner(mcity), NULL); + tgt = next_extra_for_tile(ptile, cause, city_owner(mcity), nullptr); } else if (rmcause != ERM_NONE) { - tgt = prev_extra_in_tile(ptile, rmcause, city_owner(mcity), NULL); + tgt = prev_extra_in_tile(ptile, rmcause, city_owner(mcity), nullptr); } else { - tgt = NULL; + tgt = nullptr; } - if (tgt != NULL) { + if (tgt != nullptr) { task.tgt = extra_index(tgt); } else { task.tgt = -1; @@ -1516,7 +1516,7 @@ city_dialog::city_dialog(QWidget *parent): qfc_dialog(parent) setMouseTracking(true); selected_row_p = -1; - dlgcity = NULL; + dlgcity = nullptr; lcity_name = new QPushButton(this); lcity_name->setToolTip(_("Click to change city name")); @@ -1565,7 +1565,7 @@ city_dialog::city_dialog(QWidget *parent): qfc_dialog(parent) connect(lcity_name, &QAbstractButton::clicked, this, &city_dialog::city_rename); citizens_label = new city_label(FEELING_FINAL, this); - citizen_pixmap = NULL; + citizen_pixmap = nullptr; view = new city_map(this); zoom_vbox = new QVBoxLayout(); @@ -2120,8 +2120,10 @@ void city_dialog::show_happiness() ****************************************************************************/ void city_dialog::update_disabled() { - if (NULL == client.conn.playing - || city_owner(dlgcity) != client.conn.playing) { + struct player *pplayer = client_player(); + + if (pplayer == nullptr + || city_owner(dlgcity) != pplayer) { prev_city_but->setDisabled(true); next_city_but->setDisabled(true); buy_button->setDisabled(true); @@ -2130,9 +2132,6 @@ void city_dialog::update_disabled() current_units->setDisabled(true); supported_units->setDisabled(true); view->setDisabled(true); - - if (!client_is_observer()) { - } } else { prev_city_but->setEnabled(true); next_city_but->setEnabled(true); @@ -2158,12 +2157,15 @@ void city_dialog::update_disabled() ****************************************************************************/ void city_dialog::update_prod_buttons() { + struct player *pplayer = client_player(); + work_next_but->setDisabled(true); work_prev_but->setDisabled(true); work_add_but->setDisabled(true); work_rem_but->setDisabled(true); - if (client.conn.playing && city_owner(dlgcity) == client.conn.playing) { + if (pplayer != nullptr + && city_owner(dlgcity) == pplayer) { work_add_but->setEnabled(true); if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount()) { @@ -2379,7 +2381,7 @@ void city_dialog::save_cma() ****************************************************************************/ void city_dialog::cma_enable() { - if (cma_is_city_under_agent(dlgcity, NULL)) { + if (cma_is_city_under_agent(dlgcity, nullptr)) { cma_release_city(dlgcity); return; @@ -2421,7 +2423,7 @@ void city_dialog::cma_double_clicked(int row, int column) return; } param = cmafec_preset_get_parameter(row); - if (cma_is_city_under_agent(dlgcity, NULL)) { + if (cma_is_city_under_agent(dlgcity, nullptr)) { cma_release_city(dlgcity); } @@ -2453,7 +2455,7 @@ void city_dialog::cma_selected(const QItemSelection &sl, param = cmafec_preset_get_parameter(ind); update_sliders(); - if (cma_is_city_under_agent(dlgcity, NULL)) { + if (cma_is_city_under_agent(dlgcity, nullptr)) { cma_release_city(dlgcity); cma_put_city_under_agent(dlgcity, param); } @@ -2539,7 +2541,7 @@ void city_dialog::update_cma_tab() cma_table->setItem(0, 0, item); } - if (cma_is_city_under_agent(dlgcity, NULL)) { + if (cma_is_city_under_agent(dlgcity, nullptr)) { view->update(); s = QString(cmafec_get_short_descr_of_city(dlgcity)); pix = style()->standardPixmap(QStyle::SP_DialogApplyButton); @@ -2561,7 +2563,7 @@ void city_dialog::update_cma_tab() cma_result->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); } - if (cma_is_city_under_agent(dlgcity, NULL)) { + if (cma_is_city_under_agent(dlgcity, nullptr)) { cmafec_get_fe_parameter(dlgcity, ¶m); i = cmafec_preset_get_index_of_parameter(const_cast (¶m)); @@ -2610,7 +2612,7 @@ void city_dialog::cma_remove() ****************************************************************************/ void city_dialog::cma_toggle_changed(int val) { - if (cma_is_city_under_agent(dlgcity, NULL)) { + if (cma_is_city_under_agent(dlgcity, nullptr)) { cma_changed(); update_cma_tab(); } @@ -2635,7 +2637,7 @@ void city_dialog::cma_slider(int value) label = reinterpret_cast(qvar.value()); label->setText(QString::number(value)); - if (cma_is_city_under_agent(dlgcity, NULL)) { + if (cma_is_city_under_agent(dlgcity, nullptr)) { cma_changed(); update_cma_tab(); } @@ -2788,15 +2790,16 @@ void city_dialog::update_buy_button() { QString str; int value; + struct player *pplayer = client_player(); buy_button->setDisabled(true); - if (!client_is_observer() && client.conn.playing != NULL) { + if (!client_is_observer() && pplayer != nullptr) { value = dlgcity->client.buy_cost; str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)", value)).arg(QString::number(value)); - if (client.conn.playing->economic.gold >= value && value != 0) { + if (pplayer->economic.gold >= value && value != 0) { buy_button->setEnabled(true); } } else { @@ -2929,7 +2932,7 @@ void city_dialog::update_nation_table() { QFont f = QApplication::font(); QFontMetrics fm(f); - QPixmap *pix = NULL; + QPixmap *pix = nullptr; QPixmap pix_scaled; QString str; QStringList info_list; @@ -2972,7 +2975,7 @@ void city_dialog::update_nation_table() nation_of_player (player_slot_get_player(pslot))); - if (sprite != NULL) { + if (sprite != nullptr) { pix = sprite->pm; pix_scaled = pix->scaledToHeight(h); item->setData(Qt::DecorationRole, pix_scaled); @@ -3090,7 +3093,7 @@ void city_dialog::update_info_label() fc_snprintf(buf_info[INFO_ILLNESS], sizeof(buf_info[INFO_ILLNESS]), " -.-"); } else { - illness = city_illness_calc(dlgcity, NULL, NULL, NULL, NULL); + illness = city_illness_calc(dlgcity, nullptr, nullptr, nullptr, nullptr); // Illness is in tenth of percent fc_snprintf(buf_info[INFO_ILLNESS], sizeof(buf_info[INFO_ILLNESS]), "%5.1f%%", (float) illness / 10.0); @@ -3164,11 +3167,13 @@ void city_dialog::update_units() int n; int happy_cost; int free_unhappy = get_city_bonus(dlgcity, EFT_MAKE_CONTENT_MIL); + struct player *pplayer = client_player(); + supported_units->setUpdatesEnabled(false); supported_units->clear_layout(); - if (NULL != client.conn.playing - && city_owner(dlgcity) != client.conn.playing) { + if (pplayer != nullptr + && city_owner(dlgcity) != pplayer) { units = dlgcity->client.info_units_supported; } else { units = dlgcity->units_supported; @@ -3188,8 +3193,8 @@ void city_dialog::update_units() current_units->setUpdatesEnabled(true); current_units->clear_layout(); - if (NULL != client.conn.playing - && city_owner(dlgcity) != client.conn.playing) { + if (pplayer != nullptr + && city_owner(dlgcity) != pplayer) { units = dlgcity->client.info_units_present; } else { units = dlgcity->tile->units; @@ -3233,29 +3238,30 @@ void city_dialog::item_selected(const QItemSelection &sl, void city_dialog::next_city() { int size, i; - struct city *other_pcity = NULL; + struct city *other_pcity = nullptr; + struct player *pplayer = client_player(); - if (NULL == client.conn.playing) { + if (pplayer == nullptr) { return; } - size = city_list_size(client.conn.playing->cities); + size = city_list_size(pplayer->cities); if (size <= 1) { return; } for (i = 0; i < size; i++) { - if (dlgcity == city_list_get(client.conn.playing->cities, i)) { + if (dlgcity == city_list_get(pplayer->cities, i)) { break; } } if (i >= size - 1) { // Current city last in the list (size - 1) or disappeared (size) - other_pcity = city_list_get(client.conn.playing->cities, 0); + other_pcity = city_list_get(pplayer->cities, 0); } else { - other_pcity = city_list_get(client.conn.playing->cities, i + 1); + other_pcity = city_list_get(pplayer->cities, i + 1); } center_tile_mapcanvas(other_pcity->tile); @@ -3268,29 +3274,30 @@ void city_dialog::next_city() void city_dialog::prev_city() { int size, i; - struct city *other_pcity = NULL; + struct city *other_pcity = nullptr; + struct player *pplayer = client_player(); - if (NULL == client.conn.playing) { + if (pplayer == nullptr) { return; } - size = city_list_size(client.conn.playing->cities); + size = city_list_size(pplayer->cities); if (size <= 1) { return; } for (i = 0; i < size; i++) { - if (dlgcity == city_list_get(client.conn.playing->cities, i)) { + if (dlgcity == city_list_get(pplayer->cities, i)) { break; } } if (i == 0 || i == size) { // Current city in the beginning of the list or disappeared - other_pcity = city_list_get(client.conn.playing->cities, size - 1); + other_pcity = city_list_get(pplayer->cities, size - 1); } else { - other_pcity = city_list_get(client.conn.playing->cities, i - 1); + other_pcity = city_list_get(pplayer->cities, i - 1); } center_tile_mapcanvas(other_pcity->tile); @@ -3372,7 +3379,7 @@ void city_dialog::update_improvements() { QFont f = QApplication::font(); QFontMetrics fm(f); - QPixmap *pix = NULL; + QPixmap *pix = nullptr; QPixmap pix_scaled; QString str, tooltip; QTableWidgetItem *qitem; @@ -3417,7 +3424,7 @@ void city_dialog::update_improvements() if (VUT_UTYPE == target.kind) { str = utype_values_translation(target.value.utype); - cost = utype_build_shield_cost(dlgcity, NULL, target.value.utype); + cost = utype_build_shield_cost(dlgcity, nullptr, target.value.utype); tooltip = get_tooltip_unit(target.value.utype, true).trimmed(); sprite = get_unittype_sprite(get_tileset(), target.value.utype, ACTIVITY_LAST, @@ -3859,6 +3866,7 @@ QString get_tooltip_improvement(const impr_type *building, struct city *pcity, QString upkeep; QString s1, s2, str; const char *req = skip_intl_qualifier_prefix(_("?tech:None")); + struct player *pplayer = client_player(); if (pcity != nullptr) { upkeep = QString::number(city_improvement_upkeep(pcity, building)); @@ -3882,7 +3890,8 @@ QString get_tooltip_improvement(const impr_type *building, struct city *pcity, .arg(impr_build_shield_cost(pcity, building)) .arg(upkeep).toHtmlEscaped(); } else { - int cost_est = impr_estimate_build_shield_cost(client.conn.playing, NULL, building); + int cost_est = impr_estimate_build_shield_cost(pplayer, + nullptr, building); def_str += QString(_("Cost Estimate: %1, Upkeep: %2\n")) .arg(cost_est) @@ -3895,8 +3904,8 @@ QString get_tooltip_improvement(const impr_type *building, struct city *pcity, if (ext) { char buffer[8192]; - str = helptext_building(buffer, sizeof(buffer), client.conn.playing, - NULL, building); + str = helptext_building(buffer, sizeof(buffer), pplayer, + nullptr, building); str = cut_helptext(str); str = split_text(str, true); str = str.trimmed(); @@ -3965,7 +3974,7 @@ QString get_tooltip_unit(const struct unit_type *utype, bool ext) char buf2[1]; buf2[0] = '\0'; - str = helptext_unit(buffer, sizeof(buffer), client.conn.playing, + str = helptext_unit(buffer, sizeof(buffer), client_player(), buf2, utype); str = cut_helptext(str); str = split_text(str, true); @@ -3986,22 +3995,23 @@ QString get_tooltip(QVariant qvar) char buffer[8192]; char buf2[1]; struct universal *target; + struct player *pplayer = client_player(); buf2[0] = '\0'; target = reinterpret_cast(qvar.value()); - if (target == NULL) { + if (target == nullptr) { } else if (VUT_UTYPE == target->kind) { def_str = get_tooltip_unit(target->value.utype); - str = helptext_unit(buffer, sizeof(buffer), client.conn.playing, + str = helptext_unit(buffer, sizeof(buffer), pplayer, buf2, target->value.utype); } else { if (!is_convert_improvement(target->value.building)) { def_str = get_tooltip_improvement(target->value.building); } - str = helptext_building(buffer, sizeof(buffer), client.conn.playing, - NULL, target->value.building); + str = helptext_building(buffer, sizeof(buffer), pplayer, + nullptr, target->value.building); } // Remove all lines from help which has '*' in first 3 chars @@ -4066,7 +4076,7 @@ void city_production_delegate::paint(QPainter *painter, target = reinterpret_cast(qvar.value()); - if (target == NULL) { + if (target == nullptr) { col.qcolor = Qt::white; sprite = qtg_create_sprite(100, 100, &col); free_sprite = true; @@ -4111,7 +4121,7 @@ void city_production_delegate::paint(QPainter *painter, is_coinage = improvement_has_flag(target->value.building, IF_GOLD); } - if (sprite != NULL) { + if (sprite != nullptr) { pix = sprite->pm; pix_scaled = pix->scaledToHeight(item_height - 2, Qt::SmoothTransformation); @@ -4211,7 +4221,7 @@ production_item::production_item(struct universal *ptarget, production_item::~production_item() { // Allocated as renegade in model - if (target != NULL) { + if (target != nullptr) { delete target; } } @@ -4508,7 +4518,7 @@ void production_widget::prod_selected(const QItemSelection &sl, return; } target = reinterpret_cast(qvar.value()); - if (target != NULL) { + if (target != nullptr) { city_get_queue(pw_city, &queue); switch (when_change) { case 0: // Change current target diff --git a/client/gui-qt/cityrep.cpp b/client/gui-qt/cityrep.cpp index a24f4408a6..02b7ae9ab2 100644 --- a/client/gui-qt/cityrep.cpp +++ b/client/gui-qt/cityrep.cpp @@ -409,7 +409,7 @@ void city_widget::city_view() } pcity = selected_cities[0]; - Q_ASSERT(pcity != NULL); + Q_ASSERT(pcity != nullptr); if (gui_options.center_when_popup_city) { center_tile_mapcanvas(pcity->tile); } @@ -426,7 +426,7 @@ void city_widget::clear_worlist() struct city *pcity; foreach(pcity, selected_cities) { - Q_ASSERT(pcity != NULL); + Q_ASSERT(pcity != nullptr); city_set_worklist(pcity, &empty); } } @@ -439,7 +439,7 @@ void city_widget::buy() struct city *pcity; foreach(pcity, selected_cities) { - Q_ASSERT(pcity != NULL); + Q_ASSERT(pcity != nullptr); cityrep_buy(pcity); } } @@ -455,7 +455,7 @@ void city_widget::center() return; } pcity = selected_cities[0]; - Q_ASSERT(pcity != NULL); + Q_ASSERT(pcity != nullptr); center_tile_mapcanvas(pcity->tile); gui()->game_tab_widget->setCurrentIndex(0); } @@ -570,7 +570,7 @@ void city_widget::display_list_menu(const QPoint &) target = cid_decode(id); city_list_iterate(client_player()->cities, iter_city) { - if (NULL != iter_city) { + if (iter_city != nullptr) { switch (m_state) { case SELECT_IMPR: if (need_clear) { @@ -642,7 +642,7 @@ void city_widget::display_list_menu(const QPoint &) } city_list_iterate_end; foreach (pcity_mid, selected_cities) { - if (nullptr != pcity_mid) { + if (pcity_mid != nullptr) { switch (m_state) { case CHANGE_PROD_NOW: city_change_production(pcity_mid, &target); @@ -688,7 +688,7 @@ void city_widget::display_list_menu(const QPoint &) } break; case CMA: - if (NULL != pcity_mid) { + if (pcity_mid != nullptr) { if (CMA_NONE == id) { cma_release_city(pcity_mid); } else { @@ -712,7 +712,7 @@ void city_widget::display_list_menu(const QPoint &) } break; case BUY: - if (NULL != pcity_mid) { + if (pcity_mid != nullptr) { if (city_can_buy(pcity_mid)) { city_buy_production(pcity_mid); } @@ -856,7 +856,8 @@ void city_widget::select_coastal() continue; } pcity = reinterpret_cast(qvar.value()); - if (NULL != pcity && is_terrain_class_near_tile(pcity->tile, TC_OCEAN)) { + if (pcity != nullptr + && is_terrain_class_near_tile(pcity->tile, TC_OCEAN)) { selection.append(QItemSelectionRange(i)); } } @@ -883,7 +884,7 @@ void city_widget::select_same_island() } pcity = reinterpret_cast(qvar.value()); foreach (pscity, selected_cities) { - if (NULL != pcity + if (pcity != nullptr && (tile_continent(pcity->tile) == tile_continent(pscity->tile))) { selection.append(QItemSelectionRange(i)); @@ -918,7 +919,7 @@ void city_widget::select_building_something() act = qobject_cast(sender()); qvar = act->data(); str = qvar.toString(); - if (NULL != pcity) { + if (pcity != nullptr) { if (str == "impr" && VUT_IMPROVEMENT == pcity->production.kind && !is_wonder(pcity->production.value.building) && !is_convert_improvement(pcity->production.value.building)) { @@ -1066,7 +1067,7 @@ void city_widget::gen_production_labels(city_widget::menu_labels what, targets_used = collect_production_targets(targets, city_data, num_sel, append_units, append_wonders, true, test_func); - name_and_sort_items(targets, targets_used, items, true, NULL); + name_and_sort_items(targets, targets_used, items, true, nullptr); for (i = 0; i < 4; i++) { row[i] = buf[i]; } @@ -1076,7 +1077,7 @@ void city_widget::gen_production_labels(city_widget::menu_labels what, char txt[256]; str.clear(); - get_city_dialog_production_row(row, sizeof(buf[0]), &target, NULL); + get_city_dialog_production_row(row, sizeof(buf[0]), &target, nullptr); fc_snprintf(txt, ARRAY_SIZE(txt), "%s ", row[0]); str = str + QString(txt); list.insert(str, cid_encode(target)); diff --git a/client/gui-qt/dialogs.cpp b/client/gui-qt/dialogs.cpp index bb733e12b3..7a03bbc253 100644 --- a/client/gui-qt/dialogs.cpp +++ b/client/gui-qt/dialogs.cpp @@ -587,7 +587,7 @@ races_dialog::races_dialog(struct player *pplayer, if (C_S_RUNNING == client_state()) { title = _("Edit Nation"); - } else if (NULL != pplayer && pplayer == client.conn.playing) { + } else if (pplayer != nullptr && pplayer == client_player()) { title = _("What Nation Will You Be?"); } else { title = _("Pick Nation"); @@ -774,7 +774,7 @@ void races_dialog::nation_selected(const QItemSelection &selected, qvar = index.data(Qt::UserRole); selected_nation = qvar.toInt(); - helptext_nation(buf, sizeof(buf), nation_by_number(selected_nation), NULL); + helptext_nation(buf, sizeof(buf), nation_by_number(selected_nation), nullptr); description->setPlainText(buf); leader_name->clear(); if (client.conn.playing == tplayer) { @@ -857,7 +857,7 @@ void races_dialog::ok_pressed() } natplr = nation_by_number(selected_nation)->player; - if (natplr != NULL && natplr != client_player()) { + if (natplr != nullptr && natplr != client_player()) { output_window_append(ftc_client, _("Nation has been chosen by other player")); return; @@ -1128,7 +1128,7 @@ notify_goto::notify_goto(const char *headline, const char *lines, inspect_but->setVisible(false); } else { struct city *pcity = tile_city(gtile); - inspect_but->setVisible(NULL != pcity + inspect_but->setVisible(pcity != nullptr && city_owner(pcity) == client.conn.playing); } setWindowTitle(headline); @@ -1252,7 +1252,7 @@ void popdown_races_dialog(void) ***************************************************************************/ void unit_select_dialog_popup(struct tile *ptile) { - if (ptile != NULL + if (ptile != nullptr && (unit_list_size(ptile->units) > 1 || (unit_list_size(ptile->units) == 1 && tile_city(ptile)))) { gui()->toggle_unit_sel_widget(ptile); @@ -1421,7 +1421,7 @@ choice_dialog::choice_dialog(const QString title, const QString text, targeted_unit = nullptr; // No buttons are added yet. for (int i = 0; i < BUTTON_COUNT; i++) { - action_button_map << NULL; + action_button_map << nullptr; } } @@ -1432,11 +1432,11 @@ choice_dialog::~choice_dialog() { buttons_list.clear(); action_button_map.clear(); - gui()->set_diplo_dialog(NULL); + gui()->set_diplo_dialog(nullptr); if (run_on_close) { run_on_close(unit_id); - run_on_close = NULL; + run_on_close = nullptr; } } @@ -1541,7 +1541,7 @@ Choice_dialog_button *choice_dialog::get_identified_button(const int id) { if (id < 0) { fc_assert_msg(0 <= id, "Invalid button ID."); - return NULL; + return nullptr; } return action_button_map[id]; @@ -1664,7 +1664,7 @@ void choice_dialog::update_dialog(const struct act_prob *act_probs) targeted_unit, targeted_unit->tile, (sub_target_id[ASTK_EXTRA] != EXTRA_NONE ? extra_by_number(sub_target_id[ASTK_EXTRA]) - : NULL), + : nullptr), act_probs); layout->addLayout(unit_skip); } @@ -1744,8 +1744,8 @@ static void caravan_marketplace(QVariant data1, QVariant data2) int actor_unit_id = data1.toInt(); int target_city_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_unit_id) - && NULL != game_city_by_number(target_city_id)) { + if (game_unit_by_number(actor_unit_id) != nullptr + && game_city_by_number(target_city_id) != nullptr) { request_do_action(ACTION_MARKETPLACE, actor_unit_id, target_city_id, 0, ""); } @@ -1759,8 +1759,8 @@ static void caravan_establish_trade(QVariant data1, QVariant data2) int actor_unit_id = data1.toInt(); int target_city_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_unit_id) - && NULL != game_city_by_number(target_city_id)) { + if (game_unit_by_number(actor_unit_id) != nullptr + && game_city_by_number(target_city_id) != nullptr) { request_do_action(ACTION_TRADE_ROUTE, actor_unit_id, target_city_id, 0, ""); } @@ -1774,8 +1774,8 @@ static void caravan_help_build(QVariant data1, QVariant data2) int caravan_id = data1.toInt(); int caravan_target_id = data2.toInt(); - if (NULL != game_unit_by_number(caravan_id) - && NULL != game_city_by_number(caravan_target_id)) { + if (game_unit_by_number(caravan_id) != nullptr + && game_city_by_number(caravan_target_id) != nullptr) { request_do_action(ACTION_HELP_WONDER, caravan_id, caravan_target_id, 0, ""); } @@ -1789,8 +1789,8 @@ static void unit_disband_recover(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int tgt_city_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != game_city_by_number(tgt_city_id)) { + if (game_unit_by_number(actor_id) != nullptr + && game_city_by_number(tgt_city_id) != nullptr) { request_do_action(ACTION_DISBAND_UNIT_RECOVER, actor_id, tgt_city_id, 0, ""); } @@ -1804,8 +1804,8 @@ static void unit_home_city(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int tgt_city_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != game_city_by_number(tgt_city_id)) { + if (game_unit_by_number(actor_id) != nullptr + && game_city_by_number(tgt_city_id) != nullptr) { request_do_action(ACTION_HOME_CITY, actor_id, tgt_city_id, 0, ""); } @@ -1821,8 +1821,8 @@ static void unit_upgrade(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int tgt_city_id = data2.toInt(); - if ((punit = game_unit_by_number(actor_id)) - && NULL != game_city_by_number(tgt_city_id)) { + if ((punit = game_unit_by_number(actor_id)) != nullptr + && game_city_by_number(tgt_city_id) != nullptr) { struct unit_list *as_list; as_list = unit_list_new(); @@ -1840,8 +1840,8 @@ static void airlift(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int tgt_city_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != game_city_by_number(tgt_city_id)) { + if (game_unit_by_number(actor_id) != nullptr + && game_city_by_number(tgt_city_id) != nullptr) { request_do_action(ACTION_AIRLIFT, actor_id, tgt_city_id, 0, ""); } @@ -1855,8 +1855,8 @@ static void conquer_city(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int tgt_city_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != game_city_by_number(tgt_city_id)) { + if (game_unit_by_number(actor_id) != nullptr + && game_city_by_number(tgt_city_id) != nullptr) { request_do_action(ACTION_CONQUER_CITY, actor_id, tgt_city_id, 0, ""); } @@ -1870,8 +1870,8 @@ static void conquer_city2(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int tgt_city_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != game_city_by_number(tgt_city_id)) { + if (game_unit_by_number(actor_id) != nullptr + && game_city_by_number(tgt_city_id) != nullptr) { request_do_action(ACTION_CONQUER_CITY2, actor_id, tgt_city_id, 0, ""); } @@ -1885,7 +1885,7 @@ static void conquer_extras(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id)) { + if (game_unit_by_number(actor_id) != nullptr) { request_do_action(ACTION_CONQUER_EXTRAS, actor_id, target_id, 0, ""); } @@ -1899,7 +1899,7 @@ static void conquer_extras2(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id)) { + if (game_unit_by_number(actor_id) != nullptr) { request_do_action(ACTION_CONQUER_EXTRAS2, actor_id, target_id, 0, ""); } @@ -2021,14 +2021,16 @@ void popup_action_selection(struct unit *actor_unit, foreach (caras, gui()->trade_gen.lines) { if (caras.autocaravan == actor_unit) { int i; - if (nullptr != game_unit_by_number(actor_unit->id) - && nullptr != game_city_by_number(target_city->id)) { + + if (game_unit_by_number(actor_unit->id) != nullptr + && game_city_by_number(target_city->id) != nullptr) { request_do_action(ACTION_TRADE_ROUTE, actor_unit->id, target_city->id, 0, ""); client_unit_init_act_prob_cache(actor_unit); diplomat_queue_handle_primary(actor_unit->id); i = gui()->trade_gen.lines.indexOf(caras); gui()->trade_gen.lines.takeAt(i); + return; } } @@ -2037,6 +2039,7 @@ void popup_action_selection(struct unit *actor_unit, && try_default_city_action(actor_unit->id, target_city->id) && action_prob_possible(act_probs[unit_act])) { diplomat_queue_handle_primary(actor_unit->id); + return; } @@ -2044,6 +2047,7 @@ void popup_action_selection(struct unit *actor_unit, && try_default_unit_action(actor_unit->id, target_unit->id) && action_prob_possible(act_probs[city_act])) { diplomat_queue_handle_primary(actor_unit->id); + return; } /* Could be caused by the server failing to reply to a request for more @@ -2061,18 +2065,18 @@ void popup_action_selection(struct unit *actor_unit, _("Choose Your %s's Strategy"), unit_name_translation(actor_unit)); - if (target_city && actor_homecity) { + if (target_city != nullptr && actor_homecity != nullptr) { astr_set(&text, _("Your %s from %s reaches the city of %s.\nWhat now?"), unit_name_translation(actor_unit), city_name_get(actor_homecity), city_name_get(target_city)); - } else if (target_city) { + } else if (target_city != nullptr) { astr_set(&text, _("Your %s has arrived at %s.\nWhat is your command?"), unit_name_translation(actor_unit), city_name_get(target_city)); - } else if (target_unit) { + } else if (target_unit != nullptr) { astr_set(&text, // TRANS: Your Spy is ready to act against Roman Freight. _("Your %s is ready to act against %s %s."), @@ -2080,7 +2084,9 @@ void popup_action_selection(struct unit *actor_unit, nation_adjective_for_player(unit_owner(target_unit)), unit_name_translation(target_unit)); } else { - fc_assert_msg(target_unit || target_city || target_tile, + fc_assert_msg(target_unit != nullptr + || target_city != nullptr + || target_tile != nullptr, "No target specified."); astr_set(&text, @@ -2394,7 +2400,7 @@ static void fortify(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id)) { + if (game_unit_by_number(actor_id) != nullptr) { request_do_action(ACTION_FORTIFY, actor_id, target_id, 0, ""); } @@ -2420,7 +2426,7 @@ static void homeless(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id)) { + if (game_unit_by_number(actor_id) != nullptr) { request_do_action(ACTION_HOMELESS, actor_id, target_id, 0, ""); } @@ -2434,8 +2440,8 @@ static void diplomat_bribe(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_unit_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_unit_by_number(diplomat_target_id) != nullptr) { // Wait for the server's reply before moving on to the next queued diplomat. is_more_user_input_needed = TRUE; @@ -2630,8 +2636,8 @@ static void disembark1(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_TRANSPORT_DISEMBARK1, actor_id, target_id, 0, ""); } @@ -2645,8 +2651,8 @@ static void disembark2(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_TRANSPORT_DISEMBARK2, actor_id, target_id, 0, ""); } @@ -2660,8 +2666,8 @@ static void enter_hut(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_HUT_ENTER, actor_id, target_id, 0, ""); } @@ -2675,8 +2681,8 @@ static void enter_hut2(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_HUT_ENTER2, actor_id, target_id, 0, ""); } @@ -2690,8 +2696,8 @@ static void frighten_hut(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_HUT_FRIGHTEN, actor_id, target_id, 0, ""); } @@ -2705,8 +2711,8 @@ static void frighten_hut2(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_HUT_FRIGHTEN2, actor_id, target_id, 0, ""); } @@ -2827,8 +2833,8 @@ static void transform_terrain(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_TRANSFORM_TERRAIN, actor_id, target_id, 0, ""); } @@ -2842,8 +2848,8 @@ static void cultivate(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_CULTIVATE, actor_id, target_id, 0, ""); } @@ -2857,8 +2863,8 @@ static void plant(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_PLANT, actor_id, target_id, 0, ""); } @@ -2872,8 +2878,8 @@ static void pillage(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_PILLAGE, actor_id, target_id, /* FIXME: will cause problems if more than @@ -2892,8 +2898,8 @@ static void clean(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_CLEAN, actor_id, target_id, /* FIXME: will cause problems if more than @@ -2912,9 +2918,9 @@ static void road(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id) - && NULL != extra_by_number(action_selection_target_extra())) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr + && extra_by_number(action_selection_target_extra()) != nullptr) { request_do_action(ACTION_ROAD, actor_id, target_id, /* FIXME: will cause problems if more than @@ -2933,9 +2939,9 @@ static void base(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id) - && NULL != extra_by_number(action_selection_target_extra())) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr + && extra_by_number(action_selection_target_extra()) != nullptr) { request_do_action(ACTION_BASE, actor_id, target_id, /* FIXME: will cause problems if more than @@ -2954,9 +2960,9 @@ static void mine(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id) - && NULL != extra_by_number(action_selection_target_extra())) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr + && extra_by_number(action_selection_target_extra()) != nullptr) { request_do_action(ACTION_MINE, actor_id, target_id, /* FIXME: will cause problems if more than @@ -2975,9 +2981,9 @@ static void irrigate(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id) - && NULL != extra_by_number(action_selection_target_extra())) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr + && extra_by_number(action_selection_target_extra()) != nullptr) { request_do_action(ACTION_IRRIGATE, actor_id, target_id, /* FIXME: will cause problems if more than @@ -2996,8 +3002,8 @@ static void nuke(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != index_to_tile(&(wld.map), diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && index_to_tile(&(wld.map), diplomat_target_id) != nullptr) { request_do_action(ACTION_NUKE, diplomat_id, diplomat_target_id, 0, ""); } @@ -3011,8 +3017,8 @@ static void attack(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != index_to_tile(&(wld.map), diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && index_to_tile(&(wld.map), diplomat_target_id) != nullptr) { request_do_action(ACTION_ATTACK, diplomat_id, diplomat_target_id, 0, ""); } @@ -3026,8 +3032,8 @@ static void suicide_attack(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != index_to_tile(&(wld.map), diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && index_to_tile(&(wld.map), diplomat_target_id) != nullptr) { request_do_action(ACTION_SUICIDE_ATTACK, diplomat_id, diplomat_target_id, 0, ""); } @@ -3041,8 +3047,8 @@ static void paradrop(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_PARADROP, actor_id, target_id, 0, ""); } @@ -3056,8 +3062,8 @@ static void paradrop_conquer(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_PARADROP_CONQUER, actor_id, target_id, 0, ""); } @@ -3071,8 +3077,8 @@ static void paradrop_frighten(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_PARADROP_FRIGHTEN, actor_id, target_id, 0, ""); } @@ -3086,8 +3092,8 @@ static void paradrop_frighten_conquer(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_PARADROP_FRIGHTEN_CONQUER, actor_id, target_id, 0, ""); } @@ -3101,8 +3107,8 @@ static void paradrop_enter(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_PARADROP_ENTER, actor_id, target_id, 0, ""); } @@ -3116,8 +3122,8 @@ static void paradrop_enter_conquer(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_PARADROP_ENTER_CONQUER, actor_id, target_id, 0, ""); } @@ -3131,8 +3137,8 @@ static void join_city(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != game_city_by_number(target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && game_city_by_number(target_id) != nullptr) { request_do_action(ACTION_JOIN_CITY, actor_id, target_id, 0, ""); } @@ -3151,12 +3157,12 @@ static void spy_steal_shared(QVariant data1, QVariant data2, int diplomat_target_id = data2.toInt(); struct unit *actor_unit = game_unit_by_number(diplomat_id); struct city *pvcity = game_city_by_number(diplomat_target_id); - struct player *pvictim = NULL; + struct player *pvictim = nullptr; choice_dialog *cd; QList actor_and_target; cd = gui()->get_diplo_dialog(); - if (cd != NULL) { + if (cd != nullptr) { cd->close(); } @@ -3237,8 +3243,8 @@ static void spy_steal_something(QVariant data1, QVariant data2) int diplomat_target_id = data1.toList().at(1).toInt(); action_id act_id = data1.toList().at(2).toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { if (data2.toInt() == A_UNSET) { // This is the untargeted version. request_do_action(get_non_targeted_action_id(act_id), @@ -3259,8 +3265,8 @@ static void spy_request_strike_bld_list(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != game_city_by_number(target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && game_city_by_number(target_id) != nullptr) { // Wait for the server's reply before moving on to the next queued diplomat. is_more_user_input_needed = TRUE; @@ -3276,8 +3282,8 @@ static void spy_request_sabotage_list(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { // Wait for the server's reply before moving on to the next queued diplomat. is_more_user_input_needed = TRUE; @@ -3294,8 +3300,8 @@ static void spy_request_sabotage_esc_list(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { /* Wait for the server's reply before moving on to the next queued * diplomat. */ is_more_user_input_needed = TRUE; @@ -3313,8 +3319,8 @@ static void spy_poison(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_POISON, diplomat_id, diplomat_target_id, 0, ""); } @@ -3328,8 +3334,8 @@ static void spy_poison_esc(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_POISON_ESC, diplomat_id, diplomat_target_id, 0, ""); } @@ -3343,8 +3349,8 @@ static void spy_nuke_city(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_NUKE, diplomat_id, diplomat_target_id, 0, ""); } @@ -3358,8 +3364,8 @@ static void spy_nuke_city_esc(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_NUKE_ESC, diplomat_id, diplomat_target_id, 0, ""); } @@ -3373,8 +3379,8 @@ static void nuke_city(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != game_city_by_number(target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && game_city_by_number(target_id) != nullptr) { request_do_action(ACTION_NUKE_CITY, actor_id, target_id, 0, ""); } @@ -3388,8 +3394,8 @@ static void destroy_city(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_DESTROY_CITY, diplomat_id, diplomat_target_id, 0, ""); } @@ -3403,8 +3409,8 @@ static void spy_steal_gold(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_STEAL_GOLD, diplomat_id, diplomat_target_id, 0, ""); } @@ -3418,8 +3424,8 @@ static void spy_steal_gold_esc(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_STEAL_GOLD_ESC, diplomat_id, diplomat_target_id, 0, ""); } @@ -3433,8 +3439,8 @@ static void spy_steal_maps(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_STEAL_MAPS, diplomat_id, diplomat_target_id, 0, ""); } @@ -3448,8 +3454,8 @@ static void spy_steal_maps_esc(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_STEAL_MAPS_ESC, diplomat_id, diplomat_target_id, 0, ""); } @@ -3463,8 +3469,8 @@ static void spy_escape(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_ESCAPE, diplomat_id, diplomat_target_id, 0, ""); } @@ -3478,8 +3484,8 @@ static void spy_embassy(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_ESTABLISH_EMBASSY, diplomat_id, diplomat_target_id, 0, ""); } @@ -3493,8 +3499,8 @@ static void diplomat_embassy(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_ESTABLISH_EMBASSY_STAY, diplomat_id, diplomat_target_id, 0, ""); } @@ -3508,8 +3514,8 @@ static void spy_investigate(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_city_by_number(diplomat_target_id) - && NULL != game_unit_by_number(diplomat_id)) { + if (game_city_by_number(diplomat_target_id) != nullptr + && game_unit_by_number(diplomat_id) != nullptr) { request_do_action(ACTION_SPY_INVESTIGATE_CITY, diplomat_id, diplomat_target_id, 0, ""); } @@ -3523,8 +3529,8 @@ static void diplomat_investigate(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_city_by_number(diplomat_target_id) - && NULL != game_unit_by_number(diplomat_id)) { + if (game_city_by_number(diplomat_target_id) != nullptr + && game_unit_by_number(diplomat_id) != nullptr) { request_do_action(ACTION_INV_CITY_SPEND, diplomat_id, diplomat_target_id, 0, ""); } @@ -3538,8 +3544,8 @@ static void diplomat_sabotage(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_SABOTAGE_CITY, diplomat_id, diplomat_target_id, B_LAST + 1, ""); } @@ -3553,8 +3559,8 @@ static void diplomat_sabotage_esc(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_SABOTAGE_CITY_ESC, diplomat_id, diplomat_target_id, B_LAST + 1, ""); } @@ -3568,8 +3574,8 @@ static void diplomat_steal(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_STEAL_TECH, diplomat_id, diplomat_target_id, A_UNSET, ""); } @@ -3583,8 +3589,8 @@ static void diplomat_steal_esc(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { request_do_action(ACTION_SPY_STEAL_TECH_ESC, diplomat_id, diplomat_target_id, A_UNSET, ""); } @@ -3598,8 +3604,8 @@ static void diplomat_incite(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { // Wait for the server's reply before moving on to the next queued diplomat. is_more_user_input_needed = TRUE; @@ -3616,8 +3622,8 @@ static void diplomat_incite_escape(QVariant data1, QVariant data2) int diplomat_id = data1.toInt(); int diplomat_target_id = data2.toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { // Wait for the server's reply before moving on to the next queued diplomat. is_more_user_input_needed = TRUE; @@ -3634,8 +3640,8 @@ static void regular_move(QVariant data1, QVariant data2) int actor_id = data1.toInt(); int target_id = data2.toInt(); - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { + if (game_unit_by_number(actor_id) != nullptr + && index_to_tile(&(wld.map), target_id) != nullptr) { request_do_action(ACTION_UNIT_MOVE, actor_id, target_id, 0, ""); } @@ -3780,8 +3786,8 @@ static void spy_sabotage(QVariant data1, QVariant data2) int diplomat_target_id = data1.toList().at(1).toInt(); action_id act_id = data1.toList().at(2).toInt(); - if (NULL != game_unit_by_number(diplomat_id) - && NULL != game_city_by_number(diplomat_target_id)) { + if (game_unit_by_number(diplomat_id) != nullptr + && game_city_by_number(diplomat_target_id) != nullptr) { if (data2.toInt() == B_LAST) { // This is the untargeted version. request_do_action(get_non_targeted_action_id(act_id), @@ -4104,7 +4110,7 @@ int action_selection_actor_unit(void) { choice_dialog *cd = gui()->get_diplo_dialog(); - if (cd != NULL) { + if (cd != nullptr) { return cd->unit_id; } else { return IDENTITY_NUMBER_ZERO; @@ -4121,7 +4127,7 @@ int action_selection_target_city(void) { choice_dialog *cd = gui()->get_diplo_dialog(); - if (cd != NULL) { + if (cd != nullptr) { return cd->target_id[ATK_CITY]; } else { return IDENTITY_NUMBER_ZERO; @@ -4138,7 +4144,7 @@ int action_selection_target_tile(void) { choice_dialog *cd = gui()->get_diplo_dialog(); - if (cd != NULL) { + if (cd != nullptr) { return cd->target_id[ATK_TILE]; } else { return TILE_INDEX_NONE; @@ -4155,7 +4161,7 @@ int action_selection_target_extra(void) { choice_dialog *cd = gui()->get_diplo_dialog(); - if (cd != NULL) { + if (cd != nullptr) { return cd->sub_target_id[ASTK_EXTRA]; } else { return EXTRA_NONE; @@ -4172,7 +4178,7 @@ int action_selection_target_unit(void) { choice_dialog *cd = gui()->get_diplo_dialog(); - if (cd != NULL) { + if (cd != nullptr) { return cd->target_id[ATK_UNIT]; } else { return IDENTITY_NUMBER_ZERO; @@ -4195,8 +4201,8 @@ void action_selection_refresh(struct unit *actor_unit, QVariant qv1, qv2; asd = gui()->get_diplo_dialog(); - if (asd == NULL) { - fc_assert_msg(asd != NULL, + if (asd == nullptr) { + fc_assert_msg(asd != nullptr, "The action selection dialog should have been open"); return; } @@ -4210,14 +4216,14 @@ void action_selection_refresh(struct unit *actor_unit, qv1 = actor_unit->id; cancel_button = asd->get_identified_button(BUTTON_CANCEL); - if (cancel_button != NULL) { + if (cancel_button != nullptr) { /* Temporary remove the Cancel button so it won't end up above * any added buttons. */ asd->stack_button(cancel_button); } wait_button = asd->get_identified_button(BUTTON_WAIT); - if (wait_button != NULL) { + if (wait_button != nullptr) { /* Temporary remove the Wait button so it won't end up above * any added buttons. */ asd->stack_button(wait_button); @@ -4239,22 +4245,22 @@ void action_selection_refresh(struct unit *actor_unit, // Put the target id in qv2. switch (action_id_get_target_kind(act)) { case ATK_UNIT: - if (target_unit != NULL) { + if (target_unit != nullptr) { qv2 = target_unit->id; } else { fc_assert_msg(!action_prob_possible(act_probs[act]) - || target_unit != NULL, + || target_unit != nullptr, "Action enabled against non existing unit!"); qv2 = IDENTITY_NUMBER_ZERO; } break; case ATK_CITY: - if (target_city != NULL) { + if (target_city != nullptr) { qv2 = target_city->id; } else { fc_assert_msg(!action_prob_possible(act_probs[act]) - || target_city != NULL, + || target_city != nullptr, "Action enabled against non existing city!"); qv2 = IDENTITY_NUMBER_ZERO; @@ -4263,11 +4269,11 @@ void action_selection_refresh(struct unit *actor_unit, case ATK_TILE: case ATK_EXTRAS: case ATK_UNITS: - if (target_tile != NULL) { + if (target_tile != nullptr) { qv2 = tile_index(target_tile); } else { fc_assert_msg(!action_prob_possible(act_probs[act]) - || target_tile != NULL, + || target_tile != nullptr, "Action enabled against all units on " "non existing tile!"); @@ -4295,7 +4301,7 @@ void action_selection_refresh(struct unit *actor_unit, } } action_iterate_end; - if (wait_button != NULL || cancel_button != NULL) { + if (wait_button != nullptr || cancel_button != nullptr) { /* Reinsert the non action buttons below any potential * buttons recently added. */ asd->unstack_all_buttons(); @@ -4310,7 +4316,7 @@ void action_selection_close(void) choice_dialog *cd; cd = gui()->get_diplo_dialog(); - if (cd != NULL) { + if (cd != nullptr) { did_not_decide = true; cd->close(); } @@ -4341,7 +4347,7 @@ void show_tileset_error(bool fatal, const char *tset_name, const char *msg) char buf[1024]; QMessageBox *ask = new QMessageBox(parent); - if (tset_name != NULL) { + if (tset_name != nullptr) { fc_snprintf(buf, sizeof(buf), _("Tileset \"%s\" problem, it's probably incompatible with " "the ruleset:\n%s"), tset_name, msg); @@ -4418,13 +4424,13 @@ units_select::units_select(tile *ptile, QWidget *parent) setParent(parent); utile = ptile; - pix = NULL; + pix = nullptr; show_line = 0; highligh_num = -1; ufont.setItalic(true); info_font = *fc_font::instance()->get_font(fonts::notify_label); update_units(); - h_pix = NULL; + h_pix = nullptr; create_pixmap(); p = mapFromGlobal(QCursor::pos()); cw = new close_widget(this); @@ -4475,9 +4481,9 @@ void units_select::create_pixmap() struct unit *punit; float isosize; - if (pix != NULL) { + if (pix != nullptr) { delete pix; - pix = NULL; + pix = nullptr; }; isosize = 0.7; if (tileset_hex_height(tileset) > 0 || tileset_hex_width(tileset) > 0) { @@ -4554,7 +4560,7 @@ void units_select::create_pixmap() y = y + item_size.height(); } punit = unit_list.at(i); - Q_ASSERT(punit != NULL); + Q_ASSERT(punit != nullptr); if (i == highligh_num) { p.drawPixmap(x, y, *h_pix); @@ -4700,7 +4706,7 @@ void units_select::paint(QPainter *painter, QPaintEvent *event) } } h = fm.height(); - if (pix != NULL) { + if (pix != nullptr) { painter->drawPixmap(10, h + 3, *pix); pen.setColor(palette().color(QPalette::Text)); painter->setPen(pen); @@ -4764,7 +4770,7 @@ void units_select::update_units() struct unit_list *punit_list; unit_count = 0; - if (utile == NULL) { + if (utile == nullptr) { struct unit *punit = head_of_units_in_focus(); if (punit) { utile = unit_tile(punit); @@ -4803,7 +4809,7 @@ void units_select::wheelEvent(QWheelEvent *event) { int nr; - if (!more && utile == NULL) { + if (!more && utile == nullptr) { return; } nr = qCeil(static_cast(unit_list_size(utile->units)) / 4) - 3; @@ -4880,7 +4886,7 @@ bool qtg_request_transport(struct unit *pcargo, struct tile *ptile) tcount = unit_list_size(potential_transports); if (tcount == 0) { - fc_assert(best_transport == NULL); + fc_assert(best_transport == nullptr); unit_list_destroy(potential_transports); return false; // Unit was not handled here. @@ -4954,7 +4960,7 @@ void qtg_request_action_confirmation(const char *expl, hdr = QString(_("Are you sure you want to do %1?")). arg(QString(action_id_name_translation(data->act))); - if (expl != NULL) { + if (expl != nullptr) { body_text += QString(expl); } diff --git a/client/gui-qt/diplodlg.cpp b/client/gui-qt/diplodlg.cpp index 7a64c796ad..9eb5086248 100644 --- a/client/gui-qt/diplodlg.cpp +++ b/client/gui-qt/diplodlg.cpp @@ -134,7 +134,7 @@ diplo_wdg::diplo_wdg(struct Treaty *ptreaty, label = new QLabel; sprite = get_nation_flag_sprite(tileset, nation_of_player(we)); - if (sprite != NULL) { + if (sprite != nullptr) { if (svg) { plr1_label->setPixmap(sprite->pm->scaledToHeight(FLAG_HEIGHT_DIPLDLG)); } else { @@ -154,7 +154,7 @@ diplo_wdg::diplo_wdg(struct Treaty *ptreaty, sprite2 = get_nation_flag_sprite(tileset, nation_of_player(they)); plr2_label = new QLabel; - if (sprite2 != NULL) { + if (sprite2 != nullptr) { if (svg) { plr2_label->setPixmap(sprite2->pm->scaledToHeight(FLAG_HEIGHT_DIPLDLG)); } else { @@ -700,7 +700,7 @@ void diplo_wdg::update_wdg() bool blank; int i; struct sprite *sprite; - QPixmap *pix = NULL; + QPixmap *pix = nullptr; QTableWidgetItem *qitem; blank = true; @@ -730,7 +730,7 @@ void diplo_wdg::update_wdg() } sprite = get_treaty_thumb_sprite(tileset, treaty->accept1); - if (sprite != NULL) { + if (sprite != nullptr) { pix = sprite->pm; plr1_accept->setPixmap(*pix); } else { @@ -738,7 +738,7 @@ void diplo_wdg::update_wdg() } sprite = get_treaty_thumb_sprite(tileset, treaty->accept0); - if (sprite != NULL) { + if (sprite != nullptr) { pix = sprite->pm; plr2_accept->setPixmap(*pix); } else { @@ -799,17 +799,17 @@ void diplo_dlg::add_widget(struct Treaty *ptreaty, struct player *they, QPixmap *pix; int i; - pix = NULL; + pix = nullptr; dw = new diplo_wdg(ptreaty, they, initiator); treaty_list.insert(they, dw); i = addTab(dw, nation_plural_for_player(they)); dw->set_index(i); sprite = get_nation_flag_sprite(tileset, nation_of_player(they)); - if (sprite != NULL) { + if (sprite != nullptr) { pix = sprite->pm; } - if (pix != NULL) { + if (pix != nullptr) { setTabIcon(i, QIcon(*pix)); } } @@ -1012,7 +1012,7 @@ void qtg_init_meeting(struct Treaty *ptreaty, struct player *they, } fw = dd->find_widget(they); - if (fw == NULL) { + if (fw == nullptr) { dd->add_widget(ptreaty, they, initiator); gui()->game_tab_widget->setCurrentIndex(i); } diff --git a/client/gui-qt/fc_client.cpp b/client/gui-qt/fc_client.cpp index a48ce0475f..c7d23a48f6 100644 --- a/client/gui-qt/fc_client.cpp +++ b/client/gui-qt/fc_client.cpp @@ -81,47 +81,47 @@ fc_client::fc_client() : QMainWindow() * were created. * After adding new QObjects null them here. */ - main_wdg = NULL; - connect_lan = NULL; - connect_metaserver = NULL; - central_layout = NULL; - output_window = NULL; - scenarios_view = NULL; - connect_host_edit = NULL; - connect_port_edit = NULL; - connect_login_edit = NULL; - connect_password_edit = NULL; - connect_confirm_password_edit = NULL; - button = NULL; - button_box = NULL; - server_notifier = NULL; - chat_line = NULL; - lan_widget = NULL; - wan_widget = NULL; - info_widget = NULL; - saves_load = NULL; - scenarios_load = NULL; - meta_scan_timer = NULL; - lan_scan_timer = NULL; - status_bar = NULL; - status_bar_label = NULL; - menu_bar = NULL; - mapview_wdg = NULL; + main_wdg = nullptr; + connect_lan = nullptr; + connect_metaserver = nullptr; + central_layout = nullptr; + output_window = nullptr; + scenarios_view = nullptr; + connect_host_edit = nullptr; + connect_port_edit = nullptr; + connect_login_edit = nullptr; + connect_password_edit = nullptr; + connect_confirm_password_edit = nullptr; + button = nullptr; + button_box = nullptr; + server_notifier = nullptr; + chat_line = nullptr; + lan_widget = nullptr; + wan_widget = nullptr; + info_widget = nullptr; + saves_load = nullptr; + scenarios_load = nullptr; + meta_scan_timer = nullptr; + lan_scan_timer = nullptr; + status_bar = nullptr; + status_bar_label = nullptr; + menu_bar = nullptr; + mapview_wdg = nullptr; sidebar_wdg = nullptr; - msgwdg = NULL; - infotab = NULL; - central_wdg = NULL; - game_tab_widget = NULL; - start_players_tree = NULL; - unit_sel = NULL; + msgwdg = nullptr; + infotab = nullptr; + central_wdg = nullptr; + game_tab_widget = nullptr; + start_players_tree = nullptr; + unit_sel = nullptr; info_tile_wdg = nullptr; - opened_dialog = NULL; + opened_dialog = nullptr; current_file = ""; status_bar_queue.clear(); quitting = false; - pre_vote = NULL; - x_vote = NULL; - gtd = NULL; + pre_vote = nullptr; + x_vote = nullptr; + gtd = nullptr; update_info_timer = nullptr; unitinfo_wdg = nullptr; battlelog_wdg = nullptr; @@ -129,8 +129,8 @@ fc_client::fc_client() : QMainWindow() map_scale = 1.0f; map_font_scale = true; for (int i = 0; i <= PAGE_GAME; i++) { - pages_layout[i] = NULL; - pages[i] = NULL; + pages_layout[i] = nullptr; + pages[i] = nullptr; } wtitle = _("Freeciv (%1)"); @@ -264,7 +264,7 @@ void fc_client::fc_main(QApplication *qapp) qRegisterMetaType("QTextCursor"); qRegisterMetaType("QTextBlock"); fc_allocate_ow_mutex(); - real_output_window_append(_("This is Qt-client for Freeciv."), NULL, -1); + real_output_window_append(_("This is Qt-client for Freeciv."), nullptr, -1); fc_release_ow_mutex(); chat_welcome_message(true); @@ -312,7 +312,7 @@ void fc_client::chat_message_received(const QString &message, QColor col = output_window->palette().color(QPalette::Text); QString str = apply_tags(message, tags, col); - if (output_window != NULL) { + if (output_window != nullptr) { output_window->append(str); output_window->verticalScrollBar()->setSliderPosition( output_window->verticalScrollBar()->maximum()); @@ -621,7 +621,7 @@ bool fc_client::is_repo_dlg_open(QString str) w = opened_repo_dlgs.value(str); - if (w == NULL) { + if (w == nullptr) { return false; } @@ -832,7 +832,7 @@ void fc_client::write_settings() ****************************************************************************/ void fc_client::toggle_unit_sel_widget(struct tile *ptile) { - if (unit_sel != NULL) { + if (unit_sel != nullptr) { unit_sel->close(); delete unit_sel; unit_sel = new units_select(ptile, gui()->mapview_wdg); @@ -848,7 +848,7 @@ void fc_client::toggle_unit_sel_widget(struct tile *ptile) ****************************************************************************/ void fc_client::update_unit_sel() { - if (unit_sel != NULL) { + if (unit_sel != nullptr) { unit_sel->update_units(); unit_sel->create_pixmap(); unit_sel->update(); diff --git a/client/gui-qt/gotodlg.cpp b/client/gui-qt/gotodlg.cpp index c19c6fdeac..ce3eea8b68 100644 --- a/client/gui-qt/gotodlg.cpp +++ b/client/gui-qt/gotodlg.cpp @@ -224,7 +224,7 @@ void goto_dialog::show_me() final_p.setY(height()); } move(final_p.x(), final_p.y() - height()); - if (original_tile == NULL) { + if (original_tile == nullptr) { init(); } show(); @@ -267,7 +267,7 @@ void goto_dialog::fill_tab(player *pplayer) QPixmap *pix; QPixmap pix_scaled; QTableWidgetItem *item; - unit *punit = NULL; + unit *punit = nullptr; int rnum = 0; int rvalue = 0; enum route_direction rdir = RDIR_NONE; @@ -291,7 +291,7 @@ void goto_dialog::fill_tab(player *pplayer) case GOTODLG_NATION: sprite = get_nation_flag_sprite(tileset, nation_of_player(pplayer)); - if (sprite != NULL) { + if (sprite != nullptr) { pix = sprite->pm; pix_scaled = pix->scaledToHeight(h); item->setData(Qt::DecorationRole, pix_scaled); @@ -312,7 +312,7 @@ void goto_dialog::fill_tab(player *pplayer) case GOTODLG_AIRLIFT: at = get_airlift_text(get_units_in_focus(), pcity); - if (at == NULL) { + if (at == nullptr) { str = "-"; } else { str = at; @@ -329,7 +329,7 @@ void goto_dialog::fill_tab(player *pplayer) case GOTODLG_DISTANCE: punit = head_of_units_in_focus(); - if (punit == NULL) { + if (punit == nullptr) { str = "-"; item->setTextAlignment(Qt::AlignHCenter); } else { @@ -346,7 +346,7 @@ void goto_dialog::fill_tab(player *pplayer) rvalue = 0; rdir = RDIR_NONE; rdir_value = 0; - if (punit != NULL) { + if (punit != nullptr) { trade_routes_iterate(pcity, proute) { rnum++; rvalue += proute->value; diff --git a/client/gui-qt/gui_main.cpp b/client/gui-qt/gui_main.cpp index 60265ed518..e2502d51d9 100644 --- a/client/gui-qt/gui_main.cpp +++ b/client/gui-qt/gui_main.cpp @@ -324,7 +324,7 @@ void qtg_remove_net_input() Set one of the unit icons (specified by idx) in the information area based on punit. - punit is the unit the information should be taken from. Use NULL to + punit is the unit the information should be taken from. Use nullptr to clear the icon. idx specified which icon should be modified. Use idx == -1 to indicate diff --git a/client/gui-qt/helpdlg.cpp b/client/gui-qt/helpdlg.cpp index fbb5a812f3..191013bf03 100644 --- a/client/gui-qt/helpdlg.cpp +++ b/client/gui-qt/helpdlg.cpp @@ -53,9 +53,9 @@ #define MAX_HELP_TEXT_SIZE 8192 #define REQ_LABEL_NEVER _("(Never)") #define REQ_LABEL_NONE _("?tech:None") -static help_dialog *help_dlg = NULL; +static help_dialog *help_dlg = nullptr; static canvas *terrain_canvas(struct terrain *terrain, - const struct extra_type *resource = NULL, + const struct extra_type *resource = nullptr, enum extra_cause cause = EC_COUNT); /**********************************************************************//** @@ -103,7 +103,7 @@ void popdown_help_dialog(void) if (help_dlg) { help_dlg->setVisible(false); help_dlg->deleteLater(); - help_dlg = NULL; + help_dlg = nullptr; } } @@ -435,8 +435,8 @@ void help_dialog::item_changed(QTreeWidgetItem *item, QTreeWidgetItem *prev) **************************************************************************/ help_widget::help_widget(QWidget *parent) : QWidget(parent), - main_widget(NULL), text_browser(NULL), bottom_panel(NULL), - info_panel(NULL), splitter(NULL), info_layout(NULL) + main_widget(nullptr), text_browser(nullptr), bottom_panel(nullptr), + info_panel(nullptr), splitter(nullptr), info_layout(nullptr) { setup_ui(); } @@ -446,8 +446,8 @@ help_widget::help_widget(QWidget *parent) : **************************************************************************/ help_widget::help_widget(const help_item *topic, QWidget *parent) : QWidget(parent), - main_widget(NULL), text_browser(NULL), bottom_panel(NULL), - info_panel(NULL), splitter(NULL), info_layout(NULL) + main_widget(nullptr), text_browser(nullptr), bottom_panel(nullptr), + info_panel(nullptr), splitter(nullptr), info_layout(nullptr) { setup_ui(); set_topic(topic); @@ -529,7 +529,7 @@ void help_widget::do_layout(bool horizontal) } layout()->removeWidget(main_widget); - main_widget->setParent(NULL); + main_widget->setParent(nullptr); if (bottom_panel) { splitter = new QSplitter(bottom_layout); @@ -599,17 +599,17 @@ void help_widget::undo_layout() splitter_sizes = splitter->sizes(); } // Unparent the widget we want to keep - text_browser->setParent(NULL); + text_browser->setParent(nullptr); // Delete everything else if (text_browser != main_widget) { main_widget->deleteLater(); } // Reset pointers to defaults main_widget = text_browser; - bottom_panel = NULL; - info_panel = NULL; - splitter = NULL; - info_layout = NULL; + bottom_panel = nullptr; + info_panel = nullptr; + splitter = nullptr; + info_layout = nullptr; } /**********************************************************************//** @@ -1223,7 +1223,7 @@ static canvas *terrain_canvas(struct terrain *terrain, put_drawn_sprites(canvas, 1.0f, 0, canvas_y, count, sprs, false); } - pextra = NULL; + pextra = nullptr; if (cause != EC_COUNT) { extra_type_by_cause_iterate(cause, e) { pextra = e; @@ -1234,7 +1234,7 @@ static canvas *terrain_canvas(struct terrain *terrain, put_drawn_sprites(canvas, 1.0f, 0, canvas_y, count, sprs, false); } - if (resource != NULL) { + if (resource != nullptr) { count = fill_basic_extra_sprite_array(tileset, sprs, resource); put_drawn_sprites(canvas, 1.0f, 0, canvas_y, count, sprs, false); } @@ -1339,7 +1339,7 @@ void help_widget::set_topic_terrain(const help_item *topic, if (pterrain->cultivate_result != T_NONE && action_id_univs_not_blocking(ACTION_CULTIVATE, - NULL, &for_terr)) { + nullptr, &for_terr)) { QLabel *tb; char cult_buffer[1024]; @@ -1361,7 +1361,7 @@ void help_widget::set_topic_terrain(const help_item *topic, } if (pterrain->plant_result != T_NONE - && action_id_univs_not_blocking(ACTION_PLANT, NULL, &for_terr)) { + && action_id_univs_not_blocking(ACTION_PLANT, nullptr, &for_terr)) { QLabel *tb; char plant_buffer[1024]; @@ -1384,7 +1384,7 @@ void help_widget::set_topic_terrain(const help_item *topic, if (pterrain->transform_result != T_NONE && action_id_univs_not_blocking(ACTION_TRANSFORM_TERRAIN, - NULL, &for_terr)) { + nullptr, &for_terr)) { QLabel *tb; char tf_buffer[1024]; @@ -1405,20 +1405,20 @@ void help_widget::set_topic_terrain(const help_item *topic, info_layout->addWidget(tb); } - if (action_id_univs_not_blocking(ACTION_IRRIGATE, NULL, &for_terr)) { + if (action_id_univs_not_blocking(ACTION_IRRIGATE, nullptr, &for_terr)) { // TRANS: This and similar literal strings interpreted as (Qt) HTML add_extras_of_act_for_terrain(pterrain, ACTIVITY_IRRIGATE, _("Build as irrigation")); } - if (action_id_univs_not_blocking(ACTION_MINE, NULL, &for_terr)) { + if (action_id_univs_not_blocking(ACTION_MINE, nullptr, &for_terr)) { add_extras_of_act_for_terrain(pterrain, ACTIVITY_MINE, _("Build as mine")); } - if (action_id_univs_not_blocking(ACTION_ROAD, NULL, &for_terr)) { + if (action_id_univs_not_blocking(ACTION_ROAD, nullptr, &for_terr)) { add_extras_of_act_for_terrain(pterrain, ACTIVITY_GEN_ROAD, _("Build as road")); } - if (action_id_univs_not_blocking(ACTION_BASE, NULL, &for_terr)) { + if (action_id_univs_not_blocking(ACTION_BASE, nullptr, &for_terr)) { add_extras_of_act_for_terrain(pterrain, ACTIVITY_BASE, _("Build as base")); } diff --git a/client/gui-qt/hudwidget.cpp b/client/gui-qt/hudwidget.cpp index 904b223d48..4766fae9c6 100644 --- a/client/gui-qt/hudwidget.cpp +++ b/client/gui-qt/hudwidget.cpp @@ -624,7 +624,7 @@ void hud_units::update_actions(unit_list *punits) text_str = QString(unit_name_translation(punit)); owner = punit->owner; pcity = player_city_by_number(owner, punit->homecity); - if (pcity != NULL) { + if (pcity != nullptr) { text_str = QString(("%1(%2)")) .arg(unit_name_translation(punit), city_name_get(pcity)); } diff --git a/client/gui-qt/mapctrl.cpp b/client/gui-qt/mapctrl.cpp index d857a27edb..b949829e7a 100644 --- a/client/gui-qt/mapctrl.cpp +++ b/client/gui-qt/mapctrl.cpp @@ -267,11 +267,11 @@ void map_view::shortcut_pressed(int key) } // Rally point - select tile - skip - if (bt == Qt::LeftButton && gui()->rallies.hover_tile && ctile != NULL) { + if (bt == Qt::LeftButton && gui()->rallies.hover_tile && ctile != nullptr) { char text[1024]; struct city *rcity = gui()->rallies.rally_city; - fc_assert_ret(rcity != NULL); + fc_assert_ret(rcity != nullptr); if (send_rally_tile(rcity, ctile, FALSE)) { fc_snprintf(text, sizeof(text), @@ -285,7 +285,7 @@ void map_view::shortcut_pressed(int key) output_window_append(ftc_client, text); } - gui()->rallies.rally_city = NULL; + gui()->rallies.rally_city = nullptr; gui()->rallies.hover_tile = false; return; @@ -548,7 +548,7 @@ void map_view::mouseMoveEvent(QMouseEvent *event) **************************************************************************/ void fc_client::popup_tile_info(struct tile *ptile) { - struct unit *punit = NULL; + struct unit *punit = nullptr; if (info_tile_wdg != nullptr) { popdown_tile_info(); diff --git a/client/gui-qt/mapview.cpp b/client/gui-qt/mapview.cpp index ddfe171b78..32b992eeab 100644 --- a/client/gui-qt/mapview.cpp +++ b/client/gui-qt/mapview.cpp @@ -1029,7 +1029,7 @@ void fc_client::update_info_label(void) client_warming_sprite(), client_cooling_sprite(), client_government_sprite()); - if (client.conn.playing != NULL) { + if (client.conn.playing != nullptr) { if (player_get_expected_income(client.conn.playing) > 0) { eco_info = QString(_("%1 (+%2)")) .arg(QString::number(client.conn.playing->economic.gold), @@ -1055,7 +1055,7 @@ void fc_client::update_info_label(void) and the tile under the current unit, for specified unit. Note that in practice punit is always the focus unit. - Clears label if punit is NULL. + Clears label if punit is nullptr. Typically also updates the cursor for the map_canvas (this is related because the info label may includes "select destination" @@ -1120,7 +1120,7 @@ void set_indicator_icons(struct sprite *bulb, struct sprite *sol, struct canvas *get_overview_window(void) { gui()->minimapview_wdg->update_image(); - return NULL; + return nullptr; } /**********************************************************************//** diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index 66e4bb6bbd..09decd53dd 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -88,13 +88,15 @@ void trade_generator::add_all_cities() { int i, s; struct city *pcity; + struct player *pplayer = client_player(); + clear_trade_planing(); - s = city_list_size(client.conn.playing->cities); + s = city_list_size(pplayer->cities); if (s == 0) { return; } for (i = 0; i < s; i++) { - pcity = city_list_get(client.conn.playing->cities, i); + pcity = city_list_get(pplayer->cities, i); add_city(pcity); } } @@ -551,7 +553,7 @@ static const char *get_tile_change_menu_text(struct tile *ptile, struct tile *newtile = tile_virtual_new(ptile); const char *text; - tile_apply_activity(newtile, activity, NULL); + tile_apply_activity(newtile, activity, nullptr); text = tile_get_info_text(newtile, FALSE, 0); tile_virtual_destroy(newtile); @@ -634,11 +636,11 @@ void gov_menu::update() gov = government_by_number(i); if (gov != revol_gov) { // Skip revolution goverment sprite = get_government_sprite(tileset, gov); - if (sprite != NULL) { + if (sprite != nullptr) { actions[j + 1]->setIcon(QIcon(*(sprite->pm))); } actions[j + 1]->setEnabled( - can_change_to_government(client.conn.playing, gov)); + can_change_to_government(client_player(), gov)); j++; } else { actions[0]->setEnabled(!client_is_observer() @@ -1871,19 +1873,22 @@ void mr_menu::update_airlift_menu() { Unit_type_id utype_id; QAction *act; + struct player *pplayer; airlift_menu->clear(); if (client_is_observer()) { return; } + + pplayer = client_player(); unit_type_iterate(utype) { utype_id = utype_index(utype); - if (!can_player_build_unit_now(client.conn.playing, utype) + if (!can_player_build_unit_now(pplayer, utype) || !utype_can_do_action(utype, ACTION_AIRLIFT)) { continue; } - if (!can_player_build_unit_now(client.conn.playing, utype) + if (!can_player_build_unit_now(pplayer, utype) && !has_player_unit_type(utype_id)) { continue; } @@ -2008,8 +2013,8 @@ void mr_menu::menus_sensitive() bool any_cities = false; bool city_on_tile = false; bool units_all_same_tile = true; - const struct tile *ptile = NULL; - const struct unit_type *ptype = NULL; + const struct tile *ptile = nullptr; + const struct unit_type *ptype = nullptr; players_iterate(pplayer) { if (city_list_size(pplayer->cities)) { @@ -2093,7 +2098,7 @@ void mr_menu::menus_sensitive() unit_list_iterate(punits, punit) { const struct unit_type *ntype; - fc_assert((ptile == NULL) == (ptype == NULL)); + fc_assert((ptile == nullptr) == (ptype == nullptr)); ntype = unit_type_get(punit); @@ -2154,19 +2159,19 @@ void mr_menu::menus_sensitive() if (units_all_same_tile) { if (units_have_type_flag(punits, UTYF_WORKERS, TRUE)) { - struct extra_type *pextra = NULL; + struct extra_type *pextra = nullptr; /* FIXME: this overloading doesn't work well with multiple focus * units. */ unit_list_iterate(punits, builder) { pextra = next_extra_for_tile(unit_tile(builder), EC_MINE, unit_owner(builder), builder); - if (pextra != NULL) { + if (pextra != nullptr) { break; } } unit_list_iterate_end; - if (pextra != NULL) { + if (pextra != nullptr) { i.value()->setText( // TRANS: Build mine of specific type QString(_("Build %1")) @@ -2187,19 +2192,19 @@ void mr_menu::menus_sensitive() } if (units_all_same_tile) { if (units_have_type_flag(punits, UTYF_WORKERS, TRUE)) { - struct extra_type *pextra = NULL; + struct extra_type *pextra = nullptr; /* FIXME: this overloading doesn't work well with multiple focus * units. */ unit_list_iterate(punits, builder) { pextra = next_extra_for_tile(unit_tile(builder), EC_IRRIGATION, unit_owner(builder), builder); - if (pextra != NULL) { + if (pextra != nullptr) { break; } } unit_list_iterate_end; - if (pextra != NULL) { + if (pextra != nullptr) { i.value()->setText( // TRANS: Build irrigation of specific type QString(_("Build %1")) @@ -2393,7 +2398,7 @@ void mr_menu::menus_sensitive() break; case CONNECT_ROAD: proad = road_by_gui_type(ROAD_GUI_ROAD); - if (proad != NULL) { + if (proad != nullptr) { tgt = road_extra_get(proad); } else { break; @@ -2411,7 +2416,7 @@ void mr_menu::menus_sensitive() case CONNECT_RAIL: proad = road_by_gui_type(ROAD_GUI_RAILROAD); - if (proad != NULL) { + if (proad != nullptr) { tgt = road_extra_get(proad); } else { break; @@ -2423,7 +2428,7 @@ void mr_menu::menus_sensitive() case CONNECT_MAGLEV: proad = road_by_gui_type(ROAD_GUI_MAGLEV); - if (proad != NULL) { + if (proad != nullptr) { tgt = road_extra_get(proad); } else { break; @@ -2517,8 +2522,10 @@ void mr_menu::slot_show_research_tab() **************************************************************************/ void mr_menu::slot_spaceship() { - if (NULL != client.conn.playing) { - popup_spaceship_dialog(client.conn.playing); + struct player *pplayer = client_player(); + + if (pplayer != nullptr) { + popup_spaceship_dialog(pplayer); } } @@ -2591,7 +2598,7 @@ void mr_menu::slot_clean() pextra = prev_extra_in_tile(unit_tile(punit), ERM_CLEAN, unit_owner(punit), punit); - if (pextra != NULL) { + if (pextra != nullptr) { request_new_unit_activity_targeted(punit, ACTIVITY_CLEAN, pextra); } } unit_list_iterate_end; @@ -2620,7 +2627,7 @@ void mr_menu::slot_conn_rail() { struct road_type *prail = road_by_gui_type(ROAD_GUI_RAILROAD); - if (prail != NULL) { + if (prail != nullptr) { struct extra_type *tgt; tgt = road_extra_get(prail); @@ -2635,7 +2642,7 @@ void mr_menu::slot_conn_maglev() { struct road_type *pmaglev = road_by_gui_type(ROAD_GUI_MAGLEV); - if (pmaglev != NULL) { + if (pmaglev != nullptr) { struct extra_type *tgt; tgt = road_extra_get(pmaglev); @@ -2666,7 +2673,7 @@ void mr_menu::slot_conn_road() { struct road_type *proad = road_by_gui_type(ROAD_GUI_ROAD); - if (proad != NULL) { + if (proad != nullptr) { struct extra_type *tgt; tgt = road_extra_get(proad); @@ -2732,7 +2739,7 @@ void mr_menu::slot_build_road() punit); bool building_road = false; - if (tgt != NULL + if (tgt != nullptr && can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt)) { request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt); building_road = true; @@ -2960,11 +2967,11 @@ void mr_menu::slot_delayed_goto() return; } if (hover_state != HOVER_GOTO) { - set_hover_state(punits, HOVER_GOTO, ACTIVITY_LAST, NULL, + set_hover_state(punits, HOVER_GOTO, ACTIVITY_LAST, nullptr, NO_TARGET, NO_TARGET, ACTION_NONE, ORDER_LAST); enter_goto_state(punits); create_line_at_mouse_pos(); - control_mouse_cursor(NULL); + control_mouse_cursor(nullptr); } unit_list_iterate(get_units_in_focus(), punit) { i++; @@ -3612,7 +3619,7 @@ void mr_menu::messages_options() **************************************************************************/ void mr_menu::save_options_now() { - options_save(NULL); + options_save(nullptr); } /**********************************************************************//** @@ -3678,7 +3685,7 @@ void mr_menu::save_image() **************************************************************************/ void mr_menu::save_game() { - send_save_game(NULL); + send_save_game(nullptr); } /**********************************************************************//** @@ -3755,7 +3762,8 @@ bool mr_menu::confirm_disruptive_selection() void multiairlift(struct city *acity, Unit_type_id ut) { struct tile *ptile; - city_list_iterate(client.conn.playing->cities, pcity) { + + city_list_iterate(client_player()->cities, pcity) { if (get_city_bonus(pcity, EFT_AIRLIFT) > 0) { ptile = city_tile(pcity); unit_list_iterate(ptile->units, punit) { diff --git a/client/gui-qt/messagewin.cpp b/client/gui-qt/messagewin.cpp index 0b227a9002..4c42d09ac0 100644 --- a/client/gui-qt/messagewin.cpp +++ b/client/gui-qt/messagewin.cpp @@ -261,7 +261,7 @@ void messagewdg::item_selected(const QItemSelection &sl, index = indexes.at(0); i = index.row(); pmsg = meswin_get_message(i); - if (i > -1 && pmsg != NULL) { + if (i > -1 && pmsg != nullptr) { if (QApplication::mouseButtons() == Qt::LeftButton || QApplication::mouseButtons() == Qt::RightButton) { meswin_set_visited_state(i, true); @@ -355,7 +355,7 @@ void messagewdg::msg(const struct message *pmsg) item->setFont(f); } icon = get_event_sprite(tileset, pmsg->event); - if (icon != NULL) { + if (icon != nullptr) { pix = icon->pm; item->setIcon(QIcon(*pix)); } @@ -406,7 +406,7 @@ void real_meswin_dialog_update(void *unused) int i, num; const struct message *pmsg; - if (gui()->infotab == NULL) { + if (gui()->infotab == nullptr) { return; } gui()->infotab->msgwdg->clr(); diff --git a/client/gui-qt/optiondlg.cpp b/client/gui-qt/optiondlg.cpp index 00dc3cb4a2..d5a39bf9b9 100644 --- a/client/gui-qt/optiondlg.cpp +++ b/client/gui-qt/optiondlg.cpp @@ -218,7 +218,7 @@ void option_dialog::apply_option(int response) break; case RESPONSE_SAVE: desired_settable_options_update(); - options_save(NULL); + options_save(nullptr); break; case RESPONSE_RESET: full_reset(); @@ -375,7 +375,7 @@ void option_dialog::set_string(struct option *poption, const char *string) QComboBox *cb; QLineEdit *le; - if (option_str_values(poption) != NULL) { + if (option_str_values(poption) != nullptr) { cb = reinterpret_cast(option_get_gui_data(poption)); i = cb->findText(string); if (i != -1) { @@ -395,7 +395,7 @@ QByteArray option_dialog::get_string(struct option *poption) QComboBox *cb; QLineEdit *le; - if (option_str_values(poption) != NULL) { + if (option_str_values(poption) != nullptr) { cb = reinterpret_cast(option_get_gui_data(poption)); return cb->currentText().toUtf8(); } else { @@ -474,7 +474,7 @@ unsigned int option_dialog::get_bitwise(struct option *poption) void option_dialog::set_button_color(QPushButton *button, const char *colorname) { - if (button != nullptr && colorname != NULL && colorname[0] != '\0') { + if (button != nullptr && colorname != nullptr && colorname[0] != '\0') { QString s1 = "QPushButton { background-color: "; QString s2 = ";}"; QColor col; @@ -671,7 +671,7 @@ void option_dialog::add_option(struct option *poption) case OT_STRING: values = option_str_values(poption); - if (NULL != values) { + if (values != nullptr) { combo = new QComboBox(); strvec_iterate(values, value) { combo->addItem(value); diff --git a/client/gui-qt/pages.cpp b/client/gui-qt/pages.cpp index 3a903ddda5..830c4a338d 100644 --- a/client/gui-qt/pages.cpp +++ b/client/gui-qt/pages.cpp @@ -157,7 +157,7 @@ void fc_client::create_main_page(void) rev_ver = fc_git_revision(); - if (rev_ver == NULL) { + if (rev_ver == nullptr) { // TRANS: "version 3.1.0, Qt5 client" #ifdef FC_QT5_MODE fc_snprintf(msgbuf, sizeof(msgbuf), _("%s%s, Qt5 client"), @@ -869,7 +869,7 @@ void fc_client::browse_scenarios(void) void fc_client::update_server_list(enum server_scan_type sstype, const struct server_list *list) { - QTableWidget* sel = NULL; + QTableWidget *sel = nullptr; QString host, portstr; int port; int row; @@ -984,26 +984,26 @@ void fc_client::destroy_server_scans(void) { if (meta_scan) { server_scan_finish(meta_scan); - meta_scan = NULL; + meta_scan = nullptr; } - if (meta_scan_timer != NULL) { + if (meta_scan_timer != nullptr) { meta_scan_timer->stop(); meta_scan_timer->disconnect(); delete meta_scan_timer; - meta_scan_timer = NULL; + meta_scan_timer = nullptr; } if (lan_scan) { server_scan_finish(lan_scan); - lan_scan = NULL; + lan_scan = nullptr; } - if (lan_scan_timer != NULL) { + if (lan_scan_timer != nullptr) { lan_scan_timer->stop(); lan_scan_timer->disconnect(); delete lan_scan_timer; - lan_scan_timer = NULL; + lan_scan_timer = nullptr; } } @@ -1065,7 +1065,7 @@ bool fc_client::check_server_scan(server_scan *scan_data) **************************************************************************/ void fc_client::slot_lan_scan() { - if (lan_scan_timer == NULL) { + if (lan_scan_timer == nullptr) { return; } check_server_scan(lan_scan); @@ -1076,7 +1076,7 @@ void fc_client::slot_lan_scan() **************************************************************************/ void fc_client::slot_meta_scan() { - if (meta_scan_timer == NULL) { + if (meta_scan_timer == nullptr) { return; } check_server_scan(meta_scan); @@ -1147,7 +1147,7 @@ void fc_client::slot_selection_changed(const QItemSelection &selected, client_pages cpage = current_page(); const char *terr_name; - const struct server *pserver = NULL; + const struct server *pserver = nullptr; int ii = 0; int k, col, n, nat_y, nat_x; struct section_file *sf; @@ -1324,12 +1324,12 @@ void fc_client::slot_selection_changed(const QItemSelection &selected, // Load possible terrains and their identifiers (chars) if ((sf = secfile_load_section(fn_bytes.data(), "savefile", true))) { - while ((terr_name = secfile_lookup_str_default(sf, NULL, - "savefile.terrident%d.name", ii)) != NULL) { + while ((terr_name = secfile_lookup_str_default(sf, nullptr, + "savefile.terrident%d.name", ii)) != nullptr) { struct terrain *pterr = terrain_by_rule_name(terr_name); - if (pterr != NULL) { - const char *iptr = secfile_lookup_str_default(sf, NULL, + if (pterr != nullptr) { + const char *iptr = secfile_lookup_str_default(sf, nullptr, "savefile.terrident%d.identifier", ii); pterr->identifier_load = *iptr; } @@ -1468,10 +1468,10 @@ void fc_client::update_scenarios_page(void) } else { fcdev = fcver - (fcver % 10000); // Patch version does not count. } - sname = secfile_lookup_str_default(sf, NULL, "scenario.name"); - sdescription = secfile_lookup_str_default(sf, NULL, + sname = secfile_lookup_str_default(sf, nullptr, "scenario.name"); + sdescription = secfile_lookup_str_default(sf, nullptr, "scenario.description"); - sauthors = secfile_lookup_str_default(sf, NULL, + sauthors = secfile_lookup_str_default(sf, nullptr, "scenario.authors"); // Ignore scenarios for newer freeciv versions than we are. if (fcdev <= current_dev) { @@ -1538,7 +1538,7 @@ void fc_client::update_scenarios_page(void) .toHtmlEscaped() + "" << QString(pfile->fullname).toHtmlEscaped() - << QString(NULL != sdescription && '\0' != sdescription[0] + << QString(sdescription != nullptr && '\0' != sdescription[0] ? Q_(sdescription) : "").toHtmlEscaped() + st + format << QString::number(fcver).toHtmlEscaped(); sl.replaceInStrings("\n", "
"); @@ -1828,7 +1828,7 @@ void fc_client::update_start_page() global_item->setData(0, Qt::UserRole, qvar2); conn_list_iterate(game.est_connections, pconn) { - if (NULL != pconn->playing || !pconn->observer) { + if (pconn->playing != nullptr || !pconn->observer) { continue; } item = new QTreeWidgetItem(); @@ -1861,7 +1861,7 @@ void fc_client::update_start_page() detach_item->setData(0, Qt::UserRole, qvar2); conn_list_iterate(game.all_connections, pconn) { - if (NULL != pconn->playing || pconn->observer) { + if (pconn->playing != nullptr || pconn->observer) { continue; } item = new QTreeWidgetItem(); @@ -2114,32 +2114,33 @@ void fc_client::update_sidebar_tooltips() int max; int entries_used, building_total, unit_total, tax; char buf[256]; - struct improvement_entry building_entries[B_LAST]; struct unit_entry unit_entries[U_LAST]; + struct player *pplayer; if (current_page() != PAGE_GAME) { return; } - if (NULL != client.conn.playing) { - max = get_player_bonus(client.conn.playing, EFT_MAX_RATES); + pplayer = client_player(); + if (pplayer != nullptr) { + max = get_player_bonus(pplayer, EFT_MAX_RATES); } else { max = 100; } if (!client_is_global_observer()) { sw_science->set_tooltip(science_dialog_text()); - str = QString(nation_plural_for_player(client_player())); + str = QString(nation_plural_for_player(pplayer)); str = str + '\n' + get_info_label_text(false); sw_map->set_tooltip(str); str = QString(_("Tax: %1% Science: %2% Luxury: %3%\n")) - .arg(client.conn.playing->economic.tax) - .arg(client.conn.playing->economic.luxury) - .arg(client.conn.playing->economic.science); + .arg(pplayer->economic.tax) + .arg(pplayer->economic.luxury) + .arg(pplayer->economic.science); str += QString(_("%1 - max rate: %2%")). - arg(government_name_for_player(client.conn.playing), + arg(government_name_for_player(pplayer), QString::number(max)); get_economy_report_units_data(unit_entries, &entries_used, &unit_total); @@ -2148,9 +2149,9 @@ void fc_client::update_sidebar_tooltips() fc_snprintf(buf, sizeof(buf), _("Income: %d Total Costs: %d"), tax, building_total + unit_total); sw_economy->set_tooltip(buf); - if (player_primary_capital(client_player())) { + if (player_primary_capital(pplayer)) { sw_cities->set_tooltip(text_happiness_cities( - player_primary_capital(client_player()))); + player_primary_capital(pplayer))); } } else { sw_tax->set_tooltip(""); @@ -2158,6 +2159,7 @@ void fc_client::update_sidebar_tooltips() sw_map->set_tooltip(""); sw_economy->set_tooltip(""); } + sw_indicators->set_tooltip(QString(get_info_label_text_popup())); } diff --git a/client/gui-qt/plrdlg.cpp b/client/gui-qt/plrdlg.cpp index a8e006ebef..fe652ac889 100644 --- a/client/gui-qt/plrdlg.cpp +++ b/client/gui-qt/plrdlg.cpp @@ -326,12 +326,12 @@ bool plr_sorter::lessThan(const QModelIndex &left, { struct player_dlg_column *column = &(player_dlg_columns[left.column()]); - if (column->sort_func != NULL) { + if (column->sort_func != nullptr) { int li = left.row(); int ri = right.row(); int i = 0; - struct player *lplr = NULL; - struct player *rplr = NULL; + struct player *lplr = nullptr; + struct player *rplr = nullptr; // Duplicates populate() logic to find player matching index players_iterate(pplayer) { @@ -362,7 +362,7 @@ bool plr_sorter::lessThan(const QModelIndex &left, plr_widget::plr_widget(plr_report *pr): QTreeView() { plr = pr; - other_player = NULL; + other_player = nullptr; selected_player = nullptr; pid = new plr_item_delegate(this); setItemDelegate(pid); @@ -516,7 +516,7 @@ void plr_widget::nation_selected(const QItemSelection &sl, QString rule; bool intel; - other_player = NULL; + other_player = nullptr; intel_str.clear(); tech_str.clear(); ally_str.clear(); @@ -740,12 +740,12 @@ void plr_widget::nation_selected(const QItemSelection &sl, if (wonder_is_built(pplayer, impr)) { struct city *wcity = city_from_wonder(pplayer, impr); - if (wcity != NULL) { + if (wcity != nullptr) { cityname = city_name_get(wcity); } else { cityname = _("(unknown city)"); } - if (improvement_obsolete(pplayer, impr, NULL)) { + if (improvement_obsolete(pplayer, impr, nullptr)) { notes = _(" (obsolete)"); } } else if (wonder_is_lost(pplayer, impr)) { @@ -1072,6 +1072,7 @@ void plr_report::update_report(bool update_selection) { QModelIndex qmi; int player_count = 0; + struct player *cplayer; /* First make sure number of rows is correct - there can be new * nations because of civil war. We don't want our actions to @@ -1106,15 +1107,17 @@ void plr_report::update_report(bool update_selection) tech_label->setText(plr_wdg->tech_str); wonder_label->setText(plr_wdg->wonder_str); other_player = plr_wdg->other_player; - if (other_player == NULL || !can_client_issue_orders()) { + if (other_player == nullptr || !can_client_issue_orders()) { return; } - if (NULL != client.conn.playing) { - if (other_player != client.conn.playing) { + + cplayer = client_player(); + if (cplayer != nullptr) { + if (other_player != cplayer) { // We keep button sensitive in case of DIPL_SENATE_BLOCKING, so that player // can request server side to check requirements of those effects with omniscience - if (pplayer_can_cancel_treaty(client_player(), other_player) != DIPL_ERROR) { + if (pplayer_can_cancel_treaty(cplayer, other_player) != DIPL_ERROR) { cancel_but->setEnabled(true); } toggle_ai_but->setText(_("AI Mode")); @@ -1124,13 +1127,14 @@ void plr_report::update_report(bool update_selection) } else { toggle_ai_but->setText(_("AI Mode")); } - if (gives_shared_vision(client_player(), other_player) - && !players_on_same_team(client_player(), other_player)) { + if (gives_shared_vision(cplayer, other_player) + && !players_on_same_team(cplayer, other_player)) { withdraw_but->setEnabled(true); } if (can_meet_with_player(other_player)) { meet_but->setEnabled(true); } + plr_wdg->restore_selection(); } diff --git a/client/gui-qt/repodlgs.cpp b/client/gui-qt/repodlgs.cpp index d9f452cc20..d62a6592a0 100644 --- a/client/gui-qt/repodlgs.cpp +++ b/client/gui-qt/repodlgs.cpp @@ -143,7 +143,7 @@ unittype_item::unittype_item(QWidget *parent, hbox_upkeep->addWidget(&shield_upkeep); lab = new QLabel(""); spr = tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "upkeep.shield", - "citybar.shields", NULL, "", "", false); + "citybar.shields", nullptr, "", "", false); img = spr->pm->toImage(); crop = zealous_crop_rect(img); cropped_img = img.copy(crop); @@ -164,7 +164,7 @@ unittype_item::unittype_item(QWidget *parent, hbox_upkeep->addWidget(&food_upkeep); lab = new QLabel(""); spr = tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "citybar.food", - "citybar.food", NULL, "", "", false); + "citybar.food", nullptr, "", "", false); img = spr->pm->toImage(); crop = zealous_crop_rect(img); cropped_img = img.copy(crop); @@ -551,8 +551,8 @@ bool comp_less_than(const qlist_item &q1, const qlist_item &q2) ****************************************************************************/ research_diagram::research_diagram(QWidget *parent): QWidget(parent) { - pcanvas = NULL; - req = NULL; + pcanvas = nullptr; + req = nullptr; reset(); setMouseTracking(true); } @@ -700,10 +700,10 @@ void research_diagram::update_reqtree() void research_diagram::reset() { timer_active = false; - if (req != NULL) { + if (req != nullptr) { destroy_reqtree(req); } - if (pcanvas != NULL) { + if (pcanvas != nullptr) { canvas_free(pcanvas); } req = create_reqtree(client_player(), true); @@ -771,13 +771,14 @@ void research_diagram::mouseMoveEvent(QMouseEvent *event) QString def_str; char buffer[8192]; char buf2[1]; + struct player *pplayer = client_player(); buf2[0] = '\0'; for (i = 0; i < tt_help.count(); i++) { rttp = tt_help.at(i); if (rttp->rect.contains(event->pos())) { if (rttp->tech_id != -1) { - helptext_advance(buffer, sizeof(buffer), client.conn.playing, + helptext_advance(buffer, sizeof(buffer), pplayer, buf2, rttp->tech_id); tt_text = QString(buffer); def_str = "

" @@ -787,15 +788,15 @@ void research_diagram::mouseMoveEvent(QMouseEvent *event) } else if (rttp->timpr != nullptr) { def_str = get_tooltip_improvement(rttp->timpr, nullptr); tt_text = helptext_building(buffer, sizeof(buffer), - client.conn.playing, NULL, rttp->timpr); + pplayer, nullptr, rttp->timpr); tt_text = cut_helptext(tt_text); } else if (rttp->tunit != nullptr) { def_str = get_tooltip_unit(rttp->tunit); - tt_text += helptext_unit(buffer, sizeof(buffer), client.conn.playing, - buf2, rttp->tunit); + tt_text += helptext_unit(buffer, sizeof(buffer), pplayer, + buf2, rttp->tunit); tt_text = cut_helptext(tt_text); } else if (rttp->tgov != nullptr) { - helptext_government(buffer, sizeof(buffer), client.conn.playing, + helptext_government(buffer, sizeof(buffer), pplayer, buf2, rttp->tgov); tt_text = QString(buffer); tt_text = cut_helptext(tt_text); @@ -877,8 +878,8 @@ science_report::science_report(): QWidget() res_diag = new research_diagram(); scroll = new QScrollArea(); - curr_list = NULL; - goal_list = NULL; + curr_list = nullptr; + goal_list = nullptr; progress->setTextVisible(true); progress_label->setSizePolicy(size_fixed_policy); sci_layout->addWidget(progress_label, 0, 0, 1, 8); @@ -974,7 +975,7 @@ void science_report::update_report() struct sprite *sp; Tech_type_id ac; - fc_assert_ret(NULL != research); + fc_assert_ret(research != nullptr); if (curr_list) { delete curr_list; @@ -1164,7 +1165,7 @@ void qtg_real_science_report_dialog_update(void *unused) QString str; struct player *plr = client_player(); - if (NULL != plr) { + if (plr != nullptr) { struct research *research = research_get(plr); if (research->researching == A_UNSET) { @@ -1298,12 +1299,12 @@ void eco_report::update_report() struct improvement_entry *pentry = building_entries + i; struct impr_type *pimprove = pentry->type; - pix = NULL; + pix = nullptr; sprite = get_building_sprite(tileset, pimprove); - if (sprite != NULL) { + if (sprite != nullptr) { pix = sprite->pm; } - if (pix != NULL) { + if (pix != nullptr) { pix_scaled = pix->scaledToHeight(h); } else { pix_scaled.fill(); @@ -1346,10 +1347,10 @@ void eco_report::update_report() struct unit_type *putype = pentry->type; cid id; - pix = NULL; + pix = nullptr; sprite = get_unittype_sprite(tileset, putype, ACTIVITY_LAST, direction8_invalid()); - if (sprite != NULL) { + if (sprite != nullptr) { pix = sprite->pm; } id = cid_encode_unit(putype); @@ -1360,7 +1361,7 @@ void eco_report::update_report() item->setTextAlignment(Qt::AlignHCenter); switch (j) { case 0: - if (pix != NULL) { + if (pix != nullptr) { pix_scaled = pix->scaledToHeight(h); item->setData(Qt::DecorationRole, pix_scaled); } @@ -1632,7 +1633,7 @@ void endgame_report::update_report(const struct packet_endgame_player *packet) break; case 1: pix = get_nation_flag_sprite(tileset, nation_of_player(pplayer))->pm; - if (pix != NULL) { + if (pix != nullptr) { item->setData(Qt::DecorationRole, *pix); } break; diff --git a/client/gui-qt/sidebar.cpp b/client/gui-qt/sidebar.cpp index d9cf742288..dd3014b41f 100644 --- a/client/gui-qt/sidebar.cpp +++ b/client/gui-qt/sidebar.cpp @@ -659,7 +659,7 @@ void update_turn_done_tooltip() { struct option *opt = optset_option_by_name(server_optset, "fixedlength"); - if (opt != NULL && option_bool_get(opt)) { + if (opt != nullptr && option_bool_get(opt)) { gui()->sw_endturn->setToolTip(_("Fixed length turns")); } else { char buf[256]; diff --git a/client/gui-qt/sprite.cpp b/client/gui-qt/sprite.cpp index 8dc11af7d6..8a5cf22996 100644 --- a/client/gui-qt/sprite.cpp +++ b/client/gui-qt/sprite.cpp @@ -28,7 +28,7 @@ static const char **gfx_array_extensions = nullptr; /************************************************************************//** - Return a NULL-terminated, permanently allocated array of possible + Return a nullptr-terminated, permanently allocated array of possible graphics types extensions. Extensions listed first will be checked first. ****************************************************************************/ @@ -54,7 +54,7 @@ const char **gfx_fileextensions(void) gfx_array_extensions[j] = ext; j++; } - gfx_array_extensions[j] = NULL; + gfx_array_extensions[j] = nullptr; return gfx_array_extensions; } @@ -115,10 +115,10 @@ struct sprite *qtg_crop_sprite(struct sprite *source, int heightzoom; int hex = 0; - fc_assert_ret_val(source, NULL); + fc_assert_ret_val(source, nullptr); if (!width || !height) { - return NULL; + return nullptr; } if (scale != 1.0f && (tileset_hex_height(tileset) > 0 || tileset_hex_width(tileset) > 0)) { diff --git a/client/gui-qt/voteinfo_bar.cpp b/client/gui-qt/voteinfo_bar.cpp index b533299f56..a4c9b50b00 100644 --- a/client/gui-qt/voteinfo_bar.cpp +++ b/client/gui-qt/voteinfo_bar.cpp @@ -70,8 +70,8 @@ void pregamevote::v_abstain() { struct voteinfo *vi; - vi = voteinfo_queue_get_current(NULL); - if (vi == NULL) { + vi = voteinfo_queue_get_current(nullptr); + if (vi == nullptr) { return; } voteinfo_do_vote(vi->vote_no, CVT_ABSTAIN); @@ -84,8 +84,8 @@ void pregamevote::v_no() { struct voteinfo *vi; - vi = voteinfo_queue_get_current(NULL); - if (vi == NULL) { + vi = voteinfo_queue_get_current(nullptr); + if (vi == nullptr) { return; } voteinfo_do_vote(vi->vote_no, CVT_NO); @@ -98,8 +98,8 @@ void pregamevote::v_yes() { struct voteinfo *vi; - vi = voteinfo_queue_get_current(NULL); - if (vi == NULL) { + vi = voteinfo_queue_get_current(nullptr); + if (vi == nullptr) { return; } voteinfo_do_vote(vi->vote_no, CVT_YES); @@ -111,22 +111,22 @@ void pregamevote::v_yes() void pregamevote::update_vote() { int vote_count, index; - struct voteinfo *vi = NULL; + struct voteinfo *vi = nullptr; char buf[1024], status[1024], color[32]; bool running; show(); vote_count = voteinfo_queue_size(); vi = voteinfo_queue_get_current(&index); - if (vi != NULL && vi->resolved && vi->passed) { + if (vi != nullptr && vi->resolved && vi->passed) { // TRANS: Describing a vote that passed. fc_snprintf(status, sizeof(status), _("[passed]")); sz_strlcpy(color, "green"); - } else if (vi != NULL && vi->resolved && !vi->passed) { + } else if (vi != nullptr && vi->resolved && !vi->passed) { // TRANS: Describing a vote that failed. fc_snprintf(status, sizeof(status), _("[failed]")); sz_strlcpy(color, "red"); - } else if (vi != NULL && vi->remove_time > 0) { + } else if (vi != nullptr && vi->remove_time > 0) { // TRANS: Describing a vote that was removed. fc_snprintf(status, sizeof(status), _("[removed]")); sz_strlcpy(color, "grey"); @@ -141,7 +141,7 @@ void pregamevote::update_vote() } else { buf[0] = '\0'; } - if (vi != NULL) { + if (vi != nullptr) { lab_yes->setText(QString::number(vi->yes)); lab_no->setText(QString::number(vi->no)); lab_abstain->setText(QString::number(vi->abstain)); @@ -161,7 +161,7 @@ void pregamevote::update_vote() lab_no->setText("-"); lab_abstain->setText("-"); } - running = vi != NULL && !vi->resolved && vi->remove_time == 0; + running = vi != nullptr && !vi->resolved && vi->remove_time == 0; vote_yes->setEnabled(running); vote_no->setEnabled(running); vote_abstain->setEnabled(running); @@ -231,7 +231,7 @@ void voteinfo_gui_update(void) } if (gui()->current_page() == PAGE_GAME) { - if (gui()->x_vote != NULL) { + if (gui()->x_vote != nullptr) { gui()->x_vote->show(); gui()->x_vote->update_vote(); } diff --git a/tools/fcmp/mpgui_qt.cpp b/tools/fcmp/mpgui_qt.cpp index 46fbf9f71d..2d8f6c0c03 100644 --- a/tools/fcmp/mpgui_qt.cpp +++ b/tools/fcmp/mpgui_qt.cpp @@ -47,7 +47,7 @@ #include "mpgui_qt.h" -struct fcmp_params fcmp = { MODPACK_LIST_URL, NULL, NULL }; +struct fcmp_params fcmp = { MODPACK_LIST_URL, nullptr, nullptr }; static mpgui *gui; diff --git a/tools/fcmp/mpgui_qt.h b/tools/fcmp/mpgui_qt.h index b7d4994426..20b18fee0e 100644 --- a/tools/fcmp/mpgui_qt.h +++ b/tools/fcmp/mpgui_qt.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/tools/fcmp/mpgui_qt_worker.h b/tools/fcmp/mpgui_qt_worker.h index 95df9759f9..035fb4fcb8 100644 --- a/tools/fcmp/mpgui_qt_worker.h +++ b/tools/fcmp/mpgui_qt_worker.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/tools/ruledit/effect_edit.cpp b/tools/ruledit/effect_edit.cpp index f773798c29..6ead8ab135 100644 --- a/tools/ruledit/effect_edit.cpp +++ b/tools/ruledit/effect_edit.cpp @@ -258,13 +258,13 @@ void effect_edit::fill_active() if (selected != nullptr) { edit_type_button->setText(effect_type_name(selected->type)); value_box->setValue(selected->value); - if (selected->multiplier != NULL) { + if (selected->multiplier != nullptr) { mp_button->setText(multiplier_rule_name(selected->multiplier)); } else { mp_button->setText(NO_MULTIPLIER_NAME); } - if (selected->rulesave.comment == NULL) { + if (selected->rulesave.comment == nullptr) { comment->setText(""); } else { comment->setText(selected->rulesave.comment); @@ -332,7 +332,7 @@ void effect_edit::closeEvent(QCloseEvent *event) **************************************************************************/ void effect_edit::add_now() { - struct effect *peffect = effect_new((enum effect_type)0, 0, NULL); + struct effect *peffect = effect_new((enum effect_type)0, 0, nullptr); if (filter.kind != VUT_NONE) { struct requirement req; @@ -372,7 +372,7 @@ void effect_edit::multiplier_menu(QAction *action) } if (!fc_strcasecmp(NO_MULTIPLIER_NAME, an_bytes)) { - selected->multiplier = NULL; + selected->multiplier = nullptr; } else { selected->multiplier = multiplier_by_rule_name(an_bytes); } @@ -386,14 +386,14 @@ void effect_edit::multiplier_menu(QAction *action) void effect_edit::comment_given() { if (selected != nullptr) { - if (selected->rulesave.comment != NULL) { + if (selected->rulesave.comment != nullptr) { free(selected->rulesave.comment); } if (!comment->text().isEmpty()) { selected->rulesave.comment = fc_strdup(comment->text().toUtf8()); } else { - selected->rulesave.comment = NULL; + selected->rulesave.comment = nullptr; } fill_active(); diff --git a/tools/ruledit/req_edit.cpp b/tools/ruledit/req_edit.cpp index 216d187c38..b8d9667f89 100644 --- a/tools/ruledit/req_edit.cpp +++ b/tools/ruledit/req_edit.cpp @@ -152,7 +152,7 @@ void req_edit::refresh_item(QListWidgetItem *item, struct requirement *preq) char buf[512]; buf[0] = '\0'; - if (!req_text_insert(buf, sizeof(buf), NULL, preq, VERB_ACTUAL, "")) { + if (!req_text_insert(buf, sizeof(buf), nullptr, preq, VERB_ACTUAL, "")) { if (preq->present) { universal_name_translation(&preq->source, buf, sizeof(buf)); } else { @@ -224,7 +224,7 @@ void req_edit::clear_selected() selected = nullptr; selected_values.source.kind = VUT_NONE; - selected_values.source.value.advance = NULL; + selected_values.source.value.advance = nullptr; selected_values.range = REQ_RANGE_LOCAL; selected_values.present = true; selected_values.survives = false; diff --git a/tools/ruledit/ruledit.cpp b/tools/ruledit/ruledit.cpp index e43f7f4c0c..bced574a78 100644 --- a/tools/ruledit/ruledit.cpp +++ b/tools/ruledit/ruledit.cpp @@ -68,7 +68,7 @@ int main(int argc, char **argv) // Load Windows post-crash debugger #ifdef FREECIV_MSWINDOWS # ifndef FREECIV_NDEBUG - if (LoadLibrary("exchndl.dll") == NULL) { + if (LoadLibrary("exchndl.dll") == nullptr) { # ifdef FREECIV_DEBUG fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n"); # endif // FREECIV_DEBUG @@ -94,7 +94,7 @@ int main(int argc, char **argv) registry_module_init(); // Initialize command line arguments. - reargs.ruleset = NULL; + reargs.ruleset = nullptr; ui_options = re_parse_cmdline(argc, argv); @@ -226,7 +226,7 @@ static int re_parse_cmdline(int argc, char *argv[]) i++; } - log_init(NULL, loglevel, NULL, NULL, fatal_assertions); + log_init(nullptr, loglevel, nullptr, nullptr, fatal_assertions); return ui_options; } diff --git a/tools/ruledit/ruledit_qt.cpp b/tools/ruledit/ruledit_qt.cpp index da919c71a1..a445596fbf 100644 --- a/tools/ruledit/ruledit_qt.cpp +++ b/tools/ruledit/ruledit_qt.cpp @@ -116,8 +116,8 @@ void ruledit_gui::setup(QWidget *central_in) const char *rev_ver; const char *mode; - data.nationlist = NULL; - data.nationlist_saved = NULL; + data.nationlist = nullptr; + data.nationlist_saved = nullptr; central = central_in; @@ -129,7 +129,7 @@ void ruledit_gui::setup(QWidget *central_in) mode = R__("built in Qt5 mode."); #endif // FC_QT5_MODE - if (rev_ver == NULL) { + if (rev_ver == nullptr) { fc_snprintf(verbuf, sizeof(verbuf), "%s%s\n%s", word_version(), VERSION_STRING, mode); } else { @@ -249,14 +249,14 @@ void ruledit_gui::launch_now() { convlog = new conversion_log(QString::fromUtf8(R__("Old ruleset to a new format"))); - if (load_rulesets(NULL, NULL, TRUE, conversion_log_cb, FALSE, TRUE, TRUE)) { + if (load_rulesets(nullptr, nullptr, TRUE, conversion_log_cb, FALSE, TRUE, TRUE)) { display_msg(R__("Ruleset loaded")); // Make freeable copy - if (game.server.ruledit.nationlist != NULL) { + if (game.server.ruledit.nationlist != nullptr) { data.nationlist = fc_strdup(game.server.ruledit.nationlist); } else { - data.nationlist = NULL; + data.nationlist = nullptr; } ach->refresh(); diff --git a/tools/ruledit/tab_enablers.cpp b/tools/ruledit/tab_enablers.cpp index 17dcb6edbd..66b95896fb 100644 --- a/tools/ruledit/tab_enablers.cpp +++ b/tools/ruledit/tab_enablers.cpp @@ -73,13 +73,13 @@ enabler_problem_level(struct action_enabler *enabler) { struct req_vec_problem *problem = action_enabler_suggest_repair(enabler); - if (problem != NULL) { + if (problem != nullptr) { req_vec_problem_free(problem); return RVPS_REPAIR; } problem = action_enabler_suggest_improvement(enabler); - if (problem != NULL) { + if (problem != nullptr) { req_vec_problem_free(problem); return RVPS_IMPROVE; } @@ -411,7 +411,7 @@ fix_enabler_item::fix_enabler_item(struct action_enabler *enabler) char buf[MAX_LEN_NAME * 2]; struct action *paction = enabler_get_action(enabler); - fc_assert_ret(paction != NULL); + fc_assert_ret(paction != nullptr); /* Can't use QString::asprintf() as msys libintl.h defines asprintf() * as a macro */ @@ -481,7 +481,7 @@ struct req_vec_problem *fix_enabler_item::find_next_problem(void) { struct req_vec_problem *out = action_enabler_suggest_repair(local_copy); - if (out != NULL) { + if (out != nullptr) { return out; } diff --git a/tools/ruledit/tab_misc.cpp b/tools/ruledit/tab_misc.cpp index 7970a3e1a8..2d574af078 100644 --- a/tools/ruledit/tab_misc.cpp +++ b/tools/ruledit/tab_misc.cpp @@ -90,7 +90,7 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() PWSTR folder_path; if (SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, - NULL, &folder_path) == S_OK) { + nullptr, &folder_path) == S_OK) { savedir->setText(QString::fromWCharArray(folder_path) + "\\ruledit-tmp"); } else { savedir->setText("ruledit-tmp"); @@ -250,7 +250,7 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() **************************************************************************/ void tab_misc::ruleset_loaded() { - if (game.server.ruledit.description_file != NULL) { + if (game.server.ruledit.description_file != nullptr) { desc_via_file->setChecked(true); desc_file->setText(game.server.ruledit.description_file); } else { @@ -292,7 +292,7 @@ void tab_misc::save_now() strncpy(game.control.version, ba_bytes.data(), sizeof(game.control.version) - 1); - if (!autoadjust_ruleset_data() || !sanity_check_ruleset_data(NULL)) { + if (!autoadjust_ruleset_data() || !sanity_check_ruleset_data(nullptr)) { QMessageBox *box = new QMessageBox(); box->setText("Current data fails sanity checks. Save anyway?"); @@ -519,10 +519,10 @@ void tab_misc::flush_widgets() df_bytes = desc_file->text().toUtf8(); game.server.ruledit.description_file = fc_strdup(df_bytes.data()); } else { - if (game.server.ruledit.description_file != NULL) { + if (game.server.ruledit.description_file != nullptr) { free(game.server.ruledit.description_file); } - game.server.ruledit.description_file = NULL; + game.server.ruledit.description_file = nullptr; } } diff --git a/tools/ruledit/tab_nation.cpp b/tools/ruledit/tab_nation.cpp index 139dc2c9be..f076ac22a9 100644 --- a/tools/ruledit/tab_nation.cpp +++ b/tools/ruledit/tab_nation.cpp @@ -67,7 +67,7 @@ tab_nation::tab_nation(ruledit_gui *ui_in) : QWidget() **************************************************************************/ void tab_nation::refresh() { - if (ui->data.nationlist == NULL) { + if (ui->data.nationlist == nullptr) { via_include->setChecked(false); nationlist->setEnabled(false); } else { @@ -90,7 +90,7 @@ void tab_nation::flush_widgets() nln_bytes = nationlist->text().toUtf8(); ui->data.nationlist = fc_strdup(nln_bytes.data()); } else { - ui->data.nationlist = NULL; + ui->data.nationlist = nullptr; } } @@ -100,7 +100,7 @@ void tab_nation::flush_widgets() void tab_nation::nationlist_toggle(bool checked) { if (checked) { - if (ui->data.nationlist_saved != NULL) { + if (ui->data.nationlist_saved != nullptr) { ui->data.nationlist = ui->data.nationlist_saved; } else { ui->data.nationlist = fc_strdup("default/nationlist.ruleset"); @@ -111,7 +111,7 @@ void tab_nation::nationlist_toggle(bool checked) FC_FREE(ui->data.nationlist_saved); nln_bytes = nationlist->text().toUtf8(); ui->data.nationlist_saved = fc_strdup(nln_bytes.data()); - ui->data.nationlist = NULL; + ui->data.nationlist = nullptr; } refresh(); -- 2.40.1