Project

General

Profile

Feature #513 ยป 0047-Unhardcode-wld.map-from-action_prob_vs_city.patch

Marko Lindqvist, 04/28/2024 06:43 PM

View differences:

ai/default/aidiplomat.c
struct player *pplayer = unit_owner(punit);
struct player *tplayer = city_owner(ctarget);
int count_tech = count_stealable_techs(pplayer, tplayer);
const struct civ_map *nmap = &(wld.map);
fc_assert_ret(is_ai(pplayer));
......
}
if (!action_prob_possible(
action_prob_vs_city(punit, action_number(paction),ctarget))) {
action_prob_vs_city(nmap, punit, action_number(paction),ctarget))) {
/* Not possible. */
continue;
}
......
/* An action has been selected. */
if (action_prob_possible(
action_prob_vs_city(punit, action_number(chosen_action),
action_prob_vs_city(nmap, punit, action_number(chosen_action),
ctarget))) {
log_base(LOG_DIPLOMAT, "%s %s[%d] does %s at %s",
nation_rule_name(nation_of_unit(punit)),
client/control.c
switch (action_id_get_target_kind(act)) {
case ATK_CITY:
if ((pcity = tile_city(unit_tile(punit)))
&& action_prob_possible(action_prob_vs_city(punit, act, pcity))) {
&& action_prob_possible(action_prob_vs_city(&(wld.map), punit,
act, pcity))) {
request_do_action(act, punit->id, pcity->id, 0, "");
}
break;
common/actions.c
Get the actor unit's probability of successfully performing the chosen
action on the target city.
**************************************************************************/
struct act_prob action_prob_vs_city(const struct unit *actor_unit,
struct act_prob action_prob_vs_city(const struct civ_map *nmap,
const struct unit *actor_unit,
const action_id act_id,
const struct city *target_city)
{
const struct civ_map *nmap = &(wld.map);
return action_prob_vs_city_full(nmap, actor_unit,
unit_home(actor_unit),
unit_tile(actor_unit),
......
{
/* Assume impossible until told otherwise. */
struct act_prob prob = ACTPROB_IMPOSSIBLE;
const struct civ_map *nmap = &(wld.map);
fc_assert_ret_val(paction, ACTPROB_IMPOSSIBLE);
fc_assert_ret_val(act_unit, ACTPROB_IMPOSSIBLE);
......
break;
case ATK_CITY:
if (tgt_city) {
prob = action_prob_vs_city(act_unit, paction->id, tgt_city);
prob = action_prob_vs_city(nmap, act_unit, paction->id, tgt_city);
}
break;
case ATK_UNIT:
common/actions.h
const action_id wanted_action,
const struct unit *actor_unit);
struct act_prob action_prob_vs_city(const struct unit* actor,
struct act_prob action_prob_vs_city(const struct civ_map *nmap,
const struct unit *actor,
const action_id act_id,
const struct city* victim);
const struct city *victim);
struct act_prob action_prob_vs_unit(const struct unit* actor,
const action_id act_id,
common/unit.c
return is_action_enabled_unit_on_city(nmap, ACTION_AIRLIFT,
punit, pdest_city);
} else {
return action_prob_possible(action_prob_vs_city(punit, ACTION_AIRLIFT,
return action_prob_possible(action_prob_vs_city(nmap, punit, ACTION_AIRLIFT,
pdest_city));
}
}
......
bool unit_can_help_build_wonder_here(const struct unit *punit)
{
struct city *pcity = tile_city(unit_tile(punit));
const struct civ_map *nmap = &(wld.map);
if (!pcity) {
if (pcity == NULL) {
/* No city to help at this tile. */
return FALSE;
}
......
/* Evaluate all action enablers for extra accuracy. */
/* TODO: Is it worth it? */
return action_prob_possible(action_prob_vs_city(punit,
return action_prob_possible(action_prob_vs_city(nmap, punit,
ACTION_HELP_WONDER,
pcity));
}
......
bool unit_can_add_or_build_city(const struct unit *punit)
{
struct city *tgt_city;
const struct civ_map *nmap = &(wld.map);
if ((tgt_city = tile_city(unit_tile(punit)))) {
return action_prob_possible(action_prob_vs_city(punit,
return action_prob_possible(action_prob_vs_city(nmap, punit,
ACTION_JOIN_CITY, tgt_city));
} else {
return action_prob_possible(action_prob_vs_tile(punit,
......
bool can_unit_change_homecity_to(const struct unit *punit,
const struct city *pcity)
{
const struct civ_map *nmap = &(wld.map);
if (pcity == NULL) {
/* Can't change home city to a non existing city. */
return FALSE;
}
return action_prob_possible(action_prob_vs_city(punit, ACTION_HOME_CITY,
return action_prob_possible(action_prob_vs_city(nmap, punit, ACTION_HOME_CITY,
pcity));
}
server/actiontools.c
static bool may_unit_act_vs_city(struct unit *actor, struct city *target,
bool accept_all_actions)
{
const struct civ_map *nmap = &(wld.map);
if (actor == NULL || target == NULL) {
/* Can't do any actions if actor or target are missing. */
return FALSE;
......
continue;
}
if (action_prob_possible(action_prob_vs_city(actor, act, target))) {
if (action_prob_possible(action_prob_vs_city(nmap, actor, act, target))) {
/* The actor unit may be able to do this action to the target
* city. */
return TRUE;
......
case ATK_CITY:
if (tgt_city
&& is_action_enabled_unit_on_city(nmap, act, actor, tgt_city)) {
current = action_prob_vs_city(actor, act, tgt_city);
current = action_prob_vs_city(nmap, actor, act, tgt_city);
}
break;
case ATK_UNIT:
server/unithand.c
/* Only a known city may be targeted. */
if (target_city) {
/* Calculate the probabilities. */
probabilities[act] = action_prob_vs_city(actor_unit, act,
probabilities[act] = action_prob_vs_city(nmap, actor_unit, act,
target_city);
} else if (!tile_is_seen(target_tile, actor_player)
&& action_maybe_possible_actor_unit(nmap, act, actor_unit)
server/unittools.c
tgt_id = dst_tile->index;
break;
case ATK_CITY:
prob = action_prob_vs_city(punit, order.action,
prob = action_prob_vs_city(nmap, punit, order.action,
tgt_city);
tgt_id = tgt_city->id;
break;
    (1-1/1)