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