47 enum unit_activity activity = punit->
activity;
58 if (activity != ACTIVITY_GOTO) {
84 for (i = 1; i < path.
length(); i++) {
85 struct tile *ptile = path[i].tile;
132 struct unit *ptrans =
nullptr;
150 punit, ptile,
nullptr)) {
154 punit, ptile,
nullptr)) {
163 if (paction ==
nullptr
169 struct tile *from_tile;
180 punit->
tile = from_tile;
197 if (paction && ptrans
278 int moves_left,
int hp)
323 int extras_bonus = 0;
343 db += (db * extras_bonus) / 100;
358 if ((a * a * 10) >= d) {
375 const struct player *pplayer)
407 int extras_bonus = 0;
422 db += (extras_bonus) / 100;
452 double danger = value * p_killed;
492 const double fearfulness)
497 const double linger_fraction =
500 parameter->
data = risk_cost;
503 risk_cost->
fearfulness = fearfulness * linger_fraction;
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...
int action_number(const struct action *action)
Get the universal number of the action.
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.
int adv_unit_def_rating_basic_squared(const struct unit *punit)
Square of the previous function - used in actual computations.
static int stack_value(const struct tile *ptile, const struct player *pplayer)
The value of the units belonging to a given player on a given tile.
int adv_unit_def_rating_basic(const struct unit *punit)
Basic (i.e.
static int stack_risk(const struct tile *ptile, struct adv_risk_cost *risk_cost, const struct pf_parameter *param)
PF stack risk cost.
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...
bool adv_danger_at(struct unit *punit, struct tile *ptile)
Are there dangerous enemies at or adjacent to the tile 'ptile'?
static bool adv_unit_move(struct unit *punit, struct tile *ptile)
Move a unit.
static double chance_killed_at(const struct tile *ptile, struct adv_risk_cost *risk_cost, const struct pf_parameter *param)
How dangerous would it be stop on a particular tile, because of enemy attacks, expressed as the proba...
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.
static bool adv_could_be_my_zoc(struct unit *myunit, struct tile *ptile)
Similar to is_my_zoc(), but with some changes:
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...
int adv_could_unit_move_to_tile(struct unit *punit, struct tile *dest_tile)
returns: 0 if can't move 1 if zoc_ok -1 if zoc could be ok?
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.
static int prefer_short_stacks(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
PF extra cost call back to avoid creating tall stacks or crossing dangerous tiles.
#define CALL_PLR_AI_FUNC(_func, _player,...)
struct city * is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non_allied city on this tile?
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.
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).
enum unit_attack_result unit_attack_units_at_tile_result(const struct unit *punit, const struct tile *ptile)
Check if unit can attack unit stack at tile.
bool is_stack_vulnerable(const struct tile *ptile)
Is it a city/fortress/air base or will the whole stack die in an attack.
int base_get_attack_power(const struct unit_type *punittype, int veteran, int moves_left)
Returns the attack power, modified by moves left, and veteran status.
int base_get_defense_power(const struct unit *punit)
Returns the defense power, modified by veteran status.
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...
#define fc_assert(condition)
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...
#define adjc_iterate(nmap, center_tile, itr_tile)
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Returns whether the layer 'vlayer' of the tile 'ptile' is known and seen by the player 'pplayer'.
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.
enum unit_move_result unit_move_to_tile_test(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity, const struct tile *src_tile, const struct tile *dst_tile, bool igzoc, struct unit *embark_to, bool enter_enemy_city)
Returns whether the unit can move from its current tile to the destination tile.
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players can attack each other.
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
#define UNIT_LOG(_, punit, msg,...)
const struct civ_map * map
int(* get_EC)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
const struct player * owner
const struct unit_type * utype
enum unit_activity activity
struct extra_type * activity_target
#define is_ocean_tile(ptile)
#define terrain_has_flag(terr, flag)
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Calculate defense bonus given for unit class by extras.
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Calculate defense bonus given for unit type by bases and roads.
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
#define tile_terrain(_tile)
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_my_zoc(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
Is this square controlled by the pplayer?
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
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.
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.
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.
bool unit_activity_handling_targeted(struct unit *punit, enum unit_activity new_activity, struct extra_type **new_target)
Handle request for targeted activity.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
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 ...
int unit_build_shield_cost_base(const struct unit *punit)
Returns the number of shields this unit represents.
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.