Skip to content

Commit

Permalink
Inline needless macros
Browse files Browse the repository at this point in the history
  • Loading branch information
psampathkumar authored and lmoureaux committed Jul 14, 2022
1 parent 3206f30 commit 22c0c4b
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 170 deletions.
52 changes: 18 additions & 34 deletions common/research.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,24 +353,6 @@ static bool research_allowed(
return false;
}

/**
Returns TRUE iff researching the given tech is allowed according to its
research_reqs.
Helper for research_update().
*/
#define research_is_allowed(presearch, tech) \
research_allowed(presearch, tech, are_reqs_active)

/**
Returns TRUE iff researching the given tech may become allowed according
to its research_reqs.
Helper for research_get_reachable_rreqs().
*/
#define research_may_become_allowed(presearch, tech) \
research_allowed(presearch, tech, reqs_may_activate)

/**
Returns TRUE iff the given tech is ever reachable by the players sharing
the research as far as research_reqs are concerned.
Expand All @@ -396,7 +378,7 @@ static bool research_get_reachable_rreqs(const struct research *presearch,
continue;
}

if (!research_may_become_allowed(presearch, iter_tech)) {
if (!research_allowed(presearch, iter_tech, reqs_may_activate)) {
/* It will always be illegal to start researching this tech because
* of unchanging requirements. Since it isn't already known and can't
* be researched it must be unreachable. */
Expand Down Expand Up @@ -513,7 +495,7 @@ void research_update(struct research *presearch)
&& (presearch->inventions[advance_required(i, AR_TWO)]
.state
== TECH_KNOWN)
&& research_is_allowed(presearch, i)
&& research_allowed(presearch, i, are_reqs_active)
? TECH_PREREQS_KNOWN
: TECH_UNKNOWN);
}
Expand Down Expand Up @@ -667,13 +649,14 @@ bool research_invention_reachable(const struct research *presearch,
} else if (presearch != nullptr) {
return presearch->inventions[tech].reachable;
} else {
researches_iterate(research_iter)
{
if (research_iter->inventions[tech].reachable) {
return true;
for (auto &it : research_array) {
research *research_iter = ⁢
if (team_by_number(research_number(research_iter)) != nullptr) {
if (research_iter->inventions[tech].reachable) {
return true;
}
}
}
researches_iterate_end;
};

return false;
}
Expand All @@ -696,15 +679,16 @@ bool research_invention_gettable(const struct research *presearch,
? presearch->inventions[tech].root_reqs_known
: presearch->inventions[tech].state == TECH_PREREQS_KNOWN);
} else {
researches_iterate(research_iter)
{
if (allow_holes ? research_iter->inventions[tech].root_reqs_known
: research_iter->inventions[tech].state
== TECH_PREREQS_KNOWN) {
return true;
for (auto &it : research_array) {
research *research_iter = ⁢
if (team_by_number(research_number(research_iter)) != nullptr) {
if (allow_holes ? research_iter->inventions[tech].root_reqs_known
: research_iter->inventions[tech].state
== TECH_PREREQS_KNOWN) {
return true;
}
}
}
researches_iterate_end;
};

return false;
}
Expand Down
6 changes: 0 additions & 6 deletions common/research.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ int research_total_bulbs_required(const struct research *presearch,
int player_tech_upkeep(const struct player *pplayer);

// Iterating utilities.
#define researches_iterate(_presearch) \
for (auto &it : research_array) { \
research *_presearch = ⁢ \
if (team_by_number(research_number(_presearch)) != nullptr)

#define researches_iterate_end }
struct research_player_iter;

size_t research_player_iter_sizeof();
Expand Down
25 changes: 13 additions & 12 deletions server/sanitycheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,18 +674,19 @@ static void check_teams(const char *file, const char *function, int line)
static void check_researches(const char *file, const char *function,
int line)
{
researches_iterate(presearch)
{
SANITY_CHECK(S_S_RUNNING != server_state()
|| A_UNSET == presearch->researching
|| is_future_tech(presearch->researching)
|| (A_NONE != presearch->researching
&& valid_advance_by_number(presearch->researching)));
SANITY_CHECK(A_UNSET == presearch->tech_goal
|| (A_NONE != presearch->tech_goal
&& valid_advance_by_number(presearch->tech_goal)));
}
researches_iterate_end;
for (auto &it : research_array) {
research *presearch = ⁢
if (team_by_number(research_number(presearch)) != nullptr) {
SANITY_CHECK(S_S_RUNNING != server_state()
|| A_UNSET == presearch->researching
|| is_future_tech(presearch->researching)
|| (A_NONE != presearch->researching
&& valid_advance_by_number(presearch->researching)));
SANITY_CHECK(A_UNSET == presearch->tech_goal
|| (A_NONE != presearch->tech_goal
&& valid_advance_by_number(presearch->tech_goal)));
}
};
}

/**
Expand Down
64 changes: 37 additions & 27 deletions server/savegame/savegame2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4787,8 +4787,12 @@ static void sg_load_researches(struct loaddata *loading)
sg_check_ret();

// Initialize all researches.
researches_iterate(pinitres) { init_tech(pinitres, false); }
researches_iterate_end;
for (auto &it : research_array) {
research *pinitres = ⁢
if (team_by_number(research_number(pinitres)) != nullptr) {
init_tech(pinitres, false);
}
};

// May be unsaved (e.g. scenario case).
count = secfile_lookup_int_default(loading->file, 0, "research.count");
Expand Down Expand Up @@ -4851,8 +4855,12 @@ static void sg_load_researches(struct loaddata *loading)

/* In case of tech_leakage, we can update research only after all the
* researches have been loaded */
researches_iterate(pupres) { research_update(pupres); }
researches_iterate_end;
for (auto &it : research_array) {
research *pupres = ⁢
if (team_by_number(research_number(pupres)) != nullptr) {
research_update(pupres);
}
};
}

/* =======================================================================
Expand Down Expand Up @@ -5124,29 +5132,31 @@ static void sg_load_sanitycheck(struct loaddata *loading)
#endif // FREECIV_DEBUG

// Check researching technologies and goals.
researches_iterate(presearch)
{
if (presearch->researching != A_UNSET
&& !is_future_tech(presearch->researching)
&& (valid_advance_by_number(presearch->researching) == nullptr
|| (research_invention_state(presearch, presearch->researching)
!= TECH_PREREQS_KNOWN))) {
log_sg(_("%s had invalid researching technology."),
research_name_translation(presearch));
presearch->researching = A_UNSET;
}
if (presearch->tech_goal != A_UNSET
&& !is_future_tech(presearch->tech_goal)
&& (valid_advance_by_number(presearch->tech_goal) == nullptr
|| !research_invention_reachable(presearch, presearch->tech_goal)
|| (research_invention_state(presearch, presearch->tech_goal)
== TECH_KNOWN))) {
log_sg(_("%s had invalid technology goal."),
research_name_translation(presearch));
presearch->tech_goal = A_UNSET;
}
}
researches_iterate_end;
for (auto &it : research_array) {
research *presearch = ⁢
if (team_by_number(research_number(presearch)) != nullptr) {
if (presearch->researching != A_UNSET
&& !is_future_tech(presearch->researching)
&& (valid_advance_by_number(presearch->researching) == nullptr
|| (research_invention_state(presearch, presearch->researching)
!= TECH_PREREQS_KNOWN))) {
log_sg(_("%s had invalid researching technology."),
research_name_translation(presearch));
presearch->researching = A_UNSET;
}
if (presearch->tech_goal != A_UNSET
&& !is_future_tech(presearch->tech_goal)
&& (valid_advance_by_number(presearch->tech_goal) == nullptr
|| !research_invention_reachable(presearch,
presearch->tech_goal)
|| (research_invention_state(presearch, presearch->tech_goal)
== TECH_KNOWN))) {
log_sg(_("%s had invalid technology goal."),
research_name_translation(presearch));
presearch->tech_goal = A_UNSET;
}
}
};

players_iterate(pplayer)
{
Expand Down
Loading

0 comments on commit 22c0c4b

Please sign in to comment.