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 */
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 if (research->bulbs_researched < 0) {
355 worth = -BIG_NUMBER;
356 } else {
357 worth /= 2;
358 }
359 }
360 }
361 }
362 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "%s clause worth %d",
364 break;
365
366 case CLAUSE_ALLIANCE:
367 case CLAUSE_PEACE:
368 case CLAUSE_CEASEFIRE:
369 /* Don't do anything in away mode */
370 if (has_handicap(pplayer, H_AWAY)) {
371 dai_diplo_notify(aplayer, _("*%s (AI)* In away mode AI can't sign such a treaty."),
372 player_name(pplayer));
373 worth = -BIG_NUMBER;
374 break;
375 }
376
377 /* This guy is allied to one of our enemies. Only accept
378 * ceasefire. */
380 && pclause->type != CLAUSE_CEASEFIRE) {
381 dai_diplo_notify(aplayer, _("*%s (AI)* First break alliance with %s, %s."),
382 player_name(pplayer), player_name(penemy),
384 worth = -BIG_NUMBER;
385 break;
386 }
387
388 /* They were allied with an enemy at the begining of the turn. */
389 if (adip->is_allied_with_enemy
390 && pclause->type != CLAUSE_CEASEFIRE) {
391 dai_diplo_notify(aplayer, _("*%s (AI)* I would like to see you keep your "
392 "distance from %s for some time, %s."),
393 player_name(pplayer), player_name(adip->is_allied_with_enemy),
395 worth = -BIG_NUMBER;
396 break;
397 }
398
399 /* Steps of the treaty ladder */
400 if (pclause->type == CLAUSE_PEACE) {
401 const struct player_diplstate *ds
402 = player_diplstate_get(pplayer, aplayer);
403
404 if (!pplayers_non_attack(pplayer, aplayer)) {
405 dai_diplo_notify(aplayer, _("*%s (AI)* Let us first cease hostilities, %s."),
406 player_name(pplayer),
408 worth = -BIG_NUMBER;
409 } else if (ds->type == DS_CEASEFIRE && ds->turns_left > 4) {
410 dai_diplo_notify(aplayer, _("*%s (AI)* I wish to see you keep the current "
411 "ceasefire for a bit longer first, %s."),
412 player_name(pplayer),
414 worth = -BIG_NUMBER;
415 } else if (adip->countdown >= 0 || adip->countdown < -1) {
416 worth = -BIG_NUMBER; /* but say nothing */
417 } else {
418 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
420 }
421 } else if (pclause->type == CLAUSE_ALLIANCE) {
422 if (!pplayers_in_peace(pplayer, aplayer)) {
423 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
425 }
426 if (adip->countdown >= 0 || adip->countdown < -1) {
427 worth = -BIG_NUMBER; /* but say nothing */
428 } else {
429 worth += greed(pplayer->ai_common.love[player_index(aplayer)]
431 }
432 if (pplayer->ai_common.love[player_index(aplayer)] < MAX_AI_LOVE / 10) {
433 dai_diplo_notify(aplayer, _("*%s (AI)* I simply do not trust you with an "
434 "alliance yet, %s."),
435 player_name(pplayer),
437 worth = -BIG_NUMBER;
438 }
439 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ally clause worth %d", worth);
440 } else {
441 if (is_ai(pplayer) && is_ai(aplayer)
443 worth = 0;
444 } else {
445 int turns = game.info.turn;
446
448 if (turns < TURNS_BEFORE_TARGET) {
449 worth = 0; /* show some good faith */
450 break;
451 } else {
452 worth = greed(pplayer->ai_common.love[player_index(aplayer)]);
453 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ceasefire worth=%d love=%d "
454 "turns=%d", worth,
456 turns);
457 }
458 }
459 }
460
461 /* Let's all hold hands in one happy family! */
462 if (adip->is_allied_with_ally) {
463 worth /= 2;
464 break;
465 }
466
467 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "treaty clause worth %d", worth);
468 break;
469
470 case CLAUSE_GOLD:
471 if (give) {
472 worth -= pclause->value;
473 } else {
474 worth += pclause->value * (100 - game.server.diplgoldcost) / 100;
475 }
476 break;
477
478 case CLAUSE_SEAMAP:
479 if (!give || ds_after == DS_ALLIANCE) {
480 /* Useless to us - we're omniscient! And allies get it for free! */
481 worth = 0;
482 } else {
483 /* Very silly algorithm 1: Sea map more worth if enemy has more
484 cities. Reasoning is they have more use of seamap for settling
485 new areas the more cities they have already. */
486 worth -= 15 * city_list_size(aplayer->cities);
487 /* Don't like them? Don't give it to them! */
488 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 7, worth);
489 /* Make maps from novice player cheap */
490 if (has_handicap(pplayer, H_DIPLOMACY)) {
491 worth /= 2;
492 }
493 }
494 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "seamap clause worth %d",
495 worth);
496 break;
497
498 case CLAUSE_MAP:
499 if (!give || ds_after == DS_ALLIANCE) {
500 /* Useless to us - we're omniscient! And allies get it for free! */
501 worth = 0;
502 } else {
503 /* Very silly algorithm 2: Land map more worth the more cities
504 we have, since we expose all of these to the enemy. */
505 worth -= 40 * MAX(city_list_size(pplayer->cities), 1);
506 /* Inflate numbers if not peace */
507 if (!pplayers_in_peace(pplayer, aplayer)) {
508 worth *= 2;
509 }
510 /* Don't like them? Don't give it to them! */
511 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 10, worth);
512 /* Make maps from novice player cheap */
513 if (has_handicap(pplayer, H_DIPLOMACY)) {
514 worth /= 6;
515 }
516 }
517 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "landmap clause worth %d",
518 worth);
519 break;
520
521 case CLAUSE_CITY: {
522 struct city *offer = city_list_find_number(pclause->from->cities,
523 pclause->value);
524
525 if (!offer || city_owner(offer) != giver) {
526 /* City destroyed or taken during negotiations */
527 dai_diplo_notify(aplayer, _("*%s (AI)* I do not know the city you mention."),
528 player_name(pplayer));
529 worth = 0;
530 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "city destroyed during negotiations");
531 } else if (give) {
532 /* AI must be crazy to trade away its cities */
533 worth -= city_gold_worth(offer);
534 if (is_capital(offer)) {
535 worth = -BIG_NUMBER; /* Never! Ever! */
536 } else {
537 worth *= 15;
538 }
539 if (aplayer == offer->original) {
540 /* Let them buy back their own city cheaper. */
541 worth /= 2;
542 }
543 } else {
544 worth = city_gold_worth(offer);
545 }
546 if (offer != NULL) {
547 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "worth of %s is %d",
548 city_name_get(offer), worth);
549 }
550 break;
551 }
552
553 case CLAUSE_VISION:
554 if (give) {
555 if (ds_after == DS_ALLIANCE) {
556 if (!shared_vision_is_safe(pplayer, aplayer)) {
558 _("*%s (AI)* Sorry, sharing vision with you "
559 "is not safe."),
560 player_name(pplayer));
561 worth = -BIG_NUMBER;
562 } else {
563 worth = 0;
564 }
565 } else {
566 /* so out of the question */
567 worth = -BIG_NUMBER;
568 }
569 } else {
570 worth = 0; /* We are omniscient, so... */
571 }
572 break;
573
574 case CLAUSE_EMBASSY:
575 if (give) {
576 if (ds_after == DS_ALLIANCE) {
577 worth = 0;
578 } else if (ds_after == DS_PEACE) {
579 worth = -5 * game.info.turn;
580 } else {
581 worth = MIN(-50 * game.info.turn
582 + pplayer->ai_common.love[player_index(aplayer)],
583 -5 * game.info.turn);
584 }
586 worth = game.info.tech_leak_pct / 10;
587 } else {
588 worth = 0; /* We don't need no stinkin' embassy, do we? */
589 }
590 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "embassy clause worth %d",
591 worth);
592 break;
594 if (give) {
595 if (ds_after == DS_ALLIANCE) {
596 worth = 0;
597 } else {
598 /* Here we assume that number of cities correlate with number of tiles. */
599 worth = -3 * (city_list_size(pplayer->cities) + 1);
600 }
601 } else {
602 int cities = city_list_size(aplayer->cities);
603
604 worth = MIN(cities, 3);
605 }
606 break;
607 case CLAUSE_COUNT:
609 break;
610 } /* end of switch */
611
612 if (close_here) {
613 dai_data_phase_finished(ait, pplayer);
614 }
615
617 return worth;
618}
619
620/******************************************************************/
624void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer,
625 struct player *aplayer, struct Treaty *ptreaty)
626{
627 int total_balance = 0;
628 bool only_gifts = TRUE;
631 int given_cities = 0;
632
634 if (is_pact_clause(pclause->type)) {
636 }
637 if (pclause->type == CLAUSE_CITY && pclause->from == pplayer) {
638 given_cities++;
639 }
641
642 /* Evaluate clauses */
644 const struct research *presearch = research_get(pplayer);
645
648
649 if (pclause->type != CLAUSE_GOLD && pclause->type != CLAUSE_MAP
650 && pclause->type != CLAUSE_SEAMAP && pclause->type != CLAUSE_VISION
651 && (pclause->type != CLAUSE_ADVANCE
653 || pclause->value == research_get(pplayer)->tech_goal
654 || pclause->value == research_get(pplayer)->researching
656 pclause->value))) {
657 /* We accept the above list of clauses as gifts, even if we are
658 * at war. We do not accept tech or cities since these can be used
659 * against us, unless we know that we want this tech anyway, or
660 * it doesn't matter due to tech cost style. */
662 }
664
665 /* If we are at war, and no peace is offered, then no deal, unless
666 * it is just gifts, in which case we gratefully accept. */
667 if (ds_after == DS_WAR && !only_gifts) {
668 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "no peace offered, must refuse");
669 return;
670 }
671
672 if (given_cities > 0
673 && city_list_size(pplayer->cities) - given_cities <= 2) {
674 /* always keep at least two cities */
675 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "cannot give last cities");
676 return;
677 }
678
679 /* Accept if balance is good */
680 if (total_balance >= 0) {
682 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was good: %d",
684 } else {
685 /* AI complains about the treaty which was proposed, unless the AI
686 * made the proposal. */
687 if (pplayer != ptreaty->plr0) {
688 dai_diplo_notify(aplayer, _("*%s (AI)* This deal was not very good for us, %s!"),
689 player_name(pplayer),
691 }
692 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was bad: %d",
694 }
695}
696
697/******************************************************************/
701static void dai_treaty_react(struct ai_type *ait,
702 struct player *pplayer,
703 struct player *aplayer,
704 struct Clause *pclause)
705{
706 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
707
708 switch (pclause->type) {
709 case CLAUSE_ALLIANCE:
710 if (adip->is_allied_with_ally) {
711 dai_diplo_notify(aplayer, _("*%s (AI)* Welcome into our alliance %s!"),
712 player_name(pplayer),
714 } else {
715 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, may we forever stand united, %s."),
716 player_name(pplayer),
718 }
719 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "become allies");
720 break;
721 case CLAUSE_PEACE:
722 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, peace in our time!"),
723 player_name(pplayer));
724 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign peace treaty");
725 break;
726 case CLAUSE_CEASEFIRE:
727 dai_diplo_notify(aplayer, _("*%s (AI)* Agreed. No more hostilities, %s."),
728 player_name(pplayer),
730 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign ceasefire");
731 break;
732 default:
733 break;
734 }
735}
736
737/******************************************************************/
744void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer,
745 struct player *aplayer, struct Treaty *ptreaty)
746{
747 bool close_here;
748 struct ai_plr *ai;
749 int total_balance = 0;
750 bool gift = TRUE;
753
754 ai = dai_plr_data_get(ait, pplayer, &close_here);
755
756 fc_assert_ret(pplayer != aplayer);
757
759 if (is_pact_clause(pclause->type)) {
761 }
763
764 /* Evaluate clauses */
766 int balance =
768
770 gift = (gift && (balance >= 0));
771 dai_treaty_react(ait, pplayer, aplayer, pclause);
772 if (is_pact_clause(pclause->type)
773 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown != -1) {
774 /* Cancel a countdown towards war if we just agreed to peace... */
775 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "countdown nullified");
776 dai_diplomacy_get(ait, pplayer, aplayer)->countdown = -1;
777 }
779
780 /* Rather arbitrary algorithm to increase our love for a player if
781 * they offer us gifts. It is only a gift if _all_ the clauses
782 * are beneficial to us. */
783 if (total_balance > 0 && gift) {
784 int i = total_balance / ((city_list_size(pplayer->cities) * 10) + 1);
785
786 i = MIN(i, ai->diplomacy.love_incr * 150) * 10;
787 pplayer->ai_common.love[player_index(aplayer)] += i;
788 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "gift increased love by %d", i);
789 }
790
791 if (close_here) {
792 dai_data_phase_finished(ait, pplayer);
793 }
794}
795
796/******************************************************************/
803static int dai_war_desire(struct ai_type *ait, struct player *pplayer,
804 struct player *target)
805{
806 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
807 struct adv_data *adv = adv_data_get(pplayer, NULL);
808 int want = 0, fear = 0, distance = 0, settlers = 0, cities = 0;
809 struct player_spaceship *ship = &target->spaceship;
810
811 city_list_iterate(target->cities, pcity) {
812 want += 100; /* base city want */
813 want += city_size_get(pcity) * 20;
814 want += pcity->surplus[O_SHIELD] * 8;
815 want += pcity->surplus[O_TRADE] * 6;
816
817 /* FIXME: This might be buggy if it ignores unmet UnitClass reqs. */
819
820 city_built_iterate(pcity, pimprove) {
821 int cost = impr_build_shield_cost(pcity, pimprove);
822
823 want += cost;
824 if (improvement_obsolete(pplayer, pimprove, pcity)) {
825 continue;
826 }
827 if (is_great_wonder(pimprove)) {
828 want += cost * 2;
829 } else if (is_small_wonder(pimprove)) {
830 want += cost;
831 }
834 unit_list_iterate(target->units, punit) {
835 const struct unit_type *ptype = unit_type_get(punit);
836
838
839 /* Fear enemy expansionism */
841 want += 100;
842 }
844 unit_list_iterate(pplayer->units, punit) {
845 const struct unit_type *ptype = unit_type_get(punit);
846
847 fear -= ATTACK_POWER(ptype) / 2;
848
849 /* Our own expansionism reduces want for war */
851 want -= 200;
852 settlers++;
853 }
855 city_list_iterate(pplayer->cities, pcity) {
856 if (VUT_UTYPE == pcity->production.kind
857 && utype_is_cityfounder(pcity->production.value.utype)) {
858 want -= 150;
859 settlers++;
860 }
861 cities++;
863
864 /* Modify by settler/cities ratio to prevent early wars when
865 * we should be expanding. This will eliminate want if we
866 * produce settlers in all cities (ie full expansion). */
867 want -= abs(want) / MAX(cities - settlers, 1);
868
869 /* Calculate average distances to other player's empire. */
870 distance = player_distance_to_player(pplayer, target);
871 dai_diplomacy_get(ait, pplayer, target)->distance = distance;
872
873 /* Worry a bit if the other player has extreme amounts of wealth
874 * that can be used in cities to quickly buy an army. */
875 fear += (target->economic.gold / 5000) * city_list_size(target->cities);
876
877 /* Tech lead is worrisome. FIXME: Only consider 'military' techs. */
878 fear += MAX(research_get(target)->techs_researched
879 - research_get(pplayer)->techs_researched, 0) * 100;
880
881 /* Spacerace loss we will not allow! */
882 if (ship->state >= SSHIP_STARTED) {
883 want *= 2;
884 }
885 if (adv->dipl.spacerace_leader == target) {
887 return BIG_NUMBER; /* do NOT amortize this number! */
888 }
889
890 /* Modify by which treaties we would break to other players, and what
891 * excuses we have to do so. FIXME: We only consider immediate
892 * allies, but we might trigger a wider chain reaction. */
894 bool cancel_excuse =
897
898 if (eplayer == pplayer) {
899 continue;
900 }
901
902 /* Remember: pplayers_allied() returns true when target == eplayer */
903 if (!cancel_excuse && pplayers_allied(target, eplayer)) {
904 if (ds == DS_ARMISTICE) {
905 want -= abs(want) / 10; /* 10% off */
906 } else if (ds == DS_CEASEFIRE) {
907 want -= abs(want) / 7; /* 15% off */
908 } else if (ds == DS_PEACE) {
909 want -= abs(want) / 5; /* 20% off */
910 } else if (ds == DS_ALLIANCE) {
911 want -= abs(want) / 3; /* 33% off */
912 }
913 }
915
916 /* Modify by love. Increase the divisor to make ai go to war earlier */
917 want -= MAX(0, want * pplayer->ai_common.love[player_index(target)]
918 / (2 * MAX_AI_LOVE));
919
920 /* Make novice AI more peaceful with human players */
921 if (has_handicap(pplayer, H_DIPLOMACY) && is_human(target)) {
922 want /= 2;
923 }
924
925 /* Amortize by distance */
926 want = amortize(want, distance);
927
928 if (pplayers_allied(pplayer, target)) {
929 want /= 4;
930 }
931
932 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "War want %d, war fear %d",
933 want, fear);
934 return (want - fear);
935}
936
937/******************************************************************/
942static void dai_diplomacy_suggest(struct player *pplayer,
943 struct player *aplayer,
944 enum clause_type what,
945 bool to_pplayer,
946 int value)
947{
948 if (!could_meet_with_player(pplayer, aplayer)) {
949 log_base(LOG_DIPL2, "%s tries to do diplomacy to %s without contact",
950 player_name(pplayer), player_name(aplayer));
951 return;
952 }
953
957 : pplayer),
958 what, value);
959}
960
961/******************************************************************/
964void dai_diplomacy_first_contact(struct ai_type *ait, struct player *pplayer,
965 struct player *aplayer)
966{
967 bool wants_ceasefire = FALSE;
968
969 /* Randomize initial love */
970 pplayer->ai_common.love[player_index(aplayer)] += 2 - fc_rand(5);
971
972 if (is_ai(pplayer)
973 && player_diplstate_get(pplayer, aplayer)->type == DS_WAR
974 && could_meet_with_player(pplayer, aplayer)) {
975 if (has_handicap(pplayer, H_CEASEFIRE)) {
976 fc_assert(!has_handicap(pplayer, H_AWAY));
978 } else if (!has_handicap(pplayer, H_AWAY)) {
979 struct Clause clause;
980
981 clause.from = pplayer;
982 clause.value = 0;
983 clause.type = CLAUSE_CEASEFIRE;
984
985 if (dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
986 FALSE, DS_CEASEFIRE) > 0) {
988 }
989 }
990 }
991
992 if (wants_ceasefire) {
994 _("*%s (AI)* Greetings %s! May we suggest a ceasefire "
995 "while we get to know each other better?"),
996 player_name(pplayer),
998 clear_old_treaty(pplayer, aplayer);
1000 } else {
1002 _("*%s (AI)* I found you %s! Now make it worth my "
1003 "letting you live, or be crushed."),
1004 player_name(pplayer),
1006 }
1007}
1008
1009/******************************************************************/
1018void dai_diplomacy_begin_new_phase(struct ai_type *ait, struct player *pplayer)
1019{
1020 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1021 struct adv_data *adv = adv_data_get(pplayer, NULL);
1023 int best_desire = 0;
1024 struct player *best_target = NULL;
1025
1026 fc_assert_ret(is_ai(pplayer));
1027
1028 if (!pplayer->is_alive) {
1029 return; /* duh */
1030 }
1031
1032 memset(war_desire, 0, sizeof(war_desire));
1033
1034 /* Calculate our desires, and find desired war target */
1036 /* We don't hate ourselves, those we don't know or team members. */
1037 if (aplayer == pplayer
1038 || NEVER_MET(pplayer, aplayer)
1039 || players_on_same_team(pplayer, aplayer)) {
1040 continue;
1041 }
1046 }
1048
1049 /* Time to make love. If we've been wronged, hold off that love
1050 * for a while. Also, cool our head each turn with love_coeff. */
1052 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1053 int amount = 0;
1054 int pit;
1055
1056 if (pplayer == aplayer) {
1057 continue;
1058 }
1059
1060 if ((pplayers_non_attack(pplayer, aplayer)
1061 || pplayers_allied(pplayer, aplayer))
1062 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel == 0
1063 && adip->countdown == -1
1064 && !adip->is_allied_with_enemy
1065 && !adip->at_war_with_ally
1066 && aplayer != best_target
1067 && adip->ally_patience >= 0) {
1068 amount += ai->diplomacy.love_incr / 2;
1069 if (pplayers_allied(pplayer, aplayer)) {
1070 amount += ai->diplomacy.love_incr / 3;
1071 }
1072 /* Increase love by each enemy they are at war with */
1074 if (WAR(eplayer, aplayer) && WAR(pplayer, eplayer)) {
1075 amount += ai->diplomacy.love_incr / 4;
1076 }
1079 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Increased love by %d", amount);
1080 } else if (WAR(pplayer, aplayer)) {
1081 amount -= ai->diplomacy.love_incr / 2;
1083 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost to war", amount);
1084 } else if (player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel
1085 != 0) {
1086 /* Provoked in time of peace */
1087 if (pplayer->ai_common.love[player_index(aplayer)] > 0) {
1088 amount -= pplayer->ai_common.love[player_index(aplayer)] / 2;
1089 }
1090 amount -= ai->diplomacy.love_incr * 6;
1092 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Provoked! %d love lost!",
1093 amount);
1094 }
1095 if (pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE * 8 / 10
1096 && !pplayers_allied(pplayer, aplayer)) {
1097 int love_change = ai->diplomacy.love_incr / 3;
1098
1099 /* Upper levels of AI trust and love is reserved for allies. */
1101 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost from excess",
1102 love_change);
1103 }
1104 amount = 0;
1105
1106 /* Reduce love due to units in our territory.
1107 * AI is so naive, that we have to count it even if players are allied */
1108 pit = player_in_territory(pplayer, aplayer) * (MAX_AI_LOVE / 200);
1109 amount -= MIN(pit,
1111 * ((adip->is_allied_with_enemy != NULL) + 1));
1113 if (amount != 0) {
1114 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost due to units inside "
1115 "our borders", amount);
1116 }
1117
1118 /* Increase the love if aplayer has got a building that makes
1119 * us love them more. Typically it's Eiffel Tower */
1120 if (!NEVER_MET(pplayer, aplayer)) {
1121 pplayer->ai_common.love[player_index(aplayer)] +=
1123 }
1125
1126 /* Can we win by space race? */
1127 if (adv->dipl.spacerace_leader == pplayer) {
1128 log_base(LOG_DIPL2, "%s going for space race victory!",
1129 player_name(pplayer));
1130 ai->diplomacy.strategy = WIN_SPACE; /* Yes! */
1131 } else {
1132 if (ai->diplomacy.strategy == WIN_SPACE) {
1134 }
1135 }
1136
1138 int *love = &pplayer->ai_common.love[player_index(aplayer)];
1139
1140 if (aplayer == best_target && best_desire > 0) {
1141 int reduction = MIN(best_desire, MAX_AI_LOVE / 20);
1142
1143 *love -= reduction;
1144 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Wants war, reducing "
1145 "love by %d ", reduction);
1146 }
1147
1148 /* Edge love towards zero */
1149 *love -= *love * ((double)ai->diplomacy.love_coeff / 100.0);
1150
1151 /* ai love should always be in range [-MAX_AI_LOVE..MAX_AI_LOVE] */
1152 *love = MAX(-MAX_AI_LOVE, MIN(MAX_AI_LOVE, *love));
1154}
1155
1156/******************************************************************/
1159static void suggest_tech_exchange(struct ai_type *ait,
1160 struct player *player1,
1161 struct player *player2)
1162{
1166 int worth[ac];
1167 bool is_dangerous;
1168
1169 worth[A_NONE] = 0;
1170
1173 == TECH_KNOWN) {
1176 worth[tech] = -compute_tech_sell_price(ait, player1, player2, tech,
1177 &is_dangerous);
1178 if (is_dangerous) {
1179 /* Don't try to exchange */
1180 worth[tech] = 0;
1181 }
1182 } else {
1183 worth[tech] = 0;
1184 }
1185 } else {
1189 worth[tech] = compute_tech_sell_price(ait, player2, player1, tech,
1190 &is_dangerous);
1191 if (is_dangerous) {
1192 /* Don't try to exchange */
1193 worth[tech] = 0;
1194 }
1195 } else {
1196 worth[tech] = 0;
1197 }
1198 }
1200
1202 if (worth[tech] <= 0) {
1203 continue;
1204 }
1206 int diff;
1207
1208 if (worth[tech2] >= 0) {
1209 continue;
1210 }
1211 /* Tech2 is given by player1, tech is given by player2 */
1212 diff = worth[tech] + worth[tech2];
1213 if ((diff > 0 && player1->economic.gold >= diff)
1214 || (diff < 0 && player2->economic.gold >= -diff)
1215 || diff == 0) {
1218 if (diff > 0) {
1220 } else if (diff < 0) {
1222 }
1223 return;
1224 }
1227}
1228
1229/******************************************************************/
1232static void clear_old_treaty(struct player *pplayer, struct player *aplayer)
1233{
1234 struct Treaty *old_treaty = find_treaty(pplayer, aplayer);
1235
1236 if (old_treaty != NULL) {
1237 /* Remove existing clauses */
1240 player_number(pplayer),
1241 player_number(pclause->from),
1242 pclause->type, pclause->value);
1243 free(pclause);
1246 old_treaty->clauses = clause_list_new();
1247 }
1248}
1249
1250/******************************************************************/
1253static void dai_share(struct ai_type *ait, struct player *pplayer,
1254 struct player *aplayer)
1255{
1256 struct research *presearch = research_get(pplayer);
1258 bool gives_vision;
1259
1260 clear_old_treaty(pplayer, aplayer);
1261
1262 /* Only share techs with team mates */
1263 if (presearch != aresearch
1264 && players_on_same_team(pplayer, aplayer)) {
1276 }
1278 }
1279
1280 /* Only give shared vision if safe. Only ask for shared vision if fair. */
1282 if (!gives_vision
1283 && shared_vision_is_safe(pplayer, aplayer)) {
1286 }
1287 if (gives_vision
1288 && !gives_shared_vision(aplayer, pplayer)
1289 && (is_human(aplayer)
1290 || shared_vision_is_safe(aplayer, pplayer))) {
1292 }
1293
1294 if (!player_has_embassy(pplayer, aplayer)) {
1296 }
1297 if (!player_has_embassy(aplayer, pplayer)) {
1299 }
1300
1301 if (!has_handicap(pplayer, H_DIPLOMACY) || is_human(aplayer)) {
1302 suggest_tech_exchange(ait, pplayer, aplayer);
1303 }
1304}
1305
1306/******************************************************************/
1313static void dai_declare_war(struct ai_type *ait, struct player *pplayer,
1314 struct player *target)
1315{
1316 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1317
1318 /* This will take us straight to war. */
1319 while (player_diplstate_get(pplayer, target)->type != DS_WAR) {
1320 if (pplayer_can_cancel_treaty(pplayer, target) != DIPL_OK) {
1321 DIPLO_LOG(ait, LOG_ERROR, pplayer, target,
1322 "Wanted to cancel treaty but was unable to.");
1323 adip->countdown = -1; /* War declaration aborted */
1324
1325 return;
1326 }
1328 }
1329
1330 /* Throw a tantrum */
1331 if (pplayer->ai_common.love[player_index(target)] > 0) {
1332 pplayer->ai_common.love[player_index(target)] = -1;
1333 }
1334 pplayer->ai_common.love[player_index(target)] -= MAX_AI_LOVE / 8;
1335
1336 fc_assert(!gives_shared_vision(pplayer, target));
1337
1338 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "war declared");
1339}
1340
1341/******************************************************************/
1346static void dai_go_to_war(struct ai_type *ait, struct player *pplayer,
1347 struct player *target, enum war_reason reason)
1348{
1349 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1350
1351 fc_assert_ret(pplayer != target);
1352 fc_assert_ret(target->is_alive);
1353
1354 switch (reason) {
1355 case DAI_WR_SPACE:
1356 dai_diplo_notify(target, _("*%s (AI)* Space will never be yours."),
1357 player_name(pplayer));
1358 adip->countdown = -10;
1359 break;
1360 case DAI_WR_BEHAVIOUR:
1361 dai_diplo_notify(target,
1362 _("*%s (AI)* I have tolerated your vicious antics "
1363 "long enough! To war!"),
1364 player_name(pplayer));
1365 adip->countdown = -20;
1366 break;
1367 case DAI_WR_NONE:
1368 dai_diplo_notify(target, _("*%s (AI)* Peace in ... some other time."),
1369 player_name(pplayer));
1370 adip->countdown = -10;
1371 break;
1372 case DAI_WR_HATRED:
1373 dai_diplo_notify(target,
1374 _("*%s (AI)* Finally I get around to you! Did "
1375 "you really think you could get away with your crimes?"),
1376 player_name(pplayer));
1377 adip->countdown = -20;
1378 break;
1379 case DAI_WR_EXCUSE:
1380 dai_diplo_notify(target,
1381 _("*%s (AI)* Your covert hostilities brought "
1382 "this war upon you!"),
1383 player_name(pplayer));
1384 adip->countdown = -20;
1385 break;
1386 case DAI_WR_ALLIANCE:
1387 if (adip->at_war_with_ally) {
1388 dai_diplo_notify(target,
1389 _("*%s (AI)* Your aggression against %s was "
1390 "your last mistake!"),
1391 player_name(pplayer),
1392 player_name(adip->at_war_with_ally));
1393 adip->countdown = -3;
1394 } else {
1395 /* Ooops! */
1396 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "Wanted to declare war "
1397 "for their war against an ally, but can no longer find "
1398 "this ally! War declaration aborted.");
1399 adip->countdown = -1;
1400 return;
1401 }
1402 break;
1403 }
1404
1405 fc_assert_ret(adip->countdown < 0);
1406
1407 if (gives_shared_vision(pplayer, target)) {
1408 remove_shared_vision(pplayer, target);
1409 }
1410
1411 /* Check for Senate obstruction. If so, dissolve it. */
1412 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_SENATE_BLOCKING) {
1413 struct government *real_gov = pplayer->government;
1414
1416
1417 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_OK) {
1418 /* It seems that revolution would help. */
1419 pplayer->government = real_gov;
1422 def_ai_player_data(pplayer, ait)->diplomacy.war_target = target;
1423 return;
1424 } else {
1425 /* There would be Senate even during revolution. Better not to revolt for nothing */
1426 pplayer->government = real_gov;
1427 adip->countdown = -1; /* War declaration aborted */
1428
1429 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target,
1430 "Not revolting, as there would be Senate regardless.");
1431
1432 return;
1433 }
1434 }
1435
1436 dai_declare_war(ait, pplayer, target);
1437}
1438
1439/******************************************************************/
1445void dai_revolution_start(struct ai_type *ait, struct player *pplayer)
1446{
1447 struct ai_plr *data = def_ai_player_data(pplayer, ait);
1448
1449 if (data->diplomacy.war_target != NULL) {
1450 if (gives_shared_vision(pplayer, data->diplomacy.war_target)) {
1452 }
1453
1454 dai_declare_war(ait, pplayer, data->diplomacy.war_target);
1455
1456 data->diplomacy.war_target = NULL;
1457 }
1458}
1459
1460/******************************************************************/
1472static void war_countdown(struct ai_type *ait, struct player *pplayer,
1473 struct player *target,
1474 int countdown, enum war_reason reason)
1475{
1476 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1477
1478 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "countdown to war in %d", countdown);
1479
1480 /* Otherwise we're resetting an existing countdown, which is very bad */
1481 fc_assert_ret(adip->countdown == -1);
1482
1483 adip->countdown = countdown;
1484 adip->war_reason = reason;
1485
1487 if (!pplayers_allied(pplayer, ally)
1488 || ally == target
1489 || NEVER_MET(pplayer, ally)) {
1490 continue;
1491 }
1492
1493 switch (reason) {
1494 case DAI_WR_SPACE:
1496 PL_("*%s (AI)* We will be launching an all-out war "
1497 "against %s in %d turn to stop the spaceship "
1498 "launch.",
1499 "*%s (AI)* We will be launching an all-out war "
1500 "against %s in %d turns to stop the spaceship "
1501 "launch.",
1502 countdown),
1503 player_name(pplayer),
1504 player_name(target),
1505 countdown);
1507 _("*%s (AI)* Your aid in this matter will be expected. "
1508 "Long live our glorious alliance!"),
1509 player_name(pplayer));
1510 break;
1511 case DAI_WR_BEHAVIOUR:
1512 case DAI_WR_EXCUSE:
1514 PL_("*%s (AI)* %s has grossly violated their treaties "
1515 "with us for own gain. We will answer in force in "
1516 "%d turn and expect you to honor your alliance "
1517 "with us and do likewise!",
1518 "*%s (AI)* %s has grossly violated their treaties "
1519 "with us for own gain. We will answer in force in "
1520 "%d turns and expect you to honor your alliance "
1521 "with us and do likewise!", countdown),
1522 player_name(pplayer),
1523 player_name(target),
1524 countdown);
1525 break;
1526 case DAI_WR_NONE:
1528 PL_("*%s (AI)* We intend to pillage and plunder the rich "
1529 "civilization of %s. We declare war in %d turn.",
1530 "*%s (AI)* We intend to pillage and plunder the rich "
1531 "civilization of %s. We declare war in %d turns.",
1532 countdown),
1533 player_name(pplayer),
1534 player_name(target),
1535 countdown);
1537 _("*%s (AI)* If you want a piece of the loot, feel "
1538 "free to join in the action!"),
1539 player_name(pplayer));
1540 break;
1541 case DAI_WR_HATRED:
1543 PL_("*%s (AI)* We have had it with %s. Let us tear this "
1544 "pathetic civilization apart. We declare war in "
1545 "%d turn.",
1546 "*%s (AI)* We have had it with %s. Let us tear this "
1547 "pathetic civilization apart. We declare war in "
1548 "%d turns.",
1549 countdown),
1550 player_name(pplayer),
1551 player_name(target),
1552 countdown);
1554 _("*%s (AI)* As our glorious allies, we expect your "
1555 "help in this war."),
1556 player_name(pplayer));
1557 break;
1558 case DAI_WR_ALLIANCE:
1559 if (WAR(ally, target)) {
1561 PL_("*%s (AI)* We will honor our alliance and declare "
1562 "war on %s in %d turn. Hold on - we are coming!",
1563 "*%s (AI)* We will honor our alliance and declare "
1564 "war on %s in %d turns. Hold on - we are coming!",
1565 countdown),
1566 player_name(pplayer),
1567 player_name(target),
1568 countdown);
1569 } else if (adip->at_war_with_ally) {
1571 PL_("*%s (AI)* We will honor our alliance with %s and "
1572 "declare war on %s in %d turns. We expect you to "
1573 "do likewise.",
1574 "*%s (AI)* We will honor our alliance with %s and "
1575 "declare war on %s in %d turns. We expect you to "
1576 "do likewise.",
1577 countdown),
1578 player_name(pplayer),
1579 player_name(adip->at_war_with_ally),
1580 player_name(target),
1581 countdown);
1582 } else {
1583 fc_assert(FALSE); /* Huh? */
1584 }
1585 break;
1586 }
1588}
1589
1590/******************************************************************/
1596void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
1597{
1598 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1599 bool need_targets = TRUE;
1600 struct player *target = NULL;
1602 int war_threshold;
1603 int aggr;
1604 float aggr_sr;
1605 float max_sr;
1606
1607 fc_assert_ret(is_ai(pplayer));
1608
1609 if (!pplayer->is_alive) {
1610 return;
1611 }
1612
1613 if (get_player_bonus(pplayer, EFT_NO_DIPLOMACY) > 0) {
1614 /* Diplomacy disabled for this player */
1615 return;
1616 }
1617
1618 /*** If we are greviously insulted, go to war immediately. ***/
1619
1621 if (pplayer->ai_common.love[player_index(aplayer)] < 0
1622 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel >= 2
1623 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown == -1) {
1624 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Plans war in revenge");
1625 war_countdown(ait, pplayer, aplayer, map_size_checked(),
1627 }
1629
1630 /*** Stop other players from winning by space race ***/
1631
1632 if (ai->diplomacy.strategy != WIN_SPACE) {
1633 struct adv_data *adv = adv_data_get(pplayer, NULL);
1634
1636 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1637 struct player_spaceship *ship = &aplayer->spaceship;
1638
1639 if (aplayer == pplayer
1640 || adip->countdown >= 0 /* already counting down to war */
1641 || ship->state == SSHIP_NONE
1642 || players_on_same_team(pplayer, aplayer)
1643 || pplayers_at_war(pplayer, aplayer)) {
1644 continue;
1645 }
1646
1647 /* A spaceship victory is always one single player's or team's victory */
1648 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1649 && adv->dipl.spacerace_leader == aplayer
1650 && pplayers_allied(pplayer, aplayer)) {
1652 _("*%s (AI)* Your attempt to conquer space for "
1653 "yourself alone betrays your true intentions, and I "
1654 "will have no more of our alliance!"),
1655 player_name(pplayer));
1658 if (gives_shared_vision(pplayer, aplayer)) {
1659 remove_shared_vision(pplayer, aplayer);
1660 }
1661 /* Never forgive this */
1663 } else if (ship->state == SSHIP_STARTED
1664 && adip->warned_about_space == 0) {
1665 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 10;
1666 adip->warned_about_space = 10 + fc_rand(6);
1668 _("*%s (AI)* Your attempt to unilaterally "
1669 "dominate outer space is highly offensive."),
1670 player_name(pplayer));
1672 _("*%s (AI)* If you do not stop constructing your "
1673 "spaceship, I may be forced to take action!"),
1674 player_name(pplayer));
1675 }
1676 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1677 && aplayer == adv->dipl.spacerace_leader) {
1678 /* This means war!!! */
1679 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 2;
1680 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "plans war due to spaceship");
1681 war_countdown(ait, pplayer, aplayer, 4 + map_size_checked(),
1682 DAI_WR_SPACE);
1683 }
1685 }
1686
1687 /*** Declare war against somebody if we are out of targets ***/
1688
1690 int turns; /* turns since contact */
1691
1692 if (NEVER_MET(pplayer, aplayer)) {
1693 continue;
1694 }
1695 turns = game.info.turn;
1697 if (WAR(pplayer, aplayer)) {
1699 } else if (pplayer->ai_common.love[player_index(aplayer)] < most_hatred
1700 && turns > TURNS_BEFORE_TARGET) {
1702 target = aplayer;
1703 }
1705
1708 aggr_sr = sqrt(aggr);
1709
1710 war_threshold = (MAX_AI_LOVE * (0.70 + aggr_sr / max_sr / 2.0)) - MAX_AI_LOVE;
1711
1712 if (need_targets && target && most_hatred < war_threshold
1713 && dai_diplomacy_get(ait, pplayer, target)->countdown == -1) {
1714 enum war_reason war_reason;
1715
1716 if (pplayers_allied(pplayer, target)) {
1717 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "Plans war against an ally!");
1718 }
1719 if (player_diplstate_get(pplayer, target)->has_reason_to_cancel > 0) {
1720 /* We have good reason */
1721 war_reason = DAI_WR_EXCUSE;
1722 } else if (pplayer->ai_common.love[player_index(target)] < 0) {
1723 /* We have a reason of sorts from way back, maybe? */
1724 war_reason = DAI_WR_HATRED;
1725 } else {
1726 /* We have no legimitate reason... So what? */
1727 war_reason = DAI_WR_NONE;
1728 }
1729 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "plans war for spoils");
1730 war_countdown(ait, pplayer, target, 4 + map_size_checked(), war_reason);
1731 }
1732
1733 /*** Declare war - against enemies of allies ***/
1734
1736 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1737
1738 if (adip->at_war_with_ally
1739 && adip->countdown == -1
1740 && !adip->is_allied_with_ally
1741 && !pplayers_at_war(pplayer, aplayer)
1743 || fc_rand(5) < 1)) {
1744 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "plans war to help ally %s",
1745 player_name(adip->at_war_with_ally));
1746 war_countdown(ait, pplayer, aplayer, 2 + map_size_checked(),
1748 }
1750
1751 /*** Actually declare war (when we have moved units into position) ***/
1752
1754 if (!players_on_same_team(pplayer, aplayer)) {
1755 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1756
1757 if (!aplayer->is_alive) {
1758 adip->countdown = -1;
1759 continue;
1760 }
1761 if (adip->countdown > 0) {
1762 adip->countdown--;
1763 } else if (adip->countdown == 0) {
1764 if (!WAR(pplayer, aplayer)) {
1765 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Declaring war!");
1766 dai_go_to_war(ait, pplayer, aplayer, adip->war_reason);
1767 }
1768 } else if (adip->countdown < -1) {
1769 /* Negative countdown less than -1 is war stubbornness */
1770 adip->countdown++;
1771 }
1772 }
1774
1775 /*** Try to make peace with everyone we love ***/
1776
1779 && diplomacy_possible(pplayer, aplayer)) {
1781 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1782 struct Clause clause;
1783
1784 /* Meaningless values, but rather not have them unset. */
1785 clause.from = pplayer;
1786 clause.value = 0;
1787
1788 /* Remove shared vision if we are not allied or it is no longer safe. */
1789 if (gives_shared_vision(pplayer, aplayer)) {
1790 if (!pplayers_allied(pplayer, aplayer)) {
1791 remove_shared_vision(pplayer, aplayer);
1792 } else if (!players_on_same_team(pplayer, aplayer)
1793 && !shared_vision_is_safe(pplayer, aplayer)) {
1795 _("*%s (AI)* Sorry, sharing vision with you "
1796 "is no longer safe."),
1797 player_name(pplayer));
1798 remove_shared_vision(pplayer, aplayer);
1799 }
1800 }
1801
1802 /* No peace to enemies of our allies... or pointless peace. */
1804 || aplayer == pplayer
1805 || aplayer == target /* no mercy */
1806 || adip->countdown >= 0
1807 || !could_meet_with_player(pplayer, aplayer)) {
1808 continue;
1809 }
1810
1811 /* Spam control */
1812 adip->asked_about_peace = MAX(adip->asked_about_peace - 1, 0);
1813 adip->asked_about_alliance = MAX(adip->asked_about_alliance - 1, 0);
1814 adip->asked_about_ceasefire = MAX(adip->asked_about_ceasefire - 1, 0);
1815 adip->warned_about_space = MAX(adip->warned_about_space - 1, 0);
1816 adip->spam = MAX(adip->spam - 1, 0);
1817 if (adip->spam > 0 && is_ai(aplayer)) {
1818 /* Don't spam */
1819 continue;
1820 }
1821
1822 /* Canvass support from existing friends for our war, and try to
1823 * make friends with enemies. Then we wait some turns until next time
1824 * we spam them with our gibbering chatter. */
1825 if (adip->spam <= 0) {
1826 if (!pplayers_allied(pplayer, aplayer)) {
1827 adip->spam = fc_rand(4) + 3; /* Bugger allies often. */
1828 } else {
1829 adip->spam = fc_rand(8) + 6; /* Others are less important. */
1830 }
1831 }
1832
1833 switch (ds) {
1834 case DS_TEAM:
1835 dai_share(ait, pplayer, aplayer);
1836 break;
1837 case DS_ALLIANCE:
1838 /* See if our allies are diligently declaring war on our enemies... */
1839 if (adip->at_war_with_ally) {
1840 break;
1841 }
1842 target = NULL;
1844 if (WAR(pplayer, eplayer)
1846 target = eplayer;
1847 break;
1848 }
1850
1851 if ((players_on_same_team(pplayer, aplayer)
1852 || pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE / 2)) {
1853 /* Share techs only with team mates and allies we really like. */
1854 dai_share(ait, pplayer, aplayer);
1855 }
1856 if (!target || !target->is_alive) {
1857 adip->ally_patience = 0;
1858 break; /* No need to nag our ally */
1859 }
1860
1861 if (adip->spam <= 0) {
1862 /* Count down patience toward AI player (one that can have spam > 0)
1863 * at the same speed as toward human players. */
1864 if (adip->ally_patience == 0) {
1866 _("*%s (AI)* Greetings our most trustworthy "
1867 "ally. We call upon you to destroy our enemy, %s."),
1868 player_name(pplayer),
1869 player_name(target));
1870 adip->ally_patience--;
1871 } else if (adip->ally_patience == -1) {
1872 if (fc_rand(5) == 1) {
1874 _("*%s (AI)* Greetings ally, I see you have not yet "
1875 "made war with our enemy, %s. Why do I need to remind "
1876 "you of your promises?"),
1877 player_name(pplayer),
1878 player_name(target));
1879 adip->ally_patience--;
1880 }
1881 } else if (fc_rand(5) == 1
1882 && !players_on_same_team(pplayer, aplayer)) {
1884 _("*%s (AI)* Dishonored one, we made a pact of "
1885 "alliance, and yet you remain at peace with our mortal "
1886 "enemy, %s! This is unacceptable; our alliance is no "
1887 "more!"),
1888 player_name(pplayer),
1889 player_name(target));
1890 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer,
1891 "breaking useless alliance");
1892 /* To peace */
1896 = MIN(pplayer->ai_common.love[player_index(aplayer)], 0);
1897 if (gives_shared_vision(pplayer, aplayer)) {
1898 remove_shared_vision(pplayer, aplayer);
1899 }
1900
1902 }
1903 }
1904 break;
1905
1906 case DS_PEACE:
1907 clause.type = CLAUSE_ALLIANCE;
1908 if (adip->at_war_with_ally
1909 || (is_human(aplayer) && adip->asked_about_alliance > 0)
1910 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1911 FALSE, DS_ALLIANCE) < 0) {
1912 break;
1913 }
1914 clear_old_treaty(pplayer, aplayer);
1916 adip->asked_about_alliance = is_human(aplayer) ? 13 : 0;
1918 _("*%s (AI)* Greetings friend, may we suggest "
1919 "making a common cause and join in an alliance?"),
1920 player_name(pplayer));
1921 break;
1922
1923 case DS_CEASEFIRE:
1924 clause.type = CLAUSE_PEACE;
1925 if (adip->at_war_with_ally
1926 || (is_human(aplayer) && adip->asked_about_peace > 0)
1927 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1928 FALSE, DS_PEACE) < 0) {
1929 break;
1930 }
1931 clear_old_treaty(pplayer, aplayer);
1933 adip->asked_about_peace = is_human(aplayer) ? 12 : 0;
1935 _("*%s (AI)* Greetings neighbor, may we suggest "
1936 "more peaceful relations?"),
1937 player_name(pplayer));
1938 break;
1939
1940 case DS_NO_CONTACT: /* but we do have embassy! weird. */
1941 case DS_WAR:
1942 clause.type = CLAUSE_CEASEFIRE;
1943 if ((is_human(aplayer) && adip->asked_about_ceasefire > 0)
1944 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1945 FALSE, DS_CEASEFIRE) < 0) {
1946 break; /* Fight until the end! */
1947 }
1948 clear_old_treaty(pplayer, aplayer);
1950 adip->asked_about_ceasefire = is_human(aplayer) ? 9 : 0;
1952 _("*%s (AI)* We grow weary of this constant "
1953 "bloodshed. May we suggest a cessation of hostilities?"),
1954 player_name(pplayer));
1955 break;
1956
1957 case DS_ARMISTICE:
1958 break;
1959 default:
1960 fc_assert_msg(FALSE, "Unknown pact type %d.", ds);
1961 break;
1962 }
1963 }
1965}
1966
1967/******************************************************************/
1971bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
1972{
1973 players_iterate(plr) {
1974 if (dai_diplomacy_get(ait, pplayer, plr)->countdown >= 0) {
1975 return TRUE;
1976 }
1978
1979 return FALSE;
1980}
1981
1982/******************************************************************/
1985/* AI attitude call-backs */
1988 const struct action *paction,
1989 struct player *receiver,
1990 struct player *violator, struct player *victim)
1991{
1992 if (!is_ai(receiver) || violator == receiver) {
1993 return;
1994 }
1995
1996 /* Can only handle victim only and international incidents. */
1999
2000 switch (type) {
2001 case INCIDENT_ACTION:
2002 /* Feel free the change how the action results are grouped and how bad
2003 * the ai considers each group. */
2004 switch (paction->result) {
2005 case ACTRES_SPY_NUKE:
2006 case ACTRES_NUKE:
2007 case ACTRES_NUKE_UNITS:
2008 if (receiver == victim) {
2009 /* Tell the victim */
2011 } else if (violator == victim) {
2013 } else {
2015 }
2016 break;
2019 /* Snoping */
2020 dai_incident_simple(receiver, violator, victim, scope, 2);
2021 break;
2025 case ACTRES_STEAL_MAPS:
2026 /* Theft */
2027 dai_incident_simple(receiver, violator, victim, scope, 5);
2028 break;
2029 case ACTRES_EXPEL_UNIT:
2030 /* Unit position loss */
2031 dai_incident_simple(receiver, violator, victim, scope, 1);
2032 break;
2034 /* Unit weakening */
2035 dai_incident_simple(receiver, violator, victim, scope, 3);
2036 break;
2039 case ACTRES_BOMBARD:
2040 case ACTRES_ATTACK:
2041 case ACTRES_WIPE_UNITS:
2042 case ACTRES_SPY_ATTACK:
2044 /* Unit loss */
2045 dai_incident_simple(receiver, violator, victim, scope, 5);
2046 break;
2050 /* City loss */
2051 dai_incident_simple(receiver, violator, victim, scope, 10);
2052 break;
2058 /* Building loss */
2059 dai_incident_simple(receiver, violator, victim, scope, 5);
2060 break;
2061 case ACTRES_SPY_POISON:
2063 /* Population loss */
2064 dai_incident_simple(receiver, violator, victim, scope, 5);
2065 break;
2066 case ACTRES_FOUND_CITY:
2067 /* Terrain loss */
2068 dai_incident_simple(receiver, violator, victim, scope, 4);
2069 break;
2071 case ACTRES_PILLAGE:
2072 /* Extra loss */
2073 dai_incident_simple(receiver, violator, victim, scope, 2);
2074 break;
2075 case ACTRES_UNIT_MOVE:
2076 case ACTRES_TELEPORT:
2078 case ACTRES_SPY_ESCAPE:
2079 case ACTRES_TRADE_ROUTE:
2080 case ACTRES_MARKETPLACE:
2081 case ACTRES_HELP_WONDER:
2082 case ACTRES_JOIN_CITY:
2085 case ACTRES_HOME_CITY:
2086 case ACTRES_HOMELESS:
2088 case ACTRES_PARADROP:
2089 case ACTRES_PARADROP_CONQUER: /* TODO: Bigger incident */
2090 case ACTRES_AIRLIFT:
2091 case ACTRES_HEAL_UNIT:
2093 case ACTRES_CULTIVATE:
2094 case ACTRES_PLANT:
2095 case ACTRES_CLEAN:
2096 case ACTRES_FORTIFY:
2097 case ACTRES_ROAD:
2098 case ACTRES_CONVERT:
2099 case ACTRES_BASE:
2100 case ACTRES_MINE:
2101 case ACTRES_IRRIGATE:
2108 case ACTRES_HUT_ENTER:
2111 case ACTRES_NONE:
2112 /* Various */
2113 dai_incident_simple(receiver, violator, victim, scope, 1);
2114 break;
2115
2117 }
2118 break;
2119 case INCIDENT_WAR:
2120 if (receiver == victim) {
2122 }
2123 break;
2124 case INCIDENT_LAST:
2125 /* Assert that always fails, but with meaningful message */
2127 break;
2128 }
2129}
2130
2131/******************************************************************/
2134static void dai_incident_nuclear(struct player *receiver,
2135 const struct player *violator,
2136 const struct player *victim)
2137{
2138 fc_assert_ret(receiver == victim);
2139
2140 if (violator == victim) {
2141 return;
2142 }
2143
2144 receiver->ai_common.love[player_index(violator)] -= 3 * MAX_AI_LOVE / 10;
2145}
2146
2147/******************************************************************/
2150static void dai_incident_nuclear_not_target(struct player *receiver,
2151 const struct player *violator,
2152 const struct player *victim)
2153{
2154 fc_assert_ret(receiver != victim);
2155
2156 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2157}
2158
2159/******************************************************************/
2162static void dai_incident_nuclear_self(struct player *receiver,
2163 const struct player *violator,
2164 const struct player *victim)
2165{
2166 fc_assert_ret(receiver != victim);
2168
2169 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 20;
2170}
2171
2172/**********************************************************************/
2184static void dai_incident_simple(struct player *receiver,
2185 const struct player *violator,
2186 const struct player *victim,
2188 int how_bad)
2189{
2191 if (victim == receiver) {
2193 /* The ruleset finds this bad enough to cause International Outrage.
2194 * Trust the ruleset author. Double the displeasure. */
2196 }
2197 receiver->ai_common.love[player_index(violator)] -= displeasure / 35;
2198 } else if (violator == victim) {
2199 receiver->ai_common.love[player_index(violator)] -= displeasure / 1000;
2200 } else {
2201 receiver->ai_common.love[player_index(violator)] -= displeasure / 500;
2202 }
2203}
2204
2205/******************************************************************/
2213static void dai_incident_war(struct player *violator, struct player *victim)
2214{
2215 players_iterate(pplayer) {
2216 if (!is_ai(pplayer)) {
2217 continue;
2218 }
2219
2220 if (pplayer != violator) {
2221 /* Dislike backstabbing bastards */
2222 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2223 if (player_diplstate_get(violator, victim)->max_state == DS_PEACE) {
2224 /* Extra penalty if they once had a peace treaty */
2225 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2226 } else if (player_diplstate_get(violator, victim)->max_state
2227 == DS_ALLIANCE) {
2228 /* Extra penalty if they once had an alliance */
2229 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2230 }
2231 if (victim == pplayer) {
2232 pplayer->ai_common.love[player_index(violator)] =
2233 MIN(pplayer->ai_common.love[player_index(violator)] - MAX_AI_LOVE / 3, -1);
2234 /* Scream for help!! */
2236 if (!pplayers_allied(pplayer, ally)) {
2237 continue;
2238 }
2240 _("*%s (AI)* We have been savagely attacked by "
2241 "%s, and we need your help! Honor our glorious "
2242 "alliance and your name will never be forgotten!"),
2246 }
2247 }
2249}
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:605
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1107
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:69
bool is_capital(const struct city *pcity)
Definition city.c:1579
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1679
#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:834
#define city_built_iterate_end
Definition city.h:840
char * incite_cost
Definition comments.c:75
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:756
void handle_diplomacy_init_meeting_req(struct player *pplayer, int counterpart)
Definition diplhand.c:848
void handle_diplomacy_accept_treaty_req(struct player *pplayer, int counterpart)
Definition diplhand.c:150
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:346
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:70
#define clause_list_iterate(clauselist, pclause)
Definition diptreaty.h:68
#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:846
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
int Tech_type_id
Definition fc_types.h:377
#define ACTRES_NONE
Definition fc_types.h:327
@ 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:62
GType type
Definition repodlgs.c:1313
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:566
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:882
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:271
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1693
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:645
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:1476
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:1878
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:1405
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1459
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:1485
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1426
#define players_iterate_end
Definition player.h:537
@ DIPL_SENATE_BLOCKING
Definition player.h:191
@ DIPL_OK
Definition player.h:191
#define players_iterate(_pplayer)
Definition player.h:532
#define MAX_AI_LOVE
Definition player.h:561
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
#define is_ai(plr)
Definition player.h:230
#define players_iterate_alive_end
Definition player.h:547
#define is_human(plr)
Definition player.h:229
#define players_iterate_alive(_pplayer)
Definition player.h:542
#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:1050
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:73
struct player * from
Definition diptreaty.h:74
int value
Definition diptreaty.h:75
struct player * plr0
Definition diptreaty.h:79
struct clause_list * clauses
Definition diptreaty.h:81
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
adv_want tech_want[A_LAST+1]
Definition daidata.h:104
struct ai_plr::@254 diplomacy
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:144
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:122
int first_contact_turn
Definition player.h:199
enum diplstate_type type
Definition player.h:197
char has_reason_to_cancel
Definition player.h:201
struct city_list * cities
Definition player.h:279
int bulbs_last_turn
Definition player.h:349
struct player_ai ai_common
Definition player.h:286
struct government * government
Definition player.h:256
struct team * team
Definition player.h:259
const struct ai_type * ai
Definition player.h:287
struct unit_list * units
Definition player.h:280
struct conn_list * connections
Definition player.h:296
bool is_alive
Definition player.h:266
struct player_economic economic
Definition player.h:282
struct player_spaceship spaceship
Definition player.h:284
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
int bulbs_researched
Definition research.h:53
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:299
#define advance_index_iterate_max(_start, _index, _max)
Definition tech.h:252
#define advance_index_iterate_end
Definition tech.h:248
#define advance_index_iterate_max_end
Definition tech.h:258
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:244
#define TRAIT_MAX_VALUE_SR
Definition traits.h:34
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2641
#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:2965