Feature #1240 » 0073-AI-Pass-civ_map-to-find_something_to_kill.patch
| ai/default/daimilitary.c | ||
|---|---|---|
|
goto cleanup;
|
||
|
}
|
||
|
best_choice->want = find_something_to_kill(ait, pplayer, myunit, &ptile, NULL,
|
||
|
best_choice->want = find_something_to_kill(ait, nmap, pplayer, myunit, &ptile, NULL,
|
||
|
&ferry_map, &ferryboat,
|
||
|
&boattype, &move_time);
|
||
|
if (NULL == ptile
|
||
| ai/default/daiunit.c | ||
|---|---|---|
|
struct player *pplayer, struct unit *punit);
|
||
|
static void dai_military_defend(struct ai_type *ait, struct player *pplayer,
|
||
|
struct unit *punit);
|
||
|
static void dai_military_attack(struct ai_type *ait, struct player *pplayer,
|
||
|
struct unit *punit);
|
||
|
static void dai_military_attack(struct ai_type *ait, const struct civ_map *nmap,
|
||
|
struct player *pplayer, struct unit *punit);
|
||
|
static bool unit_role_defender(const struct unit_type *punittype);
|
||
|
static int unit_def_rating_squared(const struct unit *punit,
|
||
| ... | ... | |
|
the denom, so that def=1 units are penalized correctly."
|
||
|
Translation (GB): build_cost_balanced is used in the denominator of
|
||
|
the want equation (see, e.g. find_something_to_kill) instead of
|
||
|
the want equation (see, e.g. find_something_to_kill() ) instead of
|
||
|
just build_cost to make AI build more balanced units (with def > 1).
|
||
|
**************************************************************************/
|
||
|
int build_cost_balanced(const struct unit_type *punittype)
|
||
| ... | ... | |
|
punit->id == 0 means that the unit is virtual (considered to be built).
|
||
|
**************************************************************************/
|
||
|
adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer,
|
||
|
adv_want find_something_to_kill(struct ai_type *ait, const struct civ_map *nmap,
|
||
|
struct player *pplayer,
|
||
|
struct unit *punit,
|
||
|
struct tile **pdest_tile, struct pf_path **ppath,
|
||
|
struct pf_map **pferrymap,
|
||
| ... | ... | |
|
adv_want best = 0; /* Best of all wants. */
|
||
|
struct tile *goto_dest_tile = nullptr;
|
||
|
bool can_occupy;
|
||
|
struct civ_map *nmap = &(wld.map);
|
||
|
/* Very preliminary checks. */
|
||
|
*pdest_tile = punit_tile;
|
||
| ... | ... | |
|
looking for trouble elsewhere. If there is nothing to kill, sailing units
|
||
|
go home, others explore while barbs go berserk.
|
||
|
**************************************************************************/
|
||
|
static void dai_military_attack(struct ai_type *ait, struct player *pplayer,
|
||
|
struct unit *punit)
|
||
|
static void dai_military_attack(struct ai_type *ait, const struct civ_map *nmap,
|
||
|
struct player *pplayer, struct unit *punit)
|
||
|
{
|
||
|
struct tile *dest_tile;
|
||
|
int id = punit->id;
|
||
| ... | ... | |
|
struct unit *ferryboat;
|
||
|
/* Then find enemies the hard way */
|
||
|
find_something_to_kill(ait, pplayer, punit, &dest_tile, &path,
|
||
|
find_something_to_kill(ait, nmap, pplayer, punit, &dest_tile, &path,
|
||
|
nullptr, &ferryboat, nullptr, nullptr);
|
||
|
if (!same_pos(unit_tile(punit), dest_tile)) {
|
||
|
if (!is_tiles_adjacent(unit_tile(punit), dest_tile)
|
||
| ... | ... | |
|
If something is attacking our city, kill it yeahhh!!!.
|
||
|
**************************************************************************/
|
||
|
static void dai_manage_hitpoint_recovery(struct ai_type *ait,
|
||
|
const struct civ_map *nmap,
|
||
|
struct unit *punit)
|
||
|
{
|
||
|
struct player *pplayer = unit_owner(punit);
|
||
| ... | ... | |
|
/* Oops */
|
||
|
UNIT_LOG(LOGLEVEL_RECOVERY, punit, "didn't find a city to recover in!");
|
||
|
dai_unit_new_task(ait, punit, AIUNIT_NONE, nullptr);
|
||
|
dai_military_attack(ait, pplayer, punit);
|
||
|
dai_military_attack(ait, nmap, pplayer, punit);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
case AIUNIT_ATTACK:
|
||
|
case AIUNIT_NONE:
|
||
|
TIMING_LOG(AIT_ATTACK, TIMER_START);
|
||
|
dai_military_attack(ait, pplayer, punit);
|
||
|
dai_military_attack(ait, nmap, pplayer, punit);
|
||
|
TIMING_LOG(AIT_ATTACK, TIMER_STOP);
|
||
|
break;
|
||
|
case AIUNIT_ESCORT:
|
||
| ... | ... | |
|
break;
|
||
|
case AIUNIT_RECOVER:
|
||
|
TIMING_LOG(AIT_RECOVER, TIMER_START);
|
||
|
dai_manage_hitpoint_recovery(ait, punit);
|
||
|
dai_manage_hitpoint_recovery(ait, nmap, punit);
|
||
|
TIMING_LOG(AIT_RECOVER, TIMER_STOP);
|
||
|
break;
|
||
|
case AIUNIT_HUNTER:
|
||
| ai/default/daiunit.h | ||
|---|---|---|
|
const struct unit_type *cargo_type,
|
||
|
const struct unit_type *ferry_type,
|
||
|
struct tile **ferry_dest, struct tile **beachhead_tile);
|
||
|
adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer,
|
||
|
adv_want find_something_to_kill(struct ai_type *ait, const struct civ_map *nmap,
|
||
|
struct player *pplayer,
|
||
|
struct unit *punit,
|
||
|
struct tile **pdest_tile,
|
||
|
struct pf_path **ppath,
|
||
- « Previous
- 1
- 2
- Next »