Freeciv-3.2
Loading...
Searching...
No Matches
Macros | Functions | Variables
daidiplomacy.c File Reference
#include <stdarg.h>
#include <string.h>
#include "fcintl.h"
#include "log.h"
#include "mem.h"
#include "rand.h"
#include "shared.h"
#include "support.h"
#include "aisupport.h"
#include "city.h"
#include "diptreaty.h"
#include "events.h"
#include "game.h"
#include "packets.h"
#include "player.h"
#include "nation.h"
#include "research.h"
#include "spaceship.h"
#include "tech.h"
#include "unitlist.h"
#include "citytools.h"
#include "diplhand.h"
#include "maphand.h"
#include "notify.h"
#include "srv_log.h"
#include "advdata.h"
#include "advtools.h"
#include "aitraits.h"
#include "handicaps.h"
#include "aitools.h"
#include "daicity.h"
#include "daidata.h"
#include "dailog.h"
#include "daimilitary.h"
#include "daiplayer.h"
#include "daidiplomacy.h"

Go to the source code of this file.

Macros

#define LOG_DIPL   LOG_DEBUG
 
#define LOG_DIPL2   LOG_DEBUG
 
#define BIG_NUMBER   100000
 
#define TURNS_BEFORE_TARGET   15
 

Functions

static void dai_incident_war (struct player *violator, struct player *victim)
 
static void dai_incident_simple (struct player *receiver, const struct player *violator, const struct player *victim, enum casus_belli_range scope, int how_bad)
 
static void dai_incident_nuclear (struct player *receiver, const struct player *violator, const struct player *victim)
 
static void dai_incident_nuclear_not_target (struct player *receiver, const struct player *violator, const struct player *victim)
 
static void dai_incident_nuclear_self (struct player *receiver, const struct player *violator, const struct player *victim)
 
static void clear_old_treaty (struct player *pplayer, struct player *aplayer)
 
static void dai_diplo_notify (struct player *pplayer, const char *text,...)
 
static int greed (int missing_love)
 
static enum diplstate_type pact_clause_to_diplstate_type (enum clause_type type)
 
static int dai_goldequiv_tech (struct ai_type *ait, struct player *pplayer, Tech_type_id tech)
 
static bool shared_vision_is_safe (struct player *pplayer, struct player *aplayer)
 
static bool dai_players_can_agree_on_ceasefire (struct ai_type *ait, struct player *player1, struct player *player2)
 
static int compute_tech_sell_price (struct ai_type *ait, struct player *giver, struct player *taker, int tech_id, bool *is_dangerous)
 
static const struct playerget_allied_with_enemy_player (const struct player *us, const struct player *them)
 
static int dai_goldequiv_clause (struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Clause *pclause, bool verbose, enum diplstate_type ds_after)
 
void dai_treaty_evaluate (struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
 
static void dai_treaty_react (struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Clause *pclause)
 
void dai_treaty_accepted (struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
 
static int dai_war_desire (struct ai_type *ait, struct player *pplayer, struct player *target)
 
static void dai_diplomacy_suggest (struct player *pplayer, struct player *aplayer, enum clause_type what, bool to_pplayer, int value)
 
void dai_diplomacy_first_contact (struct ai_type *ait, struct player *pplayer, struct player *aplayer)
 
void dai_diplomacy_begin_new_phase (struct ai_type *ait, struct player *pplayer)
 
static void suggest_tech_exchange (struct ai_type *ait, struct player *player1, struct player *player2)
 
static void dai_share (struct ai_type *ait, struct player *pplayer, struct player *aplayer)
 
static void dai_declare_war (struct ai_type *ait, struct player *pplayer, struct player *target)
 
static void dai_go_to_war (struct ai_type *ait, struct player *pplayer, struct player *target, enum war_reason reason)
 
void dai_revolution_start (struct ai_type *ait, struct player *pplayer)
 
static void war_countdown (struct ai_type *ait, struct player *pplayer, struct player *target, int countdown, enum war_reason reason)
 
void dai_diplomacy_actions (struct ai_type *ait, struct player *pplayer)
 
bool dai_on_war_footing (struct ai_type *ait, struct player *pplayer)
 
void dai_incident (struct ai_type *ait, enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *receiver, struct player *violator, struct player *victim)
 

Variables

static bool diplomacy_verbose = TRUE
 

Macro Definition Documentation

◆ BIG_NUMBER

#define BIG_NUMBER   100000

Definition at line 73 of file daidiplomacy.c.

◆ LOG_DIPL

#define LOG_DIPL   LOG_DEBUG

Definition at line 68 of file daidiplomacy.c.

◆ LOG_DIPL2

#define LOG_DIPL2   LOG_DEBUG

Definition at line 69 of file daidiplomacy.c.

◆ TURNS_BEFORE_TARGET

#define TURNS_BEFORE_TARGET   15

Definition at line 79 of file daidiplomacy.c.

Function Documentation

◆ clear_old_treaty()

static void clear_old_treaty ( struct player pplayer,
struct player aplayer 
)
static

Clear old clauses from the treaty between players

Definition at line 1232 of file daidiplomacy.c.

Referenced by dai_diplomacy_actions(), dai_diplomacy_first_contact(), and dai_share().

◆ compute_tech_sell_price()

static int compute_tech_sell_price ( struct ai_type ait,
struct player giver,
struct player taker,
int  tech_id,
bool is_dangerous 
)
static

Calculate a price of a tech. Note that both AI players always evaluate the tech worth symmetrically This eases tech exchange. is_dangerous returns ig the giver is afraid of giving that tech (the taker should evaluate it normally, but giver should never give that)

Definition at line 223 of file daidiplomacy.c.

Referenced by dai_goldequiv_clause(), and suggest_tech_exchange().

◆ dai_declare_war()

static void dai_declare_war ( struct ai_type ait,
struct player pplayer,
struct player target 
)
static

AI to declare war.

Parameters
aitAI type of the player declaring war
pplayerPlayer declaring war
targetPlayer to declare war to

Definition at line 1313 of file daidiplomacy.c.

Referenced by dai_go_to_war(), and dai_revolution_start().

◆ dai_diplo_notify()

static void dai_diplo_notify ( struct player pplayer,
const char text,
  ... 
)
static

Send a diplomatic message. Use this instead of notify directly because we may want to highligh/present these messages differently in the future.

Definition at line 103 of file daidiplomacy.c.

Referenced by dai_diplomacy_actions(), dai_diplomacy_first_contact(), dai_go_to_war(), dai_goldequiv_clause(), dai_incident_war(), dai_treaty_evaluate(), dai_treaty_react(), and war_countdown().

◆ dai_diplomacy_actions()

void dai_diplomacy_actions ( struct ai_type ait,
struct player pplayer 
)

Do diplomatic actions. Must be called only after calculate function above has been run for all AI players.

Only ever called for AI players.

Definition at line 1596 of file daidiplomacy.c.

Referenced by cai_diplomacy_actions(), and texwai_diplomacy_actions().

◆ dai_diplomacy_begin_new_phase()

void dai_diplomacy_begin_new_phase ( struct ai_type ait,
struct player pplayer 
)

Calculate our diplomatic predispositions here. Don't do anything.

Only ever called for AI players and never for barbarians.

This is called at the start of a new AI phase. It's not called when a game is loaded. So everything calculated here should be put into the savegame.

Definition at line 1018 of file daidiplomacy.c.

Referenced by dai_data_phase_begin().

◆ dai_diplomacy_first_contact()

void dai_diplomacy_first_contact ( struct ai_type ait,
struct player pplayer,
struct player aplayer 
)

What to do when we first meet. pplayer is the AI player.

Definition at line 964 of file daidiplomacy.c.

Referenced by cai_diplomacy_first_contact(), and texwai_diplomacy_first_contact().

◆ dai_diplomacy_suggest()

static void dai_diplomacy_suggest ( struct player pplayer,
struct player aplayer,
enum clause_type  what,
bool  to_pplayer,
int  value 
)
static

Suggest a treaty. pplayer is the (AI) player suggesting the treaty. If to_pplayer, then aplayer is giver in the clause, else pplayer is.

Definition at line 942 of file daidiplomacy.c.

Referenced by dai_diplomacy_actions(), dai_diplomacy_first_contact(), dai_share(), and suggest_tech_exchange().

◆ dai_go_to_war()

static void dai_go_to_war ( struct ai_type ait,
struct player pplayer,
struct player target,
enum war_reason  reason 
)
static

Go to war. Explain to target why we did it, and set countdown to some negative value to make us a bit stubborn to avoid immediate reversal to ceasefire.

Definition at line 1346 of file daidiplomacy.c.

Referenced by dai_diplomacy_actions().

◆ dai_goldequiv_clause()

static int dai_goldequiv_clause ( struct ai_type ait,
struct player pplayer,
struct player aplayer,
struct Clause pclause,
bool  verbose,
enum diplstate_type  ds_after 
)
static

Evaluate gold worth of a single clause in a treaty. Note that it sometimes matter a great deal who is giving what to whom, and sometimes (such as with treaties) it does not matter at all. ds_after means a pact offered in the same treaty or current diplomatic state

Definition at line 297 of file daidiplomacy.c.

Referenced by dai_diplomacy_actions(), dai_diplomacy_first_contact(), dai_treaty_accepted(), and dai_treaty_evaluate().

◆ dai_goldequiv_tech()

static int dai_goldequiv_tech ( struct ai_type ait,
struct player pplayer,
Tech_type_id  tech 
)
static

How much is a tech worth to player measured in gold

Definition at line 157 of file daidiplomacy.c.

Referenced by compute_tech_sell_price().

◆ dai_incident()

void dai_incident ( struct ai_type ait,
enum incident_type  type,
enum casus_belli_range  scope,
const struct action paction,
struct player receiver,
struct player violator,
struct player victim 
)

Handle incident caused by violator

Definition at line 1986 of file daidiplomacy.c.

Referenced by cai_incident(), and texwai_incident().

◆ dai_incident_nuclear()

static void dai_incident_nuclear ( struct player receiver,
const struct player violator,
const struct player victim 
)
static

Nuclear strike against victim.

Definition at line 2134 of file daidiplomacy.c.

Referenced by dai_incident().

◆ dai_incident_nuclear_not_target()

static void dai_incident_nuclear_not_target ( struct player receiver,
const struct player violator,
const struct player victim 
)
static

Nuclear strike against someone else.

Definition at line 2150 of file daidiplomacy.c.

Referenced by dai_incident().

◆ dai_incident_nuclear_self()

static void dai_incident_nuclear_self ( struct player receiver,
const struct player violator,
const struct player victim 
)
static

Somebody else than victim did nuclear strike against self.

Definition at line 2162 of file daidiplomacy.c.

Referenced by dai_incident().

◆ dai_incident_simple()

static void dai_incident_simple ( struct player receiver,
const struct player violator,
const struct player victim,
enum casus_belli_range  scope,
int  how_bad 
)
static

Called when someone caused an incident to make the receiver lose AI love. Make the victim angry at the violator. Twice as angry if this was bad enough to cause International Outrage. Make the rest of the world a bit angry if the violator did this to themself. Twice as angry if the violator did it to someone else.

Parameters
receiverthe player that receives information about the incident
violatorthe player that caused the incident
victimthe victim of the incident
scopethe range of the Casus Belli that caused this
how_bada badness score for the incident

Definition at line 2184 of file daidiplomacy.c.

Referenced by dai_incident().

◆ dai_incident_war()

static void dai_incident_war ( struct player violator,
struct player victim 
)
static

War declared against a player. We apply a penalty because this means they are seen as untrustworthy, especially if past relations with the victim have been cordial (betrayal).

Reasons for war and other mitigating circumstances are checked in calling code.

Definition at line 2213 of file daidiplomacy.c.

Referenced by dai_incident().

◆ dai_on_war_footing()

bool dai_on_war_footing ( struct ai_type ait,
struct player pplayer 
)

Are we going to be declaring war in a few turns time? If so, go on a war footing, and try to buy out as many units as possible.

Definition at line 1971 of file daidiplomacy.c.

Referenced by dai_city_choose_build(), dai_manage_cities(), dai_manage_taxes(), and dai_spend_gold().

◆ dai_players_can_agree_on_ceasefire()

static bool dai_players_can_agree_on_ceasefire ( struct ai_type ait,
struct player player1,
struct player player2 
)
static

Checks if player1 can agree on ceasefire with player2 This function should only be used for ai players

Definition at line 208 of file daidiplomacy.c.

Referenced by dai_goldequiv_clause().

◆ dai_revolution_start()

void dai_revolution_start ( struct ai_type ait,
struct player pplayer 
)

Revolution start callback for default AI.

Parameters
aitAI type of the player revolting
pplayerPlayer revolting

Definition at line 1445 of file daidiplomacy.c.

Referenced by cai_revolution_start(), and texwai_revolution_start().

◆ dai_share()

static void dai_share ( struct ai_type ait,
struct player pplayer,
struct player aplayer 
)
static

Offer techs and stuff to other player and ask for techs we need.

Definition at line 1253 of file daidiplomacy.c.

Referenced by dai_diplomacy_actions().

◆ dai_treaty_accepted()

void dai_treaty_accepted ( struct ai_type ait,
struct player pplayer,
struct player aplayer,
struct Treaty ptreaty 
)

This function is called when a treaty has been concluded, to deal with followup issues like comments and relationship (love) changes.

pplayer is AI player, aplayer is the other player involved, ptreaty is the treaty accepted.

Definition at line 744 of file daidiplomacy.c.

Referenced by cai_treaty_accepted(), and texwai_treaty_accepted().

◆ dai_treaty_evaluate()

void dai_treaty_evaluate ( struct ai_type ait,
struct player pplayer,
struct player aplayer,
struct Treaty ptreaty 
)

pplayer is AI player, aplayer is the other player involved, treaty is the treaty being considered. It is all a question about money :-)

Definition at line 624 of file daidiplomacy.c.

Referenced by cai_treaty_evaluate(), and texwai_treaty_evaluate().

◆ dai_treaty_react()

static void dai_treaty_react ( struct ai_type ait,
struct player pplayer,
struct player aplayer,
struct Clause pclause 
)
static

Comments to player from AI on clauses being agreed on. Does not alter any state.

Definition at line 701 of file daidiplomacy.c.

Referenced by dai_treaty_accepted().

◆ dai_war_desire()

static int dai_war_desire ( struct ai_type ait,
struct player pplayer,
struct player target 
)
static

Calculate our desire to go to war against aplayer. We want to attack a player that is easy to beat and will yield a nice profit.

This function is full of hardcoded constants by necessity. They are not macros since they are not used anywhere else.

Definition at line 803 of file daidiplomacy.c.

Referenced by dai_diplomacy_begin_new_phase().

◆ get_allied_with_enemy_player()

static const struct player * get_allied_with_enemy_player ( const struct player us,
const struct player them 
)
static

Returns an enemy player to 'us' allied with 'them' if there is one.

Definition at line 276 of file daidiplomacy.c.

Referenced by dai_goldequiv_clause().

◆ greed()

static int greed ( int  missing_love)
static

This is your typical human reaction. Convert lack of love into lust for gold.

Definition at line 124 of file daidiplomacy.c.

Referenced by dai_goldequiv_clause().

◆ pact_clause_to_diplstate_type()

static enum diplstate_type pact_clause_to_diplstate_type ( enum clause_type  type)
static

Convert clause into diplomatic state

Definition at line 139 of file daidiplomacy.c.

Referenced by dai_treaty_accepted(), and dai_treaty_evaluate().

◆ shared_vision_is_safe()

static bool shared_vision_is_safe ( struct player pplayer,
struct player aplayer 
)
static

Avoid giving pplayer's vision to non-allied player through aplayer (shared vision is transitive).

Definition at line 183 of file daidiplomacy.c.

Referenced by dai_diplomacy_actions(), dai_goldequiv_clause(), and dai_share().

◆ suggest_tech_exchange()

static void suggest_tech_exchange ( struct ai_type ait,
struct player player1,
struct player player2 
)
static

Find two techs that can be exchanged and suggest that

Definition at line 1159 of file daidiplomacy.c.

Referenced by dai_share().

◆ war_countdown()

static void war_countdown ( struct ai_type ait,
struct player pplayer,
struct player target,
int  countdown,
enum war_reason  reason 
)
static

Do diplomatic actions. Must be called only after calculate function above has been run for all AI players.

Only ever called for AI players and never for barbarians.

When the adip->coundown variable is set to a positive value, it counts down to a declaration of war. When it is set to a value smaller than -1, it is a countup towards a "neutral" stance of -1, in which time the AI will refuse to make treaties. This is to make the AI more stubborn.

Definition at line 1472 of file daidiplomacy.c.

Referenced by dai_diplomacy_actions().

Variable Documentation

◆ diplomacy_verbose

bool diplomacy_verbose = TRUE
static

Definition at line 76 of file daidiplomacy.c.

Referenced by dai_diplo_notify(), and dai_goldequiv_clause().