Freeciv-3.3
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 "daicity.h"
60#include "daidata.h"
61#include "dailog.h"
62#include "daimilitary.h"
63#include "daiplayer.h"
64#include "daiunit.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 */
76static 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,
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/******************************************************************/
103static 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);
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/******************************************************************/
124static 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/******************************************************************/
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/******************************************************************/
157static 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);
163 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
164
165 if (TECH_KNOWN == state
168 return 0;
169 }
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/******************************************************************/
183static 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 }
190 if (eplayer == pplayer || eplayer == aplayer) {
191 continue;
192 }
195
196 if (ds != DS_NO_CONTACT && ds != DS_ALLIANCE) {
197 return FALSE;
198 }
199 }
201 return TRUE;
202}
203
204/******************************************************************/
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/******************************************************************/
223static 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. */
243 == TECH_KNOWN) {
244 return 0;
245 }
246
247 /* Calculate in tech leak to our opponents, guess 50% chance */
249 if (eplayer == giver
250 || eplayer == taker
252 tech_id) == TECH_KNOWN) {
253 continue;
254 }
255
256 /* Don't risk it falling into enemy hands */
258 && adv_is_player_dangerous(giver, eplayer)) {
259 *is_dangerous = TRUE;
260 }
261
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 }
268
269 return worth;
270}
271
272/******************************************************************/
275static const struct player *
277 const struct player *them)
278{
280 if (aplayer != us
281 && aplayer != them
284 return aplayer;
285 }
287 return NULL;
288}
289
290/******************************************************************/
297static int dai_goldequiv_clause(struct ai_type *ait,
298 struct player *pplayer,
299 struct player *aplayer,
300 struct Clause *pclause,
301 bool verbose,
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;
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
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)
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",
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. */
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),
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),
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),
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),
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)]
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)]
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)]
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),
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)
439 worth = 0;
440 } else {
441 int turns = game.info.turn;
442
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,
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)) {
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 }
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;
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:
605 break;
606 } /* end of switch */
607
608 if (close_here) {
609 dai_data_phase_finished(ait, pplayer);
610 }
611
613 return worth;
614}
615
616/******************************************************************/
620void 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;
627 int given_cities = 0;
628
630 if (is_pact_clause(pclause->type)) {
632 }
633 if (pclause->type == CLAUSE_CITY && pclause->from == pplayer) {
634 given_cities++;
635 }
637
638 /* Evaluate clauses */
640 const struct research *presearch = research_get(pplayer);
641
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
649 || pclause->value == research_get(pplayer)->tech_goal
650 || pclause->value == research_get(pplayer)->researching
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. */
658 }
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) {
678 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was good: %d",
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),
687 }
688 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was bad: %d",
690 }
691}
692
693/******************************************************************/
697static 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),
710 } else {
711 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, may we forever stand united, %s."),
712 player_name(pplayer),
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),
726 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign ceasefire");
727 break;
728 default:
729 break;
730 }
731}
732
733/******************************************************************/
740void 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;
749
750 ai = dai_plr_data_get(ait, pplayer, &close_here);
751
752 fc_assert_ret(pplayer != aplayer);
753
755 if (is_pact_clause(pclause->type)) {
757 }
759
760 /* Evaluate clauses */
762 int balance =
764
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 }
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/******************************************************************/
799static 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. */
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 }
830 unit_list_iterate(target->units, punit) {
831 const struct unit_type *ptype = unit_type_get(punit);
832
834
835 /* Fear enemy expansionism */
837 want += 100;
838 }
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 */
847 want -= 200;
848 settlers++;
849 }
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++;
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) {
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. */
890 bool cancel_excuse =
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 }
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/******************************************************************/
938static 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
953 : pplayer),
954 what, value);
955}
956
957/******************************************************************/
960void 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));
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) {
984 }
985 }
986 }
987
988 if (wants_ceasefire) {
990 _("*%s (AI)* Greetings %s! May we suggest a ceasefire "
991 "while we get to know each other better?"),
992 player_name(pplayer),
994 clear_old_treaty(pplayer, aplayer);
996 } else {
998 _("*%s (AI)* I found you %s! Now make it worth my "
999 "letting you live, or be crushed."),
1000 player_name(pplayer),
1002 }
1003}
1004
1005/******************************************************************/
1014void 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);
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 */
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 }
1042 }
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. */
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 */
1070 if (WAR(eplayer, aplayer) && WAR(pplayer, eplayer)) {
1071 amount += ai->diplomacy.love_incr / 4;
1072 }
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;
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;
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. */
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,
1107 * ((adip->is_allied_with_enemy != NULL) + 1));
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)] +=
1119 }
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) {
1130 }
1131 }
1132
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));
1150}
1151
1152/******************************************************************/
1155static void suggest_tech_exchange(struct ai_type *ait,
1156 struct player *player1,
1157 struct player *player2)
1158{
1162 int worth[ac];
1163 bool is_dangerous;
1164
1165 worth[A_NONE] = 0;
1166
1169 == TECH_KNOWN) {
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 {
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 }
1196
1198 if (worth[tech] <= 0) {
1199 continue;
1200 }
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) {
1214 if (diff > 0) {
1216 } else if (diff < 0) {
1218 }
1219 return;
1220 }
1223}
1224
1225/******************************************************************/
1228static 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 */
1236 player_number(pplayer),
1237 player_number(pclause->from),
1238 pclause->type, pclause->value);
1239 free(pclause);
1242 old_treaty->clauses = clause_list_new();
1243 }
1244}
1245
1246/******************************************************************/
1249static void dai_share(struct ai_type *ait, struct player *pplayer,
1250 struct player *aplayer)
1251{
1252 struct research *presearch = research_get(pplayer);
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)) {
1272 }
1274 }
1275
1276 /* Only give shared vision if safe. Only ask for shared vision if fair. */
1278 if (!gives_vision
1279 && shared_vision_is_safe(pplayer, aplayer)) {
1282 }
1283 if (gives_vision
1284 && !gives_shared_vision(aplayer, pplayer)
1285 && (is_human(aplayer)
1286 || shared_vision_is_safe(aplayer, pplayer))) {
1288 }
1289
1290 if (!player_has_embassy(pplayer, aplayer)) {
1292 }
1293 if (!player_has_embassy(aplayer, pplayer)) {
1295 }
1296
1297 if (!has_handicap(pplayer, H_DIPLOMACY) || is_human(aplayer)) {
1298 suggest_tech_exchange(ait, pplayer, aplayer);
1299 }
1300}
1301
1302/******************************************************************/
1309static void dai_declare_war(struct ai_type *ait, struct player *pplayer,
1310 struct player *target)
1311{
1312 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1313
1314 /* This will take us straight to war. */
1315 while (player_diplstate_get(pplayer, target)->type != DS_WAR) {
1316 if (pplayer_can_cancel_treaty(pplayer, target) != DIPL_OK) {
1317 DIPLO_LOG(ait, LOG_ERROR, pplayer, target,
1318 "Wanted to cancel treaty but was unable to.");
1319 adip->countdown = -1; /* War declaration aborted */
1320
1321 return;
1322 }
1324 }
1325
1326 /* Throw a tantrum */
1327 if (pplayer->ai_common.love[player_index(target)] > 0) {
1328 pplayer->ai_common.love[player_index(target)] = -1;
1329 }
1330 pplayer->ai_common.love[player_index(target)] -= MAX_AI_LOVE / 8;
1331
1332 fc_assert(!gives_shared_vision(pplayer, target));
1333
1334 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "war declared");
1335}
1336
1337/******************************************************************/
1342static void dai_go_to_war(struct ai_type *ait, struct player *pplayer,
1343 struct player *target, enum war_reason reason)
1344{
1345 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1346
1347 fc_assert_ret(pplayer != target);
1348 fc_assert_ret(target->is_alive);
1349
1350 switch (reason) {
1351 case DAI_WR_SPACE:
1352 dai_diplo_notify(target, _("*%s (AI)* Space will never be yours."),
1353 player_name(pplayer));
1354 adip->countdown = -10;
1355 break;
1356 case DAI_WR_BEHAVIOUR:
1357 dai_diplo_notify(target,
1358 _("*%s (AI)* I have tolerated your vicious antics "
1359 "long enough! To war!"),
1360 player_name(pplayer));
1361 adip->countdown = -20;
1362 break;
1363 case DAI_WR_NONE:
1364 dai_diplo_notify(target, _("*%s (AI)* Peace in ... some other time."),
1365 player_name(pplayer));
1366 adip->countdown = -10;
1367 break;
1368 case DAI_WR_HATRED:
1369 dai_diplo_notify(target,
1370 _("*%s (AI)* Finally I get around to you! Did "
1371 "you really think you could get away with your crimes?"),
1372 player_name(pplayer));
1373 adip->countdown = -20;
1374 break;
1375 case DAI_WR_EXCUSE:
1376 dai_diplo_notify(target,
1377 _("*%s (AI)* Your covert hostilities brought "
1378 "this war upon you!"),
1379 player_name(pplayer));
1380 adip->countdown = -20;
1381 break;
1382 case DAI_WR_ALLIANCE:
1383 if (adip->at_war_with_ally) {
1384 dai_diplo_notify(target,
1385 _("*%s (AI)* Your aggression against %s was "
1386 "your last mistake!"),
1387 player_name(pplayer),
1388 player_name(adip->at_war_with_ally));
1389 adip->countdown = -3;
1390 } else {
1391 /* Ooops! */
1392 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "Wanted to declare war "
1393 "for their war against an ally, but can no longer find "
1394 "this ally! War declaration aborted.");
1395 adip->countdown = -1;
1396 return;
1397 }
1398 break;
1399 }
1400
1401 fc_assert_ret(adip->countdown < 0);
1402
1403 if (gives_shared_vision(pplayer, target)) {
1404 remove_shared_vision(pplayer, target);
1405 }
1406
1407 /* Check for Senate obstruction. If so, dissolve it. */
1408 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_SENATE_BLOCKING) {
1409 struct government *real_gov = pplayer->government;
1410
1412
1413 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_OK) {
1414 /* It seems that revolution would help. */
1415 pplayer->government = real_gov;
1418 def_ai_player_data(pplayer, ait)->diplomacy.war_target = target;
1419 return;
1420 } else {
1421 /* There would be Senate even during revolution. Better not to revolt for nothing */
1422 pplayer->government = real_gov;
1423 adip->countdown = -1; /* War declaration aborted */
1424
1425 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target,
1426 "Not revolting, as there would be Senate regardless.");
1427
1428 return;
1429 }
1430 }
1431
1432 dai_declare_war(ait, pplayer, target);
1433}
1434
1435/******************************************************************/
1441void dai_revolution_start(struct ai_type *ait, struct player *pplayer)
1442{
1443 struct ai_plr *data = def_ai_player_data(pplayer, ait);
1444
1445 if (data->diplomacy.war_target != NULL) {
1446 dai_declare_war(ait, pplayer, data->diplomacy.war_target);
1447
1448 data->diplomacy.war_target = NULL;
1449 }
1450}
1451
1452/******************************************************************/
1464static void war_countdown(struct ai_type *ait, struct player *pplayer,
1465 struct player *target,
1466 int countdown, enum war_reason reason)
1467{
1468 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1469
1470 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "countdown to war in %d", countdown);
1471
1472 /* Otherwise we're resetting an existing countdown, which is very bad */
1473 fc_assert_ret(adip->countdown == -1);
1474
1475 adip->countdown = countdown;
1476 adip->war_reason = reason;
1477
1479 if (!pplayers_allied(pplayer, ally)
1480 || ally == target
1481 || NEVER_MET(pplayer, ally)) {
1482 continue;
1483 }
1484
1485 switch (reason) {
1486 case DAI_WR_SPACE:
1488 PL_("*%s (AI)* We will be launching an all-out war "
1489 "against %s in %d turn to stop the spaceship "
1490 "launch.",
1491 "*%s (AI)* We will be launching an all-out war "
1492 "against %s in %d turns to stop the spaceship "
1493 "launch.",
1494 countdown),
1495 player_name(pplayer),
1496 player_name(target),
1497 countdown);
1499 _("*%s (AI)* Your aid in this matter will be expected. "
1500 "Long live our glorious alliance!"),
1501 player_name(pplayer));
1502 break;
1503 case DAI_WR_BEHAVIOUR:
1504 case DAI_WR_EXCUSE:
1506 PL_("*%s (AI)* %s has grossly violated their treaties "
1507 "with us for own gain. We will answer in force in "
1508 "%d turn and expect you to honor your alliance "
1509 "with us and do likewise!",
1510 "*%s (AI)* %s has grossly violated their treaties "
1511 "with us for own gain. We will answer in force in "
1512 "%d turns and expect you to honor your alliance "
1513 "with us and do likewise!", countdown),
1514 player_name(pplayer),
1515 player_name(target),
1516 countdown);
1517 break;
1518 case DAI_WR_NONE:
1520 PL_("*%s (AI)* We intend to pillage and plunder the rich "
1521 "civilization of %s. We declare war in %d turn.",
1522 "*%s (AI)* We intend to pillage and plunder the rich "
1523 "civilization of %s. We declare war in %d turns.",
1524 countdown),
1525 player_name(pplayer),
1526 player_name(target),
1527 countdown);
1529 _("*%s (AI)* If you want a piece of the loot, feel "
1530 "free to join in the action!"),
1531 player_name(pplayer));
1532 break;
1533 case DAI_WR_HATRED:
1535 PL_("*%s (AI)* We have had it with %s. Let us tear this "
1536 "pathetic civilization apart. We declare war in "
1537 "%d turn.",
1538 "*%s (AI)* We have had it with %s. Let us tear this "
1539 "pathetic civilization apart. We declare war in "
1540 "%d turns.",
1541 countdown),
1542 player_name(pplayer),
1543 player_name(target),
1544 countdown);
1546 _("*%s (AI)* As our glorious allies, we expect your "
1547 "help in this war."),
1548 player_name(pplayer));
1549 break;
1550 case DAI_WR_ALLIANCE:
1551 if (WAR(ally, target)) {
1553 PL_("*%s (AI)* We will honor our alliance and declare "
1554 "war on %s in %d turn. Hold on - we are coming!",
1555 "*%s (AI)* We will honor our alliance and declare "
1556 "war on %s in %d turns. Hold on - we are coming!",
1557 countdown),
1558 player_name(pplayer),
1559 player_name(target),
1560 countdown);
1561 } else if (adip->at_war_with_ally) {
1563 PL_("*%s (AI)* We will honor our alliance with %s and "
1564 "declare war on %s in %d turns. We expect you to "
1565 "do likewise.",
1566 "*%s (AI)* We will honor our alliance with %s and "
1567 "declare war on %s in %d turns. We expect you to "
1568 "do likewise.",
1569 countdown),
1570 player_name(pplayer),
1571 player_name(adip->at_war_with_ally),
1572 player_name(target),
1573 countdown);
1574 } else {
1575 fc_assert(FALSE); /* Huh? */
1576 }
1577 break;
1578 }
1580}
1581
1582/******************************************************************/
1588void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
1589{
1590 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1591 bool need_targets = TRUE;
1592 struct player *target = NULL;
1594 int war_threshold;
1595 int aggr;
1596 float aggr_sr;
1597 float max_sr;
1598
1599 fc_assert_ret(is_ai(pplayer));
1600
1601 if (!pplayer->is_alive) {
1602 return;
1603 }
1604
1605 if (get_player_bonus(pplayer, EFT_NO_DIPLOMACY) > 0) {
1606 /* Diplomacy disabled for this player */
1607 return;
1608 }
1609
1610 /*** If we are greviously insulted, go to war immediately. ***/
1611
1613 if (pplayer->ai_common.love[player_index(aplayer)] < 0
1614 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel >= 2
1615 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown == -1) {
1616 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Plans war in revenge");
1617 war_countdown(ait, pplayer, aplayer, map_size_checked(),
1619 }
1621
1622 /*** Stop other players from winning by space race ***/
1623
1624 if (ai->diplomacy.strategy != WIN_SPACE) {
1625 struct adv_data *adv = adv_data_get(pplayer, NULL);
1626
1628 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1629 struct player_spaceship *ship = &aplayer->spaceship;
1630
1631 if (aplayer == pplayer
1632 || adip->countdown >= 0 /* already counting down to war */
1633 || ship->state == SSHIP_NONE
1634 || players_on_same_team(pplayer, aplayer)
1635 || pplayers_at_war(pplayer, aplayer)) {
1636 continue;
1637 }
1638
1639 /* A spaceship victory is always one single player's or team's victory */
1640 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1641 && adv->dipl.spacerace_leader == aplayer
1642 && pplayers_allied(pplayer, aplayer)) {
1644 _("*%s (AI)* Your attempt to conquer space for "
1645 "yourself alone betrays your true intentions, and I "
1646 "will have no more of our alliance!"),
1647 player_name(pplayer));
1650 if (gives_shared_vision(pplayer, aplayer)) {
1651 remove_shared_vision(pplayer, aplayer);
1652 }
1653 /* Never forgive this */
1655 } else if (ship->state == SSHIP_STARTED
1656 && adip->warned_about_space == 0) {
1657 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 10;
1658 adip->warned_about_space = 10 + fc_rand(6);
1660 _("*%s (AI)* Your attempt to unilaterally "
1661 "dominate outer space is highly offensive."),
1662 player_name(pplayer));
1664 _("*%s (AI)* If you do not stop constructing your "
1665 "spaceship, I may be forced to take action!"),
1666 player_name(pplayer));
1667 }
1668 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1669 && aplayer == adv->dipl.spacerace_leader) {
1670 /* This means war!!! */
1671 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 2;
1672 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "plans war due to spaceship");
1673 war_countdown(ait, pplayer, aplayer, 4 + map_size_checked(),
1674 DAI_WR_SPACE);
1675 }
1677 }
1678
1679 /*** Declare war against somebody if we are out of targets ***/
1680
1682 int turns; /* turns since contact */
1683
1684 if (NEVER_MET(pplayer, aplayer)) {
1685 continue;
1686 }
1687 turns = game.info.turn;
1689 if (WAR(pplayer, aplayer)) {
1691 } else if (pplayer->ai_common.love[player_index(aplayer)] < most_hatred
1692 && turns > TURNS_BEFORE_TARGET) {
1694 target = aplayer;
1695 }
1697
1700 aggr_sr = sqrt(aggr);
1701
1702 war_threshold = (MAX_AI_LOVE * (0.70 + aggr_sr / max_sr / 2.0)) - MAX_AI_LOVE;
1703
1704 if (need_targets && target && most_hatred < war_threshold
1705 && dai_diplomacy_get(ait, pplayer, target)->countdown == -1) {
1706 enum war_reason war_reason;
1707
1708 if (pplayers_allied(pplayer, target)) {
1709 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "Plans war against an ally!");
1710 }
1711 if (player_diplstate_get(pplayer, target)->has_reason_to_cancel > 0) {
1712 /* We have good reason */
1713 war_reason = DAI_WR_EXCUSE;
1714 } else if (pplayer->ai_common.love[player_index(target)] < 0) {
1715 /* We have a reason of sorts from way back, maybe? */
1716 war_reason = DAI_WR_HATRED;
1717 } else {
1718 /* We have no legimitate reason... So what? */
1719 war_reason = DAI_WR_NONE;
1720 }
1721 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "plans war for spoils");
1722 war_countdown(ait, pplayer, target, 4 + map_size_checked(), war_reason);
1723 }
1724
1725 /*** Declare war - against enemies of allies ***/
1726
1728 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1729
1730 if (adip->at_war_with_ally
1731 && adip->countdown == -1
1732 && !adip->is_allied_with_ally
1733 && !pplayers_at_war(pplayer, aplayer)
1735 || fc_rand(5) < 1)) {
1736 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "plans war to help ally %s",
1737 player_name(adip->at_war_with_ally));
1738 war_countdown(ait, pplayer, aplayer, 2 + map_size_checked(),
1740 }
1742
1743 /*** Actually declare war (when we have moved units into position) ***/
1744
1746 if (!players_on_same_team(pplayer, aplayer)) {
1747 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1748
1749 if (!aplayer->is_alive) {
1750 adip->countdown = -1;
1751 continue;
1752 }
1753 if (adip->countdown > 0) {
1754 adip->countdown--;
1755 } else if (adip->countdown == 0) {
1756 if (!WAR(pplayer, aplayer)) {
1757 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Declaring war!");
1758 dai_go_to_war(ait, pplayer, aplayer, adip->war_reason);
1759 }
1760 } else if (adip->countdown < -1) {
1761 /* Negative countdown less than -1 is war stubbornness */
1762 adip->countdown++;
1763 }
1764 }
1766
1767 /*** Try to make peace with everyone we love ***/
1768
1771 && diplomacy_possible(pplayer, aplayer)) {
1773 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1774 struct Clause clause;
1775
1776 /* Meaningless values, but rather not have them unset. */
1777 clause.from = pplayer;
1778 clause.value = 0;
1779
1780 /* Remove shared vision if we are not allied or it is no longer safe. */
1781 if (gives_shared_vision(pplayer, aplayer)) {
1782 if (!pplayers_allied(pplayer, aplayer)) {
1783 remove_shared_vision(pplayer, aplayer);
1784 } else if (!players_on_same_team(pplayer, aplayer)
1785 && !shared_vision_is_safe(pplayer, aplayer)) {
1787 _("*%s (AI)* Sorry, sharing vision with you "
1788 "is no longer safe."),
1789 player_name(pplayer));
1790 remove_shared_vision(pplayer, aplayer);
1791 }
1792 }
1793
1794 /* No peace to enemies of our allies... or pointless peace. */
1796 || aplayer == pplayer
1797 || aplayer == target /* no mercy */
1798 || adip->countdown >= 0
1799 || !could_meet_with_player(pplayer, aplayer)) {
1800 continue;
1801 }
1802
1803 /* Spam control */
1804 adip->asked_about_peace = MAX(adip->asked_about_peace - 1, 0);
1805 adip->asked_about_alliance = MAX(adip->asked_about_alliance - 1, 0);
1806 adip->asked_about_ceasefire = MAX(adip->asked_about_ceasefire - 1, 0);
1807 adip->warned_about_space = MAX(adip->warned_about_space - 1, 0);
1808 adip->spam = MAX(adip->spam - 1, 0);
1809 if (adip->spam > 0 && is_ai(aplayer)) {
1810 /* Don't spam */
1811 continue;
1812 }
1813
1814 /* Canvass support from existing friends for our war, and try to
1815 * make friends with enemies. Then we wait some turns until next time
1816 * we spam them with our gibbering chatter. */
1817 if (adip->spam <= 0) {
1818 if (!pplayers_allied(pplayer, aplayer)) {
1819 adip->spam = fc_rand(4) + 3; /* Bugger allies often. */
1820 } else {
1821 adip->spam = fc_rand(8) + 6; /* Others are less important. */
1822 }
1823 }
1824
1825 switch (ds) {
1826 case DS_TEAM:
1827 dai_share(ait, pplayer, aplayer);
1828 break;
1829 case DS_ALLIANCE:
1830 /* See if our allies are diligently declaring war on our enemies... */
1831 if (adip->at_war_with_ally) {
1832 break;
1833 }
1834 target = NULL;
1836 if (WAR(pplayer, eplayer)
1838 target = eplayer;
1839 break;
1840 }
1842
1843 if ((players_on_same_team(pplayer, aplayer)
1844 || pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE / 2)) {
1845 /* Share techs only with team mates and allies we really like. */
1846 dai_share(ait, pplayer, aplayer);
1847 }
1848 if (!target || !target->is_alive) {
1849 adip->ally_patience = 0;
1850 break; /* No need to nag our ally */
1851 }
1852
1853 if (adip->spam <= 0) {
1854 /* Count down patience toward AI player (one that can have spam > 0)
1855 * at the same speed as toward human players. */
1856 if (adip->ally_patience == 0) {
1858 _("*%s (AI)* Greetings our most trustworthy "
1859 "ally. We call upon you to destroy our enemy, %s."),
1860 player_name(pplayer),
1861 player_name(target));
1862 adip->ally_patience--;
1863 } else if (adip->ally_patience == -1) {
1864 if (fc_rand(5) == 1) {
1866 _("*%s (AI)* Greetings ally, I see you have not yet "
1867 "made war with our enemy, %s. Why do I need to remind "
1868 "you of your promises?"),
1869 player_name(pplayer),
1870 player_name(target));
1871 adip->ally_patience--;
1872 }
1873 } else if (fc_rand(5) == 1
1874 && !players_on_same_team(pplayer, aplayer)) {
1876 _("*%s (AI)* Dishonored one, we made a pact of "
1877 "alliance, and yet you remain at peace with our mortal "
1878 "enemy, %s! This is unacceptable; our alliance is no "
1879 "more!"),
1880 player_name(pplayer),
1881 player_name(target));
1882 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer,
1883 "breaking useless alliance");
1884 /* To peace */
1888 = MIN(pplayer->ai_common.love[player_index(aplayer)], 0);
1889 if (gives_shared_vision(pplayer, aplayer)) {
1890 remove_shared_vision(pplayer, aplayer);
1891 }
1892
1894 }
1895 }
1896 break;
1897
1898 case DS_PEACE:
1899 clause.type = CLAUSE_ALLIANCE;
1900 if (adip->at_war_with_ally
1901 || (is_human(aplayer) && adip->asked_about_alliance > 0)
1902 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1903 FALSE, DS_ALLIANCE) < 0) {
1904 break;
1905 }
1906 clear_old_treaty(pplayer, aplayer);
1908 adip->asked_about_alliance = is_human(aplayer) ? 13 : 0;
1910 _("*%s (AI)* Greetings friend, may we suggest "
1911 "making a common cause and join in an alliance?"),
1912 player_name(pplayer));
1913 break;
1914
1915 case DS_CEASEFIRE:
1916 clause.type = CLAUSE_PEACE;
1917 if (adip->at_war_with_ally
1918 || (is_human(aplayer) && adip->asked_about_peace > 0)
1919 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1920 FALSE, DS_PEACE) < 0) {
1921 break;
1922 }
1923 clear_old_treaty(pplayer, aplayer);
1925 adip->asked_about_peace = is_human(aplayer) ? 12 : 0;
1927 _("*%s (AI)* Greetings neighbor, may we suggest "
1928 "more peaceful relations?"),
1929 player_name(pplayer));
1930 break;
1931
1932 case DS_NO_CONTACT: /* but we do have embassy! weird. */
1933 case DS_WAR:
1934 clause.type = CLAUSE_CEASEFIRE;
1935 if ((is_human(aplayer) && adip->asked_about_ceasefire > 0)
1936 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1937 FALSE, DS_CEASEFIRE) < 0) {
1938 break; /* Fight until the end! */
1939 }
1940 clear_old_treaty(pplayer, aplayer);
1942 adip->asked_about_ceasefire = is_human(aplayer) ? 9 : 0;
1944 _("*%s (AI)* We grow weary of this constant "
1945 "bloodshed. May we suggest a cessation of hostilities?"),
1946 player_name(pplayer));
1947 break;
1948
1949 case DS_ARMISTICE:
1950 break;
1951 default:
1952 fc_assert_msg(FALSE, "Unknown pact type %d.", ds);
1953 break;
1954 }
1955 }
1957}
1958
1959/******************************************************************/
1963bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
1964{
1965 players_iterate(plr) {
1966 if (dai_diplomacy_get(ait, pplayer, plr)->countdown >= 0) {
1967 return TRUE;
1968 }
1970
1971 return FALSE;
1972}
1973
1974/******************************************************************/
1977/* AI attitude call-backs */
1980 const struct action *paction,
1981 struct player *receiver,
1982 struct player *violator, struct player *victim)
1983{
1984 if (!is_ai(receiver) || violator == receiver) {
1985 return;
1986 }
1987
1988 /* Can only handle victim only and international incidents. */
1991
1992 switch (type) {
1993 case INCIDENT_ACTION:
1994 /* Feel free the change how the action results are grouped and how bad
1995 * the ai considers each group. */
1996 switch (paction->result) {
1997 case ACTRES_SPY_NUKE:
1998 case ACTRES_NUKE:
1999 case ACTRES_NUKE_UNITS:
2000 if (receiver == victim) {
2001 /* Tell the victim */
2003 } else if (violator == victim) {
2005 } else {
2007 }
2008 break;
2011 /* Snoping */
2012 dai_incident_simple(receiver, violator, victim, scope, 2);
2013 break;
2017 case ACTRES_STEAL_MAPS:
2018 /* Theft */
2019 dai_incident_simple(receiver, violator, victim, scope, 5);
2020 break;
2021 case ACTRES_EXPEL_UNIT:
2022 /* Unit position loss */
2023 dai_incident_simple(receiver, violator, victim, scope, 1);
2024 break;
2026 /* Unit weakening */
2027 dai_incident_simple(receiver, violator, victim, scope, 3);
2028 break;
2031 case ACTRES_BOMBARD:
2032 case ACTRES_ATTACK:
2033 case ACTRES_WIPE_UNITS:
2034 case ACTRES_SPY_ATTACK:
2036 /* Unit loss */
2037 dai_incident_simple(receiver, violator, victim, scope, 5);
2038 break;
2042 /* City loss */
2043 dai_incident_simple(receiver, violator, victim, scope, 10);
2044 break;
2050 /* Building loss */
2051 dai_incident_simple(receiver, violator, victim, scope, 5);
2052 break;
2053 case ACTRES_SPY_POISON:
2055 /* Population loss */
2056 dai_incident_simple(receiver, violator, victim, scope, 5);
2057 break;
2058 case ACTRES_FOUND_CITY:
2059 /* Terrain loss */
2060 dai_incident_simple(receiver, violator, victim, scope, 4);
2061 break;
2063 case ACTRES_PILLAGE:
2064 /* Extra loss */
2065 dai_incident_simple(receiver, violator, victim, scope, 2);
2066 break;
2067 case ACTRES_UNIT_MOVE:
2068 case ACTRES_TELEPORT:
2070 case ACTRES_SPY_ESCAPE:
2071 case ACTRES_TRADE_ROUTE:
2072 case ACTRES_MARKETPLACE:
2073 case ACTRES_HELP_WONDER:
2074 case ACTRES_JOIN_CITY:
2077 case ACTRES_HOME_CITY:
2078 case ACTRES_HOMELESS:
2080 case ACTRES_PARADROP:
2081 case ACTRES_PARADROP_CONQUER: /* TODO: Bigger incident */
2082 case ACTRES_AIRLIFT:
2083 case ACTRES_HEAL_UNIT:
2085 case ACTRES_CULTIVATE:
2086 case ACTRES_PLANT:
2087 case ACTRES_CLEAN:
2088 case ACTRES_FORTIFY:
2089 case ACTRES_ROAD:
2090 case ACTRES_CONVERT:
2091 case ACTRES_BASE:
2092 case ACTRES_MINE:
2093 case ACTRES_IRRIGATE:
2100 case ACTRES_HUT_ENTER:
2103 case ACTRES_NONE:
2104 /* Various */
2105 dai_incident_simple(receiver, violator, victim, scope, 1);
2106 break;
2107
2109 }
2110 break;
2111 case INCIDENT_WAR:
2112 if (receiver == victim) {
2114 }
2115 break;
2116 case INCIDENT_LAST:
2117 /* Assert that always fails, but with meaningful message */
2119 break;
2120 }
2121}
2122
2123/******************************************************************/
2126static void dai_incident_nuclear(struct player *receiver,
2127 const struct player *violator,
2128 const struct player *victim)
2129{
2130 fc_assert_ret(receiver == victim);
2131
2132 if (violator == victim) {
2133 return;
2134 }
2135
2136 receiver->ai_common.love[player_index(violator)] -= 3 * MAX_AI_LOVE / 10;
2137}
2138
2139/******************************************************************/
2142static void dai_incident_nuclear_not_target(struct player *receiver,
2143 const struct player *violator,
2144 const struct player *victim)
2145{
2146 fc_assert_ret(receiver != victim);
2147
2148 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2149}
2150
2151/******************************************************************/
2154static void dai_incident_nuclear_self(struct player *receiver,
2155 const struct player *violator,
2156 const struct player *victim)
2157{
2158 fc_assert_ret(receiver != victim);
2160
2161 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 20;
2162}
2163
2164/**********************************************************************/
2176static void dai_incident_simple(struct player *receiver,
2177 const struct player *violator,
2178 const struct player *victim,
2180 int how_bad)
2181{
2183 if (victim == receiver) {
2185 /* The ruleset finds this bad enough to cause International Outrage.
2186 * Trust the ruleset author. Double the displeasure. */
2188 }
2189 receiver->ai_common.love[player_index(violator)] -= displeasure / 35;
2190 } else if (violator == victim) {
2191 receiver->ai_common.love[player_index(violator)] -= displeasure / 1000;
2192 } else {
2193 receiver->ai_common.love[player_index(violator)] -= displeasure / 500;
2194 }
2195}
2196
2197/******************************************************************/
2205static void dai_incident_war(struct player *violator, struct player *victim)
2206{
2207 players_iterate(pplayer) {
2208 if (!is_ai(pplayer)) {
2209 continue;
2210 }
2211
2212 if (pplayer != violator) {
2213 /* Dislike backstabbing bastards */
2214 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2215 if (player_diplstate_get(violator, victim)->max_state == DS_PEACE) {
2216 /* Extra penalty if they once had a peace treaty */
2217 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2218 } else if (player_diplstate_get(violator, victim)->max_state
2219 == DS_ALLIANCE) {
2220 /* Extra penalty if they once had an alliance */
2221 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2222 }
2223 if (victim == pplayer) {
2224 pplayer->ai_common.love[player_index(violator)] =
2225 MIN(pplayer->ai_common.love[player_index(violator)] - MAX_AI_LOVE / 3, -1);
2226 /* Scream for help!! */
2228 if (!pplayers_allied(pplayer, ally)) {
2229 continue;
2230 }
2232 _("*%s (AI)* We have been savagely attacked by "
2233 "%s, and we need your help! Honor our glorious "
2234 "alliance and your name will never be forgotten!"),
2238 }
2239 }
2241}
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:604
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1106
adv_want amortize(adv_want benefit, int delay)
Definition advtools.c:29
incident_type
Definition ai.h:45
@ INCIDENT_LAST
Definition ai.h:46
@ INCIDENT_WAR
Definition ai.h:46
@ INCIDENT_ACTION
Definition ai.h:46
int player_distance_to_player(struct player *pplayer, struct player *target)
Definition aisupport.c:75
int city_gold_worth(struct city *pcity)
Definition aisupport.c:108
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:68
bool is_capital(const struct city *pcity)
Definition city.c:1575
const char * city_name_get(const struct city *pcity)
Definition city.c:1133
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1675
#define city_list_iterate(citylist, pcity)
Definition city.h:508
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
#define city_built_iterate(_pcity, _p)
Definition city.h:825
#define city_built_iterate_end
Definition city.h:831
char * incite_cost
Definition comments.c:74
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition daidata.c:308
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Definition daidata.c:402
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:285
@ WIN_SPACE
Definition daidata.h:34
@ WIN_CAPITAL
Definition daidata.h:35
@ WIN_OPEN
Definition daidata.h:32
void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
static void dai_incident_nuclear_not_target(struct player *receiver, const struct player *violator, const struct player *victim)
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)
bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
void dai_revolution_start(struct ai_type *ait, struct player *pplayer)
void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
static int dai_goldequiv_clause(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Clause *pclause, bool verbose, enum diplstate_type ds_after)
static const struct player * get_allied_with_enemy_player(const struct player *us, const struct player *them)
static void dai_incident_simple(struct player *receiver, const struct player *violator, const struct player *victim, enum casus_belli_range scope, int how_bad)
static void dai_incident_nuclear_self(struct player *receiver, const struct player *violator, const struct player *victim)
void dai_diplomacy_begin_new_phase(struct ai_type *ait, struct player *pplayer)
static void suggest_tech_exchange(struct ai_type *ait, struct player *player1, struct player *player2)
void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
#define LOG_DIPL2
static int greed(int missing_love)
static bool dai_players_can_agree_on_ceasefire(struct ai_type *ait, struct player *player1, struct player *player2)
static void dai_go_to_war(struct ai_type *ait, struct player *pplayer, struct player *target, enum war_reason reason)
static int dai_goldequiv_tech(struct ai_type *ait, struct player *pplayer, Tech_type_id tech)
#define BIG_NUMBER
#define LOG_DIPL
static enum diplstate_type pact_clause_to_diplstate_type(enum clause_type type)
static void dai_diplomacy_suggest(struct player *pplayer, struct player *aplayer, enum clause_type what, bool to_pplayer, int value)
static void dai_treaty_react(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Clause *pclause)
static int compute_tech_sell_price(struct ai_type *ait, struct player *giver, struct player *taker, int tech_id, bool *is_dangerous)
static void dai_declare_war(struct ai_type *ait, struct player *pplayer, struct player *target)
static void clear_old_treaty(struct player *pplayer, struct player *aplayer)
static void dai_diplo_notify(struct player *pplayer, const char *text,...)
static void dai_incident_nuclear(struct player *receiver, const struct player *violator, const struct player *victim)
static void dai_incident_war(struct player *violator, struct player *victim)
static void war_countdown(struct ai_type *ait, struct player *pplayer, struct player *target, int countdown, enum war_reason reason)
static void dai_share(struct ai_type *ait, struct player *pplayer, struct player *aplayer)
static bool shared_vision_is_safe(struct player *pplayer, struct player *aplayer)
static int dai_war_desire(struct ai_type *ait, struct player *pplayer, struct player *target)
#define TURNS_BEFORE_TARGET
static bool diplomacy_verbose
void dai_diplomacy_first_contact(struct ai_type *ait, struct player *pplayer, struct player *aplayer)
#define DIPLO_LOG(ait, loglevel, pplayer, aplayer, msg,...)
Definition dailog.h:53
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
#define WAR(plr1, plr2)
Definition daiunit.h:62
#define NEVER_MET(plr1, plr2)
Definition daiunit.h:64
#define ATTACK_POWER(ptype)
Definition daiunit.h:68
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
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
void handle_diplomacy_create_clause_req(struct player *pplayer, int counterpart, int giver, enum clause_type type, int value)
Definition diplhand.c:753
void handle_diplomacy_init_meeting_req(struct player *pplayer, int counterpart)
Definition diplhand.c:845
void handle_diplomacy_accept_treaty_req(struct player *pplayer, int counterpart)
Definition diplhand.c:147
struct Treaty * ptreaty
Definition diplodlg_g.h:28
bool diplomacy_possible(const struct player *pplayer1, const struct player *pplayer2)
Definition diptreaty.c:36
struct Treaty * find_treaty(struct player *plr0, struct player *plr1)
Definition diptreaty.c:362
bool could_meet_with_player(const struct player *pplayer, const struct player *aplayer)
Definition diptreaty.c:64
#define clause_list_iterate_end
Definition diptreaty.h:71
#define clause_list_iterate(clauselist, pclause)
Definition diptreaty.h:69
#define is_pact_clause(x)
Definition diptreaty.h:51
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
int Tech_type_id
Definition fc_types.h:381
#define ACTRES_NONE
Definition fc_types.h:331
@ O_SHIELD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const struct ft_color ftc_chat_private
struct civ_game game
Definition game.c:61
GType type
Definition repodlgs.c:1313
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:565
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:880
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
@ H_DIPLOMACY
Definition handicaps.h:29
@ H_AWAY
Definition handicaps.h:19
@ H_CEASEFIRE
Definition handicaps.h:33
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool is_small_wonder(const struct impr_type *pimprove)
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_base(level, message,...)
Definition log.h:94
@ LOG_ERROR
Definition log.h:30
@ LOG_DEBUG
Definition log.h:34
#define log_error(message,...)
Definition log.h:103
#define map_size_checked()
Definition map.h:257
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1700
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
void event_cache_add_for_player(const struct packet_chat_msg *packet, const struct player *pplayer)
Definition notify.c:646
void lsend_packet_chat_msg(struct conn_list *dest, const struct packet_chat_msg *packet)
void dlsend_packet_diplomacy_remove_clause(struct conn_list *dest, int counterpart, int giver, enum clause_type type, int value)
struct city_list * cities
Definition packhand.c:119
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1480
int player_slot_count(void)
Definition player.c:418
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
int player_index(const struct player *pplayer)
Definition player.c:829
int player_in_territory(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1884
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:98
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1463
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:208
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1489
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1430
#define players_iterate_end
Definition player.h:539
@ DIPL_SENATE_BLOCKING
Definition player.h:193
@ DIPL_OK
Definition player.h:193
#define players_iterate(_pplayer)
Definition player.h:534
#define MAX_AI_LOVE
Definition player.h:563
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#define is_ai(plr)
Definition player.h:232
#define players_iterate_alive_end
Definition player.h:549
#define is_human(plr)
Definition player.h:231
#define players_iterate_alive(_pplayer)
Definition player.h:544
#define fc_rand(_size)
Definition rand.h:56
bool research_goal_tech_req(const struct research *presearch, Tech_type_id goal, Tech_type_id tech)
Definition research.c:807
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1058
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:772
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:693
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
@ SSHIP_STARTED
Definition spaceship.h:84
@ SSHIP_LAUNCHED
Definition spaceship.h:85
@ SSHIP_NONE
Definition spaceship.h:84
enum clause_type type
Definition diptreaty.h:74
struct player * from
Definition diptreaty.h:75
int value
Definition diptreaty.h:76
struct player * plr0
Definition diptreaty.h:80
struct clause_list * clauses
Definition diptreaty.h:82
struct adv_data::@92 dipl
struct player * spacerace_leader
Definition advdata.h:104
enum war_reason war_reason
Definition daidata.h:62
int distance
Definition daidata.h:60
int countdown
Definition daidata.h:61
struct ai_plr::@277 diplomacy
adv_want tech_want[A_LAST+1]
Definition daidata.h:104
int req_love_for_alliance
Definition daidata.h:96
char love_incr
Definition daidata.h:94
char love_coeff
Definition daidata.h:93
struct player * war_target
Definition daidata.h:97
int req_love_for_peace
Definition daidata.h:95
enum winning_strategy strategy
Definition daidata.h:91
Definition ai.h:50
Definition city.h:320
int diplgoldcost
Definition game.h:140
struct packet_game_info info
Definition game.h:89
struct civ_game::@31::@35 server
struct government * government_during_revolution
Definition game.h:94
Government_type_id government_during_revolution_id
enum tech_upkeep_style tech_upkeep_style
enum tech_leakage_style tech_leakage
bool tech_trade_allow_holes
enum tech_cost_style tech_cost_style
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:124
int first_contact_turn
Definition player.h:201
enum diplstate_type type
Definition player.h:199
char has_reason_to_cancel
Definition player.h:203
struct city_list * cities
Definition player.h:281
int bulbs_last_turn
Definition player.h:351
struct player_ai ai_common
Definition player.h:288
struct government * government
Definition player.h:258
struct team * team
Definition player.h:261
const struct ai_type * ai
Definition player.h:289
struct unit_list * units
Definition player.h:282
struct conn_list * connections
Definition player.h:298
bool is_alive
Definition player.h:268
struct player_economic economic
Definition player.h:284
struct player_spaceship spaceship
Definition player.h:286
struct player::@70::@72 server
Tech_type_id researching
Definition research.h:52
Tech_type_id tech_goal
Definition research.h:83
int techs_researched
Definition research.h:42
struct unit_type::@87 adv
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:309
#define advance_index_iterate_max(_start, _index, _max)
Definition tech.h:253
#define advance_index_iterate_end
Definition tech.h:249
#define advance_index_iterate_max_end
Definition tech.h:259
static Tech_type_id advance_count(void)
Definition tech.h:170
#define A_FIRST
Definition tech.h:44
#define A_NONE
Definition tech.h:43
#define advance_index_iterate(_start, _index)
Definition tech.h:245
#define TRAIT_MAX_VALUE_SR
Definition traits.h:34
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2699
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_is_cityfounder(const struct unit_type *utype)
Definition unittype.c:2951