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 worth /= 2;
355 }
356 }
357 }
358 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "%s clause worth %d",
360 break;
361
362 case CLAUSE_ALLIANCE:
363 case CLAUSE_PEACE:
364 case CLAUSE_CEASEFIRE:
365 /* Don't do anything in away mode */
366 if (has_handicap(pplayer, H_AWAY)) {
367 dai_diplo_notify(aplayer, _("*%s (AI)* In away mode AI can't sign such a treaty."),
368 player_name(pplayer));
369 worth = -BIG_NUMBER;
370 break;
371 }
372
373 /* This guy is allied to one of our enemies. Only accept
374 * ceasefire. */
376 && pclause->type != CLAUSE_CEASEFIRE) {
377 dai_diplo_notify(aplayer, _("*%s (AI)* First break alliance with %s, %s."),
378 player_name(pplayer), player_name(penemy),
380 worth = -BIG_NUMBER;
381 break;
382 }
383
384 /* They were allied with an enemy at the begining of the turn. */
385 if (adip->is_allied_with_enemy
386 && pclause->type != CLAUSE_CEASEFIRE) {
387 dai_diplo_notify(aplayer, _("*%s (AI)* I would like to see you keep your "
388 "distance from %s for some time, %s."),
389 player_name(pplayer), player_name(adip->is_allied_with_enemy),
391 worth = -BIG_NUMBER;
392 break;
393 }
394
395 /* Steps of the treaty ladder */
396 if (pclause->type == CLAUSE_PEACE) {
397 const struct player_diplstate *ds
398 = player_diplstate_get(pplayer, aplayer);
399
400 if (!pplayers_non_attack(pplayer, aplayer)) {
401 dai_diplo_notify(aplayer, _("*%s (AI)* Let us first cease hostilities, %s."),
402 player_name(pplayer),
404 worth = -BIG_NUMBER;
405 } else if (ds->type == DS_CEASEFIRE && ds->turns_left > 4) {
406 dai_diplo_notify(aplayer, _("*%s (AI)* I wish to see you keep the current "
407 "ceasefire for a bit longer first, %s."),
408 player_name(pplayer),
410 worth = -BIG_NUMBER;
411 } else if (adip->countdown >= 0 || adip->countdown < -1) {
412 worth = -BIG_NUMBER; /* but say nothing */
413 } else {
414 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
416 }
417 } else if (pclause->type == CLAUSE_ALLIANCE) {
418 if (!pplayers_in_peace(pplayer, aplayer)) {
419 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
421 }
422 if (adip->countdown >= 0 || adip->countdown < -1) {
423 worth = -BIG_NUMBER; /* but say nothing */
424 } else {
425 worth += greed(pplayer->ai_common.love[player_index(aplayer)]
427 }
428 if (pplayer->ai_common.love[player_index(aplayer)] < MAX_AI_LOVE / 10) {
429 dai_diplo_notify(aplayer, _("*%s (AI)* I simply do not trust you with an "
430 "alliance yet, %s."),
431 player_name(pplayer),
433 worth = -BIG_NUMBER;
434 }
435 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ally clause worth %d", worth);
436 } else {
437 if (is_ai(pplayer) && is_ai(aplayer)
439 worth = 0;
440 } else {
441 int turns = game.info.turn;
442
444 if (turns < TURNS_BEFORE_TARGET) {
445 worth = 0; /* show some good faith */
446 break;
447 } else {
448 worth = greed(pplayer->ai_common.love[player_index(aplayer)]);
449 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ceasefire worth=%d love=%d "
450 "turns=%d", worth,
452 turns);
453 }
454 }
455 }
456
457 /* Let's all hold hands in one happy family! */
458 if (adip->is_allied_with_ally) {
459 worth /= 2;
460 break;
461 }
462
463 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "treaty clause worth %d", worth);
464 break;
465
466 case CLAUSE_GOLD:
467 if (give) {
468 worth -= pclause->value;
469 } else {
470 worth += pclause->value * (100 - game.server.diplgoldcost) / 100;
471 }
472 break;
473
474 case CLAUSE_SEAMAP:
475 if (!give || ds_after == DS_ALLIANCE) {
476 /* Useless to us - we're omniscient! And allies get it for free! */
477 worth = 0;
478 } else {
479 /* Very silly algorithm 1: Sea map more worth if enemy has more
480 cities. Reasoning is they have more use of seamap for settling
481 new areas the more cities they have already. */
482 worth -= 15 * city_list_size(aplayer->cities);
483 /* Don't like them? Don't give it to them! */
484 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 7, worth);
485 /* Make maps from novice player cheap */
486 if (has_handicap(pplayer, H_DIPLOMACY)) {
487 worth /= 2;
488 }
489 }
490 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "seamap clause worth %d",
491 worth);
492 break;
493
494 case CLAUSE_MAP:
495 if (!give || ds_after == DS_ALLIANCE) {
496 /* Useless to us - we're omniscient! And allies get it for free! */
497 worth = 0;
498 } else {
499 /* Very silly algorithm 2: Land map more worth the more cities
500 we have, since we expose all of these to the enemy. */
501 worth -= 40 * MAX(city_list_size(pplayer->cities), 1);
502 /* Inflate numbers if not peace */
503 if (!pplayers_in_peace(pplayer, aplayer)) {
504 worth *= 2;
505 }
506 /* Don't like them? Don't give it to them! */
507 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 10, worth);
508 /* Make maps from novice player cheap */
509 if (has_handicap(pplayer, H_DIPLOMACY)) {
510 worth /= 6;
511 }
512 }
513 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "landmap clause worth %d",
514 worth);
515 break;
516
517 case CLAUSE_CITY: {
518 struct city *offer = city_list_find_number(pclause->from->cities,
519 pclause->value);
520
521 if (!offer || city_owner(offer) != giver) {
522 /* City destroyed or taken during negotiations */
523 dai_diplo_notify(aplayer, _("*%s (AI)* I do not know the city you mention."),
524 player_name(pplayer));
525 worth = 0;
526 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "city destroyed during negotiations");
527 } else if (give) {
528 /* AI must be crazy to trade away its cities */
529 worth -= city_gold_worth(offer);
530 if (is_capital(offer)) {
531 worth = -BIG_NUMBER; /* Never! Ever! */
532 } else {
533 worth *= 15;
534 }
535 if (aplayer == offer->original) {
536 /* Let them buy back their own city cheaper. */
537 worth /= 2;
538 }
539 } else {
540 worth = city_gold_worth(offer);
541 }
542 if (offer != NULL) {
543 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "worth of %s is %d",
544 city_name_get(offer), worth);
545 }
546 break;
547 }
548
549 case CLAUSE_VISION:
550 if (give) {
551 if (ds_after == DS_ALLIANCE) {
552 if (!shared_vision_is_safe(pplayer, aplayer)) {
554 _("*%s (AI)* Sorry, sharing vision with you "
555 "is not safe."),
556 player_name(pplayer));
557 worth = -BIG_NUMBER;
558 } else {
559 worth = 0;
560 }
561 } else {
562 /* so out of the question */
563 worth = -BIG_NUMBER;
564 }
565 } else {
566 worth = 0; /* We are omniscient, so... */
567 }
568 break;
569
570 case CLAUSE_EMBASSY:
571 if (give) {
572 if (ds_after == DS_ALLIANCE) {
573 worth = 0;
574 } else if (ds_after == DS_PEACE) {
575 worth = -5 * game.info.turn;
576 } else {
577 worth = MIN(-50 * game.info.turn
578 + pplayer->ai_common.love[player_index(aplayer)],
579 -5 * game.info.turn);
580 }
582 worth = game.info.tech_leak_pct / 10;
583 } else {
584 worth = 0; /* We don't need no stinkin' embassy, do we? */
585 }
586 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "embassy clause worth %d",
587 worth);
588 break;
590 if (give) {
591 if (ds_after == DS_ALLIANCE) {
592 worth = 0;
593 } else {
594 /* Here we assume that number of cities correlate with number of tiles. */
595 worth = -3 * (city_list_size(pplayer->cities) + 1);
596 }
597 } else {
598 int cities = city_list_size(aplayer->cities);
599
600 worth = MIN(cities, 3);
601 }
602 break;
603 case CLAUSE_COUNT:
605 break;
606 } /* end of switch */
607
608 if (close_here) {
609 dai_data_phase_finished(ait, pplayer);
610 }
611
613 return worth;
614}
615
616/******************************************************************/
620void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer,
621 struct player *aplayer, struct Treaty *ptreaty)
622{
623 int total_balance = 0;
624 bool only_gifts = TRUE;
627 int given_cities = 0;
628
630 if (is_pact_clause(pclause->type)) {
632 }
633 if (pclause->type == CLAUSE_CITY && pclause->from == pplayer) {
634 given_cities++;
635 }
637
638 /* Evaluate clauses */
640 const struct research *presearch = research_get(pplayer);
641
644
645 if (pclause->type != CLAUSE_GOLD && pclause->type != CLAUSE_MAP
646 && pclause->type != CLAUSE_SEAMAP && pclause->type != CLAUSE_VISION
647 && (pclause->type != CLAUSE_ADVANCE
649 || pclause->value == research_get(pplayer)->tech_goal
650 || pclause->value == research_get(pplayer)->researching
652 pclause->value))) {
653 /* We accept the above list of clauses as gifts, even if we are
654 * at war. We do not accept tech or cities since these can be used
655 * against us, unless we know that we want this tech anyway, or
656 * it doesn't matter due to tech cost style. */
658 }
660
661 /* If we are at war, and no peace is offered, then no deal, unless
662 * it is just gifts, in which case we gratefully accept. */
663 if (ds_after == DS_WAR && !only_gifts) {
664 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "no peace offered, must refuse");
665 return;
666 }
667
668 if (given_cities > 0
669 && city_list_size(pplayer->cities) - given_cities <= 2) {
670 /* always keep at least two cities */
671 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "cannot give last cities");
672 return;
673 }
674
675 /* Accept if balance is good */
676 if (total_balance >= 0) {
678 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was good: %d",
680 } else {
681 /* AI complains about the treaty which was proposed, unless the AI
682 * made the proposal. */
683 if (pplayer != ptreaty->plr0) {
684 dai_diplo_notify(aplayer, _("*%s (AI)* This deal was not very good for us, %s!"),
685 player_name(pplayer),
687 }
688 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was bad: %d",
690 }
691}
692
693/******************************************************************/
697static void dai_treaty_react(struct ai_type *ait,
698 struct player *pplayer,
699 struct player *aplayer,
700 struct Clause *pclause)
701{
702 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
703
704 switch (pclause->type) {
705 case CLAUSE_ALLIANCE:
706 if (adip->is_allied_with_ally) {
707 dai_diplo_notify(aplayer, _("*%s (AI)* Welcome into our alliance %s!"),
708 player_name(pplayer),
710 } else {
711 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, may we forever stand united, %s."),
712 player_name(pplayer),
714 }
715 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "become allies");
716 break;
717 case CLAUSE_PEACE:
718 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, peace in our time!"),
719 player_name(pplayer));
720 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign peace treaty");
721 break;
722 case CLAUSE_CEASEFIRE:
723 dai_diplo_notify(aplayer, _("*%s (AI)* Agreed. No more hostilities, %s."),
724 player_name(pplayer),
726 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign ceasefire");
727 break;
728 default:
729 break;
730 }
731}
732
733/******************************************************************/
740void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer,
741 struct player *aplayer, struct Treaty *ptreaty)
742{
743 bool close_here;
744 struct ai_plr *ai;
745 int total_balance = 0;
746 bool gift = TRUE;
749
750 ai = dai_plr_data_get(ait, pplayer, &close_here);
751
752 fc_assert_ret(pplayer != aplayer);
753
755 if (is_pact_clause(pclause->type)) {
757 }
759
760 /* Evaluate clauses */
762 int balance =
764
766 gift = (gift && (balance >= 0));
767 dai_treaty_react(ait, pplayer, aplayer, pclause);
768 if (is_pact_clause(pclause->type)
769 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown != -1) {
770 /* Cancel a countdown towards war if we just agreed to peace... */
771 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "countdown nullified");
772 dai_diplomacy_get(ait, pplayer, aplayer)->countdown = -1;
773 }
775
776 /* Rather arbitrary algorithm to increase our love for a player if
777 * they offer us gifts. It is only a gift if _all_ the clauses
778 * are beneficial to us. */
779 if (total_balance > 0 && gift) {
780 int i = total_balance / ((city_list_size(pplayer->cities) * 10) + 1);
781
782 i = MIN(i, ai->diplomacy.love_incr * 150) * 10;
783 pplayer->ai_common.love[player_index(aplayer)] += i;
784 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "gift increased love by %d", i);
785 }
786
787 if (close_here) {
788 dai_data_phase_finished(ait, pplayer);
789 }
790}
791
792/******************************************************************/
799static int dai_war_desire(struct ai_type *ait, struct player *pplayer,
800 struct player *target)
801{
802 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
803 struct adv_data *adv = adv_data_get(pplayer, NULL);
804 int want = 0, fear = 0, distance = 0, settlers = 0, cities = 0;
805 struct player_spaceship *ship = &target->spaceship;
806
807 city_list_iterate(target->cities, pcity) {
808 want += 100; /* base city want */
809 want += city_size_get(pcity) * 20;
810 want += pcity->surplus[O_SHIELD] * 8;
811 want += pcity->surplus[O_TRADE] * 6;
812
813 /* FIXME: This might be buggy if it ignores unmet UnitClass reqs. */
815
816 city_built_iterate(pcity, pimprove) {
817 int cost = impr_build_shield_cost(pcity, pimprove);
818
819 want += cost;
820 if (improvement_obsolete(pplayer, pimprove, pcity)) {
821 continue;
822 }
823 if (is_great_wonder(pimprove)) {
824 want += cost * 2;
825 } else if (is_small_wonder(pimprove)) {
826 want += cost;
827 }
830 unit_list_iterate(target->units, punit) {
831 const struct unit_type *ptype = unit_type_get(punit);
832
834
835 /* Fear enemy expansionism */
837 want += 100;
838 }
840 unit_list_iterate(pplayer->units, punit) {
841 const struct unit_type *ptype = unit_type_get(punit);
842
843 fear -= ATTACK_POWER(ptype) / 2;
844
845 /* Our own expansionism reduces want for war */
847 want -= 200;
848 settlers++;
849 }
851 city_list_iterate(pplayer->cities, pcity) {
852 if (VUT_UTYPE == pcity->production.kind
853 && utype_is_cityfounder(pcity->production.value.utype)) {
854 want -= 150;
855 settlers++;
856 }
857 cities++;
859
860 /* Modify by settler/cities ratio to prevent early wars when
861 * we should be expanding. This will eliminate want if we
862 * produce settlers in all cities (ie full expansion). */
863 want -= abs(want) / MAX(cities - settlers, 1);
864
865 /* Calculate average distances to other player's empire. */
866 distance = player_distance_to_player(pplayer, target);
867 dai_diplomacy_get(ait, pplayer, target)->distance = distance;
868
869 /* Worry a bit if the other player has extreme amounts of wealth
870 * that can be used in cities to quickly buy an army. */
871 fear += (target->economic.gold / 5000) * city_list_size(target->cities);
872
873 /* Tech lead is worrisome. FIXME: Only consider 'military' techs. */
874 fear += MAX(research_get(target)->techs_researched
875 - research_get(pplayer)->techs_researched, 0) * 100;
876
877 /* Spacerace loss we will not allow! */
878 if (ship->state >= SSHIP_STARTED) {
879 want *= 2;
880 }
881 if (adv->dipl.spacerace_leader == target) {
883 return BIG_NUMBER; /* do NOT amortize this number! */
884 }
885
886 /* Modify by which treaties we would break to other players, and what
887 * excuses we have to do so. FIXME: We only consider immediate
888 * allies, but we might trigger a wider chain reaction. */
890 bool cancel_excuse =
893
894 if (eplayer == pplayer) {
895 continue;
896 }
897
898 /* Remember: pplayers_allied() returns true when target == eplayer */
899 if (!cancel_excuse && pplayers_allied(target, eplayer)) {
900 if (ds == DS_ARMISTICE) {
901 want -= abs(want) / 10; /* 10% off */
902 } else if (ds == DS_CEASEFIRE) {
903 want -= abs(want) / 7; /* 15% off */
904 } else if (ds == DS_PEACE) {
905 want -= abs(want) / 5; /* 20% off */
906 } else if (ds == DS_ALLIANCE) {
907 want -= abs(want) / 3; /* 33% off */
908 }
909 }
911
912 /* Modify by love. Increase the divisor to make ai go to war earlier */
913 want -= MAX(0, want * pplayer->ai_common.love[player_index(target)]
914 / (2 * MAX_AI_LOVE));
915
916 /* Make novice AI more peaceful with human players */
917 if (has_handicap(pplayer, H_DIPLOMACY) && is_human(target)) {
918 want /= 2;
919 }
920
921 /* Amortize by distance */
922 want = amortize(want, distance);
923
924 if (pplayers_allied(pplayer, target)) {
925 want /= 4;
926 }
927
928 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "War want %d, war fear %d",
929 want, fear);
930 return (want - fear);
931}
932
933/******************************************************************/
938static void dai_diplomacy_suggest(struct player *pplayer,
939 struct player *aplayer,
940 enum clause_type what,
941 bool to_pplayer,
942 int value)
943{
944 if (!could_meet_with_player(pplayer, aplayer)) {
945 log_base(LOG_DIPL2, "%s tries to do diplomacy to %s without contact",
946 player_name(pplayer), player_name(aplayer));
947 return;
948 }
949
953 : pplayer),
954 what, value);
955}
956
957/******************************************************************/
960void dai_diplomacy_first_contact(struct ai_type *ait, struct player *pplayer,
961 struct player *aplayer)
962{
963 bool wants_ceasefire = FALSE;
964
965 /* Randomize initial love */
966 pplayer->ai_common.love[player_index(aplayer)] += 2 - fc_rand(5);
967
968 if (is_ai(pplayer)
969 && player_diplstate_get(pplayer, aplayer)->type == DS_WAR
970 && could_meet_with_player(pplayer, aplayer)) {
971 if (has_handicap(pplayer, H_CEASEFIRE)) {
972 fc_assert(!has_handicap(pplayer, H_AWAY));
974 } else if (!has_handicap(pplayer, H_AWAY)) {
975 struct Clause clause;
976
977 clause.from = pplayer;
978 clause.value = 0;
979 clause.type = CLAUSE_CEASEFIRE;
980
981 if (dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
982 FALSE, DS_CEASEFIRE) > 0) {
984 }
985 }
986 }
987
988 if (wants_ceasefire) {
990 _("*%s (AI)* Greetings %s! May we suggest a ceasefire "
991 "while we get to know each other better?"),
992 player_name(pplayer),
994 clear_old_treaty(pplayer, aplayer);
996 } else {
998 _("*%s (AI)* I found you %s! Now make it worth my "
999 "letting you live, or be crushed."),
1000 player_name(pplayer),
1002 }
1003}
1004
1005/******************************************************************/
1014void dai_diplomacy_begin_new_phase(struct ai_type *ait, struct player *pplayer)
1015{
1016 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1017 struct adv_data *adv = adv_data_get(pplayer, NULL);
1019 int best_desire = 0;
1020 struct player *best_target = NULL;
1021
1022 fc_assert_ret(is_ai(pplayer));
1023
1024 if (!pplayer->is_alive) {
1025 return; /* duh */
1026 }
1027
1028 memset(war_desire, 0, sizeof(war_desire));
1029
1030 /* Calculate our desires, and find desired war target */
1032 /* We don't hate ourselves, those we don't know or team members. */
1033 if (aplayer == pplayer
1034 || NEVER_MET(pplayer, aplayer)
1035 || players_on_same_team(pplayer, aplayer)) {
1036 continue;
1037 }
1042 }
1044
1045 /* Time to make love. If we've been wronged, hold off that love
1046 * for a while. Also, cool our head each turn with love_coeff. */
1048 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1049 int amount = 0;
1050 int pit;
1051
1052 if (pplayer == aplayer) {
1053 continue;
1054 }
1055
1056 if ((pplayers_non_attack(pplayer, aplayer)
1057 || pplayers_allied(pplayer, aplayer))
1058 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel == 0
1059 && adip->countdown == -1
1060 && !adip->is_allied_with_enemy
1061 && !adip->at_war_with_ally
1062 && aplayer != best_target
1063 && adip->ally_patience >= 0) {
1064 amount += ai->diplomacy.love_incr / 2;
1065 if (pplayers_allied(pplayer, aplayer)) {
1066 amount += ai->diplomacy.love_incr / 3;
1067 }
1068 /* Increase love by each enemy they are at war with */
1070 if (WAR(eplayer, aplayer) && WAR(pplayer, eplayer)) {
1071 amount += ai->diplomacy.love_incr / 4;
1072 }
1075 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Increased love by %d", amount);
1076 } else if (WAR(pplayer, aplayer)) {
1077 amount -= ai->diplomacy.love_incr / 2;
1079 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost to war", amount);
1080 } else if (player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel
1081 != 0) {
1082 /* Provoked in time of peace */
1083 if (pplayer->ai_common.love[player_index(aplayer)] > 0) {
1084 amount -= pplayer->ai_common.love[player_index(aplayer)] / 2;
1085 }
1086 amount -= ai->diplomacy.love_incr * 6;
1088 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Provoked! %d love lost!",
1089 amount);
1090 }
1091 if (pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE * 8 / 10
1092 && !pplayers_allied(pplayer, aplayer)) {
1093 int love_change = ai->diplomacy.love_incr / 3;
1094
1095 /* Upper levels of AI trust and love is reserved for allies. */
1097 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost from excess",
1098 love_change);
1099 }
1100 amount = 0;
1101
1102 /* Reduce love due to units in our territory.
1103 * AI is so naive, that we have to count it even if players are allied */
1104 pit = player_in_territory(pplayer, aplayer) * (MAX_AI_LOVE / 200);
1105 amount -= MIN(pit,
1107 * ((adip->is_allied_with_enemy != NULL) + 1));
1109 if (amount != 0) {
1110 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost due to units inside "
1111 "our borders", amount);
1112 }
1113
1114 /* Increase the love if aplayer has got a building that makes
1115 * us love them more. Typically it's Eiffel Tower */
1116 if (!NEVER_MET(pplayer, aplayer)) {
1117 pplayer->ai_common.love[player_index(aplayer)] +=
1119 }
1121
1122 /* Can we win by space race? */
1123 if (adv->dipl.spacerace_leader == pplayer) {
1124 log_base(LOG_DIPL2, "%s going for space race victory!",
1125 player_name(pplayer));
1126 ai->diplomacy.strategy = WIN_SPACE; /* Yes! */
1127 } else {
1128 if (ai->diplomacy.strategy == WIN_SPACE) {
1130 }
1131 }
1132
1134 int *love = &pplayer->ai_common.love[player_index(aplayer)];
1135
1136 if (aplayer == best_target && best_desire > 0) {
1137 int reduction = MIN(best_desire, MAX_AI_LOVE / 20);
1138
1139 *love -= reduction;
1140 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Wants war, reducing "
1141 "love by %d ", reduction);
1142 }
1143
1144 /* Edge love towards zero */
1145 *love -= *love * ((double)ai->diplomacy.love_coeff / 100.0);
1146
1147 /* ai love should always be in range [-MAX_AI_LOVE..MAX_AI_LOVE] */
1148 *love = MAX(-MAX_AI_LOVE, MIN(MAX_AI_LOVE, *love));
1150}
1151
1152/******************************************************************/
1155static void suggest_tech_exchange(struct ai_type *ait,
1156 struct player *player1,
1157 struct player *player2)
1158{
1162 int worth[ac];
1163 bool is_dangerous;
1164
1165 worth[A_NONE] = 0;
1166
1169 == TECH_KNOWN) {
1172 worth[tech] = -compute_tech_sell_price(ait, player1, player2, tech,
1173 &is_dangerous);
1174 if (is_dangerous) {
1175 /* Don't try to exchange */
1176 worth[tech] = 0;
1177 }
1178 } else {
1179 worth[tech] = 0;
1180 }
1181 } else {
1185 worth[tech] = compute_tech_sell_price(ait, player2, player1, tech,
1186 &is_dangerous);
1187 if (is_dangerous) {
1188 /* Don't try to exchange */
1189 worth[tech] = 0;
1190 }
1191 } else {
1192 worth[tech] = 0;
1193 }
1194 }
1196
1198 if (worth[tech] <= 0) {
1199 continue;
1200 }
1202 int diff;
1203
1204 if (worth[tech2] >= 0) {
1205 continue;
1206 }
1207 /* Tech2 is given by player1, tech is given by player2 */
1208 diff = worth[tech] + worth[tech2];
1209 if ((diff > 0 && player1->economic.gold >= diff)
1210 || (diff < 0 && player2->economic.gold >= -diff)
1211 || diff == 0) {
1214 if (diff > 0) {
1216 } else if (diff < 0) {
1218 }
1219 return;
1220 }
1223}
1224
1225/******************************************************************/
1228static void clear_old_treaty(struct player *pplayer, struct player *aplayer)
1229{
1230 struct Treaty *old_treaty = find_treaty(pplayer, aplayer);
1231
1232 if (old_treaty != NULL) {
1233 /* Remove existing clauses */
1236 player_number(pplayer),
1237 player_number(pclause->from),
1238 pclause->type, pclause->value);
1239 free(pclause);
1242 old_treaty->clauses = clause_list_new();
1243 }
1244}
1245
1246/******************************************************************/
1249static void dai_share(struct ai_type *ait, struct player *pplayer,
1250 struct player *aplayer)
1251{
1252 struct research *presearch = research_get(pplayer);
1254 bool gives_vision;
1255
1256 clear_old_treaty(pplayer, aplayer);
1257
1258 /* Only share techs with team mates */
1259 if (presearch != aresearch
1260 && players_on_same_team(pplayer, aplayer)) {
1272 }
1274 }
1275
1276 /* Only give shared vision if safe. Only ask for shared vision if fair. */
1278 if (!gives_vision
1279 && shared_vision_is_safe(pplayer, aplayer)) {
1282 }
1283 if (gives_vision
1284 && !gives_shared_vision(aplayer, pplayer)
1285 && (is_human(aplayer)
1286 || shared_vision_is_safe(aplayer, pplayer))) {
1288 }
1289
1290 if (!player_has_embassy(pplayer, aplayer)) {
1292 }
1293 if (!player_has_embassy(aplayer, pplayer)) {
1295 }
1296
1297 if (!has_handicap(pplayer, H_DIPLOMACY) || is_human(aplayer)) {
1298 suggest_tech_exchange(ait, pplayer, aplayer);
1299 }
1300}
1301
1302/******************************************************************/
1307static void dai_go_to_war(struct ai_type *ait, struct player *pplayer,
1308 struct player *target, enum war_reason reason)
1309{
1310 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1311
1312 fc_assert_ret(pplayer != target);
1313 fc_assert_ret(target->is_alive);
1314
1315 switch (reason) {
1316 case DAI_WR_SPACE:
1317 dai_diplo_notify(target, _("*%s (AI)* Space will never be yours."),
1318 player_name(pplayer));
1319 adip->countdown = -10;
1320 break;
1321 case DAI_WR_BEHAVIOUR:
1322 dai_diplo_notify(target,
1323 _("*%s (AI)* I have tolerated your vicious antics "
1324 "long enough! To war!"),
1325 player_name(pplayer));
1326 adip->countdown = -20;
1327 break;
1328 case DAI_WR_NONE:
1329 dai_diplo_notify(target, _("*%s (AI)* Peace in ... some other time."),
1330 player_name(pplayer));
1331 adip->countdown = -10;
1332 break;
1333 case DAI_WR_HATRED:
1334 dai_diplo_notify(target,
1335 _("*%s (AI)* Finally I get around to you! Did "
1336 "you really think you could get away with your crimes?"),
1337 player_name(pplayer));
1338 adip->countdown = -20;
1339 break;
1340 case DAI_WR_EXCUSE:
1341 dai_diplo_notify(target,
1342 _("*%s (AI)* Your covert hostilities brought "
1343 "this war upon you!"),
1344 player_name(pplayer));
1345 adip->countdown = -20;
1346 break;
1347 case DAI_WR_ALLIANCE:
1348 if (adip->at_war_with_ally) {
1349 dai_diplo_notify(target,
1350 _("*%s (AI)* Your aggression against %s was "
1351 "your last mistake!"),
1352 player_name(pplayer),
1353 player_name(adip->at_war_with_ally));
1354 adip->countdown = -3;
1355 } else {
1356 /* Ooops! */
1357 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "Wanted to declare war "
1358 "for their war against an ally, but can no longer find "
1359 "this ally! War declaration aborted.");
1360 adip->countdown = -1;
1361 return;
1362 }
1363 break;
1364 }
1365
1366 fc_assert_ret(adip->countdown < 0);
1367
1368 if (gives_shared_vision(pplayer, target)) {
1369 remove_shared_vision(pplayer, target);
1370 }
1371
1372 /* Check for Senate obstruction. If so, dissolve it. */
1373 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_SENATE_BLOCKING) {
1374 struct government *real_gov = pplayer->government;
1375
1377
1378 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_OK) {
1379 /* It seems that revolution would help. */
1380 pplayer->government = real_gov;
1383 } else {
1384 /* There would be Senate even during revolution. Better not to revolt for nothing */
1385 pplayer->government = real_gov;
1386 adip->countdown = -1; /* War declaration aborted */
1387
1388 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target,
1389 "Not revolting, as there would be Senate regardless.");
1390
1391 return;
1392 }
1393 }
1394
1395 /* This will take us straight to war. */
1396 while (player_diplstate_get(pplayer, target)->type != DS_WAR) {
1397 if (pplayer_can_cancel_treaty(pplayer, target) != DIPL_OK) {
1398 DIPLO_LOG(ait, LOG_ERROR, pplayer, target,
1399 "Wanted to cancel treaty but was unable to.");
1400 adip->countdown = -1; /* War declaration aborted */
1401
1402 return;
1403 }
1405 }
1406
1407 /* Throw a tantrum */
1408 if (pplayer->ai_common.love[player_index(target)] > 0) {
1409 pplayer->ai_common.love[player_index(target)] = -1;
1410 }
1411 pplayer->ai_common.love[player_index(target)] -= MAX_AI_LOVE / 8;
1412
1413 fc_assert(!gives_shared_vision(pplayer, target));
1414 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "war declared");
1415}
1416
1417/******************************************************************/
1429static void war_countdown(struct ai_type *ait, struct player *pplayer,
1430 struct player *target,
1431 int countdown, enum war_reason reason)
1432{
1433 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1434
1435 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "countdown to war in %d", countdown);
1436
1437 /* Otherwise we're resetting an existing countdown, which is very bad */
1438 fc_assert_ret(adip->countdown == -1);
1439
1440 adip->countdown = countdown;
1441 adip->war_reason = reason;
1442
1444 if (!pplayers_allied(pplayer, ally)
1445 || ally == target
1446 || NEVER_MET(pplayer, ally)) {
1447 continue;
1448 }
1449
1450 switch (reason) {
1451 case DAI_WR_SPACE:
1453 PL_("*%s (AI)* We will be launching an all-out war "
1454 "against %s in %d turn to stop the spaceship "
1455 "launch.",
1456 "*%s (AI)* We will be launching an all-out war "
1457 "against %s in %d turns to stop the spaceship "
1458 "launch.",
1459 countdown),
1460 player_name(pplayer),
1461 player_name(target),
1462 countdown);
1464 _("*%s (AI)* Your aid in this matter will be expected. "
1465 "Long live our glorious alliance!"),
1466 player_name(pplayer));
1467 break;
1468 case DAI_WR_BEHAVIOUR:
1469 case DAI_WR_EXCUSE:
1471 PL_("*%s (AI)* %s has grossly violated their treaties "
1472 "with us for own gain. We will answer in force in "
1473 "%d turn and expect you to honor your alliance "
1474 "with us and do likewise!",
1475 "*%s (AI)* %s has grossly violated their treaties "
1476 "with us for own gain. We will answer in force in "
1477 "%d turns and expect you to honor your alliance "
1478 "with us and do likewise!", countdown),
1479 player_name(pplayer),
1480 player_name(target),
1481 countdown);
1482 break;
1483 case DAI_WR_NONE:
1485 PL_("*%s (AI)* We intend to pillage and plunder the rich "
1486 "civilization of %s. We declare war in %d turn.",
1487 "*%s (AI)* We intend to pillage and plunder the rich "
1488 "civilization of %s. We declare war in %d turns.",
1489 countdown),
1490 player_name(pplayer),
1491 player_name(target),
1492 countdown);
1494 _("*%s (AI)* If you want a piece of the loot, feel "
1495 "free to join in the action!"),
1496 player_name(pplayer));
1497 break;
1498 case DAI_WR_HATRED:
1500 PL_("*%s (AI)* We have had it with %s. Let us tear this "
1501 "pathetic civilization apart. We declare war in "
1502 "%d turn.",
1503 "*%s (AI)* We have had it with %s. Let us tear this "
1504 "pathetic civilization apart. We declare war in "
1505 "%d turns.",
1506 countdown),
1507 player_name(pplayer),
1508 player_name(target),
1509 countdown);
1511 _("*%s (AI)* As our glorious allies, we expect your "
1512 "help in this war."),
1513 player_name(pplayer));
1514 break;
1515 case DAI_WR_ALLIANCE:
1516 if (WAR(ally, target)) {
1518 PL_("*%s (AI)* We will honor our alliance and declare "
1519 "war on %s in %d turn. Hold on - we are coming!",
1520 "*%s (AI)* We will honor our alliance and declare "
1521 "war on %s in %d turns. Hold on - we are coming!",
1522 countdown),
1523 player_name(pplayer),
1524 player_name(target),
1525 countdown);
1526 } else if (adip->at_war_with_ally) {
1528 PL_("*%s (AI)* We will honor our alliance with %s and "
1529 "declare war on %s in %d turns. We expect you to "
1530 "do likewise.",
1531 "*%s (AI)* We will honor our alliance with %s and "
1532 "declare war on %s in %d turns. We expect you to "
1533 "do likewise.",
1534 countdown),
1535 player_name(pplayer),
1536 player_name(adip->at_war_with_ally),
1537 player_name(target),
1538 countdown);
1539 } else {
1540 fc_assert(FALSE); /* Huh? */
1541 }
1542 break;
1543 }
1545}
1546
1547/******************************************************************/
1553void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
1554{
1555 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1556 bool need_targets = TRUE;
1557 struct player *target = NULL;
1559 int war_threshold;
1560 int aggr;
1561 float aggr_sr;
1562 float max_sr;
1563
1564 fc_assert_ret(is_ai(pplayer));
1565
1566 if (!pplayer->is_alive) {
1567 return;
1568 }
1569
1570 if (get_player_bonus(pplayer, EFT_NO_DIPLOMACY) > 0) {
1571 /* Diplomacy disabled for this player */
1572 return;
1573 }
1574
1575 /*** If we are greviously insulted, go to war immediately. ***/
1576
1578 if (pplayer->ai_common.love[player_index(aplayer)] < 0
1579 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel >= 2
1580 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown == -1) {
1581 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Plans war in revenge");
1582 war_countdown(ait, pplayer, aplayer, map_size_checked(),
1584 }
1586
1587 /*** Stop other players from winning by space race ***/
1588
1589 if (ai->diplomacy.strategy != WIN_SPACE) {
1590 struct adv_data *adv = adv_data_get(pplayer, NULL);
1591
1593 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1594 struct player_spaceship *ship = &aplayer->spaceship;
1595
1596 if (aplayer == pplayer
1597 || adip->countdown >= 0 /* already counting down to war */
1598 || ship->state == SSHIP_NONE
1599 || players_on_same_team(pplayer, aplayer)
1600 || pplayers_at_war(pplayer, aplayer)) {
1601 continue;
1602 }
1603
1604 /* A spaceship victory is always one single player's or team's victory */
1605 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1606 && adv->dipl.spacerace_leader == aplayer
1607 && pplayers_allied(pplayer, aplayer)) {
1609 _("*%s (AI)* Your attempt to conquer space for "
1610 "yourself alone betrays your true intentions, and I "
1611 "will have no more of our alliance!"),
1612 player_name(pplayer));
1615 if (gives_shared_vision(pplayer, aplayer)) {
1616 remove_shared_vision(pplayer, aplayer);
1617 }
1618 /* Never forgive this */
1620 } else if (ship->state == SSHIP_STARTED
1621 && adip->warned_about_space == 0) {
1622 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 10;
1623 adip->warned_about_space = 10 + fc_rand(6);
1625 _("*%s (AI)* Your attempt to unilaterally "
1626 "dominate outer space is highly offensive."),
1627 player_name(pplayer));
1629 _("*%s (AI)* If you do not stop constructing your "
1630 "spaceship, I may be forced to take action!"),
1631 player_name(pplayer));
1632 }
1633 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1634 && aplayer == adv->dipl.spacerace_leader) {
1635 /* This means war!!! */
1636 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 2;
1637 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "plans war due to spaceship");
1638 war_countdown(ait, pplayer, aplayer, 4 + map_size_checked(),
1639 DAI_WR_SPACE);
1640 }
1642 }
1643
1644 /*** Declare war against somebody if we are out of targets ***/
1645
1647 int turns; /* turns since contact */
1648
1649 if (NEVER_MET(pplayer, aplayer)) {
1650 continue;
1651 }
1652 turns = game.info.turn;
1654 if (WAR(pplayer, aplayer)) {
1656 } else if (pplayer->ai_common.love[player_index(aplayer)] < most_hatred
1657 && turns > TURNS_BEFORE_TARGET) {
1659 target = aplayer;
1660 }
1662
1665 aggr_sr = sqrt(aggr);
1666
1667 war_threshold = (MAX_AI_LOVE * (0.70 + aggr_sr / max_sr / 2.0)) - MAX_AI_LOVE;
1668
1669 if (need_targets && target && most_hatred < war_threshold
1670 && dai_diplomacy_get(ait, pplayer, target)->countdown == -1) {
1671 enum war_reason war_reason;
1672
1673 if (pplayers_allied(pplayer, target)) {
1674 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "Plans war against an ally!");
1675 }
1676 if (player_diplstate_get(pplayer, target)->has_reason_to_cancel > 0) {
1677 /* We have good reason */
1678 war_reason = DAI_WR_EXCUSE;
1679 } else if (pplayer->ai_common.love[player_index(target)] < 0) {
1680 /* We have a reason of sorts from way back, maybe? */
1681 war_reason = DAI_WR_HATRED;
1682 } else {
1683 /* We have no legimitate reason... So what? */
1684 war_reason = DAI_WR_NONE;
1685 }
1686 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "plans war for spoils");
1687 war_countdown(ait, pplayer, target, 4 + map_size_checked(), war_reason);
1688 }
1689
1690 /*** Declare war - against enemies of allies ***/
1691
1693 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1694
1695 if (adip->at_war_with_ally
1696 && adip->countdown == -1
1697 && !adip->is_allied_with_ally
1698 && !pplayers_at_war(pplayer, aplayer)
1700 || fc_rand(5) < 1)) {
1701 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "plans war to help ally %s",
1702 player_name(adip->at_war_with_ally));
1703 war_countdown(ait, pplayer, aplayer, 2 + map_size_checked(),
1705 }
1707
1708 /*** Actually declare war (when we have moved units into position) ***/
1709
1711 if (!players_on_same_team(pplayer, aplayer)) {
1712 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1713
1714 if (!aplayer->is_alive) {
1715 adip->countdown = -1;
1716 continue;
1717 }
1718 if (adip->countdown > 0) {
1719 adip->countdown--;
1720 } else if (adip->countdown == 0) {
1721 if (!WAR(pplayer, aplayer)) {
1722 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Declaring war!");
1723 dai_go_to_war(ait, pplayer, aplayer, adip->war_reason);
1724 }
1725 } else if (adip->countdown < -1) {
1726 /* Negative countdown less than -1 is war stubbornness */
1727 adip->countdown++;
1728 }
1729 }
1731
1732 /*** Try to make peace with everyone we love ***/
1733
1736 && diplomacy_possible(pplayer, aplayer)) {
1738 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1739 struct Clause clause;
1740
1741 /* Meaningless values, but rather not have them unset. */
1742 clause.from = pplayer;
1743 clause.value = 0;
1744
1745 /* Remove shared vision if we are not allied or it is no longer safe. */
1746 if (gives_shared_vision(pplayer, aplayer)) {
1747 if (!pplayers_allied(pplayer, aplayer)) {
1748 remove_shared_vision(pplayer, aplayer);
1749 } else if (!players_on_same_team(pplayer, aplayer)
1750 && !shared_vision_is_safe(pplayer, aplayer)) {
1752 _("*%s (AI)* Sorry, sharing vision with you "
1753 "is no longer safe."),
1754 player_name(pplayer));
1755 remove_shared_vision(pplayer, aplayer);
1756 }
1757 }
1758
1759 /* No peace to enemies of our allies... or pointless peace. */
1761 || aplayer == pplayer
1762 || aplayer == target /* no mercy */
1763 || adip->countdown >= 0
1764 || !could_meet_with_player(pplayer, aplayer)) {
1765 continue;
1766 }
1767
1768 /* Spam control */
1769 adip->asked_about_peace = MAX(adip->asked_about_peace - 1, 0);
1770 adip->asked_about_alliance = MAX(adip->asked_about_alliance - 1, 0);
1771 adip->asked_about_ceasefire = MAX(adip->asked_about_ceasefire - 1, 0);
1772 adip->warned_about_space = MAX(adip->warned_about_space - 1, 0);
1773 adip->spam = MAX(adip->spam - 1, 0);
1774 if (adip->spam > 0 && is_ai(aplayer)) {
1775 /* Don't spam */
1776 continue;
1777 }
1778
1779 /* Canvass support from existing friends for our war, and try to
1780 * make friends with enemies. Then we wait some turns until next time
1781 * we spam them with our gibbering chatter. */
1782 if (adip->spam <= 0) {
1783 if (!pplayers_allied(pplayer, aplayer)) {
1784 adip->spam = fc_rand(4) + 3; /* Bugger allies often. */
1785 } else {
1786 adip->spam = fc_rand(8) + 6; /* Others are less important. */
1787 }
1788 }
1789
1790 switch (ds) {
1791 case DS_TEAM:
1792 dai_share(ait, pplayer, aplayer);
1793 break;
1794 case DS_ALLIANCE:
1795 /* See if our allies are diligently declaring war on our enemies... */
1796 if (adip->at_war_with_ally) {
1797 break;
1798 }
1799 target = NULL;
1801 if (WAR(pplayer, eplayer)
1803 target = eplayer;
1804 break;
1805 }
1807
1808 if ((players_on_same_team(pplayer, aplayer)
1809 || pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE / 2)) {
1810 /* Share techs only with team mates and allies we really like. */
1811 dai_share(ait, pplayer, aplayer);
1812 }
1813 if (!target || !target->is_alive) {
1814 adip->ally_patience = 0;
1815 break; /* No need to nag our ally */
1816 }
1817
1818 if (adip->spam <= 0) {
1819 /* Count down patience toward AI player (one that can have spam > 0)
1820 * at the same speed as toward human players. */
1821 if (adip->ally_patience == 0) {
1823 _("*%s (AI)* Greetings our most trustworthy "
1824 "ally. We call upon you to destroy our enemy, %s."),
1825 player_name(pplayer),
1826 player_name(target));
1827 adip->ally_patience--;
1828 } else if (adip->ally_patience == -1) {
1829 if (fc_rand(5) == 1) {
1831 _("*%s (AI)* Greetings ally, I see you have not yet "
1832 "made war with our enemy, %s. Why do I need to remind "
1833 "you of your promises?"),
1834 player_name(pplayer),
1835 player_name(target));
1836 adip->ally_patience--;
1837 }
1838 } else if (fc_rand(5) == 1
1839 && !players_on_same_team(pplayer, aplayer)) {
1841 _("*%s (AI)* Dishonored one, we made a pact of "
1842 "alliance, and yet you remain at peace with our mortal "
1843 "enemy, %s! This is unacceptable; our alliance is no "
1844 "more!"),
1845 player_name(pplayer),
1846 player_name(target));
1847 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer,
1848 "breaking useless alliance");
1849 /* To peace */
1853 = MIN(pplayer->ai_common.love[player_index(aplayer)], 0);
1854 if (gives_shared_vision(pplayer, aplayer)) {
1855 remove_shared_vision(pplayer, aplayer);
1856 }
1857
1859 }
1860 }
1861 break;
1862
1863 case DS_PEACE:
1864 clause.type = CLAUSE_ALLIANCE;
1865 if (adip->at_war_with_ally
1866 || (is_human(aplayer) && adip->asked_about_alliance > 0)
1867 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1868 FALSE, DS_ALLIANCE) < 0) {
1869 break;
1870 }
1871 clear_old_treaty(pplayer, aplayer);
1873 adip->asked_about_alliance = is_human(aplayer) ? 13 : 0;
1875 _("*%s (AI)* Greetings friend, may we suggest "
1876 "making a common cause and join in an alliance?"),
1877 player_name(pplayer));
1878 break;
1879
1880 case DS_CEASEFIRE:
1881 clause.type = CLAUSE_PEACE;
1882 if (adip->at_war_with_ally
1883 || (is_human(aplayer) && adip->asked_about_peace > 0)
1884 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1885 FALSE, DS_PEACE) < 0) {
1886 break;
1887 }
1888 clear_old_treaty(pplayer, aplayer);
1890 adip->asked_about_peace = is_human(aplayer) ? 12 : 0;
1892 _("*%s (AI)* Greetings neighbor, may we suggest "
1893 "more peaceful relations?"),
1894 player_name(pplayer));
1895 break;
1896
1897 case DS_NO_CONTACT: /* but we do have embassy! weird. */
1898 case DS_WAR:
1899 clause.type = CLAUSE_CEASEFIRE;
1900 if ((is_human(aplayer) && adip->asked_about_ceasefire > 0)
1901 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1902 FALSE, DS_CEASEFIRE) < 0) {
1903 break; /* Fight until the end! */
1904 }
1905 clear_old_treaty(pplayer, aplayer);
1907 adip->asked_about_ceasefire = is_human(aplayer) ? 9 : 0;
1909 _("*%s (AI)* We grow weary of this constant "
1910 "bloodshed. May we suggest a cessation of hostilities?"),
1911 player_name(pplayer));
1912 break;
1913
1914 case DS_ARMISTICE:
1915 break;
1916 default:
1917 fc_assert_msg(FALSE, "Unknown pact type %d.", ds);
1918 break;
1919 }
1920 }
1922}
1923
1924/******************************************************************/
1928bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
1929{
1930 players_iterate(plr) {
1931 if (dai_diplomacy_get(ait, pplayer, plr)->countdown >= 0) {
1932 return TRUE;
1933 }
1935
1936 return FALSE;
1937}
1938
1939/******************************************************************/
1942/* AI attitude call-backs */
1945 const struct action *paction,
1946 struct player *receiver,
1947 struct player *violator, struct player *victim)
1948{
1949 if (!is_ai(receiver) || violator == receiver) {
1950 return;
1951 }
1952
1953 /* Can only handle victim only and international incidents. */
1956
1957 switch (type) {
1958 case INCIDENT_ACTION:
1959 /* Feel free the change how the action results are grouped and how bad
1960 * the ai considers each group. */
1961 switch (paction->result) {
1962 case ACTRES_SPY_NUKE:
1963 case ACTRES_NUKE:
1964 case ACTRES_NUKE_UNITS:
1965 if (receiver == victim) {
1966 /* Tell the victim */
1968 } else if (violator == victim) {
1970 } else {
1972 }
1973 break;
1976 /* Snoping */
1977 dai_incident_simple(receiver, violator, victim, scope, 2);
1978 break;
1982 case ACTRES_STEAL_MAPS:
1983 /* Theft */
1984 dai_incident_simple(receiver, violator, victim, scope, 5);
1985 break;
1986 case ACTRES_EXPEL_UNIT:
1987 /* Unit position loss */
1988 dai_incident_simple(receiver, violator, victim, scope, 1);
1989 break;
1991 /* Unit weakening */
1992 dai_incident_simple(receiver, violator, victim, scope, 3);
1993 break;
1996 case ACTRES_BOMBARD:
1997 case ACTRES_ATTACK:
1998 case ACTRES_WIPE_UNITS:
1999 case ACTRES_SPY_ATTACK:
2001 /* Unit loss */
2002 dai_incident_simple(receiver, violator, victim, scope, 5);
2003 break;
2007 /* City loss */
2008 dai_incident_simple(receiver, violator, victim, scope, 10);
2009 break;
2015 /* Building loss */
2016 dai_incident_simple(receiver, violator, victim, scope, 5);
2017 break;
2018 case ACTRES_SPY_POISON:
2020 /* Population loss */
2021 dai_incident_simple(receiver, violator, victim, scope, 5);
2022 break;
2023 case ACTRES_FOUND_CITY:
2024 /* Terrain loss */
2025 dai_incident_simple(receiver, violator, victim, scope, 4);
2026 break;
2028 case ACTRES_PILLAGE:
2029 /* Extra loss */
2030 dai_incident_simple(receiver, violator, victim, scope, 2);
2031 break;
2032 case ACTRES_UNIT_MOVE:
2033 case ACTRES_TELEPORT:
2035 case ACTRES_SPY_ESCAPE:
2036 case ACTRES_TRADE_ROUTE:
2037 case ACTRES_MARKETPLACE:
2038 case ACTRES_HELP_WONDER:
2039 case ACTRES_JOIN_CITY:
2042 case ACTRES_HOME_CITY:
2043 case ACTRES_HOMELESS:
2045 case ACTRES_PARADROP:
2046 case ACTRES_PARADROP_CONQUER: /* TODO: Bigger incident */
2047 case ACTRES_AIRLIFT:
2048 case ACTRES_HEAL_UNIT:
2050 case ACTRES_CULTIVATE:
2051 case ACTRES_PLANT:
2052 case ACTRES_CLEAN:
2053 case ACTRES_FORTIFY:
2054 case ACTRES_ROAD:
2055 case ACTRES_CONVERT:
2056 case ACTRES_BASE:
2057 case ACTRES_MINE:
2058 case ACTRES_IRRIGATE:
2065 case ACTRES_HUT_ENTER:
2068 case ACTRES_NONE:
2069 /* Various */
2070 dai_incident_simple(receiver, violator, victim, scope, 1);
2071 break;
2072
2074 }
2075 break;
2076 case INCIDENT_WAR:
2077 if (receiver == victim) {
2079 }
2080 break;
2081 case INCIDENT_LAST:
2082 /* Assert that always fails, but with meaningful message */
2084 break;
2085 }
2086}
2087
2088/******************************************************************/
2091static void dai_incident_nuclear(struct player *receiver,
2092 const struct player *violator,
2093 const struct player *victim)
2094{
2095 fc_assert_ret(receiver == victim);
2096
2097 if (violator == victim) {
2098 return;
2099 }
2100
2101 receiver->ai_common.love[player_index(violator)] -= 3 * MAX_AI_LOVE / 10;
2102}
2103
2104/******************************************************************/
2107static void dai_incident_nuclear_not_target(struct player *receiver,
2108 const struct player *violator,
2109 const struct player *victim)
2110{
2111 fc_assert_ret(receiver != victim);
2112
2113 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2114}
2115
2116/******************************************************************/
2119static void dai_incident_nuclear_self(struct player *receiver,
2120 const struct player *violator,
2121 const struct player *victim)
2122{
2123 fc_assert_ret(receiver != victim);
2125
2126 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 20;
2127}
2128
2129/**********************************************************************/
2141static void dai_incident_simple(struct player *receiver,
2142 const struct player *violator,
2143 const struct player *victim,
2145 int how_bad)
2146{
2148 if (victim == receiver) {
2150 /* The ruleset finds this bad enough to cause International Outrage.
2151 * Trust the ruleset author. Double the displeasure. */
2153 }
2154 receiver->ai_common.love[player_index(violator)] -= displeasure / 35;
2155 } else if (violator == victim) {
2156 receiver->ai_common.love[player_index(violator)] -= displeasure / 1000;
2157 } else {
2158 receiver->ai_common.love[player_index(violator)] -= displeasure / 500;
2159 }
2160}
2161
2162/******************************************************************/
2170static void dai_incident_war(struct player *violator, struct player *victim)
2171{
2172 players_iterate(pplayer) {
2173 if (!is_ai(pplayer)) {
2174 continue;
2175 }
2176
2177 if (pplayer != violator) {
2178 /* Dislike backstabbing bastards */
2179 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2180 if (player_diplstate_get(violator, victim)->max_state == DS_PEACE) {
2181 /* Extra penalty if they once had a peace treaty */
2182 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2183 } else if (player_diplstate_get(violator, victim)->max_state
2184 == DS_ALLIANCE) {
2185 /* Extra penalty if they once had an alliance */
2186 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2187 }
2188 if (victim == pplayer) {
2189 pplayer->ai_common.love[player_index(violator)] =
2190 MIN(pplayer->ai_common.love[player_index(violator)] - MAX_AI_LOVE / 3, -1);
2191 /* Scream for help!! */
2193 if (!pplayers_allied(pplayer, ally)) {
2194 continue;
2195 }
2197 _("*%s (AI)* We have been savagely attacked by "
2198 "%s, and we need your help! Honor our glorious "
2199 "alliance and your name will never be forgotten!"),
2203 }
2204 }
2206}
#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:1571
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1671
#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:822
#define city_built_iterate_end
Definition city.h:828
char * incite_cost
Definition comments.c:74
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition daidata.c:308
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Definition daidata.c:402
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:285
@ WIN_SPACE
Definition daidata.h:34
@ WIN_CAPITAL
Definition daidata.h:35
@ WIN_OPEN
Definition daidata.h:32
void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
static void dai_incident_nuclear_not_target(struct player *receiver, const struct player *violator, const struct player *victim)
void dai_incident(struct ai_type *ait, enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *receiver, struct player *violator, struct player *victim)
bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
void dai_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 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:380
#define ACTRES_NONE
Definition fc_types.h:330
@ 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:878
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:1690
void vpackage_event(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format, va_list vargs)
Definition notify.c:147
void event_cache_add_for_player(const struct packet_chat_msg *packet, const struct player *pplayer)
Definition notify.c:646
void lsend_packet_chat_msg(struct conn_list *dest, const struct packet_chat_msg *packet)
void dlsend_packet_diplomacy_remove_clause(struct conn_list *dest, int counterpart, int giver, enum clause_type type, int value)
struct city_list * cities
Definition packhand.c:119
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c: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
int distance
Definition daidata.h:60
int countdown
Definition daidata.h:61
struct ai_plr::@252 diplomacy
adv_want tech_want[A_LAST+1]
Definition daidata.h:103
int req_love_for_alliance
Definition daidata.h:96
char love_incr
Definition daidata.h:94
char love_coeff
Definition daidata.h:93
int req_love_for_peace
Definition daidata.h:95
enum winning_strategy strategy
Definition daidata.h:91
Definition ai.h:50
Definition city.h:320
int diplgoldcost
Definition game.h:140
struct packet_game_info info
Definition game.h:89
struct civ_game::@31::@35 server
struct government * government_during_revolution
Definition game.h:94
Government_type_id government_during_revolution_id
enum tech_upkeep_style tech_upkeep_style
enum tech_leakage_style tech_leakage
bool tech_trade_allow_holes
enum tech_cost_style tech_cost_style
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h: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
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:2637
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_is_cityfounder(const struct unit_type *utype)
Definition unittype.c:2951