Freeciv-3.1: /fast/freeciv/nightly/S3_1/ai/default/aitools.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
aitools.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 "packets.h"
32#include "player.h"
33#include "unit.h"
34#include "unitlist.h"
35
36/* common/aicore */
37#include "citymap.h"
38#include "pf_tools.h"
39
40/* server */
41#include "barbarian.h"
42#include "citytools.h"
43#include "cityturn.h"
44#include "maphand.h"
45#include "plrhand.h"
46#include "score.h"
47#include "srv_log.h"
48#include "unithand.h"
49#include "unittools.h"
50
51/* server/advisors */
52#include "advdata.h"
53#include "advgoto.h"
54#include "advtools.h"
55#include "autosettlers.h"
56#include "infracache.h" /* adv_city */
57
58/* ai */
59#include "handicaps.h"
60
61/* ai/default */
62#include "aidata.h"
63#include "aiferry.h"
64#include "aiguard.h"
65#include "ailog.h"
66#include "aiplayer.h"
67#include "aitech.h"
68#include "aiunit.h"
69#include "daimilitary.h"
70
71#include "aitools.h"
72
73/**********************************************************************/
77 const char *dai_unit_task_rule_name(const enum ai_unit_task task)
78{
79 switch (task) {
80 case AIUNIT_NONE:
81 return "None";
82 case AIUNIT_AUTO_SETTLER:
83 return "Auto settler";
84 case AIUNIT_BUILD_CITY:
85 return "Build city";
86 case AIUNIT_DEFEND_HOME:
87 return "Defend home";
88 case AIUNIT_ATTACK:
89 return "Attack";
90 case AIUNIT_ESCORT:
91 return "Escort";
92 case AIUNIT_EXPLORE:
93 return "Explore";
94 case AIUNIT_RECOVER:
95 return "Recover";
96 case AIUNIT_HUNTER:
97 return "Hunter";
98 case AIUNIT_TRADE:
99 return "Trade";
100 case AIUNIT_WONDER:
101 return "Wonder";
102 }
103
104 /* No default, ensure all types handled somehow */
105 log_error("Unsupported ai_unit_task %d.", task);
106
107 return NULL;
108}
109
110/**********************************************************************/
118 adv_want military_amortize(struct player *pplayer, struct city *pcity,
119 adv_want value, int delay, int build_cost)
120{
121 struct adv_data *ai = adv_data_get(pplayer, NULL);
122 int city_output = (pcity ? pcity->surplus[O_SHIELD] : 1);
123 int output = MAX(city_output, ai->stats.average_production);
124 int build_time = build_cost / MAX(output, 1);
125
126 if (value <= 0) {
127 return 0;
128 }
129
130 return amortize(value, delay + build_time);
131}
132
133/**********************************************************************/
142 void dai_consider_plr_dangerous(struct ai_type *ait, struct player *plr1,
143 struct player *plr2,
144 enum override_bool *result)
145{
146 struct ai_dip_intel *adip;
147
148 adip = dai_diplomacy_get(ait, plr1, plr2);
149
150 if (adip->countdown >= 0) {
151 /* Don't trust our war target */
152 *result = OVERRIDE_TRUE;
153 }
154}
155
156/**********************************************************************/
161 static bool dai_gothere_bodyguard(struct ai_type *ait,
162 struct unit *punit, struct tile *dest_tile)
163{
164 struct player *pplayer = unit_owner(punit);
165 unsigned int danger = 0;
166 struct city *dcity;
167 struct unit *guard = aiguard_guard_of(ait, punit);
168 const struct veteran_level *vlevel;
169 bool bg_needed = FALSE;
170
171 if (is_barbarian(unit_owner(punit))) {
172 /* barbarians must have more courage (ie less brains) */
173 aiguard_clear_guard(ait, punit);
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 }
182 } unit_list_iterate_end;
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 */
186 struct unit_type *d_type = dai_choose_defender_versus(dcity, punit);
187
188 if (d_type) {
189 /* Enemy really can build something */
190 danger +=
191 adv_unittype_att_rating(
192 d_type, city_production_unit_veteran_level(dcity, d_type),
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 */
201 danger /= (unit_type_get(punit)->move_rate / SINGLE_MOVE);
202 if (unit_has_type_flag(punit, UTYF_IGTER)) {
203 danger /= 1.5;
204 }
205
206 vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran);
207 fc_assert_ret_val(vlevel != NULL, FALSE);
208
209 /* We look for the bodyguard where we stand. */
210 if (guard == NULL || unit_tile(guard) != unit_tile(punit)) {
211 int my_def = (punit->hp * unit_type_get(punit)->defense_strength
212 * POWER_FACTOR * vlevel->power_fact / 100);
213
214 if (danger >= my_def) {
215 UNIT_LOG(LOGLEVEL_BODYGUARD, punit,
216 "want bodyguard @(%d, %d) danger=%d, my_def=%d",
217 TILE_XY(dest_tile), danger, my_def);
218 aiguard_request_guard(ait, punit);
219 bg_needed = TRUE;
220 } else {
221 aiguard_clear_guard(ait, punit);
222 bg_needed = FALSE;
223 }
224 } else if (guard != NULL) {
225 bg_needed = TRUE;
226 }
227
228 /* What if we have a bodyguard, but don't need one? */
229
230 return bg_needed;
231}
232
233#define LOGLEVEL_GOTHERE LOG_DEBUG
234/**********************************************************************/
243 bool dai_gothere(struct ai_type *ait, struct player *pplayer,
244 struct unit *punit, struct tile *dest_tile)
245{
246 CHECK_UNIT(punit);
247 bool bg_needed;
248
249 if (same_pos(dest_tile, unit_tile(punit)) || punit->moves_left <= 0) {
250 /* Nowhere to go */
251 return TRUE;
252 }
253
254 /* See if we need a bodyguard at our destination */
255 /* FIXME: If bodyguard is _really_ necessary, don't go anywhere */
256 bg_needed = dai_gothere_bodyguard(ait, punit, dest_tile);
257
258 if (unit_transported(punit)
259 || !goto_is_sane(punit, dest_tile)) {
260 /* Must go by boat, call an aiferryboat function */
261 if (!aiferry_gobyboat(ait, pplayer, punit, dest_tile,
262 bg_needed)) {
263 return FALSE;
264 }
265 }
266
267 /* Go where we should be going if we can, and are at our destination
268 * if we are on a ferry */
269 if (goto_is_sane(punit, dest_tile) && punit->moves_left > 0) {
270 punit->goto_tile = dest_tile;
271 UNIT_LOG(LOGLEVEL_GOTHERE, punit, "Walking to (%d,%d)", TILE_XY(dest_tile));
272 if (!dai_unit_goto(ait, punit, dest_tile)) {
273 /* died */
274 return FALSE;
275 }
276 /* liable to bump into someone that will kill us. Should avoid? */
277 } else {
278 UNIT_LOG(LOGLEVEL_GOTHERE, punit, "Not moving");
279 return FALSE;
280 }
281
282 if (def_ai_unit_data(punit, ait)->ferryboat > 0
283 && !unit_transported(punit)) {
284 /* We probably just landed, release our boat */
285 aiferry_clear_boat(ait, punit);
286 }
287
288 /* Dead unit shouldn't reach this point */
289 CHECK_UNIT(punit);
290
291 return (same_pos(unit_tile(punit), dest_tile)
292 || is_tiles_adjacent(unit_tile(punit), dest_tile));
293}
294
295/**********************************************************************/
301 struct tile *immediate_destination(struct unit *punit,
302 struct tile *dest_tile)
303{
304 const struct civ_map *nmap = &(wld.map);
305
306 if (!same_pos(unit_tile(punit), dest_tile)
307 && utype_fuel(unit_type_get(punit))) {
308 struct pf_parameter parameter;
309 struct pf_map *pfm;
310 struct pf_path *path;
311 size_t i;
312 struct player *pplayer = unit_owner(punit);
313
314 pft_fill_unit_parameter(&parameter, nmap, punit);
315 parameter.omniscience = !has_handicap(pplayer, H_MAP);
316 pfm = pf_map_new(&parameter);
317 path = pf_map_path(pfm, punit->goto_tile);
318
319 if (path) {
320 for (i = 1; i < path->length; i++) {
321 if (path->positions[i].tile == path->positions[i - 1].tile) {
322 /* The path-finding code advices us to wait there to refuel. */
323 struct tile *ptile = path->positions[i].tile;
324
325 pf_path_destroy(path);
326 pf_map_destroy(pfm);
327 return ptile;
328 }
329 }
330 pf_path_destroy(path);
331 pf_map_destroy(pfm);
332 /* Seems it's the immediate destination */
333 return punit->goto_tile;
334 }
335
336 pf_map_destroy(pfm);
337 log_verbose("Did not find an air-route for "
338 "%s %s[%d] (%d,%d)->(%d,%d)",
339 nation_rule_name(nation_of_unit(punit)),
340 unit_rule_name(punit),
341 punit->id,
342 TILE_XY(unit_tile(punit)),
343 TILE_XY(dest_tile));
344 /* Prevent take off */
345 return unit_tile(punit);
346 }
347
348 /* else does not need way-points */
349 return dest_tile;
350}
351
352/**********************************************************************/
355 void dai_log_path(struct unit *punit,
356 struct pf_path *path, struct pf_parameter *parameter)
357{
358 const struct pf_position *last = pf_path_last_position(path);
359 const unsigned cc = PF_TURN_FACTOR * last->total_MC
360 + parameter->move_rate * last->total_EC;
361 const unsigned tc = cc / (PF_TURN_FACTOR * parameter->move_rate);
362
363 UNIT_LOG(LOG_DEBUG, punit, "path L=%d T=%d(%u) MC=%u EC=%u CC=%u",
364 path->length - 1, last->turn, tc,
365 last->total_MC, last->total_EC, cc);
366}
367
368/**********************************************************************/
377 bool dai_unit_goto_constrained(struct ai_type *ait, struct unit *punit,
378 struct tile *ptile,
379 struct pf_parameter *parameter)
380{
381 bool alive = TRUE;
382 struct pf_map *pfm;
383 struct pf_path *path;
384
385 UNIT_LOG(LOG_DEBUG, punit, "constrained goto to %d,%d", TILE_XY(ptile));
386
387 if (same_pos(unit_tile(punit), ptile)) {
388 /* Was not an error in previous versions but now is dubious... */
389 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: already there!");
390 send_unit_info(NULL, punit);
391
392 return TRUE;
393 } else if (!goto_is_sane(punit, ptile)) {/* FIXME: why do we check it? */
394 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: 'insane' goto!");
395 punit->activity = ACTIVITY_IDLE;
396 send_unit_info(NULL, punit);
397
398 return TRUE;
399 } else if (punit->moves_left == 0) {
400 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: no moves left!");
401 send_unit_info(NULL, punit);
402
403 return TRUE;
404 }
405
406 pfm = pf_map_new(parameter);
407 path = pf_map_path(pfm, ptile);
408
409 if (path) {
410 dai_log_path(punit, path, parameter);
411 UNIT_LOG(LOG_DEBUG, punit, "constrained goto: following path.");
412 alive = adv_follow_path(punit, path, ptile);
413 } else {
414 UNIT_LOG(LOG_DEBUG, punit, "no path to destination");
415 }
416
417 pf_path_destroy(path);
418 pf_map_destroy(pfm);
419
420 return alive;
421}
422
423/**********************************************************************/
428 bool goto_is_sane(struct unit *punit, struct tile *ptile)
429{
430 bool can_get_there = FALSE;
431 const struct civ_map *nmap = &(wld.map);
432
433 if (same_pos(unit_tile(punit), ptile)) {
434 can_get_there = TRUE;
435 } else {
436 struct pf_parameter parameter;
437 struct pf_map *pfm;
438
439 pft_fill_unit_attack_param(&parameter, nmap, punit);
440 pfm = pf_map_new(&parameter);
441
442 if (pf_map_move_cost(pfm, ptile) != PF_IMPOSSIBLE_MC) {
443 can_get_there = TRUE;
444 }
445 pf_map_destroy(pfm);
446 }
447 return can_get_there;
448}
449
450/*
451 * The length of time, in turns, which is long enough to be optimistic
452 * that enemy units will have moved from their current position.
453 * WAG
454 */
455#define LONG_TIME 4
456/**********************************************************************/
468 void dai_fill_unit_param(struct ai_type *ait, struct pf_parameter *parameter,
469 struct adv_risk_cost *risk_cost,
470 struct unit *punit, struct tile *ptile)
471{
472 const bool long_path = LONG_TIME < (map_distance(unit_tile(punit),
473 unit_tile(punit))
474 * SINGLE_MOVE
475 / unit_type_get(punit)->move_rate);
476 const bool barbarian = is_barbarian(unit_owner(punit));
477 bool is_ferry;
478 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
479 struct player *pplayer = unit_owner(punit);
480 const struct civ_map *nmap = &(wld.map);
481
482 /* This function is now always omniscient and should not be used
483 * for human players any more. */
484 fc_assert(is_ai(pplayer));
485
486 /* If a unit is hunting, don't expect it to be a ferry. */
487 is_ferry = (unit_data->task != AIUNIT_HUNTER
488 && dai_is_ferry(punit, ait));
489
490 if (is_ferry) {
491 /* The destination may be a coastal land tile,
492 * in which case the ferry should stop on an adjacent tile. */
493 pft_fill_unit_overlap_param(parameter, nmap, punit);
494 } else if (!utype_fuel(unit_type_get(punit))
495 && utype_can_do_action_result(unit_type_get(punit),
496 ACTRES_ATTACK)
497 && (unit_data->task == AIUNIT_DEFEND_HOME
498 || unit_data->task == AIUNIT_ATTACK
499 || unit_data->task == AIUNIT_ESCORT
500 || unit_data->task == AIUNIT_HUNTER)) {
501 /* Use attack movement for defenders and escorts so they can
502 * make defensive attacks */
503 pft_fill_unit_attack_param(parameter, nmap, punit);
504 } else {
505 pft_fill_unit_parameter(parameter, nmap, punit);
506 }
507 parameter->omniscience = !has_handicap(pplayer, H_MAP);
508
509 /* Should we use the risk avoidance code?
510 * The risk avoidance code uses omniscience, so do not use for
511 * human-player units under temporary AI control.
512 * Barbarians bravely/stupidly ignore risks
513 */
514 if (!uclass_has_flag(unit_class_get(punit), UCF_UNREACHABLE)
515 && !barbarian) {
516 adv_avoid_risks(parameter, risk_cost, punit, NORMAL_STACKING_FEARFULNESS);
517 }
518
519 /* Should we absolutely forbid ending a turn on a dangerous tile?
520 * Do not annoy human players by killing their units for them.
521 * For AI units be optimistic; allows attacks across dangerous terrain,
522 * and polar settlements.
523 * TODO: This is compatible with old code,
524 * but probably ought to be more cautious for non military units
525 */
526 if (!is_ferry && !utype_fuel(unit_type_get(punit))) {
527 parameter->get_moves_left_req = NULL;
528 }
529
530 if (long_path) {
531 /* Move as far along the path to the destination as we can;
532 * that is, ignore the presence of enemy units when computing the
533 * path.
534 * Hopefully, ai_avoid_risks will have produced a path that avoids enemy
535 * ZoCs. Ignoring ZoCs allows us to move closer to a destination
536 * for which there is not yet a clear path.
537 * That is good if the destination is several turns away,
538 * so we can reasonably expect blocking enemy units to move or
539 * be destroyed. But it can be bad if the destination is one turn away
540 * or our destination is far but there are enemy units near us and on the
541 * shortest path to the destination.
542 */
543 parameter->get_zoc = NULL;
544 }
545
546 if (unit_has_type_flag(punit, UTYF_SETTLERS)) {
547 parameter->get_TB = no_fights;
548 } else if (long_path && unit_is_cityfounder(punit)) {
549 /* Default tile behaviour;
550 * move as far along the path to the destination as we can;
551 * that is, ignore the presence of enemy units when computing the
552 * path.
553 */
554 } else if (unit_is_cityfounder(punit)) {
555 /* Short path */
556 parameter->get_TB = no_fights;
557 } else if (unit_has_type_role(punit, L_BARBARIAN_LEADER)) {
558 /* Avoid capture */
559 parameter->get_TB = no_fights;
560 } else if (is_ferry) {
561 /* Ferries are not warships */
562 parameter->get_TB = no_fights;
563 } else if (is_losing_hp(punit)) {
564 /* Losing hitpoints over time (helicopter in default rules) */
565 /* Default tile behaviour */
566 } else if (utype_may_act_at_all(unit_type_get(punit))) {
567 switch (unit_data->task) {
568 case AIUNIT_AUTO_SETTLER:
569 case AIUNIT_BUILD_CITY:
570 /* Strange, but not impossible */
571 parameter->get_TB = no_fights;
572 break;
573 case AIUNIT_DEFEND_HOME:
574 case AIUNIT_ATTACK: /* Includes spy actions */
575 case AIUNIT_ESCORT:
576 case AIUNIT_HUNTER:
577 case AIUNIT_TRADE:
578 case AIUNIT_WONDER:
579 parameter->get_TB = no_intermediate_fights;
580 break;
581 case AIUNIT_EXPLORE:
582 case AIUNIT_RECOVER:
583 parameter->get_TB = no_fights;
584 break;
585 case AIUNIT_NONE:
586 /* Default tile behaviour */
587 break;
588 }
589 } else {
590 /* Probably an explorer */
591 parameter->get_TB = no_fights;
592 }
593
594 if (is_ferry) {
595 /* Show the destination in the client when watching an AI: */
596 punit->goto_tile = ptile;
597 }
598}
599
600/**********************************************************************/
604 bool dai_unit_goto(struct ai_type *ait, struct unit *punit, struct tile *ptile)
605{
606 struct pf_parameter parameter;
607 struct adv_risk_cost risk_cost;
608
609 UNIT_LOG(LOG_DEBUG, punit, "dai_unit_goto to %d,%d", TILE_XY(ptile));
610 dai_fill_unit_param(ait, &parameter, &risk_cost, punit, ptile);
611
612 return dai_unit_goto_constrained(ait, punit, ptile, &parameter);
613}
614
615/**********************************************************************/
618 void dai_unit_new_adv_task(struct ai_type *ait, struct unit *punit,
619 enum adv_unit_task task, struct tile *ptile)
620{
621 /* Keep ai_unit_task in sync with adv task */
622 switch (task) {
623 case AUT_AUTO_SETTLER:
624 dai_unit_new_task(ait, punit, AIUNIT_AUTO_SETTLER, ptile);
625 break;
626 case AUT_BUILD_CITY:
627 dai_unit_new_task(ait, punit, AIUNIT_BUILD_CITY, ptile);
628 break;
629 case AUT_NONE:
630 dai_unit_new_task(ait, punit, AIUNIT_NONE, ptile);
631 break;
632 }
633}
634
635/**********************************************************************/
642 void dai_unit_new_task(struct ai_type *ait, struct unit *punit,
643 enum ai_unit_task task, struct tile *ptile)
644{
645 struct unit *bodyguard = aiguard_guard_of(ait, punit);
646 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
647
648 /* If the unit is under (human) orders we shouldn't control it.
649 * Allow removal of old role with AIUNIT_NONE. */
650 fc_assert_ret(!unit_has_orders(punit) || task == AIUNIT_NONE);
651
652 UNIT_LOG(LOG_DEBUG, punit, "changing task from %s to %s",
653 dai_unit_task_rule_name(unit_data->task),
654 dai_unit_task_rule_name(task));
655
656 /* Free our ferry. Most likely it has been done already. */
657 if (task == AIUNIT_NONE || task == AIUNIT_DEFEND_HOME) {
658 aiferry_clear_boat(ait, punit);
659 }
660
661 if (punit->activity == ACTIVITY_GOTO) {
662 /* It would indicate we're going somewhere otherwise */
663 unit_activity_handling(punit, ACTIVITY_IDLE);
664 }
665
666 if (unit_data->task == AIUNIT_BUILD_CITY) {
667 if (punit->goto_tile) {
668 citymap_free_city_spot(punit->goto_tile, punit->id);
669 } else {
670 /* Print error message instead of crashing in citymap_free_city_spot()
671 * This probably means that some city spot reservation has not been
672 * properly cleared; bad for the AI, as it will leave that area
673 * uninhabited. */
674 log_error("%s was on city founding mission without target tile.",
675 unit_rule_name(punit));
676 }
677 }
678
679 if (unit_data->task == AIUNIT_HUNTER) {
680 /* Clear victim's hunted bit - we're no longer chasing. */
681 struct unit *target = game_unit_by_number(unit_data->target);
682
683 if (target) {
684 BV_CLR(def_ai_unit_data(target, ait)->hunted,
685 player_index(unit_owner(punit)));
686 UNIT_LOG(LOGLEVEL_HUNT, target, "no longer hunted (new task %d, old %d)",
687 task, unit_data->task);
688 }
689 }
690
691 aiguard_clear_charge(ait, punit);
692 /* Record the city to defend; our goto may be to transport. */
693 if (task == AIUNIT_DEFEND_HOME && ptile && tile_city(ptile)) {
694 aiguard_assign_guard_city(ait, tile_city(ptile), punit);
695 }
696
697 unit_data->task = task;
698
699 /* Verify and set the goto destination. Eventually this can be a lot more
700 * stringent, but for now we don't want to break things too badly. */
701 punit->goto_tile = ptile; /* May be NULL. */
702
703 if (unit_data->task == AIUNIT_NONE && bodyguard) {
704 dai_unit_new_task(ait, bodyguard, AIUNIT_NONE, NULL);
705 }
706
707 /* Reserve city spot, _unless_ we want to add ourselves to a city. */
708 if (unit_data->task == AIUNIT_BUILD_CITY && !tile_city(ptile)) {
709 citymap_reserve_city_spot(ptile, punit->id);
710 }
711 if (unit_data->task == AIUNIT_HUNTER) {
712 /* Set victim's hunted bit - the hunt is on! */
713 struct unit *target = game_unit_by_number(unit_data->target);
714
715 fc_assert_ret(target != NULL);
716 BV_SET(def_ai_unit_data(target, ait)->hunted, player_index(unit_owner(punit)));
717 UNIT_LOG(LOGLEVEL_HUNT, target, "is being hunted");
718
719 /* Grab missiles lying around and bring them along */
720 unit_list_iterate(unit_tile(punit)->units, missile) {
721 if (unit_owner(missile) == unit_owner(punit)
722 && def_ai_unit_data(missile, ait)->task != AIUNIT_ESCORT
723 && !unit_transported(missile)
724 && unit_owner(missile) == unit_owner(punit)
725 && utype_can_do_action(unit_type_get(missile),
726 ACTION_SUICIDE_ATTACK)
727 && can_unit_load(missile, punit)) {
728 UNIT_LOG(LOGLEVEL_HUNT, missile, "loaded on hunter");
729 dai_unit_new_task(ait, missile, AIUNIT_ESCORT, unit_tile(target));
730 unit_transport_load_send(missile, punit);
731 }
732 } unit_list_iterate_end;
733 }
734
735 /* Map ai tasks to advisor tasks. For most ai tasks there is
736 no advisor, so AUT_NONE is set. */
737 switch (unit_data->task) {
738 case AIUNIT_AUTO_SETTLER:
739 punit->server.adv->task = AUT_AUTO_SETTLER;
740 break;
741 case AIUNIT_BUILD_CITY:
742 punit->server.adv->task = AUT_BUILD_CITY;
743 break;
744 default:
745 punit->server.adv->task = AUT_NONE;
746 break;
747 }
748}
749
750/**********************************************************************/
754 bool dai_unit_make_homecity(struct unit *punit, struct city *pcity)
755{
756 CHECK_UNIT(punit);
757 fc_assert_ret_val(unit_owner(punit) == city_owner(pcity), TRUE);
758
759 if (punit->homecity == 0 && !unit_has_type_role(punit, L_EXPLORER)) {
760 /* This unit doesn't pay any upkeep while it doesn't have a homecity,
761 * so it would be stupid to give it one. There can also be good reasons
762 * why it doesn't have a homecity. */
763 /* However, until we can do something more useful with them, we
764 will assign explorers to a city so that they can be disbanded for
765 the greater good -- Per */
766 return FALSE;
767 }
768 if (pcity->surplus[O_SHIELD] >= unit_type_get(punit)->upkeep[O_SHIELD]
769 && pcity->surplus[O_FOOD] >= unit_type_get(punit)->upkeep[O_FOOD]) {
770 unit_do_action(unit_owner(punit), punit->id, pcity->id,
771 0, "", ACTION_HOME_CITY);
772 return TRUE;
773 }
774 return FALSE;
775}
776
777/**********************************************************************/
783 static void dai_unit_bodyguard_move(struct ai_type *ait,
784 struct unit *bodyguard, struct tile *ptile)
785{
786 fc_assert_ret(bodyguard != NULL);
787 fc_assert_ret(unit_owner(bodyguard) != NULL);
788
789#ifndef FREECIV_NDEBUG
790 struct unit *punit =
791#endif
792 aiguard_charge_unit(ait, bodyguard);
793
794 fc_assert_ret(punit != NULL);
795
796 CHECK_GUARD(ait, bodyguard);
797 CHECK_CHARGE_UNIT(ait, punit);
798
799 if (!is_tiles_adjacent(ptile, unit_tile(bodyguard))) {
800 return;
801 }
802
803 if (bodyguard->moves_left <= 0) {
804 /* should generally should not happen */
805 BODYGUARD_LOG(ait, LOG_DEBUG, bodyguard, "was left behind by charge");
806 return;
807 }
808
809 unit_activity_handling(bodyguard, ACTIVITY_IDLE);
810 (void) dai_unit_move(ait, bodyguard, ptile);
811}
812
813/**********************************************************************/
816 bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile)
817{
818 struct unit *ptrans;
819 struct unit *bodyguard = aiguard_guard_of(ait, punit);
820 int sanity = punit->id;
821 bool alive;
822 struct city *tcity;
823 const struct civ_map *nmap = &(wld.map);
824
825 CHECK_UNIT(punit);
826 fc_assert_ret_val(is_ai(unit_owner(punit)), TRUE);
827 fc_assert_ret_val(is_tiles_adjacent(unit_tile(punit), ptile), TRUE);
828
829 unit_activity_handling(punit, ACTIVITY_IDLE);
830 /* FIXME: try the next action if the unit tried to do an illegal action.
831 * That would allow the AI to stop using the omniscient
832 * is_action_enabled_unit_on_*() functions. */
833 if (is_action_enabled_unit_on_units(nmap, ACTION_CAPTURE_UNITS,
834 punit, ptile)) {
835 /* Choose capture. */
836 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
837 0, "", ACTION_CAPTURE_UNITS);
838 } else if (is_action_enabled_unit_on_units(nmap, ACTION_BOMBARD,
839 punit, ptile)) {
840 /* Choose "Bombard". */
841 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
842 0, "", ACTION_BOMBARD);
843 } else if (is_action_enabled_unit_on_units(nmap, ACTION_BOMBARD2,
844 punit, ptile)) {
845 /* Choose "Bombard 2". */
846 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
847 0, "", ACTION_BOMBARD2);
848 } else if (is_action_enabled_unit_on_units(nmap, ACTION_BOMBARD3,
849 punit, ptile)) {
850 /* Choose "Bombard 3". */
851 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
852 0, "", ACTION_BOMBARD3);
853 } else if (is_action_enabled_unit_on_units(nmap, ACTION_NUKE_UNITS,
854 punit, ptile)) {
855 /* Choose "Nuke Units". */
856 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
857 0, "", ACTION_NUKE_UNITS);
858 } else if (action_id_get_target_kind(ACTION_NUKE) == ATK_TILE
859 && is_action_enabled_unit_on_tile(nmap, ACTION_NUKE,
860 punit, ptile, NULL)) {
861 /* Choose "Explode Nuclear". */
862 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
863 0, "", ACTION_NUKE);
864 } else if (action_id_get_target_kind(ACTION_NUKE) == ATK_CITY
865 && (tcity = tile_city(ptile))
866 && is_action_enabled_unit_on_city(nmap, ACTION_NUKE,
867 punit, tcity)) {
868 /* Choose "Explode Nuclear". */
869 unit_do_action(unit_owner(punit), punit->id, tcity->id,
870 0, "", ACTION_NUKE);
871 } else if (action_id_get_target_kind(ACTION_NUKE_CITY) == ATK_TILE
872 && is_action_enabled_unit_on_tile(nmap, ACTION_NUKE_CITY,
873 punit, ptile, NULL)) {
874 /* Choose "Nuke City". */
875 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
876 0, "", ACTION_NUKE_CITY);
877 } else if (action_id_get_target_kind(ACTION_NUKE_CITY) == ATK_CITY
878 && (tcity = tile_city(ptile))
879 && is_action_enabled_unit_on_city(nmap, ACTION_NUKE_CITY,
880 punit, tcity)) {
881 /* Choose "Nuke City". */
882 unit_do_action(unit_owner(punit), punit->id, tcity->id,
883 0, "", ACTION_NUKE_CITY);
884 } else if (is_action_enabled_unit_on_units(nmap, ACTION_ATTACK,
885 punit, ptile)) {
886 /* Choose regular attack. */
887 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
888 0, "", ACTION_ATTACK);
889 } else if (is_action_enabled_unit_on_units(nmap, ACTION_SUICIDE_ATTACK,
890 punit, ptile)) {
891 /* Choose suicide attack (explode missile). */
892 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
893 0, "", ACTION_SUICIDE_ATTACK);
894 } else if ((tcity = tile_city(ptile))
895 && is_action_enabled_unit_on_city(nmap, ACTION_CONQUER_CITY,
896 punit, tcity)) {
897 /* Choose "Conquer City". */
898 unit_do_action(unit_owner(punit), punit->id, tcity->id,
899 0, "", ACTION_CONQUER_CITY);
900 } else if ((tcity = tile_city(ptile))
901 && is_action_enabled_unit_on_city(nmap, ACTION_CONQUER_CITY2,
902 punit, tcity)) {
903 /* Choose "Conquer City 2". */
904 unit_do_action(unit_owner(punit), punit->id, tcity->id,
905 0, "", ACTION_CONQUER_CITY2);
906 } else if ((tcity = tile_city(ptile))
907 && is_action_enabled_unit_on_city(nmap, ACTION_CONQUER_CITY3,
908 punit, tcity)) {
909 /* Choose "Conquer City 3". */
910 unit_do_action(unit_owner(punit), punit->id, tcity->id,
911 0, "", ACTION_CONQUER_CITY3);
912 } else if ((tcity = tile_city(ptile))
913 && is_action_enabled_unit_on_city(nmap, ACTION_CONQUER_CITY4,
914 punit, tcity)) {
915 /* Choose "Conquer City 4". */
916 unit_do_action(unit_owner(punit), punit->id, tcity->id,
917 0, "", ACTION_CONQUER_CITY4);
918 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
919 && ((ptrans = transporter_for_unit_at(punit, ptile)))
920 && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
921 punit, ptrans)) {
922 /* "Transport Embark". */
923 unit_do_action(unit_owner(punit), punit->id, ptrans->id,
924 0, "", ACTION_TRANSPORT_EMBARK);
925 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
926 && ((ptrans = transporter_for_unit_at(punit, ptile)))
927 && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
928 punit, ptrans)) {
929 /* "Transport Embark 2". */
930 unit_do_action(unit_owner(punit), punit->id, ptrans->id,
931 0, "", ACTION_TRANSPORT_EMBARK2);
932 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
933 && ((ptrans = transporter_for_unit_at(punit, ptile)))
934 && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
935 punit, ptrans)) {
936 /* "Transport Embark 3". */
937 unit_do_action(unit_owner(punit), punit->id, ptrans->id,
938 0, "", ACTION_TRANSPORT_EMBARK3);
939 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK1,
940 punit, ptile, NULL)) {
941 /* "Transport Disembark". */
942 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
943 0, "", ACTION_TRANSPORT_DISEMBARK1);
944 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK2,
945 punit, ptile, NULL)) {
946 /* "Transport Disembark 2". */
947 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
948 0, "", ACTION_TRANSPORT_DISEMBARK2);
949 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK3,
950 punit, ptile, NULL)) {
951 /* "Transport Disembark 3". */
952 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
953 0, "", ACTION_TRANSPORT_DISEMBARK3);
954 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK4,
955 punit, ptile, NULL)) {
956 /* "Transport Disembark 4". */
957 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
958 0, "", ACTION_TRANSPORT_DISEMBARK4);
959 } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
960 && is_action_enabled_unit_on_extras(nmap, ACTION_CONQUER_EXTRAS,
961 punit, ptile, NULL)) {
962 /* Choose "Conquer Extras". */
963 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
964 0, "", ACTION_CONQUER_EXTRAS);
965 } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
966 && is_action_enabled_unit_on_extras(nmap, ACTION_CONQUER_EXTRAS2,
967 punit, ptile, NULL)) {
968 /* Choose "Conquer Extras 2". */
969 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
970 0, "", ACTION_CONQUER_EXTRAS2);
971 } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
972 && is_action_enabled_unit_on_extras(nmap, ACTION_CONQUER_EXTRAS3,
973 punit, ptile, NULL)) {
974 /* Choose "Conquer Extras 3". */
975 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
976 0, "", ACTION_CONQUER_EXTRAS3);
977 } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
978 && is_action_enabled_unit_on_extras(nmap, ACTION_CONQUER_EXTRAS4,
979 punit, ptile, NULL)) {
980 /* Choose "Conquer Extras 4". */
981 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
982 0, "", ACTION_CONQUER_EXTRAS4);
983 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER,
984 punit, ptile, NULL)) {
985 /* Choose "Enter Hut". */
986 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
987 0, "", ACTION_HUT_ENTER);
988 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER2,
989 punit, ptile, NULL)) {
990 /* Choose "Enter Hut 2". */
991 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
992 0, "", ACTION_HUT_ENTER2);
993 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER3,
994 punit, ptile, NULL)) {
995 /* Choose "Enter Hut 3". */
996 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
997 0, "", ACTION_HUT_ENTER3);
998 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER4,
999 punit, ptile, NULL)) {
1000 /* Choose "Enter Hut 4". */
1001 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
1002 0, "", ACTION_HUT_ENTER4);
1003 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN,
1004 punit, ptile, NULL)) {
1005 /* Choose "Frighten Hut". */
1006 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
1007 0, "", ACTION_HUT_FRIGHTEN);
1008 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN2,
1009 punit, ptile, NULL)) {
1010 /* Choose "Frighten Hut 2". */
1011 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
1012 0, "", ACTION_HUT_FRIGHTEN2);
1013 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN3,
1014 punit, ptile, NULL)) {
1015 /* Choose "Frighten Hut 3". */
1016 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
1017 0, "", ACTION_HUT_FRIGHTEN3);
1018 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN4,
1019 punit, ptile, NULL)) {
1020 /* Choose "Frighten Hut 4". */
1021 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
1022 0, "", ACTION_HUT_FRIGHTEN4);
1023 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE,
1024 punit, ptile, NULL)) {
1025 /* Choose "Unit Move". */
1026 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
1027 0, "", ACTION_UNIT_MOVE);
1028 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE2,
1029 punit, ptile, NULL)) {
1030 /* Choose "Unit Move 2". */
1031 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
1032 0, "", ACTION_UNIT_MOVE2);
1033 } else {
1034 /* Choose "Unit Move 3". */
1035 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
1036 0, "", ACTION_UNIT_MOVE3);
1037 }
1038 alive = (game_unit_by_number(sanity) != NULL);
1039
1040 if (alive && same_pos(ptile, unit_tile(punit))
1041 && bodyguard != NULL && def_ai_unit_data(bodyguard, ait)->charge == punit->id) {
1042 dai_unit_bodyguard_move(ait, bodyguard, ptile);
1043 /* Clumsy bodyguard might trigger an auto-attack */
1044 alive = (game_unit_by_number(sanity) != NULL);
1045 }
1046
1047 return alive;
1048}
1049
1050/**********************************************************************/
1053 void dai_unit_move_or_attack(struct ai_type *ait, struct unit *punit,
1054 struct tile *ptile, struct pf_path *path, int step)
1055{
1056 if (step == path->length - 1) {
1057 (void) dai_unit_attack(ait, punit, ptile);
1058 } else {
1059 (void) dai_unit_move(ait, punit, ptile);
1060 }
1061}
1062
1063/**********************************************************************/
1071 bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile)
1072{
1073 struct action *paction;
1074 struct unit *bodyguard;
1075 struct unit *ptrans = NULL;
1076 int sanity = punit->id;
1077 struct player *pplayer = unit_owner(punit);
1078 const bool is_plr_ai = is_ai(pplayer);
1079 const struct civ_map *nmap = &(wld.map);
1080
1081 CHECK_UNIT(punit);
1082 fc_assert_ret_val_msg(is_tiles_adjacent(unit_tile(punit), ptile), FALSE,
1083 "Tiles not adjacent: Unit = %d, "
1084 "from = (%d, %d]) to = (%d, %d).",
1085 punit->id, TILE_XY(unit_tile(punit)),
1086 TILE_XY(ptile));
1087
1088 /* if enemy, stop and give a chance for the ai attack function
1089 * to handle this case */
1090 if (is_enemy_unit_tile(ptile, pplayer)
1091 || is_enemy_city_tile(ptile, pplayer)) {
1092 UNIT_LOG(LOG_DEBUG, punit, "movement halted due to enemy presence");
1093 return FALSE;
1094 }
1095
1096 /* barbarians shouldn't enter huts */
1097 /* FIXME: use unit_can_displace_hut(punit, ptile) better */
1098 if (is_barbarian(pplayer) && hut_on_tile(ptile)) {
1099 return FALSE;
1100 }
1101
1102 /* don't leave bodyguard behind */
1103 if (is_plr_ai
1104 && (bodyguard = aiguard_guard_of(ait, punit))
1105 && same_pos(unit_tile(punit), unit_tile(bodyguard))
1106 && bodyguard->moves_left == 0) {
1107 UNIT_LOG(LOGLEVEL_BODYGUARD, punit, "does not want to leave "
1108 "its bodyguard");
1109 return FALSE;
1110 }
1111
1112 /* Select move kind. */
1113 if (!can_unit_survive_at_tile(nmap, punit, ptile)
1114 && ((ptrans = transporter_for_unit_at(punit, ptile)))
1115 && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
1116 punit, ptrans)) {
1117 /* "Transport Embark". */
1118 paction = action_by_number(ACTION_TRANSPORT_EMBARK);
1119 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
1120 && ptrans != NULL
1121 && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
1122 punit, ptrans)) {
1123 /* "Transport Embark 2". */
1124 paction = action_by_number(ACTION_TRANSPORT_EMBARK2);
1125 } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
1126 && ptrans != NULL
1127 && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
1128 punit, ptrans)) {
1129 /* "Transport Embark 3". */
1130 paction = action_by_number(ACTION_TRANSPORT_EMBARK3);
1131 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK1,
1132 punit, ptile, NULL)) {
1133 /* "Transport Disembark". */
1134 paction = action_by_number(ACTION_TRANSPORT_DISEMBARK1);
1135 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK2,
1136 punit, ptile, NULL)) {
1137 /* "Transport Disembark 2". */
1138 paction = action_by_number(ACTION_TRANSPORT_DISEMBARK2);
1139 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK3,
1140 punit, ptile, NULL)) {
1141 /* "Transport Disembark 3". */
1142 paction = action_by_number(ACTION_TRANSPORT_DISEMBARK3);
1143 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK4,
1144 punit, ptile, NULL)) {
1145 /* "Transport Disembark 4". */
1146 paction = action_by_number(ACTION_TRANSPORT_DISEMBARK4);
1147 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER,
1148 punit, ptile, NULL)) {
1149 /* "Enter Hut". */
1150 paction = action_by_number(ACTION_HUT_ENTER);
1151 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER2,
1152 punit, ptile, NULL)) {
1153 /* "Enter Hut 2". */
1154 paction = action_by_number(ACTION_HUT_ENTER2);
1155 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER3,
1156 punit, ptile, NULL)) {
1157 /* "Enter Hut 3". */
1158 paction = action_by_number(ACTION_HUT_ENTER3);
1159 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER4,
1160 punit, ptile, NULL)) {
1161 /* "Enter Hut 4". */
1162 paction = action_by_number(ACTION_HUT_ENTER4);
1163 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN,
1164 punit, ptile, NULL)) {
1165 /* "Frighten Hut". */
1166 paction = action_by_number(ACTION_HUT_FRIGHTEN);
1167 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN2,
1168 punit, ptile, NULL)) {
1169 /* "Frighten Hut 2". */
1170 paction = action_by_number(ACTION_HUT_FRIGHTEN2);
1171 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN3,
1172 punit, ptile, NULL)) {
1173 /* "Frighten Hut 3". */
1174 paction = action_by_number(ACTION_HUT_FRIGHTEN3);
1175 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN4,
1176 punit, ptile, NULL)) {
1177 /* "Frighten Hut 4". */
1178 paction = action_by_number(ACTION_HUT_FRIGHTEN4);
1179 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE,
1180 punit, ptile, NULL)) {
1181 /* "Unit Move". */
1182 paction = action_by_number(ACTION_UNIT_MOVE);
1183 } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE2,
1184 punit, ptile, NULL)) {
1185 /* "Unit Move 2". */
1186 paction = action_by_number(ACTION_UNIT_MOVE2);
1187 } else {
1188 /* "Unit Move 3". */
1189 paction = action_by_number(ACTION_UNIT_MOVE3);
1190 }
1191
1192 /* Try not to end move next to an enemy if we can avoid it by waiting */
1193 if (action_has_result(paction, ACTRES_UNIT_MOVE)
1194 || action_has_result(paction, ACTRES_TRANSPORT_DISEMBARK)) {
1195 /* The unit will have to move it self rather than being moved. */
1196 int mcost = map_move_cost_unit(nmap, punit, ptile);
1197
1198 if (paction) {
1199 struct tile *from_tile;
1200
1201 /* Ugly hack to understand the OnNativeTile unit state requirements
1202 * used in the Action_Success_Actor_Move_Cost effect. */
1203 fc_assert(utype_is_moved_to_tgt_by_action(paction,
1204 unit_type_get(punit)));
1205 from_tile = unit_tile(punit);
1206 punit->tile = ptile;
1207
1208 mcost += unit_pays_mp_for_action(paction, punit);
1209
1210 punit->tile = from_tile;
1211 }
1212
1213 if (punit->moves_left <= mcost
1214 && unit_move_rate(punit) > mcost
1215 && adv_danger_at(punit, ptile)
1216 && !adv_danger_at(punit, unit_tile(punit))) {
1217 UNIT_LOG(LOG_DEBUG, punit,
1218 "ending move early to stay out of trouble");
1219 return FALSE;
1220 }
1221 }
1222
1223 /* go */
1224 unit_activity_handling(punit, ACTIVITY_IDLE);
1225 /* Move */
1226 if (paction && ptrans
1227 && action_has_result(paction, ACTRES_TRANSPORT_EMBARK)) {
1228 /* "Transport Embark". */
1229 unit_do_action(unit_owner(punit), punit->id, ptrans->id,
1230 0, "", action_number(paction));
1231 } else if (paction
1232 && (action_has_result(paction,
1233 ACTRES_TRANSPORT_DISEMBARK)
1234 || action_has_result(paction, ACTRES_UNIT_MOVE)
1235 || action_has_result(paction,
1236 ACTRES_HUT_ENTER)
1237 || action_has_result(paction,
1238 ACTRES_HUT_FRIGHTEN))) {
1239 /* "Transport Disembark", "Transport Disembark 2", "Enter Hut",
1240 * "Frighten Hut" or "Unit Move". */
1241 unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
1242 0, "", action_number(paction));
1243 }
1244
1245 /* handle the results */
1246 if (game_unit_by_number(sanity) && same_pos(ptile, unit_tile(punit))) {
1247 bodyguard = aiguard_guard_of(ait, punit);
1248
1249 if (is_plr_ai && bodyguard != NULL
1250 && def_ai_unit_data(bodyguard, ait)->charge == punit->id) {
1251 dai_unit_bodyguard_move(ait, bodyguard, ptile);
1252 }
1253 return TRUE;
1254 }
1255 return FALSE;
1256}
1257
1258/**********************************************************************/
1262 int stack_cost(struct unit *pattacker, struct unit *pdefender)
1263{
1264 struct tile *ptile = unit_tile(pdefender);
1265 int victim_cost = 0;
1266
1267 if (is_stack_vulnerable(ptile)) {
1268 /* lotsa people die */
1269 unit_list_iterate(ptile->units, aunit) {
1270 if (unit_attack_unit_at_tile_result(pattacker, NULL, aunit, ptile)
1271 == ATT_OK) {
1272 victim_cost += unit_build_shield_cost_base(aunit);
1273 }
1274 } unit_list_iterate_end;
1275 } else if (unit_attack_unit_at_tile_result(pattacker, NULL,
1276 pdefender, ptile)
1277 == ATT_OK) {
1278 /* Only one unit dies if attack is successful */
1279 victim_cost = unit_build_shield_cost_base(pdefender);
1280 }
1281
1282 return victim_cost;
1283}
1284
1285/**********************************************************************/
1288 void dai_government_change(struct player *pplayer, struct government *gov)
1289{
1290 if (gov == government_of_player(pplayer)) {
1291 return;
1292 }
1293
1294 handle_player_change_government(pplayer, government_number(gov));
1295
1296 city_list_iterate(pplayer->cities, pcity) {
1297 auto_arrange_workers(pcity); /* update cities */
1298 } city_list_iterate_end;
1299}
1300
1301/**********************************************************************/
1307 int dai_gold_reserve(struct player *pplayer)
1308{
1309 int i = total_player_citizens(pplayer) * 2;
1310
1311 return MAX(pplayer->ai_common.maxbuycost, i);
1312}
1313
1314/**********************************************************************/
1317 void adjust_choice(int pct, struct adv_choice *choice)
1318{
1319 choice->want = (choice->want * pct) / 100;
1320}
1321
1322/**********************************************************************/
1326 bool dai_choose_role_unit(struct ai_type *ait, struct player *pplayer,
1327 struct city *pcity, struct adv_choice *choice,
1328 enum choice_type type, int role, int want,
1329 bool need_boat)
1330{
1331 struct unit_type *iunit = dai_wants_role_unit(ait, pplayer, pcity, role, want);
1332
1333 if (iunit != NULL) {
1334 choice->type = type;
1335 choice->value.utype = iunit;
1336 choice->want = want;
1337
1338 choice->need_boat = need_boat;
1339
1340 return TRUE;
1341 }
1342
1343 return FALSE;
1344}
1345
1346/**********************************************************************/
1349 void dai_build_adv_override(struct ai_type *ait, struct city *pcity,
1350 struct adv_choice *choice)
1351{
1352 const struct impr_type *chosen;
1353 adv_want want;
1354
1355 if (choice->type == CT_NONE) {
1356 want = 0;
1357 chosen = NULL;
1358 } else {
1359 want = choice->want;
1360 chosen = choice->value.building;
1361 }
1362
1363 improvement_iterate(pimprove) {
1364 /* Advisor code did not consider wonders, let's do it here */
1365 if (is_wonder(pimprove)) {
1366 int id = improvement_index(pimprove);
1367
1368 if (pcity->server.adv->building_want[id] > want
1369 && can_city_build_improvement_now(pcity, pimprove)) {
1370 want = pcity->server.adv->building_want[id];
1371 chosen = pimprove;
1372 }
1373 }
1374 } improvement_iterate_end;
1375
1376 choice->want = want;
1377 choice->value.building = chosen;
1378
1379 if (chosen) {
1380 choice->type = CT_BUILDING; /* In case advisor had not chosen anything */
1381
1382 CITY_LOG(LOG_DEBUG, pcity, "AI wants to build %s with want "
1383 ADV_WANT_PRINTF,
1384 improvement_rule_name(chosen), want);
1385 }
1386}
1387
1388/**********************************************************************/
1397 bool dai_assess_military_unhappiness(struct city *pcity)
1398{
1399 int free_unhappy = get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL);
1400 int unhap = 0;
1401
1402 /* bail out now if happy_cost is 0 */
1403 if (get_player_bonus(city_owner(pcity), EFT_UNHAPPY_FACTOR) == 0) {
1404 return FALSE;
1405 }
1406
1407 unit_list_iterate(pcity->units_supported, punit) {
1408 int happy_cost = city_unit_unhappiness(punit, &free_unhappy);
1409
1410 if (happy_cost > 0) {
1411 unhap += happy_cost;
1412 }
1413 } unit_list_iterate_end;
1414
1415 if (unhap < 0) {
1416 unhap = 0;
1417 }
1418 return (unhap > 0);
1419}
action_number
int action_number(const struct action *action)
Definition actions.c:1868
is_action_enabled_unit_on_tile
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:4996
is_action_enabled_unit_on_units
bool is_action_enabled_unit_on_units(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile)
Definition actions.c:4920
is_action_enabled_unit_on_city
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:4755
is_action_enabled_unit_on_unit
bool is_action_enabled_unit_on_unit(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Definition actions.c:4832
is_action_enabled_unit_on_extras
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:5073
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
action_has_result
#define action_has_result(_act_, _res_)
Definition actions.h:448
action_id_get_target_kind
#define action_id_get_target_kind(act_id)
Definition actions.h:655
choice_type
choice_type
Definition advchoice.h:36
CT_NONE
@ CT_NONE
Definition advchoice.h:37
CT_BUILDING
@ CT_BUILDING
Definition advchoice.h:38
adv_data_get
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:593
advdata.h
adv_follow_path
bool adv_follow_path(struct unit *punit, struct pf_path *path, struct tile *ptile)
Definition advgoto.c:47
adv_danger_at
bool adv_danger_at(struct unit *punit, struct tile *ptile)
Definition advgoto.c:414
adv_unittype_att_rating
int adv_unittype_att_rating(const struct unit_type *punittype, int veteran, int moves_left, int hp)
Definition advgoto.c:374
adv_unit_att_rating
int adv_unit_att_rating(const struct unit *punit)
Definition advgoto.c:385
adv_avoid_risks
void adv_avoid_risks(struct pf_parameter *parameter, struct adv_risk_cost *risk_cost, struct unit *punit, const double fearfulness)
Definition advgoto.c:581
advgoto.h
NORMAL_STACKING_FEARFULNESS
#define NORMAL_STACKING_FEARFULNESS
Definition advgoto.h:23
amortize
adv_want amortize(adv_want benefit, int delay)
Definition advtools.c:29
advtools.h
POWER_DIVIDER
#define POWER_DIVIDER
Definition advtools.h:32
dai_diplomacy_get
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Definition aidata.c:402
aidata.h
aiferry_gobyboat
bool aiferry_gobyboat(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile, bool with_bodyguard)
Definition aiferry.c:766
dai_is_ferry
bool dai_is_ferry(struct unit *pferry, struct ai_type *ait)
Definition aiferry.c:161
aiferry_clear_boat
void aiferry_clear_boat(struct ai_type *ait, struct unit *punit)
Definition aiferry.c:253
aiferry.h
aiguard_clear_charge
void aiguard_clear_charge(struct ai_type *ait, struct unit *guard)
Definition aiguard.c:118
aiguard_request_guard
void aiguard_request_guard(struct ai_type *ait, struct unit *punit)
Definition aiguard.c:228
aiguard_assign_guard_city
void aiguard_assign_guard_city(struct ai_type *ait, struct city *charge, struct unit *guard)
Definition aiguard.c:197
aiguard_charge_unit
struct unit * aiguard_charge_unit(struct ai_type *ait, struct unit *guard)
Definition aiguard.c:280
aiguard_clear_guard
void aiguard_clear_guard(struct ai_type *ait, struct unit *charge)
Definition aiguard.c:147
aiguard_guard_of
struct unit * aiguard_guard_of(struct ai_type *ait, struct unit *charge)
Definition aiguard.c:270
aiguard.h
CHECK_CHARGE_UNIT
#define CHECK_CHARGE_UNIT(ait, charge)
Definition aiguard.h:22
CHECK_GUARD
#define CHECK_GUARD(ait, guard)
Definition aiguard.h:21
ailog.h
BODYGUARD_LOG
#define BODYGUARD_LOG(ait, loglevel, punit, msg,...)
Definition ailog.h:69
aiplayer.h
def_ai_unit_data
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition aiplayer.h:48
dai_wants_role_unit
struct unit_type * dai_wants_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, int role, int want)
Definition aitech.c:512
aitech.h
dai_government_change
void dai_government_change(struct player *pplayer, struct government *gov)
Definition aitools.c:1288
dai_fill_unit_param
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 aitools.c:468
stack_cost
int stack_cost(struct unit *pattacker, struct unit *pdefender)
Definition aitools.c:1262
goto_is_sane
bool goto_is_sane(struct unit *punit, struct tile *ptile)
Definition aitools.c:428
LONG_TIME
#define LONG_TIME
Definition aitools.c:455
dai_assess_military_unhappiness
bool dai_assess_military_unhappiness(struct city *pcity)
Definition aitools.c:1397
immediate_destination
struct tile * immediate_destination(struct unit *punit, struct tile *dest_tile)
Definition aitools.c:301
dai_gothere_bodyguard
static bool dai_gothere_bodyguard(struct ai_type *ait, struct unit *punit, struct tile *dest_tile)
Definition aitools.c:161
dai_build_adv_override
void dai_build_adv_override(struct ai_type *ait, struct city *pcity, struct adv_choice *choice)
Definition aitools.c:1349
dai_unit_attack
bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition aitools.c:816
dai_unit_goto
bool dai_unit_goto(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition aitools.c:604
dai_unit_goto_constrained
bool dai_unit_goto_constrained(struct ai_type *ait, struct unit *punit, struct tile *ptile, struct pf_parameter *parameter)
Definition aitools.c:377
dai_log_path
void dai_log_path(struct unit *punit, struct pf_path *path, struct pf_parameter *parameter)
Definition aitools.c:355
dai_consider_plr_dangerous
void dai_consider_plr_dangerous(struct ai_type *ait, struct player *plr1, struct player *plr2, enum override_bool *result)
Definition aitools.c:142
dai_unit_new_task
void dai_unit_new_task(struct ai_type *ait, struct unit *punit, enum ai_unit_task task, struct tile *ptile)
Definition aitools.c:642
dai_gold_reserve
int dai_gold_reserve(struct player *pplayer)
Definition aitools.c:1307
adjust_choice
void adjust_choice(int pct, struct adv_choice *choice)
Definition aitools.c:1317
dai_unit_make_homecity
bool dai_unit_make_homecity(struct unit *punit, struct city *pcity)
Definition aitools.c:754
dai_choose_role_unit
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 aitools.c:1326
dai_unit_bodyguard_move
static void dai_unit_bodyguard_move(struct ai_type *ait, struct unit *bodyguard, struct tile *ptile)
Definition aitools.c:783
dai_unit_task_rule_name
const char * dai_unit_task_rule_name(const enum ai_unit_task task)
Definition aitools.c:77
LOGLEVEL_GOTHERE
#define LOGLEVEL_GOTHERE
Definition aitools.c:233
military_amortize
adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
Definition aitools.c:118
dai_gothere
bool dai_gothere(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile)
Definition aitools.c:243
dai_unit_move
bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition aitools.c:1071
dai_unit_new_adv_task
void dai_unit_new_adv_task(struct ai_type *ait, struct unit *punit, enum adv_unit_task task, struct tile *ptile)
Definition aitools.c:618
dai_unit_move_or_attack
void dai_unit_move_or_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile, struct pf_path *path, int step)
Definition aitools.c:1053
aitools.h
aiunit.h
POTENTIALLY_HOSTILE_PLAYER
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
Definition aiunit.h:72
ai_unit_task
ai_unit_task
Definition aiunit.h:27
AIUNIT_BUILD_CITY
@ AIUNIT_BUILD_CITY
Definition aiunit.h:27
AIUNIT_NONE
@ AIUNIT_NONE
Definition aiunit.h:27
AIUNIT_ATTACK
@ AIUNIT_ATTACK
Definition aiunit.h:28
AIUNIT_EXPLORE
@ AIUNIT_EXPLORE
Definition aiunit.h:29
AIUNIT_HUNTER
@ AIUNIT_HUNTER
Definition aiunit.h:29
AIUNIT_RECOVER
@ AIUNIT_RECOVER
Definition aiunit.h:29
AIUNIT_TRADE
@ AIUNIT_TRADE
Definition aiunit.h:30
AIUNIT_DEFEND_HOME
@ AIUNIT_DEFEND_HOME
Definition aiunit.h:28
AIUNIT_ESCORT
@ AIUNIT_ESCORT
Definition aiunit.h:28
AIUNIT_AUTO_SETTLER
@ AIUNIT_AUTO_SETTLER
Definition aiunit.h:27
AIUNIT_WONDER
@ AIUNIT_WONDER
Definition aiunit.h:30
autosettlers.h
barbarian.h
bitvector.h
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_CLR
#define BV_CLR(bv, bit)
Definition bitvector.h:86
city_unit_unhappiness
int city_unit_unhappiness(struct unit *punit, int *free_unhappy)
Definition city.c:2940
city_production_unit_veteran_level
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:789
can_city_build_improvement_now
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:839
city.h
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:488
is_enemy_city_tile
static bool is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:705
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:490
citymap_free_city_spot
void citymap_free_city_spot(struct tile *ptile, int id)
Definition citymap.c:150
citymap_reserve_city_spot
void citymap_reserve_city_spot(struct tile *ptile, int id)
Definition citymap.c:122
citymap.h
citytools.h
auto_arrange_workers
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:368
cityturn.h
is_stack_vulnerable
bool is_stack_vulnerable(const struct tile *ptile)
Definition combat.c:928
unit_attack_unit_at_tile_result
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:122
combat.h
POWER_FACTOR
#define POWER_FACTOR
Definition combat.h:32
ATT_OK
@ ATT_OK
Definition combat.h:35
dai_choose_defender_versus
struct unit_type * dai_choose_defender_versus(struct city *pcity, struct unit *attacker)
Definition daimilitary.c:91
daimilitary.h
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
id
int int id
Definition editgui_g.h:28
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:789
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
hut_on_tile
bool hut_on_tile(const struct tile *ptile)
Definition extras.c:672
adv_want
float adv_want
Definition fc_types.h:1206
adv_unit_task
adv_unit_task
Definition fc_types.h:340
AUT_BUILD_CITY
@ AUT_BUILD_CITY
Definition fc_types.h:340
AUT_NONE
@ AUT_NONE
Definition fc_types.h:340
AUT_AUTO_SETTLER
@ AUT_AUTO_SETTLER
Definition fc_types.h:340
ADV_WANT_PRINTF
#define ADV_WANT_PRINTF
Definition fc_types.h:1207
O_SHIELD
@ O_SHIELD
Definition fc_types.h:91
O_FOOD
@ O_FOOD
Definition fc_types.h:91
override_bool
override_bool
Definition fc_types.h:84
OVERRIDE_TRUE
@ OVERRIDE_TRUE
Definition fc_types.h:84
wld
struct world wld
Definition game.c:58
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:111
game.h
government_of_player
struct government * government_of_player(const struct player *pplayer)
Definition government.c:113
government_number
Government_type_id government_number(const struct government *pgovern)
Definition government.c:90
government.h
type
GType type
Definition repodlgs.c:1312
handle_player_change_government
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:454
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps.h
H_MAP
@ H_MAP
Definition handicaps.h:28
improvement_rule_name
const char * improvement_rule_name(const struct impr_type *pimprove)
Definition improvement.c:250
improvement_index
Impr_type_id improvement_index(const struct impr_type *pimprove)
Definition improvement.c:173
is_wonder
bool is_wonder(const struct impr_type *pimprove)
Definition improvement.c:341
improvement_iterate_end
#define improvement_iterate_end
Definition improvement.h:211
improvement_iterate
#define improvement_iterate(_p)
Definition improvement.h:205
infracache.h
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
log_verbose
#define log_verbose(message,...)
Definition log.h:109
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
LOG_DEBUG
@ LOG_DEBUG
Definition log.h:34
log_error
#define log_error(message,...)
Definition log.h:103
fc_assert_ret_val_msg
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
is_tiles_adjacent
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Definition map.c:929
same_pos
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:938
map_distance
int map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:652
map.h
map_move_cost_unit
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
Definition map.h:287
maphand.h
mem.h
unit_move_rate
int unit_move_rate(const struct unit *punit)
Definition movement.c:90
can_unit_survive_at_tile
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:476
movement.h
SINGLE_MOVE
#define SINGLE_MOVE
Definition movement.h:24
nation_rule_name
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
nation_of_unit
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:462
packets.h
pf_path_last_position
const struct pf_position * pf_path_last_position(const struct pf_path *path)
Definition path_finding.c:3531
pf_path_destroy
void pf_path_destroy(struct pf_path *path)
Definition path_finding.c:3411
pf_map_new
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
Definition path_finding.c:3182
pf_map_path
struct pf_path * pf_map_path(struct pf_map *pfm, struct tile *ptile)
Definition path_finding.c:3235
pf_map_destroy
void pf_map_destroy(struct pf_map *pfm)
Definition path_finding.c:3206
pf_map_move_cost
int pf_map_move_cost(struct pf_map *pfm, struct tile *ptile)
Definition path_finding.c:3219
PF_IMPOSSIBLE_MC
#define PF_IMPOSSIBLE_MC
Definition path_finding.h:266
PF_TURN_FACTOR
#define PF_TURN_FACTOR
Definition path_finding.h:272
pft_fill_unit_parameter
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:840
pft_fill_unit_attack_param
void pft_fill_unit_attack_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:949
pft_fill_unit_overlap_param
void pft_fill_unit_overlap_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:891
no_fights
enum tile_behavior no_fights(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:509
no_intermediate_fights
enum tile_behavior no_intermediate_fights(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:524
pf_tools.h
player_index
int player_index(const struct player *pplayer)
Definition player.c:820
player.h
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
is_ai
#define is_ai(plr)
Definition player.h:234
plrhand.h
total_player_citizens
int total_player_citizens(const struct player *pplayer)
Definition score.c:382
score.h
shared.h
MAX
#define MAX(x, y)
Definition shared.h:54
step
int step
Definition specpq.h:92
srv_log.h
CITY_LOG
#define CITY_LOG(loglevel, pcity, msg,...)
Definition srv_log.h:83
LOGLEVEL_HUNT
#define LOGLEVEL_HUNT
Definition srv_log.h:35
UNIT_LOG
#define UNIT_LOG(loglevel, punit, msg,...)
Definition srv_log.h:98
LOGLEVEL_BODYGUARD
#define LOGLEVEL_BODYGUARD
Definition srv_log.h:30
action
Definition actions.h:379
adv_choice
Definition advchoice.h:45
adv_choice::type
enum choice_type type
Definition advchoice.h:46
adv_choice::want
adv_want want
Definition advchoice.h:48
adv_choice::value
universals_u value
Definition advchoice.h:47
adv_choice::need_boat
bool need_boat
Definition advchoice.h:49
adv_city::building_want
adv_want building_want[B_LAST]
Definition infracache.h:32
adv_data
Definition advdata.h:45
adv_data::stats
struct adv_data::@92 stats
adv_data::average_production
int average_production
Definition advdata.h:92
adv_risk_cost
Definition advgoto.h:26
ai_dip_intel
Definition aidata.h:53
ai_dip_intel::countdown
int countdown
Definition aidata.h:61
ai_type
Definition ai.h:50
city
Definition city.h:309
city::surplus
int surplus[O_LAST]
Definition city.h:343
city::id
int id
Definition city.h:315
city::adv
struct adv_city * adv
Definition city.h:435
city::server
struct city::@17::@19 server
city::units_supported
struct unit_list * units_supported
Definition city.h:391
civ_map
Definition map_types.h:71
government
Definition government.h:52
impr_type
Definition improvement.h:68
pf_map
Definition path_finding.c:78
pf_parameter
Definition path_finding.h:357
pf_parameter::get_TB
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition path_finding.h:398
pf_parameter::get_moves_left_req
int(* get_moves_left_req)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
Definition path_finding.h:441
pf_parameter::move_rate
int move_rate
Definition path_finding.h:370
pf_parameter::get_zoc
bool(* get_zoc)(const struct player *pplayer, const struct tile *ptile, const struct civ_map *zmap)
Definition path_finding.h:430
pf_parameter::omniscience
bool omniscience
Definition path_finding.h:376
pf_path
Definition path_finding.h:344
pf_path::length
unsigned length
Definition path_finding.h:345
pf_path::positions
struct pf_position * positions
Definition path_finding.h:346
pf_position
Definition path_finding.h:327
pf_position::total_MC
unsigned total_MC
Definition path_finding.h:336
pf_position::total_EC
unsigned total_EC
Definition path_finding.h:337
pf_position::tile
struct tile * tile
Definition path_finding.h:328
pf_position::turn
int turn
Definition path_finding.h:329
player_ai::maxbuycost
int maxbuycost
Definition player.h:120
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::ai_common
struct player_ai ai_common
Definition player.h:288
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
unit_adv::task
enum adv_unit_task task
Definition unit.h:89
unit_ai
Definition aiunit.h:32
unit_ai::task
enum ai_unit_task task
Definition aiunit.h:46
unit_ai::charge
int charge
Definition aiunit.h:37
unit_ai::target
int target
Definition aiunit.h:42
unit_type
Definition unittype.h:481
unit_type::defense_strength
int defense_strength
Definition unittype.h:496
unit_type::move_rate
int move_rate
Definition unittype.h:497
unit_type::hp
int hp
Definition unittype.h:505
unit
Definition unit.h:138
unit::upkeep
int upkeep[O_LAST]
Definition unit.h:148
unit::activity
enum unit_activity activity
Definition unit.h:157
unit::moves_left
int moves_left
Definition unit.h:150
unit::id
int id
Definition unit.h:145
unit::hp
int hp
Definition unit.h:151
unit::tile
struct tile * tile
Definition unit.h:140
unit::adv
struct unit_adv * adv
Definition unit.h:233
unit::server
struct unit::@80::@83 server
unit::homecity
int homecity
Definition unit.h:146
unit::goto_tile
struct tile * goto_tile
Definition unit.h:155
unit::veteran
int veteran
Definition unit.h:152
veteran_level
Definition unittype.h:467
veteran_level::power_fact
int power_fact
Definition unittype.h:469
world::map
struct civ_map map
Definition world_object.h:38
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
tile_has_claimable_base
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:209
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_index
#define tile_index(_pt_)
Definition tile.h:87
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:42
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:604
universals_u::building
const struct impr_type * building
Definition fc_types.h:598
unit_pays_mp_for_action
int unit_pays_mp_for_action(const struct action *paction, const struct unit *punit)
Definition unit.c:2121
transporter_for_unit_at
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1908
is_losing_hp
bool is_losing_hp(const struct unit *punit)
Definition unit.c:2214
can_unit_load
bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:744
unit_is_cityfounder
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2625
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2411
unit_has_orders
bool unit_has_orders(const struct unit *punit)
Definition unit.c:207
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
is_enemy_unit_tile
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:411
CHECK_UNIT
#define CHECK_UNIT(punit)
Definition unit.h:268
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
unit_activity_handling
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Definition unithand.c:6176
unit_do_action
void unit_do_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id, const char *name, const action_id action_type)
Definition unithand.c:3153
unithand.h
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
send_unit_info
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2798
unit_transport_load_send
void unit_transport_load_send(struct unit *punit, struct unit *ptrans)
Definition unittools.c:3276
unittools.h
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
utype_is_moved_to_tgt_by_action
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1301
unit_rule_name
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1639
utype_may_act_at_all
bool utype_may_act_at_all(const struct unit_type *putype)
Definition unittype.c:431
unit_build_shield_cost_base
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1536
unit_class_get
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2546
utype_can_do_action_result
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:459
unit_has_type_role
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Definition unittype.c:202
utype_veteran_level
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2631
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
utype_can_do_action
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:443
uclass_has_flag
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:753
utype_fuel
#define utype_fuel(ptype)
Definition unittype.h:822