Freeciv-3.4
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 "daidata.h"
63#include "daiferry.h"
64#include "daiguard.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 nullptr;
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, nullptr);
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 const struct unit_type *ptype;
170
172 /* Barbarians must have more courage (ie less brains) */
174 return FALSE;
175 }
176
177 /* Estimate enemy attack power. */
178 unit_list_iterate(dest_tile->units, aunit) {
179 if (POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, unit_owner(aunit))) {
180 danger += adv_unit_att_rating(aunit);
181 }
183 dcity = tile_city(dest_tile);
184 if (dcity && POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, city_owner(dcity))) {
185 /* Assume enemy will build another defender, add it's attack strength */
187
188 if (d_type) {
189 /* Enemy really can build something */
190 danger +=
193 SINGLE_MOVE, d_type->hp);
194 }
195 }
196 danger *= POWER_DIVIDER;
197
198 /* If we are fast, there is less danger.
199 * FIXME: that assumes that most units have move_rate == SINGLE_MOVE;
200 * not true for all rulesets */
202 danger /= (ptype->move_rate / SINGLE_MOVE);
204 danger /= 1.5;
205 }
206
208 fc_assert_ret_val(vlevel != nullptr, FALSE);
209
210 /* We look for the bodyguard where we stand. */
211 if (guard == nullptr || unit_tile(guard) != unit_tile(punit)) {
212 int my_def = (punit->hp * ptype->defense_strength
213 * POWER_FACTOR * vlevel->power_fact / 100);
214
215 if (danger >= my_def) {
217 "want bodyguard @(%d, %d) danger=%d, my_def=%d",
218 TILE_XY(dest_tile), danger, my_def);
220 bg_needed = TRUE;
221 } else {
224 }
225 } else if (guard != nullptr) {
226 bg_needed = TRUE;
227 }
228
229 /* What if we have a bodyguard, but don't need one? */
230
231 return bg_needed;
232}
233
234#define LOGLEVEL_GOTHERE LOG_DEBUG
235/**********************************************************************/
244bool dai_gothere(struct ai_type *ait, struct player *pplayer,
245 struct unit *punit, struct tile *dest_tile)
246{
248 bool bg_needed;
249
250 if (same_pos(dest_tile, unit_tile(punit)) || punit->moves_left <= 0) {
251 /* Nowhere to go */
252 return TRUE;
253 }
254
255 /* See if we need a bodyguard at our destination */
256 /* FIXME: If bodyguard is _really_ necessary, don't go anywhere */
257 bg_needed = dai_gothere_bodyguard(ait, punit, dest_tile);
258
260 || !goto_is_sane(punit, dest_tile)) {
261 /* Must go by boat, call an aiferryboat function */
262 if (!aiferry_gobyboat(ait, pplayer, punit, dest_tile,
263 bg_needed)) {
264 return FALSE;
265 }
266 }
267
268 /* Go where we should be going if we can, and are at our destination
269 * if we are on a ferry */
270 if (goto_is_sane(punit, dest_tile) && punit->moves_left > 0) {
271 punit->goto_tile = dest_tile;
272 UNIT_LOG(LOGLEVEL_GOTHERE, punit, "Walking to (%d,%d)", TILE_XY(dest_tile));
273 if (!dai_unit_goto(ait, punit, dest_tile)) {
274 /* Died */
275 return FALSE;
276 }
277 /* Liable to bump into someone that will kill us. Should avoid? */
278 } else {
279 UNIT_LOG(LOGLEVEL_GOTHERE, punit, "Not moving");
280 return FALSE;
281 }
282
283 if (def_ai_unit_data(punit, ait)->ferryboat > 0
284 && !unit_transported(punit)) {
285 /* We probably just landed, release our boat */
287 }
288
289 /* Dead unit shouldn't reach this point */
291
292 return (same_pos(unit_tile(punit), dest_tile)
293 || is_tiles_adjacent(unit_tile(punit), dest_tile));
294}
295
296/**********************************************************************/
303 struct tile *dest_tile)
304{
305 const struct civ_map *nmap = &(wld.map);
306
307 if (!same_pos(unit_tile(punit), dest_tile)
309 struct pf_parameter parameter;
310 struct pf_map *pfm;
311 struct pf_path *path;
312 size_t i;
313 struct player *pplayer = unit_owner(punit);
314
315 pft_fill_unit_parameter(&parameter, nmap, punit);
316 parameter.omniscience = !has_handicap(pplayer, H_MAP);
317 pfm = pf_map_new(&parameter);
318 path = pf_map_path(pfm, punit->goto_tile);
319
320 if (path) {
321 for (i = 1; i < path->length; i++) {
322 if (path->positions[i].tile == path->positions[i - 1].tile) {
323 /* The path-finding code advice us to wait there to refuel. */
324 struct tile *ptile = path->positions[i].tile;
325
326 pf_path_destroy(path);
328 return ptile;
329 }
330 }
331 pf_path_destroy(path);
333 /* Seems it's the immediate destination */
334 return punit->goto_tile;
335 }
336
338 log_verbose("Did not find an air-route for "
339 "%s %s[%d] (%d,%d)->(%d,%d)",
342 punit->id,
344 TILE_XY(dest_tile));
345 /* Prevent take off */
346 return unit_tile(punit);
347 }
348
349 /* else does not need way-points */
350 return dest_tile;
351}
352
353/**********************************************************************/
357 struct pf_path *path, struct pf_parameter *parameter)
358{
359 const struct pf_position *last = pf_path_last_position(path);
360 const unsigned cc = PF_TURN_FACTOR * last->total_MC
361 + parameter->move_rate * last->total_EC;
362 const unsigned tc = cc / (PF_TURN_FACTOR * parameter->move_rate);
363
364 UNIT_LOG(LOG_DEBUG, punit, "path L=%d T=%d(%u) MC=%u EC=%u CC=%u",
365 path->length - 1, last->turn, tc,
366 last->total_MC, last->total_EC, cc);
367}
368
369/**********************************************************************/
378bool dai_unit_goto_constrained(struct ai_type *ait, struct unit *punit,
379 struct tile *ptile,
380 struct pf_parameter *parameter)
381{
382 bool alive = TRUE;
383 struct pf_map *pfm;
384 struct pf_path *path;
385
386 UNIT_LOG(LOG_DEBUG, punit, "constrained goto to %d,%d", TILE_XY(ptile));
387
388 if (same_pos(unit_tile(punit), ptile)) {
389 /* Was not an error in previous versions but now is dubious... */
390 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: already there!");
391 send_unit_info(nullptr, punit);
392
393 return TRUE;
394 } else if (!goto_is_sane(punit, ptile)) { /* FIXME: why do we check it? */
395 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: 'insane' goto!");
397 send_unit_info(nullptr, punit);
398
399 return TRUE;
400 } else if (punit->moves_left == 0) {
401 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: no moves left!");
402 send_unit_info(nullptr, punit);
403
404 return TRUE;
405 }
406
407 pfm = pf_map_new(parameter);
408 path = pf_map_path(pfm, ptile);
409
410 if (path) {
411 dai_log_path(punit, path, parameter);
412 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: following path.");
413 alive = adv_follow_path(punit, path, ptile);
414 } else {
415 UNIT_LOG(LOG_DEBUG, punit, "no path to destination");
416 }
417
418 pf_path_destroy(path);
420
421 return alive;
422}
423
424/**********************************************************************/
429bool goto_is_sane(struct unit *punit, struct tile *ptile)
430{
431 bool can_get_there = FALSE;
432 const struct civ_map *nmap = &(wld.map);
433
434 if (same_pos(unit_tile(punit), ptile)) {
436 } else {
437 struct pf_parameter parameter;
438 struct pf_map *pfm;
439
441 pfm = pf_map_new(&parameter);
442
443 if (pf_map_move_cost(pfm, ptile) != PF_IMPOSSIBLE_MC) {
445 }
447 }
448 return can_get_there;
449}
450
451/*
452 * The length of time, in turns, which is long enough to be optimistic
453 * that enemy units will have moved from their current position.
454 * WAG
455 */
456#define LONG_TIME 4
457/**********************************************************************/
469void dai_fill_unit_param(struct ai_type *ait, struct pf_parameter *parameter,
470 struct adv_risk_cost *risk_cost,
471 struct unit *punit, struct tile *ptile)
472{
477 const bool barbarian = is_barbarian(unit_owner(punit));
478 bool is_ferry;
479 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
480 struct player *pplayer = unit_owner(punit);
481 const struct civ_map *nmap = &(wld.map);
482
483 /* This function is now always omniscient and should not be used
484 * for human players any more. */
485 fc_assert(is_ai(pplayer));
486
487 /* If a unit is hunting, don't expect it to be a ferry. */
489 && dai_is_ferry(punit, ait));
490
491 if (is_ferry) {
492 /* The destination may be a coastal land tile,
493 * in which case the ferry should stop on an adjacent tile. */
495 } else if (!utype_fuel(unit_type_get(punit))
498 && (unit_data->task == AIUNIT_DEFEND_HOME
499 || unit_data->task == AIUNIT_ATTACK
500 || unit_data->task == AIUNIT_ESCORT
501 || unit_data->task == AIUNIT_HUNTER)) {
502 /* Use attack movement for defenders and escorts so they can
503 * make defensive attacks */
505 } else {
507 }
508 parameter->omniscience = !has_handicap(pplayer, H_MAP);
509
510 /* Should we use the risk avoidance code?
511 * The risk avoidance code uses omniscience, so do not use for
512 * human-player units under temporary AI control.
513 * Barbarians bravely/stupidly ignore risks
514 */
516 && !barbarian) {
518 }
519
520 /* Should we absolutely forbid ending a turn on a dangerous tile?
521 * Do not annoy human players by killing their units for them.
522 * For AI units be optimistic; allows attacks across dangerous terrain,
523 * and polar settlements.
524 * TODO: This is compatible with old code,
525 * but probably ought to be more cautious for non military units
526 */
528 parameter->get_moves_left_req = nullptr;
529 }
530
531 if (long_path) {
532 /* Move as far along the path to the destination as we can;
533 * that is, ignore the presence of enemy units when computing the
534 * path.
535 * Hopefully, ai_avoid_risks() have produced a path that avoids enemy
536 * ZoCs. Ignoring ZoCs allows us to move closer to a destination
537 * for which there is not yet a clear path.
538 * That is good if the destination is several turns away,
539 * so we can reasonably expect blocking enemy units to move or
540 * be destroyed. But it can be bad if the destination is one turn away
541 * or our destination is far but there are enemy units near us and on the
542 * shortest path to the destination.
543 */
544 parameter->get_zoc = nullptr;
545 }
546
548 parameter->get_TB = no_fights;
549 } else if (long_path && unit_is_cityfounder(punit)) {
550 /* Default tile behavior;
551 * move as far along the path to the destination as we can;
552 * that is, ignore the presence of enemy units when computing the
553 * path.
554 */
555 } else if (unit_is_cityfounder(punit)) {
556 /* Short path */
557 parameter->get_TB = no_fights;
559 /* Avoid capture */
560 parameter->get_TB = no_fights;
561 } else if (is_ferry) {
562 /* Ferries are not warships */
563 parameter->get_TB = no_fights;
564 } else if (is_losing_hp(punit)) {
565 /* Losing hitpoints over time (helicopter in classic rules) */
566 /* Default tile behavior */
568 switch (unit_data->task) {
571 /* Strange, but not impossible */
572 parameter->get_TB = no_fights;
573 break;
575 case AIUNIT_ATTACK: /* Includes spy actions */
576 case AIUNIT_ESCORT:
577 case AIUNIT_HUNTER:
578 case AIUNIT_TRADE:
579 case AIUNIT_WONDER:
580 parameter->get_TB = no_intermediate_fights;
581 break;
582 case AIUNIT_EXPLORE:
583 case AIUNIT_RECOVER:
584 parameter->get_TB = no_fights;
585 break;
586 case AIUNIT_NONE:
587 /* Default tile behavior */
588 break;
589 }
590 } else {
591 /* Probably an explorer */
592 parameter->get_TB = no_fights;
593 }
594
595 if (is_ferry) {
596 /* Show the destination in the client when watching an AI: */
597 punit->goto_tile = ptile;
598 }
599}
600
601/**********************************************************************/
605bool dai_unit_goto(struct ai_type *ait, struct unit *punit, struct tile *ptile)
606{
607 struct pf_parameter parameter;
609
610 UNIT_LOG(LOG_DEBUG, punit, "dai_unit_goto() to %d,%d", TILE_XY(ptile));
611 dai_fill_unit_param(ait, &parameter, &risk_cost, punit, ptile);
612
613 return dai_unit_goto_constrained(ait, punit, ptile, &parameter);
614}
615
616/**********************************************************************/
619void dai_unit_new_adv_task(struct ai_type *ait, struct unit *punit,
620 enum adv_unit_task task, struct tile *ptile)
621{
622 /* Keep ai_unit_task in sync with adv task */
623 switch (task) {
624 case AUT_AUTO_WORKER:
626 break;
627 case AUT_BUILD_CITY:
629 break;
630 case AUT_NONE:
631 dai_unit_new_task(ait, punit, AIUNIT_NONE, ptile);
632 break;
633 }
634}
635
636/**********************************************************************/
643void dai_unit_new_task(struct ai_type *ait, struct unit *punit,
644 enum ai_unit_task task, struct tile *ptile)
645{
646 struct unit *bodyguard = aiguard_guard_of(ait, punit);
647 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
648
649 /* If the unit is under (human) orders we shouldn't control it.
650 * Allow removal of old role with AIUNIT_NONE. */
652
653 UNIT_LOG(LOG_DEBUG, punit, "changing task from %s to %s",
656
657 /* Free our ferry. Most likely it has been done already. */
660 }
661
662 if (punit->activity == ACTIVITY_GOTO) {
663 /* It would indicate we're going somewhere otherwise */
665 }
666
667 if (unit_data->task == AIUNIT_BUILD_CITY) {
668 if (punit->goto_tile) {
670 } else {
671 /* Print error message instead of crashing in citymap_free_city_spot()
672 * This probably means that some city spot reservation has not been
673 * properly cleared; bad for the AI, as it will leave that area
674 * uninhabited. */
675 log_error("%s was on city founding mission without target tile.",
677 }
678 }
679
680 if (unit_data->task == AIUNIT_HUNTER) {
681 /* Clear victim's hunted bit - we're no longer chasing. */
682 struct unit *target = game_unit_by_number(unit_data->target);
683
684 if (target != nullptr) {
685 BV_CLR(def_ai_unit_data(target, ait)->hunted,
687 UNIT_LOG(LOGLEVEL_HUNT, target, "no longer hunted (new task %d, old %d)",
688 task, unit_data->task);
689 }
690 }
691
693 /* Record the city to defend; our goto may be to transport. */
694 if (task == AIUNIT_DEFEND_HOME && ptile && tile_city(ptile)) {
696 }
697
698 unit_data->task = task;
699
700 /* Verify and set the goto destination. Eventually this can be a lot more
701 * stringent, but for now we don't want to break things too badly. */
702 punit->goto_tile = ptile; /* May be nullptr. */
703
704 if (unit_data->task == AIUNIT_NONE && bodyguard) {
705 dai_unit_new_task(ait, bodyguard, AIUNIT_NONE, nullptr);
706 }
707
708 /* Reserve city spot, _unless_ we want to add ourselves to a city. */
709 if (unit_data->task == AIUNIT_BUILD_CITY && !tile_city(ptile)) {
711 }
712 if (unit_data->task == AIUNIT_HUNTER) {
713 /* Set victim's hunted bit - the hunt is on! */
714 struct unit *target = game_unit_by_number(unit_data->target);
715
716 fc_assert_ret(target != nullptr);
717 BV_SET(def_ai_unit_data(target, ait)->hunted, player_index(unit_owner(punit)));
718 UNIT_LOG(LOGLEVEL_HUNT, target, "is being hunted");
719
720 /* Grab missiles lying around and bring them along */
723 && def_ai_unit_data(missile, ait)->task != AIUNIT_ESCORT
729 UNIT_LOG(LOGLEVEL_HUNT, missile, "loaded on hunter");
732 }
734 }
735
736 /* Map ai tasks to advisor tasks. For most ai tasks there is
737 no advisor, so AUT_NONE is set. */
738 switch (unit_data->task) {
741 break;
744 break;
745 default:
747 break;
748 }
749}
750
751/**********************************************************************/
756{
759
761 /* This unit doesn't pay any upkeep while it doesn't have a homecity,
762 * so it would be stupid to give it one. There can also be good reasons
763 * why it doesn't have a homecity. */
764 /* However, until we can do something more useful with them, we
765 will assign explorers to a city so that they can be disbanded for
766 the greater good -- Per */
767 return FALSE;
768 }
769 if (pcity->surplus[O_SHIELD] >= unit_type_get(punit)->upkeep[O_SHIELD]
770 && pcity->surplus[O_FOOD] >= unit_type_get(punit)->upkeep[O_FOOD]) {
772 0, "", ACTION_HOME_CITY);
773 return TRUE;
774 }
775 return FALSE;
776}
777
778/**********************************************************************/
784static void dai_unit_bodyguard_move(struct ai_type *ait,
785 struct unit *bodyguard, struct tile *ptile)
786{
787 fc_assert_ret(bodyguard != nullptr);
788 fc_assert_ret(unit_owner(bodyguard) != nullptr);
789
790#ifndef FREECIV_NDEBUG
791 struct unit *punit =
792#endif
793 aiguard_charge_unit(ait, bodyguard);
794
795 fc_assert_ret(punit != nullptr);
796
797 CHECK_GUARD(ait, bodyguard);
799
800 if (!is_tiles_adjacent(ptile, unit_tile(bodyguard))) {
801 return;
802 }
803
804 if (bodyguard->moves_left <= 0) {
805 /* Should generally not happen */
806 BODYGUARD_LOG(ait, LOG_DEBUG, bodyguard, "was left behind by charge");
807 return;
808 }
809
811 (void) dai_unit_move(ait, bodyguard, ptile);
812}
813
814/**********************************************************************/
817bool dai_unit_attack(struct ai_type *ait, struct unit *punit,
818 struct tile *ptile)
819{
820 struct unit *ptrans;
821 struct unit *bodyguard = aiguard_guard_of(ait, punit);
822 int sanity = punit->id;
823 bool alive;
824 struct city *tcity;
825 const struct civ_map *nmap = &(wld.map);
826
830
832 /* FIXME: try the next action if the unit tried to do an illegal action.
833 * That would allow the AI to stop using the omniscient
834 * is_action_enabled_unit_on_*() functions. */
836 punit, ptile)) {
837 /* Choose capture. */
839 0, "", ACTION_CAPTURE_UNITS);
841 punit, ptile)) {
842 /* Choose "Collect Ransom". */
844 0, "", ACTION_COLLECT_RANSOM);
846 punit, ptile)) {
847 /* Choose "Bombard Lethal". */
849 0, "", ACTION_BOMBARD_LETHAL);
851 punit, ptile)) {
852 /* Choose "Bombard Lethal 2". */
856 punit, ptile)) {
857 /* Choose "Bombard". */
859 0, "", ACTION_BOMBARD);
861 punit, ptile)) {
862 /* Choose "Bombard 2". */
864 0, "", ACTION_BOMBARD2);
866 punit, ptile)) {
867 /* Choose "Bombard 3". */
869 0, "", ACTION_BOMBARD3);
871 punit, ptile)) {
872 /* Choose "Bombard 4". */
874 0, "", ACTION_BOMBARD4);
876 punit, ptile)) {
877 /* Choose "Nuke Units". */
879 0, "", ACTION_NUKE_UNITS);
882 punit, ptile, nullptr)) {
883 /* Choose "Explode Nuclear". */
885 0, "", ACTION_NUKE);
887 && (tcity = tile_city(ptile))
889 punit, tcity)) {
890 /* Choose "Explode Nuclear". */
892 0, "", ACTION_NUKE);
895 punit, ptile, nullptr)) {
896 /* Choose "Nuke City". */
898 0, "", ACTION_NUKE_CITY);
900 && (tcity = tile_city(ptile))
902 punit, tcity)) {
903 /* Choose "Nuke City". */
905 0, "", ACTION_NUKE_CITY);
907 punit, ptile)) {
908 /* Choose regular attack. */
910 0, "", ACTION_ATTACK);
912 punit, ptile)) {
913 /* Choose regular attack 2. */
915 0, "", ACTION_ATTACK2);
917 punit, ptile)) {
918 /* Choose suicide attack (explode missile). */
920 0, "", ACTION_SUICIDE_ATTACK);
922 punit, ptile)) {
923 /* Choose suicide attack (explode missile) 2. */
926 } else if ((tcity = tile_city(ptile))
928 punit, tcity)) {
929 /* Choose "Conquer City Shrink". */
932 } else if ((tcity = tile_city(ptile))
934 punit, tcity)) {
935 /* Choose "Conquer City Shrink 2". */
938 } else if ((tcity = tile_city(ptile))
940 punit, tcity)) {
941 /* Choose "Conquer City Shrink 3". */
944 } else if ((tcity = tile_city(ptile))
946 punit, tcity)) {
947 /* Choose "Conquer City Shrink 4". */
950 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
951 && ((ptrans = transporter_for_unit_at(punit, ptile)))
953 punit, ptrans)) {
954 /* "Transport Embark". */
957 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
958 && ((ptrans = transporter_for_unit_at(punit, ptile)))
960 punit, ptrans)) {
961 /* "Transport Embark 2". */
964 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
965 && ((ptrans = transporter_for_unit_at(punit, ptile)))
967 punit, ptrans)) {
968 /* "Transport Embark 3". */
971 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
972 && ((ptrans = transporter_for_unit_at(punit, ptile)))
974 punit, ptrans)) {
975 /* "Transport Embark 4". */
979 punit, ptile, nullptr)) {
980 /* "Transport Disembark". */
984 punit, ptile, nullptr)) {
985 /* "Transport Disembark 2". */
989 punit, ptile, nullptr)) {
990 /* "Transport Disembark 3". */
994 punit, ptile, nullptr)) {
995 /* "Transport Disembark 4". */
1000 punit, ptile, nullptr)) {
1001 /* Choose "Conquer Extras". */
1003 0, "", ACTION_CONQUER_EXTRAS);
1004 } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
1006 punit, ptile, nullptr)) {
1007 /* Choose "Conquer Extras 2". */
1009 0, "", ACTION_CONQUER_EXTRAS2);
1010 } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
1012 punit, ptile, nullptr)) {
1013 /* Choose "Conquer Extras 3". */
1015 0, "", ACTION_CONQUER_EXTRAS3);
1016 } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
1018 punit, ptile, nullptr)) {
1019 /* Choose "Conquer Extras 4". */
1021 0, "", ACTION_CONQUER_EXTRAS4);
1023 punit, ptile, nullptr)) {
1024 /* Choose "Enter Hut". */
1026 0, "", ACTION_HUT_ENTER);
1028 punit, ptile, nullptr)) {
1029 /* Choose "Enter Hut 2". */
1031 0, "", ACTION_HUT_ENTER2);
1033 punit, ptile, nullptr)) {
1034 /* Choose "Enter Hut 3". */
1036 0, "", ACTION_HUT_ENTER3);
1038 punit, ptile, nullptr)) {
1039 /* Choose "Enter Hut 4". */
1041 0, "", ACTION_HUT_ENTER4);
1043 punit, ptile, nullptr)) {
1044 /* Choose "Frighten Hut". */
1046 0, "", ACTION_HUT_FRIGHTEN);
1048 punit, ptile, nullptr)) {
1049 /* Choose "Frighten Hut 2". */
1051 0, "", ACTION_HUT_FRIGHTEN2);
1053 punit, ptile, nullptr)) {
1054 /* Choose "Frighten Hut 3". */
1056 0, "", ACTION_HUT_FRIGHTEN3);
1058 punit, ptile, nullptr)) {
1059 /* Choose "Frighten Hut 4". */
1061 0, "", ACTION_HUT_FRIGHTEN4);
1063 punit, ptile, nullptr)) {
1064 /* Choose "Unit Move". */
1066 0, "", ACTION_UNIT_MOVE);
1068 punit, ptile, nullptr)) {
1069 /* Choose "Unit Move 2". */
1071 0, "", ACTION_UNIT_MOVE2);
1072 } else {
1073 /* Choose "Unit Move 3". */
1075 0, "", ACTION_UNIT_MOVE3);
1076 }
1077 alive = (game_unit_by_number(sanity) != nullptr);
1078
1079 if (alive && same_pos(ptile, unit_tile(punit))
1080 && bodyguard != nullptr
1081 && def_ai_unit_data(bodyguard, ait)->charge == punit->id) {
1082 dai_unit_bodyguard_move(ait, bodyguard, ptile);
1083 /* Clumsy bodyguard might trigger an auto-attack */
1084 alive = (game_unit_by_number(sanity) != nullptr);
1085 }
1086
1087 return alive;
1088}
1089
1090/**********************************************************************/
1093void dai_unit_move_or_attack(struct ai_type *ait, struct unit *punit,
1094 struct tile *ptile, struct pf_path *path, int step)
1095{
1096 if (step == path->length - 1) {
1097 (void) dai_unit_attack(ait, punit, ptile);
1098 } else {
1099 (void) dai_unit_move(ait, punit, ptile);
1100 }
1101}
1102
1103/**********************************************************************/
1111bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile)
1112{
1113 struct action *paction;
1114 struct unit *bodyguard;
1115 struct unit *ptrans = nullptr;
1116 int sanity = punit->id;
1117 struct player *pplayer = unit_owner(punit);
1118 const bool is_plr_ai = is_ai(pplayer);
1119 const struct civ_map *nmap = &(wld.map);
1120
1123 "Tiles not adjacent: Unit = %d, "
1124 "from = (%d, %d]) to = (%d, %d).",
1126 TILE_XY(ptile));
1127
1128 /* if enemy, stop and give a chance for the ai attack function
1129 * to handle this case */
1130 if (is_enemy_unit_tile(ptile, pplayer)
1131 || is_enemy_city_tile(ptile, pplayer)) {
1132 UNIT_LOG(LOG_DEBUG, punit, "movement halted due to enemy presence");
1133 return FALSE;
1134 }
1135
1136 /* barbarians shouldn't enter huts */
1137 /* FIXME: use unit_can_displace_hut(punit, ptile) better */
1138 if (is_barbarian(pplayer) && hut_on_tile(ptile)) {
1139 return FALSE;
1140 }
1141
1142 /* Don't leave bodyguard behind */
1143 if (is_plr_ai
1144 && (bodyguard = aiguard_guard_of(ait, punit))
1145 && same_pos(unit_tile(punit), unit_tile(bodyguard))
1146 && bodyguard->moves_left == 0) {
1148 "does not want to leave its bodyguard");
1149 return FALSE;
1150 }
1151
1152 /* Select move kind. */
1153 if (!can_unit_survive_at_tile(nmap, punit, ptile)
1154 && ((ptrans = transporter_for_unit_at(punit, ptile)))
1156 punit, ptrans)) {
1157 /* "Transport Embark". */
1159 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
1160 && ptrans != nullptr
1162 punit, ptrans)) {
1163 /* "Transport Embark 2". */
1165 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
1166 && ptrans != nullptr
1168 punit, ptrans)) {
1169 /* "Transport Embark 3". */
1171 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
1172 && ptrans != nullptr
1174 punit, ptrans)) {
1175 /* "Transport Embark 4". */
1178 punit, ptile, nullptr)) {
1179 /* "Transport Disembark". */
1182 punit, ptile, nullptr)) {
1183 /* "Transport Disembark 2". */
1186 punit, ptile, nullptr)) {
1187 /* "Transport Disembark 3". */
1190 punit, ptile, nullptr)) {
1191 /* "Transport Disembark 4". */
1194 punit, ptile, nullptr)) {
1195 /* "Enter Hut". */
1198 punit, ptile, nullptr)) {
1199 /* "Enter Hut 2". */
1202 punit, ptile, nullptr)) {
1203 /* "Enter Hut 3". */
1206 punit, ptile, nullptr)) {
1207 /* "Enter Hut 4". */
1210 punit, ptile, nullptr)) {
1211 /* "Frighten Hut". */
1214 punit, ptile, nullptr)) {
1215 /* "Frighten Hut 2". */
1218 punit, ptile, nullptr)) {
1219 /* "Frighten Hut 3". */
1222 punit, ptile, nullptr)) {
1223 /* "Frighten Hut 4". */
1226 punit, ptile, nullptr)) {
1227 /* "Unit Move". */
1230 punit, ptile, nullptr)) {
1231 /* "Unit Move 2". */
1233 } else {
1234 /* "Unit Move 3". */
1236 }
1237
1238 /* Try not to end move next to an enemy if we can avoid it by waiting */
1241 /* The unit will have to move it self rather than being moved. */
1242 int mcost = map_move_cost_unit(nmap, punit, ptile);
1243
1244 if (paction != nullptr) {
1245 struct tile *from_tile;
1246
1247 /* Ugly hack to understand the OnNativeTile unit state requirements
1248 * used in the Action_Success_Actor_Move_Cost effect. */
1252 punit->tile = ptile;
1253
1255
1256 punit->tile = from_tile;
1257 }
1258
1259 if (punit->moves_left <= mcost
1260 && unit_move_rate(punit) > mcost
1261 && adv_danger_at(punit, ptile)
1264 "ending move early to stay out of trouble");
1265 return FALSE;
1266 }
1267 }
1268
1269 /* Go */
1271 /* Move */
1272 if (paction != nullptr && ptrans != nullptr
1274 /* "Transport Embark". */
1276 0, "", action_number(paction));
1277 } else if (paction
1285 /* "Transport Disembark", "Transport Disembark 2", "Enter Hut",
1286 * "Frighten Hut" or "Unit Move". */
1288 0, "", action_number(paction));
1289 }
1290
1291 /* handle the results */
1293 bodyguard = aiguard_guard_of(ait, punit);
1294
1295 if (is_plr_ai && bodyguard != nullptr
1296 && def_ai_unit_data(bodyguard, ait)->charge == punit->id) {
1297 dai_unit_bodyguard_move(ait, bodyguard, ptile);
1298 }
1299 return TRUE;
1300 }
1301 return FALSE;
1302}
1303
1304/**********************************************************************/
1309{
1310 struct tile *ptile = unit_tile(pdefender);
1311 int victim_cost = 0;
1312
1313 if (is_stack_vulnerable(ptile)) {
1314 /* Lotsa people die */
1315 unit_list_iterate(ptile->units, aunit) {
1317 aunit, ptile)
1318 == ATT_OK) {
1320 }
1322 } else if (unit_attack_unit_at_tile_result(pattacker, nullptr,
1323 pdefender, ptile)
1324 == ATT_OK) {
1325 /* Only one unit dies if attack is successful */
1327 }
1328
1329 return victim_cost;
1330}
1331
1332/**********************************************************************/
1335void dai_government_change(struct player *pplayer, struct government *gov)
1336{
1337 if (gov == government_of_player(pplayer)) {
1338 return;
1339 }
1340
1342
1343 city_list_iterate(pplayer->cities, pcity) {
1344 auto_arrange_workers(pcity); /* Update cities */
1346}
1347
1348/**********************************************************************/
1354int dai_gold_reserve(struct player *pplayer)
1355{
1356 int i = total_player_citizens(pplayer) * 2;
1357
1358 return MAX(pplayer->ai_common.maxbuycost, i);
1359}
1360
1361/**********************************************************************/
1364void adjust_choice(int pct, struct adv_choice *choice)
1365{
1366 choice->want = (choice->want * pct) / 100;
1367}
1368
1369/**********************************************************************/
1373bool dai_choose_role_unit(struct ai_type *ait, struct player *pplayer,
1374 struct city *pcity, struct adv_choice *choice,
1375 enum choice_type type, int role, int want,
1376 bool need_boat)
1377{
1378 struct unit_type *iunit = dai_wants_role_unit(ait, pplayer, pcity, role, want);
1379
1380 if (iunit != nullptr) {
1381 choice->type = type;
1382 choice->value.utype = iunit;
1383 choice->want = want;
1384
1385 choice->need_boat = need_boat;
1386
1387 return TRUE;
1388 }
1389
1390 return FALSE;
1391}
1392
1393/**********************************************************************/
1396void dai_build_adv_override(struct ai_type *ait, struct city *pcity,
1397 struct adv_choice *choice)
1398{
1399 const struct impr_type *chosen;
1400 adv_want want;
1401
1402 if (choice->type == CT_NONE) {
1403 want = 0;
1404 chosen = nullptr;
1405 } else {
1406 want = choice->want;
1407 chosen = choice->value.building;
1408 }
1409
1410 improvement_iterate(pimprove) {
1411 /* Advisor code did not consider wonders, let's do it here */
1412 if (is_wonder(pimprove)) {
1413 int id = improvement_index(pimprove);
1414
1415 if (pcity->server.adv->building_want[id] > want
1416 && can_city_build_improvement_now(pcity, pimprove)) {
1417 want = pcity->server.adv->building_want[id];
1418 chosen = pimprove;
1419 }
1420 }
1422
1423 choice->want = want;
1424 choice->value.building = chosen;
1425
1426 if (chosen) {
1427 choice->type = CT_BUILDING; /* In case advisor had not chosen anything */
1428
1429 CITY_LOG(LOG_DEBUG, pcity, "AI wants to build %s with want "
1432 }
1433}
1434
1435/**********************************************************************/
1445 struct city *pcity)
1446{
1448 int unhap = 0;
1449
1450 /* Bail out now if happy_cost is 0 */
1452 return FALSE;
1453 }
1454
1455 unit_list_iterate(pcity->units_supported, punit) {
1456 int happy_cost = city_unit_unhappiness(nmap, punit, &free_unhappy);
1457
1458 if (happy_cost > 0) {
1459 unhap += happy_cost;
1460 }
1462
1463 if (unhap < 0) {
1464 unhap = 0;
1465 }
1466
1467 return (unhap > 0);
1468}
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:3268
int action_number(const struct action *action)
Definition actions.c:1229
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:3344
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:3103
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:3180
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:3421
static struct action * action_by_number(action_id act_id)
Definition actions.h:400
#define action_has_result(_act_, _res_)
Definition actions.h:184
#define action_id_get_target_kind(act_id)
Definition actions.h:417
#define ACTION_NONE
Definition actions.h:59
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:613
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
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_CLR(bv, bit)
Definition bitvector.h:94
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:808
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:858
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3091
#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:736
#define city_owner(_pcity_)
Definition city.h:564
#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:367
bool is_stack_vulnerable(const struct tile *ptile)
Definition combat.c:994
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:77
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Definition daidata.c:402
bool aiferry_gobyboat(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile, bool with_bodyguard)
Definition daiferry.c:764
bool dai_is_ferry(struct unit *pferry, struct ai_type *ait)
Definition daiferry.c:159
void aiferry_clear_boat(struct ai_type *ait, struct unit *punit)
Definition daiferry.c:251
void aiguard_clear_charge(struct ai_type *ait, struct unit *guard)
Definition daiguard.c:117
void aiguard_request_guard(struct ai_type *ait, struct unit *punit)
Definition daiguard.c:227
void aiguard_assign_guard_city(struct ai_type *ait, struct city *charge, struct unit *guard)
Definition daiguard.c:196
struct unit * aiguard_charge_unit(struct ai_type *ait, struct unit *guard)
Definition daiguard.c:279
void aiguard_clear_guard(struct ai_type *ait, struct unit *charge)
Definition daiguard.c:146
struct unit * aiguard_guard_of(struct ai_type *ait, struct unit *charge)
Definition daiguard.c:269
#define CHECK_CHARGE_UNIT(ait, charge)
Definition daiguard.h:22
#define CHECK_GUARD(ait, guard)
Definition daiguard.h:21
#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:50
struct unit_type * dai_wants_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, int role, int want)
Definition daitech.c:522
void dai_government_change(struct player *pplayer, struct government *gov)
Definition daitools.c:1335
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:469
int stack_cost(struct unit *pattacker, struct unit *pdefender)
Definition daitools.c:1308
bool goto_is_sane(struct unit *punit, struct tile *ptile)
Definition daitools.c:429
#define LONG_TIME
Definition daitools.c:456
struct tile * immediate_destination(struct unit *punit, struct tile *dest_tile)
Definition daitools.c:302
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:1396
bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition daitools.c:817
bool dai_unit_goto(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition daitools.c:605
bool dai_unit_goto_constrained(struct ai_type *ait, struct unit *punit, struct tile *ptile, struct pf_parameter *parameter)
Definition daitools.c:378
void dai_log_path(struct unit *punit, struct pf_path *path, struct pf_parameter *parameter)
Definition daitools.c:356
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:643
int dai_gold_reserve(struct player *pplayer)
Definition daitools.c:1354
bool dai_assess_military_unhappiness(const struct civ_map *nmap, struct city *pcity)
Definition daitools.c:1444
void adjust_choice(int pct, struct adv_choice *choice)
Definition daitools.c:1364
bool dai_unit_make_homecity(struct unit *punit, struct city *pcity)
Definition daitools.c:755
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:1373
static void dai_unit_bodyguard_move(struct ai_type *ait, struct unit *bodyguard, struct tile *ptile)
Definition daitools.c:784
const char * dai_unit_task_rule_name(const enum ai_unit_task task)
Definition daitools.c:76
#define LOGLEVEL_GOTHERE
Definition daitools.c:234
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:244
bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition daitools.c:1111
void dai_unit_new_adv_task(struct ai_type *ait, struct unit *punit, enum adv_unit_task task, struct tile *ptile)
Definition daitools.c:619
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:1093
#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
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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:1050
adv_unit_task
Definition fc_types.h:231
@ AUT_BUILD_CITY
Definition fc_types.h:231
@ AUT_NONE
Definition fc_types.h:231
@ AUT_AUTO_WORKER
Definition fc_types.h:231
#define ADV_WANT_PRINTF
Definition fc_types.h:1051
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
override_bool
Definition fc_types.h:96
@ OVERRIDE_TRUE
Definition fc_types.h:96
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:116
struct government * government_of_player(const struct player *pplayer)
Definition government.c:116
Government_type_id government_number(const struct government *pgovern)
Definition government.c:93
GType type
Definition repodlgs.c:1313
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:192
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
@ LOG_DEBUG
Definition log.h:35
#define log_error(message,...)
Definition log.h:104
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:209
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:565
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Definition map.c:1067
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:1076
int map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:699
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
Definition map.h:299
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:522
#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:461
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:818
static bool is_barbarian(const struct player *pplayer)
Definition player.h:499
#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
int average_production
Definition advdata.h:98
struct adv_data::@94 stats
Definition ai.h:50
Definition city.h:318
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 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::@84::@87 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:216
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:536
const struct impr_type * building
Definition fc_types.h:529
int unit_pays_mp_for_action(const struct action *paction, const struct unit *punit)
Definition unit.c:2199
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1986
bool is_losing_hp(const struct unit *punit)
Definition unit.c:2292
bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:768
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2745
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2529
bool unit_has_orders(const struct unit *punit)
Definition unit.c:221
#define unit_tile(_pu)
Definition unit.h:407
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:430
#define CHECK_UNIT(punit)
Definition unit.h:273
#define unit_owner(_pu)
Definition unit.h:406
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity, enum gen_action trigger_action)
Definition unithand.c:6708
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:3350
#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:2882
void unit_transport_load_send(struct unit *punit, struct unit *ptrans)
Definition unittools.c:3394
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1274
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1613
bool utype_may_act_at_all(const struct unit_type *putype)
Definition unittype.c:384
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1509
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2530
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:412
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Definition unittype.c:233
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2629
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:215
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
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:847