![]() |
Freeciv21
Develop your civilization from humble roots to a global empire
|
#include <cstdarg>#include <cstring>#include "fcintl.h"#include "log.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 "nation.h"#include "packets.h"#include "player.h"#include "research.h"#include "spaceship.h"#include "tech.h"#include "unitlist.h"#include "diplhand.h"#include "maphand.h"#include "notify.h"#include "advdata.h"#include "advtools.h"#include "aitraits.h"#include "handicaps.h"#include "aidata.h"#include "ailog.h"#include "aiplayer.h"#include "aitools.h"#include "aiunit.h"#include "daicity.h"#include "daidiplomacy.h"
Include dependency graph for daidiplomacy.cpp:Go to the source code of this file.
Macros | |
| #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) |
| War declared against a player. More... | |
| static void | dai_incident_simple (struct player *receiver, const struct player *violator, const struct player *victim, enum casus_belli_range scope, int how_bad) |
| Called when someone caused an incident to make the receiver lose AI love. More... | |
| static void | dai_incident_nuclear (struct player *receiver, const struct player *violator, const struct player *victim) |
| Nuclear strike against victim. More... | |
| static void | dai_incident_nuclear_not_target (struct player *receiver, const struct player *violator, const struct player *victim) |
| Nuclear strike against someone else. More... | |
| static void | dai_incident_nuclear_self (struct player *receiver, const struct player *violator, const struct player *victim) |
| Somebody else than victim did nuclear strike against self. More... | |
| static void | clear_old_treaty (struct player *pplayer, struct player *aplayer) |
| Clear old clauses from the treaty between players. More... | |
| static void | dai_diplo_notify (struct player *pplayer, const char *text,...) |
| Send a diplomatic message. More... | |
| static int | greed (int missing_love) |
| This is your typical human reaction. More... | |
| static enum diplstate_type | pact_clause_to_diplstate_type (enum clause_type type) |
| Convert clause into diplomatic state. More... | |
| static int | dai_goldequiv_tech (struct ai_type *ait, struct player *pplayer, Tech_type_id tech) |
| How much is a tech worth to player measured in gold. More... | |
| static bool | shared_vision_is_safe (struct player *pplayer, struct player *aplayer) |
| Avoid giving pplayer's vision to non-allied player through aplayer (shared vision is transitive). More... | |
| static bool | dai_players_can_agree_on_ceasefire (struct ai_type *ait, struct player *player1, struct player *player2) |
| Checks if player1 can agree on ceasefire with player2 This function should only be used for ai players. More... | |
| static int | compute_tech_sell_price (struct ai_type *ait, struct player *giver, struct player *taker, int tech_id, bool *is_dangerous) |
| Calculate a price of a tech. More... | |
| static const struct player * | get_allied_with_enemy_player (const struct player *us, const struct player *them) |
| Returns an enemy player to 'us' allied with 'them' if there is one. More... | |
| 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) |
| Evaluate gold worth of a single clause in a treaty. More... | |
| 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. More... | |
| static void | dai_treaty_react (struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Clause *pclause) |
| Comments to player from AI on clauses being agreed on. More... | |
| 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. More... | |
| static int | dai_war_desire (struct ai_type *ait, struct player *pplayer, struct player *target) |
| Calculate our desire to go to war against aplayer. More... | |
| static void | dai_diplomacy_suggest (struct player *pplayer, struct player *aplayer, enum clause_type what, bool to_pplayer, int value) |
| Suggest a treaty. More... | |
| void | dai_diplomacy_first_contact (struct ai_type *ait, struct player *pplayer, struct player *aplayer) |
| What to do when we first meet. More... | |
| void | dai_diplomacy_begin_new_phase (struct ai_type *ait, struct player *pplayer) |
| Calculate our diplomatic predispositions here. More... | |
| static void | suggest_tech_exchange (struct ai_type *ait, struct player *player1, struct player *player2) |
| Find two techs that can be exchanged and suggest that. More... | |
| static void | dai_share (struct ai_type *ait, struct player *pplayer, struct player *aplayer) |
| Offer techs and stuff to other player and ask for techs we need. More... | |
| static void | dai_go_to_war (struct ai_type *ait, struct player *pplayer, struct player *target, enum war_reason reason) |
| Go to war. More... | |
| static void | war_countdown (struct ai_type *ait, struct player *pplayer, struct player *target, int countdown, enum war_reason reason) |
| Do diplomatic actions. More... | |
| void | dai_diplomacy_actions (struct ai_type *ait, struct player *pplayer) |
| Do diplomatic actions. More... | |
| 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. More... | |
| 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. More... | |
Variables | |
| static bool | diplomacy_verbose = true |
| #define BIG_NUMBER 100000 |
Definition at line 63 of file daidiplomacy.cpp.
| #define LOG_DIPL2 LOG_DEBUG |
Definition at line 59 of file daidiplomacy.cpp.
| #define TURNS_BEFORE_TARGET 15 |
Definition at line 69 of file daidiplomacy.cpp.
Clear old clauses from the treaty between players.
Definition at line 1241 of file daidiplomacy.cpp.
Referenced by dai_diplomacy_actions(), dai_diplomacy_first_contact(), and dai_share().
|
static |
Calculate a price of a tech.
Note that both AI players always evaluate the tech worth symetrically 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 217 of file daidiplomacy.cpp.
Referenced by dai_goldequiv_clause(), and suggest_tech_exchange().
|
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 92 of file daidiplomacy.cpp.
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().
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 1547 of file daidiplomacy.cpp.
Referenced by cai_diplomacy_actions(), texwai_diplomacy_actions(), and twai_diplomacy_actions().
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 1010 of file daidiplomacy.cpp.
Referenced by dai_data_phase_begin().
| 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 957 of file daidiplomacy.cpp.
Referenced by cai_diplomacy_first_contact(), texwai_diplomacy_first_contact(), and twai_diplomacy_first_contact().
|
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 937 of file daidiplomacy.cpp.
Referenced by dai_diplomacy_actions(), dai_diplomacy_first_contact(), dai_share(), and suggest_tech_exchange().
|
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 1319 of file daidiplomacy.cpp.
Referenced by dai_diplomacy_actions().
|
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 291 of file daidiplomacy.cpp.
Referenced by dai_diplomacy_actions(), dai_diplomacy_first_contact(), dai_treaty_accepted(), and dai_treaty_evaluate().
|
static |
How much is a tech worth to player measured in gold.
Definition at line 148 of file daidiplomacy.cpp.
Referenced by compute_tech_sell_price().
| 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 1958 of file daidiplomacy.cpp.
Referenced by cai_incident(), texwai_incident(), and twai_incident().
|
static |
Nuclear strike against victim.
Definition at line 2092 of file daidiplomacy.cpp.
Referenced by dai_incident().
|
static |
Nuclear strike against someone else.
Definition at line 2108 of file daidiplomacy.cpp.
Referenced by dai_incident().
|
static |
Somebody else than victim did nuclear strike against self.
Definition at line 2120 of file daidiplomacy.cpp.
Referenced by dai_incident().
|
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 him self. Twice as angry if the violator did it to someone else.
| receiver | the player that receives information about the incident |
| violator | the player that caused the incident |
| victim | the victim of the incident |
| scope | the range of the Casus Belli that caused this |
| how_bad | a badness score for the incident |
Definition at line 2142 of file daidiplomacy.cpp.
Referenced by dai_incident().
War declared against a player.
We apply a penalty because this means he is 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 2170 of file daidiplomacy.cpp.
Referenced by dai_incident().
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 1941 of file daidiplomacy.cpp.
Referenced by dai_city_choose_build(), dai_manage_cities(), dai_manage_taxes(), and dai_spend_gold().
|
static |
Checks if player1 can agree on ceasefire with player2 This function should only be used for ai players.
Definition at line 201 of file daidiplomacy.cpp.
Referenced by dai_goldequiv_clause().
|
static |
Offer techs and stuff to other player and ask for techs we need.
Definition at line 1263 of file daidiplomacy.cpp.
Referenced by dai_diplomacy_actions().
| 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 720 of file daidiplomacy.cpp.
Referenced by cai_treaty_accepted(), texwai_treaty_accepted(), and twai_treaty_accepted().
| 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 598 of file daidiplomacy.cpp.
Referenced by cai_treaty_evaluate(), texwai_treaty_evaluate(), and twai_treaty_evaluate().
|
static |
Comments to player from AI on clauses being agreed on.
Does not alter any state.
Definition at line 680 of file daidiplomacy.cpp.
Referenced by dai_treaty_accepted().
|
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 #defines since they are not used anywhere else.
Definition at line 784 of file daidiplomacy.cpp.
Referenced by dai_diplomacy_begin_new_phase().
|
static |
Returns an enemy player to 'us' allied with 'them' if there is one.
Definition at line 270 of file daidiplomacy.cpp.
Referenced by dai_goldequiv_clause().
|
static |
This is your typical human reaction.
Convert lack of love into lust for gold.
Definition at line 114 of file daidiplomacy.cpp.
Referenced by dai_goldequiv_clause().
|
static |
Convert clause into diplomatic state.
Definition at line 114 of file daidiplomacy.cpp.
Referenced by dai_treaty_accepted(), and dai_treaty_evaluate().
Avoid giving pplayer's vision to non-allied player through aplayer (shared vision is transitive).
Definition at line 174 of file daidiplomacy.cpp.
Referenced by dai_diplomacy_actions(), dai_goldequiv_clause(), and dai_share().
|
static |
Find two techs that can be exchanged and suggest that.
Definition at line 1163 of file daidiplomacy.cpp.
Referenced by dai_share().
|
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 1426 of file daidiplomacy.cpp.
Referenced by dai_diplomacy_actions().
|
static |
Definition at line 66 of file daidiplomacy.cpp.
Referenced by dai_diplo_notify(), and dai_goldequiv_clause().