Freeciv-3.2: /fast/freeciv/nightly/S3_2/ai/default/daidiplomacy.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
daidiplomacy.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdarg.h>
19#include <string.h>
20
21/* utility */
22#include "fcintl.h"
23#include "log.h"
24#include "mem.h"
25#include "rand.h"
26#include "shared.h"
27#include "support.h"
28
29/* common */
30#include "aisupport.h"
31#include "city.h"
32#include "diptreaty.h"
33#include "events.h"
34#include "game.h"
35#include "packets.h"
36#include "player.h"
37#include "nation.h"
38#include "research.h"
39#include "spaceship.h"
40#include "tech.h"
41#include "unitlist.h"
42
43/* server */
44#include "citytools.h"
45#include "diplhand.h"
46#include "maphand.h"
47#include "notify.h"
48#include "srv_log.h"
49
50/* server/advisors */
51#include "advdata.h"
52#include "advtools.h"
53
54/* ai */
55#include "aitraits.h"
56#include "handicaps.h"
57
58/* ai/default */
59#include "aitools.h"
60#include "daicity.h"
61#include "daidata.h"
62#include "dailog.h"
63#include "daimilitary.h"
64#include "daiplayer.h"
65
66#include "daidiplomacy.h"
67
68#define LOG_DIPL LOG_DEBUG
69#define LOG_DIPL2 LOG_DEBUG
70
71/* One hundred thousand. Basically a number of gold that no player is
72 * ever likely to have, but not so big that we get integer overflows. */
73#define BIG_NUMBER 100000
74
75/* turn this off when we don't want functions to message players */
76 static bool diplomacy_verbose = TRUE;
77
78/* turns to wait after contact before taking aim for war */
79#define TURNS_BEFORE_TARGET 15
80
81static void dai_incident_war(struct player *violator, struct player *victim);
82static void dai_incident_simple(struct player *receiver,
83 const struct player *violator,
84 const struct player *victim,
85 enum casus_belli_range scope,
86 int how_bad);
87static void dai_incident_nuclear(struct player *receiver,
88 const struct player *violator,
89 const struct player *victim);
90static void dai_incident_nuclear_not_target(struct player *receiver,
91 const struct player *violator,
92 const struct player *victim);
93static void dai_incident_nuclear_self(struct player *receiver,
94 const struct player *violator,
95 const struct player *victim);
96static void clear_old_treaty(struct player *pplayer, struct player *aplayer);
97
98/******************************************************************/
103 static void dai_diplo_notify(struct player *pplayer, const char *text, ...)
104{
105 if (diplomacy_verbose) {
106 va_list ap;
107 struct conn_list *dest = pplayer->connections;
108 struct packet_chat_msg packet;
109
110 va_start(ap, text);
111 vpackage_event(&packet, NULL, E_DIPLOMACY, ftc_chat_private, text, ap);
112 va_end(ap);
113
114 lsend_packet_chat_msg(dest, &packet);
115 /* Add to the event cache. */
116 event_cache_add_for_player(&packet, pplayer);
117 }
118}
119
120/******************************************************************/
124 static int greed(int missing_love)
125{
126 if (missing_love > 0) {
127 return 0;
128 } else {
129 /* Don't change the operation order here.
130 * We do not want integer overflows */
131 return -((missing_love * MAX_AI_LOVE) / 1000) *
132 ((missing_love * MAX_AI_LOVE) / 1000) / 10;
133 }
134}
135
136/******************************************************************/
139 static enum diplstate_type pact_clause_to_diplstate_type(enum clause_type type)
140{
141 switch (type) {
142 case CLAUSE_ALLIANCE:
143 return DS_ALLIANCE;
144 case CLAUSE_PEACE:
145 return DS_PEACE;
146 case CLAUSE_CEASEFIRE:
147 return DS_CEASEFIRE;
148 default:
149 log_error("Invalid diplomatic clause %d.", type)
150 return DS_WAR;
151 }
152}
153
154/******************************************************************/
157 static int dai_goldequiv_tech(struct ai_type *ait,
158 struct player *pplayer, Tech_type_id tech)
159{
160 int bulbs, tech_want, worth;
161 struct research *presearch = research_get(pplayer);
162 enum tech_state state = research_invention_state(presearch, tech);
163 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
164
165 if (TECH_KNOWN == state
166 || !research_invention_gettable(presearch, tech,
167 game.info.tech_trade_allow_holes)) {
168 return 0;
169 }
170 bulbs = research_goal_bulbs_required(presearch, tech) * 3;
171 tech_want = MAX(plr_data->tech_want[tech], 0) / MAX(game.info.turn, 1);
172 worth = bulbs + tech_want;
173 if (TECH_PREREQS_KNOWN == state) {
174 worth /= 2;
175 }
176 return worth;
177}
178
179/******************************************************************/
183 static bool shared_vision_is_safe(struct player* pplayer,
184 struct player* aplayer)
185{
186 if (pplayer->team && pplayer->team == aplayer->team) {
187 return TRUE;
188 }
189 players_iterate_alive(eplayer) {
190 if (eplayer == pplayer || eplayer == aplayer) {
191 continue;
192 }
193 if (gives_shared_vision(aplayer, eplayer)) {
194 enum diplstate_type ds = player_diplstate_get(pplayer, eplayer)->type;
195
196 if (ds != DS_NO_CONTACT && ds != DS_ALLIANCE) {
197 return FALSE;
198 }
199 }
200 } players_iterate_alive_end;
201 return TRUE;
202}
203
204/******************************************************************/
208 static bool dai_players_can_agree_on_ceasefire(struct ai_type *ait,
209 struct player* player1,
210 struct player* player2)
211{
212 return (player1->ai_common.love[player_index(player2)] > - (MAX_AI_LOVE * 4 / 10)
213 && dai_diplomacy_get(ait, player1, player2)->countdown == -1);
214}
215
216/******************************************************************/
223 static int compute_tech_sell_price(struct ai_type *ait,
224 struct player *giver, struct player *taker,
225 int tech_id, bool *is_dangerous)
226{
227 int worth;
228
229 worth = dai_goldequiv_tech(ait, taker, tech_id);
230
231 *is_dangerous = FALSE;
232
233 /* Share and expect being shared brotherly between allies */
234 if (pplayers_allied(giver, taker)) {
235 worth /= 2;
236 }
237 if (players_on_same_team(giver, taker)) {
238 return 0;
239 }
240
241 /* Do not bother wanting a tech that we already have. */
242 if (research_invention_state(research_get(taker), tech_id)
243 == TECH_KNOWN) {
244 return 0;
245 }
246
247 /* Calculate in tech leak to our opponents, guess 50% chance */
248 players_iterate_alive(eplayer) {
249 if (eplayer == giver
250 || eplayer == taker
251 || research_invention_state(research_get(eplayer),
252 tech_id) == TECH_KNOWN) {
253 continue;
254 }
255
256 /* Don't risk it falling into enemy hands */
257 if (pplayers_allied(taker, eplayer)
258 && adv_is_player_dangerous(giver, eplayer)) {
259 *is_dangerous = TRUE;
260 }
261
262 if (pplayers_allied(taker, eplayer)
263 && !pplayers_allied(giver, eplayer)) {
264 /* Taker can enrich their side with this tech */
265 worth += dai_goldequiv_tech(ait, eplayer, tech_id) / 4;
266 }
267 } players_iterate_alive_end;
268
269 return worth;
270}
271
272/******************************************************************/
275static const struct player *
276get_allied_with_enemy_player(const struct player *us,
277 const struct player *them)
278{
279 players_iterate_alive(aplayer) {
280 if (aplayer != us
281 && aplayer != them
282 && pplayers_allied(them, aplayer)
283 && player_diplstate_get(us, aplayer)->type == DS_WAR) {
284 return aplayer;
285 }
286 } players_iterate_alive_end;
287 return NULL;
288}
289
290/******************************************************************/
297 static int dai_goldequiv_clause(struct ai_type *ait,
298 struct player *pplayer,
299 struct player *aplayer,
300 struct Clause *pclause,
301 bool verbose,
302 enum diplstate_type ds_after)
303{
304 bool close_here;
305 struct ai_plr *ai;
306 int worth = 0; /* worth for pplayer of what aplayer gives */
307 bool give = (pplayer == pclause->from);
308 struct player *giver;
309 const struct player *penemy;
310 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
311 bool is_dangerous;
312
313 ai = dai_plr_data_get(ait, pplayer, &close_here);
314
315 fc_assert_ret_val(pplayer != aplayer, 0);
316
317 diplomacy_verbose = verbose;
318 ds_after = MAX(ds_after, player_diplstate_get(pplayer, aplayer)->type);
319 giver = pclause->from;
320
321 switch (pclause->type) {
322 case CLAUSE_ADVANCE:
323 if (give) {
324 worth -= compute_tech_sell_price(ait, pplayer, aplayer, pclause->value,
325 &is_dangerous);
326 if (is_dangerous) {
327 worth = -BIG_NUMBER;
328 }
329 } else if (research_invention_state(research_get(pplayer),
330 pclause->value) != TECH_KNOWN) {
331 worth += compute_tech_sell_price(ait, aplayer, pplayer, pclause->value,
332 &is_dangerous);
333
334 if (game.info.tech_upkeep_style != TECH_UPKEEP_NONE) {
335 /* Consider the upkeep costs! Thus, one can not get an AI player by
336 * - given AI lots of techs for gold/cities etc.
337 * - AI losses tech due to high upkeep.
338 * FIXME: Is there a better way for this? */
339 struct research *research = research_get(pplayer);
340 int limit;
341
342 /* Make sure there's no division by zero */
343 if (research->techs_researched > 0) {
344 int upk_per_tech = player_tech_upkeep(pplayer)
345 / research->techs_researched;
346
347 limit = MAX(1, upk_per_tech);
348 } else {
349 limit = 1;
350 fc_assert(player_tech_upkeep(pplayer) == 0);
351 }
352
353 if (pplayer->server.bulbs_last_turn < limit) {
354 worth /= 2;
355 }
356 }
357 }
358 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "%s clause worth %d",
359 advance_rule_name(advance_by_number(pclause->value)), worth);
360 break;
361
362 case CLAUSE_ALLIANCE:
363 case CLAUSE_PEACE:
364 case CLAUSE_CEASEFIRE:
365 /* Don't do anything in away mode */
366 if (has_handicap(pplayer, H_AWAY)) {
367 dai_diplo_notify(aplayer, _("*%s (AI)* In away mode AI can't sign such a treaty."),
368 player_name(pplayer));
369 worth = -BIG_NUMBER;
370 break;
371 }
372
373 /* This guy is allied to one of our enemies. Only accept
374 * ceasefire. */
375 if ((penemy = get_allied_with_enemy_player(pplayer, aplayer))
376 && pclause->type != CLAUSE_CEASEFIRE) {
377 dai_diplo_notify(aplayer, _("*%s (AI)* First break alliance with %s, %s."),
378 player_name(pplayer), player_name(penemy),
379 player_name(aplayer));
380 worth = -BIG_NUMBER;
381 break;
382 }
383
384 /* They were allied with an enemy at the begining of the turn. */
385 if (adip->is_allied_with_enemy
386 && pclause->type != CLAUSE_CEASEFIRE) {
387 dai_diplo_notify(aplayer, _("*%s (AI)* I would like to see you keep your "
388 "distance from %s for some time, %s."),
389 player_name(pplayer), player_name(adip->is_allied_with_enemy),
390 player_name(aplayer));
391 worth = -BIG_NUMBER;
392 break;
393 }
394
395 /* Steps of the treaty ladder */
396 if (pclause->type == CLAUSE_PEACE) {
397 const struct player_diplstate *ds
398 = player_diplstate_get(pplayer, aplayer);
399
400 if (!pplayers_non_attack(pplayer, aplayer)) {
401 dai_diplo_notify(aplayer, _("*%s (AI)* Let us first cease hostilities, %s."),
402 player_name(pplayer),
403 player_name(aplayer));
404 worth = -BIG_NUMBER;
405 } else if (ds->type == DS_CEASEFIRE && ds->turns_left > 4) {
406 dai_diplo_notify(aplayer, _("*%s (AI)* I wish to see you keep the current "
407 "ceasefire for a bit longer first, %s."),
408 player_name(pplayer),
409 player_name(aplayer));
410 worth = -BIG_NUMBER;
411 } else if (adip->countdown >= 0 || adip->countdown < -1) {
412 worth = -BIG_NUMBER; /* but say nothing */
413 } else {
414 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
415 - ai->diplomacy.req_love_for_peace);
416 }
417 } else if (pclause->type == CLAUSE_ALLIANCE) {
418 if (!pplayers_in_peace(pplayer, aplayer)) {
419 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
420 - ai->diplomacy.req_love_for_peace);
421 }
422 if (adip->countdown >= 0 || adip->countdown < -1) {
423 worth = -BIG_NUMBER; /* but say nothing */
424 } else {
425 worth += greed(pplayer->ai_common.love[player_index(aplayer)]
426 - ai->diplomacy.req_love_for_alliance);
427 }
428 if (pplayer->ai_common.love[player_index(aplayer)] < MAX_AI_LOVE / 10) {
429 dai_diplo_notify(aplayer, _("*%s (AI)* I simply do not trust you with an "
430 "alliance yet, %s."),
431 player_name(pplayer),
432 player_name(aplayer));
433 worth = -BIG_NUMBER;
434 }
435 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ally clause worth %d", worth);
436 } else {
437 if (is_ai(pplayer) && is_ai(aplayer)
438 && dai_players_can_agree_on_ceasefire(ait, pplayer, aplayer)) {
439 worth = 0;
440 } else {
441 int turns = game.info.turn;
442
443 turns -= player_diplstate_get(pplayer, aplayer)->first_contact_turn;
444 if (turns < TURNS_BEFORE_TARGET) {
445 worth = 0; /* show some good faith */
446 break;
447 } else {
448 worth = greed(pplayer->ai_common.love[player_index(aplayer)]);
449 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ceasefire worth=%d love=%d "
450 "turns=%d", worth,
451 pplayer->ai_common.love[player_index(aplayer)],
452 turns);
453 }
454 }
455 }
456
457 /* Let's all hold hands in one happy family! */
458 if (adip->is_allied_with_ally) {
459 worth /= 2;
460 break;
461 }
462
463 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "treaty clause worth %d", worth);
464 break;
465
466 case CLAUSE_GOLD:
467 if (give) {
468 worth -= pclause->value;
469 } else {
470 worth += pclause->value * (100 - game.server.diplgoldcost) / 100;
471 }
472 break;
473
474 case CLAUSE_SEAMAP:
475 if (!give || ds_after == DS_ALLIANCE) {
476 /* Useless to us - we're omniscient! And allies get it for free! */
477 worth = 0;
478 } else {
479 /* Very silly algorithm 1: Sea map more worth if enemy has more
480 cities. Reasoning is they have more use of seamap for settling
481 new areas the more cities they have already. */
482 worth -= 15 * city_list_size(aplayer->cities);
483 /* Don't like them? Don't give it to them! */
484 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 7, worth);
485 /* Make maps from novice player cheap */
486 if (has_handicap(pplayer, H_DIPLOMACY)) {
487 worth /= 2;
488 }
489 }
490 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "seamap clause worth %d",
491 worth);
492 break;
493
494 case CLAUSE_MAP:
495 if (!give || ds_after == DS_ALLIANCE) {
496 /* Useless to us - we're omniscient! And allies get it for free! */
497 worth = 0;
498 } else {
499 /* Very silly algorithm 2: Land map more worth the more cities
500 we have, since we expose all of these to the enemy. */
501 worth -= 40 * MAX(city_list_size(pplayer->cities), 1);
502 /* Inflate numbers if not peace */
503 if (!pplayers_in_peace(pplayer, aplayer)) {
504 worth *= 2;
505 }
506 /* Don't like them? Don't give it to them! */
507 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 10, worth);
508 /* Make maps from novice player cheap */
509 if (has_handicap(pplayer, H_DIPLOMACY)) {
510 worth /= 6;
511 }
512 }
513 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "landmap clause worth %d",
514 worth);
515 break;
516
517 case CLAUSE_CITY: {
518 struct city *offer = city_list_find_number(pclause->from->cities,
519 pclause->value);
520
521 if (!offer || city_owner(offer) != giver) {
522 /* City destroyed or taken during negotiations */
523 dai_diplo_notify(aplayer, _("*%s (AI)* I do not know the city you mention."),
524 player_name(pplayer));
525 worth = 0;
526 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "city destroyed during negotiations");
527 } else if (give) {
528 /* AI must be crazy to trade away its cities */
529 worth -= city_gold_worth(offer);
530 if (is_capital(offer)) {
531 worth = -BIG_NUMBER; /* Never! Ever! */
532 } else {
533 worth *= 15;
534 }
535 if (aplayer == offer->original) {
536 /* Let them buy back their own city cheaper. */
537 worth /= 2;
538 }
539 } else {
540 worth = city_gold_worth(offer);
541 }
542 if (offer != NULL) {
543 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "worth of %s is %d",
544 city_name_get(offer), worth);
545 }
546 break;
547 }
548
549 case CLAUSE_VISION:
550 if (give) {
551 if (ds_after == DS_ALLIANCE) {
552 if (!shared_vision_is_safe(pplayer, aplayer)) {
553 dai_diplo_notify(aplayer,
554 _("*%s (AI)* Sorry, sharing vision with you "
555 "is not safe."),
556 player_name(pplayer));
557 worth = -BIG_NUMBER;
558 } else {
559 worth = 0;
560 }
561 } else {
562 /* so out of the question */
563 worth = -BIG_NUMBER;
564 }
565 } else {
566 worth = 0; /* We are omniscient, so... */
567 }
568 break;
569
570 case CLAUSE_EMBASSY:
571 if (give) {
572 if (ds_after == DS_ALLIANCE) {
573 worth = 0;
574 } else if (ds_after == DS_PEACE) {
575 worth = -5 * game.info.turn;
576 } else {
577 worth = MIN(-50 * game.info.turn
578 + pplayer->ai_common.love[player_index(aplayer)],
579 -5 * game.info.turn);
580 }
581 } else if (game.info.tech_leakage == TECH_LEAKAGE_EMBASSIES) {
582 worth = game.info.tech_leak_pct / 10;
583 } else {
584 worth = 0; /* We don't need no stinkin' embassy, do we? */
585 }
586 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "embassy clause worth %d",
587 worth);
588 break;
589 case CLAUSE_SHARED_TILES:
590 if (give) {
591 if (ds_after == DS_ALLIANCE) {
592 worth = 0;
593 } else {
594 /* Here we assume that number of cities correlate with number of tiles. */
595 worth = -3 * (city_list_size(pplayer->cities) + 1);
596 }
597 } else {
598 int cities = city_list_size(aplayer->cities);
599
600 worth = MIN(cities, 3);
601 }
602 break;
603 case CLAUSE_COUNT:
604 fc_assert(pclause->type != CLAUSE_COUNT);
605 break;
606 } /* end of switch */
607
608 if (close_here) {
609 dai_data_phase_finished(ait, pplayer);
610 }
611
612 diplomacy_verbose = TRUE;
613 return worth;
614}
615
616/******************************************************************/
620 void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer,
621 struct player *aplayer, struct Treaty *ptreaty)
622{
623 int total_balance = 0;
624 bool only_gifts = TRUE;
625 enum diplstate_type ds_after =
626 player_diplstate_get(pplayer, aplayer)->type;
627 int given_cities = 0;
628
629 clause_list_iterate(ptreaty->clauses, pclause) {
630 if (is_pact_clause(pclause->type)) {
631 ds_after = pact_clause_to_diplstate_type(pclause->type);
632 }
633 if (pclause->type == CLAUSE_CITY && pclause->from == pplayer) {
634 given_cities++;
635 }
636 } clause_list_iterate_end;
637
638 /* Evaluate clauses */
639 clause_list_iterate(ptreaty->clauses, pclause) {
640 const struct research *presearch = research_get(pplayer);
641
642 total_balance +=
643 dai_goldequiv_clause(ait, pplayer, aplayer, pclause, TRUE, ds_after);
644
645 if (pclause->type != CLAUSE_GOLD && pclause->type != CLAUSE_MAP
646 && pclause->type != CLAUSE_SEAMAP && pclause->type != CLAUSE_VISION
647 && (pclause->type != CLAUSE_ADVANCE
648 || game.info.tech_cost_style != TECH_COST_CIV1CIV2
649 || pclause->value == research_get(pplayer)->tech_goal
650 || pclause->value == research_get(pplayer)->researching
651 || research_goal_tech_req(presearch, presearch->tech_goal,
652 pclause->value))) {
653 /* We accept the above list of clauses as gifts, even if we are
654 * at war. We do not accept tech or cities since these can be used
655 * against us, unless we know that we want this tech anyway, or
656 * it doesn't matter due to tech cost style. */
657 only_gifts = FALSE;
658 }
659 } clause_list_iterate_end;
660
661 /* If we are at war, and no peace is offered, then no deal, unless
662 * it is just gifts, in which case we gratefully accept. */
663 if (ds_after == DS_WAR && !only_gifts) {
664 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "no peace offered, must refuse");
665 return;
666 }
667
668 if (given_cities > 0
669 && city_list_size(pplayer->cities) - given_cities <= 2) {
670 /* always keep at least two cities */
671 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "cannot give last cities");
672 return;
673 }
674
675 /* Accept if balance is good */
676 if (total_balance >= 0) {
677 handle_diplomacy_accept_treaty_req(pplayer, player_number(aplayer));
678 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was good: %d",
679 total_balance);
680 } else {
681 /* AI complains about the treaty which was proposed, unless the AI
682 * made the proposal. */
683 if (pplayer != ptreaty->plr0) {
684 dai_diplo_notify(aplayer, _("*%s (AI)* This deal was not very good for us, %s!"),
685 player_name(pplayer),
686 player_name(aplayer));
687 }
688 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was bad: %d",
689 total_balance);
690 }
691}
692
693/******************************************************************/
697 static void dai_treaty_react(struct ai_type *ait,
698 struct player *pplayer,
699 struct player *aplayer,
700 struct Clause *pclause)
701{
702 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
703
704 switch (pclause->type) {
705 case CLAUSE_ALLIANCE:
706 if (adip->is_allied_with_ally) {
707 dai_diplo_notify(aplayer, _("*%s (AI)* Welcome into our alliance %s!"),
708 player_name(pplayer),
709 player_name(aplayer));
710 } else {
711 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, may we forever stand united, %s."),
712 player_name(pplayer),
713 player_name(aplayer));
714 }
715 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "become allies");
716 break;
717 case CLAUSE_PEACE:
718 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, peace in our time!"),
719 player_name(pplayer));
720 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign peace treaty");
721 break;
722 case CLAUSE_CEASEFIRE:
723 dai_diplo_notify(aplayer, _("*%s (AI)* Agreed. No more hostilities, %s."),
724 player_name(pplayer),
725 player_name(aplayer));
726 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign ceasefire");
727 break;
728 default:
729 break;
730 }
731}
732
733/******************************************************************/
740 void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer,
741 struct player *aplayer, struct Treaty *ptreaty)
742{
743 bool close_here;
744 struct ai_plr *ai;
745 int total_balance = 0;
746 bool gift = TRUE;
747 enum diplstate_type ds_after =
748 player_diplstate_get(pplayer, aplayer)->type;
749
750 ai = dai_plr_data_get(ait, pplayer, &close_here);
751
752 fc_assert_ret(pplayer != aplayer);
753
754 clause_list_iterate(ptreaty->clauses, pclause) {
755 if (is_pact_clause(pclause->type)) {
756 ds_after = pact_clause_to_diplstate_type(pclause->type);
757 }
758 } clause_list_iterate_end;
759
760 /* Evaluate clauses */
761 clause_list_iterate(ptreaty->clauses, pclause) {
762 int balance =
763 dai_goldequiv_clause(ait, pplayer, aplayer, pclause, TRUE, ds_after);
764
765 total_balance += balance;
766 gift = (gift && (balance >= 0));
767 dai_treaty_react(ait, pplayer, aplayer, pclause);
768 if (is_pact_clause(pclause->type)
769 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown != -1) {
770 /* Cancel a countdown towards war if we just agreed to peace... */
771 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "countdown nullified");
772 dai_diplomacy_get(ait, pplayer, aplayer)->countdown = -1;
773 }
774 } clause_list_iterate_end;
775
776 /* Rather arbitrary algorithm to increase our love for a player if
777 * they offer us gifts. It is only a gift if _all_ the clauses
778 * are beneficial to us. */
779 if (total_balance > 0 && gift) {
780 int i = total_balance / ((city_list_size(pplayer->cities) * 10) + 1);
781
782 i = MIN(i, ai->diplomacy.love_incr * 150) * 10;
783 pplayer->ai_common.love[player_index(aplayer)] += i;
784 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "gift increased love by %d", i);
785 }
786
787 if (close_here) {
788 dai_data_phase_finished(ait, pplayer);
789 }
790}
791
792/******************************************************************/
799 static int dai_war_desire(struct ai_type *ait, struct player *pplayer,
800 struct player *target)
801{
802 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
803 struct adv_data *adv = adv_data_get(pplayer, NULL);
804 int want = 0, fear = 0, distance = 0, settlers = 0, cities = 0;
805 struct player_spaceship *ship = &target->spaceship;
806
807 city_list_iterate(target->cities, pcity) {
808 want += 100; /* base city want */
809 want += city_size_get(pcity) * 20;
810 want += pcity->surplus[O_SHIELD] * 8;
811 want += pcity->surplus[O_TRADE] * 6;
812
813 /* FIXME: This might be buggy if it ignores unmet UnitClass reqs. */
814 fear += get_city_bonus(pcity, EFT_DEFEND_BONUS);
815
816 city_built_iterate(pcity, pimprove) {
817 int cost = impr_build_shield_cost(pcity, pimprove);
818
819 want += cost;
820 if (improvement_obsolete(pplayer, pimprove, pcity)) {
821 continue;
822 }
823 if (is_great_wonder(pimprove)) {
824 want += cost * 2;
825 } else if (is_small_wonder(pimprove)) {
826 want += cost;
827 }
828 } city_built_iterate_end;
829 } city_list_iterate_end;
830 unit_list_iterate(target->units, punit) {
831 const struct unit_type *ptype = unit_type_get(punit);
832
833 fear += ATTACK_POWER(ptype);
834
835 /* Fear enemy expansionism */
836 if (unit_is_cityfounder(punit)) {
837 want += 100;
838 }
839 } unit_list_iterate_end;
840 unit_list_iterate(pplayer->units, punit) {
841 const struct unit_type *ptype = unit_type_get(punit);
842
843 fear -= ATTACK_POWER(ptype) / 2;
844
845 /* Our own expansionism reduces want for war */
846 if (unit_is_cityfounder(punit)) {
847 want -= 200;
848 settlers++;
849 }
850 } unit_list_iterate_end;
851 city_list_iterate(pplayer->cities, pcity) {
852 if (VUT_UTYPE == pcity->production.kind
853 && utype_is_cityfounder(pcity->production.value.utype)) {
854 want -= 150;
855 settlers++;
856 }
857 cities++;
858 } city_list_iterate_end;
859
860 /* Modify by settler/cities ratio to prevent early wars when
861 * we should be expanding. This will eliminate want if we
862 * produce settlers in all cities (ie full expansion). */
863 want -= abs(want) / MAX(cities - settlers, 1);
864
865 /* Calculate average distances to other player's empire. */
866 distance = player_distance_to_player(pplayer, target);
867 dai_diplomacy_get(ait, pplayer, target)->distance = distance;
868
869 /* Worry a bit if the other player has extreme amounts of wealth
870 * that can be used in cities to quickly buy an army. */
871 fear += (target->economic.gold / 5000) * city_list_size(target->cities);
872
873 /* Tech lead is worrisome. FIXME: Only consider 'military' techs. */
874 fear += MAX(research_get(target)->techs_researched
875 - research_get(pplayer)->techs_researched, 0) * 100;
876
877 /* Spacerace loss we will not allow! */
878 if (ship->state >= SSHIP_STARTED) {
879 want *= 2;
880 }
881 if (adv->dipl.spacerace_leader == target) {
882 ai->diplomacy.strategy = WIN_CAPITAL;
883 return BIG_NUMBER; /* do NOT amortize this number! */
884 }
885
886 /* Modify by which treaties we would break to other players, and what
887 * excuses we have to do so. FIXME: We only consider immediate
888 * allies, but we might trigger a wider chain reaction. */
889 players_iterate_alive(eplayer) {
890 bool cancel_excuse =
891 player_diplstate_get(pplayer, eplayer)->has_reason_to_cancel != 0;
892 enum diplstate_type ds = player_diplstate_get(pplayer, eplayer)->type;
893
894 if (eplayer == pplayer) {
895 continue;
896 }
897
898 /* Remember: pplayers_allied() returns true when target == eplayer */
899 if (!cancel_excuse && pplayers_allied(target, eplayer)) {
900 if (ds == DS_ARMISTICE) {
901 want -= abs(want) / 10; /* 10% off */
902 } else if (ds == DS_CEASEFIRE) {
903 want -= abs(want) / 7; /* 15% off */
904 } else if (ds == DS_PEACE) {
905 want -= abs(want) / 5; /* 20% off */
906 } else if (ds == DS_ALLIANCE) {
907 want -= abs(want) / 3; /* 33% off */
908 }
909 }
910 } players_iterate_alive_end;
911
912 /* Modify by love. Increase the divisor to make ai go to war earlier */
913 want -= MAX(0, want * pplayer->ai_common.love[player_index(target)]
914 / (2 * MAX_AI_LOVE));
915
916 /* Make novice AI more peaceful with human players */
917 if (has_handicap(pplayer, H_DIPLOMACY) && is_human(target)) {
918 want /= 2;
919 }
920
921 /* Amortize by distance */
922 want = amortize(want, distance);
923
924 if (pplayers_allied(pplayer, target)) {
925 want /= 4;
926 }
927
928 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "War want %d, war fear %d",
929 want, fear);
930 return (want - fear);
931}
932
933/******************************************************************/
938 static void dai_diplomacy_suggest(struct player *pplayer,
939 struct player *aplayer,
940 enum clause_type what,
941 bool to_pplayer,
942 int value)
943{
944 if (!could_meet_with_player(pplayer, aplayer)) {
945 log_base(LOG_DIPL2, "%s tries to do diplomacy to %s without contact",
946 player_name(pplayer), player_name(aplayer));
947 return;
948 }
949
950 handle_diplomacy_init_meeting_req(pplayer, player_number(aplayer));
951 handle_diplomacy_create_clause_req(pplayer, player_number(aplayer),
952 player_number(to_pplayer ? aplayer
953 : pplayer),
954 what, value);
955}
956
957/******************************************************************/
960 void dai_diplomacy_first_contact(struct ai_type *ait, struct player *pplayer,
961 struct player *aplayer)
962{
963 bool wants_ceasefire = FALSE;
964
965 /* Randomize initial love */
966 pplayer->ai_common.love[player_index(aplayer)] += 2 - fc_rand(5);
967
968 if (is_ai(pplayer)
969 && player_diplstate_get(pplayer, aplayer)->type == DS_WAR
970 && could_meet_with_player(pplayer, aplayer)) {
971 if (has_handicap(pplayer, H_CEASEFIRE)) {
972 fc_assert(!has_handicap(pplayer, H_AWAY));
973 wants_ceasefire = TRUE;
974 } else if (!has_handicap(pplayer, H_AWAY)) {
975 struct Clause clause;
976
977 clause.from = pplayer;
978 clause.value = 0;
979 clause.type = CLAUSE_CEASEFIRE;
980
981 if (dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
982 FALSE, DS_CEASEFIRE) > 0) {
983 wants_ceasefire = TRUE;
984 }
985 }
986 }
987
988 if (wants_ceasefire) {
989 dai_diplo_notify(aplayer,
990 _("*%s (AI)* Greetings %s! May we suggest a ceasefire "
991 "while we get to know each other better?"),
992 player_name(pplayer),
993 player_name(aplayer));
994 clear_old_treaty(pplayer, aplayer);
995 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_CEASEFIRE, FALSE, 0);
996 } else {
997 dai_diplo_notify(aplayer,
998 _("*%s (AI)* I found you %s! Now make it worth my "
999 "letting you live, or be crushed."),
1000 player_name(pplayer),
1001 player_name(aplayer));
1002 }
1003}
1004
1005/******************************************************************/
1014 void dai_diplomacy_begin_new_phase(struct ai_type *ait, struct player *pplayer)
1015{
1016 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1017 struct adv_data *adv = adv_data_get(pplayer, NULL);
1018 int war_desire[player_slot_count()];
1019 int best_desire = 0;
1020 struct player *best_target = NULL;
1021
1022 fc_assert_ret(is_ai(pplayer));
1023
1024 if (!pplayer->is_alive) {
1025 return; /* duh */
1026 }
1027
1028 memset(war_desire, 0, sizeof(war_desire));
1029
1030 /* Calculate our desires, and find desired war target */
1031 players_iterate_alive(aplayer) {
1032 /* We don't hate ourselves, those we don't know or team members. */
1033 if (aplayer == pplayer
1034 || NEVER_MET(pplayer, aplayer)
1035 || players_on_same_team(pplayer, aplayer)) {
1036 continue;
1037 }
1038 war_desire[player_index(aplayer)] = dai_war_desire(ait, pplayer, aplayer);
1039 if (war_desire[player_index(aplayer)] > best_desire) {
1040 best_desire = war_desire[player_index(aplayer)];
1041 best_target = aplayer;
1042 }
1043 } players_iterate_alive_end;
1044
1045 /* Time to make love. If we've been wronged, hold off that love
1046 * for a while. Also, cool our head each turn with love_coeff. */
1047 players_iterate_alive(aplayer) {
1048 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1049 int amount = 0;
1050 int pit;
1051
1052 if (pplayer == aplayer) {
1053 continue;
1054 }
1055
1056 if ((pplayers_non_attack(pplayer, aplayer)
1057 || pplayers_allied(pplayer, aplayer))
1058 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel == 0
1059 && adip->countdown == -1
1060 && !adip->is_allied_with_enemy
1061 && !adip->at_war_with_ally
1062 && aplayer != best_target
1063 && adip->ally_patience >= 0) {
1064 amount += ai->diplomacy.love_incr / 2;
1065 if (pplayers_allied(pplayer, aplayer)) {
1066 amount += ai->diplomacy.love_incr / 3;
1067 }
1068 /* Increase love by each enemy they are at war with */
1069 players_iterate(eplayer) {
1070 if (WAR(eplayer, aplayer) && WAR(pplayer, eplayer)) {
1071 amount += ai->diplomacy.love_incr / 4;
1072 }
1073 } players_iterate_end;
1074 pplayer->ai_common.love[player_index(aplayer)] += amount;
1075 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Increased love by %d", amount);
1076 } else if (WAR(pplayer, aplayer)) {
1077 amount -= ai->diplomacy.love_incr / 2;
1078 pplayer->ai_common.love[player_index(aplayer)] += amount;
1079 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost to war", amount);
1080 } else if (player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel
1081 != 0) {
1082 /* Provoked in time of peace */
1083 if (pplayer->ai_common.love[player_index(aplayer)] > 0) {
1084 amount -= pplayer->ai_common.love[player_index(aplayer)] / 2;
1085 }
1086 amount -= ai->diplomacy.love_incr * 6;
1087 pplayer->ai_common.love[player_index(aplayer)] += amount;
1088 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Provoked! %d love lost!",
1089 amount);
1090 }
1091 if (pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE * 8 / 10
1092 && !pplayers_allied(pplayer, aplayer)) {
1093 int love_change = ai->diplomacy.love_incr / 3;
1094
1095 /* Upper levels of AI trust and love is reserved for allies. */
1096 pplayer->ai_common.love[player_index(aplayer)] -= love_change;
1097 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost from excess",
1098 love_change);
1099 }
1100 amount = 0;
1101
1102 /* Reduce love due to units in our territory.
1103 * AI is so naive, that we have to count it even if players are allied */
1104 pit = player_in_territory(pplayer, aplayer) * (MAX_AI_LOVE / 200);
1105 amount -= MIN(pit,
1106 ai->diplomacy.love_incr
1107 * ((adip->is_allied_with_enemy != NULL) + 1));
1108 pplayer->ai_common.love[player_index(aplayer)] += amount;
1109 if (amount != 0) {
1110 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost due to units inside "
1111 "our borders", amount);
1112 }
1113
1114 /* Increase the love if aplayer has got a building that makes
1115 * us love them more. Typically it's Eiffel Tower */
1116 if (!NEVER_MET(pplayer, aplayer)) {
1117 pplayer->ai_common.love[player_index(aplayer)] +=
1118 get_player_bonus(aplayer, EFT_GAIN_AI_LOVE) * MAX_AI_LOVE / 1000;
1119 }
1120 } players_iterate_alive_end;
1121
1122 /* Can we win by space race? */
1123 if (adv->dipl.spacerace_leader == pplayer) {
1124 log_base(LOG_DIPL2, "%s going for space race victory!",
1125 player_name(pplayer));
1126 ai->diplomacy.strategy = WIN_SPACE; /* Yes! */
1127 } else {
1128 if (ai->diplomacy.strategy == WIN_SPACE) {
1129 ai->diplomacy.strategy = WIN_OPEN;
1130 }
1131 }
1132
1133 players_iterate(aplayer) {
1134 int *love = &pplayer->ai_common.love[player_index(aplayer)];
1135
1136 if (aplayer == best_target && best_desire > 0) {
1137 int reduction = MIN(best_desire, MAX_AI_LOVE / 20);
1138
1139 *love -= reduction;
1140 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Wants war, reducing "
1141 "love by %d ", reduction);
1142 }
1143
1144 /* Edge love towards zero */
1145 *love -= *love * ((double)ai->diplomacy.love_coeff / 100.0);
1146
1147 /* ai love should always be in range [-MAX_AI_LOVE..MAX_AI_LOVE] */
1148 *love = MAX(-MAX_AI_LOVE, MIN(MAX_AI_LOVE, *love));
1149 } players_iterate_end;
1150}
1151
1152/******************************************************************/
1155 static void suggest_tech_exchange(struct ai_type *ait,
1156 struct player *player1,
1157 struct player *player2)
1158{
1159 struct research *presearch1 = research_get(player1);
1160 struct research *presearch2 = research_get(player2);
1161 Tech_type_id ac = advance_count();
1162 int worth[ac];
1163 bool is_dangerous;
1164
1165 worth[A_NONE] = 0;
1166
1167 advance_index_iterate_max(A_FIRST, tech, ac) {
1168 if (research_invention_state(presearch1, tech)
1169 == TECH_KNOWN) {
1170 if (research_invention_state(presearch2, tech) != TECH_KNOWN
1171 && research_invention_gettable(presearch2, tech, game.info.tech_trade_allow_holes)) {
1172 worth[tech] = -compute_tech_sell_price(ait, player1, player2, tech,
1173 &is_dangerous);
1174 if (is_dangerous) {
1175 /* Don't try to exchange */
1176 worth[tech] = 0;
1177 }
1178 } else {
1179 worth[tech] = 0;
1180 }
1181 } else {
1182 if (research_invention_state(presearch2, tech) == TECH_KNOWN
1183 && research_invention_gettable(presearch1, tech,
1184 game.info.tech_trade_allow_holes)) {
1185 worth[tech] = compute_tech_sell_price(ait, player2, player1, tech,
1186 &is_dangerous);
1187 if (is_dangerous) {
1188 /* Don't try to exchange */
1189 worth[tech] = 0;
1190 }
1191 } else {
1192 worth[tech] = 0;
1193 }
1194 }
1195 } advance_index_iterate_max_end;
1196
1197 advance_index_iterate_max(A_FIRST, tech, ac) {
1198 if (worth[tech] <= 0) {
1199 continue;
1200 }
1201 advance_index_iterate_max(A_FIRST, tech2, ac) {
1202 int diff;
1203
1204 if (worth[tech2] >= 0) {
1205 continue;
1206 }
1207 /* Tech2 is given by player1, tech is given by player2 */
1208 diff = worth[tech] + worth[tech2];
1209 if ((diff > 0 && player1->economic.gold >= diff)
1210 || (diff < 0 && player2->economic.gold >= -diff)
1211 || diff == 0) {
1212 dai_diplomacy_suggest(player1, player2, CLAUSE_ADVANCE, FALSE, tech2);
1213 dai_diplomacy_suggest(player1, player2, CLAUSE_ADVANCE, TRUE, tech);
1214 if (diff > 0) {
1215 dai_diplomacy_suggest(player1, player2, CLAUSE_GOLD, FALSE, diff);
1216 } else if (diff < 0) {
1217 dai_diplomacy_suggest(player1, player2, CLAUSE_GOLD, TRUE, -diff);
1218 }
1219 return;
1220 }
1221 } advance_index_iterate_max_end;
1222 } advance_index_iterate_max_end;
1223}
1224
1225/******************************************************************/
1228 static void clear_old_treaty(struct player *pplayer, struct player *aplayer)
1229{
1230 struct Treaty *old_treaty = find_treaty(pplayer, aplayer);
1231
1232 if (old_treaty != NULL) {
1233 /* Remove existing clauses */
1234 clause_list_iterate(old_treaty->clauses, pclause) {
1235 dlsend_packet_diplomacy_remove_clause(aplayer->connections,
1236 player_number(pplayer),
1237 player_number(pclause->from),
1238 pclause->type, pclause->value);
1239 free(pclause);
1240 } clause_list_iterate_end;
1241 clause_list_destroy(old_treaty->clauses);
1242 old_treaty->clauses = clause_list_new();
1243 }
1244}
1245
1246/******************************************************************/
1249 static void dai_share(struct ai_type *ait, struct player *pplayer,
1250 struct player *aplayer)
1251{
1252 struct research *presearch = research_get(pplayer);
1253 struct research *aresearch = research_get(aplayer);
1254 bool gives_vision;
1255
1256 clear_old_treaty(pplayer, aplayer);
1257
1258 /* Only share techs with team mates */
1259 if (presearch != aresearch
1260 && players_on_same_team(pplayer, aplayer)) {
1261 advance_index_iterate(A_FIRST, idx) {
1262 if (research_invention_state(presearch, idx) != TECH_KNOWN
1263 && research_invention_state(aresearch, idx) == TECH_KNOWN
1264 && research_invention_gettable(presearch, idx,
1265 game.info.tech_trade_allow_holes)) {
1266 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_ADVANCE, TRUE, idx);
1267 } else if (research_invention_state(presearch, idx) == TECH_KNOWN
1268 && research_invention_state(aresearch, idx) != TECH_KNOWN
1269 && research_invention_gettable(aresearch, idx,
1270 game.info.tech_trade_allow_holes)) {
1271 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_ADVANCE, FALSE, idx);
1272 }
1273 } advance_index_iterate_end;
1274 }
1275
1276 /* Only give shared vision if safe. Only ask for shared vision if fair. */
1277 gives_vision = gives_shared_vision(pplayer, aplayer);
1278 if (!gives_vision
1279 && shared_vision_is_safe(pplayer, aplayer)) {
1280 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_VISION, FALSE, 0);
1281 gives_vision = TRUE;
1282 }
1283 if (gives_vision
1284 && !gives_shared_vision(aplayer, pplayer)
1285 && (is_human(aplayer)
1286 || shared_vision_is_safe(aplayer, pplayer))) {
1287 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_VISION, TRUE, 0);
1288 }
1289
1290 if (!player_has_embassy(pplayer, aplayer)) {
1291 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_EMBASSY, TRUE, 0);
1292 }
1293 if (!player_has_embassy(aplayer, pplayer)) {
1294 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_EMBASSY, FALSE, 0);
1295 }
1296
1297 if (!has_handicap(pplayer, H_DIPLOMACY) || is_human(aplayer)) {
1298 suggest_tech_exchange(ait, pplayer, aplayer);
1299 }
1300}
1301
1302/******************************************************************/
1307 static void dai_go_to_war(struct ai_type *ait, struct player *pplayer,
1308 struct player *target, enum war_reason reason)
1309{
1310 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1311
1312 fc_assert_ret(pplayer != target);
1313 fc_assert_ret(target->is_alive);
1314
1315 switch (reason) {
1316 case DAI_WR_SPACE:
1317 dai_diplo_notify(target, _("*%s (AI)* Space will never be yours."),
1318 player_name(pplayer));
1319 adip->countdown = -10;
1320 break;
1321 case DAI_WR_BEHAVIOUR:
1322 dai_diplo_notify(target,
1323 _("*%s (AI)* I have tolerated your vicious antics "
1324 "long enough! To war!"),
1325 player_name(pplayer));
1326 adip->countdown = -20;
1327 break;
1328 case DAI_WR_NONE:
1329 dai_diplo_notify(target, _("*%s (AI)* Peace in ... some other time."),
1330 player_name(pplayer));
1331 adip->countdown = -10;
1332 break;
1333 case DAI_WR_HATRED:
1334 dai_diplo_notify(target,
1335 _("*%s (AI)* Finally I get around to you! Did "
1336 "you really think you could get away with your crimes?"),
1337 player_name(pplayer));
1338 adip->countdown = -20;
1339 break;
1340 case DAI_WR_EXCUSE:
1341 dai_diplo_notify(target,
1342 _("*%s (AI)* Your covert hostilities brought "
1343 "this war upon you!"),
1344 player_name(pplayer));
1345 adip->countdown = -20;
1346 break;
1347 case DAI_WR_ALLIANCE:
1348 if (adip->at_war_with_ally) {
1349 dai_diplo_notify(target,
1350 _("*%s (AI)* Your aggression against %s was "
1351 "your last mistake!"),
1352 player_name(pplayer),
1353 player_name(adip->at_war_with_ally));
1354 adip->countdown = -3;
1355 } else {
1356 /* Ooops! */
1357 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "Wanted to declare war "
1358 "for their war against an ally, but can no longer find "
1359 "this ally! War declaration aborted.");
1360 adip->countdown = -1;
1361 return;
1362 }
1363 break;
1364 }
1365
1366 fc_assert_ret(adip->countdown < 0);
1367
1368 if (gives_shared_vision(pplayer, target)) {
1369 remove_shared_vision(pplayer, target);
1370 }
1371
1372 /* Check for Senate obstruction. If so, dissolve it. */
1373 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_SENATE_BLOCKING) {
1374 struct government *real_gov = pplayer->government;
1375
1376 pplayer->government = game.government_during_revolution;
1377
1378 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_OK) {
1379 /* It seems that revolution would help. */
1380 pplayer->government = real_gov;
1381 handle_player_change_government(pplayer,
1382 game.info.government_during_revolution_id);
1383 } else {
1384 /* There would be Senate even during revolution. Better not to revolt for nothing */
1385 pplayer->government = real_gov;
1386 adip->countdown = -1; /* War declaration aborted */
1387
1388 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target,
1389 "Not revolting, as there would be Senate regardless.");
1390
1391 return;
1392 }
1393 }
1394
1395 /* This will take us straight to war. */
1396 while (player_diplstate_get(pplayer, target)->type != DS_WAR) {
1397 if (pplayer_can_cancel_treaty(pplayer, target) != DIPL_OK) {
1398 DIPLO_LOG(ait, LOG_ERROR, pplayer, target,
1399 "Wanted to cancel treaty but was unable to.");
1400 adip->countdown = -1; /* War declaration aborted */
1401
1402 return;
1403 }
1404 handle_diplomacy_cancel_pact(pplayer, player_number(target), clause_type_invalid());
1405 }
1406
1407 /* Throw a tantrum */
1408 if (pplayer->ai_common.love[player_index(target)] > 0) {
1409 pplayer->ai_common.love[player_index(target)] = -1;
1410 }
1411 pplayer->ai_common.love[player_index(target)] -= MAX_AI_LOVE / 8;
1412
1413 fc_assert(!gives_shared_vision(pplayer, target));
1414 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "war declared");
1415}
1416
1417/******************************************************************/
1429 static void war_countdown(struct ai_type *ait, struct player *pplayer,
1430 struct player *target,
1431 int countdown, enum war_reason reason)
1432{
1433 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1434
1435 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "countdown to war in %d", countdown);
1436
1437 /* Otherwise we're resetting an existing countdown, which is very bad */
1438 fc_assert_ret(adip->countdown == -1);
1439
1440 adip->countdown = countdown;
1441 adip->war_reason = reason;
1442
1443 players_iterate_alive(ally) {
1444 if (!pplayers_allied(pplayer, ally)
1445 || ally == target
1446 || NEVER_MET(pplayer, ally)) {
1447 continue;
1448 }
1449
1450 switch (reason) {
1451 case DAI_WR_SPACE:
1452 dai_diplo_notify(ally,
1453 PL_("*%s (AI)* We will be launching an all-out war "
1454 "against %s in %d turn to stop the spaceship "
1455 "launch.",
1456 "*%s (AI)* We will be launching an all-out war "
1457 "against %s in %d turns to stop the spaceship "
1458 "launch.",
1459 countdown),
1460 player_name(pplayer),
1461 player_name(target),
1462 countdown);
1463 dai_diplo_notify(ally,
1464 _("*%s (AI)* Your aid in this matter will be expected. "
1465 "Long live our glorious alliance!"),
1466 player_name(pplayer));
1467 break;
1468 case DAI_WR_BEHAVIOUR:
1469 case DAI_WR_EXCUSE:
1470 dai_diplo_notify(ally,
1471 PL_("*%s (AI)* %s has grossly violated their treaties "
1472 "with us for own gain. We will answer in force in "
1473 "%d turn and expect you to honor your alliance "
1474 "with us and do likewise!",
1475 "*%s (AI)* %s has grossly violated their treaties "
1476 "with us for own gain. We will answer in force in "
1477 "%d turns and expect you to honor your alliance "
1478 "with us and do likewise!", countdown),
1479 player_name(pplayer),
1480 player_name(target),
1481 countdown);
1482 break;
1483 case DAI_WR_NONE:
1484 dai_diplo_notify(ally,
1485 PL_("*%s (AI)* We intend to pillage and plunder the rich "
1486 "civilization of %s. We declare war in %d turn.",
1487 "*%s (AI)* We intend to pillage and plunder the rich "
1488 "civilization of %s. We declare war in %d turns.",
1489 countdown),
1490 player_name(pplayer),
1491 player_name(target),
1492 countdown);
1493 dai_diplo_notify(ally,
1494 _("*%s (AI)* If you want a piece of the loot, feel "
1495 "free to join in the action!"),
1496 player_name(pplayer));
1497 break;
1498 case DAI_WR_HATRED:
1499 dai_diplo_notify(ally,
1500 PL_("*%s (AI)* We have had it with %s. Let us tear this "
1501 "pathetic civilization apart. We declare war in "
1502 "%d turn.",
1503 "*%s (AI)* We have had it with %s. Let us tear this "
1504 "pathetic civilization apart. We declare war in "
1505 "%d turns.",
1506 countdown),
1507 player_name(pplayer),
1508 player_name(target),
1509 countdown);
1510 dai_diplo_notify(ally,
1511 _("*%s (AI)* As our glorious allies, we expect your "
1512 "help in this war."),
1513 player_name(pplayer));
1514 break;
1515 case DAI_WR_ALLIANCE:
1516 if (WAR(ally, target)) {
1517 dai_diplo_notify(ally,
1518 PL_("*%s (AI)* We will honor our alliance and declare "
1519 "war on %s in %d turn. Hold on - we are coming!",
1520 "*%s (AI)* We will honor our alliance and declare "
1521 "war on %s in %d turns. Hold on - we are coming!",
1522 countdown),
1523 player_name(pplayer),
1524 player_name(target),
1525 countdown);
1526 } else if (adip->at_war_with_ally) {
1527 dai_diplo_notify(ally,
1528 PL_("*%s (AI)* We will honor our alliance with %s and "
1529 "declare war on %s in %d turns. We expect you to "
1530 "do likewise.",
1531 "*%s (AI)* We will honor our alliance with %s and "
1532 "declare war on %s in %d turns. We expect you to "
1533 "do likewise.",
1534 countdown),
1535 player_name(pplayer),
1536 player_name(adip->at_war_with_ally),
1537 player_name(target),
1538 countdown);
1539 } else {
1540 fc_assert(FALSE); /* Huh? */
1541 }
1542 break;
1543 }
1544 } players_iterate_alive_end;
1545}
1546
1547/******************************************************************/
1553 void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
1554{
1555 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1556 bool need_targets = TRUE;
1557 struct player *target = NULL;
1558 int most_hatred = MAX_AI_LOVE;
1559 int war_threshold;
1560 int aggr;
1561 float aggr_sr;
1562 float max_sr;
1563
1564 fc_assert_ret(is_ai(pplayer));
1565
1566 if (!pplayer->is_alive) {
1567 return;
1568 }
1569
1570 if (get_player_bonus(pplayer, EFT_NO_DIPLOMACY) > 0) {
1571 /* Diplomacy disabled for this player */
1572 return;
1573 }
1574
1575 /*** If we are greviously insulted, go to war immediately. ***/
1576
1577 players_iterate(aplayer) {
1578 if (pplayer->ai_common.love[player_index(aplayer)] < 0
1579 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel >= 2
1580 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown == -1) {
1581 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Plans war in revenge");
1582 war_countdown(ait, pplayer, aplayer, map_size_checked(),
1583 DAI_WR_BEHAVIOUR);
1584 }
1585 } players_iterate_end;
1586
1587 /*** Stop other players from winning by space race ***/
1588
1589 if (ai->diplomacy.strategy != WIN_SPACE) {
1590 struct adv_data *adv = adv_data_get(pplayer, NULL);
1591
1592 players_iterate_alive(aplayer) {
1593 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1594 struct player_spaceship *ship = &aplayer->spaceship;
1595
1596 if (aplayer == pplayer
1597 || adip->countdown >= 0 /* already counting down to war */
1598 || ship->state == SSHIP_NONE
1599 || players_on_same_team(pplayer, aplayer)
1600 || pplayers_at_war(pplayer, aplayer)) {
1601 continue;
1602 }
1603
1604 /* A spaceship victory is always one single player's or team's victory */
1605 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1606 && adv->dipl.spacerace_leader == aplayer
1607 && pplayers_allied(pplayer, aplayer)) {
1608 dai_diplo_notify(aplayer,
1609 _("*%s (AI)* Your attempt to conquer space for "
1610 "yourself alone betrays your true intentions, and I "
1611 "will have no more of our alliance!"),
1612 player_name(pplayer));
1613 handle_diplomacy_cancel_pact(pplayer, player_number(aplayer),
1614 CLAUSE_ALLIANCE);
1615 if (gives_shared_vision(pplayer, aplayer)) {
1616 remove_shared_vision(pplayer, aplayer);
1617 }
1618 /* Never forgive this */
1619 pplayer->ai_common.love[player_index(aplayer)] = -MAX_AI_LOVE;
1620 } else if (ship->state == SSHIP_STARTED
1621 && adip->warned_about_space == 0) {
1622 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 10;
1623 adip->warned_about_space = 10 + fc_rand(6);
1624 dai_diplo_notify(aplayer,
1625 _("*%s (AI)* Your attempt to unilaterally "
1626 "dominate outer space is highly offensive."),
1627 player_name(pplayer));
1628 dai_diplo_notify(aplayer,
1629 _("*%s (AI)* If you do not stop constructing your "
1630 "spaceship, I may be forced to take action!"),
1631 player_name(pplayer));
1632 }
1633 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1634 && aplayer == adv->dipl.spacerace_leader) {
1635 /* This means war!!! */
1636 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 2;
1637 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "plans war due to spaceship");
1638 war_countdown(ait, pplayer, aplayer, 4 + map_size_checked(),
1639 DAI_WR_SPACE);
1640 }
1641 } players_iterate_alive_end;
1642 }
1643
1644 /*** Declare war against somebody if we are out of targets ***/
1645
1646 players_iterate_alive(aplayer) {
1647 int turns; /* turns since contact */
1648
1649 if (NEVER_MET(pplayer, aplayer)) {
1650 continue;
1651 }
1652 turns = game.info.turn;
1653 turns -= player_diplstate_get(pplayer, aplayer)->first_contact_turn;
1654 if (WAR(pplayer, aplayer)) {
1655 need_targets = FALSE;
1656 } else if (pplayer->ai_common.love[player_index(aplayer)] < most_hatred
1657 && turns > TURNS_BEFORE_TARGET) {
1658 most_hatred = pplayer->ai_common.love[player_index(aplayer)];
1659 target = aplayer;
1660 }
1661 } players_iterate_alive_end;
1662
1663 aggr = ai_trait_get_value(TRAIT_AGGRESSIVE, pplayer);
1664 max_sr = TRAIT_MAX_VALUE_SR;
1665 aggr_sr = sqrt(aggr);
1666
1667 war_threshold = (MAX_AI_LOVE * (0.70 + aggr_sr / max_sr / 2.0)) - MAX_AI_LOVE;
1668
1669 if (need_targets && target && most_hatred < war_threshold
1670 && dai_diplomacy_get(ait, pplayer, target)->countdown == -1) {
1671 enum war_reason war_reason;
1672
1673 if (pplayers_allied(pplayer, target)) {
1674 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "Plans war against an ally!");
1675 }
1676 if (player_diplstate_get(pplayer, target)->has_reason_to_cancel > 0) {
1677 /* We have good reason */
1678 war_reason = DAI_WR_EXCUSE;
1679 } else if (pplayer->ai_common.love[player_index(target)] < 0) {
1680 /* We have a reason of sorts from way back, maybe? */
1681 war_reason = DAI_WR_HATRED;
1682 } else {
1683 /* We have no legimitate reason... So what? */
1684 war_reason = DAI_WR_NONE;
1685 }
1686 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "plans war for spoils");
1687 war_countdown(ait, pplayer, target, 4 + map_size_checked(), war_reason);
1688 }
1689
1690 /*** Declare war - against enemies of allies ***/
1691
1692 players_iterate_alive(aplayer) {
1693 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1694
1695 if (adip->at_war_with_ally
1696 && adip->countdown == -1
1697 && !adip->is_allied_with_ally
1698 && !pplayers_at_war(pplayer, aplayer)
1699 && (player_diplstate_get(pplayer, aplayer)->type != DS_CEASEFIRE
1700 || fc_rand(5) < 1)) {
1701 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "plans war to help ally %s",
1702 player_name(adip->at_war_with_ally));
1703 war_countdown(ait, pplayer, aplayer, 2 + map_size_checked(),
1704 DAI_WR_ALLIANCE);
1705 }
1706 } players_iterate_alive_end;
1707
1708 /*** Actually declare war (when we have moved units into position) ***/
1709
1710 players_iterate(aplayer) {
1711 if (!players_on_same_team(pplayer, aplayer)) {
1712 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1713
1714 if (!aplayer->is_alive) {
1715 adip->countdown = -1;
1716 continue;
1717 }
1718 if (adip->countdown > 0) {
1719 adip->countdown--;
1720 } else if (adip->countdown == 0) {
1721 if (!WAR(pplayer, aplayer)) {
1722 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Declaring war!");
1723 dai_go_to_war(ait, pplayer, aplayer, adip->war_reason);
1724 }
1725 } else if (adip->countdown < -1) {
1726 /* Negative countdown less than -1 is war stubbornness */
1727 adip->countdown++;
1728 }
1729 }
1730 } players_iterate_end;
1731
1732 /*** Try to make peace with everyone we love ***/
1733
1734 players_iterate_alive(aplayer) {
1735 if (get_player_bonus(aplayer, EFT_NO_DIPLOMACY) <= 0
1736 && diplomacy_possible(pplayer, aplayer)) {
1737 enum diplstate_type ds = player_diplstate_get(pplayer, aplayer)->type;
1738 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1739 struct Clause clause;
1740
1741 /* Meaningless values, but rather not have them unset. */
1742 clause.from = pplayer;
1743 clause.value = 0;
1744
1745 /* Remove shared vision if we are not allied or it is no longer safe. */
1746 if (gives_shared_vision(pplayer, aplayer)) {
1747 if (!pplayers_allied(pplayer, aplayer)) {
1748 remove_shared_vision(pplayer, aplayer);
1749 } else if (!players_on_same_team(pplayer, aplayer)
1750 && !shared_vision_is_safe(pplayer, aplayer)) {
1751 dai_diplo_notify(aplayer,
1752 _("*%s (AI)* Sorry, sharing vision with you "
1753 "is no longer safe."),
1754 player_name(pplayer));
1755 remove_shared_vision(pplayer, aplayer);
1756 }
1757 }
1758
1759 /* No peace to enemies of our allies... or pointless peace. */
1760 if (is_barbarian(aplayer)
1761 || aplayer == pplayer
1762 || aplayer == target /* no mercy */
1763 || adip->countdown >= 0
1764 || !could_meet_with_player(pplayer, aplayer)) {
1765 continue;
1766 }
1767
1768 /* Spam control */
1769 adip->asked_about_peace = MAX(adip->asked_about_peace - 1, 0);
1770 adip->asked_about_alliance = MAX(adip->asked_about_alliance - 1, 0);
1771 adip->asked_about_ceasefire = MAX(adip->asked_about_ceasefire - 1, 0);
1772 adip->warned_about_space = MAX(adip->warned_about_space - 1, 0);
1773 adip->spam = MAX(adip->spam - 1, 0);
1774 if (adip->spam > 0 && is_ai(aplayer)) {
1775 /* Don't spam */
1776 continue;
1777 }
1778
1779 /* Canvass support from existing friends for our war, and try to
1780 * make friends with enemies. Then we wait some turns until next time
1781 * we spam them with our gibbering chatter. */
1782 if (adip->spam <= 0) {
1783 if (!pplayers_allied(pplayer, aplayer)) {
1784 adip->spam = fc_rand(4) + 3; /* Bugger allies often. */
1785 } else {
1786 adip->spam = fc_rand(8) + 6; /* Others are less important. */
1787 }
1788 }
1789
1790 switch (ds) {
1791 case DS_TEAM:
1792 dai_share(ait, pplayer, aplayer);
1793 break;
1794 case DS_ALLIANCE:
1795 /* See if our allies are diligently declaring war on our enemies... */
1796 if (adip->at_war_with_ally) {
1797 break;
1798 }
1799 target = NULL;
1800 players_iterate(eplayer) {
1801 if (WAR(pplayer, eplayer)
1802 && !pplayers_at_war(aplayer, eplayer)) {
1803 target = eplayer;
1804 break;
1805 }
1806 } players_iterate_end;
1807
1808 if ((players_on_same_team(pplayer, aplayer)
1809 || pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE / 2)) {
1810 /* Share techs only with team mates and allies we really like. */
1811 dai_share(ait, pplayer, aplayer);
1812 }
1813 if (!target || !target->is_alive) {
1814 adip->ally_patience = 0;
1815 break; /* No need to nag our ally */
1816 }
1817
1818 if (adip->spam <= 0) {
1819 /* Count down patience toward AI player (one that can have spam > 0)
1820 * at the same speed as toward human players. */
1821 if (adip->ally_patience == 0) {
1822 dai_diplo_notify(aplayer,
1823 _("*%s (AI)* Greetings our most trustworthy "
1824 "ally. We call upon you to destroy our enemy, %s."),
1825 player_name(pplayer),
1826 player_name(target));
1827 adip->ally_patience--;
1828 } else if (adip->ally_patience == -1) {
1829 if (fc_rand(5) == 1) {
1830 dai_diplo_notify(aplayer,
1831 _("*%s (AI)* Greetings ally, I see you have not yet "
1832 "made war with our enemy, %s. Why do I need to remind "
1833 "you of your promises?"),
1834 player_name(pplayer),
1835 player_name(target));
1836 adip->ally_patience--;
1837 }
1838 } else if (fc_rand(5) == 1
1839 && !players_on_same_team(pplayer, aplayer)) {
1840 dai_diplo_notify(aplayer,
1841 _("*%s (AI)* Dishonored one, we made a pact of "
1842 "alliance, and yet you remain at peace with our mortal "
1843 "enemy, %s! This is unacceptable; our alliance is no "
1844 "more!"),
1845 player_name(pplayer),
1846 player_name(target));
1847 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer,
1848 "breaking useless alliance");
1849 /* To peace */
1850 handle_diplomacy_cancel_pact(pplayer, player_number(aplayer),
1851 CLAUSE_ALLIANCE);
1852 pplayer->ai_common.love[player_index(aplayer)]
1853 = MIN(pplayer->ai_common.love[player_index(aplayer)], 0);
1854 if (gives_shared_vision(pplayer, aplayer)) {
1855 remove_shared_vision(pplayer, aplayer);
1856 }
1857
1858 fc_assert(!gives_shared_vision(pplayer, aplayer));
1859 }
1860 }
1861 break;
1862
1863 case DS_PEACE:
1864 clause.type = CLAUSE_ALLIANCE;
1865 if (adip->at_war_with_ally
1866 || (is_human(aplayer) && adip->asked_about_alliance > 0)
1867 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1868 FALSE, DS_ALLIANCE) < 0) {
1869 break;
1870 }
1871 clear_old_treaty(pplayer, aplayer);
1872 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_ALLIANCE, FALSE, 0);
1873 adip->asked_about_alliance = is_human(aplayer) ? 13 : 0;
1874 dai_diplo_notify(aplayer,
1875 _("*%s (AI)* Greetings friend, may we suggest "
1876 "making a common cause and join in an alliance?"),
1877 player_name(pplayer));
1878 break;
1879
1880 case DS_CEASEFIRE:
1881 clause.type = CLAUSE_PEACE;
1882 if (adip->at_war_with_ally
1883 || (is_human(aplayer) && adip->asked_about_peace > 0)
1884 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1885 FALSE, DS_PEACE) < 0) {
1886 break;
1887 }
1888 clear_old_treaty(pplayer, aplayer);
1889 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_PEACE, FALSE, 0);
1890 adip->asked_about_peace = is_human(aplayer) ? 12 : 0;
1891 dai_diplo_notify(aplayer,
1892 _("*%s (AI)* Greetings neighbor, may we suggest "
1893 "more peaceful relations?"),
1894 player_name(pplayer));
1895 break;
1896
1897 case DS_NO_CONTACT: /* but we do have embassy! weird. */
1898 case DS_WAR:
1899 clause.type = CLAUSE_CEASEFIRE;
1900 if ((is_human(aplayer) && adip->asked_about_ceasefire > 0)
1901 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1902 FALSE, DS_CEASEFIRE) < 0) {
1903 break; /* Fight until the end! */
1904 }
1905 clear_old_treaty(pplayer, aplayer);
1906 dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_CEASEFIRE, FALSE, 0);
1907 adip->asked_about_ceasefire = is_human(aplayer) ? 9 : 0;
1908 dai_diplo_notify(aplayer,
1909 _("*%s (AI)* We grow weary of this constant "
1910 "bloodshed. May we suggest a cessation of hostilities?"),
1911 player_name(pplayer));
1912 break;
1913
1914 case DS_ARMISTICE:
1915 break;
1916 default:
1917 fc_assert_msg(FALSE, "Unknown pact type %d.", ds);
1918 break;
1919 }
1920 }
1921 } players_iterate_alive_end;
1922}
1923
1924/******************************************************************/
1928 bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
1929{
1930 players_iterate(plr) {
1931 if (dai_diplomacy_get(ait, pplayer, plr)->countdown >= 0) {
1932 return TRUE;
1933 }
1934 } players_iterate_end;
1935
1936 return FALSE;
1937}
1938
1939/******************************************************************/
1942/* AI attitude call-backs */
1943 void dai_incident(struct ai_type *ait, enum incident_type type,
1944 enum casus_belli_range scope,
1945 const struct action *paction,
1946 struct player *receiver,
1947 struct player *violator, struct player *victim)
1948{
1949 if (!is_ai(receiver) || violator == receiver) {
1950 return;
1951 }
1952
1953 /* Can only handle victim only and international incidents. */
1954 fc_assert_ret(scope == CBR_VICTIM_ONLY
1955 || scope == CBR_INTERNATIONAL_OUTRAGE);
1956
1957 switch (type) {
1958 case INCIDENT_ACTION:
1959 /* Feel free the change how the action results are grouped and how bad
1960 * the ai considers each group. */
1961 switch (paction->result) {
1962 case ACTRES_SPY_NUKE:
1963 case ACTRES_NUKE:
1964 case ACTRES_NUKE_UNITS:
1965 if (receiver == victim) {
1966 /* Tell the victim */
1967 dai_incident_nuclear(receiver, violator, victim);
1968 } else if (violator == victim) {
1969 dai_incident_nuclear_self(receiver, violator, victim);
1970 } else {
1971 dai_incident_nuclear_not_target(receiver, violator, victim);
1972 }
1973 break;
1974 case ACTRES_ESTABLISH_EMBASSY:
1975 case ACTRES_SPY_INVESTIGATE_CITY:
1976 /* Snoping */
1977 dai_incident_simple(receiver, violator, victim, scope, 2);
1978 break;
1979 case ACTRES_SPY_STEAL_GOLD:
1980 case ACTRES_SPY_STEAL_TECH:
1981 case ACTRES_SPY_TARGETED_STEAL_TECH:
1982 case ACTRES_STEAL_MAPS:
1983 /* Theft */
1984 dai_incident_simple(receiver, violator, victim, scope, 5);
1985 break;
1986 case ACTRES_EXPEL_UNIT:
1987 /* Unit position loss */
1988 dai_incident_simple(receiver, violator, victim, scope, 1);
1989 break;
1990 case ACTRES_SPY_SABOTAGE_UNIT:
1991 /* Unit weakening */
1992 dai_incident_simple(receiver, violator, victim, scope, 3);
1993 break;
1994 case ACTRES_SPY_BRIBE_UNIT:
1995 case ACTRES_CAPTURE_UNITS:
1996 case ACTRES_BOMBARD:
1997 case ACTRES_ATTACK:
1998 case ACTRES_WIPE_UNITS:
1999 case ACTRES_SPY_ATTACK:
2000 case ACTRES_COLLECT_RANSOM:
2001 /* Unit loss */
2002 dai_incident_simple(receiver, violator, victim, scope, 5);
2003 break;
2004 case ACTRES_SPY_INCITE_CITY:
2005 case ACTRES_DESTROY_CITY:
2006 case ACTRES_CONQUER_CITY:
2007 /* City loss */
2008 dai_incident_simple(receiver, violator, victim, scope, 10);
2009 break;
2010 case ACTRES_SPY_SABOTAGE_CITY:
2011 case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
2012 case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
2013 case ACTRES_STRIKE_BUILDING:
2014 case ACTRES_STRIKE_PRODUCTION:
2015 /* Building loss */
2016 dai_incident_simple(receiver, violator, victim, scope, 5);
2017 break;
2018 case ACTRES_SPY_POISON:
2019 case ACTRES_SPY_SPREAD_PLAGUE:
2020 /* Population loss */
2021 dai_incident_simple(receiver, violator, victim, scope, 5);
2022 break;
2023 case ACTRES_FOUND_CITY:
2024 /* Terrain loss */
2025 dai_incident_simple(receiver, violator, victim, scope, 4);
2026 break;
2027 case ACTRES_CONQUER_EXTRAS:
2028 case ACTRES_PILLAGE:
2029 /* Extra loss */
2030 dai_incident_simple(receiver, violator, victim, scope, 2);
2031 break;
2032 case ACTRES_UNIT_MOVE:
2033 case ACTRES_TELEPORT:
2034 case ACTRES_TELEPORT_CONQUER:
2035 case ACTRES_SPY_ESCAPE:
2036 case ACTRES_TRADE_ROUTE:
2037 case ACTRES_MARKETPLACE:
2038 case ACTRES_HELP_WONDER:
2039 case ACTRES_JOIN_CITY:
2040 case ACTRES_DISBAND_UNIT_RECOVER:
2041 case ACTRES_DISBAND_UNIT:
2042 case ACTRES_HOME_CITY:
2043 case ACTRES_HOMELESS:
2044 case ACTRES_UPGRADE_UNIT:
2045 case ACTRES_PARADROP:
2046 case ACTRES_PARADROP_CONQUER: /* TODO: Bigger incident */
2047 case ACTRES_AIRLIFT:
2048 case ACTRES_HEAL_UNIT:
2049 case ACTRES_TRANSFORM_TERRAIN:
2050 case ACTRES_CULTIVATE:
2051 case ACTRES_PLANT:
2052 case ACTRES_CLEAN:
2053 case ACTRES_FORTIFY:
2054 case ACTRES_ROAD:
2055 case ACTRES_CONVERT:
2056 case ACTRES_BASE:
2057 case ACTRES_MINE:
2058 case ACTRES_IRRIGATE:
2059 case ACTRES_TRANSPORT_DEBOARD:
2060 case ACTRES_TRANSPORT_UNLOAD:
2061 case ACTRES_TRANSPORT_DISEMBARK:
2062 case ACTRES_TRANSPORT_BOARD:
2063 case ACTRES_TRANSPORT_LOAD:
2064 case ACTRES_TRANSPORT_EMBARK:
2065 case ACTRES_HUT_ENTER:
2066 case ACTRES_HUT_FRIGHTEN:
2067 case ACTRES_ENABLER_CHECK:
2068 case ACTRES_NONE:
2069 /* Various */
2070 dai_incident_simple(receiver, violator, victim, scope, 1);
2071 break;
2072
2073 ASSERT_UNUSED_ACTRES_CASES;
2074 }
2075 break;
2076 case INCIDENT_WAR:
2077 if (receiver == victim) {
2078 dai_incident_war(violator, victim);
2079 }
2080 break;
2081 case INCIDENT_LAST:
2082 /* Assert that always fails, but with meaningful message */
2083 fc_assert(type != INCIDENT_LAST);
2084 break;
2085 }
2086}
2087
2088/******************************************************************/
2091 static void dai_incident_nuclear(struct player *receiver,
2092 const struct player *violator,
2093 const struct player *victim)
2094{
2095 fc_assert_ret(receiver == victim);
2096
2097 if (violator == victim) {
2098 return;
2099 }
2100
2101 receiver->ai_common.love[player_index(violator)] -= 3 * MAX_AI_LOVE / 10;
2102}
2103
2104/******************************************************************/
2107 static void dai_incident_nuclear_not_target(struct player *receiver,
2108 const struct player *violator,
2109 const struct player *victim)
2110{
2111 fc_assert_ret(receiver != victim);
2112
2113 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2114}
2115
2116/******************************************************************/
2119 static void dai_incident_nuclear_self(struct player *receiver,
2120 const struct player *violator,
2121 const struct player *victim)
2122{
2123 fc_assert_ret(receiver != victim);
2124 fc_assert_ret(violator == victim);
2125
2126 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 20;
2127}
2128
2129/**********************************************************************/
2141 static void dai_incident_simple(struct player *receiver,
2142 const struct player *violator,
2143 const struct player *victim,
2144 enum casus_belli_range scope,
2145 int how_bad)
2146{
2147 int displeasure = how_bad * MAX_AI_LOVE;
2148 if (victim == receiver) {
2149 if (scope == CBR_INTERNATIONAL_OUTRAGE) {
2150 /* The ruleset finds this bad enough to cause International Outrage.
2151 * Trust the ruleset author. Double the displeasure. */
2152 displeasure = displeasure * 2;
2153 }
2154 receiver->ai_common.love[player_index(violator)] -= displeasure / 35;
2155 } else if (violator == victim) {
2156 receiver->ai_common.love[player_index(violator)] -= displeasure / 1000;
2157 } else {
2158 receiver->ai_common.love[player_index(violator)] -= displeasure / 500;
2159 }
2160}
2161
2162/******************************************************************/
2170 static void dai_incident_war(struct player *violator, struct player *victim)
2171{
2172 players_iterate(pplayer) {
2173 if (!is_ai(pplayer)) {
2174 continue;
2175 }
2176
2177 if (pplayer != violator) {
2178 /* Dislike backstabbing bastards */
2179 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2180 if (player_diplstate_get(violator, victim)->max_state == DS_PEACE) {
2181 /* Extra penalty if they once had a peace treaty */
2182 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2183 } else if (player_diplstate_get(violator, victim)->max_state
2184 == DS_ALLIANCE) {
2185 /* Extra penalty if they once had an alliance */
2186 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2187 }
2188 if (victim == pplayer) {
2189 pplayer->ai_common.love[player_index(violator)] =
2190 MIN(pplayer->ai_common.love[player_index(violator)] - MAX_AI_LOVE / 3, -1);
2191 /* Scream for help!! */
2192 players_iterate_alive(ally) {
2193 if (!pplayers_allied(pplayer, ally)) {
2194 continue;
2195 }
2196 dai_diplo_notify(ally,
2197 _("*%s (AI)* We have been savagely attacked by "
2198 "%s, and we need your help! Honor our glorious "
2199 "alliance and your name will never be forgotten!"),
2200 player_name(victim),
2201 player_name(violator));
2202 } players_iterate_alive_end;
2203 }
2204 }
2205 } players_iterate_end;
2206}
ASSERT_UNUSED_ACTRES_CASES
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
adv_data_get
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:605
adv_is_player_dangerous
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1107
advdata.h
amortize
adv_want amortize(adv_want benefit, int delay)
Definition advtools.c:29
advtools.h
incident_type
incident_type
Definition ai.h:45
INCIDENT_LAST
@ INCIDENT_LAST
Definition ai.h:46
INCIDENT_WAR
@ INCIDENT_WAR
Definition ai.h:46
INCIDENT_ACTION
@ INCIDENT_ACTION
Definition ai.h:46
player_distance_to_player
int player_distance_to_player(struct player *pplayer, struct player *target)
Definition aisupport.c:75
city_gold_worth
int city_gold_worth(struct city *pcity)
Definition aisupport.c:108
aisupport.h
aitools.h
ai_trait_get_value
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:69
aitraits.h
is_capital
bool is_capital(const struct city *pcity)
Definition city.c:1571
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
city_list_find_number
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1671
city.h
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_size_get
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
city_owner
#define city_owner(_pcity_)
Definition city.h:563
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
city_built_iterate
#define city_built_iterate(_pcity, _p)
Definition city.h:822
city_built_iterate_end
#define city_built_iterate_end
Definition city.h:828
citytools.h
incite_cost
char * incite_cost
Definition comments.c:74
daicity.h
dai_plr_data_get
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition daidata.c:308
dai_diplomacy_get
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Definition daidata.c:402
dai_data_phase_finished
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:285
daidata.h
WIN_SPACE
@ WIN_SPACE
Definition daidata.h:34
WIN_CAPITAL
@ WIN_CAPITAL
Definition daidata.h:35
WIN_OPEN
@ WIN_OPEN
Definition daidata.h:32
dai_treaty_accepted
void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Definition daidiplomacy.c:740
dai_incident_nuclear_not_target
static void dai_incident_nuclear_not_target(struct player *receiver, const struct player *violator, const struct player *victim)
Definition daidiplomacy.c:2107
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)
Definition daidiplomacy.c:1943
dai_on_war_footing
bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
Definition daidiplomacy.c:1928
dai_diplomacy_actions
void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
Definition daidiplomacy.c:1553
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)
Definition daidiplomacy.c:297
get_allied_with_enemy_player
static const struct player * get_allied_with_enemy_player(const struct player *us, const struct player *them)
Definition daidiplomacy.c:276
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)
Definition daidiplomacy.c:2141
dai_incident_nuclear_self
static void dai_incident_nuclear_self(struct player *receiver, const struct player *violator, const struct player *victim)
Definition daidiplomacy.c:2119
dai_diplomacy_begin_new_phase
void dai_diplomacy_begin_new_phase(struct ai_type *ait, struct player *pplayer)
Definition daidiplomacy.c:1014
suggest_tech_exchange
static void suggest_tech_exchange(struct ai_type *ait, struct player *player1, struct player *player2)
Definition daidiplomacy.c:1155
dai_treaty_evaluate
void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Definition daidiplomacy.c:620
LOG_DIPL2
#define LOG_DIPL2
Definition daidiplomacy.c:69
greed
static int greed(int missing_love)
Definition daidiplomacy.c:124
dai_players_can_agree_on_ceasefire
static bool dai_players_can_agree_on_ceasefire(struct ai_type *ait, struct player *player1, struct player *player2)
Definition daidiplomacy.c:208
dai_go_to_war
static void dai_go_to_war(struct ai_type *ait, struct player *pplayer, struct player *target, enum war_reason reason)
Definition daidiplomacy.c:1307
dai_goldequiv_tech
static int dai_goldequiv_tech(struct ai_type *ait, struct player *pplayer, Tech_type_id tech)
Definition daidiplomacy.c:157
BIG_NUMBER
#define BIG_NUMBER
Definition daidiplomacy.c:73
LOG_DIPL
#define LOG_DIPL
Definition daidiplomacy.c:68
pact_clause_to_diplstate_type
static enum diplstate_type pact_clause_to_diplstate_type(enum clause_type type)
Definition daidiplomacy.c:139
dai_diplomacy_suggest
static void dai_diplomacy_suggest(struct player *pplayer, struct player *aplayer, enum clause_type what, bool to_pplayer, int value)
Definition daidiplomacy.c:938
dai_treaty_react
static void dai_treaty_react(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Clause *pclause)
Definition daidiplomacy.c:697
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)
Definition daidiplomacy.c:223
clear_old_treaty
static void clear_old_treaty(struct player *pplayer, struct player *aplayer)
Definition daidiplomacy.c:1228
dai_diplo_notify
static void dai_diplo_notify(struct player *pplayer, const char *text,...)
Definition daidiplomacy.c:103
dai_incident_nuclear
static void dai_incident_nuclear(struct player *receiver, const struct player *violator, const struct player *victim)
Definition daidiplomacy.c:2091
dai_incident_war
static void dai_incident_war(struct player *violator, struct player *victim)
Definition daidiplomacy.c:2170
war_countdown
static void war_countdown(struct ai_type *ait, struct player *pplayer, struct player *target, int countdown, enum war_reason reason)
Definition daidiplomacy.c:1429
dai_share
static void dai_share(struct ai_type *ait, struct player *pplayer, struct player *aplayer)
Definition daidiplomacy.c:1249
shared_vision_is_safe
static bool shared_vision_is_safe(struct player *pplayer, struct player *aplayer)
Definition daidiplomacy.c:183
dai_war_desire
static int dai_war_desire(struct ai_type *ait, struct player *pplayer, struct player *target)
Definition daidiplomacy.c:799
TURNS_BEFORE_TARGET
#define TURNS_BEFORE_TARGET
Definition daidiplomacy.c:79
diplomacy_verbose
static bool diplomacy_verbose
Definition daidiplomacy.c:76
dai_diplomacy_first_contact
void dai_diplomacy_first_contact(struct ai_type *ait, struct player *pplayer, struct player *aplayer)
Definition daidiplomacy.c:960
daidiplomacy.h
dailog.h
DIPLO_LOG
#define DIPLO_LOG(ait, loglevel, pplayer, aplayer, msg,...)
Definition dailog.h:53
daimilitary.h
daiplayer.h
def_ai_player_data
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
WAR
#define WAR(plr1, plr2)
Definition daiunit.h:62
NEVER_MET
#define NEVER_MET(plr1, plr2)
Definition daiunit.h:64
ATTACK_POWER
#define ATTACK_POWER(ptype)
Definition daiunit.h:68
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
cost
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
handle_diplomacy_create_clause_req
void handle_diplomacy_create_clause_req(struct player *pplayer, int counterpart, int giver, enum clause_type type, int value)
Definition diplhand.c:756
handle_diplomacy_init_meeting_req
void handle_diplomacy_init_meeting_req(struct player *pplayer, int counterpart)
Definition diplhand.c:848
handle_diplomacy_accept_treaty_req
void handle_diplomacy_accept_treaty_req(struct player *pplayer, int counterpart)
Definition diplhand.c:150
diplhand.h
ptreaty
struct Treaty * ptreaty
Definition diplodlg_g.h:28
diplomacy_possible
bool diplomacy_possible(const struct player *pplayer1, const struct player *pplayer2)
Definition diptreaty.c:36
find_treaty
struct Treaty * find_treaty(struct player *plr0, struct player *plr1)
Definition diptreaty.c:346
could_meet_with_player
bool could_meet_with_player(const struct player *pplayer, const struct player *aplayer)
Definition diptreaty.c:64
diptreaty.h
clause_list_iterate_end
#define clause_list_iterate_end
Definition diptreaty.h:70
clause_list_iterate
#define clause_list_iterate(clauselist, pclause)
Definition diptreaty.h:68
is_pact_clause
#define is_pact_clause(x)
Definition diptreaty.h:51
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
events.h
Tech_type_id
int Tech_type_id
Definition fc_types.h:380
ACTRES_NONE
#define ACTRES_NONE
Definition fc_types.h:330
O_SHIELD
@ O_SHIELD
Definition fc_types.h:101
O_TRADE
@ O_TRADE
Definition fc_types.h:101
fcintl.h
PL_
#define PL_(String1, String2, n)
Definition fcintl.h:71
_
#define _(String)
Definition fcintl.h:67
ftc_chat_private
const struct ft_color ftc_chat_private
Definition featured_text.c:88
game
struct civ_game game
Definition game.c:62
game.h
type
GType type
Definition repodlgs.c:1313
handle_player_change_government
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:566
handle_diplomacy_cancel_pact
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:878
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps.h
H_DIPLOMACY
@ H_DIPLOMACY
Definition handicaps.h:29
H_AWAY
@ H_AWAY
Definition handicaps.h:19
H_CEASEFIRE
@ H_CEASEFIRE
Definition handicaps.h:33
impr_build_shield_cost
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:294
is_great_wonder
bool is_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:772
improvement_obsolete
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
Definition improvement.c:411
is_small_wonder
bool is_small_wonder(const struct impr_type *pimprove)
Definition improvement.c:780
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
log_base
#define log_base(level, message,...)
Definition log.h:94
LOG_ERROR
@ LOG_ERROR
Definition log.h:30
LOG_DEBUG
@ LOG_DEBUG
Definition log.h:34
log_error
#define log_error(message,...)
Definition log.h:103
map_size_checked
#define map_size_checked()
Definition map.h:271
remove_shared_vision
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1690
maphand.h
mem.h
nation.h
vpackage_event
void vpackage_event(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format, va_list vargs)
Definition notify.c:147
event_cache_add_for_player
void event_cache_add_for_player(const struct packet_chat_msg *packet, const struct player *pplayer)
Definition notify.c:646
notify.h
packets.h
lsend_packet_chat_msg
void lsend_packet_chat_msg(struct conn_list *dest, const struct packet_chat_msg *packet)
Definition packets_gen.c:11543
dlsend_packet_diplomacy_remove_clause
void dlsend_packet_diplomacy_remove_clause(struct conn_list *dest, int counterpart, int giver, enum clause_type type, int value)
Definition packets_gen.c:35685
cities
struct city_list * cities
Definition packhand.c:119
players_on_same_team
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1476
player_slot_count
int player_slot_count(void)
Definition player.c:418
player_number
int player_number(const struct player *pplayer)
Definition player.c:837
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:895
pplayers_at_war
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
player_index
int player_index(const struct player *pplayer)
Definition player.c:829
player_in_territory
int player_in_territory(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1878
pplayer_can_cancel_treaty
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:98
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
pplayers_non_attack
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1459
player_has_embassy
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:208
gives_shared_vision
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1485
pplayers_in_peace
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1426
player.h
players_iterate_end
#define players_iterate_end
Definition player.h:537
DIPL_SENATE_BLOCKING
@ DIPL_SENATE_BLOCKING
Definition player.h:191
DIPL_OK
@ DIPL_OK
Definition player.h:191
players_iterate
#define players_iterate(_pplayer)
Definition player.h:532
MAX_AI_LOVE
#define MAX_AI_LOVE
Definition player.h:561
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
is_ai
#define is_ai(plr)
Definition player.h:230
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:547
is_human
#define is_human(plr)
Definition player.h:229
players_iterate_alive
#define players_iterate_alive(_pplayer)
Definition player.h:542
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:56
research_goal_tech_req
bool research_goal_tech_req(const struct research *presearch, Tech_type_id goal, Tech_type_id tech)
Definition research.c:807
player_tech_upkeep
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1050
research_goal_bulbs_required
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:772
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
research_invention_gettable
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:693
research.h
shared.h
MIN
#define MIN(x, y)
Definition shared.h:55
MAX
#define MAX(x, y)
Definition shared.h:54
spaceship.h
SSHIP_STARTED
@ SSHIP_STARTED
Definition spaceship.h:84
SSHIP_LAUNCHED
@ SSHIP_LAUNCHED
Definition spaceship.h:85
SSHIP_NONE
@ SSHIP_NONE
Definition spaceship.h:84
srv_log.h
Clause
Definition diptreaty.h:72
Clause::type
enum clause_type type
Definition diptreaty.h:73
Clause::from
struct player * from
Definition diptreaty.h:74
Clause::value
int value
Definition diptreaty.h:75
Treaty
Definition diptreaty.h:78
Treaty::plr0
struct player * plr0
Definition diptreaty.h:79
Treaty::clauses
struct clause_list * clauses
Definition diptreaty.h:81
action
Definition actions.h:360
adv_data
Definition advdata.h:50
adv_data::dipl
struct adv_data::@92 dipl
adv_data::spacerace_leader
struct player * spacerace_leader
Definition advdata.h:104
ai_dip_intel
Definition daidata.h:53
ai_dip_intel::distance
int distance
Definition daidata.h:60
ai_dip_intel::countdown
int countdown
Definition daidata.h:61
ai_plr
Definition daidata.h:71
ai_plr::diplomacy
struct ai_plr::@252 diplomacy
ai_plr::tech_want
adv_want tech_want[A_LAST+1]
Definition daidata.h:103
ai_plr::req_love_for_alliance
int req_love_for_alliance
Definition daidata.h:96
ai_plr::love_incr
char love_incr
Definition daidata.h:94
ai_plr::love_coeff
char love_coeff
Definition daidata.h:93
ai_plr::req_love_for_peace
int req_love_for_peace
Definition daidata.h:95
ai_plr::strategy
enum winning_strategy strategy
Definition daidata.h:91
ai_type
Definition ai.h:50
city
Definition city.h:320
civ_game::diplgoldcost
int diplgoldcost
Definition game.h:140
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::server
struct civ_game::@31::@35 server
civ_game::government_during_revolution
struct government * government_during_revolution
Definition game.h:94
government
Definition government.h:52
packet_chat_msg
Definition packets_gen.h:291
packet_game_info::government_during_revolution_id
Government_type_id government_during_revolution_id
Definition packets_gen.h:171
packet_game_info::tech_upkeep_style
enum tech_upkeep_style tech_upkeep_style
Definition packets_gen.h:229
packet_game_info::tech_leak_pct
int tech_leak_pct
Definition packets_gen.h:126
packet_game_info::tech_leakage
enum tech_leakage_style tech_leakage
Definition packets_gen.h:227
packet_game_info::tech_trade_allow_holes
bool tech_trade_allow_holes
Definition packets_gen.h:212
packet_game_info::turn
int turn
Definition packets_gen.h:241
packet_game_info::tech_cost_style
enum tech_cost_style tech_cost_style
Definition packets_gen.h:226
player_ai::love
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:122
player_diplstate
Definition player.h:196
player_diplstate::first_contact_turn
int first_contact_turn
Definition player.h:199
player_diplstate::type
enum diplstate_type type
Definition player.h:197
player_diplstate::has_reason_to_cancel
char has_reason_to_cancel
Definition player.h:201
player_economic::gold
int gold
Definition player.h:61
player_spaceship
Definition spaceship.h:94
player
Definition player.h:247
player::cities
struct city_list * cities
Definition player.h:279
player::bulbs_last_turn
int bulbs_last_turn
Definition player.h:349
player::ai_common
struct player_ai ai_common
Definition player.h:286
player::government
struct government * government
Definition player.h:256
player::team
struct team * team
Definition player.h:259
player::ai
const struct ai_type * ai
Definition player.h:287
player::units
struct unit_list * units
Definition player.h:280
player::connections
struct conn_list * connections
Definition player.h:296
player::is_alive
bool is_alive
Definition player.h:266
player::economic
struct player_economic economic
Definition player.h:282
player::spaceship
struct player_spaceship spaceship
Definition player.h:284
player::server
struct player::@70::@72 server
research
Definition research.h:39
research::researching
Tech_type_id researching
Definition research.h:52
research::tech_goal
Tech_type_id tech_goal
Definition research.h:83
research::techs_researched
int techs_researched
Definition research.h:42
unit_type
Definition unittype.h:500
unit_type::adv
struct unit_type::@87 adv
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
advance_by_number
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
advance_rule_name
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
tech.h
advance_index_iterate_max
#define advance_index_iterate_max(_start, _index, _max)
Definition tech.h:252
advance_index_iterate_end
#define advance_index_iterate_end
Definition tech.h:248
advance_index_iterate_max_end
#define advance_index_iterate_max_end
Definition tech.h:258
advance_count
static Tech_type_id advance_count(void)
Definition tech.h:170
A_FIRST
#define A_FIRST
Definition tech.h:44
A_NONE
#define A_NONE
Definition tech.h:43
advance_index_iterate
#define advance_index_iterate(_start, _index)
Definition tech.h:244
TRAIT_MAX_VALUE_SR
#define TRAIT_MAX_VALUE_SR
Definition traits.h:34
unit_is_cityfounder
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2637
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
utype_is_cityfounder
bool utype_is_cityfounder(const struct unit_type *utype)
Definition unittype.c:2951