From 95759aa8942e84999e260b92da291f5e06790a1a Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 22 Jul 2025 01:52:41 +0300
Subject: [PATCH 63/63] research.c: Replace NULL with nullptr

See RM #1621

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/research.c | 122 ++++++++++++++++++++++++----------------------
 1 file changed, 63 insertions(+), 59 deletions(-)

diff --git a/common/research.c b/common/research.c
index 69f29e8b26..3fed430a7c 100644
--- a/common/research.c
+++ b/common/research.c
@@ -85,10 +85,10 @@ void researches_init(void)
 
   /* Set technology names. */
   /* TRANS: "None" tech */
-  name_set(&advance_unset_name, NULL, N_("?tech:None"));
-  name_set(&advance_future_name, NULL, N_("Future Tech."));
+  name_set(&advance_unset_name, nullptr, N_("?tech:None"));
+  name_set(&advance_future_name, nullptr, N_("Future Tech."));
   /* TRANS: "Unknown" advance/technology */
-  name_set(&advance_unknown_name, NULL, N_("(Unknown)"));
+  name_set(&advance_unknown_name, nullptr, N_("(Unknown)"));
 
   future_rule_name = strvec_new();
   future_name_translation = strvec_new();
@@ -108,7 +108,8 @@ void researches_free(void)
 ****************************************************************************/
 int research_number(const struct research *presearch)
 {
-  fc_assert_ret_val(NULL != presearch, -1);
+  fc_assert_ret_val(presearch != nullptr, -1);
+
   return presearch - research_array;
 }
 
@@ -117,8 +118,9 @@ int research_number(const struct research *presearch)
 ****************************************************************************/
 struct research *research_by_number(int number)
 {
-  fc_assert_ret_val(0 <= number, NULL);
-  fc_assert_ret_val(ARRAY_SIZE(research_array) > number, NULL);
+  fc_assert_ret_val(0 <= number, nullptr);
+  fc_assert_ret_val(ARRAY_SIZE(research_array) > number, nullptr);
+
   return &research_array[number];
 }
 
@@ -127,9 +129,9 @@ struct research *research_by_number(int number)
 ****************************************************************************/
 struct research *research_get(const struct player *pplayer)
 {
-  if (NULL == pplayer) {
+  if (pplayer == nullptr) {
     /* Special case used at client side. */
-    return NULL;
+    return nullptr;
   } else if (game.info.team_pooled_research) {
     return &research_array[team_number(pplayer->team)];
   } else {
@@ -207,7 +209,8 @@ research_advance_name(Tech_type_id tech)
   } else {
     const struct advance *padvance = advance_by_number(tech);
 
-    fc_assert_ret_val(NULL != padvance, NULL);
+    fc_assert_ret_val(padvance != nullptr, nullptr);
+
     return &padvance->name;
   }
 }
@@ -233,19 +236,19 @@ static const char *research_future_set_name(struct strvec *psv, int no,
 
 /************************************************************************//**
   Store the rule name of the given tech (including A_FUTURE) in 'buf'.
-  'presearch' may be NULL.
+  'presearch' may be nullptr.
   We don't return a static buffer because that would break anything that
   needed to work with more than one name at a time.
 ****************************************************************************/
 const char *research_advance_rule_name(const struct research *presearch,
                                        Tech_type_id tech)
 {
-  if (A_FUTURE == tech && NULL != presearch) {
+  if (A_FUTURE == tech && presearch != nullptr) {
     const int no = presearch->future_tech;
     const char *name;
 
     name = strvec_get(future_rule_name, no);
-    if (name == NULL) {
+    if (name == nullptr) {
       char buffer[256];
 
       /* NB: 'presearch->future_tech == 0' means "Future Tech. 1". */
@@ -255,7 +258,7 @@ const char *research_advance_rule_name(const struct research *presearch,
       name = research_future_set_name(future_rule_name, no, buffer);
     }
 
-    fc_assert(name != NULL);
+    fc_assert(name != nullptr);
 
     return name;
   }
@@ -265,7 +268,7 @@ const char *research_advance_rule_name(const struct research *presearch,
 
 /************************************************************************//**
   Store the translated name of the given tech (including A_FUTURE) in 'buf'.
-  'presearch' may be NULL.
+  'presearch' may be nullptr.
   We don't return a static buffer because that would break anything that
   needed to work with more than one name at a time.
 ****************************************************************************/
@@ -273,12 +276,12 @@ const char *
 research_advance_name_translation(const struct research *presearch,
                                   Tech_type_id tech)
 {
-  if (A_FUTURE == tech && NULL != presearch) {
+  if (A_FUTURE == tech && presearch != nullptr) {
     const int no = presearch->future_tech;
     const char *name;
 
     name = strvec_get(future_name_translation, no);
-    if (name == NULL) {
+    if (name == nullptr) {
       char buffer[256];
 
       /* NB: 'presearch->future_tech == 0' means "Future Tech. 1". */
@@ -286,7 +289,7 @@ research_advance_name_translation(const struct research *presearch,
       name = research_future_set_name(future_name_translation, no, buffer);
     }
 
-    fc_assert(name != NULL);
+    fc_assert(name != nullptr);
 
     return name;
   }
@@ -335,14 +338,14 @@ research_allowed(const struct research *presearch,
 
   adv = valid_advance_by_number(tech);
 
-  if (adv == NULL) {
+  if (adv == nullptr) {
     /* Not a valid advance. */
     return FALSE;
   }
 
   research_players_iterate(presearch, pplayer) {
     if (reqs_eval(&(const struct req_context) { .player = pplayer },
-                  NULL, &(adv->research_reqs), RPT_CERTAIN)) {
+                  nullptr, &(adv->research_reqs), RPT_CERTAIN)) {
       /* It is enough that one player that shares research is allowed to
        * research it.
        * Reasoning: Imagine a tech with that requires a nation in the
@@ -416,7 +419,7 @@ static bool research_get_reachable_rreqs(const struct research *presearch,
     for (req = 0; req < AR_SIZE; req++) {
       Tech_type_id req_tech = advance_required(techs[i], req);
 
-      if (valid_advance_by_number(req_tech) == NULL) {
+      if (valid_advance_by_number(req_tech) == nullptr) {
         return FALSE;
       } else if (!BV_ISSET(done, req_tech)) {
         fc_assert(techs_num < ARRAY_SIZE(techs));
@@ -440,7 +443,7 @@ static bool research_get_reachable_rreqs(const struct research *presearch,
 static bool research_get_reachable(const struct research *presearch,
                                    Tech_type_id tech)
 {
-  if (valid_advance_by_number(tech) == NULL) {
+  if (valid_advance_by_number(tech) == nullptr) {
     return FALSE;
   } else {
     advance_root_req_iterate(advance_by_number(tech), proot) {
@@ -456,7 +459,7 @@ static bool research_get_reachable(const struct research *presearch,
         enum tech_req req;
 
         for (req = 0; req < AR_SIZE; req++) {
-          if (valid_advance(advance_requires(proot, req)) == NULL) {
+          if (valid_advance(advance_requires(proot, req)) == nullptr) {
             return FALSE;
           }
         }
@@ -613,16 +616,16 @@ void research_update(struct research *presearch)
   This can be: TECH_KNOWN, TECH_UNKNOWN, or TECH_PREREQS_KNOWN
   Should be called with existing techs.
 
-  If 'presearch' is NULL this checks whether any player knows the tech
+  If 'presearch' is nullptr this checks whether any player knows the tech
   (used by the client).
 ****************************************************************************/
 enum tech_state research_invention_state(const struct research *presearch,
                                          Tech_type_id tech)
 {
-  fc_assert_ret_val(NULL != valid_advance_by_number(tech),
+  fc_assert_ret_val(valid_advance_by_number(tech) != nullptr,
                     tech_state_invalid());
 
-  if (NULL != presearch) {
+  if (presearch != nullptr) {
     return presearch->inventions[tech].state;
   } else if (game.info.global_advances[tech]) {
     return TECH_KNOWN;
@@ -640,7 +643,7 @@ enum tech_state research_invention_set(struct research *presearch,
 {
   enum tech_state old;
 
-  fc_assert_ret_val(NULL != valid_advance_by_number(tech), -1);
+  fc_assert_ret_val(valid_advance_by_number(tech) != nullptr, -1);
 
   old = presearch->inventions[tech].state;
   if (old == value) {
@@ -662,15 +665,15 @@ enum tech_state research_invention_set(struct research *presearch,
   Returns TRUE iff the given tech is ever reachable via research by the
   players sharing the research by checking tech tree limitations.
 
-  'presearch' may be NULL in which case a simplified result is returned
+  'presearch' may be nullptr in which case a simplified result is returned
   (used by the client).
 ****************************************************************************/
 bool research_invention_reachable(const struct research *presearch,
                                   const Tech_type_id tech)
 {
-  if (valid_advance_by_number(tech) == NULL) {
+  if (valid_advance_by_number(tech) == nullptr) {
     return FALSE;
-  } else if (presearch != NULL) {
+  } else if (presearch != nullptr) {
     return presearch->inventions[tech].reachable;
   } else {
     researches_iterate(research_iter) {
@@ -694,9 +697,9 @@ bool research_invention_gettable(const struct research *presearch,
                                  const Tech_type_id tech,
                                  bool allow_holes)
 {
-  if (valid_advance_by_number(tech) == NULL) {
+  if (valid_advance_by_number(tech) == nullptr) {
     return FALSE;
-  } else if (presearch != NULL) {
+  } else if (presearch != nullptr) {
     return (allow_holes
             ? presearch->inventions[tech].root_reqs_known
             : presearch->inventions[tech].state == TECH_PREREQS_KNOWN);
@@ -722,7 +725,7 @@ Tech_type_id research_goal_step(const struct research *presearch,
 {
   const struct advance *pgoal = valid_advance_by_number(goal);
 
-  if (NULL == pgoal
+  if (pgoal == nullptr
       || !research_invention_reachable(presearch, goal)) {
     return A_UNSET;
   }
@@ -744,7 +747,7 @@ Tech_type_id research_goal_step(const struct research *presearch,
   the goal technology. This includes the goal technology. Technologies
   are only counted once.
 
-  'presearch' may be NULL in which case it will returns the total number
+  'presearch' may be nullptr in which case it will returns the total number
   of technologies needed for reaching the goal.
 ****************************************************************************/
 int research_goal_unknown_techs(const struct research *presearch,
@@ -752,9 +755,9 @@ int research_goal_unknown_techs(const struct research *presearch,
 {
   const struct advance *pgoal = valid_advance_by_number(goal);
 
-  if (NULL == pgoal) {
+  if (pgoal == nullptr) {
     return 0;
-  } else if (NULL != presearch) {
+  } else if (presearch != nullptr) {
     return presearch->inventions[goal].num_required_techs;
   } else {
     return pgoal->num_reqs;
@@ -766,7 +769,7 @@ int research_goal_unknown_techs(const struct research *presearch,
   These costs _include_ the cost for researching the goal technology
   itself.
 
-  'presearch' may be NULL in which case it will returns the total number
+  'presearch' may be nullptr in which case it will returns the total number
   of bulbs needed for reaching the goal.
 ****************************************************************************/
 int research_goal_bulbs_required(const struct research *presearch,
@@ -774,9 +777,9 @@ int research_goal_bulbs_required(const struct research *presearch,
 {
   const struct advance *pgoal = valid_advance_by_number(goal);
 
-  if (NULL == pgoal) {
+  if (pgoal == nullptr) {
     return 0;
-  } else if (NULL != presearch) {
+  } else if (presearch != nullptr) {
     return presearch->inventions[goal].bulbs_required;
   } else if (game.info.tech_cost_style == TECH_COST_CIV1CIV2) {
     int base_cost = game.info.base_tech_cost * pgoal->num_reqs
@@ -802,7 +805,7 @@ int research_goal_bulbs_required(const struct research *presearch,
   Returns if the given tech has to be researched to reach the goal. The
   goal itself isn't a requirement of itself.
 
-  'presearch' may be NULL.
+  'presearch' may be nullptr.
 ****************************************************************************/
 bool research_goal_tech_req(const struct research *presearch,
                             Tech_type_id goal, Tech_type_id tech)
@@ -810,10 +813,10 @@ bool research_goal_tech_req(const struct research *presearch,
   const struct advance *pgoal, *ptech;
 
   if (tech == goal
-      || NULL == (pgoal = valid_advance_by_number(goal))
-      || NULL == (ptech = valid_advance_by_number(tech))) {
+      || (pgoal = valid_advance_by_number(goal)) == nullptr
+      || (ptech = valid_advance_by_number(tech)) == nullptr) {
     return FALSE;
-  } else if (NULL != presearch) {
+  } else if (presearch != nullptr) {
     return BV_ISSET(presearch->inventions[goal].required_techs, tech);
   } else {
     advance_req_iterate(pgoal, preq) {
@@ -821,6 +824,7 @@ bool research_goal_tech_req(const struct research *presearch,
         return TRUE;
       }
     } advance_req_iterate_end;
+
     return FALSE;
   }
 }
@@ -862,7 +866,7 @@ bool research_goal_tech_req(const struct research *presearch,
   At the end we multiply by the sciencebox value, as a percentage. The
   cost can never be less than 1.
 
-  'presearch' may be NULL in which case a simplified result is returned
+  'presearch' may be nullptr in which case a simplified result is returned
   (used by client and manual code).
 ****************************************************************************/
 int research_total_bulbs_required(const struct research *presearch,
@@ -873,12 +877,12 @@ int research_total_bulbs_required(const struct research *presearch,
   double base_cost, total_cost;
   bool leakage = FALSE;
 
-  if (valid_advance_by_number(tech) == NULL) {
+  if (valid_advance_by_number(tech) == nullptr) {
     return 0;
   }
 
   if (!loss_value
-      && NULL != presearch
+      && presearch != nullptr
       && !is_future_tech(tech)
       && research_invention_state(presearch, tech) == TECH_KNOWN) {
     /* A non-future tech which is already known costs nothing. */
@@ -895,12 +899,12 @@ int research_total_bulbs_required(const struct research *presearch,
   base_cost = 0.0;
   switch (tech_cost_style) {
   case TECH_COST_CIV1CIV2:
-    if (NULL != presearch) {
+    if (presearch != nullptr) {
       base_cost = game.info.base_tech_cost * presearch->techs_researched;
       break;
     }
 
-    fc_assert(presearch != NULL);
+    fc_assert(presearch != nullptr);
     fc__fallthrough; /* No break; Fallback to using preset cost. */
   case TECH_COST_CLASSIC:
   case TECH_COST_CLASSIC_PRESET:
@@ -910,10 +914,10 @@ int research_total_bulbs_required(const struct research *presearch,
     {
       const struct advance *padvance = valid_advance_by_number(tech);
 
-      if (NULL != padvance) {
+      if (padvance != nullptr) {
         base_cost = padvance->cost;
       } else {
-        fc_assert(NULL != padvance); /* Always fails. */
+        fc_assert(padvance != nullptr); /* Always fails. */
       }
     }
     break;
@@ -1178,7 +1182,7 @@ static bool research_iter_team_valid(const struct iterator *it)
 
   return (0 <= rit->index
           && ARRAY_SIZE(research_array) > rit->index
-          && NULL != team_by_number(rit->index));
+          && team_by_number(rit->index) != nullptr);
 }
 
 /************************************************************************//**
@@ -1204,7 +1208,7 @@ static bool research_iter_player_valid(const struct iterator *it)
 
   return (0 <= rit->index
           && ARRAY_SIZE(research_array) > rit->index
-          && NULL != player_by_number(rit->index));
+          && player_by_number(rit->index) != nullptr);
 }
 
 /************************************************************************//**
@@ -1244,7 +1248,7 @@ static inline bool research_player_iter_valid_state(struct iterator *it)
 {
   const struct player *pplayer = iterator_get(it);
 
-  return (NULL == pplayer || pplayer->is_alive);
+  return (pplayer == nullptr || pplayer->is_alive);
 }
 
 /************************************************************************//**
@@ -1272,7 +1276,7 @@ static void research_player_iter_pooled_next(struct iterator *it)
 ****************************************************************************/
 static bool research_player_iter_pooled_valid(const struct iterator *it)
 {
-  return NULL != RESEARCH_PLAYER_ITER(it)->plink;
+  return RESEARCH_PLAYER_ITER(it)->plink != nullptr;
 }
 
 /************************************************************************//**
@@ -1288,7 +1292,7 @@ static void *research_player_iter_not_pooled_get(const struct iterator *it)
 ****************************************************************************/
 static void research_player_iter_not_pooled_next(struct iterator *it)
 {
-  RESEARCH_PLAYER_ITER(it)->pplayer = NULL;
+  RESEARCH_PLAYER_ITER(it)->pplayer = nullptr;
 }
 
 /************************************************************************//**
@@ -1296,7 +1300,7 @@ static void research_player_iter_not_pooled_next(struct iterator *it)
 ****************************************************************************/
 static bool research_player_iter_not_pooled_valid(const struct iterator *it)
 {
-  return NULL != RESEARCH_PLAYER_ITER(it)->pplayer;
+  return RESEARCH_PLAYER_ITER(it)->pplayer != nullptr;
 }
 
 /************************************************************************//**
@@ -1307,7 +1311,7 @@ struct iterator *research_player_iter_init(struct research_player_iter *it,
 {
   struct iterator *base = ITERATOR(it);
 
-  if (game.info.team_pooled_research && NULL != presearch) {
+  if (game.info.team_pooled_research && presearch != nullptr) {
     base->get = research_player_iter_pooled_get;
     base->next = research_player_iter_pooled_next;
     base->valid = research_player_iter_pooled_valid;
@@ -1317,8 +1321,8 @@ struct iterator *research_player_iter_init(struct research_player_iter *it,
     base->get = research_player_iter_not_pooled_get;
     base->next = research_player_iter_not_pooled_next;
     base->valid = research_player_iter_not_pooled_valid;
-    it->pplayer = (NULL != presearch
-                   ? player_by_number(research_number(presearch)) : NULL);
+    it->pplayer = (presearch != nullptr
+                   ? player_by_number(research_number(presearch)) : nullptr);
   }
 
   /* Ensure we have consistent data. */
@@ -1355,7 +1359,7 @@ int recalculate_techs_researched(const struct research *presearch)
   int techs = 1; /* A_NONE known, and not part of below iteration */
 
   advance_iterate(t) {
-    if (valid_advance(t) != NULL
+    if (valid_advance(t) != nullptr
         && research_invention_state(presearch, advance_number(t)) == TECH_KNOWN) {
       techs++;
     }
-- 
2.47.2

