Project

General

Profile

Feature #2193 ยป 0067-mapgen_utils.-ch-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 08/31/2026 05:34 AM

View differences:

server/generator/mapgen_utils.c
**************************************************************************/
bool placed_map_is_initialized(void)
{
return placed_map != NULL;
return placed_map != nullptr;
}
/**********************************************************************//**
......
{
fc_assert_ret(placed_map_is_initialized());
free(placed_map);
placed_map = NULL;
placed_map = nullptr;
}
......
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;
......
**************************************************************************/
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);
......
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)) {
......
/**********************************************************************//**
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) {
......
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;
......
} adjc_iterate_end;
} terrain_type_iterate_end;
return NULL;
return nullptr;
}
/**********************************************************************//**
......
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)),
......
}
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)),
......
terrain_type_iterate(pterrain) {
if (has_flag[terrain_index(pterrain)]) {
if (count == 0) {
return pterrain;
return pterrain;
}
count--;
}
......
/**********************************************************************//**
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) {
server/generator/mapgen_utils.h
_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);
......
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 */
    (1-1/1)