83 enum terrain_class tc,
85 bool allow_gold_upkeep)
108 || ut->attack_strength < ut->transport_capacity
114 desire = (ut->hp * ut->attack_strength * ut->firepower * ut->move_rate
115 + ut->defense_strength)
119 desire += desire / 6;
123 desire += desire / 2;
125 if (ut->vlayer == V_INVIS) {
126 desire += desire / 4;
129 desire -= desire / 4;
157 struct unit_type *best_unit_type =
nullptr;
158 struct unit *hunter =
nullptr;
200 desire = (ut->hp *
MIN(ut->attack_strength, 30)
201 * ut->firepower * ut->move_rate)
220 if (best > choice->
want) {
228 }
else if (best >= 0) {
243 struct unit *virtualunit;
249 if (want > choice->
want) {
264 bool allow_gold_upkeep)
272 if ((!best_land_hunter && !best_sea_hunter) ||
is_barbarian(pplayer)
282 if (best_sea_hunter) {
284 ait, pplayer, pcity, choice, best_sea_hunter,
287 if (best_land_hunter) {
289 ait, pplayer, pcity, choice, best_land_hunter,
314 int target_sanity = target->
id;
320 struct unit *sucker =
nullptr;
324 ACTION_SUICIDE_ATTACK)) {
332 if (move_cost > missile->moves_left /
SINGLE_MOVE) {
340 enum diplstate_type ds =
348 if (victim == target) {
351 "found primary target %d(%d, %d)"
382 ACTION_TRANSPORT_ALIGHT);
407 struct unit *target,
int *stackthreat,
420 *stackthreat += 5000;
430 *stackthreat += *stackcost;
448 bool is_virtual = (punit->
id == 0);
454 int original_threat = 0, original_cost = 0;
463 if (original_target) {
471 if (move_cost > limit) {
484 int dist1, dist2, stackthreat = 0, stackcost = 0;
485 int sanity_target = target->id;
514 "considering chasing %s[%d](%d, %d) "
523 "giving up racing %s (%d, %d)->(%d, %d)",
542 "%d is too expensive (it %d vs us %d)",
target->id,
546 stackthreat /= move_cost + 1;
547 if (!is_virtual && original_target !=
target
548 && original_threat > stackthreat) {
559 "hunting %s %s[%d](%d,%d) "
560 "with want %d, dist1 %d, dist2 %d",
580 "mission accomplished by cargo (pre)");
604 "mission accomplished by cargo (post)");
611 unit_data->
done =
true;
bool is_action_enabled_unit_on_unit(const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Returns TRUE if actor_unit can do wanted_action to target_unit as far as action enablers are concerne...
#define adv_choice_set_use(_choice, _use)
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
There are some signs that a player might be dangerous: We are at war with him, he has done lots of ig...
bool adv_unit_execute_path(struct unit *punit, const PFPath &path)
This is a function to execute paths returned by the path-finding engine, for units controlled by advi...
static struct unit * dai_hunter_find(struct player *pplayer, struct city *pcity)
We don't need a hunter in this city if we already have one.
static void eval_hunter_want(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, struct unit_type *best_type, int veteran)
Support function for ai_hunter_choice()
bool dai_hunter_qualify(struct player *pplayer, struct unit *punit)
Does this unit qualify as a hunter?
static void dai_hunter_juiciness(struct player *pplayer, struct unit *punit, struct unit *target, int *stackthreat, int *stackcost)
Calculate desire to crush this target.
static void dai_hunter_missile_want(struct player *pplayer, struct city *pcity, struct adv_choice *choice)
Check if we want to build a missile for our hunter.
static struct unit_type * dai_hunter_guess_best(struct city *pcity, enum terrain_class tc, struct ai_type *ait, bool allow_gold_upkeep)
Guess best hunter unit type.
void dai_hunter_choice(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, bool allow_gold_upkeep)
Check if we want to build a hunter.
int dai_hunter_manage(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Manage a (possibly virtual) hunter.
static void dai_hunter_try_launch(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct unit *target)
Try to shoot our target with a missile.
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
bool dai_unit_can_strike_my_unit(const struct unit *attacker, const struct unit *defender)
Returns whether 'attacker' can attack 'defender' immediately.
#define DEFENSE_POWER(ptype)
#define ATTACK_POWER(ptype)
#define UNITTYPE_COSTS(ut)
bool BV_ISSET(const BV &bv, int bit)
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
How many veteran levels will created unit of this type get?
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Return whether given city can build given unit; returns FALSE if unit is obsolete.
struct unit * get_defender(const struct unit *attacker, const struct tile *ptile)
Finds the best defender on the tile, given an attacker.
double unit_win_chance(const struct unit *attacker, const struct unit *defender)
Returns a double in the range [0;1] indicating the attackers chance of winning.
bool can_unit_attack_tile(const struct unit *punit, const struct tile *dest_tile)
Is unit (1) diplomatically allowed to attack and (2) physically able to do so?
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
AI players may have handicaps - allowing them to cheat or preventing them from using certain algorith...
#define fc_assert_ret_val(condition, val)
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Are two tiles adjacent to each other.
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
static int index_to_map_pos_y(int mindex)
static int index_to_map_pos_x(int mindex)
int unit_move_rate(const struct unit *punit)
This function calculates the move rate of the unit.
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Return TRUE iff transporter type has ability to transport transported class.
bool can_attack_non_native(const struct unit_type *utype)
This unit can attack non-native tiles (eg.
const char * nation_rule_name(const struct nation_type *pnation)
Return the (untranslated) rule name of the nation (adjective form).
struct nation_type * nation_of_unit(const struct unit *punit)
Return the nation of the player who owns the unit.
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
Factory function to create a new map according to the parameter.
PFPath pf_map_path(struct pf_map *pfm, struct tile *ptile)
CHECK DOCS AFTER FULL CONVERSTION OF pf_path to class PFPath Tries to find the best path in the given...
void pf_map_destroy(struct pf_map *pfm)
After usage the map must be destroyed.
#define pf_map_move_costs_iterate_end
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
int player_index(const struct player *pplayer)
Return the player index.
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
static bool is_barbarian(const struct player *pplayer)
#define UNIT_LOG(_, punit, msg,...)
#define CITY_LOG(_, pcity, msg,...)
struct unit_list * units_supported
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
const struct unit_type * utype
struct unit * unit_transport_get(const struct unit *pcargo)
Returns the transporter of the unit or nullptr if it is not transported.
int get_transporter_capacity(const struct unit *punit)
Return the number of units the transporter can hold (or 0).
void unit_virtual_destroy(struct unit *punit)
Free the memory used by virtual unit.
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Create a virtual unit skeleton.
bool unit_transported(const struct unit *pcargo)
Returns TRUE iff the unit is transported.
void unit_do_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id, const char *name, const action_id action_type)
Handle unit action.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_safe(unitlist, _unit)
#define unit_list_iterate_end
#define unit_list_iterate_safe_end
const char * unit_rule_name(const struct unit *punit)
Return the (untranslated) rule name of the unit.
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Returns the upkeep of a unit of this type under the given government.
int utype_build_shield_cost(const struct city *pcity, const struct unit_type *punittype)
Returns the number of shields it takes to build this unit type.
bool utype_is_consumed_by_action_result(enum action_result result, const struct unit_type *utype)
Returns TRUE iff performing an action with the specified action result will consume an actor unit of ...
int unit_build_shield_cost_base(const struct unit *punit)
Returns the number of shields this unit represents.
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Return whether the unit has the given role.
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
bool utype_acts_hostile(const struct unit_type *putype)
Return TRUE iff units of this type can do hostile actions controlled by generalized (ruleset defined)...
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Return TRUE iff units of the given type can do the specified generalized (ruleset defined) action ena...
void * utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
Return pointer to ai data of given unit type and ai type.
#define utype_fuel(ptype)
static bool utype_has_flag(const struct unit_type *punittype, int flag)
#define unit_type_iterate(_p)
#define unit_type_iterate_end