65 #define LOG_DIPLOMAT LOG_DEBUG
66 #define LOG_DIPLOMAT_BUILD LOG_DEBUG
70 #define DIPLO_DEFENSE_WANT 3000
78 struct city **ctarget,
int *move_dist,
124 "A defensive diplomat will be built in city %s.",
126 choice->
want = 16000;
135 "A defensive diplomat is wanted badly in city %s.",
144 "ai_choose_diplomat_defensive() + %d for %s",
182 int want, loss, p_success, p_failure, time_to_dest;
183 int gain_incite = 0, gain_theft = 0, gain = 1;
209 && (incite_cost < pplayer->economic.gold - expenses)) {
239 gain =
MAX(gain_incite, gain_theft);
254 time_to_dest *= ((time_to_dest + 1) / 2);
257 want = (p_success * gain - p_failure * loss) / 100
272 "A diplomat desired in %s to establish an embassy with %s "
278 if (want > choice->
want) {
280 "%s, %s: %s is desired with want %d to spy in %s (incite "
281 "want %d cost %d gold %d, tech theft want %d, ttd %d)",
284 incite_cost, pplayer->
economic.
gold - expenses, gain_theft,
306 struct city *ctarget)
308 struct action *chosen_action;
310 int chosen_sub_tgt_id;
325 chosen_action =
nullptr;
326 chosen_action_utility = -1;
327 chosen_sub_tgt_id = 0;
356 sub_tgt_id, count_tech);
358 if (chosen_action_utility < action_utility) {
359 chosen_action = paction;
360 chosen_action_utility = action_utility;
361 chosen_sub_tgt_id = sub_tgt_id;
366 if (chosen_action !=
nullptr) {
383 "decides to stand idle outside enemy city %s!",
393 struct city *enemy_city)
421 struct city **ctarget,
int *move_dist,
460 ACTION_SPY_INCITE_CITY_ESC, pplayer, acity));
485 || (incite_cost < (pplayer->
economic.
gold - expenses) && can_incite
490 *move_dist = move_cost;
508 int best_urgency = 0;
509 struct city *ctarget =
nullptr;
530 if (aplayer != pplayer) {
541 }
else if (dipls > 0) {
547 if (move_cost > best_dist) {
549 urgency /=
static_cast<float>(move_cost / best_dist);
557 best_dist =
MAX(move_cost, 1);
574 int gold_avail, expenses;
581 struct tile *ptile = pos.tile;
583 int newval, bestval = 0, cost;
585 int sanity = punit->
id;
608 if (bestval < newval) {
638 if (cost > gold_avail) {
645 struct tile *bribee_tile;
650 static_cast<direction8
>(
DIR_REVERSE(pos.dir_to_here)));
661 ACTION_SPY_BRIBE_UNIT);
665 punit, ACTION_SPY_SABOTAGE_UNIT_ESC, pvictim))
669 ACTION_SPY_SABOTAGE_UNIT_ESC);
675 "could not bribe target (%d, %d), "
699 struct city *pcity, *ctarget =
nullptr;
744 bool failure =
false;
801 pplayer,
true,
false,
false,
802 true,
false,
nullptr))
822 if (ctarget ==
nullptr) {
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Returns TRUE if the wanted action can be done to the target city.
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...
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Get the actor kind of an action.
const char * action_rule_name(const struct action *action)
Get the rule name of the action.
bool action_prob_possible(const struct act_prob probability)
Returns TRUE iff the given action probability belongs to an action that may be possible.
struct act_prob action_prob_vs_city(const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Get the actor unit's probability of successfully performing the chosen action on the target city.
struct act_prob action_prob_vs_unit(const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Get the actor unit's probability of successfully performing the chosen action on the target unit.
int action_number(const struct action *action)
Get the universal number of the action.
struct action * action_by_number(action_id act_id)
Return the action with the given id.
enum action_target_kind action_get_target_kind(const struct action *paction)
Get the target kind of an action.
#define action_iterate_end
#define action_iterate(_act_)
#define adv_choice_set_use(_choice, _use)
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 aia_utype_is_considered_spy(const struct unit_type *putype)
Returns TRUE if the specified unit type is able to perform diplomatic actions.
bool aia_utype_is_considered_worker(const struct unit_type *putype)
Returns TRUE if the specified unit type is able to perform worker actions.
static bool is_city_surrounded_by_our_spies(struct player *pplayer, struct city *pcity)
Check if we have a diplomat / spy near a given city.
void dai_choose_diplomat_defensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, int def)
Calculates our need for diplomats as defensive units.
static struct city * dai_diplomat_defend(struct ai_type *ait, struct player *pplayer, struct unit *punit, const struct unit_type *utype, struct pf_map *pfm)
Go to nearest/most threatened city (can be the current city too).
void dai_manage_diplomat(struct ai_type *ait, struct player *pplayer, struct unit *punit)
If we are the only diplomat in a threatened city, defend against enemy actions.
#define LOG_DIPLOMAT_BUILD
static void dai_diplomat_city(struct ai_type *ait, struct unit *punit, struct city *ctarget)
Check if something is on our receiving end for some nasty diplomat business! Note that punit may die ...
void dai_choose_diplomat_offensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice)
Calculates our need for diplomats as offensive units.
#define DIPLO_DEFENSE_WANT
static bool dai_diplomat_bribe_nearby(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct pf_map *pfm)
Find units that we can reach, and bribe them.
static int count_stealable_techs(struct player *pplayer, struct player *tplayer)
Number of techs that we don't have and the enemy (tplayer) does.
static void find_city_to_diplomat(struct player *pplayer, struct unit *punit, struct city **ctarget, int *move_dist, struct pf_map *pfm)
Returns (in ctarget) the closest city to send diplomats against, or nullptr if none available on this...
void aiguard_request_guard(struct ai_type *ait, struct unit *punit)
Request a (new) bodyguard for the unit.
void dai_calc_data(const struct player *pplayer, int *trade, int *expenses, int *income)
Returns the total amount of trade generated (trade) and total amount of gold needed as upkeep (expens...
#define TECH_LOG(ait, _, pplayer, padvance, msg,...)
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
#define DEFENSE_POWER(ptype)
#define ATTACK_POWER(ptype)
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
struct tile * city_tile(const struct city *pcity)
Return the tile location 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?
const char * city_name_get(const struct city *pcity)
Return the name of the city.
#define INCITE_IMPOSSIBLE_COST
int city_incite_cost(struct player *pplayer, struct city *pcity)
Returns the cost to incite a city.
int dai_action_choose_sub_tgt_unit_vs_city(struct action *paction, struct unit *actor_unit, struct city *target_city)
Returns the sub target id of the sub target chosen for the specified action performed by the specifie...
adv_want dai_action_value_unit_vs_city(struct action *paction, struct unit *actor_unit, struct city *target_city, int sub_tgt_id, int count_tech)
Returns the utility of having the specified unit perform the specified action to the specified city t...
int diplomats_unignored_tech_stealings(struct unit *pdiplomat, struct city *pcity)
Returns the amount of tech thefts from a city not ignored by the EFT_STEALINGS_IGNORE effect.
int count_diplomats_on_tile(struct tile *ptile)
Return number of diplomats on this square.
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(condition)
#define fc_assert(condition)
#define log_base(level, message,...)
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 real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Step from the given tile in the given direction.
#define adjc_iterate(nmap, center_tile, itr_tile)
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.
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.
bool pf_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
Get info about position at ptile and put it in pos.
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_positions_iterate_end
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
#define pf_map_positions_iterate(ARG_pfm, NAME_pos, COND_from_start)
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Check if pplayer has an embassy with pplayer2.
static bool is_barbarian(const struct player *pplayer)
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Function to determine cost for technology.
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
#define UNIT_LOG(_, punit, msg,...)
enum act_tgt_compl target_complexity
adv_want tech_want[A_LAST+1]
QSet< int > diplomat_reservations
struct ai_plr::@155 stats
struct civ_game::@28::@32 server
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
bool(* get_zoc)(const struct player *pplayer, const struct tile *ptile, const struct civ_map *zmap)
struct player_economic economic
struct advance * require_advance
Tech_type_id advance_index(const struct advance *padvance)
Return the advance index.
#define advance_index_iterate_end
#define advance_index_iterate(_start, _index)
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 * is_other_players_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an unit belonging to another player on this tile?
int unit_bribe_cost(struct unit *punit, struct player *briber)
Calculate how expensive it is to bribe the unit.
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Return TRUE iff this unit can do any enabler controlled action with the specified action result.
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.
#define CHECK_UNIT(punit)
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.
struct unit_type * best_role_unit(const struct city *pcity, int role)
Return "best" unit this city can build, with given role/flag.
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
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.
int num_role_units(int role)
How many unit types have specified role/flag.
struct unit_type * get_role_unit(int role, int role_index)
Return index-th unit with specified role/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...