Freeciv-3.4
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 text, ap);
113 va_end(ap);
114
115 lsend_packet_chat_msg(dest, &packet);
116 /* Add to the event cache. */
117 event_cache_add_for_player(&packet, pplayer);
118 }
119}
120
121/******************************************************************/
125static int greed(int missing_love)
126{
127 if (missing_love > 0) {
128 return 0;
129 } else {
130 /* Don't change the operation order here.
131 * We do not want integer overflows */
132 return -((missing_love * MAX_AI_LOVE) / 1000) *
133 ((missing_love * MAX_AI_LOVE) / 1000) / 10;
134 }
135}
136
137/******************************************************************/
141{
142 switch (type) {
143 case CLAUSE_ALLIANCE:
144 return DS_ALLIANCE;
145 case CLAUSE_PEACE:
146 return DS_PEACE;
147 case CLAUSE_CEASEFIRE:
148 return DS_CEASEFIRE;
149 default:
150 log_error("Invalid diplomatic clause %d.", type)
151 return DS_WAR;
152 }
153}
154
155/******************************************************************/
158static int dai_goldequiv_tech(struct ai_type *ait,
159 struct player *pplayer, Tech_type_id tech)
160{
161 int bulbs, tech_want, worth;
162 struct research *presearch = research_get(pplayer);
164 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
165
166 if (TECH_KNOWN == state
169 return 0;
170 }
172 tech_want = MAX(plr_data->tech_want[tech], 0) / MAX(game.info.turn, 1);
173 worth = bulbs + tech_want;
174 if (TECH_PREREQS_KNOWN == state) {
175 worth /= 2;
176 }
177
178 return worth;
179}
180
181/******************************************************************/
185static bool shared_vision_is_safe(struct player* pplayer,
186 struct player* aplayer)
187{
188 if (pplayer->team && pplayer->team == aplayer->team) {
189 return TRUE;
190 }
192 if (eplayer == pplayer || eplayer == aplayer) {
193 continue;
194 }
197
198 if (ds != DS_NO_CONTACT && ds != DS_ALLIANCE) {
199 return FALSE;
200 }
201 }
203
204 return TRUE;
205}
206
207/******************************************************************/
212 struct player* player1,
213 struct player* player2)
214{
215 return (player1->ai_common.love[player_index(player2)] > - (MAX_AI_LOVE * 4 / 10)
216 && dai_diplomacy_get(ait, player1, player2)->countdown == -1);
217}
218
219/******************************************************************/
226static int compute_tech_sell_price(struct ai_type *ait,
227 struct player *giver, struct player *taker,
228 int tech_id, bool *is_dangerous)
229{
230 int worth;
231
232 worth = dai_goldequiv_tech(ait, taker, tech_id);
233
234 *is_dangerous = FALSE;
235
236 /* Share and expect being shared brotherly between allies */
237 if (pplayers_allied(giver, taker)) {
238 worth /= 2;
239 }
240 if (players_on_same_team(giver, taker)) {
241 return 0;
242 }
243
244 /* Do not bother wanting a tech that we already have. */
246 == TECH_KNOWN) {
247 return 0;
248 }
249
250 /* Calculate in tech leak to our opponents, guess 50% chance */
252 if (eplayer == giver
253 || eplayer == taker
255 tech_id) == TECH_KNOWN) {
256 continue;
257 }
258
259 /* Don't risk it falling into enemy hands */
261 && adv_is_player_dangerous(giver, eplayer)) {
262 *is_dangerous = TRUE;
263 }
264
266 && !pplayers_allied(giver, eplayer)) {
267 /* Taker can enrich their side with this tech */
268 worth += dai_goldequiv_tech(ait, eplayer, tech_id) / 4;
269 }
271
272 return worth;
273}
274
275/******************************************************************/
278static const struct player *
280 const struct player *them)
281{
283 if (aplayer != us
284 && aplayer != them
287 return aplayer;
288 }
290
291 return nullptr;
292}
293
294/******************************************************************/
301static int dai_goldequiv_clause(struct ai_type *ait,
302 struct player *pplayer,
303 struct player *aplayer,
304 struct Clause *pclause,
305 bool verbose,
307{
308 bool close_here;
309 struct ai_plr *ai;
310 int worth = 0; /* Worth for pplayer of what aplayer gives */
311 bool give = (pplayer == pclause->from);
312 struct player *giver;
313 const struct player *penemy;
314 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
315 bool is_dangerous;
316 const struct civ_map *nmap = &(wld.map);
317
318 ai = dai_plr_data_get(ait, pplayer, &close_here);
319
320 fc_assert_ret_val(pplayer != aplayer, 0);
321
322 diplomacy_verbose = verbose;
324 giver = pclause->from;
325
326 switch (pclause->type) {
327 case CLAUSE_ADVANCE:
328 if (give) {
329 worth -= compute_tech_sell_price(ait, pplayer, aplayer, pclause->value,
330 &is_dangerous);
331 if (is_dangerous) {
332 worth = -BIG_NUMBER;
333 }
334 } else if (research_invention_state(research_get(pplayer),
335 pclause->value) != TECH_KNOWN) {
336 worth += compute_tech_sell_price(ait, aplayer, pplayer, pclause->value,
337 &is_dangerous);
338
340 /* Consider the upkeep costs! Thus, one can not get an AI player by
341 * - given AI lots of techs for gold/cities etc.
342 * - AI losses tech due to high upkeep.
343 * FIXME: Is there a better way for this? */
344 struct research *research = research_get(pplayer);
345 int limit;
346
347 /* Make sure there's no division by zero */
348 if (research->techs_researched > 0) {
349 int upk_per_tech = player_tech_upkeep(pplayer)
351
352 limit = MAX(1, upk_per_tech);
353 } else {
354 limit = 1;
355 fc_assert(player_tech_upkeep(pplayer) == 0);
356 }
357
358 if (pplayer->server.bulbs_last_turn < limit) {
359 if (research->bulbs_researched < 0) {
360 worth = -BIG_NUMBER;
361 } else {
362 worth /= 2;
363 }
364 }
365 }
366 }
367 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "%s clause worth %d",
369 break;
370
371 case CLAUSE_ALLIANCE:
372 case CLAUSE_PEACE:
373 case CLAUSE_CEASEFIRE:
374 /* Don't do anything in away mode */
375 if (has_handicap(pplayer, H_AWAY)) {
377 _("*%s (AI)* In away mode AI can't sign such a treaty."),
378 player_name(pplayer));
379 worth = -BIG_NUMBER;
380 break;
381 }
382
383 /* This guy is allied to one of our enemies. Only accept
384 * ceasefire. */
386 && pclause->type != CLAUSE_CEASEFIRE) {
387 dai_diplo_notify(aplayer, _("*%s (AI)* First break alliance with %s, %s."),
388 player_name(pplayer), player_name(penemy),
390 worth = -BIG_NUMBER;
391 break;
392 }
393
394 /* They were allied with an enemy at the beginning of the turn. */
395 if (adip->is_allied_with_enemy
396 && pclause->type != CLAUSE_CEASEFIRE) {
397 dai_diplo_notify(aplayer, _("*%s (AI)* I would like to see you keep your "
398 "distance from %s for some time, %s."),
399 player_name(pplayer),
400 player_name(adip->is_allied_with_enemy),
402 worth = -BIG_NUMBER;
403 break;
404 }
405
406 /* Steps of the treaty ladder */
407 if (pclause->type == CLAUSE_PEACE) {
408 const struct player_diplstate *ds
409 = player_diplstate_get(pplayer, aplayer);
410
411 if (!pplayers_non_attack(pplayer, aplayer)) {
413 _("*%s (AI)* Let us first cease hostilities, %s."),
414 player_name(pplayer),
416 worth = -BIG_NUMBER;
417 } else if (ds->type == DS_CEASEFIRE && ds->turns_left > 4) {
419 _("*%s (AI)* I wish to see you keep the current "
420 "ceasefire for a bit longer first, %s."),
421 player_name(pplayer),
423 worth = -BIG_NUMBER;
424 } else if (adip->countdown >= 0 || adip->countdown < -1) {
425 worth = -BIG_NUMBER; /* But say nothing */
426 } else {
427 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
429 }
430 } else if (pclause->type == CLAUSE_ALLIANCE) {
431 if (!pplayers_in_peace(pplayer, aplayer)) {
432 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
434 }
435 if (adip->countdown >= 0 || adip->countdown < -1) {
436 worth = -BIG_NUMBER; /* But say nothing */
437 } else {
438 worth += greed(pplayer->ai_common.love[player_index(aplayer)]
440 }
441 if (pplayer->ai_common.love[player_index(aplayer)] < MAX_AI_LOVE / 10) {
442 dai_diplo_notify(aplayer, _("*%s (AI)* I simply do not trust you with an "
443 "alliance yet, %s."),
444 player_name(pplayer),
446 worth = -BIG_NUMBER;
447 }
448 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ally clause worth %d", worth);
449 } else {
450 if (is_ai(pplayer) && is_ai(aplayer)
452 worth = 0;
453 } else {
454 int turns = game.info.turn;
455
457 if (turns < TURNS_BEFORE_TARGET) {
458 worth = 0; /* Show some good faith */
459 break;
460 } else {
461 worth = greed(pplayer->ai_common.love[player_index(aplayer)]);
462 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ceasefire worth=%d love=%d "
463 "turns=%d", worth,
465 turns);
466 }
467 }
468 }
469
470 /* Let's all hold hands in one happy family! */
471 if (adip->is_allied_with_ally) {
472 worth /= 2;
473 break;
474 }
475
476 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "treaty clause worth %d", worth);
477 break;
478
479 case CLAUSE_GOLD:
480 if (give) {
481 worth -= pclause->value;
482 } else {
483 worth += pclause->value * (100 - game.server.diplgoldcost) / 100;
484 }
485 break;
486
487 case CLAUSE_SEAMAP:
488 if (!give || ds_after == DS_ALLIANCE) {
489 /* Useless to us - we're omniscient! And allies get it for free! */
490 worth = 0;
491 } else {
492 /* Very silly algorithm 1: Sea map more worth if enemy has more
493 cities. Reasoning is they have more use of seamap for settling
494 new areas the more cities they have already. */
495 worth -= 15 * city_list_size(aplayer->cities);
496 /* Don't like them? Don't give it to them! */
497 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 7, worth);
498 /* Make maps from novice player cheap */
499 if (has_handicap(pplayer, H_DIPLOMACY)) {
500 worth /= 2;
501 }
502 }
503 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "seamap clause worth %d",
504 worth);
505 break;
506
507 case CLAUSE_MAP:
508 if (!give || ds_after == DS_ALLIANCE) {
509 /* Useless to us - we're omniscient! And allies get it for free! */
510 worth = 0;
511 } else {
512 /* Very silly algorithm 2: Land map more worth the more cities
513 we have, since we expose all of these to the enemy. */
514 worth -= 40 * MAX(city_list_size(pplayer->cities), 1);
515 /* Inflate numbers if not peace */
516 if (!pplayers_in_peace(pplayer, aplayer)) {
517 worth *= 2;
518 }
519 /* Don't like them? Don't give it to them! */
520 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 10, worth);
521 /* Make maps from novice player cheap */
522 if (has_handicap(pplayer, H_DIPLOMACY)) {
523 worth /= 6;
524 }
525 }
526 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "landmap clause worth %d",
527 worth);
528 break;
529
530 case CLAUSE_CITY: {
531 struct city *offer = city_list_find_number(pclause->from->cities,
532 pclause->value);
533
534 if (!offer || city_owner(offer) != giver) {
535 /* City destroyed or taken during negotiations */
537 _("*%s (AI)* I do not know the city you mention."),
538 player_name(pplayer));
539 worth = 0;
540 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer,
541 "city destroyed during negotiations");
542 } else if (give) {
543 /* AI must be crazy to trade away its cities */
544 worth -= city_gold_worth(nmap, offer);
545 if (is_capital(offer)) {
546 worth = -BIG_NUMBER; /* Never! Ever! */
547 } else {
548 worth *= 15;
549 }
550 if (aplayer == offer->original) {
551 /* Let them buy back their own city cheaper. */
552 worth /= 2;
553 }
554 } else {
555 worth = city_gold_worth(nmap, offer);
556 }
557 if (offer != nullptr) {
558 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "worth of %s is %d",
559 city_name_get(offer), worth);
560 }
561 break;
562 }
563
564 case CLAUSE_VISION:
565 if (give) {
566 if (ds_after == DS_ALLIANCE) {
567 if (!shared_vision_is_safe(pplayer, aplayer)) {
569 _("*%s (AI)* Sorry, sharing vision with you "
570 "is not safe."),
571 player_name(pplayer));
572 worth = -BIG_NUMBER;
573 } else {
574 worth = 0;
575 }
576 } else {
577 /* So out of the question */
578 worth = -BIG_NUMBER;
579 }
580 } else {
581 worth = 0; /* We are omniscient, so... */
582 }
583 break;
584
585 case CLAUSE_EMBASSY:
586 if (give) {
587 if (ds_after == DS_ALLIANCE) {
588 worth = 0;
589 } else if (ds_after == DS_PEACE) {
590 worth = -5 * game.info.turn;
591 } else {
592 worth = MIN(-50 * game.info.turn
593 + pplayer->ai_common.love[player_index(aplayer)],
594 -5 * game.info.turn);
595 }
597 worth = game.info.tech_leak_pct / 10;
598 } else {
599 worth = 0; /* We don't need no stinkin' embassy, do we? */
600 }
601 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "embassy clause worth %d",
602 worth);
603 break;
605 if (give) {
606 if (ds_after == DS_ALLIANCE) {
607 worth = 0;
608 } else {
609 /* Here we assume that number of cities correlate with number of tiles. */
610 worth = -3 * (city_list_size(pplayer->cities) + 1);
611 }
612 } else {
613 int cities = city_list_size(aplayer->cities);
614
615 worth = MIN(cities, 3);
616 }
617 break;
618 case CLAUSE_COUNT:
620 break;
621 } /* End of switch */
622
623 if (close_here) {
624 dai_data_phase_finished(ait, pplayer);
625 }
626
628
629 return worth;
630}
631
632/******************************************************************/
636void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer,
637 struct player *aplayer, struct treaty *ptreaty)
638{
639 int total_balance = 0;
640 bool only_gifts = TRUE;
642 = player_diplstate_get(pplayer, aplayer)->type;
643 int given_cities = 0;
644
646 if (is_pact_clause(pclause->type)) {
648 }
649 if (pclause->type == CLAUSE_CITY && pclause->from == pplayer) {
650 given_cities++;
651 }
653
654 /* Evaluate clauses */
656 const struct research *presearch = research_get(pplayer);
657
660
661 if (pclause->type != CLAUSE_GOLD && pclause->type != CLAUSE_MAP
662 && pclause->type != CLAUSE_SEAMAP && pclause->type != CLAUSE_VISION
663 && (pclause->type != CLAUSE_ADVANCE
665 || pclause->value == research_get(pplayer)->tech_goal
666 || pclause->value == research_get(pplayer)->researching
668 pclause->value))) {
669 /* We accept the above list of clauses as gifts, even if we are
670 * at war. We do not accept tech or cities since these can be used
671 * against us, unless we know that we want this tech anyway, or
672 * it doesn't matter due to tech cost style. */
674 }
676
677 /* If we are at war, and no peace is offered, then no deal, unless
678 * it is just gifts, in which case we gratefully accept. */
679 if (ds_after == DS_WAR && !only_gifts) {
680 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "no peace offered, must refuse");
681 return;
682 }
683
684 if (given_cities > 0
685 && city_list_size(pplayer->cities) - given_cities <= 2) {
686 /* always keep at least two cities */
687 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "cannot give last cities");
688 return;
689 }
690
691 /* Accept if balance is good */
692 if (total_balance >= 0) {
694 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was good: %d",
696 } else {
697 /* AI complains about the treaty which was proposed, unless the AI
698 * made the proposal. */
699 if (pplayer != ptreaty->plr0) {
701 _("*%s (AI)* This deal was not very good for us, %s!"),
702 player_name(pplayer),
704 }
705 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was bad: %d",
707 }
708}
709
710/******************************************************************/
714static void dai_treaty_react(struct ai_type *ait,
715 struct player *pplayer,
716 struct player *aplayer,
717 struct Clause *pclause)
718{
719 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
720
721 switch (pclause->type) {
722 case CLAUSE_ALLIANCE:
723 if (adip->is_allied_with_ally) {
724 dai_diplo_notify(aplayer, _("*%s (AI)* Welcome into our alliance %s!"),
725 player_name(pplayer),
727 } else {
728 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, may we forever stand united, %s."),
729 player_name(pplayer),
731 }
732 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "become allies");
733 break;
734 case CLAUSE_PEACE:
735 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, peace in our time!"),
736 player_name(pplayer));
737 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign peace treaty");
738 break;
739 case CLAUSE_CEASEFIRE:
740 dai_diplo_notify(aplayer, _("*%s (AI)* Agreed. No more hostilities, %s."),
741 player_name(pplayer),
743 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign ceasefire");
744 break;
745 default:
746 break;
747 }
748}
749
750/******************************************************************/
757void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer,
758 struct player *aplayer, struct treaty *ptreaty)
759{
760 bool close_here;
761 struct ai_plr *ai;
762 int total_balance = 0;
763 bool gift = TRUE;
765 = player_diplstate_get(pplayer, aplayer)->type;
766
767 ai = dai_plr_data_get(ait, pplayer, &close_here);
768
769 fc_assert_ret(pplayer != aplayer);
770
772 if (is_pact_clause(pclause->type)) {
774 }
776
777 /* Evaluate clauses */
779 int balance
781
783 gift = (gift && (balance >= 0));
784 dai_treaty_react(ait, pplayer, aplayer, pclause);
785 if (is_pact_clause(pclause->type)
786 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown != -1) {
787 /* Cancel a countdown towards war if we just agreed to peace... */
788 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "countdown nullified");
789 dai_diplomacy_get(ait, pplayer, aplayer)->countdown = -1;
790 }
792
793 /* Rather arbitrary algorithm to increase our love for a player if
794 * they offer us gifts. It is only a gift if _all_ the clauses
795 * are beneficial to us. */
796 if (total_balance > 0 && gift) {
797 int i = total_balance / ((city_list_size(pplayer->cities) * 10) + 1);
798
799 i = MIN(i, ai->diplomacy.love_incr * 150) * 10;
800 pplayer->ai_common.love[player_index(aplayer)] += i;
801 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "gift increased love by %d", i);
802 }
803
804 if (close_here) {
805 dai_data_phase_finished(ait, pplayer);
806 }
807}
808
809/******************************************************************/
816static int dai_war_desire(struct ai_type *ait, struct player *pplayer,
817 struct player *target)
818{
819 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, nullptr);
820 struct adv_data *adv = adv_data_get(pplayer, nullptr);
821 int want = 0, fear = 0, distance = 0, settlers = 0, cities = 0;
822 struct player_spaceship *ship = &target->spaceship;
823
824 city_list_iterate(target->cities, pcity) {
825 want += 100; /* Base city want */
826 want += city_size_get(pcity) * 20;
827 want += pcity->surplus[O_SHIELD] * 8;
828 want += pcity->surplus[O_TRADE] * 6;
829
830 /* FIXME: This might be buggy if it ignores unmet UnitClass reqs. */
832
833 city_built_iterate(pcity, pimprove) {
834 int cost = impr_build_shield_cost(pcity, pimprove);
835
836 want += cost;
837 if (improvement_obsolete(pplayer, pimprove, pcity)) {
838 continue;
839 }
840 if (is_great_wonder(pimprove)) {
841 want += cost * 2;
842 } else if (is_small_wonder(pimprove)) {
843 want += cost;
844 }
847 unit_list_iterate(target->units, punit) {
848 const struct unit_type *ptype = unit_type_get(punit);
849
851
852 /* Fear enemy expansionism */
854 want += 100;
855 }
857 unit_list_iterate(pplayer->units, punit) {
858 const struct unit_type *ptype = unit_type_get(punit);
859
860 fear -= ATTACK_POWER(ptype) / 2;
861
862 /* Our own expansionism reduces want for war */
864 want -= 200;
865 settlers++;
866 }
868 city_list_iterate(pplayer->cities, pcity) {
869 if (VUT_UTYPE == pcity->production.kind
870 && utype_is_cityfounder(pcity->production.value.utype)) {
871 want -= 150;
872 settlers++;
873 }
874 cities++;
876
877 /* Modify by settler/cities ratio to prevent early wars when
878 * we should be expanding. This will eliminate want if we
879 * produce settlers in all cities (ie full expansion). */
880 want -= abs(want) / MAX(cities - settlers, 1);
881
882 /* Calculate average distances to other player's empire. */
883 distance = player_distance_to_player(pplayer, target);
884 dai_diplomacy_get(ait, pplayer, target)->distance = distance;
885
886 /* Worry a bit if the other player has extreme amounts of wealth
887 * that can be used in cities to quickly buy an army. */
888 fear += (target->economic.gold / 5000) * city_list_size(target->cities);
889
890 /* Tech lead is worrisome. FIXME: Only consider 'military' techs. */
891 fear += MAX(research_get(target)->techs_researched
892 - research_get(pplayer)->techs_researched, 0) * 100;
893
894 /* Spacerace loss we will not allow! */
895 if (ship->state >= SSHIP_STARTED) {
896 want *= 2;
897 }
898 if (adv->dipl.spacerace_leader == target) {
900
901 return BIG_NUMBER; /* Do NOT amortize this number! */
902 }
903
904 /* Modify by which treaties we would break to other players, and what
905 * excuses we have to do so. FIXME: We only consider immediate
906 * allies, but we might trigger a wider chain reaction. */
908 bool cancel_excuse =
911
912 if (eplayer == pplayer) {
913 continue;
914 }
915
916 /* Remember: pplayers_allied() returns true when target == eplayer */
917 if (!cancel_excuse && pplayers_allied(target, eplayer)) {
918 if (ds == DS_ARMISTICE) {
919 want -= abs(want) / 10; /* 10% off */
920 } else if (ds == DS_CEASEFIRE) {
921 want -= abs(want) / 7; /* 15% off */
922 } else if (ds == DS_PEACE) {
923 want -= abs(want) / 5; /* 20% off */
924 } else if (ds == DS_ALLIANCE) {
925 want -= abs(want) / 3; /* 33% off */
926 }
927 }
929
930 /* Modify by love. Increase the divisor to make ai go to war earlier */
931 want -= MAX(0, want * pplayer->ai_common.love[player_index(target)]
932 / (2 * MAX_AI_LOVE));
933
934 /* Make novice AI more peaceful with human players */
935 if (has_handicap(pplayer, H_DIPLOMACY) && is_human(target)) {
936 want /= 2;
937 }
938
939 /* Amortize by distance */
940 want = amortize(want, distance);
941
942 if (pplayers_allied(pplayer, target)) {
943 want /= 4;
944 }
945
946 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "War want %d, war fear %d",
947 want, fear);
948 return (want - fear);
949}
950
951/******************************************************************/
956static void dai_diplomacy_suggest(struct player *pplayer,
957 struct player *aplayer,
958 enum clause_type what,
959 bool to_pplayer,
960 int value)
961{
962 if (!could_meet_with_player(pplayer, aplayer)) {
963 log_base(LOG_DIPL2, "%s tries to do diplomacy to %s without contact",
964 player_name(pplayer), player_name(aplayer));
965 return;
966 }
967
971 : pplayer),
972 what, value);
973}
974
975/******************************************************************/
978void dai_diplomacy_first_contact(struct ai_type *ait, struct player *pplayer,
979 struct player *aplayer)
980{
981 bool wants_ceasefire = FALSE;
982
983 /* Randomize initial love */
984 pplayer->ai_common.love[player_index(aplayer)] += 2 - fc_rand(5);
985
986 if (is_ai(pplayer)
987 && player_diplstate_get(pplayer, aplayer)->type == DS_WAR
988 && could_meet_with_player(pplayer, aplayer)) {
989 if (has_handicap(pplayer, H_CEASEFIRE)) {
990 fc_assert(!has_handicap(pplayer, H_AWAY));
992 } else if (!has_handicap(pplayer, H_AWAY)) {
993 struct Clause clause;
994
995 clause.from = pplayer;
996 clause.value = 0;
997 clause.type = CLAUSE_CEASEFIRE;
998
999 if (dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1000 FALSE, DS_CEASEFIRE) > 0) {
1002 }
1003 }
1004 }
1005
1006 if (wants_ceasefire) {
1008 _("*%s (AI)* Greetings %s! May we suggest a ceasefire "
1009 "while we get to know each other better?"),
1010 player_name(pplayer),
1012 clear_old_treaty(pplayer, aplayer);
1014 } else {
1016 _("*%s (AI)* I found you %s! Now make it worth my "
1017 "letting you live, or be crushed."),
1018 player_name(pplayer),
1020 }
1021}
1022
1023/******************************************************************/
1032void dai_diplomacy_begin_new_phase(struct ai_type *ait, struct player *pplayer)
1033{
1034 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, nullptr);
1035 struct adv_data *adv = adv_data_get(pplayer, nullptr);
1037 int best_desire = 0;
1038 struct player *best_target = nullptr;
1039
1040 fc_assert_ret(is_ai(pplayer));
1041
1042 if (!pplayer->is_alive) {
1043 return; /* Duh */
1044 }
1045
1046 memset(war_desire, 0, sizeof(war_desire));
1047
1048 /* Calculate our desires, and find desired war target */
1050 /* We don't hate ourselves, those we don't know or team members. */
1051 if (aplayer == pplayer
1052 || NEVER_MET(pplayer, aplayer)
1053 || players_on_same_team(pplayer, aplayer)) {
1054 continue;
1055 }
1060 }
1062
1063 /* Time to make love. If we've been wronged, hold off that love
1064 * for a while. Also, cool our head each turn with love_coeff. */
1066 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1067 int amount = 0;
1068 int pit;
1069
1070 if (pplayer == aplayer) {
1071 continue;
1072 }
1073
1074 if ((pplayers_non_attack(pplayer, aplayer)
1075 || pplayers_allied(pplayer, aplayer))
1076 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel == 0
1077 && adip->countdown == -1
1078 && !adip->is_allied_with_enemy
1079 && !adip->at_war_with_ally
1080 && aplayer != best_target
1081 && adip->ally_patience >= 0) {
1082 amount += ai->diplomacy.love_incr / 2;
1083 if (pplayers_allied(pplayer, aplayer)) {
1084 amount += ai->diplomacy.love_incr / 3;
1085 }
1086 /* Increase love by each enemy they are at war with */
1088 if (WAR(eplayer, aplayer) && WAR(pplayer, eplayer)) {
1089 amount += ai->diplomacy.love_incr / 4;
1090 }
1093 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Increased love by %d", amount);
1094 } else if (WAR(pplayer, aplayer)) {
1095 amount -= ai->diplomacy.love_incr / 2;
1097 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost to war", amount);
1098 } else if (player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel
1099 != 0) {
1100 /* Provoked in time of peace */
1101 if (pplayer->ai_common.love[player_index(aplayer)] > 0) {
1102 amount -= pplayer->ai_common.love[player_index(aplayer)] / 2;
1103 }
1104 amount -= ai->diplomacy.love_incr * 6;
1106 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Provoked! %d love lost!",
1107 amount);
1108 }
1109 if (pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE * 8 / 10
1110 && !pplayers_allied(pplayer, aplayer)) {
1111 int love_change = ai->diplomacy.love_incr / 3;
1112
1113 /* Upper levels of AI trust and love is reserved for allies. */
1115 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost from excess",
1116 love_change);
1117 }
1118 amount = 0;
1119
1120 /* Reduce love due to units in our territory.
1121 * AI is so naive, that we have to count it even if players are allied */
1122 pit = player_in_territory(pplayer, aplayer) * (MAX_AI_LOVE / 200);
1123 amount -= MIN(pit,
1125 * ((adip->is_allied_with_enemy != nullptr) + 1));
1127 if (amount != 0) {
1128 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost due to units inside "
1129 "our borders", amount);
1130 }
1131
1132 /* Increase the love if aplayer has got a building that makes
1133 * us love them more. Typically it's Eiffel Tower */
1134 if (!NEVER_MET(pplayer, aplayer)) {
1135 pplayer->ai_common.love[player_index(aplayer)] +=
1137 }
1139
1140 /* Can we win by space race? */
1141 if (adv->dipl.spacerace_leader == pplayer) {
1142 log_base(LOG_DIPL2, "%s going for space race victory!",
1143 player_name(pplayer));
1144 ai->diplomacy.strategy = WIN_SPACE; /* Yes! */
1145 } else {
1146 if (ai->diplomacy.strategy == WIN_SPACE) {
1148 }
1149 }
1150
1152 int *love = &pplayer->ai_common.love[player_index(aplayer)];
1153
1154 if (aplayer == best_target && best_desire > 0) {
1155 int reduction = MIN(best_desire, MAX_AI_LOVE / 20);
1156
1157 *love -= reduction;
1158 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Wants war, reducing "
1159 "love by %d ", reduction);
1160 }
1161
1162 /* Edge love towards zero */
1163 *love -= *love * ((double)ai->diplomacy.love_coeff / 100.0);
1164
1165 /* AI love should always be in range [-MAX_AI_LOVE..MAX_AI_LOVE] */
1166 *love = MAX(-MAX_AI_LOVE, MIN(MAX_AI_LOVE, *love));
1168}
1169
1170/******************************************************************/
1173static void suggest_tech_exchange(struct ai_type *ait,
1174 struct player *player1,
1175 struct player *player2)
1176{
1180 int worth[ac];
1181 bool is_dangerous;
1182
1183 worth[A_NONE] = 0;
1184
1187 == TECH_KNOWN) {
1190 worth[tech] = -compute_tech_sell_price(ait, player1, player2, tech,
1191 &is_dangerous);
1192 if (is_dangerous) {
1193 /* Don't try to exchange */
1194 worth[tech] = 0;
1195 }
1196 } else {
1197 worth[tech] = 0;
1198 }
1199 } else {
1203 worth[tech] = compute_tech_sell_price(ait, player2, player1, tech,
1204 &is_dangerous);
1205 if (is_dangerous) {
1206 /* Don't try to exchange */
1207 worth[tech] = 0;
1208 }
1209 } else {
1210 worth[tech] = 0;
1211 }
1212 }
1214
1216 if (worth[tech] <= 0) {
1217 continue;
1218 }
1220 int diff;
1221
1222 if (worth[tech2] >= 0) {
1223 continue;
1224 }
1225 /* Tech2 is given by player1, tech is given by player2 */
1226 diff = worth[tech] + worth[tech2];
1227 if ((diff > 0 && player1->economic.gold >= diff)
1228 || (diff < 0 && player2->economic.gold >= -diff)
1229 || diff == 0) {
1232 if (diff > 0) {
1234 } else if (diff < 0) {
1236 }
1237 return;
1238 }
1241}
1242
1243/******************************************************************/
1246static void clear_old_treaty(struct player *pplayer, struct player *aplayer)
1247{
1248 struct treaty *old_treaty = find_treaty(pplayer, aplayer);
1249
1250 if (old_treaty != nullptr) {
1251 /* Remove existing clauses */
1254 player_number(pplayer),
1255 player_number(pclause->from),
1256 pclause->type, pclause->value);
1257 free(pclause);
1260 old_treaty->clauses = clause_list_new();
1261 }
1262}
1263
1264/******************************************************************/
1267static void dai_share(struct ai_type *ait, struct player *pplayer,
1268 struct player *aplayer)
1269{
1270 struct research *presearch = research_get(pplayer);
1272 bool gives_vision;
1273
1274 clear_old_treaty(pplayer, aplayer);
1275
1276 /* Only share techs with team mates */
1277 if (presearch != aresearch
1278 && players_on_same_team(pplayer, aplayer)) {
1290 }
1292 }
1293
1294 /* Only give shared vision if safe. Only ask for shared vision if fair. */
1296 if (!gives_vision
1297 && shared_vision_is_safe(pplayer, aplayer)) {
1300 }
1301 if (gives_vision
1302 && !gives_shared_vision(aplayer, pplayer)
1303 && (is_human(aplayer)
1304 || shared_vision_is_safe(aplayer, pplayer))) {
1306 }
1307
1308 if (!player_has_embassy(pplayer, aplayer)) {
1310 }
1311 if (!player_has_embassy(aplayer, pplayer)) {
1313 }
1314
1315 if (!has_handicap(pplayer, H_DIPLOMACY) || is_human(aplayer)) {
1316 suggest_tech_exchange(ait, pplayer, aplayer);
1317 }
1318}
1319
1320/******************************************************************/
1327static void dai_declare_war(struct ai_type *ait, struct player *pplayer,
1328 struct player *target)
1329{
1330 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1331
1332 /* This will take us straight to war. */
1333 while (player_diplstate_get(pplayer, target)->type != DS_WAR) {
1334 if (pplayer_can_cancel_treaty(pplayer, target) != DIPL_OK) {
1335 DIPLO_LOG(ait, LOG_ERROR, pplayer, target,
1336 "Wanted to cancel treaty but was unable to.");
1337 adip->countdown = -1; /* War declaration aborted */
1338
1339 return;
1340 }
1342 }
1343
1344 /* Throw a tantrum */
1345 if (pplayer->ai_common.love[player_index(target)] > 0) {
1346 pplayer->ai_common.love[player_index(target)] = -1;
1347 }
1348 pplayer->ai_common.love[player_index(target)] -= MAX_AI_LOVE / 8;
1349
1350 fc_assert(!gives_shared_vision(pplayer, target));
1351
1352 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "war declared");
1353}
1354
1355/******************************************************************/
1360static void dai_go_to_war(struct ai_type *ait, struct player *pplayer,
1361 struct player *target, enum war_reason reason)
1362{
1363 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1364
1365 fc_assert_ret(pplayer != target);
1366 fc_assert_ret(target->is_alive);
1367
1368 switch (reason) {
1369 case DAI_WR_SPACE:
1370 dai_diplo_notify(target, _("*%s (AI)* Space will never be yours."),
1371 player_name(pplayer));
1372 adip->countdown = -10;
1373 break;
1374 case DAI_WR_BEHAVIOR:
1375 dai_diplo_notify(target,
1376 _("*%s (AI)* I have tolerated your vicious antics "
1377 "long enough! To war!"),
1378 player_name(pplayer));
1379 adip->countdown = -20;
1380 break;
1381 case DAI_WR_NONE:
1382 dai_diplo_notify(target, _("*%s (AI)* Peace in ... some other time."),
1383 player_name(pplayer));
1384 adip->countdown = -10;
1385 break;
1386 case DAI_WR_HATRED:
1387 dai_diplo_notify(target,
1388 _("*%s (AI)* Finally I get around to you! Did "
1389 "you really think you could get away with your crimes?"),
1390 player_name(pplayer));
1391 adip->countdown = -20;
1392 break;
1393 case DAI_WR_EXCUSE:
1394 dai_diplo_notify(target,
1395 _("*%s (AI)* Your covert hostilities brought "
1396 "this war upon you!"),
1397 player_name(pplayer));
1398 adip->countdown = -20;
1399 break;
1400 case DAI_WR_ALLIANCE:
1401 if (adip->at_war_with_ally) {
1402 dai_diplo_notify(target,
1403 _("*%s (AI)* Your aggression against %s was "
1404 "your last mistake!"),
1405 player_name(pplayer),
1406 player_name(adip->at_war_with_ally));
1407 adip->countdown = -3;
1408 } else {
1409 /* Ooops! */
1410 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "Wanted to declare war "
1411 "for their war against an ally, but can no longer find "
1412 "this ally! War declaration aborted.");
1413 adip->countdown = -1;
1414 return;
1415 }
1416 break;
1417 }
1418
1419 fc_assert_ret(adip->countdown < 0);
1420
1421 if (gives_shared_vision(pplayer, target)) {
1422 remove_shared_vision(pplayer, target);
1423 }
1424
1425 /* Check for Senate obstruction. If so, dissolve it. */
1426 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_SENATE_BLOCKING) {
1427 struct government *real_gov = pplayer->government;
1428
1430
1431 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_OK) {
1432 /* It seems that revolution would help. */
1433 pplayer->government = real_gov;
1436 def_ai_player_data(pplayer, ait)->diplomacy.war_target = target;
1437 return;
1438 } else {
1439 /* There would be Senate even during revolution. Better not to revolt for nothing */
1440 pplayer->government = real_gov;
1441 adip->countdown = -1; /* War declaration aborted */
1442
1443 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target,
1444 "Not revolting, as there would be Senate regardless.");
1445
1446 return;
1447 }
1448 }
1449
1450 dai_declare_war(ait, pplayer, target);
1451}
1452
1453/******************************************************************/
1459void dai_revolution_start(struct ai_type *ait, struct player *pplayer)
1460{
1461 struct ai_plr *data = def_ai_player_data(pplayer, ait);
1462
1463 if (data->diplomacy.war_target != nullptr) {
1464 if (gives_shared_vision(pplayer, data->diplomacy.war_target)) {
1466 }
1467
1468 dai_declare_war(ait, pplayer, data->diplomacy.war_target);
1469
1470 data->diplomacy.war_target = nullptr;
1471 }
1472}
1473
1474/******************************************************************/
1486static void war_countdown(struct ai_type *ait, struct player *pplayer,
1487 struct player *target,
1488 int countdown, enum war_reason reason)
1489{
1490 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1491
1492 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "countdown to war in %d", countdown);
1493
1494 /* Otherwise we're resetting an existing countdown, which is very bad */
1495 fc_assert_ret(adip->countdown == -1);
1496
1497 adip->countdown = countdown;
1498 adip->war_reason = reason;
1499
1501 if (!pplayers_allied(pplayer, ally)
1502 || ally == target
1503 || NEVER_MET(pplayer, ally)) {
1504 continue;
1505 }
1506
1507 switch (reason) {
1508 case DAI_WR_SPACE:
1510 PL_("*%s (AI)* We will be launching an all-out war "
1511 "against %s in %d turn to stop the spaceship "
1512 "launch.",
1513 "*%s (AI)* We will be launching an all-out war "
1514 "against %s in %d turns to stop the spaceship "
1515 "launch.",
1516 countdown),
1517 player_name(pplayer),
1518 player_name(target),
1519 countdown);
1521 _("*%s (AI)* Your aid in this matter will be expected. "
1522 "Long live our glorious alliance!"),
1523 player_name(pplayer));
1524 break;
1525 case DAI_WR_BEHAVIOR:
1526 case DAI_WR_EXCUSE:
1528 PL_("*%s (AI)* %s has grossly violated their treaties "
1529 "with us for own gain. We will answer in force in "
1530 "%d turn and expect you to honor your alliance "
1531 "with us and do likewise!",
1532 "*%s (AI)* %s has grossly violated their treaties "
1533 "with us for own gain. We will answer in force in "
1534 "%d turns and expect you to honor your alliance "
1535 "with us and do likewise!", countdown),
1536 player_name(pplayer),
1537 player_name(target),
1538 countdown);
1539 break;
1540 case DAI_WR_NONE:
1542 PL_("*%s (AI)* We intend to pillage and plunder the rich "
1543 "civilization of %s. We declare war in %d turn.",
1544 "*%s (AI)* We intend to pillage and plunder the rich "
1545 "civilization of %s. We declare war in %d turns.",
1546 countdown),
1547 player_name(pplayer),
1548 player_name(target),
1549 countdown);
1551 _("*%s (AI)* If you want a piece of the loot, feel "
1552 "free to join in the action!"),
1553 player_name(pplayer));
1554 break;
1555 case DAI_WR_HATRED:
1557 PL_("*%s (AI)* We have had it with %s. Let us tear this "
1558 "pathetic civilization apart. We declare war in "
1559 "%d turn.",
1560 "*%s (AI)* We have had it with %s. Let us tear this "
1561 "pathetic civilization apart. We declare war in "
1562 "%d turns.",
1563 countdown),
1564 player_name(pplayer),
1565 player_name(target),
1566 countdown);
1568 _("*%s (AI)* As our glorious allies, we expect your "
1569 "help in this war."),
1570 player_name(pplayer));
1571 break;
1572 case DAI_WR_ALLIANCE:
1573 if (WAR(ally, target)) {
1575 PL_("*%s (AI)* We will honor our alliance and declare "
1576 "war on %s in %d turn. Hold on - we are coming!",
1577 "*%s (AI)* We will honor our alliance and declare "
1578 "war on %s in %d turns. Hold on - we are coming!",
1579 countdown),
1580 player_name(pplayer),
1581 player_name(target),
1582 countdown);
1583 } else if (adip->at_war_with_ally) {
1585 PL_("*%s (AI)* We will honor our alliance with %s and "
1586 "declare war on %s in %d turns. We expect you to "
1587 "do likewise.",
1588 "*%s (AI)* We will honor our alliance with %s and "
1589 "declare war on %s in %d turns. We expect you to "
1590 "do likewise.",
1591 countdown),
1592 player_name(pplayer),
1593 player_name(adip->at_war_with_ally),
1594 player_name(target),
1595 countdown);
1596 } else {
1597 fc_assert(FALSE); /* Huh? */
1598 }
1599 break;
1600 }
1602}
1603
1604/******************************************************************/
1610void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
1611{
1612 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, nullptr);
1613 bool need_targets = TRUE;
1614 struct player *target = nullptr;
1616 int war_threshold;
1617 int aggr;
1618 float aggr_sr;
1619 float max_sr;
1620
1621 fc_assert_ret(is_ai(pplayer));
1622
1623 if (!pplayer->is_alive) {
1624 return;
1625 }
1626
1627 if (get_player_bonus(pplayer, EFT_NO_DIPLOMACY) > 0) {
1628 /* Diplomacy disabled for this player */
1629 return;
1630 }
1631
1632 /*** If we are greviously insulted, go to war immediately. ***/
1633
1635 if (pplayer->ai_common.love[player_index(aplayer)] < 0
1636 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel >= 2
1637 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown == -1) {
1638 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Plans war in revenge");
1639 war_countdown(ait, pplayer, aplayer, map_size_checked(),
1641 }
1643
1644 /*** Stop other players from winning by space race ***/
1645
1646 if (ai->diplomacy.strategy != WIN_SPACE) {
1647 struct adv_data *adv = adv_data_get(pplayer, nullptr);
1648
1650 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1651 struct player_spaceship *ship = &aplayer->spaceship;
1652
1653 if (aplayer == pplayer
1654 || adip->countdown >= 0 /* Already counting down to war */
1655 || ship->state == SSHIP_NONE
1656 || players_on_same_team(pplayer, aplayer)
1657 || pplayers_at_war(pplayer, aplayer)) {
1658 continue;
1659 }
1660
1661 /* A spaceship victory is always one single player's or team's victory */
1662 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1663 && adv->dipl.spacerace_leader == aplayer
1664 && pplayers_allied(pplayer, aplayer)) {
1666 _("*%s (AI)* Your attempt to conquer space for "
1667 "yourself alone betrays your true intentions, and I "
1668 "will have no more of our alliance!"),
1669 player_name(pplayer));
1672 if (gives_shared_vision(pplayer, aplayer)) {
1673 remove_shared_vision(pplayer, aplayer);
1674 }
1675 /* Never forgive this */
1677 } else if (ship->state == SSHIP_STARTED
1678 && adip->warned_about_space == 0) {
1679 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 10;
1680 adip->warned_about_space = 10 + fc_rand(6);
1682 _("*%s (AI)* Your attempt to unilaterally "
1683 "dominate outer space is highly offensive."),
1684 player_name(pplayer));
1686 _("*%s (AI)* If you do not stop constructing your "
1687 "spaceship, I may be forced to take action!"),
1688 player_name(pplayer));
1689 }
1690 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1691 && aplayer == adv->dipl.spacerace_leader) {
1692 /* This means war!!! */
1693 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 2;
1694 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "plans war due to spaceship");
1695 war_countdown(ait, pplayer, aplayer, 4 + map_size_checked(),
1696 DAI_WR_SPACE);
1697 }
1699 }
1700
1701 /*** Declare war against somebody if we are out of targets ***/
1702
1704 int turns; /* Turns since contact */
1705
1706 if (NEVER_MET(pplayer, aplayer)) {
1707 continue;
1708 }
1709 turns = game.info.turn;
1711 if (WAR(pplayer, aplayer)) {
1713 } else if (pplayer->ai_common.love[player_index(aplayer)] < most_hatred
1714 && turns > TURNS_BEFORE_TARGET) {
1716 target = aplayer;
1717 }
1719
1722 aggr_sr = sqrt(aggr);
1723
1724 war_threshold = (MAX_AI_LOVE * (0.70 + aggr_sr / max_sr / 2.0)) - MAX_AI_LOVE;
1725
1726 if (need_targets && target && most_hatred < war_threshold
1727 && dai_diplomacy_get(ait, pplayer, target)->countdown == -1) {
1728 enum war_reason war_reason;
1729
1730 if (pplayers_allied(pplayer, target)) {
1731 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "Plans war against an ally!");
1732 }
1733 if (player_diplstate_get(pplayer, target)->has_reason_to_cancel > 0) {
1734 /* We have good reason */
1735 war_reason = DAI_WR_EXCUSE;
1736 } else if (pplayer->ai_common.love[player_index(target)] < 0) {
1737 /* We have a reason of sorts from way back, maybe? */
1738 war_reason = DAI_WR_HATRED;
1739 } else {
1740 /* We have no legimitate reason... So what? */
1741 war_reason = DAI_WR_NONE;
1742 }
1743 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "plans war for spoils");
1744 war_countdown(ait, pplayer, target, 4 + map_size_checked(), war_reason);
1745 }
1746
1747 /*** Declare war - against enemies of allies ***/
1748
1750 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1751
1752 if (adip->at_war_with_ally
1753 && adip->countdown == -1
1754 && !adip->is_allied_with_ally
1755 && !pplayers_at_war(pplayer, aplayer)
1757 || fc_rand(5) < 1)) {
1758 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "plans war to help ally %s",
1759 player_name(adip->at_war_with_ally));
1760 war_countdown(ait, pplayer, aplayer, 2 + map_size_checked(),
1762 }
1764
1765 /*** Actually declare war (when we have moved units into position) ***/
1766
1768 if (!players_on_same_team(pplayer, aplayer)) {
1769 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1770
1771 if (!aplayer->is_alive) {
1772 adip->countdown = -1;
1773 continue;
1774 }
1775 if (adip->countdown > 0) {
1776 adip->countdown--;
1777 } else if (adip->countdown == 0) {
1778 if (!WAR(pplayer, aplayer)) {
1779 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Declaring war!");
1780 dai_go_to_war(ait, pplayer, aplayer, adip->war_reason);
1781 }
1782 } else if (adip->countdown < -1) {
1783 /* Negative countdown less than -1 is war stubbornness */
1784 adip->countdown++;
1785 }
1786 }
1788
1789 /*** Try to make peace with everyone we love ***/
1790
1793 && diplomacy_possible(pplayer, aplayer)) {
1795 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1796 struct Clause clause;
1797
1798 /* Meaningless values, but rather not have them unset. */
1799 clause.from = pplayer;
1800 clause.value = 0;
1801
1802 /* Remove shared vision if we are not allied or it is no longer safe. */
1803 if (gives_shared_vision(pplayer, aplayer)) {
1804 if (!pplayers_allied(pplayer, aplayer)) {
1805 remove_shared_vision(pplayer, aplayer);
1806 } else if (!players_on_same_team(pplayer, aplayer)
1807 && !shared_vision_is_safe(pplayer, aplayer)) {
1809 _("*%s (AI)* Sorry, sharing vision with you "
1810 "is no longer safe."),
1811 player_name(pplayer));
1812 remove_shared_vision(pplayer, aplayer);
1813 }
1814 }
1815
1816 /* No peace to enemies of our allies... or pointless peace. */
1818 || aplayer == pplayer
1819 || aplayer == target /* no mercy */
1820 || adip->countdown >= 0
1821 || !could_meet_with_player(pplayer, aplayer)) {
1822 continue;
1823 }
1824
1825 /* Spam control */
1826 adip->asked_about_peace = MAX(adip->asked_about_peace - 1, 0);
1827 adip->asked_about_alliance = MAX(adip->asked_about_alliance - 1, 0);
1828 adip->asked_about_ceasefire = MAX(adip->asked_about_ceasefire - 1, 0);
1829 adip->warned_about_space = MAX(adip->warned_about_space - 1, 0);
1830 adip->spam = MAX(adip->spam - 1, 0);
1831 if (adip->spam > 0 && is_ai(aplayer)) {
1832 /* Don't spam */
1833 continue;
1834 }
1835
1836 /* Canvass support from existing friends for our war, and try to
1837 * make friends with enemies. Then we wait some turns until next time
1838 * we spam them with our gibbering chatter. */
1839 if (adip->spam <= 0) {
1840 if (!pplayers_allied(pplayer, aplayer)) {
1841 adip->spam = fc_rand(4) + 3; /* Bugger allies often. */
1842 } else {
1843 adip->spam = fc_rand(8) + 6; /* Others are less important. */
1844 }
1845 }
1846
1847 switch (ds) {
1848 case DS_TEAM:
1849 dai_share(ait, pplayer, aplayer);
1850 break;
1851 case DS_ALLIANCE:
1852 /* See if our allies are diligently declaring war on our enemies... */
1853 if (adip->at_war_with_ally) {
1854 break;
1855 }
1856 target = nullptr;
1858 if (WAR(pplayer, eplayer)
1860 target = eplayer;
1861 break;
1862 }
1864
1865 if ((players_on_same_team(pplayer, aplayer)
1866 || pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE / 2)) {
1867 /* Share techs only with team mates and allies we really like. */
1868 dai_share(ait, pplayer, aplayer);
1869 }
1870 if (!target || !target->is_alive) {
1871 adip->ally_patience = 0;
1872 break; /* No need to nag our ally */
1873 }
1874
1875 if (adip->spam <= 0) {
1876 /* Count down patience toward AI player (one that can have spam > 0)
1877 * at the same speed as toward human players. */
1878 if (adip->ally_patience == 0) {
1880 _("*%s (AI)* Greetings our most trustworthy "
1881 "ally. We call upon you to destroy our enemy, %s."),
1882 player_name(pplayer),
1883 player_name(target));
1884 adip->ally_patience--;
1885 } else if (adip->ally_patience == -1) {
1886 if (fc_rand(5) == 1) {
1888 _("*%s (AI)* Greetings ally, I see you have not yet "
1889 "made war with our enemy, %s. Why do I need to remind "
1890 "you of your promises?"),
1891 player_name(pplayer),
1892 player_name(target));
1893 adip->ally_patience--;
1894 }
1895 } else if (fc_rand(5) == 1
1896 && !players_on_same_team(pplayer, aplayer)) {
1898 _("*%s (AI)* Dishonored one, we made a pact of "
1899 "alliance, and yet you remain at peace with our mortal "
1900 "enemy, %s! This is unacceptable; our alliance is no "
1901 "more!"),
1902 player_name(pplayer),
1903 player_name(target));
1904 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer,
1905 "breaking useless alliance");
1906 /* To peace */
1910 = MIN(pplayer->ai_common.love[player_index(aplayer)], 0);
1911 if (gives_shared_vision(pplayer, aplayer)) {
1912 remove_shared_vision(pplayer, aplayer);
1913 }
1914
1916 }
1917 }
1918 break;
1919
1920 case DS_PEACE:
1921 clause.type = CLAUSE_ALLIANCE;
1922 if (adip->at_war_with_ally
1923 || (is_human(aplayer) && adip->asked_about_alliance > 0)
1924 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1925 FALSE, DS_ALLIANCE) < 0) {
1926 break;
1927 }
1928 clear_old_treaty(pplayer, aplayer);
1930 adip->asked_about_alliance = is_human(aplayer) ? 13 : 0;
1932 _("*%s (AI)* Greetings friend, may we suggest "
1933 "making a common cause and join in an alliance?"),
1934 player_name(pplayer));
1935 break;
1936
1937 case DS_CEASEFIRE:
1938 clause.type = CLAUSE_PEACE;
1939 if (adip->at_war_with_ally
1940 || (is_human(aplayer) && adip->asked_about_peace > 0)
1941 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1942 FALSE, DS_PEACE) < 0) {
1943 break;
1944 }
1945 clear_old_treaty(pplayer, aplayer);
1947 adip->asked_about_peace = is_human(aplayer) ? 12 : 0;
1949 _("*%s (AI)* Greetings neighbor, may we suggest "
1950 "more peaceful relations?"),
1951 player_name(pplayer));
1952 break;
1953
1954 case DS_NO_CONTACT: /* But we do have embassy! weird. */
1955 case DS_WAR:
1956 clause.type = CLAUSE_CEASEFIRE;
1957 if ((is_human(aplayer) && adip->asked_about_ceasefire > 0)
1958 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1959 FALSE, DS_CEASEFIRE) < 0) {
1960 break; /* Fight until the end! */
1961 }
1962 clear_old_treaty(pplayer, aplayer);
1964 adip->asked_about_ceasefire = is_human(aplayer) ? 9 : 0;
1966 _("*%s (AI)* We grow weary of this constant "
1967 "bloodshed. May we suggest a cessation of hostilities?"),
1968 player_name(pplayer));
1969 break;
1970
1971 case DS_ARMISTICE:
1972 break;
1973 default:
1974 fc_assert_msg(FALSE, "Unknown pact type %d.", ds);
1975 break;
1976 }
1977 }
1979}
1980
1981/******************************************************************/
1985bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
1986{
1987 players_iterate(plr) {
1988 if (dai_diplomacy_get(ait, pplayer, plr)->countdown >= 0) {
1989 return TRUE;
1990 }
1992
1993 return FALSE;
1994}
1995
1996/******************************************************************/
1999/* AI attitude call-backs */
2002 const struct action *paction,
2003 struct player *receiver,
2004 struct player *violator, struct player *victim)
2005{
2006 if (!is_ai(receiver) || violator == receiver) {
2007 return;
2008 }
2009
2010 /* Can only handle victim only and international incidents. */
2013
2014 switch (type) {
2015 case INCIDENT_ACTION:
2016 /* Feel free the change how the action results are grouped and how bad
2017 * the ai considers each group. */
2018 switch (paction->result) {
2019 case ACTRES_SPY_NUKE:
2020 case ACTRES_NUKE:
2021 case ACTRES_NUKE_UNITS:
2022 if (receiver == victim) {
2023 /* Tell the victim */
2025 } else if (violator == victim) {
2027 } else {
2029 }
2030 break;
2033 /* Snoping */
2034 dai_incident_simple(receiver, violator, victim, scope, 2);
2035 break;
2039 case ACTRES_STEAL_MAPS:
2040 /* Theft */
2041 dai_incident_simple(receiver, violator, victim, scope, 5);
2042 break;
2043 case ACTRES_EXPEL_UNIT:
2044 /* Unit position loss */
2045 dai_incident_simple(receiver, violator, victim, scope, 1);
2046 break;
2048 /* Unit weakening */
2049 dai_incident_simple(receiver, violator, victim, scope, 3);
2050 break;
2054 case ACTRES_BOMBARD:
2055 case ACTRES_ATTACK:
2056 case ACTRES_WIPE_UNITS:
2057 case ACTRES_SPY_ATTACK:
2059 /* Unit loss */
2060 dai_incident_simple(receiver, violator, victim, scope, 5);
2061 break;
2065 /* City loss */
2066 dai_incident_simple(receiver, violator, victim, scope, 10);
2067 break;
2073 /* Building loss */
2074 dai_incident_simple(receiver, violator, victim, scope, 5);
2075 break;
2076 case ACTRES_SPY_POISON:
2078 /* Population loss */
2079 dai_incident_simple(receiver, violator, victim, scope, 5);
2080 break;
2081 case ACTRES_FOUND_CITY:
2082 /* Terrain loss */
2083 dai_incident_simple(receiver, violator, victim, scope, 4);
2084 break;
2086 case ACTRES_PILLAGE:
2087 /* Extra loss */
2088 dai_incident_simple(receiver, violator, victim, scope, 2);
2089 break;
2090 case ACTRES_UNIT_MOVE:
2091 case ACTRES_TELEPORT:
2093 case ACTRES_SPY_ESCAPE:
2094 case ACTRES_TRADE_ROUTE:
2095 case ACTRES_MARKETPLACE:
2096 case ACTRES_HELP_WONDER:
2097 case ACTRES_JOIN_CITY:
2100 case ACTRES_HOME_CITY:
2101 case ACTRES_HOMELESS:
2103 case ACTRES_PARADROP:
2104 case ACTRES_PARADROP_CONQUER: /* TODO: Bigger incident */
2105 case ACTRES_AIRLIFT:
2106 case ACTRES_HEAL_UNIT:
2108 case ACTRES_CULTIVATE:
2109 case ACTRES_PLANT:
2110 case ACTRES_CLEAN:
2111 case ACTRES_FORTIFY:
2112 case ACTRES_ROAD:
2113 case ACTRES_CONVERT:
2114 case ACTRES_BASE:
2115 case ACTRES_MINE:
2116 case ACTRES_IRRIGATE:
2123 case ACTRES_HUT_ENTER:
2126 case ACTRES_NONE:
2127 /* Various */
2128 dai_incident_simple(receiver, violator, victim, scope, 1);
2129 break;
2130
2132 }
2133 break;
2134 case INCIDENT_WAR:
2135 if (receiver == victim) {
2137 }
2138 break;
2139 case INCIDENT_LAST:
2140 /* Assert that always fails, but with meaningful message */
2142 break;
2143 }
2144}
2145
2146/******************************************************************/
2149static void dai_incident_nuclear(struct player *receiver,
2150 const struct player *violator,
2151 const struct player *victim)
2152{
2153 fc_assert_ret(receiver == victim);
2154
2155 if (violator == victim) {
2156 return;
2157 }
2158
2159 receiver->ai_common.love[player_index(violator)] -= 3 * MAX_AI_LOVE / 10;
2160}
2161
2162/******************************************************************/
2165static void dai_incident_nuclear_not_target(struct player *receiver,
2166 const struct player *violator,
2167 const struct player *victim)
2168{
2169 fc_assert_ret(receiver != victim);
2170
2171 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2172}
2173
2174/******************************************************************/
2177static void dai_incident_nuclear_self(struct player *receiver,
2178 const struct player *violator,
2179 const struct player *victim)
2180{
2181 fc_assert_ret(receiver != victim);
2183
2184 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 20;
2185}
2186
2187/**********************************************************************/
2199static void dai_incident_simple(struct player *receiver,
2200 const struct player *violator,
2201 const struct player *victim,
2203 int how_bad)
2204{
2206 if (victim == receiver) {
2208 /* The ruleset finds this bad enough to cause International Outrage.
2209 * Trust the ruleset author. Double the displeasure. */
2211 }
2212 receiver->ai_common.love[player_index(violator)] -= displeasure / 35;
2213 } else if (violator == victim) {
2214 receiver->ai_common.love[player_index(violator)] -= displeasure / 1000;
2215 } else {
2216 receiver->ai_common.love[player_index(violator)] -= displeasure / 500;
2217 }
2218}
2219
2220/******************************************************************/
2228static void dai_incident_war(struct player *violator, struct player *victim)
2229{
2230 players_iterate(pplayer) {
2231 if (!is_ai(pplayer)) {
2232 continue;
2233 }
2234
2235 if (pplayer != violator) {
2236 /* Dislike backstabbing bastards */
2237 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2238 if (player_diplstate_get(violator, victim)->max_state == DS_PEACE) {
2239 /* Extra penalty if they once had a peace treaty */
2240 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2241 } else if (player_diplstate_get(violator, victim)->max_state
2242 == DS_ALLIANCE) {
2243 /* Extra penalty if they once had an alliance */
2244 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2245 }
2246 if (victim == pplayer) {
2247 pplayer->ai_common.love[player_index(violator)] =
2248 MIN(pplayer->ai_common.love[player_index(violator)] - MAX_AI_LOVE / 3, -1);
2249 /* Scream for help!! */
2251 if (!pplayers_allied(pplayer, ally)) {
2252 continue;
2253 }
2255 _("*%s (AI)* We have been savagely attacked by "
2256 "%s, and we need your help! Honor our glorious "
2257 "alliance and your name will never be forgotten!"),
2261 }
2262 }
2264}
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:606
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1113
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(const struct civ_map *nmap, 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: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:835
#define city_built_iterate_end
Definition city.h:841
char * incite_cost
Definition comments.c:76
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
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_treaty_accepted(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct treaty *ptreaty)
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)
#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)
void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct treaty *ptreaty)
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 const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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:73
#define clause_list_iterate(clauselist, pclause)
Definition diptreaty.h:71
#define is_pact_clause(x)
Definition diptreaty.h:53
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:237
#define ACTRES_NONE
Definition fc_types.h:187
@ O_SHIELD
Definition fc_types.h:102
@ O_TRADE
Definition fc_types.h:102
#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
struct world wld
Definition game.c:63
GType type
Definition repodlgs.c:1313
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:182
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_base(level, message,...)
Definition log.h:95
@ LOG_ERROR
Definition log.h:31
@ LOG_DEBUG
Definition log.h:35
#define log_error(message,...)
Definition log.h:104
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)
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:882
#define map_size_checked()
Definition map.h:268
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1698
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
struct city_list * cities
Definition packhand.c:120
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1488
int player_slot_count(void)
Definition player.c:420
int player_number(const struct player *pplayer)
Definition player.c:839
const char * player_name(const struct player *pplayer)
Definition player.c:900
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1396
int player_index(const struct player *pplayer)
Definition player.c:831
int player_in_territory(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1892
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:1417
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1471
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:1497
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1438
#define players_iterate_end
Definition player.h:542
@ DIPL_SENATE_BLOCKING
Definition player.h:193
@ DIPL_OK
Definition player.h:193
#define players_iterate(_pplayer)
Definition player.h:537
#define MAX_AI_LOVE
Definition player.h:566
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:552
#define is_human(plr)
Definition player.h:231
#define players_iterate_alive(_pplayer)
Definition player.h:547
#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:810
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1062
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:775
struct research * research_get(const struct player *pplayer)
Definition research.c:130
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:622
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:696
#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:76
struct player * from
Definition diptreaty.h:77
int value
Definition diptreaty.h:78
struct adv_data::@95 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::@283 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:318
int diplgoldcost
Definition game.h:147
struct packet_game_info info
Definition game.h:89
struct civ_game::@32::@36 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::@73::@75 server
struct player_economic economic
Definition player.h:284
struct player_spaceship spaceship
Definition player.h:286
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 clause_list * clauses
Definition diptreaty.h:84
struct player * plr0
Definition diptreaty.h:82
struct unit_type::@90 adv
const struct unit_type * utype
Definition unit.h:141
struct civ_map map
#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:250
#define advance_index_iterate_end
Definition tech.h:246
#define advance_index_iterate_max_end
Definition tech.h:256
static Tech_type_id advance_count(void)
Definition tech.h:167
#define A_FIRST
Definition tech.h:44
#define A_NONE
Definition tech.h:43
#define advance_index_iterate(_start, _index)
Definition tech.h:242
#define TRAIT_MAX_VALUE_SR
Definition traits.h:34
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2745
#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:126
bool utype_is_cityfounder(const struct unit_type *utype)
Definition unittype.c:2997