Freeciv-3.2
Loading...
Searching...
No Matches
aidiplomat.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2002 - The Freeciv Project
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/* utility */
19#include "bitvector.h"
20#include "log.h"
21#include "mem.h"
22#include "shared.h"
23#include "timing.h"
24
25/* common */
26#include "actions.h"
27#include "city.h"
28#include "combat.h"
29#include "game.h"
30#include "government.h"
31#include "map.h"
32#include "movement.h"
33#include "nation.h"
34#include "packets.h"
35#include "player.h"
36#include "research.h"
37#include "unit.h"
38#include "unitlist.h"
39
40/* aicore */
41#include "aiactions.h"
42#include "pf_tools.h"
43
44/* server */
45#include "barbarian.h"
46#include "citytools.h"
47#include "cityturn.h"
48#include "diplomats.h"
49#include "maphand.h"
50#include "srv_log.h"
51#include "unithand.h"
52#include "unittools.h"
53
54/* server/advisors */
55#include "advbuilding.h"
56#include "advdata.h"
57#include "advgoto.h"
58#include "autosettlers.h"
59
60/* ai */
61#include "handicaps.h"
62
63/* ai/default */
64#include "aiguard.h"
65#include "aihand.h"
66#include "aitools.h"
67#include "daiactions.h"
68#include "daicity.h"
69#include "daidata.h"
70#include "dailog.h"
71#include "daimilitary.h"
72#include "daiplayer.h"
73
74#include "aidiplomat.h"
75
76
77#define LOG_DIPLOMAT LOG_DEBUG
78#define LOG_DIPLOMAT_BUILD LOG_DEBUG
79
80/* 3000 is a just a large number, but not hillariously large as the
81 * previously used one. This is important for diplomacy. - Per */
82#define DIPLO_DEFENSE_WANT 3000
83
84static bool is_city_surrounded_by_our_spies(struct player *pplayer,
85 struct city *pcity);
86
87static void find_city_to_diplomat(struct player *pplayer, struct unit *punit,
88 struct city **ctarget, int *move_dist,
89 struct pf_map *pfm);
90
91/**************************************************************************/
94static int count_stealable_techs(struct player *pplayer, struct player *tplayer)
95{
96 struct research *presearch = research_get(pplayer);
97 struct research *tresearch = research_get(tplayer);
98 int count = 0;
99
101 if (research_invention_state(presearch, idx) != TECH_KNOWN
102 && research_invention_state(tresearch, idx) == TECH_KNOWN) {
103 count++;
104 }
106
107 return count;
108}
109
110/**************************************************************************/
116 struct player *pplayer,
117 struct city *pcity,
118 struct adv_choice *choice, int def)
119{
120 /* Build a diplomat if our city is threatened by enemy diplomats, and
121 we have other defensive troops, and we don't already have a diplomat
122 to protect us. If we see an enemy diplomat and we don't have diplomat
123 tech... race it! */
124 struct ai_city *city_data = def_ai_city_data(pcity, ait);
125
126 if (def != 0 && city_data->diplomat_threat
127 && !city_data->has_diplomat) {
128 struct unit_type *ut = best_role_unit(pcity, UTYF_DIPLOMAT);
129
130 if (ut) {
132 "A defensive diplomat will be built in city %s.",
133 city_name_get(pcity));
134 choice->want = 16000; /* diplomat more important than soldiers */
135 city_data->urgency = 1;
136 choice->type = CT_DEFENDER;
137 choice->value.utype = ut;
138 choice->need_boat = FALSE;
139 adv_choice_set_use(choice, "defensive diplomat");
140 } else if (num_role_units(UTYF_DIPLOMAT) > 0) {
141 /* We don't know diplomats yet... */
143 "A defensive diplomat is wanted badly in city %s.",
144 city_name_get(pcity));
145 ut = get_role_unit(UTYF_DIPLOMAT, 0);
146 if (ut) {
147 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
148
149 unit_tech_reqs_iterate(ut, padv) {
150 plr_data->tech_want[advance_index(padv)]
152 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
153 "ai_choose_diplomat_defensive() + %d for %s",
155 utype_rule_name(ut));
157 }
158 }
159 }
160}
161
162/**************************************************************************/
167 struct player *pplayer,
168 struct city *pcity,
169 struct adv_choice *choice)
170{
171 struct unit_type *ut = best_role_unit(pcity, UTYF_DIPLOMAT);
172 struct ai_plr *ai = def_ai_player_data(pplayer, ait);
173 int expenses;
174 const struct civ_map *nmap = &(wld.map);
175
176 dai_calc_data(pplayer, NULL, &expenses, NULL);
177
178 if (!ut) {
179 /* We don't know diplomats yet! */
180 return;
181 }
182
183 if (has_handicap(pplayer, H_DIPLOMAT)) {
184 /* Diplomats are too tough on newbies */
185 return;
186 }
187
188 /* Do we have a good reason for building diplomats? */
189 {
190 const struct research *presearch = research_get(pplayer);
191 struct pf_map *pfm;
192 struct pf_parameter parameter;
193 struct city *acity;
194 adv_want want;
195 int loss, p_success, p_failure, time_to_dest;
196 int gain_incite = 0, gain_theft = 0, gain = 1;
197 int incite_cost;
199 pplayer, pcity, ut,
201
202 pft_fill_unit_parameter(&parameter, nmap, punit);
203 parameter.omniscience = !has_handicap(pplayer, H_MAP);
204 pfm = pf_map_new(&parameter);
205
206 find_city_to_diplomat(pplayer, punit, &acity, &time_to_dest, pfm);
207
208 pf_map_destroy(pfm);
210
211 if (acity == NULL
212 || BV_ISSET(ai->stats.diplomat_reservations, acity->id)) {
213 /* Found no target or city already considered */
214 return;
215 }
216 incite_cost = city_incite_cost(pplayer, acity);
217 if (POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, city_owner(acity))
218 && (is_action_possible_on_city(ACTION_SPY_INCITE_CITY,
219 pplayer, acity)
220 || is_action_possible_on_city(ACTION_SPY_INCITE_CITY_ESC,
221 pplayer, acity))
223 && (incite_cost < pplayer->economic.gold - expenses)) {
224 /* incite gain (FIXME: we should count wonders too but need to
225 cache that somehow to avoid CPU hog -- Per) */
228 + (acity->prod[O_LUXURY]
229 + acity->prod[O_GOLD]
230 + acity->prod[O_SCIENCE]) * TRADE_WEIGHTING;
231 gain_incite *= SHIELD_WEIGHTING; /* WAG cost to take city otherwise */
233 }
234 if ((research_get(city_owner(acity))->techs_researched
237 pplayer, acity)
239 pplayer, acity)
241 pplayer, acity)
243 pplayer, acity))
244 && !pplayers_allied(pplayer, city_owner(acity))) {
245 /* tech theft gain */
246 /* FIXME: this value is right only when
247 * 'game.info.game.info.tech_cost_style' is set to
248 * TECH_COST_CIV1CIV2. */
249 gain_theft =
252 }
255
256 /* Probability to succeed, assuming no defending diplomat */
258 /* Probability to lose our unit */
261 100 - p_success :
262 100);
263
264 /* Get the time to dest in turns (minimum 1 turn) */
265 time_to_dest = (time_to_dest + ut->move_rate - 1) / ut->move_rate;
266 /* Discourage long treks */
267 time_to_dest *= ((time_to_dest + 1) / 2);
268
269 /* Almost kill_desire() */
270 want = (adv_want)(p_success * gain - p_failure * loss) / 100
272 if (want <= 0) {
273 return;
274 }
275
276 want = military_amortize(pplayer, pcity, want, time_to_dest,
278
279 if (!player_has_embassy(pplayer, city_owner(acity))
280 && want < 99
282 pplayer, acity)
284 pplayer, acity))) {
286 "A diplomat desired in %s to establish an embassy with %s "
287 "in %s",
288 city_name_get(pcity),
291 want = 99;
292 }
293 if (want > choice->want) {
295 "%s, %s: %s is desired with want " ADV_WANT_PRINTF
296 " to spy in %s (incite want %d cost %d gold %d, "
297 "tech theft want %d, ttd %d)",
298 player_name(pplayer),
299 city_name_get(pcity),
301 want,
305 pplayer->economic.gold - expenses,
308 choice->want = want;
309 choice->type = CT_CIVILIAN; /* so we don't build barracks for it */
310 choice->value.utype = ut;
311 choice->need_boat = FALSE;
312 adv_choice_set_use(choice, "offensive diplomat");
314 }
315 }
316}
317
318/**************************************************************************/
327static void dai_diplomat_city(struct ai_type *ait, struct unit *punit,
328 struct city *ctarget)
329{
330 struct action *chosen_action;
333 struct player *pplayer = unit_owner(punit);
334 struct player *tplayer = city_owner(ctarget);
335 int count_tech = count_stealable_techs(pplayer, tplayer);
336
337 fc_assert_ret(is_ai(pplayer));
338
339 if (punit->moves_left == 0) {
340 UNIT_LOG(LOG_ERROR, punit, "no moves left in ai_diplomat_city()!");
341 }
342
344
345 /* Select the best potentially legal action. */
346 /* FIXME: what if it is illegal? */
350 action_iterate(act_id) {
351 struct action *paction = action_by_number(act_id);
353 int sub_tgt_id;
354
357 /* Not relevant here. */
358 continue;
359 }
360
363 /* Not possible. */
364 continue;
365 }
366
367 if (paction->target_complexity == ACT_TGT_COMPL_SIMPLE) {
368 /* No sub target */
369 sub_tgt_id = 0;
370 } else {
371 /* Pick a suitable sub target. */
373 punit, ctarget);
374 }
375
377 ctarget, sub_tgt_id,
378 count_tech);
379
383 chosen_sub_tgt_id = sub_tgt_id;
384 }
386
387 if (chosen_action != NULL) {
388 /* An action has been selected. */
389
392 ctarget))) {
393 log_base(LOG_DIPLOMAT, "%s %s[%d] does %s at %s",
398 unit_do_action(pplayer, punit->id,
399 ctarget->id, chosen_sub_tgt_id, "",
401 return;
402 }
403 }
404
405 /* This can happen for a number of odd and esoteric reasons */
407 "decides to stand idle outside enemy city %s!",
410}
411
412/**************************************************************************/
416static bool is_city_surrounded_by_our_spies(struct player *pplayer,
417 struct city *enemy_city)
418{
420 if (has_handicap(pplayer, H_FOG)
421 && !map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
422 /* We cannot see danger at (ptile) => assume there is none. */
423 continue;
424 }
425 unit_list_iterate(ptile->units, punit) {
426 if (unit_owner(punit) == pplayer
428 return TRUE;
429 }
432
433 return FALSE;
434}
435
436/**************************************************************************/
440static void find_city_to_diplomat(struct player *pplayer, struct unit *punit,
441 struct city **ctarget, int *move_dist,
442 struct pf_map *pfm)
443{
444 bool has_embassy;
445 int incite_cost = 0; /* incite cost */
446 int expenses;
447 bool dipldef; /* whether target is protected by diplomats */
448
450 *ctarget = NULL;
451 *move_dist = -1;
452 dai_calc_data(pplayer, NULL, &expenses, NULL);
453
454 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
455 struct city *acity;
456 struct player *aplayer;
457 bool can_incite;
458 bool can_steal;
459
460 acity = tile_city(ptile);
461
462 if (!acity) {
463 continue;
464 }
466
468
469 if (aplayer == pplayer || is_barbarian(aplayer)
470 || (pplayers_allied(pplayer, aplayer) && has_embassy)) {
471 continue;
472 }
473
477 pplayer, acity)
479 pplayer, acity));
480
482 pplayer, acity)
484 pplayer, acity)
486 pplayer, acity)
488 pplayer, acity);
489
491 /* Three actions to consider:
492 * 1. establishing embassy OR
493 * 2. stealing techs OR
494 * 3. inciting revolt */
495 if ((!has_embassy
497 pplayer, acity)
499 pplayer, acity)))
501 && !dipldef && can_steal
502 && (research_get(pplayer)->techs_researched
504 || (incite_cost < (pplayer->economic.gold - expenses)
505 && can_incite && !dipldef)) {
506 if (!is_city_surrounded_by_our_spies(pplayer, acity)) {
507 /* We have the closest enemy city on the continent */
508 *ctarget = acity;
509 *move_dist = move_cost;
510 break;
511 }
512 }
514}
515
516/**************************************************************************/
519static struct city *dai_diplomat_defend(struct ai_type *ait,
520 struct player *pplayer,
521 struct unit *punit,
522 const struct unit_type *utype,
523 struct pf_map *pfm)
524{
525 int best_dist = 30; /* any city closer than this is better than none */
526 int best_urgency = 0;
527 struct city *ctarget = NULL;
528 struct city *pcity = tile_city(unit_tile(punit));
529
530 if (pcity
531 && count_diplomats_on_tile(pcity->tile) == 1
532 && def_ai_city_data(pcity, ait)->urgency > 0) {
533 /* Danger and we are only diplomat present - stay. */
534 return pcity;
535 }
536
537 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
538 struct city *acity;
539 struct player *aplayer;
540 int dipls, urgency;
541 struct ai_city *city_data;
542
543 acity = tile_city(ptile);
544 if (!acity) {
545 continue;
546 }
548 if (aplayer != pplayer) {
549 continue;
550 }
551
553 urgency = city_data->urgency;
555 - (same_pos(ptile, unit_tile(punit)) ? 1 : 0));
556 if (dipls == 0 && city_data->diplomat_threat) {
557 /* We are _really_ needed there */
558 urgency = (urgency + 1) * 5;
559 } else if (dipls > 0) {
560 /* We are probably not needed there... */
561 urgency /= 3;
562 }
563
564 /* This formula may not be optimal, but it works. */
565 if (move_cost > best_dist) {
566 /* punish city for being so far away */
567 urgency /= (float) (move_cost / best_dist);
568 }
569
570 if (urgency > best_urgency) {
571 /* Found something worthy of our presence */
572 ctarget = acity;
574 /* squelch divide-by-zero */
575 best_dist = MAX(move_cost, 1);
576 }
578
579 return ctarget;
580}
581
582/**************************************************************************/
587static bool dai_diplomat_bribe_nearby(struct ai_type *ait,
588 struct player *pplayer,
589 struct unit *punit, struct pf_map *pfm)
590{
591 int gold_avail, expenses;
592 const struct civ_map *nmap = &(wld.map);
593
594 dai_calc_data(pplayer, NULL, &expenses, NULL);
595 gold_avail = pplayer->economic.gold - expenses;
596
598 struct tile *ptile = pos.tile;
599 bool threat = FALSE;
600 int newval, bestval = 0, cost;
601 struct unit *pvictim = tile_other_players_unit(ptile, pplayer);
602 int sanity = punit->id;
603 const struct unit_type *ptype;
604
605 if (pos.total_MC > punit->moves_left) {
606 /* Didn't find anything within range. */
607 break;
608 }
609
610 if (!pvictim
612 || unit_list_size(ptile->units) > 1
613 || tile_city(ptile)
615 punit, pvictim)) {
616 continue;
617 }
618
619 /* Calculate if enemy is a threat */
620 /* First find best defender on our tile */
621 unit_list_iterate(ptile->units, aunit) {
622 const struct unit_type *atype = unit_type_get(aunit);
623
625 if (bestval < newval) {
626 bestval = newval;
627 }
629 /* Compare with victim's attack power */
632 if (newval > bestval
633 && unit_move_rate(pvictim) > pos.total_MC) {
634 /* Enemy can probably kill us */
635 threat = TRUE;
636 } else {
637 /* Enemy cannot reach us or probably not kill us */
638 threat = FALSE;
639 }
640
641 if (has_handicap(pplayer, H_NOBRIBE_WF)) {
642 /* Don't bribe workers or city founders! */
645 continue;
646 }
647 }
648
649 /* Should we make the expense? */
650 cost = unit_bribe_cost(pvictim, pplayer);
651 if (!threat) {
652 /* Don't empty our treasure without good reason! */
653 gold_avail = pplayer->economic.gold - dai_gold_reserve(pplayer);
654 }
655 if (cost > gold_avail) {
656 /* Can't afford */
657 continue;
658 }
659
660 /* Found someone! */
661 {
662 struct tile *bribee_tile;
663 struct pf_path *path;
664
665 bribee_tile = mapstep(nmap, pos.tile, DIR_REVERSE(pos.dir_to_here));
666 path = pf_map_path(pfm, bribee_tile);
667 if (!path || !adv_unit_execute_path(punit, path)
668 || punit->moves_left <= 0) {
669 pf_path_destroy(path);
670 return FALSE;
671 }
672 pf_path_destroy(path);
673 }
674
677 pvictim))) {
678 unit_do_action(pplayer, punit->id,
679 pvictim->id, -1, "",
681 /* autoattack might kill us as we move in */
683 return TRUE;
684 } else {
685 return FALSE;
686 }
689 pvictim))
690 && threat) {
691 /* don't stand around waiting for the final blow */
692 unit_do_action(pplayer, punit->id,
693 pvictim->id, -1, "",
695 /* autoattack might kill us as we move in */
697 return TRUE;
698 } else {
699 return FALSE;
700 }
701 } else {
702 /* usually because we ended move early due to another unit */
703 UNIT_LOG(LOG_DIPLOMAT, punit, "could not bribe target (%d, %d), "
704 " %d moves left", TILE_XY(pos.tile), punit->moves_left);
705 return FALSE;
706 }
708
709 return (punit->moves_left > 0);
710}
711
712/**************************************************************************/
722void dai_manage_diplomat(struct ai_type *ait, struct player *pplayer,
723 struct unit *punit)
724{
725 struct city *pcity, *ctarget = NULL;
726 struct pf_parameter parameter;
727 struct pf_map *pfm;
728 struct pf_position pos;
729 struct unit_ai *unit_data;
730 const struct civ_map *nmap = &(wld.map);
731
733
734 /* Generate map */
735 pft_fill_unit_parameter(&parameter, nmap, punit);
736 parameter.omniscience = !has_handicap(pplayer, H_MAP);
737 parameter.get_zoc = NULL; /* Kludge */
738 parameter.get_TB = no_intermediate_fights;
739 pfm = pf_map_new(&parameter);
740
741 /* Look for someone to bribe */
742 if (!dai_diplomat_bribe_nearby(ait, pplayer, punit, pfm)) {
743 /* Died or ran out of moves */
745 return;
746 }
747
748 /* If we are the only diplomat in a threatened city, then stay to defend */
749 pcity = tile_city(unit_tile(punit)); /* we may have moved */
750 if (pcity) {
751 struct ai_city *city_data = def_ai_city_data(pcity, ait);
752
754 && (city_data->diplomat_threat
755 || city_data->urgency > 0)) {
756 UNIT_LOG(LOG_DIPLOMAT, punit, "stays to protect %s (urg %d)",
757 city_name_get(pcity), city_data->urgency);
758 dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL); /* abort mission */
761 return;
762 }
763 }
764
766
767 /* Check if existing target still makes sense */
768 if (unit_data->task == AIUNIT_ATTACK
769 || unit_data->task == AIUNIT_DEFEND_HOME) {
770 bool failure = FALSE;
771
774 && ctarget) {
775 if (same_pos(ctarget->tile, unit_tile(punit))) {
776 failure = TRUE;
777 } else if (pplayers_allied(pplayer, city_owner(ctarget))
778 && unit_data->task == AIUNIT_ATTACK
779 && player_has_embassy(pplayer, city_owner(ctarget))) {
780 /* We probably incited this city with another diplomat */
781 failure = TRUE;
782 } else if (!pplayers_allied(pplayer, city_owner(ctarget))
783 && unit_data->task == AIUNIT_DEFEND_HOME) {
784 /* We probably lost the city */
785 failure = TRUE;
786 }
787 } else {
788 /* City vanished! */
789 failure = TRUE;
790 }
791 if (failure) {
792 UNIT_LOG(LOG_DIPLOMAT, punit, "mission aborted");
794 }
795 }
796
797 /* We may need a new map now. Both because we cannot get paths from an
798 * old map, and we need paths to move, and because fctd below requires
799 * a new map for its iterator. */
800 if (!same_pos(parameter.start_tile, unit_tile(punit))
801 || unit_data->task == AIUNIT_NONE) {
803 pft_fill_unit_parameter(&parameter, nmap, punit);
804 parameter.omniscience = !has_handicap(pplayer, H_MAP);
805 parameter.get_zoc = NULL; /* Kludge */
806 parameter.get_TB = no_intermediate_fights;
807 pfm = pf_map_new(&parameter);
808 }
809
810 /* If we are not busy, acquire a target. */
811 if (unit_data->task == AIUNIT_NONE) {
812 enum ai_unit_task task;
813 int move_dist; /* dummy */
814
816
817 if (ctarget) {
818 task = AIUNIT_ATTACK;
820 UNIT_LOG(LOG_DIPLOMAT, punit, "going on attack");
821 } else if ((ctarget = dai_diplomat_defend(ait, pplayer, punit,
823 != NULL) {
824 task = AIUNIT_DEFEND_HOME;
825 UNIT_LOG(LOG_DIPLOMAT, punit, "going to defend %s",
827 } else if ((ctarget = find_closest_city(unit_tile(punit), NULL, pplayer,
829 NULL))
830 != NULL) {
831 /* This should only happen if the entire continent was suddenly
832 * conquered. So we head for closest coastal city and wait for someone
833 * to code ferrying for diplomats, or hostile attacks from the sea. */
834 task = AIUNIT_DEFEND_HOME;
835 UNIT_LOG(LOG_DIPLOMAT, punit, "going idle");
836 } else {
837 UNIT_LOG(LOG_DIPLOMAT, punit, "could not find a job");
840 return;
841 }
842
843 dai_unit_new_task(ait, punit, task, ctarget->tile);
845 && unit_data->task != AIUNIT_NONE);
846 }
847
849 if (ctarget == NULL) {
850 UNIT_LOG(LOG_ERROR, punit, "ctarget not set (task == %d)",
851 unit_data->task);
853 return;
854 }
855
856 /* GOTO unless we want to stay */
857 if (!same_pos(unit_tile(punit), ctarget->tile)) {
858 struct pf_path *path;
859
860 path = pf_map_path(pfm, punit->goto_tile);
861 if (path && adv_unit_execute_path(punit, path) && punit->moves_left > 0) {
862 /* Check if we can do something with our destination now. */
863 if (unit_data->task == AIUNIT_ATTACK) {
865
866 UNIT_LOG(LOG_DIPLOMAT, punit, "attack, dist %d to %s",
867 dist, ctarget ? city_name_get(ctarget) : "(none)");
868 if (dist <= 1) {
869 /* Do our stuff */
872 }
873 }
874 }
875 pf_path_destroy(path);
876 } else {
878 }
880}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:6216
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1850
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5823
struct act_prob action_prob_vs_city(const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Definition actions.c:4981
struct act_prob action_prob_vs_unit(const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Definition actions.c:5065
const char * action_rule_name(const struct action *action)
Definition actions.c:1968
int action_number(const struct action *action)
Definition actions.c:1960
bool is_action_enabled_unit_on_unit(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Definition actions.c:3909
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1860
static struct action * action_by_number(action_id act_id)
Definition actions.h:633
#define action_iterate_end
Definition actions.h:463
#define action_iterate(_act_)
Definition actions.h:459
#define TRADE_WEIGHTING
Definition advbuilding.h:21
#define FOOD_WEIGHTING
Definition advbuilding.h:19
#define SHIELD_WEIGHTING
Definition advbuilding.h:20
#define adv_choice_set_use(_choice, _use)
Definition advchoice.h:85
@ CT_CIVILIAN
Definition advchoice.h:39
@ CT_DEFENDER
Definition advchoice.h:41
bool adv_unit_execute_path(struct unit *punit, struct pf_path *path)
Definition advgoto.c:82
bool aia_utype_is_considered_spy(const struct unit_type *putype)
Definition aiactions.c:51
bool aia_utype_is_considered_worker(const struct unit_type *putype)
Definition aiactions.c:89
static struct city * dai_diplomat_defend(struct ai_type *ait, struct player *pplayer, struct unit *punit, const struct unit_type *utype, struct pf_map *pfm)
Definition aidiplomat.c:519
void dai_choose_diplomat_defensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, int def)
Definition aidiplomat.c:115
void dai_manage_diplomat(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition aidiplomat.c:722
#define LOG_DIPLOMAT_BUILD
Definition aidiplomat.c:78
static void dai_diplomat_city(struct ai_type *ait, struct unit *punit, struct city *ctarget)
Definition aidiplomat.c:327
void dai_choose_diplomat_offensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice)
Definition aidiplomat.c:166
#define LOG_DIPLOMAT
Definition aidiplomat.c:77
#define DIPLO_DEFENSE_WANT
Definition aidiplomat.c:82
static bool dai_diplomat_bribe_nearby(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct pf_map *pfm)
Definition aidiplomat.c:587
static int count_stealable_techs(struct player *pplayer, struct player *tplayer)
Definition aidiplomat.c:94
static void find_city_to_diplomat(struct player *pplayer, struct unit *punit, struct city **ctarget, int *move_dist, struct pf_map *pfm)
Definition aidiplomat.c:440
static bool is_city_surrounded_by_our_spies(struct player *pplayer, struct city *pcity)
Definition aidiplomat.c:416
void aiguard_request_guard(struct ai_type *ait, struct unit *punit)
Definition aiguard.c:227
void dai_calc_data(const struct player *pplayer, int *trade, int *expenses, int *income)
Definition aihand.c:117
void dai_unit_new_task(struct ai_type *ait, struct unit *punit, enum ai_unit_task task, struct tile *ptile)
Definition aitools.c:642
int dai_gold_reserve(struct player *pplayer)
Definition aitools.c:1325
adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
Definition aitools.c:118
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:803
#define city_tile(_pcity_)
Definition city.h:564
#define INCITE_IMPOSSIBLE_COST
Definition city.h:96
#define city_owner(_pcity_)
Definition city.h:563
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Definition citytools.c:851
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3424
char * incite_cost
Definition comments.c:74
int dai_action_choose_sub_tgt_unit_vs_city(struct action *paction, struct unit *actor_unit, struct city *target_city)
Definition daiactions.c:310
adv_want dai_action_value_unit_vs_city(struct action *paction, struct unit *actor_unit, struct city *target_city, int sub_tgt_id, int count_tech)
Definition daiactions.c:96
#define TECH_LOG(ait, loglevel, pplayer, padvance, msg,...)
Definition dailog.h:36
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition daiplayer.h:42
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition daiplayer.h:48
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
Definition daiunit.h:72
ai_unit_task
Definition daiunit.h:27
@ AIUNIT_NONE
Definition daiunit.h:27
@ AIUNIT_ATTACK
Definition daiunit.h:28
@ AIUNIT_DEFEND_HOME
Definition daiunit.h:28
#define DEFENSE_POWER(ptype)
Definition daiunit.h:66
#define ATTACK_POWER(ptype)
Definition daiunit.h:68
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
int diplomats_unignored_tech_stealings(struct unit *pdiplomat, struct city *pcity)
Definition diplomats.c:850
int count_diplomats_on_tile(struct tile *ptile)
Definition diplomats.c:2374
float adv_want
Definition fc_types.h:1355
#define ADV_WANT_PRINTF
Definition fc_types.h:1356
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:116
static struct tile * pos
Definition finddlg.c:53
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
@ H_MAP
Definition handicaps.h:28
@ H_DIPLOMAT
Definition handicaps.h:18
@ H_NOBRIBE_WF
Definition handicaps.h:34
@ H_FOG
Definition handicaps.h:26
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
#define log_base(level, message,...)
Definition log.h:94
@ LOG_ERROR
Definition log.h:30
@ LOG_DEBUG
Definition log.h:34
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:940
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:630
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:371
#define adjc_iterate_end
Definition map.h:433
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:428
#define DIR_REVERSE(dir)
Definition map.h:561
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:920
int unit_move_rate(const struct unit *punit)
Definition movement.c:90
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
void pf_path_destroy(struct pf_path *path)
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
struct pf_path * pf_map_path(struct pf_map *pfm, struct tile *ptile)
bool pf_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
void pf_map_destroy(struct pf_map *pfm)
#define pf_map_move_costs_iterate_end
#define pf_map_positions_iterate_end
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
#define pf_map_positions_iterate(ARG_pfm, NAME_pos, COND_from_start)
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:840
enum tile_behavior no_intermediate_fights(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:524
const char * player_name(const struct player *pplayer)
Definition player.c:895
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:208
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
#define is_ai(plr)
Definition player.h:230
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Definition research.c:868
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
#define MAX(x, y)
Definition shared.h:54
#define UNIT_LOG(loglevel, punit, msg,...)
Definition srv_log.h:98
enum choice_type type
Definition advchoice.h:46
adv_want want
Definition advchoice.h:48
universals_u value
Definition advchoice.h:47
bool need_boat
Definition advchoice.h:49
bool has_diplomat
Definition daicity.h:59
unsigned int urgency
Definition daicity.h:49
bool diplomat_threat
Definition daicity.h:58
struct ai_plr::@251 stats
adv_want tech_want[A_LAST+1]
Definition daidata.h:103
bv_id diplomat_reservations
Definition daidata.h:85
Definition ai.h:50
Definition city.h:320
int id
Definition city.h:326
struct tile * tile
Definition city.h:322
int diplchance
Definition game.h:138
struct civ_game::@31::@35 server
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
bool(* get_zoc)(const struct player *pplayer, const struct tile *ptile, const struct civ_map *zmap)
struct tile * start_tile
struct player_economic economic
Definition player.h:282
int techs_researched
Definition research.h:42
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
bool done
Definition daiunit.h:44
Definition unit.h:138
int moves_left
Definition unit.h:150
int id
Definition unit.h:145
struct tile * tile
Definition unit.h:140
struct tile * goto_tile
Definition unit.h:155
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
#define advance_index_iterate_end
Definition tech.h:248
#define A_FIRST
Definition tech.h:44
#define advance_index_iterate(_start, _index)
Definition tech.h:244
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define TILE_XY(ptile)
Definition tile.h:43
const struct unit_type * utype
Definition fc_types.h:724
int unit_bribe_cost(struct unit *punit, struct player *briber)
Definition unit.c:2300
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:371
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1620
struct unit * tile_other_players_unit(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1320
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1725
#define unit_tile(_pu)
Definition unit.h:390
#define CHECK_UNIT(punit)
Definition unit.h:270
#define unit_owner(_pu)
Definition unit.h:389
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Definition unithand.c:6468
void unit_do_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id, const char *name, const action_id action_type)
Definition unithand.c:3291
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
struct unit_type * best_role_unit(const struct city *pcity, int role)
Definition unittype.c:2271
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2253
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1587
int num_role_units(int role)
Definition unittype.c:2203
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1438
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
#define unit_tech_reqs_iterate_end
Definition unittype.h:878
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:872