Freeciv-3.4
Loading...
Searching...
No Matches
daidiplomat.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
59/* ai */
60#include "handicaps.h"
61
62/* ai/default */
63#include "daiactions.h"
64#include "daicity.h"
65#include "daidata.h"
66#include "daiguard.h"
67#include "daihand.h"
68#include "dailog.h"
69#include "daimilitary.h"
70#include "daiplayer.h"
71#include "daitools.h"
72#include "daiunit.h"
73
74#include "daidiplomat.h"
75
76
77#define LOG_DIPLOMAT LOG_DEBUG
78#define LOG_DIPLOMAT_BUILD LOG_DEBUG
79
80/* 3000 is just a large number, but not hilariously 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_diplomats_on_tile(struct tile *ptile)
95{
96 int count = 0;
97
98 unit_list_iterate((ptile)->units, punit) {
100 count++;
101 }
103
104 return count;
105}
106
107/**************************************************************************/
110static int count_stealable_techs(struct player *pplayer, struct player *tplayer)
111{
112 struct research *presearch = research_get(pplayer);
113 struct research *tresearch = research_get(tplayer);
114 int count = 0;
115
119 count++;
120 }
122
123 return count;
124}
125
126/**************************************************************************/
132 struct player *pplayer,
133 struct city *pcity,
134 struct adv_choice *choice, int def)
135{
136 /* Build a diplomat if our city is threatened by enemy diplomats, and
137 we have other defensive troops, and we don't already have a diplomat
138 to protect us. If we see an enemy diplomat and we don't have diplomat
139 tech... race it! */
140 struct ai_city *city_data = def_ai_city_data(pcity, ait);
141
142 if (def != 0 && city_data->diplomat_threat
143 && !city_data->has_diplomat) {
145
146 if (ut) {
148 "A defensive diplomat will be built in city %s.",
150 choice->want = 16000; /* diplomat more important than soldiers */
151 city_data->urgency = 1;
152 choice->type = CT_DEFENDER;
153 choice->value.utype = ut;
154 choice->need_boat = FALSE;
155 adv_choice_set_use(choice, "defensive diplomat");
156 } else if (num_role_units(UTYF_DIPLOMAT) > 0) {
157 /* We don't know diplomats yet... */
159 "A defensive diplomat is wanted badly in city %s.",
162 if (ut) {
163 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
164
166 plr_data->tech_want[advance_index(padv)]
168 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
169 "ai_choose_diplomat_defensive() + %d for %s",
173 }
174 }
175 }
176}
177
178/**************************************************************************/
183 const struct civ_map *nmap,
184 struct player *pplayer,
185 struct city *pcity,
186 struct adv_choice *choice)
187{
189 struct ai_plr *ai = def_ai_player_data(pplayer, ait);
190 int expenses;
191
192 dai_calc_data(pplayer, nullptr, &expenses, nullptr);
193
194 if (!ut) {
195 /* We don't know diplomats yet! */
196 return;
197 }
198
199 if (has_handicap(pplayer, H_DIPLOMAT)) {
200 /* Diplomats are too tough on newbies */
201 return;
202 }
203
204 /* Do we have a good reason for building diplomats? */
205 {
206 const struct research *presearch = research_get(pplayer);
207 struct pf_map *pfm;
208 struct pf_parameter parameter;
209 struct city *acity;
210 adv_want want;
212 int gain_incite = 0, gain_theft = 0, gain = 1;
213 int incite_cost;
215 pplayer, pcity, ut,
217
218 pft_fill_unit_parameter(&parameter, nmap, punit);
219 parameter.omniscience = !has_handicap(pplayer, H_MAP);
220 pfm = pf_map_new(&parameter);
221
223
226
227 if (acity == nullptr
229 /* Found no target or city already considered */
230 return;
231 }
235 pplayer, acity)
237 pplayer, acity))
239 && (incite_cost < pplayer->economic.gold - expenses)) {
240 /* incite gain (FIXME: we should count wonders too but need to
241 cache that somehow to avoid CPU hog -- Per) */
244 + (acity->prod[O_LUXURY]
245 + acity->prod[O_GOLD]
246 + acity->prod[O_SCIENCE]) * TRADE_WEIGHTING;
247 gain_incite *= SHIELD_WEIGHTING; /* WAG cost to take city otherwise */
249 }
250 if ((research_get(city_owner(acity))->techs_researched
253 pplayer, acity)
255 pplayer, acity)
257 pplayer, acity)
259 pplayer, acity))
260 && !pplayers_allied(pplayer, city_owner(acity))) {
261 /* Tech theft gain */
262 /* FIXME: This value is right only when
263 * 'game.info.game.info.tech_cost_style' is set to
264 * TECH_COST_CIV1CIV2. */
265 gain_theft =
268 }
271
272 /* Probability to succeed, assuming no defending diplomat */
274 /* Probability to lose our unit */
277 100 - p_success :
278 100);
279
280 /* Get the time to dest in turns (minimum 1 turn) */
281 time_to_dest = (time_to_dest + ut->move_rate - 1) / ut->move_rate;
282 /* Discourage long treks */
283 time_to_dest *= ((time_to_dest + 1) / 2);
284
285 /* Almost kill_desire() */
286 want = (adv_want)(p_success * gain - p_failure * loss) / 100
288 if (want <= 0) {
289 return;
290 }
291
292 want = military_amortize(pplayer, pcity, want, time_to_dest,
293 utype_build_shield_cost(pcity, nullptr, ut));
294
295 if (!player_has_embassy(pplayer, city_owner(acity))
296 && want < 99
298 pplayer, acity)
300 pplayer, acity))) {
302 "A diplomat desired in %s to establish an embassy with %s "
303 "in %s",
307 want = 99;
308 }
309 if (want > choice->want) {
311 "%s, %s: %s is desired with want " ADV_WANT_PRINTF
312 " to spy in %s (incite want %d cost %d gold %d, "
313 "tech theft want %d, ttd %d)",
314 player_name(pplayer),
317 want,
321 pplayer->economic.gold - expenses,
324 choice->want = want;
325 choice->type = CT_CIVILIAN; /* so we don't build barracks for it */
326 choice->value.utype = ut;
327 choice->need_boat = FALSE;
328 adv_choice_set_use(choice, "offensive diplomat");
330 }
331 }
332}
333
334/**************************************************************************/
343static void dai_diplomat_city(struct ai_type *ait, struct unit *punit,
344 struct city *ctarget)
345{
346 struct action *chosen_action;
349 struct player *pplayer = unit_owner(punit);
350 struct player *tplayer = city_owner(ctarget);
351 int count_tech = count_stealable_techs(pplayer, tplayer);
352 const struct civ_map *nmap = &(wld.map);
353
354 fc_assert_ret(is_ai(pplayer));
355
356 if (punit->moves_left == 0) {
357 UNIT_LOG(LOG_ERROR, punit, "no moves left in ai_diplomat_city()!");
358 }
359
361
362 /* Select the best potentially legal action. */
363 /* FIXME: What if it is illegal? */
364 chosen_action = nullptr;
367 action_iterate(act_id) {
368 struct action *paction = action_by_number(act_id);
370 int sub_tgt_id;
371
374 /* Not relevant here. */
375 continue;
376 }
377
380 /* Not possible. */
381 continue;
382 }
383
384 if (paction->target_complexity == ACT_TGT_COMPL_SIMPLE) {
385 /* No sub target */
386 sub_tgt_id = 0;
387 } else {
388 /* Pick a suitable sub target. */
390 punit, ctarget);
391 }
392
394 ctarget, sub_tgt_id,
395 count_tech);
396
400 chosen_sub_tgt_id = sub_tgt_id;
401 }
403
404 if (chosen_action != nullptr) {
405 /* An action has been selected. */
406
409 ctarget))) {
410 log_base(LOG_DIPLOMAT, "%s %s[%d] does %s at %s",
415 unit_do_action(pplayer, punit->id,
416 ctarget->id, chosen_sub_tgt_id, "",
418 return;
419 }
420 }
421
422 /* This can happen for a number of odd and esoteric reasons */
424 "decides to stand idle outside enemy city %s!",
426 dai_unit_new_task(ait, punit, AIUNIT_NONE, nullptr);
427}
428
429/**************************************************************************/
433static bool is_city_surrounded_by_our_spies(struct player *pplayer,
434 struct city *enemy_city)
435{
437 if (has_handicap(pplayer, H_FOG)
438 && !map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
439 /* We cannot see danger at (ptile) => assume there is none. */
440 continue;
441 }
442 unit_list_iterate(ptile->units, punit) {
443 if (unit_owner(punit) == pplayer
445 return TRUE;
446 }
449
450 return FALSE;
451}
452
453/**************************************************************************/
457static void find_city_to_diplomat(struct player *pplayer, struct unit *punit,
458 struct city **ctarget, int *move_dist,
459 struct pf_map *pfm)
460{
461 bool has_embassy;
462 int incite_cost = 0; /* Incite cost */
463 int expenses;
464 bool dipldef; /* Whether target is protected by diplomats */
465
466 fc_assert_ret(punit != nullptr);
467
468 *ctarget = nullptr;
469 *move_dist = -1;
470 dai_calc_data(pplayer, nullptr, &expenses, nullptr);
471
472 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
473 struct city *acity;
474 struct player *aplayer;
475 bool can_incite;
476 bool can_steal;
477
478 acity = tile_city(ptile);
479
480 if (!acity) {
481 continue;
482 }
484
486
487 if (aplayer == pplayer || is_barbarian(aplayer)
488 || (pplayers_allied(pplayer, aplayer) && has_embassy)) {
489 continue;
490 }
491
495 pplayer, acity)
497 pplayer, acity));
498
500 pplayer, acity)
502 pplayer, acity)
504 pplayer, acity)
506 pplayer, acity);
507
509 /* Three actions to consider:
510 * 1. establishing embassy OR
511 * 2. stealing techs OR
512 * 3. inciting revolt */
513 if ((!has_embassy
515 pplayer, acity)
517 pplayer, acity)))
519 && !dipldef && can_steal
520 && (research_get(pplayer)->techs_researched
522 || (incite_cost < (pplayer->economic.gold - expenses)
523 && can_incite && !dipldef)) {
524 if (!is_city_surrounded_by_our_spies(pplayer, acity)) {
525 /* We have the closest enemy city on the continent */
526 *ctarget = acity;
527 *move_dist = move_cost;
528 break;
529 }
530 }
532}
533
534/**************************************************************************/
537static struct city *dai_diplomat_defend(struct ai_type *ait,
538 struct player *pplayer,
539 struct unit *punit,
540 const struct unit_type *utype,
541 struct pf_map *pfm)
542{
543 int best_dist = 30; /* Any city closer than this is better than none */
544 int best_urgency = 0;
545 struct city *ctarget = nullptr;
546 struct city *pcity = tile_city(unit_tile(punit));
547
548 if (pcity
550 && def_ai_city_data(pcity, ait)->urgency > 0) {
551 /* Danger and we are only diplomat present - stay. */
552 return pcity;
553 }
554
555 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
556 struct city *acity;
557 struct player *aplayer;
558 int dipls, urgency;
559 struct ai_city *city_data;
560
561 acity = tile_city(ptile);
562 if (!acity) {
563 continue;
564 }
566 if (aplayer != pplayer) {
567 continue;
568 }
569
571 urgency = city_data->urgency;
573 - (same_pos(ptile, unit_tile(punit)) ? 1 : 0));
574 if (dipls == 0 && city_data->diplomat_threat) {
575 /* We are _really_ needed there */
576 urgency = (urgency + 1) * 5;
577 } else if (dipls > 0) {
578 /* We are probably not needed there... */
579 urgency /= 3;
580 }
581
582 /* This formula may not be optimal, but it works. */
583 if (move_cost > best_dist) {
584 /* punish city for being so far away */
585 urgency /= (float) (move_cost / best_dist);
586 }
587
588 if (urgency > best_urgency) {
589 /* Found something worthy of our presence */
590 ctarget = acity;
592 /* squelch divide-by-zero */
593 best_dist = MAX(move_cost, 1);
594 }
596
597 return ctarget;
598}
599
600/**************************************************************************/
605static bool dai_diplomat_bribe_nearby(struct ai_type *ait,
606 struct player *pplayer,
607 struct unit *punit, struct pf_map *pfm)
608{
609 int gold_avail, expenses;
610 const struct civ_map *nmap = &(wld.map);
611
612 dai_calc_data(pplayer, nullptr, &expenses, nullptr);
613 gold_avail = pplayer->economic.gold - expenses;
614
616 struct tile *ptile = pos.tile;
617 bool threat = FALSE;
618 int newval, bestval = 0, cost;
619 struct unit *pvictim = tile_other_players_unit(ptile, pplayer);
620 int sanity = punit->id;
621 const struct unit_type *ptype;
622
623 if (pos.total_MC > punit->moves_left) {
624 /* Didn't find anything within range. */
625 break;
626 }
627
628 if (!pvictim
630 || unit_list_size(ptile->units) > 1
631 || tile_city(ptile)
633 punit, pvictim)) {
634 continue;
635 }
636
637 /* Calculate if enemy is a threat */
638 /* First find best defender on our tile */
639 unit_list_iterate(ptile->units, aunit) {
640 const struct unit_type *atype = unit_type_get(aunit);
641
643 if (bestval < newval) {
644 bestval = newval;
645 }
647 /* Compare with victim's attack power */
650 if (newval > bestval
651 && unit_move_rate(pvictim) > pos.total_MC) {
652 /* Enemy can probably kill us */
653 threat = TRUE;
654 } else {
655 /* Enemy cannot reach us or probably not kill us */
656 threat = FALSE;
657 }
658
659 if (has_handicap(pplayer, H_NOBRIBE_WF)) {
660 /* Don't bribe workers or city founders! */
663 continue;
664 }
665 }
666
667 /* Should we make the expense? */
668 cost = unit_bribe_cost(pvictim, pplayer, punit);
669 if (!threat) {
670 /* Don't empty our treasure without good reason! */
671 gold_avail = pplayer->economic.gold - dai_gold_reserve(pplayer);
672 }
673 if (cost > gold_avail) {
674 /* Can't afford */
675 continue;
676 }
677
678 /* Found someone! */
679 {
680 struct tile *bribee_tile;
681 struct pf_path *path;
682
683 bribee_tile = mapstep(nmap, pos.tile, DIR_REVERSE(pos.dir_to_here));
684 path = pf_map_path(pfm, bribee_tile);
685 if (!path || !adv_unit_execute_path(punit, path)
686 || punit->moves_left <= 0) {
687 pf_path_destroy(path);
688 return FALSE;
689 }
690 pf_path_destroy(path);
691 }
692
695 pvictim))) {
696 unit_do_action(pplayer, punit->id,
697 pvictim->id, -1, "",
699 /* Autoattack might kill us as we move in */
701 return TRUE;
702 } else {
703 return FALSE;
704 }
707 pvictim))
708 && threat) {
709 /* don't stand around waiting for the final blow */
710 unit_do_action(pplayer, punit->id,
711 pvictim->id, -1, "",
713 /* autoattack might kill us as we move in */
715 return TRUE;
716 } else {
717 return FALSE;
718 }
719 } else {
720 /* usually because we ended move early due to another unit */
721 UNIT_LOG(LOG_DIPLOMAT, punit, "could not bribe target (%d, %d), "
722 " %d moves left", TILE_XY(pos.tile), punit->moves_left);
723 return FALSE;
724 }
726
727 return (punit->moves_left > 0);
728}
729
730/**************************************************************************/
740void dai_manage_diplomat(struct ai_type *ait, struct player *pplayer,
741 struct unit *punit)
742{
743 struct city *pcity, *ctarget = nullptr;
744 struct pf_parameter parameter;
745 struct pf_map *pfm;
746 struct pf_position pos;
747 struct unit_ai *unit_data;
748 const struct civ_map *nmap = &(wld.map);
749
751
752 /* Generate map */
753 pft_fill_unit_parameter(&parameter, nmap, punit);
754 parameter.omniscience = !has_handicap(pplayer, H_MAP);
755 parameter.get_zoc = nullptr; /* Kludge */
756 parameter.get_TB = no_intermediate_fights;
757 pfm = pf_map_new(&parameter);
758
759 /* Look for someone to bribe */
760 if (!dai_diplomat_bribe_nearby(ait, pplayer, punit, pfm)) {
761 /* Died or ran out of moves */
763 return;
764 }
765
766 /* If we are the only diplomat in a threatened city, then stay to defend */
767 pcity = tile_city(unit_tile(punit)); /* We may have moved */
768 if (pcity) {
769 struct ai_city *city_data = def_ai_city_data(pcity, ait);
770
772 && (city_data->diplomat_threat
773 || city_data->urgency > 0)) {
774 UNIT_LOG(LOG_DIPLOMAT, punit, "stays to protect %s (urg %d)",
775 city_name_get(pcity), city_data->urgency);
776 dai_unit_new_task(ait, punit, AIUNIT_NONE, nullptr); /* Abort mission */
779 return;
780 }
781 }
782
784
785 /* Check if existing target still makes sense */
786 if (unit_data->task == AIUNIT_ATTACK
787 || unit_data->task == AIUNIT_DEFEND_HOME) {
788 bool failure = FALSE;
789
792 && ctarget) {
793 if (same_pos(ctarget->tile, unit_tile(punit))) {
794 failure = TRUE;
795 } else if (pplayers_allied(pplayer, city_owner(ctarget))
796 && unit_data->task == AIUNIT_ATTACK
797 && player_has_embassy(pplayer, city_owner(ctarget))) {
798 /* We probably incited this city with another diplomat */
799 failure = TRUE;
800 } else if (!pplayers_allied(pplayer, city_owner(ctarget))
801 && unit_data->task == AIUNIT_DEFEND_HOME) {
802 /* We probably lost the city */
803 failure = TRUE;
804 }
805 } else {
806 /* City vanished! */
807 failure = TRUE;
808 }
809 if (failure) {
810 UNIT_LOG(LOG_DIPLOMAT, punit, "mission aborted");
811 dai_unit_new_task(ait, punit, AIUNIT_NONE, nullptr);
812 }
813 }
814
815 /* We may need a new map now. Both because we cannot get paths from an
816 * old map, and we need paths to move, and because fctd below requires
817 * a new map for its iterator. */
818 if (!same_pos(parameter.start_tile, unit_tile(punit))
819 || unit_data->task == AIUNIT_NONE) {
821 pft_fill_unit_parameter(&parameter, nmap, punit);
822 parameter.omniscience = !has_handicap(pplayer, H_MAP);
823 parameter.get_zoc = nullptr; /* Kludge */
824 parameter.get_TB = no_intermediate_fights;
825 pfm = pf_map_new(&parameter);
826 }
827
828 /* If we are not busy, acquire a target. */
829 if (unit_data->task == AIUNIT_NONE) {
830 enum ai_unit_task task;
831 int move_dist; /* dummy */
832
834
835 if (ctarget) {
836 task = AIUNIT_ATTACK;
838 UNIT_LOG(LOG_DIPLOMAT, punit, "going on attack");
839 } else if ((ctarget = dai_diplomat_defend(ait, pplayer, punit,
841 != nullptr) {
842 task = AIUNIT_DEFEND_HOME;
843 UNIT_LOG(LOG_DIPLOMAT, punit, "going to defend %s",
845 } else if ((ctarget = find_closest_city(unit_tile(punit), nullptr, pplayer,
847 nullptr))
848 != nullptr) {
849 /* This should only happen if the entire continent was suddenly
850 * conquered. So we head for closest coastal city and wait for someone
851 * to code ferrying for diplomats, or hostile attacks from the sea. */
852 task = AIUNIT_DEFEND_HOME;
853 UNIT_LOG(LOG_DIPLOMAT, punit, "going idle");
854 } else {
855 UNIT_LOG(LOG_DIPLOMAT, punit, "could not find a job");
858 return;
859 }
860
861 dai_unit_new_task(ait, punit, task, ctarget->tile);
863 && unit_data->task != AIUNIT_NONE);
864 }
865
867 if (ctarget == nullptr) {
868 UNIT_LOG(LOG_ERROR, punit, "ctarget not set (task == %d)",
869 unit_data->task);
871 return;
872 }
873
874 /* GOTO unless we want to stay */
875 if (!same_pos(unit_tile(punit), ctarget->tile)) {
876 struct pf_path *path;
877
878 path = pf_map_path(pfm, punit->goto_tile);
879 if (path && adv_unit_execute_path(punit, path) && punit->moves_left > 0) {
880 /* Check if we can do something with our destination now. */
881 if (unit_data->task == AIUNIT_ATTACK) {
883
884 UNIT_LOG(LOG_DIPLOMAT, punit, "attack, dist %d to %s",
885 dist, ctarget ? city_name_get(ctarget) : "(none)");
886 if (dist <= 1) {
887 /* Do our stuff */
888 dai_unit_new_task(ait, punit, AIUNIT_NONE, nullptr);
890 }
891 }
892 }
893 pf_path_destroy(path);
894 } else {
896 }
898}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5727
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1124
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5327
const char * action_rule_name(const struct action *action)
Definition actions.c:1242
int action_number(const struct action *action)
Definition actions.c:1234
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:3187
struct act_prob action_prob_vs_city(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Definition actions.c:4490
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1134
struct act_prob action_prob_vs_unit(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Definition actions.c:4573
static struct action * action_by_number(action_id act_id)
Definition actions.h:400
#define action_iterate_end
Definition actions.h:218
#define action_iterate(_act_)
Definition actions.h:214
#define ACTION_NONE
Definition actions.h:59
#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:88
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
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
const char * city_name_get(const struct city *pcity)
Definition city.c:1157
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:808
#define city_tile(_pcity_)
Definition city.h:565
#define INCITE_IMPOSSIBLE_COST
Definition city.h:94
#define city_owner(_pcity_)
Definition city.h:564
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:856
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3631
char * incite_cost
Definition comments.c:77
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
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)
void dai_choose_diplomat_defensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, int def)
void dai_manage_diplomat(struct ai_type *ait, struct player *pplayer, struct unit *punit)
#define LOG_DIPLOMAT_BUILD
Definition daidiplomat.c:78
static void dai_diplomat_city(struct ai_type *ait, struct unit *punit, struct city *ctarget)
#define LOG_DIPLOMAT
Definition daidiplomat.c:77
static int count_diplomats_on_tile(struct tile *ptile)
Definition daidiplomat.c:94
#define DIPLO_DEFENSE_WANT
Definition daidiplomat.c:82
static bool dai_diplomat_bribe_nearby(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct pf_map *pfm)
void dai_choose_diplomat_offensive(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, struct adv_choice *choice)
static int count_stealable_techs(struct player *pplayer, struct player *tplayer)
static void find_city_to_diplomat(struct player *pplayer, struct unit *punit, struct city **ctarget, int *move_dist, struct pf_map *pfm)
static bool is_city_surrounded_by_our_spies(struct player *pplayer, struct city *pcity)
void aiguard_request_guard(struct ai_type *ait, struct unit *punit)
Definition daiguard.c:227
void dai_calc_data(const struct player *pplayer, int *trade, int *expenses, int *income)
Definition daihand.c:117
#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
void dai_unit_new_task(struct ai_type *ait, struct unit *punit, enum ai_unit_task task, struct tile *ptile)
Definition daitools.c:643
int dai_gold_reserve(struct player *pplayer)
Definition daitools.c:1354
adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
Definition daitools.c:117
#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:73
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:77
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:73
int diplomats_unignored_tech_stealings(struct unit *pdiplomat, struct city *pcity)
Definition diplomats.c:970
float adv_want
Definition fc_types.h:1050
#define ADV_WANT_PRINTF
Definition fc_types.h:1051
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
@ O_SCIENCE
Definition fc_types.h:103
@ O_LUXURY
Definition fc_types.h:103
@ O_GOLD
Definition fc_types.h:103
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:115
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:192
#define fc_assert(condition)
Definition log.h:177
#define log_base(level, message,...)
Definition log.h:95
@ LOG_ERROR
Definition log.h:31
@ LOG_DEBUG
Definition log.h:35
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:1085
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:675
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:384
#define adjc_iterate_end
Definition map.h:439
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:434
#define DIR_REVERSE(dir)
Definition map.h:598
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:937
int unit_move_rate(const struct unit *punit)
Definition movement.c:89
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:461
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:842
enum tile_behavior no_intermediate_fights(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:526
const char * player_name(const struct player *pplayer)
Definition player.c:885
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1397
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:213
static bool is_barbarian(const struct player *pplayer)
Definition player.h:499
#define is_ai(plr)
Definition player.h:232
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Definition research.c:872
struct research * research_get(const struct player *pplayer)
Definition research.c:130
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:622
#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
unsigned int urgency
Definition daicity.h:49
struct ai_plr::@279 stats
bv_id diplomat_reservations
Definition daidata.h:85
Definition ai.h:50
Definition city.h:318
int diplchance
Definition game.h:145
struct civ_game::@32::@36 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:284
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:139
int moves_left
Definition unit.h:151
int id
Definition unit.h:146
struct tile * tile
Definition unit.h:141
struct tile * goto_tile
Definition unit.h:156
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:90
#define advance_index_iterate_end
Definition tech.h:246
#define A_FIRST
Definition tech.h:44
#define advance_index_iterate(_start, _index)
Definition tech.h:242
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:536
int unit_bribe_cost(const struct unit *punit, const struct player *briber, const struct unit *briber_unit)
Definition unit.c:2361
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:412
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1682
struct unit * tile_other_players_unit(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1382
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1787
#define unit_tile(_pu)
Definition unit.h:408
#define CHECK_UNIT(punit)
Definition unit.h:273
#define unit_owner(_pu)
Definition unit.h:407
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity, enum gen_action trigger_action)
Definition unithand.c:6714
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:3354
#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:2303
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2284
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1613
int num_role_units(int role)
Definition unittype.c:2234
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1604
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:215
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1463
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
#define unit_tech_reqs_iterate_end
Definition unittype.h:891
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:885