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

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/**************************************************************************/
94 static 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
100 advance_index_iterate(A_FIRST, idx) {
101 if (research_invention_state(presearch, idx) != TECH_KNOWN
102 && research_invention_state(tresearch, idx) == TECH_KNOWN) {
103 count++;
104 }
105 } advance_index_iterate_end;
106
107 return count;
108}
109
110/**************************************************************************/
115 void dai_choose_diplomat_defensive(struct ai_type *ait,
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) {
131 log_base(LOG_DIPLOMAT_BUILD,
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... */
142 log_base(LOG_DIPLOMAT_BUILD,
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)]
151 += DIPLO_DEFENSE_WANT;
152 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
153 "ai_choose_diplomat_defensive() + %d for %s",
154 DIPLO_DEFENSE_WANT,
155 utype_rule_name(ut));
156 } unit_tech_reqs_iterate_end;
157 }
158 }
159 }
160}
161
162/**************************************************************************/
166 void dai_choose_diplomat_offensive(struct ai_type *ait,
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;
198 struct unit *punit = unit_virtual_create(
199 pplayer, pcity, ut,
200 city_production_unit_veteran_level(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);
209 unit_virtual_destroy(punit);
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))
222 && (incite_cost < INCITE_IMPOSSIBLE_COST)
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) */
226 gain_incite = acity->prod[O_FOOD] * FOOD_WEIGHTING
227 + acity->prod[O_SHIELD] * SHIELD_WEIGHTING
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 */
232 gain_incite -= incite_cost * TRADE_WEIGHTING;
233 }
234 if ((research_get(city_owner(acity))->techs_researched
235 > presearch->techs_researched)
236 && (is_action_possible_on_city(ACTION_SPY_TARGETED_STEAL_TECH,
237 pplayer, acity)
238 || is_action_possible_on_city(ACTION_SPY_TARGETED_STEAL_TECH_ESC,
239 pplayer, acity)
240 || is_action_possible_on_city(ACTION_SPY_STEAL_TECH,
241 pplayer, acity)
242 || is_action_possible_on_city(ACTION_SPY_STEAL_TECH_ESC,
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 =
250 (research_total_bulbs_required(presearch, presearch->researching,
251 FALSE) * TRADE_WEIGHTING);
252 }
253 gain = MAX(gain_incite, gain_theft);
254 loss = utype_build_shield_cost(pcity, NULL, ut) * SHIELD_WEIGHTING;
255
256 /* Probability to succeed, assuming no defending diplomat */
257 p_success = game.server.diplchance;
258 /* Probability to lose our unit */
259 p_failure = (utype_can_do_action(ut, ACTION_SPY_TARGETED_STEAL_TECH_ESC)
260 || utype_can_do_action(ut, ACTION_SPY_STEAL_TECH_ESC) ?
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
271 - SHIELD_WEIGHTING * time_to_dest;
272 if (want <= 0) {
273 return;
274 }
275
276 want = military_amortize(pplayer, pcity, want, time_to_dest,
277 utype_build_shield_cost(pcity, NULL, ut));
278
279 if (!player_has_embassy(pplayer, city_owner(acity))
280 && want < 99
281 && (is_action_possible_on_city(ACTION_ESTABLISH_EMBASSY,
282 pplayer, acity)
283 || is_action_possible_on_city(ACTION_ESTABLISH_EMBASSY_STAY,
284 pplayer, acity))) {
285 log_base(LOG_DIPLOMAT_BUILD,
286 "A diplomat desired in %s to establish an embassy with %s "
287 "in %s",
288 city_name_get(pcity),
289 player_name(city_owner(acity)),
290 city_name_get(acity));
291 want = 99;
292 }
293 if (want > choice->want) {
294 log_base(LOG_DIPLOMAT_BUILD,
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),
300 utype_rule_name(ut),
301 want,
302 city_name_get(acity),
303 gain_incite,
304 incite_cost,
305 pplayer->economic.gold - expenses,
306 gain_theft,
307 time_to_dest);
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");
313 BV_SET(ai->stats.diplomat_reservations, acity->id);
314 }
315 }
316}
317
318/**************************************************************************/
327 static void dai_diplomat_city(struct ai_type *ait, struct unit *punit,
328 struct city *ctarget)
329{
330 struct action *chosen_action;
331 adv_want chosen_action_utility;
332 int chosen_sub_tgt_id;
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
344 unit_activity_handling(punit, ACTIVITY_IDLE, ACTION_NONE);
345
346 /* Select the best potentially legal action. */
347 /* FIXME: what if it is illegal? */
348 chosen_action = NULL;
349 chosen_action_utility = -1;
350 chosen_sub_tgt_id = 0;
351 action_iterate(act_id) {
352 struct action *paction = action_by_number(act_id);
353 adv_want action_utility;
354 int sub_tgt_id;
355
356 if (action_get_actor_kind(paction) != AAK_UNIT
357 || action_get_target_kind(paction) != ATK_CITY) {
358 /* Not relevant here. */
359 continue;
360 }
361
362 if (!action_prob_possible(
363 action_prob_vs_city(nmap, punit, action_number(paction),ctarget))) {
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. */
373 sub_tgt_id = dai_action_choose_sub_tgt_unit_vs_city(paction,
374 punit, ctarget);
375 }
376
377 action_utility = dai_action_value_unit_vs_city(paction, punit,
378 ctarget, sub_tgt_id,
379 count_tech);
380
381 if (chosen_action_utility < action_utility) {
382 chosen_action = paction;
383 chosen_action_utility = action_utility;
384 chosen_sub_tgt_id = sub_tgt_id;
385 }
386 } action_iterate_end;
387
388 if (chosen_action != NULL) {
389 /* An action has been selected. */
390
391 if (action_prob_possible(
392 action_prob_vs_city(nmap, punit, action_number(chosen_action),
393 ctarget))) {
394 log_base(LOG_DIPLOMAT, "%s %s[%d] does %s at %s",
395 nation_rule_name(nation_of_unit(punit)),
396 unit_rule_name(punit), punit->id,
397 action_rule_name(chosen_action),
398 city_name_get(ctarget));
399 unit_do_action(pplayer, punit->id,
400 ctarget->id, chosen_sub_tgt_id, "",
401 action_number(chosen_action));
402 return;
403 }
404 }
405
406 /* This can happen for a number of odd and esoteric reasons */
407 UNIT_LOG(LOG_DIPLOMAT, punit,
408 "decides to stand idle outside enemy city %s!",
409 city_name_get(ctarget));
410 dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
411}
412
413/**************************************************************************/
417 static bool is_city_surrounded_by_our_spies(struct player *pplayer,
418 struct city *enemy_city)
419{
420 adjc_iterate(&(wld.map), city_tile(enemy_city), ptile) {
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
428 && aia_utype_is_considered_spy(unit_type_get(punit))) {
429 return TRUE;
430 }
431 } unit_list_iterate_end;
432 } adjc_iterate_end;
433
434 return FALSE;
435}
436
437/**************************************************************************/
441 static 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
450 fc_assert_ret(punit != NULL);
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 }
466 aplayer = city_owner(acity);
467
468 has_embassy = player_has_embassy(pplayer, aplayer);
469
470 if (aplayer == pplayer || is_barbarian(aplayer)
471 || (pplayers_allied(pplayer, aplayer) && has_embassy)) {
472 continue;
473 }
474
475 incite_cost = city_incite_cost(pplayer, acity);
476 can_incite = (incite_cost < INCITE_IMPOSSIBLE_COST)
477 && (is_action_possible_on_city(ACTION_SPY_INCITE_CITY,
478 pplayer, acity)
479 || is_action_possible_on_city(ACTION_SPY_INCITE_CITY_ESC,
480 pplayer, acity));
481
482 can_steal = is_action_possible_on_city(ACTION_SPY_STEAL_TECH,
483 pplayer, acity)
484 || is_action_possible_on_city(ACTION_SPY_STEAL_TECH_ESC,
485 pplayer, acity)
486 || is_action_possible_on_city(ACTION_SPY_TARGETED_STEAL_TECH,
487 pplayer, acity)
488 || is_action_possible_on_city(ACTION_SPY_TARGETED_STEAL_TECH_ESC,
489 pplayer, acity);
490
491 dipldef = (count_diplomats_on_tile(acity->tile) > 0);
492 /* Three actions to consider:
493 * 1. establishing embassy OR
494 * 2. stealing techs OR
495 * 3. inciting revolt */
496 if ((!has_embassy
497 && (is_action_possible_on_city(ACTION_ESTABLISH_EMBASSY,
498 pplayer, acity)
499 || is_action_possible_on_city(ACTION_ESTABLISH_EMBASSY_STAY,
500 pplayer, acity)))
501 || (diplomats_unignored_tech_stealings(punit, acity) == 0
502 && !dipldef && can_steal
503 && (research_get(pplayer)->techs_researched
504 < research_get(aplayer)->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 }
514 } pf_map_move_costs_iterate_end;
515}
516
517/**************************************************************************/
520 static 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
532 && count_diplomats_on_tile(pcity->tile) == 1
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 }
548 aplayer = city_owner(acity);
549 if (aplayer != pplayer) {
550 continue;
551 }
552
553 city_data = def_ai_city_data(acity, ait);
554 urgency = city_data->urgency;
555 dipls = (count_diplomats_on_tile(ptile)
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;
574 best_urgency = urgency;
575 /* squelch divide-by-zero */
576 best_dist = MAX(move_cost, 1);
577 }
578 } pf_map_move_costs_iterate_end;
579
580 return ctarget;
581}
582
583/**************************************************************************/
588 static 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
598 pf_map_positions_iterate(pfm, pos, FALSE) {
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
612 || !POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, unit_owner(pvictim))
613 || unit_list_size(ptile->units) > 1
614 || tile_city(ptile)
615 || !is_action_enabled_unit_on_unit(nmap, ACTION_SPY_BRIBE_UNIT,
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
625 newval = DEFENSE_POWER(atype);
626 if (bestval < newval) {
627 bestval = newval;
628 }
629 } unit_list_iterate_end;
630 /* Compare with victim's attack power */
631 ptype = unit_type_get(pvictim);
632 newval = ATTACK_POWER(ptype);
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! */
644 if (aia_utype_is_considered_worker(unit_type_get(pvictim))
645 || unit_can_do_action_result(pvictim, ACTRES_FOUND_CITY)) {
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
676 if (action_prob_possible(action_prob_vs_unit(nmap, punit,
677 ACTION_SPY_BRIBE_UNIT,
678 pvictim))) {
679 unit_do_action(pplayer, punit->id,
680 pvictim->id, -1, "",
681 ACTION_SPY_BRIBE_UNIT);
682 /* autoattack might kill us as we move in */
683 if (game_unit_by_number(sanity) && punit->moves_left > 0) {
684 return TRUE;
685 } else {
686 return FALSE;
687 }
688 } else if (action_prob_possible(action_prob_vs_unit(nmap, punit,
689 ACTION_SPY_SABOTAGE_UNIT_ESC,
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, "",
695 ACTION_SPY_SABOTAGE_UNIT_ESC);
696 /* autoattack might kill us as we move in */
697 if (game_unit_by_number(sanity) && punit->moves_left > 0) {
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 }
708 } pf_map_positions_iterate_end;
709
710 return (punit->moves_left > 0);
711}
712
713/**************************************************************************/
723 void 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
733 CHECK_UNIT(punit);
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 */
745 pf_map_destroy(pfm);
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
754 if (count_diplomats_on_tile(unit_tile(punit)) == 1
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 */
760 def_ai_unit_data(punit, ait)->done = TRUE;
761 pf_map_destroy(pfm);
762 return;
763 }
764 }
765
766 unit_data = def_ai_unit_data(punit, ait);
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
773 ctarget = tile_city(punit->goto_tile);
774 if (pf_map_position(pfm, punit->goto_tile, &pos)
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");
794 dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
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) {
803 pf_map_destroy(pfm);
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
816 find_city_to_diplomat(pplayer, punit, &ctarget, &move_dist, pfm);
817
818 if (ctarget) {
819 task = AIUNIT_ATTACK;
820 aiguard_request_guard(ait, punit);
821 UNIT_LOG(LOG_DIPLOMAT, punit, "going on attack");
822 } else if ((ctarget = dai_diplomat_defend(ait, pplayer, punit,
823 unit_type_get(punit), pfm))
824 != NULL) {
825 task = AIUNIT_DEFEND_HOME;
826 UNIT_LOG(LOG_DIPLOMAT, punit, "going to defend %s",
827 city_name_get(ctarget));
828 } else if ((ctarget = find_closest_city(unit_tile(punit), NULL, pplayer,
829 TRUE, FALSE, FALSE, TRUE, FALSE,
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");
839 def_ai_unit_data(punit, ait)->done = TRUE;
840 pf_map_destroy(pfm);
841 return;
842 }
843
844 dai_unit_new_task(ait, punit, task, ctarget->tile);
845 fc_assert(punit->moves_left > 0 && ctarget
846 && unit_data->task != AIUNIT_NONE);
847 }
848
849 CHECK_UNIT(punit);
850 if (ctarget == NULL) {
851 UNIT_LOG(LOG_ERROR, punit, "ctarget not set (task == %d)",
852 unit_data->task);
853 pf_map_destroy(pfm);
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) {
865 int dist = real_map_distance(unit_tile(punit), punit->goto_tile);
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 */
871 dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
872 dai_diplomat_city(ait, punit, ctarget);
873 }
874 }
875 }
876 pf_path_destroy(path);
877 } else {
878 def_ai_unit_data(punit, ait)->done = TRUE;
879 }
880 pf_map_destroy(pfm);
881}
is_action_possible_on_city
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5444
action_get_actor_kind
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1073
action_prob_possible
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5044
action_rule_name
const char * action_rule_name(const struct action *action)
Definition actions.c:1191
action_number
int action_number(const struct action *action)
Definition actions.c:1183
is_action_enabled_unit_on_unit
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:3129
action_prob_vs_city
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:4203
action_get_target_kind
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1083
action_prob_vs_unit
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:4286
actions.h
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:390
action_iterate_end
#define action_iterate_end
Definition actions.h:209
action_iterate
#define action_iterate(_act_)
Definition actions.h:205
ACTION_NONE
#define ACTION_NONE
Definition actions.h:55
advbuilding.h
TRADE_WEIGHTING
#define TRADE_WEIGHTING
Definition advbuilding.h:21
FOOD_WEIGHTING
#define FOOD_WEIGHTING
Definition advbuilding.h:19
SHIELD_WEIGHTING
#define SHIELD_WEIGHTING
Definition advbuilding.h:20
adv_choice_set_use
#define adv_choice_set_use(_choice, _use)
Definition advchoice.h:85
CT_CIVILIAN
@ CT_CIVILIAN
Definition advchoice.h:39
CT_DEFENDER
@ CT_DEFENDER
Definition advchoice.h:41
advdata.h
adv_unit_execute_path
bool adv_unit_execute_path(struct unit *punit, struct pf_path *path)
Definition advgoto.c:86
advgoto.h
aia_utype_is_considered_spy
bool aia_utype_is_considered_spy(const struct unit_type *putype)
Definition aiactions.c:51
aia_utype_is_considered_worker
bool aia_utype_is_considered_worker(const struct unit_type *putype)
Definition aiactions.c:89
aiactions.h
dai_diplomat_defend
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
dai_choose_diplomat_defensive
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
dai_manage_diplomat
void dai_manage_diplomat(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition aidiplomat.c:723
LOG_DIPLOMAT_BUILD
#define LOG_DIPLOMAT_BUILD
Definition aidiplomat.c:78
dai_diplomat_city
static void dai_diplomat_city(struct ai_type *ait, struct unit *punit, struct city *ctarget)
Definition aidiplomat.c:327
dai_choose_diplomat_offensive
void dai_choose_diplomat_offensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice)
Definition aidiplomat.c:166
LOG_DIPLOMAT
#define LOG_DIPLOMAT
Definition aidiplomat.c:77
DIPLO_DEFENSE_WANT
#define DIPLO_DEFENSE_WANT
Definition aidiplomat.c:82
dai_diplomat_bribe_nearby
static bool dai_diplomat_bribe_nearby(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct pf_map *pfm)
Definition aidiplomat.c:588
count_stealable_techs
static int count_stealable_techs(struct player *pplayer, struct player *tplayer)
Definition aidiplomat.c:94
find_city_to_diplomat
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
is_city_surrounded_by_our_spies
static bool is_city_surrounded_by_our_spies(struct player *pplayer, struct city *pcity)
Definition aidiplomat.c:417
aidiplomat.h
aiguard_request_guard
void aiguard_request_guard(struct ai_type *ait, struct unit *punit)
Definition aiguard.c:227
aiguard.h
dai_calc_data
void dai_calc_data(const struct player *pplayer, int *trade, int *expenses, int *income)
Definition aihand.c:117
aihand.h
barbarian.h
bitvector.h
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1133
city_production_unit_veteran_level
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:804
city.h
city_tile
#define city_tile(_pcity_)
Definition city.h:564
INCITE_IMPOSSIBLE_COST
#define INCITE_IMPOSSIBLE_COST
Definition city.h:96
city_owner
#define city_owner(_pcity_)
Definition city.h:563
find_closest_city
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
citytools.h
city_incite_cost
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3438
cityturn.h
combat.h
incite_cost
char * incite_cost
Definition comments.c:74
dai_action_choose_sub_tgt_unit_vs_city
int dai_action_choose_sub_tgt_unit_vs_city(struct action *paction, struct unit *actor_unit, struct city *target_city)
Definition daiactions.c:310
dai_action_value_unit_vs_city
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
daiactions.h
daicity.h
daidata.h
dailog.h
TECH_LOG
#define TECH_LOG(ait, loglevel, pplayer, padvance, msg,...)
Definition dailog.h:36
daimilitary.h
daiplayer.h
def_ai_player_data
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
def_ai_city_data
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition daiplayer.h:42
def_ai_unit_data
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition daiplayer.h:48
dai_unit_new_task
void dai_unit_new_task(struct ai_type *ait, struct unit *punit, enum ai_unit_task task, struct tile *ptile)
Definition daitools.c:641
dai_gold_reserve
int dai_gold_reserve(struct player *pplayer)
Definition daitools.c:1324
military_amortize
adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
Definition daitools.c:117
daitools.h
daiunit.h
POTENTIALLY_HOSTILE_PLAYER
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
Definition daiunit.h:72
ai_unit_task
ai_unit_task
Definition daiunit.h:27
AIUNIT_NONE
@ AIUNIT_NONE
Definition daiunit.h:27
AIUNIT_ATTACK
@ AIUNIT_ATTACK
Definition daiunit.h:28
AIUNIT_DEFEND_HOME
@ AIUNIT_DEFEND_HOME
Definition daiunit.h:28
DEFENSE_POWER
#define DEFENSE_POWER(ptype)
Definition daiunit.h:66
ATTACK_POWER
#define ATTACK_POWER(ptype)
Definition daiunit.h:68
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
cost
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
diplomats_unignored_tech_stealings
int diplomats_unignored_tech_stealings(struct unit *pdiplomat, struct city *pcity)
Definition diplomats.c:851
count_diplomats_on_tile
int count_diplomats_on_tile(struct tile *ptile)
Definition diplomats.c:2377
diplomats.h
adv_want
float adv_want
Definition fc_types.h:1335
ADV_WANT_PRINTF
#define ADV_WANT_PRINTF
Definition fc_types.h:1336
O_SHIELD
@ O_SHIELD
Definition fc_types.h:101
O_FOOD
@ O_FOOD
Definition fc_types.h:101
O_SCIENCE
@ O_SCIENCE
Definition fc_types.h:101
O_LUXURY
@ O_LUXURY
Definition fc_types.h:101
O_GOLD
@ O_GOLD
Definition fc_types.h:101
game
struct civ_game game
Definition game.c:61
wld
struct world wld
Definition game.c:62
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:115
game.h
government.h
pos
static struct tile * pos
Definition finddlg.c:53
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps.h
H_MAP
@ H_MAP
Definition handicaps.h:28
H_DIPLOMAT
@ H_DIPLOMAT
Definition handicaps.h:18
H_NOBRIBE_WF
@ H_NOBRIBE_WF
Definition handicaps.h:34
H_FOG
@ H_FOG
Definition handicaps.h:26
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
log_base
#define log_base(level, message,...)
Definition log.h:94
LOG_ERROR
@ LOG_ERROR
Definition log.h:30
LOG_DEBUG
@ LOG_DEBUG
Definition log.h:34
same_pos
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:950
real_map_distance
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:636
mapstep
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:375
map.h
adjc_iterate_end
#define adjc_iterate_end
Definition map.h:419
adjc_iterate
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:414
DIR_REVERSE
#define DIR_REVERSE(dir)
Definition map.h:547
map_is_known_and_seen
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:927
maphand.h
mem.h
unit_move_rate
int unit_move_rate(const struct unit *punit)
Definition movement.c:89
movement.h
nation_rule_name
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
nation_of_unit
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
nation.h
packets.h
pf_path_destroy
void pf_path_destroy(struct pf_path *path)
Definition path_finding.c:3411
pf_map_new
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
Definition path_finding.c:3182
pf_map_path
struct pf_path * pf_map_path(struct pf_map *pfm, struct tile *ptile)
Definition path_finding.c:3235
pf_map_position
bool pf_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
Definition path_finding.c:3267
pf_map_destroy
void pf_map_destroy(struct pf_map *pfm)
Definition path_finding.c:3206
pf_map_move_costs_iterate_end
#define pf_map_move_costs_iterate_end
Definition path_finding.h:592
pf_map_positions_iterate_end
#define pf_map_positions_iterate_end
Definition path_finding.h:612
pf_map_move_costs_iterate
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
Definition path_finding.h:582
pf_map_positions_iterate
#define pf_map_positions_iterate(ARG_pfm, NAME_pos, COND_from_start)
Definition path_finding.h:605
pft_fill_unit_parameter
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:843
no_intermediate_fights
enum tile_behavior no_intermediate_fights(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:526
pf_tools.h
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:895
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
player_has_embassy
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:208
player.h
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
is_ai
#define is_ai(plr)
Definition player.h:232
research_total_bulbs_required
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Definition research.c:868
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
research.h
shared.h
MAX
#define MAX(x, y)
Definition shared.h:54
srv_log.h
UNIT_LOG
#define UNIT_LOG(loglevel, punit, msg,...)
Definition srv_log.h:98
action
Definition actions.h:106
adv_choice
Definition advchoice.h:45
adv_choice::type
enum choice_type type
Definition advchoice.h:46
adv_choice::want
adv_want want
Definition advchoice.h:48
adv_choice::value
universals_u value
Definition advchoice.h:47
adv_choice::need_boat
bool need_boat
Definition advchoice.h:49
ai_city
Definition daicity.h:34
ai_city::has_diplomat
bool has_diplomat
Definition daicity.h:59
ai_city::urgency
unsigned int urgency
Definition daicity.h:49
ai_city::diplomat_threat
bool diplomat_threat
Definition daicity.h:58
ai_plr
Definition daidata.h:71
ai_plr::tech_want
adv_want tech_want[A_LAST+1]
Definition daidata.h:104
ai_plr::diplomat_reservations
bv_id diplomat_reservations
Definition daidata.h:85
ai_plr::stats
struct ai_plr::@276 stats
ai_type
Definition ai.h:50
city
Definition city.h:320
city::id
int id
Definition city.h:326
city::tile
struct tile * tile
Definition city.h:322
civ_game::diplchance
int diplchance
Definition game.h:138
civ_game::server
struct civ_game::@31::@35 server
civ_map
Definition map_types.h:71
pf_map
Definition path_finding.c:78
pf_parameter
Definition path_finding.h:357
pf_parameter::get_TB
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition path_finding.h:398
pf_parameter::get_zoc
bool(* get_zoc)(const struct player *pplayer, const struct tile *ptile, const struct civ_map *zmap)
Definition path_finding.h:430
pf_parameter::omniscience
bool omniscience
Definition path_finding.h:376
pf_parameter::start_tile
struct tile * start_tile
Definition path_finding.h:359
pf_path
Definition path_finding.h:344
pf_position
Definition path_finding.h:327
player_economic::gold
int gold
Definition player.h:63
player
Definition player.h:249
player::economic
struct player_economic economic
Definition player.h:284
research
Definition research.h:39
research::techs_researched
int techs_researched
Definition research.h:42
tile
Definition tile.h:50
tile::units
struct unit_list * units
Definition tile.h:58
unit_ai
Definition daiunit.h:32
unit_ai::done
bool done
Definition daiunit.h:44
unit_type
Definition unittype.h:507
unit
Definition unit.h:140
unit::moves_left
int moves_left
Definition unit.h:152
unit::id
int id
Definition unit.h:147
unit::tile
struct tile * tile
Definition unit.h:142
unit::goto_tile
struct tile * goto_tile
Definition unit.h:157
world::map
struct civ_map map
Definition world_object.h:38
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
advance_index
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
advance_index_iterate_end
#define advance_index_iterate_end
Definition tech.h:249
A_FIRST
#define A_FIRST
Definition tech.h:44
advance_index_iterate
#define advance_index_iterate(_start, _index)
Definition tech.h:245
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:43
timing.h
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:698
unit_bribe_cost
int unit_bribe_cost(const struct unit *punit, const struct player *briber, const struct unit *briber_unit)
Definition unit.c:2345
unit_can_do_action_result
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:396
unit_virtual_create
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1662
tile_other_players_unit
struct unit * tile_other_players_unit(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1361
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1767
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:397
CHECK_UNIT
#define CHECK_UNIT(punit)
Definition unit.h:273
unit_owner
#define unit_owner(_pu)
Definition unit.h:396
unit_activity_handling
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity, enum gen_action trigger_action)
Definition unithand.c:6613
unit_do_action
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:3317
unithand.h
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unittools.h
best_role_unit
struct unit_type * best_role_unit(const struct city *pcity, int role)
Definition unittype.c:2271
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
get_role_unit
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2253
unit_rule_name
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1587
num_role_units
int num_role_units(int role)
Definition unittype.c:2203
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
utype_build_shield_cost
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1438
utype_can_do_action
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
unit_tech_reqs_iterate_end
#define unit_tech_reqs_iterate_end
Definition unittype.h:885
unit_tech_reqs_iterate
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:879