76 return "Auto settler";
97 qCritical(
"Unsupported ai_unit_task %d.", task);
107 switch (choice->
type) {
120 qCritical(
"Unsupported ai_unit_task %d.", choice->
type);
133 int delay,
int build_cost)
138 int build_time = build_cost /
MAX(output, 1);
144 return amortize(value, delay + build_time);
176 struct tile *dest_tile)
183 bool bg_needed =
false;
229 if (danger >= my_def) {
231 "want bodyguard @(%d, %d) danger=%d, my_def=%d",
232 TILE_XY(dest_tile), danger, my_def);
239 }
else if (guard !=
nullptr) {
248 #define LOGLEVEL_GOTHERE LOG_DEBUG
259 struct unit *punit,
struct tile *dest_tile)
315 struct tile *dest_tile)
330 for (i = 1; i < path.length(); i++) {
331 if (path[i].
tile == path[i - 1].
tile) {
333 struct tile *ptile = path[i].tile;
344 qDebug(
"Did not find an air-route for "
345 "%s %s[%d] (%d,%d)->(%d,%d)",
438 bool can_get_there =
false;
441 can_get_there =
true;
450 can_get_there =
true;
454 return can_get_there;
479 const bool long_path =
565 }
else if (is_ferry) {
572 switch (unit_data->
task) {
667 if (punit->
activity == ACTIVITY_GOTO) {
680 qCritical(
"%s was on city founding mission without target tile.",
693 "no longer hunted (new task %d, old %d)", task,
704 unit_data->
task = task;
734 ACTION_SUICIDE_ATTACK)
746 switch (unit_data->
task) {
793 struct unit *bodyguard,
830 int sanity = punit->
id;
845 ACTION_CAPTURE_UNITS);
879 ACTION_SUICIDE_ATTACK);
885 ACTION_CONQUER_CITY);
891 ACTION_CONQUER_CITY2);
898 ACTION_TRANSPORT_EMBARK);
900 punit, ptile,
nullptr)) {
903 ACTION_TRANSPORT_DISEMBARK1);
905 punit, ptile,
nullptr)) {
908 ACTION_TRANSPORT_DISEMBARK2);
951 struct unit *bodyguard;
952 struct unit *ptrans =
nullptr;
953 int sanity = punit->
id;
955 const bool is_plr_ai =
is_ai(pplayer);
959 "Tiles not adjacent: Unit = %d, "
960 "from = (%d, %d]) to = (%d, %d).",
983 "does not want to leave "
996 punit, ptile,
nullptr)) {
1000 punit, ptile,
nullptr)) {
1009 if (paction ==
nullptr
1015 struct tile *from_tile;
1022 punit->
tile = ptile;
1026 punit->
tile = from_tile;
1040 if (paction && ptrans
1059 if (is_plr_ai && bodyguard !=
nullptr
1075 int victim_cost = 0;
1139 if (iunit !=
nullptr) {
1140 choice->
type = type;
1142 choice->
want = want;
1165 want = choice->
want;
1183 choice->
want = want;
1217 if (happy_cost > 0) {
1218 unhap += happy_cost;
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...
bool is_action_enabled_unit_on_city(const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
Returns TRUE if actor_unit can do wanted_action to target_city as far as action enablers are concerne...
int action_number(const struct action *action)
Get the universal number of the action.
bool is_action_enabled_unit_on_units(const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile)
Returns TRUE if actor_unit can do wanted_action to all units on the target_tile as far as action enab...
bool is_action_enabled_unit_on_tile(const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Returns TRUE if actor_unit can do wanted_action to the target_tile as far as action enablers are conc...
struct action * action_by_number(action_id act_id)
Return the action with the given id.
bool action_has_result(const struct action *paction, enum action_result result)
Returns TRUE iff performing the specified action has the specified result.
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Return a pointer to our data.
bool adv_danger_at(struct unit *punit, struct tile *ptile)
Are there dangerous enemies at or adjacent to the tile 'ptile'?
int adv_unittype_att_rating(const struct unit_type *punittype, int veteran, int moves_left, int hp)
Attack rating of this kind of unit.
int adv_unit_att_rating(const struct unit *punit)
Attack rating of this particular unit assuming that it has a complete move left.
bool adv_follow_path(struct unit *punit, const PFPath &path, struct tile *ptile)
Move a unit along a path without disturbing its activity, role or assigned destination Return FALSE i...
void adv_avoid_risks(struct pf_parameter *parameter, struct adv_risk_cost *risk_cost, struct unit *punit, const double fearfulness)
Set PF callbacks to favour paths that do not create tall stacks or cross dangerous tiles.
#define NORMAL_STACKING_FEARFULNESS
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
bool aiferry_gobyboat(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile, bool with_bodyguard)
This function is to be called if punit needs to use a boat to get to the destination.
bool dai_is_ferry(struct unit *pferry, struct ai_type *ait)
Should unit be considered a ferry?
void aiferry_clear_boat(struct ai_type *ait, struct unit *punit)
Use on a unit which no longer needs a boat.
struct unit * aiguard_charge_unit(struct ai_type *ait, struct unit *guard)
Which unit (if any) has a guard been assigned to? Returns nullptr if the unit is not the guard for a ...
void aiguard_clear_charge(struct ai_type *ait, struct unit *guard)
Remove the assignment of a charge to a guard.
void aiguard_request_guard(struct ai_type *ait, struct unit *punit)
Request a (new) bodyguard for the unit.
void aiguard_assign_guard_city(struct ai_type *ait, struct city *charge, struct unit *guard)
Assign a guard to a city.
void aiguard_clear_guard(struct ai_type *ait, struct unit *charge)
Remove assignment of bodyguard for a unit.
struct unit * aiguard_guard_of(struct ai_type *ait, struct unit *charge)
Which unit, if any, is the body guard of a unit? Returns nullptr if the unit has not been assigned a ...
#define CHECK_CHARGE_UNIT(ait, charge)
#define CHECK_GUARD(ait, guard)
#define BODYGUARD_LOG(ait, loglevel, punit, msg,...)
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
struct unit_type * dai_wants_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, int role, int want)
Returns the best unit we can build, or nullptr if none.
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
struct city * is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy city on this tile?
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_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Return whether given city can build given building; returns FALSE if the building is obsolete.
int city_unit_unhappiness(const unit *punit, int *free_unhappy)
Query unhappiness caused by a given unit.
#define city_list_iterate(citylist, pcity)
#define city_list_iterate_end
void citymap_free_city_spot(struct tile *ptile, int id)
Reverse any reservations we have made in the surrounding area.
void citymap_reserve_city_spot(struct tile *ptile, int id)
This function reserves a single tile for a (possibly virtual) city with a settler's or a city's id.
void auto_arrange_workers(struct city *pcity)
Call sync_cities() to send the affected cities to the clients.
enum unit_attack_result unit_attack_unit_at_tile_result(const struct unit *punit, const struct unit *pdefender, const struct tile *dest_tile)
Checks if a unit can physically attack pdefender at the tile (assuming it is adjacent and at war).
bool is_stack_vulnerable(const struct tile *ptile)
Is it a city/fortress/air base or will the whole stack die in an attack.
struct unit_type * dai_choose_defender_versus(struct city *pcity, struct unit *attacker)
Choose the best unit the city can build to defend against attacker v.
int get_city_bonus(const struct city *pcity, enum effect_type effect_type, enum vision_layer vlayer)
Returns the effect bonus at a city.
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
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...
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
Government_type_id government_number(const struct government *pgovern)
Return the government index.
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...
const char * improvement_rule_name(const struct impr_type *pimprove)
Return the (untranslated) rule name of the improvement.
Impr_type_id improvement_index(const struct impr_type *pimprove)
Return the improvement index.
bool is_wonder(const struct impr_type *pimprove)
Returns whether improvement is some kind of wonder.
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define fc_assert_ret_val_msg(condition, val, message,...)
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Are two tiles adjacent to each other.
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Are (x1,y1) and (x2,y2) really the same when adjusted? This function might be necessary ALOT of place...
int map_distance(const struct tile *tile0, const struct tile *tile1)
Return Manhattan distance between two tiles.
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
int unit_move_rate(const struct unit *punit)
This function calculates the move rate of the unit.
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Return TRUE iff the unit can "survive" at this location.
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.
int pf_map_move_cost(struct pf_map *pfm, struct tile *ptile)
Tries to find the minimal move cost to reach ptile.
int player_index(const struct player *pplayer)
Return the player index.
static bool is_barbarian(const struct player *pplayer)
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Called by the client or AI to change government.
int total_player_citizens(const struct player *pplayer)
Return the total number of citizens in the player's nation.
#define UNIT_LOG(_, punit, msg,...)
#define CITY_LOG(_, pcity, msg,...)
#define LOGLEVEL_BODYGUARD
struct adv_data::@87 stats
struct city::@15::@17 server
struct unit_list * units_supported
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
int(* get_moves_left_req)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
bool(* get_zoc)(const struct player *pplayer, const struct tile *ptile, const struct civ_map *zmap)
struct city_list * cities
struct player_ai ai_common
enum unit_activity activity
struct unit::@76::@79 server
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
const struct impr_type * building
int unit_pays_mp_for_action(const struct action *paction, const struct unit *punit)
Returns the amount of movement points successfully performing the specified action will consume in th...
bool is_losing_hp(const struct unit *punit)
Does unit lose hitpoints each turn?
bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit can be loaded into the transporter.
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Find the best transporter at the given location for the unit.
bool unit_is_cityfounder(const struct unit *punit)
Is a cityfounder unit?
bool unit_transported(const struct unit *pcargo)
Returns TRUE iff the unit is transported.
bool unit_has_orders(const struct unit *punit)
Return TRUE iff the unit is following client-side orders.
struct unit * is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy unit on this tile? Returns the unit or nullptr if none.
#define CHECK_UNIT(punit)
bool unit_move_handling(struct unit *punit, struct tile *pdesttile, bool igzoc, bool move_do_not_act)
Will try to move to/attack the tile dest_x,dest_y.
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Handle request for changing activity.
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_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.
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Returns TRUE iff successfully performing the specified action always will move the actor unit of the ...
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
bool utype_may_act_at_all(const struct unit_type *putype)
Return TRUE iff units of this type can do actions controlled by generalized (ruleset defined) action ...
int unit_build_shield_cost_base(const struct unit *punit)
Returns the number of shields this unit represents.
struct unit_class * unit_class_get(const struct unit *punit)
Returns unit class pointer for a unit.
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Return TRUE iff units of the given type can do any enabler controlled action with the specified actio...
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_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...
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Return veteran level properties of given unit in given veterancy level.
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
#define utype_fuel(ptype)