Project

General

Profile

Feature #1941 ยป 0038-Pass-enum-req_problem_type-to-can_city_build_unit_no.patch

Marko Lindqvist, 02/14/2026 11:14 AM

View differences:

ai/default/daiair.c
continue;
}
if (can_city_build_unit_now(nmap, pcity, punittype)) {
if (can_city_build_unit_now(nmap, pcity, punittype, RPT_CERTAIN)) {
struct unit *virtual_unit =
unit_virtual_create(
pplayer, pcity, punittype,
ai/default/daicity.c
struct unit_type *iunit = get_role_unit(L_BARBARIAN_BUILD, i);
if (iunit->attack_strength > bestattack
&& can_city_build_unit_now(nmap, pcity, iunit)) {
&& can_city_build_unit_now(nmap, pcity, iunit,
RPT_CERTAIN)) {
bestunit = iunit;
bestattack = iunit->attack_strength;
}
......
struct unit_type *iunit = get_role_unit(L_BARBARIAN_BUILD_TECH, i);
if (iunit->attack_strength > bestattack
&& can_city_build_unit_now(nmap, pcity, iunit)) {
&& can_city_build_unit_now(nmap, pcity, iunit,
RPT_CERTAIN)) {
bestunit = iunit;
bestattack = iunit->attack_strength;
}
ai/default/daihunter.c
continue;
}
if (!can_city_build_unit_now(nmap, pcity, ut)
if (!can_city_build_unit_now(nmap, pcity, ut, RPT_CERTAIN)
|| ut->attack_strength < ut->transport_capacity
|| (tc == TC_OCEAN && utype_class(ut)->adv.sea_move == MOVE_NONE)
|| (tc == TC_LAND && utype_class(ut)->adv.land_move == MOVE_NONE)) {
......
int desire;
if (!utype_can_do_action(ut, ACTION_SUICIDE_ATTACK)
|| !can_city_build_unit_now(nmap, pcity, ut)) {
|| !can_city_build_unit_now(nmap, pcity, ut, RPT_CERTAIN)) {
continue;
}
ai/default/daimilitary.c
struct civ_map *nmap = &(wld.map);
simple_ai_unit_type_iterate(punittype) {
if (can_city_build_unit_now(nmap, pcity, punittype)) {
if (can_city_build_unit_now(nmap, pcity, punittype, RPT_CERTAIN)) {
int fpatt, fpdef, defense, attack;
double want, loss, cost = utype_build_shield_cost(pcity, NULL, punittype);
struct unit *defender;
......
if ((tc == TC_LAND && utype_class(putype)->adv.land_move != MOVE_NONE)
|| (tc == TC_OCEAN
&& utype_class(putype)->adv.sea_move != MOVE_NONE)) {
if (can_city_build_unit_now(nmap, pcity, putype)
if (can_city_build_unit_now(nmap, pcity, putype, RPT_CERTAIN)
&& (cur > best
|| (ADV_WANTS_EQ(cur, best)
&& utype_build_shield_cost(pcity, NULL, putype)
......
}
/* Now find best */
if (can_city_build_unit_now(nmap, pcity, putype)) {
if (can_city_build_unit_now(nmap, pcity, putype, RPT_CERTAIN)) {
const adv_want desire = dai_unit_defense_desirability(ait, putype);
if (desire > best
......
desire /= POWER_DIVIDER / 2; /* Good enough, no rounding errors. */
desire *= desire;
if (can_city_build_unit_now(nmap, pcity, punittype)) {
if (can_city_build_unit_now(nmap, pcity, punittype, RPT_CERTAIN)) {
/* We can build the unit now... */
int build_cost = utype_build_shield_cost(pcity, NULL, punittype);
......
if (dai_can_unit_type_follow_unit_type(punittype, orig_utype, ait)
&& is_native_near_tile(&(wld.map), utype_class(punittype), ptile)
&& (U_NOT_OBSOLETED == punittype->obsoleted_by
|| !can_city_build_unit_direct(nmap, pcity, punittype->obsoleted_by))
|| !can_city_build_unit_direct(nmap, pcity, punittype->obsoleted_by,
RPT_CERTAIN))
&& punittype->attack_strength > 0 /* Or we'll get SIGFPE */) {
/* Values to be computed */
adv_want desire;
......
} else if (want > best_choice->want) {
const struct impr_type *impr_req;
if (can_city_build_unit_now(nmap, pcity, punittype)) {
if (can_city_build_unit_now(nmap, pcity, punittype, RPT_CERTAIN)) {
/* This is a real unit and we really want it */
CITY_LOG(LOG_DEBUG, pcity, "overriding %s(" ADV_WANT_PRINTF
ai/default/daiparadrop.c
} unit_tech_reqs_iterate_end;
/* we only update choice struct if we can build it! */
if (!can_city_build_unit_now(nmap, pcity, u_type)) {
if (!can_city_build_unit_now(nmap, pcity, u_type, RPT_CERTAIN)) {
continue;
}
ai/default/daitech.c
def_values[utype_index(deftype)] = def;
if (can_city_build_unit_now(nmap, pcity, deftype)) {
if (can_city_build_unit_now(nmap, pcity, deftype, RPT_CERTAIN)) {
if (def > best_avl_def) {
best_avl_def = def;
best_avl = deftype;
......
unit_type_iterate(deftype) {
if (def_values[utype_index(deftype)] > best_avl_def
&& !can_city_build_unit_now(nmap, pcity, deftype)
&& !can_city_build_unit_now(nmap, pcity, deftype, RPT_CERTAIN)
&& can_city_build_unit_later(nmap, pcity, deftype)) {
/* It would be better than current best. Consider researching tech */
const struct impr_type *building;
......
for (i = n - 1; i >= 0; i--) {
struct unit_type *iunit = get_role_unit(role, i);
if (can_city_build_unit_now(nmap, pcity, iunit)) {
if (can_city_build_unit_now(nmap, pcity, iunit, RPT_CERTAIN)) {
build_unit = iunit;
break;
} else if (can_city_build_unit_later(nmap, pcity, iunit)) {
ai/default/daiunit.c
}
if (cb_data->build_city == nullptr
|| can_city_build_unit_now(nmap, cb_data->build_city, ptype)) {
|| can_city_build_unit_now(nmap, cb_data->build_city, ptype,
RPT_CERTAIN)) {
return TRUE;
}
ai/tex/texaicity.c
case TWTL_BUILDABLE_UNITS:
units = unit_list_new();
unit_type_iterate(ptype) {
if (can_city_build_unit_now(nmap, pcity, ptype)) {
if (can_city_build_unit_now(nmap, pcity, ptype, RPT_CERTAIN)) {
unit_list_append(units, unit_virtual_create(pplayer, pcity, ptype, 0));
}
} unit_type_iterate_end;
client/climisc.c
} improvement_iterate_end;
unit_type_iterate(punittype) {
if (can_player_build_unit_now(client.conn.playing, punittype)) {
if (can_player_build_unit_now(client.conn.playing, punittype,
RPT_CERTAIN)) {
targets[cids_used].kind = VUT_UTYPE;
targets[cids_used].value.utype = punittype;
cids_used++;
......
if (NULL != pcity) {
/* Can the city build? */
can_build = can_city_build_unit_now(nmap, pcity, punittype);
can_build = can_city_build_unit_now(nmap, pcity, punittype, RPT_CERTAIN);
can_eventually_build = can_city_build_unit_later(nmap, pcity, punittype);
} else if (NULL != pplayer) {
/* Can our player build? */
can_build = can_player_build_unit_now(pplayer, punittype);
can_build = can_player_build_unit_now(pplayer, punittype, RPT_CERTAIN);
can_eventually_build = can_player_build_unit_later(pplayer, punittype);
} else {
/* Global observer case: can any player build? */
can_build = FALSE;
players_iterate(aplayer) {
if (can_player_build_unit_now(aplayer, punittype)) {
if (can_player_build_unit_now(aplayer, punittype, RPT_CERTAIN)) {
can_build = TRUE;
break;
}
client/gui-qt/menu.cpp
unit_type_iterate(utype) {
utype_id = utype_index(utype);
if (!can_player_build_unit_now(pplayer, utype)
if (!can_player_build_unit_now(pplayer, utype, RPT_CERTAIN)
|| !utype_can_do_action(utype, ACTION_AIRLIFT)) {
continue;
}
if (!can_player_build_unit_now(pplayer, utype)
if (!can_player_build_unit_now(pplayer, utype, RPT_CERTAIN)
&& !has_player_unit_type(utype_id)) {
continue;
}
client/gui-sdl2/wldlg.c
/* ------------------------------ */
unit_type_iterate(un) {
can_build = can_player_build_unit_now(client.conn.playing, un);
can_eventually_build =
can_player_build_unit_later(client.conn.playing, un);
can_build = can_player_build_unit_now(client.conn.playing, un, RPT_CERTAIN);
can_eventually_build
= can_player_build_unit_later(client.conn.playing, un);
/* If there's a city, can the city build the unit? */
if (pcity) {
can_build = can_build && can_city_build_unit_now(nmap, pcity, un);
can_build = can_build && can_city_build_unit_now(nmap, pcity, un,
RPT_CERTAIN);
can_eventually_build = can_eventually_build
&& can_city_build_unit_later(nmap, pcity, un);
}
client/gui-sdl3/wldlg.c
/* ------------------------------ */
unit_type_iterate(un) {
can_build = can_player_build_unit_now(client.conn.playing, un);
can_eventually_build =
can_player_build_unit_later(client.conn.playing, un);
can_build = can_player_build_unit_now(client.conn.playing, un, RPT_CERTAIN);
can_eventually_build
= can_player_build_unit_later(client.conn.playing, un);
/* If there's a city, can the city build the unit? */
if (pcity) {
can_build = can_build && can_city_build_unit_now(nmap, pcity, un);
can_build = can_build && can_city_build_unit_now(nmap, pcity, un,
RPT_CERTAIN);
can_eventually_build = can_eventually_build
&& can_city_build_unit_later(nmap, pcity, un);
}
client/mapctrl_common.c
if (!can_player_build_unit_direct(client.conn.playing,
unit_type_get(punit),
RPT_CERTAIN,
FALSE)) {
create_event(ptile, E_BAD_COMMAND, ftc_client,
_("You don't know how to build %s!"),
common/aicore/aisupport.c
if (same_pos(unit_tile(punit), pcity->tile)) {
const struct unit_type *punittype = unit_type_get(punit)->obsoleted_by;
if (punittype && can_city_build_unit_direct(nmap, pcity, punittype)) {
if (punittype
&& can_city_build_unit_direct(nmap, pcity, punittype, RPT_CERTAIN)) {
/* Obsolete, candidate for disbanding */
worth += unit_shield_value(punit, unit_type_get(punit),
action_by_number(ACTION_DISBAND_UNIT_RECOVER));
common/city.c
**************************************************************************/
bool can_city_build_unit_direct(const struct civ_map *nmap,
const struct city *pcity,
const struct unit_type *punittype)
const struct unit_type *punittype,
const enum req_problem_type prob_type)
{
if (!can_player_build_unit_direct(city_owner(pcity), punittype, FALSE)) {
if (!can_player_build_unit_direct(city_owner(pcity), punittype,
prob_type, FALSE)) {
return FALSE;
}
......
**************************************************************************/
bool can_city_build_unit_now(const struct civ_map *nmap,
const struct city *pcity,
const struct unit_type *punittype)
const struct unit_type *punittype,
const enum req_problem_type prob_type)
{
if (!can_city_build_unit_direct(nmap, pcity, punittype)) {
if (!can_city_build_unit_direct(nmap, pcity, punittype, prob_type)) {
return FALSE;
}
while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
/* TODO: Decide if fulfilled impr_req is needed to make unit obsolete,
* i.e., should the 'consider_reg_impr_req' be TRUE or FALSE. */
if (can_player_build_unit_direct(city_owner(pcity), punittype, TRUE)) {
if (can_player_build_unit_direct(city_owner(pcity), punittype,
prob_type, TRUE)) {
return FALSE;
}
}
......
{
switch (target->kind) {
case VUT_UTYPE:
return can_city_build_unit_direct(nmap, pcity, target->value.utype);
return can_city_build_unit_direct(nmap, pcity, target->value.utype,
RPT_CERTAIN);
case VUT_IMPROVEMENT:
return can_city_build_improvement_direct(pcity, target->value.building,
RPT_CERTAIN);
......
{
switch (target->kind) {
case VUT_UTYPE:
return can_city_build_unit_now(nmap, pcity, target->value.utype);
return can_city_build_unit_now(nmap, pcity, target->value.utype,
RPT_CERTAIN);
case VUT_IMPROVEMENT:
return can_city_build_improvement_now(pcity, target->value.building,
RPT_CERTAIN);
......
if (city_tile(pcity) == nullptr) {
/* When a "dummy" city is created with no tile, then choosing a build
* target could fail. This currently might happen during map editing.
* FIXME: assumes the first unit is always "valid", so check for
* FIXME: Assumes the first unit is always "valid", so check for
* obsolete units elsewhere. */
pcity->production.kind = VUT_UTYPE;
pcity->production.value.utype = utype_by_number(0);
......
if (!found) {
unit_type_iterate(punittype) {
if (can_city_build_unit_direct(nmap, pcity, punittype)) {
if (can_city_build_unit_direct(nmap, pcity, punittype,
RPT_CERTAIN)) {
#ifndef FREECIV_NDEBUG
/* Later than this, 'found' is only needed in an fc_assert() */
found = TRUE;
common/city.h
bool can_city_build_unit_direct(const struct civ_map *nmap,
const struct city *pcity,
const struct unit_type *punittype);
const struct unit_type *punittype,
const enum req_problem_type prob_type);
bool can_city_build_unit_later(const struct civ_map *nmap,
const struct city *pcity,
const struct unit_type *punittype);
bool can_city_build_unit_now(const struct civ_map *nmap,
const struct city *pcity,
const struct unit_type *punittype);
const struct unit_type *punittype,
const enum req_problem_type prob_type);
bool can_city_build_direct(const struct civ_map *nmap,
const struct city *pcity,
common/improvement.c
unit_type_iterate(ut) {
if (requirement_needs_improvement(pimprove, &ut->build_reqs)
&& can_city_build_unit_now(nmap, pcity, ut)) {
&& can_city_build_unit_now(nmap, pcity, ut, RPT_CERTAIN)) {
return TRUE;
}
} unit_type_iterate_end;
......
return TRUE;
}
if (can_city_build_unit_now(nmap, pcity, ut)) {
if (can_city_build_unit_now(nmap, pcity, ut, RPT_CERTAIN)) {
/* This city can build a unit that uses the building */
return TRUE;
}
common/scriptcore/api_game_methods.c
LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
LUASCRIPT_CHECK_ARG_NIL(L, utype, 3, Unit_Type, FALSE);
return can_player_build_unit_direct(pplayer, utype, TRUE);
return can_player_build_unit_direct(pplayer, utype, RPT_CERTAIN, TRUE);
}
/**********************************************************************//**
common/unittype.c
* diplomatic treaties, or lua script. */
while ((upgrade = upgrade->obsoleted_by) != U_NOT_OBSOLETED) {
if (can_player_build_unit_direct(pplayer, upgrade, TRUE)) {
if (can_player_build_unit_direct(pplayer, upgrade,
RPT_CERTAIN, TRUE)) {
best_upgrade = upgrade;
}
}
......
**************************************************************************/
bool can_player_build_unit_direct(const struct player *p,
const struct unit_type *punittype,
const enum req_problem_type prob_type,
bool consider_reg_impr_req)
{
const struct req_context context = { .player = p, .unittype = punittype };
......
req_copy(&copy, preq);
copy.range = REQ_RANGE_WORLD;
if (!is_req_active(&context, nullptr, &copy, RPT_CERTAIN)) {
if (!is_req_active(&context, nullptr, &copy, prob_type)) {
return FALSE;
}
} else if (!is_req_active(&context, nullptr, preq, RPT_CERTAIN)) {
} else if (!is_req_active(&context, nullptr, preq, prob_type)) {
return FALSE;
}
}
} else if (!is_req_active(&context, nullptr, preq, RPT_CERTAIN)) {
} else if (!is_req_active(&context, nullptr, preq, prob_type)) {
return FALSE;
}
} requirement_vector_iterate_end;
......
returns FALSE if unit is obsolete.
**************************************************************************/
bool can_player_build_unit_now(const struct player *p,
const struct unit_type *punittype)
const struct unit_type *punittype,
const enum req_problem_type prob_type)
{
if (!can_player_build_unit_direct(p, punittype, FALSE)) {
if (!can_player_build_unit_direct(p, punittype, prob_type, FALSE)) {
return FALSE;
}
while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
if (can_player_build_unit_direct(p, punittype, TRUE)) {
if (can_player_build_unit_direct(p, punittype, prob_type, TRUE)) {
return FALSE;
}
}
......
}
while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
if (can_player_build_unit_direct(p, punittype, TRUE)) {
if (can_player_build_unit_direct(p, punittype, RPT_CERTAIN, TRUE)) {
return FALSE;
}
}
......
for (j = n_with_role[role] - 1; j >= 0; j--) {
u = with_role[role][j];
if (can_city_build_unit_now(nmap, pcity, u)) {
if (can_city_build_unit_now(nmap, pcity, u, RPT_CERTAIN)) {
return u;
}
}
......
for (j = n_with_role[role] - 1; j >= 0; j--) {
struct unit_type *utype = with_role[role][j];
if (can_player_build_unit_now(pplayer, utype)) {
if (can_player_build_unit_now(pplayer, utype, RPT_CERTAIN)) {
return utype;
}
}
......
for (j = 0; j < n_with_role[role]; j++) {
struct unit_type *utype = with_role[role][j];
if (can_player_build_unit_now(pplayer, utype)) {
if (can_player_build_unit_now(pplayer, utype, RPT_CERTAIN)) {
return utype;
}
}
common/unittype.h
bool can_player_build_unit_direct(const struct player *p,
const struct unit_type *punittype,
const enum req_problem_type prob_type,
bool consider_reg_impr_req);
bool can_player_build_unit_later(const struct player *p,
const struct unit_type *punittype);
bool can_player_build_unit_now(const struct player *p,
const struct unit_type *punittype);
const struct unit_type *punittype,
const enum req_problem_type prob_type);
#define utype_fuel(ptype) (ptype)->fuel
server/advisors/advdata.c
struct unit_type *nuke
= get_role_unit(action_id_get_role(act_id), i);
if (can_player_build_unit_direct(aplayer, nuke, FALSE)) {
if (can_player_build_unit_direct(aplayer, nuke,
RPT_CERTAIN, FALSE)) {
adv->threats.nuclear = 1;
}
}
server/cityturn.c
case VUT_UTYPE:
/* We can build a unit again unless it's unique or we have lost the tech. */
if (!utype_has_flag(pcity->production.value.utype, UTYF_UNIQUE)
&& can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
&& can_city_build_unit_now(nmap, pcity, pcity->production.value.utype,
RPT_CERTAIN)) {
log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
utype_rule_name(pcity->production.value.utype));
return;
......
const struct unit_type *best_upgrade = U_NOT_OBSOLETED;
const struct civ_map *nmap = &(wld.map);
if (!can_city_build_unit_direct(nmap, pcity, punittype)) {
if (!can_city_build_unit_direct(nmap, pcity, punittype, RPT_CERTAIN)) {
return U_NOT_OBSOLETED;
}
while ((check = check->obsoleted_by) != U_NOT_OBSOLETED) {
if (can_city_build_unit_direct(nmap, pcity, check)) {
if (can_city_build_unit_direct(nmap, pcity, check, RPT_CERTAIN)) {
best_upgrade = check;
}
}
......
const struct unit_type *upgrading = unit_upgrades_to(pcity, producing);
const struct civ_map *nmap = &(wld.map);
if (upgrading && can_city_build_unit_direct(nmap, pcity, upgrading)) {
if (upgrading && can_city_build_unit_direct(nmap, pcity, upgrading,
RPT_CERTAIN)) {
notify_player(city_owner(pcity), city_tile(pcity),
E_UNIT_UPGRADED, ftc_server,
_("Production of %s is upgraded to %s in %s."),
......
/* We must make a special case for barbarians here, because they are
so dumb. Really. They don't know the prerequisite techs for units
they build!! - Per */
if (!can_city_build_unit_direct(nmap, pcity, utype)
if (!can_city_build_unit_direct(nmap, pcity, utype, RPT_CERTAIN)
&& !is_barbarian(pplayer)) {
notify_player(pplayer, city_tile(pcity), E_CITY_CANTBUILD, ftc_server,
_("%s is building %s, which is no longer available."),
server/techtools.c
bool update = FALSE;
if (pcity->production.kind == VUT_UTYPE
&& !can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
&& !can_city_build_unit_now(nmap, pcity, pcity->production.value.utype,
RPT_CERTAIN)) {
notify_player(pplayer, city_tile(pcity),
E_CITY_CANTBUILD, ftc_server,
_("%s can't build %s. The required technology was "
server/unittools.c
* fail. */
players_iterate(pplayer) {
if (!is_barbarian(pplayer)
&& can_player_build_unit_direct(pplayer, iunit, TRUE)) {
&& can_player_build_unit_direct(pplayer, iunit,
RPT_CERTAIN, TRUE)) {
players++;
}
} players_iterate_end;
    (1-1/1)