Freeciv-3.3
Loading...
Searching...
No Matches
daitools.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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
24/* common */
25#include "city.h"
26#include "combat.h"
27#include "game.h"
28#include "government.h"
29#include "map.h"
30#include "movement.h"
31#include "nation.h"
32#include "packets.h"
33#include "player.h"
34#include "unit.h"
35#include "unitlist.h"
36
37/* common/aicore */
38#include "citymap.h"
39#include "pf_tools.h"
40
41/* server */
42#include "barbarian.h"
43#include "citytools.h"
44#include "cityturn.h"
45#include "maphand.h"
46#include "plrhand.h"
47#include "score.h"
48#include "srv_log.h"
49#include "unithand.h"
50#include "unittools.h"
51
52/* server/advisors */
53#include "advdata.h"
54#include "advgoto.h"
55#include "advtools.h"
56#include "infracache.h"
57
58/* ai */
59#include "handicaps.h"
60
61/* ai/default */
62#include "aiferry.h"
63#include "aiguard.h"
64#include "daidata.h"
65#include "dailog.h"
66#include "daimilitary.h"
67#include "daiplayer.h"
68#include "daitech.h"
69
70#include "daitools.h"
71
72/**********************************************************************/
76const char *dai_unit_task_rule_name(const enum ai_unit_task task)
77{
78 switch (task) {
79 case AIUNIT_NONE:
80 return "None";
82 return "Auto worker";
84 return "Build city";
86 return "Defend home";
87 case AIUNIT_ATTACK:
88 return "Attack";
89 case AIUNIT_ESCORT:
90 return "Escort";
91 case AIUNIT_EXPLORE:
92 return "Explore";
93 case AIUNIT_RECOVER:
94 return "Recover";
95 case AIUNIT_HUNTER:
96 return "Hunter";
97 case AIUNIT_TRADE:
98 return "Trade";
99 case AIUNIT_WONDER:
100 return "Wonder";
101 }
102
103 /* No default, ensure all types handled somehow */
104 log_error("Unsupported ai_unit_task %d.", task);
105
106 return NULL;
107}
108
109/**********************************************************************/
117adv_want military_amortize(struct player *pplayer, struct city *pcity,
118 adv_want value, int delay, int build_cost)
119{
120 struct adv_data *ai = adv_data_get(pplayer, NULL);
121 int city_output = (pcity ? pcity->surplus[O_SHIELD] : 1);
122 int output = MAX(city_output, ai->stats.average_production);
123 int build_time = build_cost / MAX(output, 1);
124
125 if (value <= 0) {
126 return 0;
127 }
128
129 return amortize(value, delay + build_time);
130}
131
132/**********************************************************************/
141void dai_consider_plr_dangerous(struct ai_type *ait, struct player *plr1,
142 struct player *plr2,
143 enum override_bool *result)
144{
145 struct ai_dip_intel *adip;
146
147 adip = dai_diplomacy_get(ait, plr1, plr2);
148
149 if (adip->countdown >= 0) {
150 /* Don't trust our war target */
151 *result = OVERRIDE_TRUE;
152 }
153}
154
155/**********************************************************************/
160static bool dai_gothere_bodyguard(struct ai_type *ait,
161 struct unit *punit, struct tile *dest_tile)
162{
163 struct player *pplayer = unit_owner(punit);
164 unsigned int danger = 0;
165 struct city *dcity;
166 struct unit *guard = aiguard_guard_of(ait, punit);
167 const struct veteran_level *vlevel;
168 bool bg_needed = FALSE;
169
171 /* barbarians must have more courage (ie less brains) */
173 return FALSE;
174 }
175
176 /* Estimate enemy attack power. */
177 unit_list_iterate(dest_tile->units, aunit) {
178 if (POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, unit_owner(aunit))) {
179 danger += adv_unit_att_rating(aunit);
180 }
182 dcity = tile_city(dest_tile);
183 if (dcity && POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, city_owner(dcity))) {
184 /* Assume enemy will build another defender, add it's attack strength */
186
187 if (d_type) {
188 /* Enemy really can build something */
189 danger +=
192 SINGLE_MOVE, d_type->hp);
193 }
194 }
195 danger *= POWER_DIVIDER;
196
197 /* If we are fast, there is less danger.
198 * FIXME: that assumes that most units have move_rate == SINGLE_MOVE;
199 * not true for all rulesets */
202 danger /= 1.5;
203 }
204
207
208 /* We look for the bodyguard where we stand. */
209 if (guard == NULL || unit_tile(guard) != unit_tile(punit)) {
211 * POWER_FACTOR * vlevel->power_fact / 100);
212
213 if (danger >= my_def) {
215 "want bodyguard @(%d, %d) danger=%d, my_def=%d",
216 TILE_XY(dest_tile), danger, my_def);
218 bg_needed = TRUE;
219 } else {
222 }
223 } else if (guard != NULL) {
224 bg_needed = TRUE;
225 }
226
227 /* What if we have a bodyguard, but don't need one? */
228
229 return bg_needed;
230}
231
232#define LOGLEVEL_GOTHERE LOG_DEBUG
233/**********************************************************************/
242bool dai_gothere(struct ai_type *ait, struct player *pplayer,
243 struct unit *punit, struct tile *dest_tile)
244{
246 bool bg_needed;
247
248 if (same_pos(dest_tile, unit_tile(punit)) || punit->moves_left <= 0) {
249 /* Nowhere to go */
250 return TRUE;
251 }
252
253 /* See if we need a bodyguard at our destination */
254 /* FIXME: If bodyguard is _really_ necessary, don't go anywhere */
255 bg_needed = dai_gothere_bodyguard(ait, punit, dest_tile);
256
258 || !goto_is_sane(punit, dest_tile)) {
259 /* Must go by boat, call an aiferryboat function */
260 if (!aiferry_gobyboat(ait, pplayer, punit, dest_tile,
261 bg_needed)) {
262 return FALSE;
263 }
264 }
265
266 /* Go where we should be going if we can, and are at our destination
267 * if we are on a ferry */
268 if (goto_is_sane(punit, dest_tile) && punit->moves_left > 0) {
269 punit->goto_tile = dest_tile;
270 UNIT_LOG(LOGLEVEL_GOTHERE, punit, "Walking to (%d,%d)", TILE_XY(dest_tile));
271 if (!dai_unit_goto(ait, punit, dest_tile)) {
272 /* died */
273 return FALSE;
274 }
275 /* liable to bump into someone that will kill us. Should avoid? */
276 } else {
277 UNIT_LOG(LOGLEVEL_GOTHERE, punit, "Not moving");
278 return FALSE;
279 }
280
281 if (def_ai_unit_data(punit, ait)->ferryboat > 0
282 && !unit_transported(punit)) {
283 /* We probably just landed, release our boat */
285 }
286
287 /* Dead unit shouldn't reach this point */
289
290 return (same_pos(unit_tile(punit), dest_tile)
291 || is_tiles_adjacent(unit_tile(punit), dest_tile));
292}
293
294/**********************************************************************/
301 struct tile *dest_tile)
302{
303 const struct civ_map *nmap = &(wld.map);
304
305 if (!same_pos(unit_tile(punit), dest_tile)
307 struct pf_parameter parameter;
308 struct pf_map *pfm;
309 struct pf_path *path;
310 size_t i;
311 struct player *pplayer = unit_owner(punit);
312
313 pft_fill_unit_parameter(&parameter, nmap, punit);
314 parameter.omniscience = !has_handicap(pplayer, H_MAP);
315 pfm = pf_map_new(&parameter);
316 path = pf_map_path(pfm, punit->goto_tile);
317
318 if (path) {
319 for (i = 1; i < path->length; i++) {
320 if (path->positions[i].tile == path->positions[i - 1].tile) {
321 /* The path-finding code advices us to wait there to refuel. */
322 struct tile *ptile = path->positions[i].tile;
323
324 pf_path_destroy(path);
326 return ptile;
327 }
328 }
329 pf_path_destroy(path);
331 /* Seems it's the immediate destination */
332 return punit->goto_tile;
333 }
334
336 log_verbose("Did not find an air-route for "
337 "%s %s[%d] (%d,%d)->(%d,%d)",
340 punit->id,
342 TILE_XY(dest_tile));
343 /* Prevent take off */
344 return unit_tile(punit);
345 }
346
347 /* else does not need way-points */
348 return dest_tile;
349}
350
351/**********************************************************************/
355 struct pf_path *path, struct pf_parameter *parameter)
356{
357 const struct pf_position *last = pf_path_last_position(path);
358 const unsigned cc = PF_TURN_FACTOR * last->total_MC
359 + parameter->move_rate * last->total_EC;
360 const unsigned tc = cc / (PF_TURN_FACTOR * parameter->move_rate);
361
362 UNIT_LOG(LOG_DEBUG, punit, "path L=%d T=%d(%u) MC=%u EC=%u CC=%u",
363 path->length - 1, last->turn, tc,
364 last->total_MC, last->total_EC, cc);
365}
366
367/**********************************************************************/
376bool dai_unit_goto_constrained(struct ai_type *ait, struct unit *punit,
377 struct tile *ptile,
378 struct pf_parameter *parameter)
379{
380 bool alive = TRUE;
381 struct pf_map *pfm;
382 struct pf_path *path;
383
384 UNIT_LOG(LOG_DEBUG, punit, "constrained goto to %d,%d", TILE_XY(ptile));
385
386 if (same_pos(unit_tile(punit), ptile)) {
387 /* Was not an error in previous versions but now is dubious... */
388 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: already there!");
390
391 return TRUE;
392 } else if (!goto_is_sane(punit, ptile)) {/* FIXME: why do we check it? */
393 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: 'insane' goto!");
396
397 return TRUE;
398 } else if (punit->moves_left == 0) {
399 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: no moves left!");
401
402 return TRUE;
403 }
404
405 pfm = pf_map_new(parameter);
406 path = pf_map_path(pfm, ptile);
407
408 if (path) {
409 dai_log_path(punit, path, parameter);
410 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: following path.");
411 alive = adv_follow_path(punit, path, ptile);
412 } else {
413 UNIT_LOG(LOG_DEBUG, punit, "no path to destination");
414 }
415
416 pf_path_destroy(path);
418
419 return alive;
420}
421
422/**********************************************************************/
427bool goto_is_sane(struct unit *punit, struct tile *ptile)
428{
429 bool can_get_there = FALSE;
430 const struct civ_map *nmap = &(wld.map);
431
432 if (same_pos(unit_tile(punit), ptile)) {
434 } else {
435 struct pf_parameter parameter;
436 struct pf_map *pfm;
437
439 pfm = pf_map_new(&parameter);
440
441 if (pf_map_move_cost(pfm, ptile) != PF_IMPOSSIBLE_MC) {
443 }
445 }
446 return can_get_there;
447}
448
449/*
450 * The length of time, in turns, which is long enough to be optimistic
451 * that enemy units will have moved from their current position.
452 * WAG
453 */
454#define LONG_TIME 4
455/**********************************************************************/
467void dai_fill_unit_param(struct ai_type *ait, struct pf_parameter *parameter,
468 struct adv_risk_cost *risk_cost,
469 struct unit *punit, struct tile *ptile)
470{
475 const bool barbarian = is_barbarian(unit_owner(punit));
476 bool is_ferry;
477 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
478 struct player *pplayer = unit_owner(punit);
479 const struct civ_map *nmap = &(wld.map);
480
481 /* This function is now always omniscient and should not be used
482 * for human players any more. */
483 fc_assert(is_ai(pplayer));
484
485 /* If a unit is hunting, don't expect it to be a ferry. */
487 && dai_is_ferry(punit, ait));
488
489 if (is_ferry) {
490 /* The destination may be a coastal land tile,
491 * in which case the ferry should stop on an adjacent tile. */
493 } else if (!utype_fuel(unit_type_get(punit))
496 && (unit_data->task == AIUNIT_DEFEND_HOME
497 || unit_data->task == AIUNIT_ATTACK
498 || unit_data->task == AIUNIT_ESCORT
499 || unit_data->task == AIUNIT_HUNTER)) {
500 /* Use attack movement for defenders and escorts so they can
501 * make defensive attacks */
503 } else {
505 }
506 parameter->omniscience = !has_handicap(pplayer, H_MAP);
507
508 /* Should we use the risk avoidance code?
509 * The risk avoidance code uses omniscience, so do not use for
510 * human-player units under temporary AI control.
511 * Barbarians bravely/stupidly ignore risks
512 */
514 && !barbarian) {
516 }
517
518 /* Should we absolutely forbid ending a turn on a dangerous tile?
519 * Do not annoy human players by killing their units for them.
520 * For AI units be optimistic; allows attacks across dangerous terrain,
521 * and polar settlements.
522 * TODO: This is compatible with old code,
523 * but probably ought to be more cautious for non military units
524 */
526 parameter->get_moves_left_req = NULL;
527 }
528
529 if (long_path) {
530 /* Move as far along the path to the destination as we can;
531 * that is, ignore the presence of enemy units when computing the
532 * path.
533 * Hopefully, ai_avoid_risks will have produced a path that avoids enemy
534 * ZoCs. Ignoring ZoCs allows us to move closer to a destination
535 * for which there is not yet a clear path.
536 * That is good if the destination is several turns away,
537 * so we can reasonably expect blocking enemy units to move or
538 * be destroyed. But it can be bad if the destination is one turn away
539 * or our destination is far but there are enemy units near us and on the
540 * shortest path to the destination.
541 */
542 parameter->get_zoc = NULL;
543 }
544
546 parameter->get_TB = no_fights;
547 } else if (long_path && unit_is_cityfounder(punit)) {
548 /* Default tile behaviour;
549 * move as far along the path to the destination as we can;
550 * that is, ignore the presence of enemy units when computing the
551 * path.
552 */
553 } else if (unit_is_cityfounder(punit)) {
554 /* Short path */
555 parameter->get_TB = no_fights;
557 /* Avoid capture */
558 parameter->get_TB = no_fights;
559 } else if (is_ferry) {
560 /* Ferries are not warships */
561 parameter->get_TB = no_fights;
562 } else if (is_losing_hp(punit)) {
563 /* Losing hitpoints over time (helicopter in default rules) */
564 /* Default tile behaviour */
566 switch (unit_data->task) {
569 /* Strange, but not impossible */
570 parameter->get_TB = no_fights;
571 break;
573 case AIUNIT_ATTACK: /* Includes spy actions */
574 case AIUNIT_ESCORT:
575 case AIUNIT_HUNTER:
576 case AIUNIT_TRADE:
577 case AIUNIT_WONDER:
578 parameter->get_TB = no_intermediate_fights;
579 break;
580 case AIUNIT_EXPLORE:
581 case AIUNIT_RECOVER:
582 parameter->get_TB = no_fights;
583 break;
584 case AIUNIT_NONE:
585 /* Default tile behaviour */
586 break;
587 }
588 } else {
589 /* Probably an explorer */
590 parameter->get_TB = no_fights;
591 }
592
593 if (is_ferry) {
594 /* Show the destination in the client when watching an AI: */
595 punit->goto_tile = ptile;
596 }
597}
598
599/**********************************************************************/
603bool dai_unit_goto(struct ai_type *ait, struct unit *punit, struct tile *ptile)
604{
605 struct pf_parameter parameter;
607
608 UNIT_LOG(LOG_DEBUG, punit, "dai_unit_goto to %d,%d", TILE_XY(ptile));
609 dai_fill_unit_param(ait, &parameter, &risk_cost, punit, ptile);
610
611 return dai_unit_goto_constrained(ait, punit, ptile, &parameter);
612}
613
614/**********************************************************************/
617void dai_unit_new_adv_task(struct ai_type *ait, struct unit *punit,
618 enum adv_unit_task task, struct tile *ptile)
619{
620 /* Keep ai_unit_task in sync with adv task */
621 switch (task) {
622 case AUT_AUTO_WORKER:
624 break;
625 case AUT_BUILD_CITY:
627 break;
628 case AUT_NONE:
629 dai_unit_new_task(ait, punit, AIUNIT_NONE, ptile);
630 break;
631 }
632}
633
634/**********************************************************************/
641void dai_unit_new_task(struct ai_type *ait, struct unit *punit,
642 enum ai_unit_task task, struct tile *ptile)
643{
644 struct unit *bodyguard = aiguard_guard_of(ait, punit);
645 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
646
647 /* If the unit is under (human) orders we shouldn't control it.
648 * Allow removal of old role with AIUNIT_NONE. */
650
651 UNIT_LOG(LOG_DEBUG, punit, "changing task from %s to %s",
654
655 /* Free our ferry. Most likely it has been done already. */
658 }
659
660 if (punit->activity == ACTIVITY_GOTO) {
661 /* It would indicate we're going somewhere otherwise */
663 }
664
665 if (unit_data->task == AIUNIT_BUILD_CITY) {
666 if (punit->goto_tile) {
668 } else {
669 /* Print error message instead of crashing in citymap_free_city_spot()
670 * This probably means that some city spot reservation has not been
671 * properly cleared; bad for the AI, as it will leave that area
672 * uninhabited. */
673 log_error("%s was on city founding mission without target tile.",
675 }
676 }
677
678 if (unit_data->task == AIUNIT_HUNTER) {
679 /* Clear victim's hunted bit - we're no longer chasing. */
680 struct unit *target = game_unit_by_number(unit_data->target);
681
682 if (target) {
683 BV_CLR(def_ai_unit_data(target, ait)->hunted,
685 UNIT_LOG(LOGLEVEL_HUNT, target, "no longer hunted (new task %d, old %d)",
686 task, unit_data->task);
687 }
688 }
689
691 /* Record the city to defend; our goto may be to transport. */
692 if (task == AIUNIT_DEFEND_HOME && ptile && tile_city(ptile)) {
694 }
695
696 unit_data->task = task;
697
698 /* Verify and set the goto destination. Eventually this can be a lot more
699 * stringent, but for now we don't want to break things too badly. */
700 punit->goto_tile = ptile; /* May be NULL. */
701
702 if (unit_data->task == AIUNIT_NONE && bodyguard) {
703 dai_unit_new_task(ait, bodyguard, AIUNIT_NONE, NULL);
704 }
705
706 /* Reserve city spot, _unless_ we want to add ourselves to a city. */
707 if (unit_data->task == AIUNIT_BUILD_CITY && !tile_city(ptile)) {
709 }
710 if (unit_data->task == AIUNIT_HUNTER) {
711 /* Set victim's hunted bit - the hunt is on! */
712 struct unit *target = game_unit_by_number(unit_data->target);
713
714 fc_assert_ret(target != NULL);
715 BV_SET(def_ai_unit_data(target, ait)->hunted, player_index(unit_owner(punit)));
716 UNIT_LOG(LOGLEVEL_HUNT, target, "is being hunted");
717
718 /* Grab missiles lying around and bring them along */
721 && def_ai_unit_data(missile, ait)->task != AIUNIT_ESCORT
727 UNIT_LOG(LOGLEVEL_HUNT, missile, "loaded on hunter");
730 }
732 }
733
734 /* Map ai tasks to advisor tasks. For most ai tasks there is
735 no advisor, so AUT_NONE is set. */
736 switch (unit_data->task) {
739 break;
742 break;
743 default:
745 break;
746 }
747}
748
749/**********************************************************************/
753bool dai_unit_make_homecity(struct unit *punit, struct city *pcity)
754{
757
759 /* This unit doesn't pay any upkeep while it doesn't have a homecity,
760 * so it would be stupid to give it one. There can also be good reasons
761 * why it doesn't have a homecity. */
762 /* However, until we can do something more useful with them, we
763 will assign explorers to a city so that they can be disbanded for
764 the greater good -- Per */
765 return FALSE;
766 }
768 && pcity->surplus[O_FOOD] >= unit_type_get(punit)->upkeep[O_FOOD]) {
770 0, "", ACTION_HOME_CITY);
771 return TRUE;
772 }
773 return FALSE;
774}
775
776/**********************************************************************/
782static void dai_unit_bodyguard_move(struct ai_type *ait,
783 struct unit *bodyguard, struct tile *ptile)
784{
785 fc_assert_ret(bodyguard != NULL);
786 fc_assert_ret(unit_owner(bodyguard) != NULL);
787
788#ifndef FREECIV_NDEBUG
789 struct unit *punit =
790#endif
791 aiguard_charge_unit(ait, bodyguard);
792
794
795 CHECK_GUARD(ait, bodyguard);
797
798 if (!is_tiles_adjacent(ptile, unit_tile(bodyguard))) {
799 return;
800 }
801
802 if (bodyguard->moves_left <= 0) {
803 /* Should generally not happen */
804 BODYGUARD_LOG(ait, LOG_DEBUG, bodyguard, "was left behind by charge");
805 return;
806 }
807
809 (void) dai_unit_move(ait, bodyguard, ptile);
810}
811
812/**********************************************************************/
815bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile)
816{
817 struct unit *ptrans;
818 struct unit *bodyguard = aiguard_guard_of(ait, punit);
819 int sanity = punit->id;
820 bool alive;
821 struct city *tcity;
822 const struct civ_map *nmap = &(wld.map);
823
827
829 /* FIXME: try the next action if the unit tried to do an illegal action.
830 * That would allow the AI to stop using the omniscient
831 * is_action_enabled_unit_on_*() functions. */
833 punit, ptile)) {
834 /* Choose capture. */
836 0, "", ACTION_CAPTURE_UNITS);
838 punit, ptile)) {
839 /* Choose "Bombard Lethal". */
841 0, "", ACTION_BOMBARD_LETHAL);
843 punit, ptile)) {
844 /* Choose "Bombard". */
846 0, "", ACTION_BOMBARD);
848 punit, ptile)) {
849 /* Choose "Bombard 2". */
851 0, "", ACTION_BOMBARD2);
853 punit, ptile)) {
854 /* Choose "Bombard 3". */
856 0, "", ACTION_BOMBARD3);
858 punit, ptile)) {
859 /* Choose "Nuke Units". */
861 0, "", ACTION_NUKE_UNITS);
864 punit, ptile, NULL)) {
865 /* Choose "Explode Nuclear". */
867 0, "", ACTION_NUKE);
869 && (tcity = tile_city(ptile))
871 punit, tcity)) {
872 /* Choose "Explode Nuclear". */
874 0, "", ACTION_NUKE);
877 punit, ptile, NULL)) {
878 /* Choose "Nuke City". */
880 0, "", ACTION_NUKE_CITY);
882 && (tcity = tile_city(ptile))
884 punit, tcity)) {
885 /* Choose "Nuke City". */
887 0, "", ACTION_NUKE_CITY);
889 punit, ptile)) {
890 /* Choose regular attack. */
892 0, "", ACTION_ATTACK);
894 punit, ptile)) {
895 /* Choose suicide attack (explode missile). */
897 0, "", ACTION_SUICIDE_ATTACK);
898 } else if ((tcity = tile_city(ptile))
900 punit, tcity)) {
901 /* Choose "Conquer City". */
903 0, "", ACTION_CONQUER_CITY);
904 } else if ((tcity = tile_city(ptile))
906 punit, tcity)) {
907 /* Choose "Conquer City 2". */
909 0, "", ACTION_CONQUER_CITY2);
910 } else if ((tcity = tile_city(ptile))
912 punit, tcity)) {
913 /* Choose "Conquer City 3". */
915 0, "", ACTION_CONQUER_CITY3);
916 } else if ((tcity = tile_city(ptile))
918 punit, tcity)) {
919 /* Choose "Conquer City 4". */
921 0, "", ACTION_CONQUER_CITY4);
922 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
923 && ((ptrans = transporter_for_unit_at(punit, ptile)))
925 punit, ptrans)) {
926 /* "Transport Embark". */
929 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
930 && ((ptrans = transporter_for_unit_at(punit, ptile)))
932 punit, ptrans)) {
933 /* "Transport Embark 2". */
936 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
937 && ((ptrans = transporter_for_unit_at(punit, ptile)))
939 punit, ptrans)) {
940 /* "Transport Embark 3". */
943 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
944 && ((ptrans = transporter_for_unit_at(punit, ptile)))
946 punit, ptrans)) {
947 /* "Transport Embark 4". */
951 punit, ptile, NULL)) {
952 /* "Transport Disembark". */
956 punit, ptile, NULL)) {
957 /* "Transport Disembark 2". */
961 punit, ptile, NULL)) {
962 /* "Transport Disembark 3". */
966 punit, ptile, NULL)) {
967 /* "Transport Disembark 4". */
972 punit, ptile, NULL)) {
973 /* Choose "Conquer Extras". */
975 0, "", ACTION_CONQUER_EXTRAS);
978 punit, ptile, NULL)) {
979 /* Choose "Conquer Extras 2". */
984 punit, ptile, NULL)) {
985 /* Choose "Conquer Extras 3". */
990 punit, ptile, NULL)) {
991 /* Choose "Conquer Extras 4". */
995 punit, ptile, NULL)) {
996 /* Choose "Enter Hut". */
998 0, "", ACTION_HUT_ENTER);
1000 punit, ptile, NULL)) {
1001 /* Choose "Enter Hut 2". */
1003 0, "", ACTION_HUT_ENTER2);
1005 punit, ptile, NULL)) {
1006 /* Choose "Enter Hut 3". */
1008 0, "", ACTION_HUT_ENTER3);
1010 punit, ptile, NULL)) {
1011 /* Choose "Enter Hut 4". */
1013 0, "", ACTION_HUT_ENTER4);
1015 punit, ptile, NULL)) {
1016 /* Choose "Frighten Hut". */
1018 0, "", ACTION_HUT_FRIGHTEN);
1020 punit, ptile, NULL)) {
1021 /* Choose "Frighten Hut 2". */
1023 0, "", ACTION_HUT_FRIGHTEN2);
1025 punit, ptile, NULL)) {
1026 /* Choose "Frighten Hut 3". */
1028 0, "", ACTION_HUT_FRIGHTEN3);
1030 punit, ptile, NULL)) {
1031 /* Choose "Frighten Hut 4". */
1033 0, "", ACTION_HUT_FRIGHTEN4);
1035 punit, ptile, NULL)) {
1036 /* Choose "Unit Move". */
1038 0, "", ACTION_UNIT_MOVE);
1040 punit, ptile, NULL)) {
1041 /* Choose "Unit Move 2". */
1043 0, "", ACTION_UNIT_MOVE2);
1044 } else {
1045 /* Choose "Unit Move 3". */
1047 0, "", ACTION_UNIT_MOVE3);
1048 }
1050
1051 if (alive && same_pos(ptile, unit_tile(punit))
1052 && bodyguard != NULL && def_ai_unit_data(bodyguard, ait)->charge == punit->id) {
1053 dai_unit_bodyguard_move(ait, bodyguard, ptile);
1054 /* Clumsy bodyguard might trigger an auto-attack */
1056 }
1057
1058 return alive;
1059}
1060
1061/**********************************************************************/
1064void dai_unit_move_or_attack(struct ai_type *ait, struct unit *punit,
1065 struct tile *ptile, struct pf_path *path, int step)
1066{
1067 if (step == path->length - 1) {
1068 (void) dai_unit_attack(ait, punit, ptile);
1069 } else {
1070 (void) dai_unit_move(ait, punit, ptile);
1071 }
1072}
1073
1074/**********************************************************************/
1082bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile)
1083{
1084 struct action *paction;
1085 struct unit *bodyguard;
1086 struct unit *ptrans = NULL;
1087 int sanity = punit->id;
1088 struct player *pplayer = unit_owner(punit);
1089 const bool is_plr_ai = is_ai(pplayer);
1090 const struct civ_map *nmap = &(wld.map);
1091
1094 "Tiles not adjacent: Unit = %d, "
1095 "from = (%d, %d]) to = (%d, %d).",
1097 TILE_XY(ptile));
1098
1099 /* if enemy, stop and give a chance for the ai attack function
1100 * to handle this case */
1101 if (is_enemy_unit_tile(ptile, pplayer)
1102 || is_enemy_city_tile(ptile, pplayer)) {
1103 UNIT_LOG(LOG_DEBUG, punit, "movement halted due to enemy presence");
1104 return FALSE;
1105 }
1106
1107 /* barbarians shouldn't enter huts */
1108 /* FIXME: use unit_can_displace_hut(punit, ptile) better */
1109 if (is_barbarian(pplayer) && hut_on_tile(ptile)) {
1110 return FALSE;
1111 }
1112
1113 /* don't leave bodyguard behind */
1114 if (is_plr_ai
1115 && (bodyguard = aiguard_guard_of(ait, punit))
1116 && same_pos(unit_tile(punit), unit_tile(bodyguard))
1117 && bodyguard->moves_left == 0) {
1118 UNIT_LOG(LOGLEVEL_BODYGUARD, punit, "does not want to leave "
1119 "its bodyguard");
1120 return FALSE;
1121 }
1122
1123 /* Select move kind. */
1124 if (!can_unit_survive_at_tile(nmap, punit, ptile)
1125 && ((ptrans = transporter_for_unit_at(punit, ptile)))
1127 punit, ptrans)) {
1128 /* "Transport Embark". */
1130 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
1131 && ptrans != NULL
1133 punit, ptrans)) {
1134 /* "Transport Embark 2". */
1136 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
1137 && ptrans != NULL
1139 punit, ptrans)) {
1140 /* "Transport Embark 3". */
1142 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
1143 && ptrans != NULL
1145 punit, ptrans)) {
1146 /* "Transport Embark 4". */
1149 punit, ptile, NULL)) {
1150 /* "Transport Disembark". */
1153 punit, ptile, NULL)) {
1154 /* "Transport Disembark 2". */
1157 punit, ptile, NULL)) {
1158 /* "Transport Disembark 3". */
1161 punit, ptile, NULL)) {
1162 /* "Transport Disembark 4". */
1165 punit, ptile, NULL)) {
1166 /* "Enter Hut". */
1169 punit, ptile, NULL)) {
1170 /* "Enter Hut 2". */
1173 punit, ptile, NULL)) {
1174 /* "Enter Hut 3". */
1177 punit, ptile, NULL)) {
1178 /* "Enter Hut 4". */
1181 punit, ptile, NULL)) {
1182 /* "Frighten Hut". */
1185 punit, ptile, NULL)) {
1186 /* "Frighten Hut 2". */
1189 punit, ptile, NULL)) {
1190 /* "Frighten Hut 3". */
1193 punit, ptile, NULL)) {
1194 /* "Frighten Hut 4". */
1197 punit, ptile, NULL)) {
1198 /* "Unit Move". */
1201 punit, ptile, NULL)) {
1202 /* "Unit Move 2". */
1204 } else {
1205 /* "Unit Move 3". */
1207 }
1208
1209 /* Try not to end move next to an enemy if we can avoid it by waiting */
1212 /* The unit will have to move it self rather than being moved. */
1213 int mcost = map_move_cost_unit(nmap, punit, ptile);
1214
1215 if (paction) {
1216 struct tile *from_tile;
1217
1218 /* Ugly hack to understand the OnNativeTile unit state requirements
1219 * used in the Action_Success_Actor_Move_Cost effect. */
1223 punit->tile = ptile;
1224
1226
1227 punit->tile = from_tile;
1228 }
1229
1230 if (punit->moves_left <= mcost
1231 && unit_move_rate(punit) > mcost
1232 && adv_danger_at(punit, ptile)
1235 "ending move early to stay out of trouble");
1236 return FALSE;
1237 }
1238 }
1239
1240 /* Go */
1242 /* Move */
1243 if (paction != nullptr && ptrans != nullptr
1245 /* "Transport Embark". */
1247 0, "", action_number(paction));
1248 } else if (paction
1256 /* "Transport Disembark", "Transport Disembark 2", "Enter Hut",
1257 * "Frighten Hut" or "Unit Move". */
1259 0, "", action_number(paction));
1260 }
1261
1262 /* handle the results */
1264 bodyguard = aiguard_guard_of(ait, punit);
1265
1266 if (is_plr_ai && bodyguard != NULL
1267 && def_ai_unit_data(bodyguard, ait)->charge == punit->id) {
1268 dai_unit_bodyguard_move(ait, bodyguard, ptile);
1269 }
1270 return TRUE;
1271 }
1272 return FALSE;
1273}
1274
1275/**********************************************************************/
1280{
1281 struct tile *ptile = unit_tile(pdefender);
1282 int victim_cost = 0;
1283
1284 if (is_stack_vulnerable(ptile)) {
1285 /* lotsa people die */
1286 unit_list_iterate(ptile->units, aunit) {
1288 == ATT_OK) {
1290 }
1293 pdefender, ptile)
1294 == ATT_OK) {
1295 /* Only one unit dies if attack is successful */
1297 }
1298
1299 return victim_cost;
1300}
1301
1302/**********************************************************************/
1305void dai_government_change(struct player *pplayer, struct government *gov)
1306{
1307 if (gov == government_of_player(pplayer)) {
1308 return;
1309 }
1310
1312
1313 city_list_iterate(pplayer->cities, pcity) {
1314 auto_arrange_workers(pcity); /* update cities */
1316}
1317
1318/**********************************************************************/
1324int dai_gold_reserve(struct player *pplayer)
1325{
1326 int i = total_player_citizens(pplayer) * 2;
1327
1328 return MAX(pplayer->ai_common.maxbuycost, i);
1329}
1330
1331/**********************************************************************/
1334void adjust_choice(int pct, struct adv_choice *choice)
1335{
1336 choice->want = (choice->want * pct) / 100;
1337}
1338
1339/**********************************************************************/
1343bool dai_choose_role_unit(struct ai_type *ait, struct player *pplayer,
1344 struct city *pcity, struct adv_choice *choice,
1345 enum choice_type type, int role, int want,
1346 bool need_boat)
1347{
1348 struct unit_type *iunit = dai_wants_role_unit(ait, pplayer, pcity, role, want);
1349
1350 if (iunit != NULL) {
1351 choice->type = type;
1352 choice->value.utype = iunit;
1353 choice->want = want;
1354
1355 choice->need_boat = need_boat;
1356
1357 return TRUE;
1358 }
1359
1360 return FALSE;
1361}
1362
1363/**********************************************************************/
1366void dai_build_adv_override(struct ai_type *ait, struct city *pcity,
1367 struct adv_choice *choice)
1368{
1369 const struct impr_type *chosen;
1370 adv_want want;
1371
1372 if (choice->type == CT_NONE) {
1373 want = 0;
1374 chosen = NULL;
1375 } else {
1376 want = choice->want;
1377 chosen = choice->value.building;
1378 }
1379
1380 improvement_iterate(pimprove) {
1381 /* Advisor code did not consider wonders, let's do it here */
1382 if (is_wonder(pimprove)) {
1383 int id = improvement_index(pimprove);
1384
1385 if (pcity->server.adv->building_want[id] > want
1386 && can_city_build_improvement_now(pcity, pimprove)) {
1387 want = pcity->server.adv->building_want[id];
1388 chosen = pimprove;
1389 }
1390 }
1392
1393 choice->want = want;
1394 choice->value.building = chosen;
1395
1396 if (chosen) {
1397 choice->type = CT_BUILDING; /* In case advisor had not chosen anything */
1398
1399 CITY_LOG(LOG_DEBUG, pcity, "AI wants to build %s with want "
1402 }
1403}
1404
1405/**********************************************************************/
1415{
1417 int unhap = 0;
1418
1419 /* bail out now if happy_cost is 0 */
1421 return FALSE;
1422 }
1423
1425 int happy_cost = city_unit_unhappiness(punit, &free_unhappy);
1426
1427 if (happy_cost > 0) {
1428 unhap += happy_cost;
1429 }
1431
1432 if (unhap < 0) {
1433 unhap = 0;
1434 }
1435 return (unhap > 0);
1436}
bool is_action_enabled_unit_on_stack(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile)
Definition actions.c:3217
int action_number(const struct action *action)
Definition actions.c:1183
bool is_action_enabled_unit_on_tile(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3293
bool is_action_enabled_unit_on_city(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
Definition actions.c:3052
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
bool is_action_enabled_unit_on_extras(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3370
static struct action * action_by_number(action_id act_id)
Definition actions.h:390
#define action_has_result(_act_, _res_)
Definition actions.h:175
#define action_id_get_target_kind(act_id)
Definition actions.h:407
#define ACTION_NONE
Definition actions.h:55
choice_type
Definition advchoice.h:36
@ CT_NONE
Definition advchoice.h:37
@ CT_BUILDING
Definition advchoice.h:38
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:604
bool adv_follow_path(struct unit *punit, struct pf_path *path, struct tile *ptile)
Definition advgoto.c:47
bool adv_danger_at(struct unit *punit, struct tile *ptile)
Definition advgoto.c:425
int adv_unittype_att_rating(const struct unit_type *punittype, int veteran, int moves_left, int hp)
Definition advgoto.c:385
int adv_unit_att_rating(const struct unit *punit)
Definition advgoto.c:396
void adv_avoid_risks(struct pf_parameter *parameter, struct adv_risk_cost *risk_cost, struct unit *punit, const double fearfulness)
Definition advgoto.c:595
#define NORMAL_STACKING_FEARFULNESS
Definition advgoto.h:23
adv_want amortize(adv_want benefit, int delay)
Definition advtools.c:29
#define POWER_DIVIDER
Definition advtools.h:32
bool aiferry_gobyboat(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile, bool with_bodyguard)
Definition aiferry.c:764
bool dai_is_ferry(struct unit *pferry, struct ai_type *ait)
Definition aiferry.c:159
void aiferry_clear_boat(struct ai_type *ait, struct unit *punit)
Definition aiferry.c:251
void aiguard_clear_charge(struct ai_type *ait, struct unit *guard)
Definition aiguard.c:117
void aiguard_request_guard(struct ai_type *ait, struct unit *punit)
Definition aiguard.c:227
void aiguard_assign_guard_city(struct ai_type *ait, struct city *charge, struct unit *guard)
Definition aiguard.c:196
struct unit * aiguard_charge_unit(struct ai_type *ait, struct unit *guard)
Definition aiguard.c:279
void aiguard_clear_guard(struct ai_type *ait, struct unit *charge)
Definition aiguard.c:146
struct unit * aiguard_guard_of(struct ai_type *ait, struct unit *charge)
Definition aiguard.c:269
#define CHECK_CHARGE_UNIT(ait, charge)
Definition aiguard.h:22
#define CHECK_GUARD(ait, guard)
Definition aiguard.h:21
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_CLR(bv, bit)
Definition bitvector.h:86
int city_unit_unhappiness(struct unit *punit, int *free_unhappy)
Definition city.c:3046
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:804
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:854
#define city_list_iterate(citylist, pcity)
Definition city.h:508
static bool is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:727
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
void citymap_free_city_spot(struct tile *ptile, int id)
Definition citymap.c:150
void citymap_reserve_city_spot(struct tile *ptile, int id)
Definition citymap.c:122
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:365
bool is_stack_vulnerable(const struct tile *ptile)
Definition combat.c:992
enum unit_attack_result unit_attack_unit_at_tile_result(const struct unit *punit, const struct action *paction, const struct unit *pdefender, const struct tile *dest_tile)
Definition combat.c:123
#define POWER_FACTOR
Definition combat.h:32
@ ATT_OK
Definition combat.h:35
char * incite_cost
Definition comments.c:74
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Definition daidata.c:402
#define BODYGUARD_LOG(ait, loglevel, punit, msg,...)
Definition dailog.h:69
struct unit_type * dai_choose_defender_versus(struct city *pcity, struct unit *attacker)
Definition daimilitary.c:89
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition daiplayer.h:48
struct unit_type * dai_wants_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, int role, int want)
Definition daitech.c:521
void dai_government_change(struct player *pplayer, struct government *gov)
Definition daitools.c:1305
void dai_fill_unit_param(struct ai_type *ait, struct pf_parameter *parameter, struct adv_risk_cost *risk_cost, struct unit *punit, struct tile *ptile)
Definition daitools.c:467
int stack_cost(struct unit *pattacker, struct unit *pdefender)
Definition daitools.c:1279
bool goto_is_sane(struct unit *punit, struct tile *ptile)
Definition daitools.c:427
#define LONG_TIME
Definition daitools.c:454
bool dai_assess_military_unhappiness(struct city *pcity)
Definition daitools.c:1414
struct tile * immediate_destination(struct unit *punit, struct tile *dest_tile)
Definition daitools.c:300
static bool dai_gothere_bodyguard(struct ai_type *ait, struct unit *punit, struct tile *dest_tile)
Definition daitools.c:160
void dai_build_adv_override(struct ai_type *ait, struct city *pcity, struct adv_choice *choice)
Definition daitools.c:1366
bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition daitools.c:815
bool dai_unit_goto(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition daitools.c:603
bool dai_unit_goto_constrained(struct ai_type *ait, struct unit *punit, struct tile *ptile, struct pf_parameter *parameter)
Definition daitools.c:376
void dai_log_path(struct unit *punit, struct pf_path *path, struct pf_parameter *parameter)
Definition daitools.c:354
void dai_consider_plr_dangerous(struct ai_type *ait, struct player *plr1, struct player *plr2, enum override_bool *result)
Definition daitools.c:141
void dai_unit_new_task(struct ai_type *ait, struct unit *punit, enum ai_unit_task task, struct tile *ptile)
Definition daitools.c:641
int dai_gold_reserve(struct player *pplayer)
Definition daitools.c:1324
void adjust_choice(int pct, struct adv_choice *choice)
Definition daitools.c:1334
bool dai_unit_make_homecity(struct unit *punit, struct city *pcity)
Definition daitools.c:753
bool dai_choose_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, enum choice_type type, int role, int want, bool need_boat)
Definition daitools.c:1343
static void dai_unit_bodyguard_move(struct ai_type *ait, struct unit *bodyguard, struct tile *ptile)
Definition daitools.c:782
const char * dai_unit_task_rule_name(const enum ai_unit_task task)
Definition daitools.c:76
#define LOGLEVEL_GOTHERE
Definition daitools.c:232
adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
Definition daitools.c:117
bool dai_gothere(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile)
Definition daitools.c:242
bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition daitools.c:1082
void dai_unit_new_adv_task(struct ai_type *ait, struct unit *punit, enum adv_unit_task task, struct tile *ptile)
Definition daitools.c:617
void dai_unit_move_or_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile, struct pf_path *path, int step)
Definition daitools.c:1064
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
Definition daiunit.h:72
ai_unit_task
Definition daiunit.h:27
@ AIUNIT_BUILD_CITY
Definition daiunit.h:27
@ AIUNIT_NONE
Definition daiunit.h:27
@ AIUNIT_ATTACK
Definition daiunit.h:28
@ AIUNIT_EXPLORE
Definition daiunit.h:29
@ AIUNIT_HUNTER
Definition daiunit.h:29
@ AIUNIT_AUTO_WORKER
Definition daiunit.h:27
@ AIUNIT_RECOVER
Definition daiunit.h:29
@ AIUNIT_TRADE
Definition daiunit.h:30
@ AIUNIT_DEFEND_HOME
Definition daiunit.h:28
@ AIUNIT_ESCORT
Definition daiunit.h:28
@ AIUNIT_WONDER
Definition daiunit.h:30
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
int int id
Definition editgui_g.h:28
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
bool hut_on_tile(const struct tile *ptile)
Definition extras.c:705
float adv_want
Definition fc_types.h:1335
adv_unit_task
Definition fc_types.h:374
@ AUT_BUILD_CITY
Definition fc_types.h:374
@ AUT_NONE
Definition fc_types.h:374
@ AUT_AUTO_WORKER
Definition fc_types.h:374
#define ADV_WANT_PRINTF
Definition fc_types.h:1336
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
override_bool
Definition fc_types.h:94
@ OVERRIDE_TRUE
Definition fc_types.h:94
struct world wld
Definition game.c:62
struct unit * game_unit_by_number(int id)
Definition game.c:115
struct government * government_of_player(const struct player *pplayer)
Definition government.c:114
Government_type_id government_number(const struct government *pgovern)
Definition government.c:91
GType type
Definition repodlgs.c:1313
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:565
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
@ H_MAP
Definition handicaps.h:28
const char * improvement_rule_name(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_assert_ret(condition)
Definition log.h:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
@ LOG_DEBUG
Definition log.h:34
#define log_error(message,...)
Definition log.h:103
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Definition map.c:941
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:950
int map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:660
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
Definition map.h:279
int unit_move_rate(const struct unit *punit)
Definition movement.c:89
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:490
#define SINGLE_MOVE
Definition movement.h:26
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
const struct pf_position * pf_path_last_position(const struct pf_path *path)
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)
void pf_map_destroy(struct pf_map *pfm)
int pf_map_move_cost(struct pf_map *pfm, struct tile *ptile)
#define PF_IMPOSSIBLE_MC
#define PF_TURN_FACTOR
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:843
void pft_fill_unit_attack_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:952
void pft_fill_unit_overlap_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:894
enum tile_behavior no_fights(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:510
enum tile_behavior no_intermediate_fights(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:526
int player_index(const struct player *pplayer)
Definition player.c:829
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#define is_ai(plr)
Definition player.h:232
int total_player_citizens(const struct player *pplayer)
Definition score.c:382
#define MAX(x, y)
Definition shared.h:54
int step
Definition specpq.h:92
#define CITY_LOG(loglevel, pcity, msg,...)
Definition srv_log.h:83
#define LOGLEVEL_HUNT
Definition srv_log.h:35
#define UNIT_LOG(loglevel, punit, msg,...)
Definition srv_log.h:98
#define LOGLEVEL_BODYGUARD
Definition srv_log.h:30
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
adv_want building_want[B_LAST]
Definition infracache.h:32
int average_production
Definition advdata.h:98
struct adv_data::@91 stats
Definition ai.h:50
Definition city.h:320
int surplus[O_LAST]
Definition city.h:355
int id
Definition city.h:326
struct adv_city * adv
Definition city.h:452
struct city::@17::@19 server
struct unit_list * units_supported
Definition city.h:406
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
int(* get_moves_left_req)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
bool(* get_zoc)(const struct player *pplayer, const struct tile *ptile, const struct civ_map *zmap)
unsigned length
struct pf_position * positions
unsigned total_MC
unsigned total_EC
struct tile * tile
int maxbuycost
Definition player.h:114
struct city_list * cities
Definition player.h:281
struct player_ai ai_common
Definition player.h:288
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
enum adv_unit_task task
Definition unit.h:90
enum ai_unit_task task
Definition daiunit.h:46
int charge
Definition daiunit.h:37
int defense_strength
Definition unittype.h:523
int move_rate
Definition unittype.h:524
Definition unit.h:140
int upkeep[O_LAST]
Definition unit.h:150
enum unit_activity activity
Definition unit.h:159
int moves_left
Definition unit.h:152
int id
Definition unit.h:147
int hp
Definition unit.h:153
struct unit::@81::@84 server
struct tile * tile
Definition unit.h:142
struct unit_adv * adv
Definition unit.h:239
int homecity
Definition unit.h:148
struct tile * goto_tile
Definition unit.h:157
int veteran
Definition unit.h:154
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:215
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:89
#define TILE_XY(ptile)
Definition tile.h:43
const struct unit_type * utype
Definition fc_types.h:698
const struct impr_type * building
Definition fc_types.h:691
int unit_pays_mp_for_action(const struct action *paction, const struct unit *punit)
Definition unit.c:2173
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1960
bool is_losing_hp(const struct unit *punit)
Definition unit.c:2266
bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:749
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2699
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2483
bool unit_has_orders(const struct unit *punit)
Definition unit.c:205
#define unit_tile(_pu)
Definition unit.h:397
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:420
#define CHECK_UNIT(punit)
Definition unit.h:273
#define unit_owner(_pu)
Definition unit.h:396
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity, enum gen_action trigger_action)
Definition unithand.c:6613
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
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2878
void unit_transport_load_send(struct unit *punit, struct unit *ptrans)
Definition unittools.c:3386
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1249
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1587
bool utype_may_act_at_all(const struct unit_type *putype)
Definition unittype.c:359
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1484
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2498
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:387
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Definition unittype.c:208
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2583
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_fuel(ptype)
Definition unittype.h:843