Freeciv-3.4
Loading...
Searching...
No Matches
daidiplomacy.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdarg.h>
19#include <string.h>
20
21/* utility */
22#include "fcintl.h"
23#include "log.h"
24#include "mem.h"
25#include "rand.h"
26#include "shared.h"
27#include "support.h"
28
29/* common */
30#include "aisupport.h"
31#include "city.h"
32#include "diptreaty.h"
33#include "events.h"
34#include "game.h"
35#include "packets.h"
36#include "player.h"
37#include "nation.h"
38#include "research.h"
39#include "spaceship.h"
40#include "tech.h"
41#include "unitlist.h"
42
43/* server */
44#include "citytools.h"
45#include "diplhand.h"
46#include "maphand.h"
47#include "notify.h"
48#include "srv_log.h"
49
50/* server/advisors */
51#include "advdata.h"
52#include "advtools.h"
53
54/* ai */
55#include "aitraits.h"
56#include "handicaps.h"
57
58/* ai/default */
59#include "daicity.h"
60#include "daidata.h"
61#include "dailog.h"
62#include "daimilitary.h"
63#include "daiplayer.h"
64#include "daiunit.h"
65
66#include "daidiplomacy.h"
67
68#define LOG_DIPL LOG_DEBUG
69#define LOG_DIPL2 LOG_DEBUG
70
71/* One hundred thousand. Basically a number of gold that no player is
72 * ever likely to have, but not so big that we get integer overflows. */
73#define BIG_NUMBER 100000
74
75/* turn this off when we don't want functions to message players */
76static bool diplomacy_verbose = TRUE;
77
78/* turns to wait after contact before taking aim for war */
79#define TURNS_BEFORE_TARGET 15
80
81static void dai_incident_war(struct player *violator, struct player *victim);
82static void dai_incident_simple(struct player *receiver,
83 const struct player *violator,
84 const struct player *victim,
86 int how_bad);
87static void dai_incident_nuclear(struct player *receiver,
88 const struct player *violator,
89 const struct player *victim);
90static void dai_incident_nuclear_not_target(struct player *receiver,
91 const struct player *violator,
92 const struct player *victim);
93static void dai_incident_nuclear_self(struct player *receiver,
94 const struct player *violator,
95 const struct player *victim);
96static void clear_old_treaty(struct player *pplayer, struct player *aplayer);
97
98/******************************************************************/
103static void dai_diplo_notify(struct player *pplayer, const char *text, ...)
104{
105 if (diplomacy_verbose) {
106 va_list ap;
107 struct conn_list *dest = pplayer->connections;
108 struct packet_chat_msg packet;
109
110 va_start(ap, text);
112 text, ap);
113 va_end(ap);
114
115 lsend_packet_chat_msg(dest, &packet);
116 /* Add to the event cache. */
117 event_cache_add_for_player(&packet, pplayer);
118 }
119}
120
121/******************************************************************/
125static int greed(int missing_love)
126{
127 if (missing_love > 0) {
128 return 0;
129 } else {
130 /* Don't change the operation order here.
131 * We do not want integer overflows */
132 return -((missing_love * MAX_AI_LOVE) / 1000) *
133 ((missing_love * MAX_AI_LOVE) / 1000) / 10;
134 }
135}
136
137/******************************************************************/
141{
142 switch (type) {
143 case CLAUSE_ALLIANCE:
144 return DS_ALLIANCE;
145 case CLAUSE_PEACE:
146 return DS_PEACE;
147 case CLAUSE_CEASEFIRE:
148 return DS_CEASEFIRE;
149 default:
150 log_error("Invalid diplomatic clause %d.", type)
151 return DS_WAR;
152 }
153}
154
155/******************************************************************/
158static int dai_goldequiv_tech(struct ai_type *ait,
159 struct player *pplayer, Tech_type_id tech)
160{
161 int bulbs, tech_want, worth;
162 struct research *presearch = research_get(pplayer);
164 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
165
166 if (TECH_KNOWN == state
169 return 0;
170 }
172 tech_want = MAX(plr_data->tech_want[tech], 0) / MAX(game.info.turn, 1);
173 worth = bulbs + tech_want;
174 if (TECH_PREREQS_KNOWN == state) {
175 worth /= 2;
176 }
177
178 return worth;
179}
180
181/******************************************************************/
185static bool shared_vision_is_safe(struct player* pplayer,
186 struct player* aplayer)
187{
188 if (pplayer->team && pplayer->team == aplayer->team) {
189 return TRUE;
190 }
192 if (eplayer == pplayer || eplayer == aplayer) {
193 continue;
194 }
197
198 if (ds != DS_NO_CONTACT && ds != DS_ALLIANCE) {
199 return FALSE;
200 }
201 }
203
204 return TRUE;
205}
206
207/******************************************************************/
214static int compute_tech_sell_price(struct ai_type *ait,
215 struct player *giver, struct player *taker,
216 int tech_id, bool *is_dangerous)
217{
218 int worth;
219
220 worth = dai_goldequiv_tech(ait, taker, tech_id);
221
222 *is_dangerous = FALSE;
223
224 /* Share and expect being shared brotherly between allies */
225 if (pplayers_allied(giver, taker)) {
226 worth /= 2;
227 }
228 if (players_on_same_team(giver, taker)) {
229 return 0;
230 }
231
232 /* Do not bother wanting a tech that we already have. */
234 == TECH_KNOWN) {
235 return 0;
236 }
237
238 /* Calculate in tech leak to our opponents, guess 50% chance */
240 if (eplayer == giver
241 || eplayer == taker
243 tech_id) == TECH_KNOWN) {
244 continue;
245 }
246
247 /* Don't risk it falling into enemy hands */
249 && adv_is_player_dangerous(giver, eplayer)) {
250 *is_dangerous = TRUE;
251 }
252
254 && !pplayers_allied(giver, eplayer)) {
255 /* Taker can enrich their side with this tech */
256 worth += dai_goldequiv_tech(ait, eplayer, tech_id) / 4;
257 }
259
260 return worth;
261}
262
263/******************************************************************/
266static const struct player *
268 const struct player *them)
269{
271 if (aplayer != us
272 && aplayer != them
275 return aplayer;
276 }
278
279 return nullptr;
280}
281
282/******************************************************************/
289static int dai_goldequiv_clause(struct ai_type *ait,
290 struct player *pplayer,
291 struct player *aplayer,
292 struct Clause *pclause,
293 bool verbose,
295{
296 bool close_here;
297 struct ai_plr *ai;
298 int worth = 0; /* Worth for pplayer of what aplayer gives */
299 bool give = (pplayer == pclause->from);
300 struct player *giver;
301 const struct player *penemy;
302 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
303 bool is_dangerous;
304 const struct civ_map *nmap = &(wld.map);
305
306 ai = dai_plr_data_get(ait, pplayer, &close_here);
307
308 fc_assert_ret_val(pplayer != aplayer, 0);
309
310 diplomacy_verbose = verbose;
312 giver = pclause->from;
313
314 switch (pclause->type) {
315 case CLAUSE_ADVANCE:
316 if (give) {
317 worth -= compute_tech_sell_price(ait, pplayer, aplayer, pclause->value,
318 &is_dangerous);
319 if (is_dangerous) {
320 worth = -BIG_NUMBER;
321 }
322 } else if (research_invention_state(research_get(pplayer),
323 pclause->value) != TECH_KNOWN) {
324 worth += compute_tech_sell_price(ait, aplayer, pplayer, pclause->value,
325 &is_dangerous);
326
328 /* Consider the upkeep costs! Thus, one can not get an AI player by
329 * - given AI lots of techs for gold/cities etc.
330 * - AI losses tech due to high upkeep.
331 * FIXME: Is there a better way for this? */
332 struct research *research = research_get(pplayer);
333 int limit;
334
335 /* Make sure there's no division by zero */
336 if (research->techs_researched > 0) {
337 int upk_per_tech = player_tech_upkeep(pplayer)
339
340 limit = MAX(1, upk_per_tech);
341 } else {
342 limit = 1;
343 fc_assert(player_tech_upkeep(pplayer) == 0);
344 }
345
346 if (pplayer->server.bulbs_last_turn < limit) {
347 if (research->bulbs_researched < 0) {
348 worth = -BIG_NUMBER;
349 } else {
350 worth /= 2;
351 }
352 }
353 }
354 }
355 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "%s clause worth %d",
357 break;
358
359 case CLAUSE_ALLIANCE:
360 case CLAUSE_PEACE:
361 case CLAUSE_CEASEFIRE:
362 /* Don't do anything in away mode */
363 if (has_handicap(pplayer, H_AWAY)) {
365 _("*%s (AI)* In away mode AI can't sign such a treaty."),
366 player_name(pplayer));
367 worth = -BIG_NUMBER;
368 break;
369 }
370
371 /* This guy is allied to one of our enemies. Only accept
372 * ceasefire. */
374 && pclause->type != CLAUSE_CEASEFIRE) {
375 dai_diplo_notify(aplayer, _("*%s (AI)* First break alliance with %s, %s."),
376 player_name(pplayer), player_name(penemy),
378 worth = -BIG_NUMBER;
379 break;
380 }
381
382 /* They were allied with an enemy at the beginning of the turn. */
383 if (adip->is_allied_with_enemy
384 && pclause->type != CLAUSE_CEASEFIRE) {
385 dai_diplo_notify(aplayer, _("*%s (AI)* I would like to see you keep your "
386 "distance from %s for some time, %s."),
387 player_name(pplayer),
388 player_name(adip->is_allied_with_enemy),
390 worth = -BIG_NUMBER;
391 break;
392 }
393
394 /* Steps of the treaty ladder */
395 if (pclause->type == CLAUSE_PEACE) {
396 const struct player_diplstate *ds
397 = player_diplstate_get(pplayer, aplayer);
398
399 if (!pplayers_non_attack(pplayer, aplayer)) {
401 _("*%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) {
407 _("*%s (AI)* I wish to see you keep the current "
408 "ceasefire for a bit longer first, %s."),
409 player_name(pplayer),
411 worth = -BIG_NUMBER;
412 } else if (adip->countdown >= 0 || adip->countdown < -1) {
413 worth = -BIG_NUMBER; /* But say nothing */
414 } else {
415 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
417 }
418 } else if (pclause->type == CLAUSE_ALLIANCE) {
419 if (!pplayers_in_peace(pplayer, aplayer)) {
420 worth = greed(pplayer->ai_common.love[player_index(aplayer)]
422 }
423 if (adip->countdown >= 0 || adip->countdown < -1) {
424 worth = -BIG_NUMBER; /* But say nothing */
425 } else {
426 worth += greed(pplayer->ai_common.love[player_index(aplayer)]
428 }
429 if (pplayer->ai_common.love[player_index(aplayer)] < MAX_AI_LOVE / 10) {
430 dai_diplo_notify(aplayer, _("*%s (AI)* I simply do not trust you with an "
431 "alliance yet, %s."),
432 player_name(pplayer),
434 worth = -BIG_NUMBER;
435 }
436 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ally clause worth %d", worth);
437 } else {
438 int turns = game.info.turn;
439
441 if (turns < TURNS_BEFORE_TARGET) {
442 worth = 0; /* Show some good faith */
443 } else {
444 worth = greed(pplayer->ai_common.love[player_index(aplayer)]);
445 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "ceasefire worth=%d love=%d "
446 "turns=%d", worth,
448 turns);
449 }
450 }
451
452 /* Let's all hold hands in one happy family! */
453 if (adip->is_allied_with_ally) {
454 worth /= 2;
455 }
456
457 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "treaty clause worth %d", worth);
458 break;
459
460 case CLAUSE_GOLD:
461 if (give) {
462 worth -= pclause->value;
463 } else {
464 worth += pclause->value * (100 - game.server.diplgoldcost) / 100;
465 }
466 break;
467
468 case CLAUSE_SEAMAP:
469 if (!give || ds_after == DS_ALLIANCE) {
470 /* Useless to us - we're omniscient! And allies get it for free! */
471 worth = 0;
472 } else {
473 /* Very silly algorithm 1: Sea map more worth if enemy has more
474 cities. Reasoning is they have more use of seamap for settling
475 new areas the more cities they have already. */
476 worth -= 15 * city_list_size(aplayer->cities);
477 /* Don't like them? Don't give it to them! */
478 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 7, worth);
479 /* Make maps from novice player cheap */
480 if (has_handicap(pplayer, H_DIPLOMACY)) {
481 worth /= 2;
482 }
483 }
484 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "seamap clause worth %d",
485 worth);
486 break;
487
488 case CLAUSE_MAP:
489 if (!give || ds_after == DS_ALLIANCE) {
490 /* Useless to us - we're omniscient! And allies get it for free! */
491 worth = 0;
492 } else {
493 /* Very silly algorithm 2: Land map more worth the more cities
494 we have, since we expose all of these to the enemy. */
495 worth -= 40 * MAX(city_list_size(pplayer->cities), 1);
496 /* Inflate numbers if not peace */
497 if (!pplayers_in_peace(pplayer, aplayer)) {
498 worth *= 2;
499 }
500 /* Don't like them? Don't give it to them! */
501 worth = MIN(pplayer->ai_common.love[player_index(aplayer)] * 10, worth);
502 /* Make maps from novice player cheap */
503 if (has_handicap(pplayer, H_DIPLOMACY)) {
504 worth /= 6;
505 }
506 }
507 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "landmap clause worth %d",
508 worth);
509 break;
510
511 case CLAUSE_CITY: {
512 struct city *offer = city_list_find_number(pclause->from->cities,
513 pclause->value);
514
515 if (!offer || city_owner(offer) != giver) {
516 /* City destroyed or taken during negotiations */
518 _("*%s (AI)* I do not know the city you mention."),
519 player_name(pplayer));
520 worth = 0;
521 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer,
522 "city destroyed during negotiations");
523 } else if (give) {
524 /* AI must be crazy to trade away its cities */
525 worth -= city_gold_worth(nmap, offer);
526 if (is_capital(offer)) {
527 worth = -BIG_NUMBER; /* Never! Ever! */
528 } else {
529 worth *= 15;
530 }
531 if (aplayer == offer->original) {
532 /* Let them buy back their own city cheaper. */
533 worth /= 2;
534 }
535 } else {
536 worth = city_gold_worth(nmap, offer);
537 }
538 if (offer != nullptr) {
539 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "worth of %s is %d",
540 city_name_get(offer), worth);
541 }
542 break;
543 }
544
545 case CLAUSE_VISION:
546 if (give) {
547 if (ds_after == DS_ALLIANCE) {
548 if (!shared_vision_is_safe(pplayer, aplayer)) {
550 _("*%s (AI)* Sorry, sharing vision with you "
551 "is not safe."),
552 player_name(pplayer));
553 worth = -BIG_NUMBER;
554 } else {
555 worth = 0;
556 }
557 } else {
558 /* So out of the question */
559 worth = -BIG_NUMBER;
560 }
561 } else {
562 worth = 0; /* We are omniscient, so... */
563 }
564 break;
565
566 case CLAUSE_EMBASSY:
567 if (give) {
568 if (ds_after == DS_ALLIANCE) {
569 worth = 0;
570 } else if (ds_after == DS_PEACE) {
571 worth = -5 * game.info.turn;
572 } else {
573 worth = MIN(-50 * game.info.turn
574 + pplayer->ai_common.love[player_index(aplayer)],
575 -5 * game.info.turn);
576 }
578 worth = game.info.tech_leak_pct / 10;
579 } else {
580 worth = 0; /* We don't need no stinkin' embassy, do we? */
581 }
582 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "embassy clause worth %d",
583 worth);
584 break;
586 if (give) {
587 if (ds_after == DS_ALLIANCE) {
588 worth = 0;
589 } else {
590 /* Here we assume that number of cities correlate with number of tiles. */
591 worth = -3 * (city_list_size(pplayer->cities) + 1);
592 }
593 } else {
594 int cities = city_list_size(aplayer->cities);
595
596 worth = MIN(cities, 3);
597 }
598 break;
599 case CLAUSE_COUNT:
601 break;
602 } /* End of switch */
603
604 if (close_here) {
605 dai_data_phase_finished(ait, pplayer);
606 }
607
609
610 return worth;
611}
612
613/******************************************************************/
617void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer,
618 struct player *aplayer, struct treaty *ptreaty)
619{
620 int total_balance = 0;
621 bool only_gifts = TRUE;
623 = player_diplstate_get(pplayer, aplayer)->type;
624 int given_cities = 0;
625
627 if (is_pact_clause(pclause->type)) {
629 }
630 if (pclause->type == CLAUSE_CITY && pclause->from == pplayer) {
631 given_cities++;
632 }
634
635 /* Evaluate clauses */
637 const struct research *presearch = research_get(pplayer);
638
641
642 if (pclause->type != CLAUSE_GOLD && pclause->type != CLAUSE_MAP
643 && pclause->type != CLAUSE_SEAMAP && pclause->type != CLAUSE_VISION
644 && (pclause->type != CLAUSE_ADVANCE
646 || pclause->value == research_get(pplayer)->tech_goal
647 || pclause->value == research_get(pplayer)->researching
649 pclause->value))) {
650 /* We accept the above list of clauses as gifts, even if we are
651 * at war. We do not accept tech or cities since these can be used
652 * against us, unless we know that we want this tech anyway, or
653 * it doesn't matter due to tech cost style. */
655 }
657
658 /* If we are at war, and no peace is offered, then no deal, unless
659 * it is just gifts, in which case we gratefully accept. */
660 if (ds_after == DS_WAR && !only_gifts) {
661 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "no peace offered, must refuse");
662 return;
663 }
664
665 if (given_cities > 0
666 && city_list_size(pplayer->cities) - given_cities <= 2) {
667 /* always keep at least two cities */
668 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "cannot give last cities");
669 return;
670 }
671
672 /* Accept if balance is good */
673 if (total_balance >= 0) {
675 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was good: %d",
677 } else {
678 /* AI complains about the treaty which was proposed, unless the AI
679 * made the proposal. */
680 if (pplayer != ptreaty->plr0) {
682 _("*%s (AI)* This deal was not very good for us, %s!"),
683 player_name(pplayer),
685 }
686 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "balance was bad: %d",
688 }
689}
690
691/******************************************************************/
695static void dai_treaty_react(struct ai_type *ait,
696 struct player *pplayer,
697 struct player *aplayer,
698 struct Clause *pclause)
699{
700 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
701
702 switch (pclause->type) {
703 case CLAUSE_ALLIANCE:
704 if (adip->is_allied_with_ally) {
705 dai_diplo_notify(aplayer, _("*%s (AI)* Welcome into our alliance %s!"),
706 player_name(pplayer),
708 } else {
709 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, may we forever stand united, %s."),
710 player_name(pplayer),
712 }
713 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "become allies");
714 break;
715 case CLAUSE_PEACE:
716 dai_diplo_notify(aplayer, _("*%s (AI)* Yes, peace in our time!"),
717 player_name(pplayer));
718 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign peace treaty");
719 break;
720 case CLAUSE_CEASEFIRE:
721 dai_diplo_notify(aplayer, _("*%s (AI)* Agreed. No more hostilities, %s."),
722 player_name(pplayer),
724 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "sign ceasefire");
725 break;
726 default:
727 break;
728 }
729}
730
731/******************************************************************/
738void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer,
739 struct player *aplayer, struct treaty *ptreaty)
740{
741 bool close_here;
742 struct ai_plr *ai;
743 int total_balance = 0;
744 bool gift = TRUE;
746 = player_diplstate_get(pplayer, aplayer)->type;
747
748 ai = dai_plr_data_get(ait, pplayer, &close_here);
749
750 fc_assert_ret(pplayer != aplayer);
751
753 if (is_pact_clause(pclause->type)) {
755 }
757
758 /* Evaluate clauses */
760 int balance
762
764 gift = (gift && (balance >= 0));
765 dai_treaty_react(ait, pplayer, aplayer, pclause);
766 if (is_pact_clause(pclause->type)
767 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown != -1) {
768 /* Cancel a countdown towards war if we just agreed to peace... */
769 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "countdown nullified");
770 dai_diplomacy_get(ait, pplayer, aplayer)->countdown = -1;
771 }
773
774 /* Rather arbitrary algorithm to increase our love for a player if
775 * they offer us gifts. It is only a gift if _all_ the clauses
776 * are beneficial to us. */
777 if (total_balance > 0 && gift) {
778 int i = total_balance / ((city_list_size(pplayer->cities) * 10) + 1);
779
780 i = MIN(i, ai->diplomacy.love_incr * 150) * 10;
781 pplayer->ai_common.love[player_index(aplayer)] += i;
782 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "gift increased love by %d", i);
783 }
784
785 if (close_here) {
786 dai_data_phase_finished(ait, pplayer);
787 }
788}
789
790/******************************************************************/
797static int dai_war_desire(struct ai_type *ait, struct player *pplayer,
798 struct player *target)
799{
800 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, nullptr);
801 struct adv_data *adv = adv_data_get(pplayer, nullptr);
802 int want = 0, fear = 0, distance = 0, settlers = 0, cities = 0;
803 struct player_spaceship *ship = &target->spaceship;
804
805 city_list_iterate(target->cities, pcity) {
806 want += 100; /* Base city want */
807 want += city_size_get(pcity) * 20;
808 want += pcity->surplus[O_SHIELD] * 8;
809 want += pcity->surplus[O_TRADE] * 6;
810
811 /* FIXME: This might be buggy if it ignores unmet UnitClass reqs. */
813
814 city_built_iterate(pcity, pimprove) {
815 int cost = impr_build_shield_cost(pcity, pimprove);
816
817 want += cost;
818 if (improvement_obsolete(pplayer, pimprove, pcity)) {
819 continue;
820 }
821 if (is_great_wonder(pimprove)) {
822 want += cost * 2;
823 } else if (is_small_wonder(pimprove)) {
824 want += cost;
825 }
828 unit_list_iterate(target->units, punit) {
829 const struct unit_type *ptype = unit_type_get(punit);
830
832
833 /* Fear enemy expansionism */
835 want += 100;
836 }
838 unit_list_iterate(pplayer->units, punit) {
839 const struct unit_type *ptype = unit_type_get(punit);
840
841 fear -= ATTACK_POWER(ptype) / 2;
842
843 /* Our own expansionism reduces want for war */
845 want -= 200;
846 settlers++;
847 }
849 city_list_iterate(pplayer->cities, pcity) {
850 if (VUT_UTYPE == pcity->production.kind
851 && utype_is_cityfounder(pcity->production.value.utype)) {
852 want -= 150;
853 settlers++;
854 }
855 cities++;
857
858 /* Modify by settler/cities ratio to prevent early wars when
859 * we should be expanding. This will eliminate want if we
860 * produce settlers in all cities (ie full expansion). */
861 want -= abs(want) / MAX(cities - settlers, 1);
862
863 /* Calculate average distances to other player's empire. */
864 distance = player_distance_to_player(pplayer, target);
865 dai_diplomacy_get(ait, pplayer, target)->distance = distance;
866
867 /* Worry a bit if the other player has extreme amounts of wealth
868 * that can be used in cities to quickly buy an army. */
869 fear += (target->economic.gold / 5000) * city_list_size(target->cities);
870
871 /* Tech lead is worrisome. FIXME: Only consider 'military' techs. */
872 fear += MAX(research_get(target)->techs_researched
873 - research_get(pplayer)->techs_researched, 0) * 100;
874
875 /* Spacerace loss we will not allow! */
876 if (ship->state >= SSHIP_STARTED) {
877 want *= 2;
878 }
879 if (adv->dipl.spacerace_leader == target) {
881
882 return BIG_NUMBER; /* Do NOT amortize this number! */
883 }
884
885 /* Modify by which treaties we would break to other players, and what
886 * excuses we have to do so. FIXME: We only consider immediate
887 * allies, but we might trigger a wider chain reaction. */
889 bool cancel_excuse =
892
893 if (eplayer == pplayer) {
894 continue;
895 }
896
897 /* Remember: pplayers_allied() returns true when target == eplayer */
898 if (!cancel_excuse && pplayers_allied(target, eplayer)) {
899 if (ds == DS_ARMISTICE) {
900 want -= abs(want) / 10; /* 10% off */
901 } else if (ds == DS_CEASEFIRE) {
902 want -= abs(want) / 7; /* 15% off */
903 } else if (ds == DS_PEACE) {
904 want -= abs(want) / 5; /* 20% off */
905 } else if (ds == DS_ALLIANCE) {
906 want -= abs(want) / 3; /* 33% off */
907 }
908 }
910
911 /* Modify by love. Increase the divisor to make ai go to war earlier */
912 want -= MAX(0, want * pplayer->ai_common.love[player_index(target)]
913 / (2 * MAX_AI_LOVE));
914
915 /* Make novice AI more peaceful with human players */
916 if (has_handicap(pplayer, H_DIPLOMACY) && is_human(target)) {
917 want /= 2;
918 }
919
920 /* Amortize by distance */
921 want = amortize(want, distance);
922
923 if (pplayers_allied(pplayer, target)) {
924 want /= 4;
925 }
926
927 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "War want %d, war fear %d",
928 want, fear);
929 return (want - fear);
930}
931
932/******************************************************************/
937static void dai_diplomacy_suggest(struct player *pplayer,
938 struct player *aplayer,
939 enum clause_type what,
940 bool to_pplayer,
941 int value)
942{
943 if (!could_meet_with_player(pplayer, aplayer)) {
944 log_base(LOG_DIPL2, "%s tries to do diplomacy to %s without contact",
945 player_name(pplayer), player_name(aplayer));
946 return;
947 }
948
952 : pplayer),
953 what, value);
954}
955
956/******************************************************************/
959void dai_diplomacy_first_contact(struct ai_type *ait, struct player *pplayer,
960 struct player *aplayer)
961{
962 bool wants_ceasefire = FALSE;
963
964 /* Randomize initial love */
965 pplayer->ai_common.love[player_index(aplayer)] += 2 - fc_rand(5);
966
967 if (is_ai(pplayer)
968 && player_diplstate_get(pplayer, aplayer)->type == DS_WAR
969 && could_meet_with_player(pplayer, aplayer)) {
970 if (has_handicap(pplayer, H_CEASEFIRE)) {
971 fc_assert(!has_handicap(pplayer, H_AWAY));
973 } else if (!has_handicap(pplayer, H_AWAY)) {
974 struct Clause clause;
975
976 clause.from = pplayer;
977 clause.value = 0;
978 clause.type = CLAUSE_CEASEFIRE;
979
980 if (dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
981 FALSE, DS_CEASEFIRE) > 0) {
983 }
984 }
985 }
986
987 if (wants_ceasefire) {
989 _("*%s (AI)* Greetings %s! May we suggest a ceasefire "
990 "while we get to know each other better?"),
991 player_name(pplayer),
993 clear_old_treaty(pplayer, aplayer);
995 } else {
997 _("*%s (AI)* I found you %s! Now make it worth my "
998 "letting you live, or be crushed."),
999 player_name(pplayer),
1001 }
1002}
1003
1004/******************************************************************/
1013void dai_diplomacy_begin_new_phase(struct ai_type *ait, struct player *pplayer)
1014{
1015 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, nullptr);
1016 struct adv_data *adv = adv_data_get(pplayer, nullptr);
1018 int best_desire = 0;
1019 struct player *best_target = nullptr;
1020
1021 fc_assert_ret(is_ai(pplayer));
1022
1023 if (!pplayer->is_alive) {
1024 return; /* Duh */
1025 }
1026
1027 memset(war_desire, 0, sizeof(war_desire));
1028
1029 /* Calculate our desires, and find desired war target */
1031 /* We don't hate ourselves, those we don't know or team members. */
1032 if (aplayer == pplayer
1033 || NEVER_MET(pplayer, aplayer)
1034 || players_on_same_team(pplayer, aplayer)) {
1035 continue;
1036 }
1041 }
1043
1044 /* Time to make love. If we've been wronged, hold off that love
1045 * for a while. Also, cool our head each turn with love_coeff. */
1047 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1048 int amount = 0;
1049 int pit;
1050
1051 if (pplayer == aplayer) {
1052 continue;
1053 }
1054
1055 if ((pplayers_non_attack(pplayer, aplayer)
1056 || pplayers_allied(pplayer, aplayer))
1057 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel == 0
1058 && adip->countdown == -1
1059 && !adip->is_allied_with_enemy
1060 && !adip->at_war_with_ally
1061 && aplayer != best_target
1062 && adip->ally_patience >= 0) {
1063 amount += ai->diplomacy.love_incr / 2;
1064 if (pplayers_allied(pplayer, aplayer)) {
1065 amount += ai->diplomacy.love_incr / 3;
1066 }
1067 /* Increase love by each enemy they are at war with */
1069 if (WAR(eplayer, aplayer) && WAR(pplayer, eplayer)) {
1070 amount += ai->diplomacy.love_incr / 4;
1071 }
1074 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Increased love by %d", amount);
1075 } else if (WAR(pplayer, aplayer)) {
1076 amount -= ai->diplomacy.love_incr / 2;
1078 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost to war", amount);
1079 } else if (player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel
1080 != 0) {
1081 /* Provoked in time of peace */
1082 if (pplayer->ai_common.love[player_index(aplayer)] > 0) {
1083 amount -= pplayer->ai_common.love[player_index(aplayer)] / 2;
1084 }
1085 amount -= ai->diplomacy.love_incr * 6;
1087 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Provoked! %d love lost!",
1088 amount);
1089 }
1090 if (pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE * 8 / 10
1091 && !pplayers_allied(pplayer, aplayer)) {
1092 int love_change = ai->diplomacy.love_incr / 3;
1093
1094 /* Upper levels of AI trust and love is reserved for allies. */
1096 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost from excess",
1097 love_change);
1098 }
1099 amount = 0;
1100
1101 /* Reduce love due to units in our territory.
1102 * AI is so naive, that we have to count it even if players are allied */
1103 pit = player_in_territory(pplayer, aplayer) * (MAX_AI_LOVE / 200);
1104 amount -= MIN(pit,
1106 * ((adip->is_allied_with_enemy != nullptr) + 1));
1108 if (amount != 0) {
1109 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "%d love lost due to units inside "
1110 "our borders", amount);
1111 }
1112
1113 /* Increase the love if aplayer has got a building that makes
1114 * us love them more. Typically it's Eiffel Tower */
1115 if (!NEVER_MET(pplayer, aplayer)) {
1116 pplayer->ai_common.love[player_index(aplayer)] +=
1118 }
1120
1121 /* Can we win by space race? */
1122 if (adv->dipl.spacerace_leader == pplayer) {
1123 log_base(LOG_DIPL2, "%s going for space race victory!",
1124 player_name(pplayer));
1125 ai->diplomacy.strategy = WIN_SPACE; /* Yes! */
1126 } else {
1127 if (ai->diplomacy.strategy == WIN_SPACE) {
1129 }
1130 }
1131
1133 int *love = &pplayer->ai_common.love[player_index(aplayer)];
1134
1135 if (aplayer == best_target && best_desire > 0) {
1136 int reduction = MIN(best_desire, MAX_AI_LOVE / 20);
1137
1138 *love -= reduction;
1139 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "Wants war, reducing "
1140 "love by %d ", reduction);
1141 }
1142
1143 /* Edge love towards zero */
1144 *love -= *love * ((double)ai->diplomacy.love_coeff / 100.0);
1145
1146 /* AI love should always be in range [-MAX_AI_LOVE..MAX_AI_LOVE] */
1147 *love = MAX(-MAX_AI_LOVE, MIN(MAX_AI_LOVE, *love));
1149}
1150
1151/******************************************************************/
1154static void suggest_tech_exchange(struct ai_type *ait,
1155 struct player *player1,
1156 struct player *player2)
1157{
1161 int worth[ac];
1162 bool is_dangerous;
1163
1164 worth[A_NONE] = 0;
1165
1168 == TECH_KNOWN) {
1171 worth[tech] = -compute_tech_sell_price(ait, player1, player2, tech,
1172 &is_dangerous);
1173 if (is_dangerous) {
1174 /* Don't try to exchange */
1175 worth[tech] = 0;
1176 }
1177 } else {
1178 worth[tech] = 0;
1179 }
1180 } else {
1184 worth[tech] = compute_tech_sell_price(ait, player2, player1, tech,
1185 &is_dangerous);
1186 if (is_dangerous) {
1187 /* Don't try to exchange */
1188 worth[tech] = 0;
1189 }
1190 } else {
1191 worth[tech] = 0;
1192 }
1193 }
1195
1197 if (worth[tech] <= 0) {
1198 continue;
1199 }
1201 int diff;
1202
1203 if (worth[tech2] >= 0) {
1204 continue;
1205 }
1206 /* Tech2 is given by player1, tech is given by player2 */
1207 diff = worth[tech] + worth[tech2];
1208 if ((diff > 0 && player1->economic.gold >= diff)
1209 || (diff < 0 && player2->economic.gold >= -diff)
1210 || diff == 0) {
1213 if (diff > 0) {
1215 } else if (diff < 0) {
1217 }
1218 return;
1219 }
1222}
1223
1224/******************************************************************/
1227static void clear_old_treaty(struct player *pplayer, struct player *aplayer)
1228{
1229 struct treaty *old_treaty = find_treaty(pplayer, aplayer);
1230
1231 if (old_treaty != nullptr) {
1232 /* Remove existing clauses */
1235 player_number(pplayer),
1236 player_number(pclause->from),
1237 pclause->type, pclause->value);
1238 free(pclause);
1241 old_treaty->clauses = clause_list_new();
1242 }
1243}
1244
1245/******************************************************************/
1248static void dai_share(struct ai_type *ait, struct player *pplayer,
1249 struct player *aplayer)
1250{
1251 struct research *presearch = research_get(pplayer);
1253 bool gives_vision;
1254
1255 clear_old_treaty(pplayer, aplayer);
1256
1257 /* Only share techs with team mates */
1258 if (presearch != aresearch
1259 && players_on_same_team(pplayer, aplayer)) {
1271 }
1273 }
1274
1275 /* Only give shared vision if safe. Only ask for shared vision if fair. */
1277 if (!gives_vision
1278 && shared_vision_is_safe(pplayer, aplayer)) {
1281 }
1282 if (gives_vision
1283 && !gives_shared_vision(aplayer, pplayer)
1284 && (is_human(aplayer)
1285 || shared_vision_is_safe(aplayer, pplayer))) {
1287 }
1288
1289 if (!player_has_embassy(pplayer, aplayer)) {
1291 }
1292 if (!player_has_embassy(aplayer, pplayer)) {
1294 }
1295
1296 if (!has_handicap(pplayer, H_DIPLOMACY) || is_human(aplayer)) {
1297 suggest_tech_exchange(ait, pplayer, aplayer);
1298 }
1299}
1300
1301/******************************************************************/
1308static void dai_declare_war(struct ai_type *ait, struct player *pplayer,
1309 struct player *target)
1310{
1311 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1312
1313 /* This will take us straight to war. */
1314 while (player_diplstate_get(pplayer, target)->type != DS_WAR) {
1315 if (pplayer_can_cancel_treaty(pplayer, target) != DIPL_OK) {
1316 DIPLO_LOG(ait, LOG_ERROR, pplayer, target,
1317 "Wanted to cancel treaty but was unable to.");
1318 adip->countdown = -1; /* War declaration aborted */
1319
1320 return;
1321 }
1323 }
1324
1325 /* Throw a tantrum */
1326 if (pplayer->ai_common.love[player_index(target)] > 0) {
1327 pplayer->ai_common.love[player_index(target)] = -1;
1328 }
1329 pplayer->ai_common.love[player_index(target)] -= MAX_AI_LOVE / 8;
1330
1331 fc_assert(!gives_shared_vision(pplayer, target));
1332
1333 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "war declared");
1334}
1335
1336/******************************************************************/
1341static void dai_go_to_war(struct ai_type *ait, struct player *pplayer,
1342 struct player *target, enum war_reason reason)
1343{
1344 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1345
1346 fc_assert_ret(pplayer != target);
1347 fc_assert_ret(target->is_alive);
1348
1349 switch (reason) {
1350 case DAI_WR_SPACE:
1351 dai_diplo_notify(target, _("*%s (AI)* Space will never be yours."),
1352 player_name(pplayer));
1353 adip->countdown = -10;
1354 break;
1355 case DAI_WR_BEHAVIOR:
1356 dai_diplo_notify(target,
1357 _("*%s (AI)* I have tolerated your vicious antics "
1358 "long enough! To war!"),
1359 player_name(pplayer));
1360 adip->countdown = -20;
1361 break;
1362 case DAI_WR_NONE:
1363 dai_diplo_notify(target, _("*%s (AI)* Peace in ... some other time."),
1364 player_name(pplayer));
1365 adip->countdown = -10;
1366 break;
1367 case DAI_WR_HATRED:
1368 dai_diplo_notify(target,
1369 _("*%s (AI)* Finally I get around to you! Did "
1370 "you really think you could get away with your crimes?"),
1371 player_name(pplayer));
1372 adip->countdown = -20;
1373 break;
1374 case DAI_WR_EXCUSE:
1375 dai_diplo_notify(target,
1376 _("*%s (AI)* Your covert hostilities brought "
1377 "this war upon you!"),
1378 player_name(pplayer));
1379 adip->countdown = -20;
1380 break;
1381 case DAI_WR_ALLIANCE:
1382 if (adip->at_war_with_ally) {
1383 dai_diplo_notify(target,
1384 _("*%s (AI)* Your aggression against %s was "
1385 "your last mistake!"),
1386 player_name(pplayer),
1387 player_name(adip->at_war_with_ally));
1388 adip->countdown = -3;
1389 } else {
1390 /* Ooops! */
1391 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "Wanted to declare war "
1392 "for their war against an ally, but can no longer find "
1393 "this ally! War declaration aborted.");
1394 adip->countdown = -1;
1395 return;
1396 }
1397 break;
1398 }
1399
1400 fc_assert_ret(adip->countdown < 0);
1401
1402 if (gives_shared_vision(pplayer, target)) {
1403 remove_shared_vision(pplayer, target);
1404 }
1405
1406 /* Check for Senate obstruction. If so, dissolve it. */
1407 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_SENATE_BLOCKING) {
1408 struct government *real_gov = pplayer->government;
1409
1411
1412 if (pplayer_can_cancel_treaty(pplayer, target) == DIPL_OK) {
1413 /* It seems that revolution would help. */
1414 pplayer->government = real_gov;
1417 def_ai_player_data(pplayer, ait)->diplomacy.war_target = target;
1418 return;
1419 } else {
1420 /* There would be Senate even during revolution. Better not to revolt for nothing */
1421 pplayer->government = real_gov;
1422 adip->countdown = -1; /* War declaration aborted */
1423
1424 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target,
1425 "Not revolting, as there would be Senate regardless.");
1426
1427 return;
1428 }
1429 }
1430
1431 dai_declare_war(ait, pplayer, target);
1432}
1433
1434/******************************************************************/
1440void dai_revolution_start(struct ai_type *ait, struct player *pplayer)
1441{
1442 struct ai_plr *data = def_ai_player_data(pplayer, ait);
1443
1444 if (data->diplomacy.war_target != nullptr) {
1445 /* Target might have died since it was set. */
1446 if (data->diplomacy.war_target->is_alive) {
1447 if (gives_shared_vision(pplayer, data->diplomacy.war_target)) {
1449 }
1450
1451 dai_declare_war(ait, pplayer, data->diplomacy.war_target);
1452 }
1453
1454 data->diplomacy.war_target = nullptr;
1455 }
1456}
1457
1458/******************************************************************/
1470static void war_countdown(struct ai_type *ait, struct player *pplayer,
1471 struct player *target,
1472 int countdown, enum war_reason reason)
1473{
1474 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, target);
1475
1476 DIPLO_LOG(ait, LOG_DIPL, pplayer, target, "countdown to war in %d", countdown);
1477
1478 /* Otherwise we're resetting an existing countdown, which is very bad */
1479 fc_assert_ret(adip->countdown == -1);
1480
1481 adip->countdown = countdown;
1482 adip->war_reason = reason;
1483
1485 if (!pplayers_allied(pplayer, ally)
1486 || ally == target
1487 || NEVER_MET(pplayer, ally)) {
1488 continue;
1489 }
1490
1491 switch (reason) {
1492 case DAI_WR_SPACE:
1494 PL_("*%s (AI)* We will be launching an all-out war "
1495 "against %s in %d turn to stop the spaceship "
1496 "launch.",
1497 "*%s (AI)* We will be launching an all-out war "
1498 "against %s in %d turns to stop the spaceship "
1499 "launch.",
1500 countdown),
1501 player_name(pplayer),
1502 player_name(target),
1503 countdown);
1505 _("*%s (AI)* Your aid in this matter will be expected. "
1506 "Long live our glorious alliance!"),
1507 player_name(pplayer));
1508 break;
1509 case DAI_WR_BEHAVIOR:
1510 case DAI_WR_EXCUSE:
1512 PL_("*%s (AI)* %s has grossly violated their treaties "
1513 "with us for own gain. We will answer in force in "
1514 "%d turn and expect you to honor your alliance "
1515 "with us and do likewise!",
1516 "*%s (AI)* %s has grossly violated their treaties "
1517 "with us for own gain. We will answer in force in "
1518 "%d turns and expect you to honor your alliance "
1519 "with us and do likewise!", countdown),
1520 player_name(pplayer),
1521 player_name(target),
1522 countdown);
1523 break;
1524 case DAI_WR_NONE:
1526 PL_("*%s (AI)* We intend to pillage and plunder the rich "
1527 "civilization of %s. We declare war in %d turn.",
1528 "*%s (AI)* We intend to pillage and plunder the rich "
1529 "civilization of %s. We declare war in %d turns.",
1530 countdown),
1531 player_name(pplayer),
1532 player_name(target),
1533 countdown);
1535 _("*%s (AI)* If you want a piece of the loot, feel "
1536 "free to join in the action!"),
1537 player_name(pplayer));
1538 break;
1539 case DAI_WR_HATRED:
1541 PL_("*%s (AI)* We have had it with %s. Let us tear this "
1542 "pathetic civilization apart. We declare war in "
1543 "%d turn.",
1544 "*%s (AI)* We have had it with %s. Let us tear this "
1545 "pathetic civilization apart. We declare war in "
1546 "%d turns.",
1547 countdown),
1548 player_name(pplayer),
1549 player_name(target),
1550 countdown);
1552 _("*%s (AI)* As our glorious allies, we expect your "
1553 "help in this war."),
1554 player_name(pplayer));
1555 break;
1556 case DAI_WR_ALLIANCE:
1557 if (WAR(ally, target)) {
1559 PL_("*%s (AI)* We will honor our alliance and declare "
1560 "war on %s in %d turn. Hold on - we are coming!",
1561 "*%s (AI)* We will honor our alliance and declare "
1562 "war on %s in %d turns. Hold on - we are coming!",
1563 countdown),
1564 player_name(pplayer),
1565 player_name(target),
1566 countdown);
1567 } else if (adip->at_war_with_ally) {
1569 PL_("*%s (AI)* We will honor our alliance with %s and "
1570 "declare war on %s in %d turn. We expect you to "
1571 "do likewise.",
1572 "*%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 countdown),
1576 player_name(pplayer),
1577 player_name(adip->at_war_with_ally),
1578 player_name(target),
1579 countdown);
1580 } else {
1581 fc_assert(FALSE); /* Huh? */
1582 }
1583 break;
1584 }
1586}
1587
1588/******************************************************************/
1594void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
1595{
1596 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, nullptr);
1597 bool need_targets = TRUE;
1598 struct player *target = nullptr;
1600 int war_threshold;
1601 int aggr;
1602 float aggr_sr;
1603 float max_sr;
1604
1605 fc_assert_ret(is_ai(pplayer));
1606
1607 if (!pplayer->is_alive) {
1608 return;
1609 }
1610
1611 if (get_player_bonus(pplayer, EFT_NO_DIPLOMACY) > 0) {
1612 /* Diplomacy disabled for this player */
1613 return;
1614 }
1615
1616 /*** If we are greviously insulted, go to war immediately. ***/
1617
1619 if (pplayer->ai_common.love[player_index(aplayer)] < 0
1620 && player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel >= 2
1621 && dai_diplomacy_get(ait, pplayer, aplayer)->countdown == -1) {
1622 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Plans war in revenge");
1623 war_countdown(ait, pplayer, aplayer, map_size_checked(),
1625 }
1627
1628 /*** Stop other players from winning by space race ***/
1629
1630 if (ai->diplomacy.strategy != WIN_SPACE) {
1631 struct adv_data *adv = adv_data_get(pplayer, nullptr);
1632
1634 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1635 struct player_spaceship *ship = &aplayer->spaceship;
1636
1637 if (aplayer == pplayer
1638 || adip->countdown != -1 /* Already counting down to war */
1639 || ship->state == SSHIP_NONE
1640 || players_on_same_team(pplayer, aplayer)
1641 || pplayers_at_war(pplayer, aplayer)) {
1642 continue;
1643 }
1644
1645 /* A spaceship victory is always one single player's or team's victory */
1646 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1647 && adv->dipl.spacerace_leader == aplayer
1648 && pplayers_allied(pplayer, aplayer)) {
1650 _("*%s (AI)* Your attempt to conquer space for "
1651 "yourself alone betrays your true intentions, and I "
1652 "will have no more of our alliance!"),
1653 player_name(pplayer));
1656 if (gives_shared_vision(pplayer, aplayer)) {
1657 remove_shared_vision(pplayer, aplayer);
1658 }
1659 /* Never forgive this */
1661 } else if (ship->state == SSHIP_STARTED
1662 && adip->warned_about_space == 0) {
1663 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 10;
1664 adip->warned_about_space = 10 + fc_rand(6);
1666 _("*%s (AI)* Your attempt to unilaterally "
1667 "dominate outer space is highly offensive."),
1668 player_name(pplayer));
1670 _("*%s (AI)* If you do not stop constructing your "
1671 "spaceship, I may be forced to take action!"),
1672 player_name(pplayer));
1673 }
1674 if (aplayer->spaceship.state == SSHIP_LAUNCHED
1675 && aplayer == adv->dipl.spacerace_leader) {
1676 /* This means war!!! */
1677 pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 2;
1678 DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "plans war due to spaceship");
1679 war_countdown(ait, pplayer, aplayer, 2, DAI_WR_SPACE);
1680 }
1682 }
1683
1684 /*** Declare war against somebody if we are out of targets ***/
1685
1687 int turns; /* Turns since contact */
1688
1689 if (NEVER_MET(pplayer, aplayer)) {
1690 continue;
1691 }
1692 turns = game.info.turn;
1694 if (WAR(pplayer, aplayer)) {
1696 } else if (pplayer->ai_common.love[player_index(aplayer)] < most_hatred
1697 && turns > TURNS_BEFORE_TARGET) {
1699 target = aplayer;
1700 }
1702
1705 aggr_sr = sqrt(aggr);
1706
1707 war_threshold = (MAX_AI_LOVE * (0.70 + aggr_sr / max_sr / 2.0)) - MAX_AI_LOVE;
1708
1709 if (need_targets && target && most_hatred < war_threshold
1710 && dai_diplomacy_get(ait, pplayer, target)->countdown == -1) {
1711 enum war_reason war_reason;
1712
1713 if (pplayers_allied(pplayer, target)) {
1714 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "Plans war against an ally!");
1715 }
1716 if (player_diplstate_get(pplayer, target)->has_reason_to_cancel > 0) {
1717 /* We have good reason */
1718 war_reason = DAI_WR_EXCUSE;
1719 } else if (pplayer->ai_common.love[player_index(target)] < 0) {
1720 /* We have a reason of sorts from way back, maybe? */
1721 war_reason = DAI_WR_HATRED;
1722 } else {
1723 /* We have no legimitate reason... So what? */
1724 war_reason = DAI_WR_NONE;
1725 }
1726 DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "plans war for spoils");
1727 war_countdown(ait, pplayer, target, 4 + map_size_checked(), war_reason);
1728 }
1729
1730 /*** Declare war - against enemies of allies ***/
1731
1733 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1734
1735 if (adip->at_war_with_ally
1736 && adip->countdown == -1
1737 && !adip->is_allied_with_ally
1738 && !pplayers_at_war(pplayer, aplayer)
1740 || fc_rand(5) < 1)) {
1741 DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "plans war to help ally %s",
1742 player_name(adip->at_war_with_ally));
1743 war_countdown(ait, pplayer, aplayer, 2 + map_size_checked(),
1745 }
1747
1748 /*** Actually declare war (when we have moved units into position) ***/
1749
1751 if (!players_on_same_team(pplayer, aplayer)) {
1752 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1753
1754 if (!aplayer->is_alive) {
1755 adip->countdown = -1;
1756 continue;
1757 }
1758 if (adip->countdown > 0) {
1759 adip->countdown--;
1760 } else if (adip->countdown == 0) {
1761 if (!WAR(pplayer, aplayer)) {
1762 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Declaring war!");
1763 dai_go_to_war(ait, pplayer, aplayer, adip->war_reason);
1764 }
1765 } else if (adip->countdown < -1) {
1766 /* Negative countdown less than -1 is war stubbornness */
1767 adip->countdown++;
1768 }
1769 }
1771
1772 /*** Try to make peace with everyone we love ***/
1773
1776 && diplomacy_possible(pplayer, aplayer)) {
1778 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
1779 struct Clause clause;
1780
1781 /* Meaningless values, but rather not have them unset. */
1782 clause.from = pplayer;
1783 clause.value = 0;
1784
1785 /* Remove shared vision if we are not allied or it is no longer safe. */
1786 if (gives_shared_vision(pplayer, aplayer)) {
1787 if (!pplayers_allied(pplayer, aplayer)) {
1788 remove_shared_vision(pplayer, aplayer);
1789 } else if (!players_on_same_team(pplayer, aplayer)
1790 && !shared_vision_is_safe(pplayer, aplayer)) {
1792 _("*%s (AI)* Sorry, sharing vision with you "
1793 "is no longer safe."),
1794 player_name(pplayer));
1795 remove_shared_vision(pplayer, aplayer);
1796 }
1797 }
1798
1799 /* No peace to enemies of our allies... or pointless peace. */
1801 || aplayer == pplayer
1802 || aplayer == target /* no mercy */
1803 || adip->countdown >= 0
1804 || !could_meet_with_player(pplayer, aplayer)) {
1805 continue;
1806 }
1807
1808 /* Spam control */
1809 adip->asked_about_peace = MAX(adip->asked_about_peace - 1, 0);
1810 adip->asked_about_alliance = MAX(adip->asked_about_alliance - 1, 0);
1811 adip->asked_about_ceasefire = MAX(adip->asked_about_ceasefire - 1, 0);
1812 adip->warned_about_space = MAX(adip->warned_about_space - 1, 0);
1813 adip->spam = MAX(adip->spam - 1, 0);
1814 if (adip->spam > 0 && is_ai(aplayer)) {
1815 /* Don't spam */
1816 continue;
1817 }
1818
1819 /* Canvass support from existing friends for our war, and try to
1820 * make friends with enemies. Then we wait some turns until next time
1821 * we spam them with our gibbering chatter. */
1822 if (adip->spam <= 0) {
1823 if (!pplayers_allied(pplayer, aplayer)) {
1824 adip->spam = fc_rand(4) + 3; /* Bugger allies often. */
1825 } else {
1826 adip->spam = fc_rand(8) + 6; /* Others are less important. */
1827 }
1828 }
1829
1830 switch (ds) {
1831 case DS_TEAM:
1832 dai_share(ait, pplayer, aplayer);
1833 break;
1834 case DS_ALLIANCE:
1835 /* See if our allies are diligently declaring war on our enemies... */
1836 if (adip->at_war_with_ally) {
1837 break;
1838 }
1839 target = nullptr;
1841 if (WAR(pplayer, eplayer)
1843 target = eplayer;
1844 break;
1845 }
1847
1848 if ((players_on_same_team(pplayer, aplayer)
1849 || pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE / 2)) {
1850 /* Share techs only with team mates and allies we really like. */
1851 dai_share(ait, pplayer, aplayer);
1852 }
1853 if (!target || !target->is_alive) {
1854 adip->ally_patience = 0;
1855 break; /* No need to nag our ally */
1856 }
1857
1858 if (adip->spam <= 0) {
1859 /* Count down patience toward AI player (one that can have spam > 0)
1860 * at the same speed as toward human players. */
1861 if (adip->ally_patience == 0) {
1863 _("*%s (AI)* Greetings our most trustworthy "
1864 "ally. We call upon you to destroy our enemy, %s."),
1865 player_name(pplayer),
1866 player_name(target));
1867 adip->ally_patience--;
1868 } else if (adip->ally_patience == -1) {
1869 if (fc_rand(5) == 1) {
1871 _("*%s (AI)* Greetings ally, I see you have not yet "
1872 "made war with our enemy, %s. Why do I need to remind "
1873 "you of your promises?"),
1874 player_name(pplayer),
1875 player_name(target));
1876 adip->ally_patience--;
1877 }
1878 } else if (fc_rand(5) == 1
1879 && !players_on_same_team(pplayer, aplayer)) {
1881 _("*%s (AI)* Dishonored one, we made a pact of "
1882 "alliance, and yet you remain at peace with our mortal "
1883 "enemy, %s! This is unacceptable; our alliance is no "
1884 "more!"),
1885 player_name(pplayer),
1886 player_name(target));
1887 DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer,
1888 "breaking useless alliance");
1889 /* To peace */
1893 = MIN(pplayer->ai_common.love[player_index(aplayer)], 0);
1894 if (gives_shared_vision(pplayer, aplayer)) {
1895 remove_shared_vision(pplayer, aplayer);
1896 }
1897
1899 }
1900 }
1901 break;
1902
1903 case DS_PEACE:
1904 clause.type = CLAUSE_ALLIANCE;
1905 if (adip->at_war_with_ally
1906 || (is_human(aplayer) && adip->asked_about_alliance > 0)
1907 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1908 FALSE, DS_ALLIANCE) < 0) {
1909 break;
1910 }
1911 clear_old_treaty(pplayer, aplayer);
1913 adip->asked_about_alliance = is_human(aplayer) ? 13 : 0;
1915 _("*%s (AI)* Greetings friend, may we suggest "
1916 "making a common cause and join in an alliance?"),
1917 player_name(pplayer));
1918 break;
1919
1920 case DS_CEASEFIRE:
1921 clause.type = CLAUSE_PEACE;
1922 if (adip->at_war_with_ally
1923 || (is_human(aplayer) && adip->asked_about_peace > 0)
1924 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1925 FALSE, DS_PEACE) < 0) {
1926 break;
1927 }
1928 clear_old_treaty(pplayer, aplayer);
1930 adip->asked_about_peace = is_human(aplayer) ? 12 : 0;
1932 _("*%s (AI)* Greetings neighbor, may we suggest "
1933 "more peaceful relations?"),
1934 player_name(pplayer));
1935 break;
1936
1937 case DS_NO_CONTACT: /* But we do have embassy! weird. */
1938 case DS_WAR:
1939 clause.type = CLAUSE_CEASEFIRE;
1940 if ((is_human(aplayer) && adip->asked_about_ceasefire > 0)
1941 || dai_goldequiv_clause(ait, pplayer, aplayer, &clause,
1942 FALSE, DS_CEASEFIRE) < 0) {
1943 break; /* Fight until the end! */
1944 }
1945 clear_old_treaty(pplayer, aplayer);
1947 adip->asked_about_ceasefire = is_human(aplayer) ? 9 : 0;
1949 _("*%s (AI)* We grow weary of this constant "
1950 "bloodshed. May we suggest a cessation of hostilities?"),
1951 player_name(pplayer));
1952 break;
1953
1954 case DS_ARMISTICE:
1955 break;
1956 default:
1957 fc_assert_msg(FALSE, "Unknown pact type %d.", ds);
1958 break;
1959 }
1960 }
1962}
1963
1964/******************************************************************/
1968bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
1969{
1971 if (dai_diplomacy_get(ait, pplayer, plr)->countdown >= 0) {
1972 return TRUE;
1973 }
1975
1976 return FALSE;
1977}
1978
1979/******************************************************************/
1982/* AI attitude call-backs */
1985 const struct action *paction,
1986 struct player *receiver,
1987 struct player *violator, struct player *victim)
1988{
1989 if (!is_ai(receiver) || violator == receiver) {
1990 return;
1991 }
1992
1993 /* Can only handle victim only and international incidents. */
1996
1997 switch (type) {
1998 case INCIDENT_ACTION:
1999 /* Feel free the change how the action results are grouped and how bad
2000 * the ai considers each group. */
2001 switch (paction->result) {
2002 case ACTRES_SPY_NUKE:
2003 case ACTRES_NUKE:
2004 case ACTRES_NUKE_UNITS:
2005 if (receiver == victim) {
2006 /* Tell the victim */
2008 } else if (violator == victim) {
2010 } else {
2012 }
2013 break;
2016 /* Snoping */
2017 dai_incident_simple(receiver, violator, victim, scope, 2);
2018 break;
2022 case ACTRES_STEAL_MAPS:
2023 /* Theft */
2024 dai_incident_simple(receiver, violator, victim, scope, 5);
2025 break;
2026 case ACTRES_EXPEL_UNIT:
2027 /* Unit position loss */
2028 dai_incident_simple(receiver, violator, victim, scope, 1);
2029 break;
2031 /* Unit weakening */
2032 dai_incident_simple(receiver, violator, victim, scope, 3);
2033 break;
2037 case ACTRES_BOMBARD:
2038 case ACTRES_ATTACK:
2039 case ACTRES_WIPE_UNITS:
2040 case ACTRES_SPY_ATTACK:
2042 /* Unit loss */
2043 dai_incident_simple(receiver, violator, victim, scope, 5);
2044 break;
2048 /* City loss */
2049 dai_incident_simple(receiver, violator, victim, scope, 10);
2050 break;
2056 /* Building loss */
2057 dai_incident_simple(receiver, violator, victim, scope, 5);
2058 break;
2059 case ACTRES_SPY_POISON:
2061 /* Population loss */
2062 dai_incident_simple(receiver, violator, victim, scope, 5);
2063 break;
2064 case ACTRES_FOUND_CITY:
2065 /* Terrain loss */
2066 dai_incident_simple(receiver, violator, victim, scope, 4);
2067 break;
2069 case ACTRES_PILLAGE:
2070 /* Extra loss */
2071 dai_incident_simple(receiver, violator, victim, scope, 2);
2072 break;
2073 case ACTRES_UNIT_MOVE:
2074 case ACTRES_TELEPORT:
2076 case ACTRES_SPY_ESCAPE:
2077 case ACTRES_TRADE_ROUTE:
2078 case ACTRES_MARKETPLACE:
2079 case ACTRES_HELP_WONDER:
2080 case ACTRES_JOIN_CITY:
2083 case ACTRES_HOME_CITY:
2084 case ACTRES_HOMELESS:
2086 case ACTRES_PARADROP:
2087 case ACTRES_PARADROP_CONQUER: /* TODO: Bigger incident */
2088 case ACTRES_AIRLIFT:
2089 case ACTRES_HEAL_UNIT:
2091 case ACTRES_CULTIVATE:
2092 case ACTRES_PLANT:
2093 case ACTRES_CLEAN:
2094 case ACTRES_FORTIFY:
2095 case ACTRES_ROAD:
2096 case ACTRES_CONVERT:
2097 case ACTRES_BASE:
2098 case ACTRES_MINE:
2099 case ACTRES_IRRIGATE:
2106 case ACTRES_HUT_ENTER:
2109 case ACTRES_NONE:
2110 /* Various */
2111 dai_incident_simple(receiver, violator, victim, scope, 1);
2112 break;
2113
2115 }
2116 break;
2117 case INCIDENT_WAR:
2118 if (receiver == victim) {
2120 }
2121 break;
2122 case INCIDENT_LAST:
2123 /* Assert that always fails, but with meaningful message */
2125 break;
2126 }
2127}
2128
2129/******************************************************************/
2132static void dai_incident_nuclear(struct player *receiver,
2133 const struct player *violator,
2134 const struct player *victim)
2135{
2136 fc_assert_ret(receiver == victim);
2137
2138 if (violator == victim) {
2139 return;
2140 }
2141
2142 receiver->ai_common.love[player_index(violator)] -= 3 * MAX_AI_LOVE / 10;
2143}
2144
2145/******************************************************************/
2148static void dai_incident_nuclear_not_target(struct player *receiver,
2149 const struct player *violator,
2150 const struct player *victim)
2151{
2152 fc_assert_ret(receiver != victim);
2153
2154 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2155}
2156
2157/******************************************************************/
2160static void dai_incident_nuclear_self(struct player *receiver,
2161 const struct player *violator,
2162 const struct player *victim)
2163{
2164 fc_assert_ret(receiver != victim);
2166
2167 receiver->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 20;
2168}
2169
2170/**********************************************************************/
2182static void dai_incident_simple(struct player *receiver,
2183 const struct player *violator,
2184 const struct player *victim,
2186 int how_bad)
2187{
2189 if (victim == receiver) {
2191 /* The ruleset finds this bad enough to cause International Outrage.
2192 * Trust the ruleset author. Double the displeasure. */
2194 }
2195 receiver->ai_common.love[player_index(violator)] -= displeasure / 35;
2196 } else if (violator == victim) {
2197 receiver->ai_common.love[player_index(violator)] -= displeasure / 1000;
2198 } else {
2199 receiver->ai_common.love[player_index(violator)] -= displeasure / 500;
2200 }
2201}
2202
2203/******************************************************************/
2211static void dai_incident_war(struct player *violator, struct player *victim)
2212{
2213 players_iterate(pplayer) {
2214 if (!is_ai(pplayer)) {
2215 continue;
2216 }
2217
2218 if (pplayer != violator) {
2219 /* Dislike backstabbing bastards */
2220 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2221 if (player_diplstate_get(violator, victim)->max_state == DS_PEACE) {
2222 /* Extra penalty if they once had a peace treaty */
2223 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 30;
2224 } else if (player_diplstate_get(violator, victim)->max_state
2225 == DS_ALLIANCE) {
2226 /* Extra penalty if they once had an alliance */
2227 pplayer->ai_common.love[player_index(violator)] -= MAX_AI_LOVE / 10;
2228 }
2229 if (victim == pplayer) {
2230 pplayer->ai_common.love[player_index(violator)] =
2231 MIN(pplayer->ai_common.love[player_index(violator)] - MAX_AI_LOVE / 3, -1);
2232 /* Scream for help!! */
2234 if (!pplayers_allied(pplayer, ally)) {
2235 continue;
2236 }
2238 _("*%s (AI)* We have been savagely attacked by "
2239 "%s, and we need your help! Honor our glorious "
2240 "alliance and your name will never be forgotten!"),
2244 }
2245 }
2247}
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:613
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1120
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:1620
const char * city_name_get(const struct city *pcity)
Definition city.c:1141
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1720
#define city_list_iterate(citylist, pcity)
Definition city.h:508
static citizens city_size_get(const struct city *pcity)
Definition city.h:570
#define city_owner(_pcity_)
Definition city.h:564
#define city_list_iterate_end
Definition city.h:510
#define city_built_iterate(_pcity, _p)
Definition city.h:836
#define city_built_iterate_end
Definition city.h:842
char * incite_cost
Definition comments.c:77
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 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:56
#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:238
#define ACTRES_NONE
Definition fc_types.h:188
@ O_SHIELD
Definition fc_types.h:103
@ O_TRADE
Definition fc_types.h:103
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const struct ft_color ftc_chat_private
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
GType type
Definition repodlgs.c:1313
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
@ H_DIPLOMACY
Definition handicaps.h:29
@ H_AWAY
Definition handicaps.h:19
@ H_CEASEFIRE
Definition handicaps.h:33
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool is_small_wonder(const struct impr_type *pimprove)
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_base(level, message,...)
Definition log.h:95
@ LOG_ERROR
Definition log.h:31
@ LOG_DEBUG
Definition log.h:35
#define log_error(message,...)
Definition log.h:104
void lsend_packet_chat_msg(struct conn_list *dest, const struct packet_chat_msg *packet)
void dlsend_packet_diplomacy_remove_clause(struct conn_list *dest, int counterpart, int giver, enum clause_type type, int value)
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:565
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:882
static int map_size_checked(void)
Definition map.h:272
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1698
void vpackage_event(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format, va_list vargs)
Definition notify.c:147
void event_cache_add_for_player(const struct packet_chat_msg *packet, const struct player *pplayer)
Definition notify.c:645
struct city_list * cities
Definition packhand.c:120
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1468
int player_slot_count(void)
Definition player.c:415
int player_number(const struct player *pplayer)
Definition player.c:826
const char * player_name(const struct player *pplayer)
Definition player.c:885
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1376
int player_index(const struct player *pplayer)
Definition player.c:818
int player_in_territory(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1867
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:103
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:325
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1397
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1451
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:213
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1477
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1418
#define players_iterate_end
Definition player.h:552
@ DIPL_SENATE_BLOCKING
Definition player.h:193
@ DIPL_OK
Definition player.h:193
#define players_iterate(_pplayer)
Definition player.h:547
#define MAX_AI_LOVE
Definition player.h:576
static bool is_barbarian(const struct player *pplayer)
Definition player.h:499
#define is_ai(plr)
Definition player.h:232
#define players_iterate_alive_end
Definition player.h:562
#define is_human(plr)
Definition player.h:231
#define players_iterate_alive(_pplayer)
Definition player.h:557
#define fc_rand(_size)
Definition rand.h:56
bool research_goal_tech_req(const struct research *presearch, Tech_type_id goal, Tech_type_id tech)
Definition research.c:810
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1062
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:775
struct research * research_get(const struct player *pplayer)
Definition research.c:130
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:622
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:696
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
@ SSHIP_STARTED
Definition spaceship.h:84
@ SSHIP_LAUNCHED
Definition spaceship.h:85
@ SSHIP_NONE
Definition spaceship.h:84
enum clause_type type
Definition diptreaty.h:76
struct player * from
Definition diptreaty.h:77
int value
Definition diptreaty.h:78
struct adv_data::@95 dipl
struct player * spacerace_leader
Definition advdata.h:104
enum war_reason war_reason
Definition daidata.h:62
int distance
Definition daidata.h:60
int countdown
Definition daidata.h:61
struct ai_plr::@280 diplomacy
adv_want tech_want[A_LAST+1]
Definition daidata.h:104
int req_love_for_alliance
Definition daidata.h:96
char love_incr
Definition daidata.h:94
char love_coeff
Definition daidata.h:93
struct player * war_target
Definition daidata.h:97
int req_love_for_peace
Definition daidata.h:95
enum winning_strategy strategy
Definition daidata.h:91
Definition ai.h:50
Definition city.h:318
int diplgoldcost
Definition game.h:147
struct packet_game_info info
Definition game.h:89
struct civ_game::@32::@36 server
struct government * government_during_revolution
Definition game.h:94
Government_type_id government_during_revolution_id
enum tech_upkeep_style tech_upkeep_style
enum tech_leakage_style tech_leakage
bool tech_trade_allow_holes
enum tech_cost_style tech_cost_style
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:124
int first_contact_turn
Definition player.h:201
enum diplstate_type type
Definition player.h:199
char has_reason_to_cancel
Definition player.h:203
struct city_list * cities
Definition player.h:281
int bulbs_last_turn
Definition player.h:351
struct player_ai ai_common
Definition player.h:288
struct government * government
Definition player.h:258
struct team * team
Definition player.h:261
const struct ai_type * ai
Definition player.h:289
struct unit_list * units
Definition player.h:282
struct conn_list * connections
Definition player.h:298
bool is_alive
Definition player.h:268
struct player::@73::@75 server
struct player_economic economic
Definition player.h:284
struct player_spaceship spaceship
Definition player.h:286
Tech_type_id researching
Definition research.h:52
Tech_type_id tech_goal
Definition research.h:83
int techs_researched
Definition research.h:42
int bulbs_researched
Definition research.h:53
struct clause_list * clauses
Definition diptreaty.h:84
struct player * plr0
Definition diptreaty.h:82
struct unit_type::@90 adv
const struct unit_type * utype
Definition unit.h:141
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:110
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:314
#define advance_index_iterate_max(_start, _index, _max)
Definition tech.h:250
#define advance_index_iterate_end
Definition tech.h:246
#define advance_index_iterate_max_end
Definition tech.h:256
static Tech_type_id advance_count(void)
Definition tech.h:167
#define A_FIRST
Definition tech.h:44
#define A_NONE
Definition tech.h:43
#define advance_index_iterate(_start, _index)
Definition tech.h:242
#define TRAIT_MAX_VALUE_SR
Definition traits.h:34
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2722
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
bool utype_is_cityfounder(const struct unit_type *utype)
Definition unittype.c:2997