From 4f403dba4acecf1aa53d1f55ac513522f148595d Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Mon, 31 Aug 2026 05:33:22 +0300
Subject: [PATCH 67/67] mapgen_utils.[ch]: Replace NULL with nullptr

See RM #2193

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 server/generator/mapgen_utils.c | 36 ++++++++++-----------
 server/generator/mapgen_utils.h | 56 ++++++++++++++++-----------------
 2 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/server/generator/mapgen_utils.c b/server/generator/mapgen_utils.c
index 950cc1a6f4..908208dfb4 100644
--- a/server/generator/mapgen_utils.c
+++ b/server/generator/mapgen_utils.c
@@ -39,7 +39,7 @@ static bool *placed_map;
 **************************************************************************/
 bool placed_map_is_initialized(void)
 {
-  return placed_map != NULL;
+  return placed_map != nullptr;
 }
 
 /**********************************************************************//**
@@ -59,7 +59,7 @@ void destroy_placed_map(void)
 {
   fc_assert_ret(placed_map_is_initialized());
   free(placed_map);
-  placed_map = NULL;
+  placed_map = nullptr;
 }
 
 
@@ -197,7 +197,7 @@ void smooth_int_map(int *int_map, bool zeroes_at_edges)
   int *target_map, *source_map;
   int *alt_int_map = fc_calloc(MAP_INDEX_SIZE, sizeof(*alt_int_map));
 
-  fc_assert_ret(NULL != int_map);
+  fc_assert_ret(int_map != nullptr);
 
   weight = weight_standard;
   target_map = alt_int_map;
@@ -296,10 +296,10 @@ static void recalculate_surrounders(void)
 **************************************************************************/
 static void assign_continent_flood(struct tile *ptile, bool is_land, int nr)
 {
-  struct tile_list *tlist = NULL;
+  struct tile_list *tlist = nullptr;
   const struct terrain *pterrain;
 
-  fc_assert_ret(ptile != NULL);
+  fc_assert_ret(ptile != nullptr);
 
 #ifndef FREECIV_NDEBUG
   pterrain = tile_terrain(ptile);
@@ -479,7 +479,7 @@ void assign_continent_numbers(void)
 struct terrain *most_shallow_ocean(bool frozen)
 {
   bool oceans = FALSE, frozenmatch = FALSE;
-  struct terrain *shallow = NULL;
+  struct terrain *shallow = nullptr;
 
   terrain_type_iterate(pterr) {
     if (is_ocean(pterr) && !terrain_has_flag(pterr, TER_NOT_GENERATED)) {
@@ -520,11 +520,11 @@ struct terrain *most_shallow_ocean(bool frozen)
 /**********************************************************************//**
   Picks an ocean terrain to match the given depth.
   Only considers terrains with/without Frozen flag depending on 'frozen'.
-  Return NULL when there is no available ocean.
+  Return nullptr when there is no available ocean.
 **************************************************************************/
 struct terrain *pick_ocean(int depth, bool frozen)
 {
-  struct terrain *best_terrain = NULL;
+  struct terrain *best_terrain = nullptr;
   int best_match = TERRAIN_OCEAN_DEPTH_MAXIMUM;
 
   terrain_type_iterate(pterrain) {
@@ -535,8 +535,8 @@ struct terrain *pick_ocean(int depth, bool frozen)
       int match = abs(depth - pterrain->property[MG_OCEAN_DEPTH]);
 
       if (best_match > match) {
-	best_match = match;
-	best_terrain = pterrain;
+        best_match = match;
+        best_terrain = pterrain;
       }
     }
   } terrain_type_iterate_end;
@@ -580,7 +580,7 @@ static struct terrain *most_adjacent_ocean_type(const struct tile *ptile)
     } adjc_iterate_end;
   } terrain_type_iterate_end;
 
-  return NULL;
+  return nullptr;
 }
 
 /**********************************************************************//**
@@ -608,7 +608,7 @@ void smooth_water_depth(void)
       ocean = pick_ocean(dist * OCEAN_DEPTH_STEP
                          + fc_rand(OCEAN_DEPTH_RAND),
                          terrain_has_flag(tile_terrain(ptile), TER_FROZEN));
-      if (NULL != ocean && ocean != tile_terrain(ptile)) {
+      if (ocean != nullptr && ocean != tile_terrain(ptile)) {
         log_debug("Replacing %s by %s at (%d, %d) "
                   "to have shallow ocean on coast.",
                   terrain_rule_name(tile_terrain(ptile)),
@@ -625,7 +625,7 @@ void smooth_water_depth(void)
     }
 
     ocean = most_adjacent_ocean_type(ptile);
-    if (NULL != ocean && ocean != tile_terrain(ptile)) {
+    if (ocean != nullptr && ocean != tile_terrain(ptile)) {
       log_debug("Replacing %s by %s at (%d, %d) "
                 "to smooth the ocean types.",
                 terrain_rule_name(tile_terrain(ptile)),
@@ -663,7 +663,7 @@ struct terrain *pick_terrain_by_flag(enum terrain_flag_id flag)
   terrain_type_iterate(pterrain) {
     if (has_flag[terrain_index(pterrain)]) {
       if (count == 0) {
-	return pterrain;
+        return pterrain;
       }
       count--;
     }
@@ -762,20 +762,20 @@ struct terrain *pick_terrain(enum mapgen_terrain_property target,
 
 /**********************************************************************//**
   Pick a random resource to put on a tile of the given terrain type.
-  May return NULL when there is no eligible resource.
+  May return nullptr when there is no eligible resource.
 **************************************************************************/
 struct extra_type *pick_resource(const struct terrain *pterrain)
 {
   int freq_sum = 0;
-  struct extra_type *result = NULL;
+  struct extra_type *result = nullptr;
 
-  fc_assert_ret_val(NULL != pterrain, NULL);
+  fc_assert_ret_val(pterrain != nullptr, nullptr);
 
   terrain_resources_iterate(pterrain, res, freq) {
     /* This is a standard way to get a weighted random element from
      * pterrain->resources with weights from pterrain->resource_freq,
      * without computing its length or total weight in advance.
-     * Note that if *(pterrain->resources) == NULL,
+     * Note that if *(pterrain->resources) == nullptr,
      * then this loop is a no-op. */
 
     if (res->generated && freq > 0) {
diff --git a/server/generator/mapgen_utils.h b/server/generator/mapgen_utils.h
index 8258f86c7e..55fb2b6664 100644
--- a/server/generator/mapgen_utils.h
+++ b/server/generator/mapgen_utils.h
@@ -54,42 +54,42 @@ struct extra_type *pick_resource(const struct terrain *pterrain);
  _index : the position in the interval of iteration (from -dist to dist)
  _tile : the tile pointer
  ***************************************************************************/
-#define axis_iterate(nmap, center_tile, _tile, _index, dist, is_X_axis)	\
-{									\
-  int _tile##_x, _tile##_y;						\
-  struct tile *_tile;							\
-  const struct tile *_tile##_center = (center_tile);			\
-  const bool _index##_axis = (is_X_axis);				\
-  const int _index##_d = (dist);					\
-  int _index = -(_index##_d);						\
-									\
-  for (; _index <= _index##_d; _index++) {				\
-    int _nat##_x, _nat##_y;                                                    \
+#define axis_iterate(nmap, center_tile, _tile, _index, dist, is_X_axis) \
+{                                                                       \
+  int _tile##_x, _tile##_y;                                             \
+  struct tile *_tile;                                                   \
+  const struct tile *_tile##_center = (center_tile);                    \
+  const bool _index##_axis = (is_X_axis);                               \
+  const int _index##_d = (dist);                                        \
+  int _index = -(_index##_d);                                           \
+                                                                        \
+  for (; _index <= _index##_d; _index++) {                              \
+    int _nat##_x, _nat##_y;                                                \
     index_to_native_pos(&_nat##_x, &_nat##_y, tile_index(_tile##_center)); \
-    _tile##_x = _nat##_x + (_index##_axis ? _index : 0);                       \
-    _tile##_y = _nat##_y + (_index##_axis ? 0 : _index);                       \
+    _tile##_x = _nat##_x + (_index##_axis ? _index : 0);                   \
+    _tile##_y = _nat##_y + (_index##_axis ? 0 : _index);                   \
     _tile = native_pos_to_tile(nmap, _tile##_x, _tile##_y);              \
-    if (NULL != _tile) {
+    if (_tile != nullptr) {
 
-#define axis_iterate_end						\
-    }									\
-  }									\
+#define axis_iterate_end                                                \
+    }                                                                   \
+  }                                                                     \
 }
 
 /***************************************************************************
-  pdata or pfilter can be NULL!
+  pdata or pfilter can be nullptr!
 ***************************************************************************/
-#define whole_map_iterate_filtered(_tile, pdata, pfilter)		\
-{									\
+#define whole_map_iterate_filtered(_tile, pdata, pfilter)               \
+{                                                                       \
   bool (*_tile##_filter)(const struct tile *vtile, const void *vdata) = (pfilter);\
-  const void *_tile##_data = (pdata);					\
-									\
+  const void *_tile##_data = (pdata);                                   \
+                                                                        \
   whole_map_iterate(&(wld.map), _tile) {                                \
-    if (NULL == _tile##_filter || (_tile##_filter)(_tile, _tile##_data)) {
+    if (_tile##_filter == nullptr || (_tile##_filter)(_tile, _tile##_data)) {
 
-#define whole_map_iterate_filtered_end					\
-    }									\
-  } whole_map_iterate_end;						\
+#define whole_map_iterate_filtered_end                                  \
+    }                                                                   \
+  } whole_map_iterate_end;                                              \
 }
 
 bool is_normal_nat_pos(int x, int y);
@@ -101,8 +101,8 @@ void adjust_int_map_filtered(int *int_map, int int_map_min,
                                             const void *data));
 #define adjust_int_map(int_map, int_map_min, int_map_max)         \
   adjust_int_map_filtered(int_map, int_map_min, int_map_max,      \
-      (void *)NULL,                                               \
-      (bool (*)(const struct tile *ptile, const void *data))NULL)
+      nullptr,                                                    \
+      (bool (*)(const struct tile *ptile, const void *data))nullptr)
 void smooth_int_map(int *int_map, bool zeroes_at_edges);
 
 /* placed_map tool */
-- 
2.53.0

