Freeciv-3.3: /fast/freeciv/nightly/main/ai/default/daidiplomacy.c Source File

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