Project

General

Profile

Bug #207 » 0027-AI-Stop-attempts-to-recover-Helicopter-HP-in-the-ope.patch

Marko Lindqvist, 01/30/2024 07:30 PM

View differences:

ai/default/daiunit.c
CHECK_UNIT(punit);
if (pcity) {
/* rest in city until the hitpoints are recovered, but attempt
to protect city from attack (and be opportunistic too)*/
if (pcity != NULL) {
/* Rest in the city until the hitpoints are recovered, but attempt
* to protect city from attack (and be opportunistic too)*/
if (dai_military_rampage(punit, RAMPAGE_ANYTHING,
RAMPAGE_FREE_CITY_OR_BETTER)) {
UNIT_LOG(LOGLEVEL_RECOVERY, punit, "recovering hit points.");
} else {
return; /* we died heroically defending our city */
return; /* We died heroically defending our city */
}
} else {
/* goto to nearest city to recover hit points */
/* just before, check to see if we can occupy an undefended enemy city */
/* Goto to nearest city to recover hit points */
/* Just before, check to see if we can occupy an undefended enemy city */
if (!dai_military_rampage(punit, RAMPAGE_FREE_CITY_OR_BETTER,
RAMPAGE_FREE_CITY_OR_BETTER)) {
return; /* oops, we died */
return; /* Oops, we died */
}
/* find city to stay and go there */
/* Find a city to stay and go there */
safe = find_nearest_safe_city(punit);
if (safe) {
UNIT_LOG(LOGLEVEL_RECOVERY, punit, "going to %s to recover",
......
return;
}
} else {
/* oops */
/* Oops */
UNIT_LOG(LOGLEVEL_RECOVERY, punit, "didn't find a city to recover in!");
dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
dai_military_attack(ait, pplayer, punit);
......
}
}
/* is the unit still damaged? if true recover hit points, if not idle */
if (punit->hp == punittype->hp) {
/* we are ready to go out and kick ass again */
/* Is the unit still damaged? If true, and could recover hit points, do so.
* Don't wait if would be losing hitpoints that way! */
if (punit->hp == punittype->hp || !is_gaining_hp(punit)) {
/* We are ready to go out and kick ass again */
UNIT_LOG(LOGLEVEL_RECOVERY, punit, "ready to kick ass again!");
dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
return;
} else {
def_ai_unit_data(punit, ait)->done = TRUE; /* sit tight */
def_ai_unit_data(punit, ait)->done = TRUE; /* Sit tight */
}
}
common/unit.c
utype_class(punittype)->hp_loss_pct / 100);
}
/**********************************************************************//**
Does unit gain hitpoints each turn?
**************************************************************************/
bool is_gaining_hp(const struct unit *punit)
{
const struct unit_type *punittype = unit_type_get(punit);
return get_unit_bonus(punit, EFT_UNIT_RECOVER)
> (punittype->hp *
utype_class(punittype)->hp_loss_pct / 100);
}
/**********************************************************************//**
Does unit lose hitpoints each turn?
**************************************************************************/
common/unit.h
bool is_losing_hp(const struct unit *punit);
bool unit_type_is_losing_hp(const struct player *pplayer,
const struct unit_type *punittype);
bool is_gaining_hp(const struct unit *punit);
bool unit_is_alive(int id);
(1-1/4)