Project

General

Profile

Feature #1621 ยป 0063-research.c-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 07/22/2025 01:53 AM

View differences:

common/research.c
/* 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();
......
****************************************************************************/
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;
}
......
****************************************************************************/
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];
}
......
****************************************************************************/
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 {
......
} 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;
}
}
......
/************************************************************************//**
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". */
......
name = research_future_set_name(future_rule_name, no, buffer);
}
fc_assert(name != NULL);
fc_assert(name != nullptr);
return name;
}
......
/************************************************************************//**
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.
****************************************************************************/
......
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". */
......
name = research_future_set_name(future_name_translation, no, buffer);
}
fc_assert(name != NULL);
fc_assert(name != nullptr);
return name;
}
......
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
......
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));
......
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) {
......
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;
}
}
......
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;
......
{
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) {
......
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) {
......
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);
......
{
const struct advance *pgoal = valid_advance_by_number(goal);
if (NULL == pgoal
if (pgoal == nullptr
|| !research_invention_reachable(presearch, goal)) {
return A_UNSET;
}
......
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,
......
{
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;
......
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,
......
{
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
......
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)
......
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) {
......
return TRUE;
}
} advance_req_iterate_end;
return FALSE;
}
}
......
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,
......
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. */
......
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:
......
{
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;
......
return (0 <= rit->index
&& ARRAY_SIZE(research_array) > rit->index
&& NULL != team_by_number(rit->index));
&& team_by_number(rit->index) != nullptr);
}
/************************************************************************//**
......
return (0 <= rit->index
&& ARRAY_SIZE(research_array) > rit->index
&& NULL != player_by_number(rit->index));
&& player_by_number(rit->index) != nullptr);
}
/************************************************************************//**
......
{
const struct player *pplayer = iterator_get(it);
return (NULL == pplayer || pplayer->is_alive);
return (pplayer == nullptr || pplayer->is_alive);
}
/************************************************************************//**
......
****************************************************************************/
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;
}
/************************************************************************//**
......
****************************************************************************/
static void research_player_iter_not_pooled_next(struct iterator *it)
{
RESEARCH_PLAYER_ITER(it)->pplayer = NULL;
RESEARCH_PLAYER_ITER(it)->pplayer = nullptr;
}
/************************************************************************//**
......
****************************************************************************/
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;
}
/************************************************************************//**
......
{
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;
......
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. */
......
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++;
}
    (1-1/1)