Freeciv-3.3
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
59/* ai */
60#include "handicaps.h"
61
62/* ai/default */
63#include "aiguard.h"
64#include "aihand.h"
65#include "daiactions.h"
66#include "daicity.h"
67#include "daidata.h"
68#include "dailog.h"
69#include "daimilitary.h"
70#include "daiplayer.h"
71#include "daitools.h"
72#include "daiunit.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.",
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.",
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",
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),
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 const struct civ_map *nmap = &(wld.map);
337
338 fc_assert_ret(is_ai(pplayer));
339
340 if (punit->moves_left == 0) {
341 UNIT_LOG(LOG_ERROR, punit, "no moves left in ai_diplomat_city()!");
342 }
343
345
346 /* Select the best potentially legal action. */
347 /* FIXME: what if it is illegal? */
351 action_iterate(act_id) {
352 struct action *paction = action_by_number(act_id);
354 int sub_tgt_id;
355
358 /* Not relevant here. */
359 continue;
360 }
361
364 /* Not possible. */
365 continue;
366 }
367
368 if (paction->target_complexity == ACT_TGT_COMPL_SIMPLE) {
369 /* No sub target */
370 sub_tgt_id = 0;
371 } else {
372 /* Pick a suitable sub target. */
374 punit, ctarget);
375 }
376
378 ctarget, sub_tgt_id,
379 count_tech);
380
384 chosen_sub_tgt_id = sub_tgt_id;
385 }
387
388 if (chosen_action != NULL) {
389 /* An action has been selected. */
390
393 ctarget))) {
394 log_base(LOG_DIPLOMAT, "%s %s[%d] does %s at %s",
399 unit_do_action(pplayer, punit->id,
400 ctarget->id, chosen_sub_tgt_id, "",
402 return;
403 }
404 }
405
406 /* This can happen for a number of odd and esoteric reasons */
408 "decides to stand idle outside enemy city %s!",
411}
412
413/**************************************************************************/
417static bool is_city_surrounded_by_our_spies(struct player *pplayer,
418 struct city *enemy_city)
419{
421 if (has_handicap(pplayer, H_FOG)
422 && !map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
423 /* We cannot see danger at (ptile) => assume there is none. */
424 continue;
425 }
426 unit_list_iterate(ptile->units, punit) {
427 if (unit_owner(punit) == pplayer
429 return TRUE;
430 }
433
434 return FALSE;
435}
436
437/**************************************************************************/
441static void find_city_to_diplomat(struct player *pplayer, struct unit *punit,
442 struct city **ctarget, int *move_dist,
443 struct pf_map *pfm)
444{
445 bool has_embassy;
446 int incite_cost = 0; /* incite cost */
447 int expenses;
448 bool dipldef; /* whether target is protected by diplomats */
449
451 *ctarget = NULL;
452 *move_dist = -1;
453 dai_calc_data(pplayer, NULL, &expenses, NULL);
454
455 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
456 struct city *acity;
457 struct player *aplayer;
458 bool can_incite;
459 bool can_steal;
460
461 acity = tile_city(ptile);
462
463 if (!acity) {
464 continue;
465 }
467
469
470 if (aplayer == pplayer || is_barbarian(aplayer)
471 || (pplayers_allied(pplayer, aplayer) && has_embassy)) {
472 continue;
473 }
474
478 pplayer, acity)
480 pplayer, acity));
481
483 pplayer, acity)
485 pplayer, acity)
487 pplayer, acity)
489 pplayer, acity);
490
492 /* Three actions to consider:
493 * 1. establishing embassy OR
494 * 2. stealing techs OR
495 * 3. inciting revolt */
496 if ((!has_embassy
498 pplayer, acity)
500 pplayer, acity)))
502 && !dipldef && can_steal
503 && (research_get(pplayer)->techs_researched
505 || (incite_cost < (pplayer->economic.gold - expenses)
506 && can_incite && !dipldef)) {
507 if (!is_city_surrounded_by_our_spies(pplayer, acity)) {
508 /* We have the closest enemy city on the continent */
509 *ctarget = acity;
510 *move_dist = move_cost;
511 break;
512 }
513 }
515}
516
517/**************************************************************************/
520static struct city *dai_diplomat_defend(struct ai_type *ait,
521 struct player *pplayer,
522 struct unit *punit,
523 const struct unit_type *utype,
524 struct pf_map *pfm)
525{
526 int best_dist = 30; /* any city closer than this is better than none */
527 int best_urgency = 0;
528 struct city *ctarget = NULL;
529 struct city *pcity = tile_city(unit_tile(punit));
530
531 if (pcity
533 && def_ai_city_data(pcity, ait)->urgency > 0) {
534 /* Danger and we are only diplomat present - stay. */
535 return pcity;
536 }
537
538 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
539 struct city *acity;
540 struct player *aplayer;
541 int dipls, urgency;
542 struct ai_city *city_data;
543
544 acity = tile_city(ptile);
545 if (!acity) {
546 continue;
547 }
549 if (aplayer != pplayer) {
550 continue;
551 }
552
554 urgency = city_data->urgency;
556 - (same_pos(ptile, unit_tile(punit)) ? 1 : 0));
557 if (dipls == 0 && city_data->diplomat_threat) {
558 /* We are _really_ needed there */
559 urgency = (urgency + 1) * 5;
560 } else if (dipls > 0) {
561 /* We are probably not needed there... */
562 urgency /= 3;
563 }
564
565 /* This formula may not be optimal, but it works. */
566 if (move_cost > best_dist) {
567 /* punish city for being so far away */
568 urgency /= (float) (move_cost / best_dist);
569 }
570
571 if (urgency > best_urgency) {
572 /* Found something worthy of our presence */
573 ctarget = acity;
575 /* squelch divide-by-zero */
576 best_dist = MAX(move_cost, 1);
577 }
579
580 return ctarget;
581}
582
583/**************************************************************************/
588static bool dai_diplomat_bribe_nearby(struct ai_type *ait,
589 struct player *pplayer,
590 struct unit *punit, struct pf_map *pfm)
591{
592 int gold_avail, expenses;
593 const struct civ_map *nmap = &(wld.map);
594
595 dai_calc_data(pplayer, NULL, &expenses, NULL);
596 gold_avail = pplayer->economic.gold - expenses;
597
599 struct tile *ptile = pos.tile;
600 bool threat = FALSE;
601 int newval, bestval = 0, cost;
602 struct unit *pvictim = tile_other_players_unit(ptile, pplayer);
603 int sanity = punit->id;
604 const struct unit_type *ptype;
605
606 if (pos.total_MC > punit->moves_left) {
607 /* Didn't find anything within range. */
608 break;
609 }
610
611 if (!pvictim
613 || unit_list_size(ptile->units) > 1
614 || tile_city(ptile)
616 punit, pvictim)) {
617 continue;
618 }
619
620 /* Calculate if enemy is a threat */
621 /* First find best defender on our tile */
622 unit_list_iterate(ptile->units, aunit) {
623 const struct unit_type *atype = unit_type_get(aunit);
624
626 if (bestval < newval) {
627 bestval = newval;
628 }
630 /* Compare with victim's attack power */
633 if (newval > bestval
634 && unit_move_rate(pvictim) > pos.total_MC) {
635 /* Enemy can probably kill us */
636 threat = TRUE;
637 } else {
638 /* Enemy cannot reach us or probably not kill us */
639 threat = FALSE;
640 }
641
642 if (has_handicap(pplayer, H_NOBRIBE_WF)) {
643 /* Don't bribe workers or city founders! */
646 continue;
647 }
648 }
649
650 /* Should we make the expense? */
651 cost = unit_bribe_cost(pvictim, pplayer, punit);
652 if (!threat) {
653 /* Don't empty our treasure without good reason! */
654 gold_avail = pplayer->economic.gold - dai_gold_reserve(pplayer);
655 }
656 if (cost > gold_avail) {
657 /* Can't afford */
658 continue;
659 }
660
661 /* Found someone! */
662 {
663 struct tile *bribee_tile;
664 struct pf_path *path;
665
666 bribee_tile = mapstep(nmap, pos.tile, DIR_REVERSE(pos.dir_to_here));
667 path = pf_map_path(pfm, bribee_tile);
668 if (!path || !adv_unit_execute_path(punit, path)
669 || punit->moves_left <= 0) {
670 pf_path_destroy(path);
671 return FALSE;
672 }
673 pf_path_destroy(path);
674 }
675
678 pvictim))) {
679 unit_do_action(pplayer, punit->id,
680 pvictim->id, -1, "",
682 /* Autoattack might kill us as we move in */
684 return TRUE;
685 } else {
686 return FALSE;
687 }
690 pvictim))
691 && threat) {
692 /* don't stand around waiting for the final blow */
693 unit_do_action(pplayer, punit->id,
694 pvictim->id, -1, "",
696 /* autoattack might kill us as we move in */
698 return TRUE;
699 } else {
700 return FALSE;
701 }
702 } else {
703 /* usually because we ended move early due to another unit */
704 UNIT_LOG(LOG_DIPLOMAT, punit, "could not bribe target (%d, %d), "
705 " %d moves left", TILE_XY(pos.tile), punit->moves_left);
706 return FALSE;
707 }
709
710 return (punit->moves_left > 0);
711}
712
713/**************************************************************************/
723void dai_manage_diplomat(struct ai_type *ait, struct player *pplayer,
724 struct unit *punit)
725{
726 struct city *pcity, *ctarget = NULL;
727 struct pf_parameter parameter;
728 struct pf_map *pfm;
729 struct pf_position pos;
730 struct unit_ai *unit_data;
731 const struct civ_map *nmap = &(wld.map);
732
734
735 /* Generate map */
736 pft_fill_unit_parameter(&parameter, nmap, punit);
737 parameter.omniscience = !has_handicap(pplayer, H_MAP);
738 parameter.get_zoc = NULL; /* Kludge */
739 parameter.get_TB = no_intermediate_fights;
740 pfm = pf_map_new(&parameter);
741
742 /* Look for someone to bribe */
743 if (!dai_diplomat_bribe_nearby(ait, pplayer, punit, pfm)) {
744 /* Died or ran out of moves */
746 return;
747 }
748
749 /* If we are the only diplomat in a threatened city, then stay to defend */
750 pcity = tile_city(unit_tile(punit)); /* we may have moved */
751 if (pcity) {
752 struct ai_city *city_data = def_ai_city_data(pcity, ait);
753
755 && (city_data->diplomat_threat
756 || city_data->urgency > 0)) {
757 UNIT_LOG(LOG_DIPLOMAT, punit, "stays to protect %s (urg %d)",
758 city_name_get(pcity), city_data->urgency);
759 dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL); /* abort mission */
762 return;
763 }
764 }
765
767
768 /* Check if existing target still makes sense */
769 if (unit_data->task == AIUNIT_ATTACK
770 || unit_data->task == AIUNIT_DEFEND_HOME) {
771 bool failure = FALSE;
772
775 && ctarget) {
776 if (same_pos(ctarget->tile, unit_tile(punit))) {
777 failure = TRUE;
778 } else if (pplayers_allied(pplayer, city_owner(ctarget))
779 && unit_data->task == AIUNIT_ATTACK
780 && player_has_embassy(pplayer, city_owner(ctarget))) {
781 /* We probably incited this city with another diplomat */
782 failure = TRUE;
783 } else if (!pplayers_allied(pplayer, city_owner(ctarget))
784 && unit_data->task == AIUNIT_DEFEND_HOME) {
785 /* We probably lost the city */
786 failure = TRUE;
787 }
788 } else {
789 /* City vanished! */
790 failure = TRUE;
791 }
792 if (failure) {
793 UNIT_LOG(LOG_DIPLOMAT, punit, "mission aborted");
795 }
796 }
797
798 /* We may need a new map now. Both because we cannot get paths from an
799 * old map, and we need paths to move, and because fctd below requires
800 * a new map for its iterator. */
801 if (!same_pos(parameter.start_tile, unit_tile(punit))
802 || unit_data->task == AIUNIT_NONE) {
804 pft_fill_unit_parameter(&parameter, nmap, punit);
805 parameter.omniscience = !has_handicap(pplayer, H_MAP);
806 parameter.get_zoc = NULL; /* Kludge */
807 parameter.get_TB = no_intermediate_fights;
808 pfm = pf_map_new(&parameter);
809 }
810
811 /* If we are not busy, acquire a target. */
812 if (unit_data->task == AIUNIT_NONE) {
813 enum ai_unit_task task;
814 int move_dist; /* dummy */
815
817
818 if (ctarget) {
819 task = AIUNIT_ATTACK;
821 UNIT_LOG(LOG_DIPLOMAT, punit, "going on attack");
822 } else if ((ctarget = dai_diplomat_defend(ait, pplayer, punit,
824 != NULL) {
825 task = AIUNIT_DEFEND_HOME;
826 UNIT_LOG(LOG_DIPLOMAT, punit, "going to defend %s",
828 } else if ((ctarget = find_closest_city(unit_tile(punit), NULL, pplayer,
830 NULL))
831 != NULL) {
832 /* This should only happen if the entire continent was suddenly
833 * conquered. So we head for closest coastal city and wait for someone
834 * to code ferrying for diplomats, or hostile attacks from the sea. */
835 task = AIUNIT_DEFEND_HOME;
836 UNIT_LOG(LOG_DIPLOMAT, punit, "going idle");
837 } else {
838 UNIT_LOG(LOG_DIPLOMAT, punit, "could not find a job");
841 return;
842 }
843
844 dai_unit_new_task(ait, punit, task, ctarget->tile);
846 && unit_data->task != AIUNIT_NONE);
847 }
848
850 if (ctarget == NULL) {
851 UNIT_LOG(LOG_ERROR, punit, "ctarget not set (task == %d)",
852 unit_data->task);
854 return;
855 }
856
857 /* GOTO unless we want to stay */
858 if (!same_pos(unit_tile(punit), ctarget->tile)) {
859 struct pf_path *path;
860
861 path = pf_map_path(pfm, punit->goto_tile);
862 if (path && adv_unit_execute_path(punit, path) && punit->moves_left > 0) {
863 /* Check if we can do something with our destination now. */
864 if (unit_data->task == AIUNIT_ATTACK) {
866
867 UNIT_LOG(LOG_DIPLOMAT, punit, "attack, dist %d to %s",
868 dist, ctarget ? city_name_get(ctarget) : "(none)");
869 if (dist <= 1) {
870 /* Do our stuff */
873 }
874 }
875 }
876 pf_path_destroy(path);
877 } else {
879 }
881}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5491
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1098
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5091
const char * action_rule_name(const struct action *action)
Definition actions.c:1216
int action_number(const struct action *action)
Definition actions.c:1208
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:3168
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:4254
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1108
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:4337
static struct action * action_by_number(action_id act_id)
Definition actions.h:396
#define action_iterate_end
Definition actions.h:214
#define action_iterate(_act_)
Definition actions.h:210
#define ACTION_NONE
Definition actions.h:55
#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:86
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:520
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:723
#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:588
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:441
static bool is_city_surrounded_by_our_spies(struct player *pplayer, struct city *pcity)
Definition aidiplomat.c:417
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
#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:1137
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:804
#define city_tile(_pcity_)
Definition city.h:561
#define INCITE_IMPOSSIBLE_COST
Definition city.h:93
#define city_owner(_pcity_)
Definition city.h:560
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:3455
char * incite_cost
Definition comments.c:76
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
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:1326
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:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
int diplomats_unignored_tech_stealings(struct unit *pdiplomat, struct city *pcity)
Definition diplomats.c:970
int count_diplomats_on_tile(struct tile *ptile)
Definition diplomats.c:2499
float adv_want
Definition fc_types.h:1063
#define ADV_WANT_PRINTF
Definition fc_types.h:1064
@ 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:61
struct world wld
Definition game.c:62
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:1076
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:430
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:425
#define DIR_REVERSE(dir)
Definition map.h:589
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:925
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: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:843
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:895
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
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:491
#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: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::@282 stats
adv_want tech_want[A_LAST+1]
Definition daidata.h:104
bv_id diplomat_reservations
Definition daidata.h:85
Definition ai.h:50
Definition city.h:317
int id
Definition city.h:323
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:140
int moves_left
Definition unit.h:152
int id
Definition unit.h:147
struct tile * tile
Definition unit.h:142
struct tile * goto_tile
Definition unit.h:157
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:244
#define A_FIRST
Definition tech.h:44
#define advance_index_iterate(_start, _index)
Definition tech.h:240
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:553
int unit_bribe_cost(const struct unit *punit, const struct player *briber, const struct unit *briber_unit)
Definition unit.c:2344
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:393
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1661
struct unit * tile_other_players_unit(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1360
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1766
#define unit_tile(_pu)
Definition unit.h:404
#define CHECK_UNIT(punit)
Definition unit.h:273
#define unit_owner(_pu)
Definition unit.h:403
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity, enum gen_action trigger_action)
Definition unithand.c:6663
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:3338
#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:2277
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:2259
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1593
int num_role_units(int role)
Definition unittype.c:2209
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1584
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1444
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:377
#define unit_tech_reqs_iterate_end
Definition unittype.h:888
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:882