Project

General

Profile

Feature #1966 ยป 0021-ai.-ch-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 03/23/2026 12:09 AM

View differences:

common/ai.c
static struct ai_timer *ai_timer_get(const struct ai_type *ai);
static struct ai_timer *ai_timer_player_get(const struct player *pplayer);
static struct ai_timer *aitimers = NULL;
static struct ai_timer *aitimer_plrs = NULL;
static struct ai_timer *aitimers = nullptr;
static struct ai_timer *aitimer_plrs = nullptr;
/*************************************************************************//**
Allocate resources for the AI timers.
......
{
int i;
fc_assert_ret(aitimers == NULL);
fc_assert_ret(aitimer_plrs == NULL);
fc_assert_ret(aitimers == nullptr);
fc_assert_ret(aitimer_plrs == nullptr);
aitimers = fc_calloc(FREECIV_AI_MOD_LAST, sizeof(*aitimers));
for (i = 0; i < FREECIV_AI_MOD_LAST; i++) {
struct ai_timer *aitimer = aitimers + i;
aitimer->count = 0;
aitimer->timer = NULL;
aitimer->timer = nullptr;
}
aitimer_plrs = fc_calloc(FREECIV_AI_MOD_LAST * MAX_NUM_PLAYER_SLOTS,
......
struct ai_timer *aitimer = aitimer_plrs + i;
aitimer->count = 0;
aitimer->timer = NULL;
aitimer->timer = nullptr;
}
}
......
}
}
free(aitimers);
aitimers = NULL;
aitimers = nullptr;
free(aitimer_plrs);
aitimer_plrs = NULL;
aitimer_plrs = nullptr;
}
/*************************************************************************//**
......
{
struct ai_timer *aitimer;
fc_assert_ret_val(ai != NULL, NULL);
fc_assert_ret_val(aitimers != NULL, NULL);
fc_assert_ret_val(ai != nullptr, nullptr);
fc_assert_ret_val(aitimers != nullptr, nullptr);
aitimer = aitimers + ai_type_number(ai);
......
{
struct ai_timer *aitimer;
fc_assert_ret_val(pplayer != NULL, NULL);
fc_assert_ret_val(pplayer->ai != NULL, NULL);
fc_assert_ret_val(aitimer_plrs != NULL, NULL);
fc_assert_ret_val(pplayer != nullptr, nullptr);
fc_assert_ret_val(pplayer->ai != nullptr, nullptr);
fc_assert_ret_val(aitimer_plrs != nullptr, nullptr);
aitimer = aitimer_plrs + (player_index(pplayer) * FREECIV_AI_MOD_LAST
+ ai_type_number(pplayer->ai));
......
{
struct ai_timer *aitimer = ai_timer_get(ai);
fc_assert_ret(aitimer != NULL);
fc_assert_ret(aitimer->timer != NULL);
fc_assert_ret(aitimer != nullptr);
fc_assert_ret(aitimer->timer != nullptr);
if (aitimer->count == 0) {
log_debug("AI timer start [%15.3f] ---- (AI type: %s)",
......
{
struct ai_timer *aitimer = ai_timer_get(ai);
fc_assert_ret(aitimer != NULL);
fc_assert_ret(aitimer->timer != NULL);
fc_assert_ret(aitimer != nullptr);
fc_assert_ret(aitimer->timer != nullptr);
if (aitimer->count > 0) {
if (aitimer->count == 1) {
......
{
struct ai_timer *aitimer = ai_timer_player_get(pplayer);
fc_assert_ret(aitimer != NULL);
fc_assert_ret(aitimer->timer != NULL);
fc_assert_ret(aitimer != nullptr);
fc_assert_ret(aitimer->timer != nullptr);
if (aitimer->count == 0) {
log_debug("AI timer start [%15.3f] P%03d (AI type: %s) %s",
......
{
struct ai_timer *aitimer = ai_timer_player_get(pplayer);
fc_assert_ret(aitimer != NULL);
fc_assert_ret(aitimer->timer != NULL);
fc_assert_ret(aitimer != nullptr);
fc_assert_ret(aitimer->timer != nullptr);
if (aitimer->count > 0) {
if (aitimer->count == 1) {
......
}
} ai_type_iterate_end;
return NULL;
return nullptr;
}
/*************************************************************************//**
......
log_error(_("Too many AI modules. Max is %d."),
FREECIV_AI_MOD_LAST);
return NULL;
return nullptr;
}
return get_ai_type(ai_type_count++);
......
*****************************************************************************/
const char *ai_name(const struct ai_type *ai)
{
fc_assert_ret_val(ai, NULL);
fc_assert_ret_val(ai, nullptr);
return ai->name;
}
/*************************************************************************//**
Return usable ai type name, if possible. This is either the name
given as parameter or some fallback name for it. NULL is returned if
given as parameter or some fallback name for it. Nullptr is returned if
no name matches.
*****************************************************************************/
const char *ai_type_name_or_fallback(const char *orig_name)
{
if (orig_name == NULL) {
return NULL;
if (orig_name == nullptr) {
return nullptr;
}
if (ai_type_by_name(orig_name) != NULL) {
if (ai_type_by_name(orig_name) != nullptr) {
return orig_name;
}
......
fb = ai_type_by_name("classic");
if (fb != NULL) {
if (fb != nullptr) {
/* Get pointer to persistent name of the ai_type */
return ai_name(fb);
}
}
return NULL;
return nullptr;
}
/*************************************************************************//**
common/ai.h
/* These are here reserving space for future optional callbacks.
* This way we don't need to change the mandatory capability of the AI module
* interface when adding such callbacks, but existing modules just have these
* set to NULL. Optional capability should be set when taking one of these to use,
* set to nullptr. Optional capability should be set when taking one of these to use,
* so that new modules know if the server is going to call these or is it too old
* version to do so.
* When mandatory capability then changes again, please add new reservations to
    (1-1/1)