Project

General

Profile

Feature #646 » 0038-Unhardcode-wld.map-from-can_city_build_unit_now.patch

S3_1 - Marko Lindqvist, 05/18/2024 03:51 AM

View differences:

ai/default/aiair.c
bool allow_gold_upkeep)
{
bool want_something = FALSE;
const struct civ_map *nmap = &(wld.map);
/* This AI doesn't know how to build planes */
if (has_handicap(pplayer, H_NOPLANES)) {
......
continue;
}
if (can_city_build_unit_now(pcity, punittype)) {
if (can_city_build_unit_now(nmap, pcity, punittype)) {
struct unit *virtual_unit =
unit_virtual_create(
pplayer, pcity, punittype,
ai/default/aihunt.c
struct unit_type *bestid = NULL;
int best = 0;
struct player *pplayer = city_owner(pcity);
const struct civ_map *nmap = &(wld.map);
unit_type_iterate(ut) {
struct unit_type_ai *utai = utype_ai_data(ut, ait);
......
continue;
}
if (!can_city_build_unit_now(pcity, ut)
if (!can_city_build_unit_now(nmap, pcity, ut)
|| 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)) {
......
adv_want best = -1;
struct unit_type *best_unit_type = NULL;
struct unit *hunter = NULL;
const struct civ_map *nmap = &(wld.map);
unit_list_iterate(pcity->tile->units, punit) {
if (dai_hunter_qualify(pplayer, punit)) {
......
int desire;
if (!utype_can_do_action(ut, ACTION_SUICIDE_ATTACK)
|| !can_city_build_unit_now(pcity, ut)) {
|| !can_city_build_unit_now(nmap, pcity, ut)) {
continue;
}
ai/default/aiparatrooper.c
int num_requirements = 0;
int i;
struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
const struct civ_map *nmap = &(wld.map);
/* military_advisor_choose_build() does something idiotic,
* this function should not be called if there is danger... */
......
}
/* we only update choice struct if we can build it! */
if (!can_city_build_unit_now(pcity, u_type)) {
if (!can_city_build_unit_now(nmap, pcity, u_type)) {
continue;
}
ai/default/aitech.c
int att_idx = utype_index(att);
int defbonus = 100
+ get_unittype_bonus(pplayer, ptile, att, NULL, EFT_DEFEND_BONUS);
const struct civ_map *nmap = &(wld.map);
unit_type_iterate(deftype) {
int mp_pct = deftype->cache.defense_mp_bonuses_pct[att_idx] + 100;
......
def_values[utype_index(deftype)] = def;
if (can_city_build_unit_now(pcity, deftype)) {
if (can_city_build_unit_now(nmap, pcity, deftype)) {
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(pcity, deftype)
&& !can_city_build_unit_now(nmap, pcity, deftype)
&& can_city_build_unit_later(pcity, deftype)) {
/* It would be better than current best. Consider researching tech */
const struct impr_type *building;
......
struct advance *best_tech = A_NEVER;
struct unit_type *best_unit = NULL;
struct unit_type *build_unit = NULL;
const struct civ_map *nmap = &(wld.map);
n = num_role_units(role);
for (i = n - 1; i >= 0; i--) {
struct unit_type *iunit = get_role_unit(role, i);
struct advance *itech = iunit->require_advance;
if (can_city_build_unit_now(pcity, iunit)) {
if (can_city_build_unit_now(nmap, pcity, iunit)) {
build_unit = iunit;
break;
} else if (can_city_build_unit_later(pcity, iunit)) {
ai/default/aiunit.c
{
struct role_unit_cb_data *cb_data = (struct role_unit_cb_data *)data;
struct unit_class *pclass = utype_class(ptype);
const struct civ_map *nmap = &(wld.map);
if ((cb_data->tc == TC_LAND && pclass->adv.land_move == MOVE_NONE)
|| (cb_data->tc == TC_OCEAN && pclass->adv.sea_move == MOVE_NONE)) {
......
}
if (cb_data->build_city == NULL
|| can_city_build_unit_now(cb_data->build_city, ptype)) {
|| can_city_build_unit_now(nmap, cb_data->build_city, ptype)) {
return TRUE;
}
ai/default/daicity.c
{
struct unit_type *bestunit = NULL;
int i, bestattack = 0;
const struct civ_map *nmap = &(wld.map);
/* Choose the best unit among the basic ones */
for (i = 0; i < num_role_units(L_BARBARIAN_BUILD); i++) {
struct unit_type *iunit = get_role_unit(L_BARBARIAN_BUILD, i);
if (iunit->attack_strength > bestattack
&& can_city_build_unit_now(pcity, iunit)) {
&& can_city_build_unit_now(nmap, pcity, iunit)) {
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(pcity, iunit)) {
&& can_city_build_unit_now(nmap, pcity, iunit)) {
bestunit = iunit;
bestattack = iunit->attack_strength;
}
ai/default/daimilitary.c
struct civ_map *nmap = &(wld.map);
simple_ai_unit_type_iterate(punittype) {
if (can_city_build_unit_now(pcity, punittype)) {
if (can_city_build_unit_now(nmap, pcity, punittype)) {
int fpatt, fpdef, defense, attack;
double want, loss, cost = utype_build_shield_cost(pcity, NULL, punittype);
struct unit *defender;
......
adv_want best = -1;
adv_want cur;
struct player *pplayer = city_owner(pcity);
const struct civ_map *nmap = &(wld.map);
simple_ai_unit_type_iterate(putype) {
if (!allow_gold_upkeep && utype_upkeep_cost(putype, pplayer, O_GOLD) > 0) {
......
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(pcity, putype)
if (can_city_build_unit_now(nmap, pcity, putype)
&& (cur > best
|| (ADV_WANTS_EQ(cur, best)
&& utype_build_shield_cost(pcity, NULL, putype)
......
struct unit_type *bestid = NULL;
adv_want best = 0;
struct player *pplayer = city_owner(pcity);
const struct civ_map *nmap = &(wld.map);
simple_ai_unit_type_iterate(putype) {
/* Only consider units of given role, or any if invalid given */
......
}
/* Now find best */
if (can_city_build_unit_now(pcity, putype)) {
if (can_city_build_unit_now(nmap, pcity, putype)) {
const adv_want desire = dai_unit_defense_desirability(ait, putype);
if (desire > best
......
struct ai_city *city_data = def_ai_city_data(pcity, ait);
struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
adv_want total_want = danger + extra_want;
const struct civ_map *nmap = &(wld.map);
memset(tech_desire, 0, sizeof(tech_desire));
......
desire /= POWER_DIVIDER / 2; /* Good enough, no rounding errors. */
desire *= desire;
if (can_city_build_unit_now(pcity, punittype)) {
if (can_city_build_unit_now(nmap, pcity, punittype)) {
/* We can build the unit now... */
int build_cost = utype_build_shield_cost(pcity, NULL, punittype);
......
} else if (want > best_choice->want) {
const struct impr_type *impr_req;
if (can_city_build_unit_now(pcity, punittype)) {
if (can_city_build_unit_now(nmap, pcity, punittype)) {
/* This is a real unit and we really want it */
CITY_LOG(LOG_DEBUG, pcity, "overriding %s(" ADV_WANT_PRINTF
ai/tex/texaicity.c
case TWTL_BUILDABLE_UNITS:
units = unit_list_new();
unit_type_iterate(ptype) {
if (can_city_build_unit_now(pcity, ptype)) {
if (can_city_build_unit_now(nmap, pcity, ptype)) {
unit_list_append(units, unit_virtual_create(pplayer, pcity, ptype, 0));
}
} unit_type_iterate_end;
ai/threaded/taicity.c
case TWTL_BUILDABLE_UNITS:
units = unit_list_new();
unit_type_iterate(ptype) {
if (can_city_build_unit_now(pcity, ptype)) {
if (can_city_build_unit_now(nmap, pcity, ptype)) {
unit_list_append(units, unit_virtual_create(pplayer, pcity, ptype, 0));
}
} unit_type_iterate_end;
client/climisc.c
if (NULL != pcity) {
/* Can the city build? */
can_build = can_city_build_unit_now(pcity, punittype);
can_build = can_city_build_unit_now(&(wld.map), pcity, punittype);
can_eventually_build = can_city_build_unit_later(pcity, punittype);
} else if (NULL != pplayer) {
/* Can our player build? */
client/gui-sdl2/wldlg.c
/* If there's a city, can the city build the unit? */
if (pcity) {
can_build = can_build && can_city_build_unit_now(pcity, un);
can_build = can_build && can_city_build_unit_now(&(wld.map), pcity, un);
can_eventually_build = can_eventually_build
&& can_city_build_unit_later(pcity, un);
}
common/city.c
Return whether given city can build given unit; returns FALSE if unit is
obsolete.
**************************************************************************/
bool can_city_build_unit_now(const struct city *pcity,
bool can_city_build_unit_now(const struct civ_map *nmap,
const struct city *pcity,
const struct unit_type *punittype)
{
const struct civ_map *nmap = &(wld.map);
if (!can_city_build_unit_direct(nmap, pcity, punittype)) {
return FALSE;
}
......
bool can_city_build_now(const struct city *pcity,
const struct universal *target)
{
const struct civ_map *nmap = &(wld.map);
switch (target->kind) {
case VUT_UTYPE:
return can_city_build_unit_now(pcity, target->value.utype);
return can_city_build_unit_now(nmap, pcity, target->value.utype);
case VUT_IMPROVEMENT:
return can_city_build_improvement_now(pcity, target->value.building);
default:
common/city.h
const struct unit_type *punittype);
bool can_city_build_unit_later(const struct city *pcity,
const struct unit_type *punittype);
bool can_city_build_unit_now(const struct city *pcity,
bool can_city_build_unit_now(const struct civ_map *nmap,
const struct city *pcity,
const struct unit_type *punittype);
bool can_city_build_direct(const struct city *pcity,
common/improvement.c
static bool impr_provides_buildable_units(const struct city *pcity,
const struct impr_type *pimprove)
{
const struct civ_map *nmap = &(wld.map);
/* Fast check */
if (!pimprove->allows_units) {
return FALSE;
......
unit_type_iterate(ut) {
if (requirement_needs_improvement(pimprove, &ut->build_reqs)
&& can_city_build_unit_now(pcity, ut)) {
&& can_city_build_unit_now(nmap, pcity, ut)) {
return TRUE;
}
} unit_type_iterate_end;
......
static bool impr_allows_actions(const struct city *pcity,
const struct impr_type *pimprove)
{
const struct civ_map *nmap = &(wld.map);
/* Fast check */
if (!pimprove->allows_actions) {
return FALSE;
......
return TRUE;
}
if (can_city_build_unit_now(pcity, ut)) {
if (can_city_build_unit_now(nmap, pcity, ut)) {
/* This city can build a unit that uses the building */
return TRUE;
}
common/unittype.c
{
struct unit_type *u;
int j;
const struct civ_map *nmap = &(wld.map);
fc_assert_ret_val((role >= 0 && role <= UTYF_LAST_USER_FLAG)
|| (role >= L_FIRST && role < L_LAST)
......
for (j = n_with_role[role] - 1; j >= 0; j--) {
u = with_role[role][j];
if (can_city_build_unit_now(pcity, u)) {
if (can_city_build_unit_now(nmap, pcity, u)) {
return u;
}
}
server/cityturn.c
**************************************************************************/
void choose_build_target(struct player *pplayer, struct city *pcity)
{
const struct civ_map *nmap = &(wld.map);
/* Pick the next thing off the worklist. */
if (worklist_change_build_target(pplayer, pcity)) {
return;
......
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(pcity, pcity->production.value.utype)) {
&& can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
utype_rule_name(pcity->production.value.utype));
return;
server/techtools.c
{
char research_name[MAX_LEN_NAME * 2];
/* Research members will be notified when new tech is chosen. */
const struct civ_map *nmap = &(wld.map);
research_pretty_name(presearch, research_name, sizeof(research_name));
......
bool update = FALSE;
if (pcity->production.kind == VUT_UTYPE
&& !can_city_build_unit_now(pcity, pcity->production.value.utype)) {
&& !can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
notify_player(pplayer, city_tile(pcity),
E_CITY_CANTBUILD, ftc_server,
_("%s can't build %s. The required technology was "
(2-2/3)