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

Freeciv-3.1

Loading...
Searching...
No Matches
aihunt.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2003 - The Freeciv Team
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
22/* common */
23#include "city.h"
24#include "combat.h"
25#include "game.h"
26#include "map.h"
27#include "movement.h"
28#include "player.h"
29#include "unit.h"
30#include "unitlist.h"
31
32/* aicore */
33#include "pf_tools.h"
34
35/* server */
36#include "citytools.h"
37#include "srv_log.h"
38#include "unithand.h"
39#include "unittools.h"
40
41/* server/advisors */
42#include "advdata.h"
43#include "advgoto.h"
44#include "advtools.h"
45#include "autosettlers.h"
46
47/* ai */
48#include "handicaps.h"
49
50/* ai/default */
51#include "ailog.h"
52#include "aiplayer.h"
53#include "aitools.h"
54#include "aiunit.h"
55#include "daicity.h"
56
57#include "aihunt.h"
58
59
60/**********************************************************************/
64 static struct unit *dai_hunter_find(struct player *pplayer,
65 struct city *pcity)
66{
67 unit_list_iterate(pcity->units_supported, punit) {
68 if (dai_hunter_qualify(pplayer, punit)) {
69 return punit;
70 }
71 } unit_list_iterate_end;
72 unit_list_iterate(pcity->tile->units, punit) {
73 if (dai_hunter_qualify(pplayer, punit)) {
74 return punit;
75 }
76 } unit_list_iterate_end;
77
78 return NULL;
79}
80
81/**********************************************************************/
84 static struct unit_type *dai_hunter_guess_best(struct city *pcity,
85 enum terrain_class tc,
86 struct ai_type *ait,
87 bool allow_gold_upkeep)
88{
89 struct unit_type *bestid = NULL;
90 int best = 0;
91 struct player *pplayer = city_owner(pcity);
92
93 unit_type_iterate(ut) {
94 struct unit_type_ai *utai = utype_ai_data(ut, ait);
95 int desire;
96
97 if (!allow_gold_upkeep && utype_upkeep_cost(ut, pplayer, O_GOLD) > 0) {
98 continue;
99 }
100
101 if (!can_city_build_unit_now(pcity, ut)
102 || ut->attack_strength < ut->transport_capacity
103 || (tc == TC_OCEAN && utype_class(ut)->adv.sea_move == MOVE_NONE)
104 || (tc == TC_LAND && utype_class(ut)->adv.land_move == MOVE_NONE)) {
105 continue;
106 }
107
108 desire = (ut->hp
109 * ut->attack_strength
110 * ut->firepower
111 * ut->move_rate
112 + ut->defense_strength) / MAX(UNITTYPE_COSTS(ut), 1);
113
114 if (utai->missile_platform) {
115 desire += desire / 6;
116 }
117
118 if (utype_has_flag(ut, UTYF_IGTER)) {
119 desire += desire / 2;
120 }
121 if (ut->vlayer == V_INVIS) {
122 desire += desire / 4;
123 }
124 if (!can_attack_non_native(ut)) {
125 desire -= desire / 4; /* less flexibility */
126 }
127 /* Causes continual unhappiness */
128 if (utype_has_flag(ut, UTYF_FIELDUNIT)) {
129 desire /= 2;
130 }
131
132 desire = amortize(desire,
133 (utype_build_shield_cost(pcity, NULL, ut)
134 / MAX(pcity->surplus[O_SHIELD], 1)));
135
136 if (desire > best) {
137 best = desire;
138 bestid = ut;
139 }
140 } unit_type_iterate_end;
141
142 return bestid;
143}
144
145/**********************************************************************/
148 static void dai_hunter_missile_want(struct player *pplayer,
149 struct city *pcity,
150 struct adv_choice *choice)
151{
152 adv_want best = -1;
153 struct unit_type *best_unit_type = NULL;
154 struct unit *hunter = NULL;
155
156 unit_list_iterate(pcity->tile->units, punit) {
157 if (dai_hunter_qualify(pplayer, punit)) {
158 unit_type_iterate(pcargo) {
159 if (can_unit_type_transport(unit_type_get(punit),
160 utype_class(pcargo))
161 && utype_can_do_action(pcargo, ACTION_SUICIDE_ATTACK)) {
162 hunter = punit;
163 break;
164 }
165 } unit_type_iterate_end;
166 if (hunter) {
167 break;
168 }
169 }
170 } unit_list_iterate_end;
171
172 if (!hunter) {
173 return;
174 }
175
176 unit_type_iterate(ut) {
177 int desire;
178
179 if (!utype_can_do_action(ut, ACTION_SUICIDE_ATTACK)
180 || !can_city_build_unit_now(pcity, ut)) {
181 continue;
182 }
183
184 if (!can_unit_type_transport(unit_type_get(hunter), utype_class(ut))) {
185 continue;
186 }
187
188 /* FIXME: We need to store some data that can tell us if
189 * enemy transports are protected by anti-missile technology.
190 * In this case, want nuclear much more! */
191 desire = (ut->hp
192 * MIN(ut->attack_strength, 30) /* nuke fix */
193 * ut->firepower
194 * ut->move_rate) / UNITTYPE_COSTS(ut) + 1;
195
196 /* Causes continual unhappiness */
197 if (utype_has_flag(ut, UTYF_FIELDUNIT)) {
198 desire /= 2;
199 }
200
201 desire = amortize(desire,
202 (utype_build_shield_cost(pcity, NULL, ut)
203 / MAX(pcity->surplus[O_SHIELD], 1)));
204
205 if (desire > best) {
206 best = desire;
207 best_unit_type = ut;
208 }
209 } unit_type_iterate_end;
210
211 if (best > choice->want) {
212 CITY_LOG(LOGLEVEL_HUNT, pcity,
213 "pri missile w/ want " ADV_WANT_PRINTF, best);
214 choice->value.utype = best_unit_type;
215 choice->want = best;
216 choice->type = CT_ATTACKER;
217 choice->need_boat = FALSE;
218 adv_choice_set_use(choice, "missile");
219 } else if (best >= 0) {
220 CITY_LOG(LOGLEVEL_HUNT, pcity, "not pri missile w/ want " ADV_WANT_PRINTF
221 "(old want " ADV_WANT_PRINTF ")", best, choice->want);
222 }
223}
224
225/**********************************************************************/
228 static void eval_hunter_want(struct ai_type *ait, struct player *pplayer,
229 struct city *pcity,
230 struct adv_choice *choice,
231 struct unit_type *best_type,
232 int veteran)
233{
234 struct unit *virtualunit;
235 int want = 0;
236
237 virtualunit = unit_virtual_create(pplayer, pcity, best_type, veteran);
238 want = dai_hunter_manage(ait, pplayer, virtualunit);
239 unit_virtual_destroy(virtualunit);
240 if (want > choice->want) {
241 CITY_LOG(LOGLEVEL_HUNT, pcity, "pri hunter w/ want %d", want);
242 choice->value.utype = best_type;
243 choice->want = want;
244 choice->type = CT_ATTACKER;
245 choice->need_boat = FALSE;
246 adv_choice_set_use(choice, "hunter");
247 }
248}
249
250/**********************************************************************/
253 void dai_hunter_choice(struct ai_type *ait, struct player *pplayer,
254 struct city *pcity, struct adv_choice *choice,
255 bool allow_gold_upkeep)
256{
257 struct unit_type *best_land_hunter
258 = dai_hunter_guess_best(pcity, TC_LAND, ait, allow_gold_upkeep);
259 struct unit_type *best_sea_hunter
260 = dai_hunter_guess_best(pcity, TC_OCEAN, ait, allow_gold_upkeep);
261 struct unit *hunter = dai_hunter_find(pplayer, pcity);
262
263 if ((!best_land_hunter && !best_sea_hunter)
264 || is_barbarian(pplayer) || !pplayer->is_alive
265 || has_handicap(pplayer, H_TARGETS)) {
266 return; /* None available */
267 }
268 if (hunter) {
269 /* Maybe want missiles to go with a hunter instead? */
270 dai_hunter_missile_want(pplayer, pcity, choice);
271 return;
272 }
273
274 if (best_sea_hunter) {
275 eval_hunter_want(
276 ait, pplayer, pcity, choice, best_sea_hunter,
277 city_production_unit_veteran_level(pcity, best_sea_hunter));
278 }
279 if (best_land_hunter) {
280 eval_hunter_want(
281 ait, pplayer, pcity, choice, best_land_hunter,
282 city_production_unit_veteran_level(pcity, best_land_hunter));
283 }
284}
285
286/**********************************************************************/
289 bool dai_hunter_qualify(struct player *pplayer, struct unit *punit)
290{
291 if (is_barbarian(pplayer) || unit_owner(punit) != pplayer) {
292 return FALSE;
293 }
294 if (unit_has_type_role(punit, L_HUNTER)) {
295 return TRUE;
296 }
297 return FALSE;
298}
299
300/**********************************************************************/
305 static void dai_hunter_try_launch(struct ai_type *ait,
306 struct player *pplayer,
307 struct unit *punit,
308 struct unit *target)
309{
310 int target_sanity = target->id;
311 struct pf_parameter parameter;
312 struct pf_map *pfm;
313 const struct civ_map *nmap = &(wld.map);
314
315 /* Only directly transported units. Not launching cargo of cargo */
316 unit_list_iterate_safe(punit->transporting, missile) {
317 struct unit *sucker = NULL;
318
319 if (unit_owner(missile) == pplayer
320 && utype_can_do_action(unit_type_get(missile),
321 ACTION_SUICIDE_ATTACK)) {
322 UNIT_LOG(LOGLEVEL_HUNT, missile, "checking for hunt targets");
323 pft_fill_unit_parameter(&parameter, nmap, punit);
324 parameter.omniscience = !has_handicap(pplayer, H_MAP);
325 pfm = pf_map_new(&parameter);
326
327 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
328 if (move_cost > missile->moves_left / SINGLE_MOVE) {
329 break;
330 }
331 if (tile_city(ptile)
332 || !can_unit_attack_tile(punit, NULL, ptile)) {
333 continue;
334 }
335 unit_list_iterate(ptile->units, victim) {
336 enum diplstate_type ds =
337 player_diplstate_get(pplayer, unit_owner(victim))->type;
338 const struct unit_type *ptype;
339 const struct unit_type *victim_type;
340
341 if (ds != DS_WAR) {
342 continue;
343 }
344 if (victim == target) {
345 sucker = victim;
346 UNIT_LOG(LOGLEVEL_HUNT, missile, "found primary target %d(%d, %d)"
347 " dist %d", victim->id, TILE_XY(unit_tile(victim)),
348 move_cost);
349 break; /* Our target! Get it!!! */
350 }
351
352 victim_type = unit_type_get(victim);
353 ptype = unit_type_get(punit);
354
355 if (ATTACK_POWER(victim_type) > DEFENSE_POWER(ptype)
356 && dai_unit_can_strike_my_unit(victim, punit)) {
357 sucker = victim;
358 UNIT_LOG(LOGLEVEL_HUNT, missile, "found aux target %d(%d, %d)",
359 victim->id, TILE_XY(unit_tile(victim)));
360 break;
361 }
362 } unit_list_iterate_end;
363 if (sucker) {
364 break; /* Found something - kill it! */
365 }
366 } pf_map_move_costs_iterate_end;
367 pf_map_destroy(pfm);
368
369 if (sucker) {
370 if (unit_transported(missile)) {
371 struct unit *ptrans = unit_transport_get(missile);
372
373 if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_ALIGHT,
374 missile, ptrans)) {
375 unit_do_action(unit_owner(punit), punit->id, ptrans->id,
376 0, "", ACTION_TRANSPORT_ALIGHT);
377 }
378 }
379
380 missile->goto_tile = unit_tile(sucker);
381 if (dai_unit_goto(ait, missile, unit_tile(sucker))) {
382 /* We survived; did they? */
383 sucker = game_unit_by_number(target_sanity); /* Sanity */
384 if (sucker && is_tiles_adjacent(unit_tile(sucker),
385 unit_tile(missile))) {
386 dai_unit_attack(ait, missile, unit_tile(sucker));
387 }
388 }
389 if (game_unit_by_number(target_sanity) == NULL) {
390 return; /* Target killed */
391 }
392 }
393 } /* if */
394 } unit_list_iterate_safe_end;
395}
396
397/**********************************************************************/
400 static void dai_hunter_juiciness(struct player *pplayer, struct unit *punit,
401 struct unit *target, unsigned *stackthreat,
402 unsigned *stackcost)
403{
404 *stackthreat = 0;
405 *stackcost = 0;
406
407 unit_list_iterate(unit_tile(target)->units, sucker) {
408 const struct unit_type *suck_type = unit_type_get(sucker);
409
410 *stackthreat += ATTACK_POWER(suck_type);
411 if (unit_has_type_flag(sucker, UTYF_GAMELOSS)) {
412 *stackcost += 1000;
413 *stackthreat += 5000;
414 }
415 if (utype_acts_hostile(unit_type_get(sucker))) {
416 *stackthreat += 500; /* Extra threatening */
417 }
418 *stackcost += unit_build_shield_cost_base(sucker);
419 } unit_list_iterate_end;
420
421 *stackthreat *= 9; /* WAG - reduced by distance later */
422 *stackthreat += *stackcost;
423}
424
425/**********************************************************************/
437 int dai_hunter_manage(struct ai_type *ait, struct player *pplayer,
438 struct unit *punit)
439{
440 bool is_virtual = (punit->id == 0);
441 struct pf_parameter parameter;
442 struct pf_map *pfm;
443 int limit = unit_move_rate(punit) * 6;
444 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
445 struct unit *original_target = game_unit_by_number(unit_data->target);
446 unsigned original_threat = 0, original_cost = 0;
447 struct civ_map *nmap = &(wld.map);
448
449 fc_assert_ret_val(!is_barbarian(pplayer), 0);
450 fc_assert_ret_val(pplayer->is_alive, 0);
451
452 pft_fill_unit_parameter(&parameter, nmap, punit);
453 parameter.omniscience = !has_handicap(pplayer, H_MAP);
454 pfm = pf_map_new(&parameter);
455
456 if (original_target) {
457 dai_hunter_juiciness(pplayer, punit, original_target,
458 &original_threat, &original_cost);
459 }
460
461 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
462 /* End faster if we have a target */
463 if (move_cost > limit) {
464 UNIT_LOG(LOGLEVEL_HUNT, punit, "gave up finding hunt target");
465 pf_map_destroy(pfm);
466 return 0;
467 }
468
469 if (tile_city(ptile)
470 || !can_unit_attack_tile(punit, NULL, ptile)) {
471 continue;
472 }
473
474 unit_list_iterate_safe(ptile->units, target) {
475 struct player *aplayer = unit_owner(target);
476 int dist1, dist2;
477 unsigned stackthreat = 0, stackcost = 0;
478 int sanity_target = target->id;
479 struct pf_path *path;
480 struct unit_ai *target_data;
481 struct tile *target_tile;
482 struct unit *defender;
483
484 /* Note that we need not (yet) be at war with aplayer */
485 if (!adv_is_player_dangerous(pplayer, aplayer)) {
486 continue;
487 }
488
489 target_data = def_ai_unit_data(target, ait);
490 if (BV_ISSET(target_data->hunted, player_index(pplayer))) {
491 /* Can't hunt this one. The bit is cleared in the beginning
492 * of each turn. */
493 continue;
494 }
495 if (!utype_acts_hostile(unit_type_get(target))
496 && get_transporter_capacity(target) == 0
497 && !unit_has_type_flag(target, UTYF_GAMELOSS)) {
498 /* Won't hunt this one. */
499 continue;
500 }
501
502 target_tile = unit_tile(target);
503 if (!unit_attack_unit_at_tile_result(punit, NULL, target, target_tile)) {
504 /* We can't attack the target */
505 continue;
506 }
507
508 /* Figure out whether unit is coming closer */
509 if (target_data->cur_pos && target_data->prev_pos) {
510 dist1 = real_map_distance(unit_tile(punit), *target_data->cur_pos);
511 dist2 = real_map_distance(unit_tile(punit), *target_data->prev_pos);
512 } else {
513 dist1 = dist2 = 0;
514 }
515 UNIT_LOG(LOGLEVEL_HUNT, punit, "considering chasing %s[%d](%d, %d) "
516 "dist1 %d dist2 %d",
517 unit_rule_name(target), target->id, TILE_XY(target_tile),
518 dist1, dist2);
519
520 /* We can't chase if we aren't faster or on intercept vector */
521 if (unit_type_get(punit)->move_rate < unit_type_get(target)->move_rate
522 && dist1 >= dist2) {
523 UNIT_LOG(LOGLEVEL_HUNT, punit,
524 "giving up racing %s (%d, %d)->(%d, %d)",
525 unit_rule_name(target),
526 target_data->prev_pos
527 ? index_to_map_pos_x(tile_index(*target_data->prev_pos))
528 : -1,
529 target_data->prev_pos
530 ? index_to_map_pos_y(tile_index(*target_data->prev_pos))
531 : -1,
532 TILE_XY(target_tile));
533 continue;
534 }
535
536 /* Calculate juiciness of target, compare with existing target,
537 * if any. */
538 dai_hunter_juiciness(pplayer, punit, target, &stackthreat, &stackcost);
539 defender = get_defender(nmap, punit, target_tile);
540 if (defender != NULL) {
541 stackcost *= unit_win_chance(nmap, punit, defender);
542 }
543 if (stackcost < unit_build_shield_cost_base(punit)) {
544 UNIT_LOG(LOGLEVEL_HUNT, punit, "%d is too expensive (it %d vs us %d)",
545 target->id, stackcost,
546 unit_build_shield_cost_base(punit));
547 continue; /* Too expensive */
548 }
549 stackthreat /= move_cost + 1;
550 if (!is_virtual
551 && original_target != target
552 && original_threat > stackthreat) {
553 UNIT_LOG(LOGLEVEL_HUNT, punit, "Unit %d is not worse than %d",
554 target->id, original_target->id);
555 continue; /* The threat we found originally was worse than this! */
556 }
557 if (stackthreat < unit_build_shield_cost_base(punit)) {
558 UNIT_LOG(LOGLEVEL_HUNT, punit, "%d is not worth it", target->id);
559 continue; /* Not worth it */
560 }
561
562 UNIT_LOG(LOGLEVEL_HUNT, punit, "hunting %s %s[%d](%d,%d) "
563 "with want %d, dist1 %d, dist2 %d",
564 nation_rule_name(nation_of_unit(target)),
565 unit_rule_name(target),
566 target->id,
567 TILE_XY(target_tile),
568 stackthreat,
569 dist1,
570 dist2);
571 /* Ok, now we FINALLY have a target worth destroying! */
572 unit_data->target = target->id;
573 if (is_virtual) {
574 pf_map_destroy(pfm);
575 return stackthreat;
576 }
577
578 /* This assigns missiles to us */
579 dai_unit_new_task(ait, punit, AIUNIT_HUNTER, target_tile);
580
581 /* Check if we can nuke it */
582 dai_hunter_try_launch(ait, pplayer, punit, target);
583
584 /* Check if we have nuked it */
585 if (target != game_unit_by_number(sanity_target)) {
586 UNIT_LOG(LOGLEVEL_HUNT, punit, "mission accomplished by cargo (pre)");
587 dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
588 pf_map_destroy(pfm);
589 return -1; /* try again */
590 }
591
592 /* Go towards it. */
593 path = pf_map_path(pfm, target_tile);
594 if (!adv_unit_execute_path(punit, path)) {
595 pf_path_destroy(path);
596 pf_map_destroy(pfm);
597 return 0;
598 }
599 pf_path_destroy(path);
600
601 if (target != game_unit_by_number(sanity_target)) {
602 UNIT_LOG(LOGLEVEL_HUNT, punit, "mission accomplished");
603 dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
604 pf_map_destroy(pfm);
605 return -1; /* try again */
606 }
607
608 /* Check if we can nuke it now */
609 dai_hunter_try_launch(ait, pplayer, punit, target);
610 if (target != game_unit_by_number(sanity_target)) {
611 UNIT_LOG(LOGLEVEL_HUNT, punit, "mission accomplished by cargo (post)");
612 dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
613 pf_map_destroy(pfm);
614 return -1; /* try again */
615 }
616
617 pf_map_destroy(pfm);
618 unit_data->done = TRUE;
619 return stackthreat; /* still have work to do */
620 } unit_list_iterate_safe_end;
621 } pf_map_move_costs_iterate_end;
622
623 UNIT_LOG(LOGLEVEL_HUNT, punit, "ran out of map finding hunt target");
624 pf_map_destroy(pfm);
625 return 0; /* found nothing */
626}
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
adv_choice_set_use
#define adv_choice_set_use(_choice, _use)
Definition advchoice.h:85
CT_ATTACKER
@ CT_ATTACKER
Definition advchoice.h:40
adv_is_player_dangerous
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1087
advdata.h
adv_unit_execute_path
bool adv_unit_execute_path(struct unit *punit, struct pf_path *path)
Definition advgoto.c:82
advgoto.h
amortize
adv_want amortize(adv_want benefit, int delay)
Definition advtools.c:29
advtools.h
dai_hunter_juiciness
static void dai_hunter_juiciness(struct player *pplayer, struct unit *punit, struct unit *target, unsigned *stackthreat, unsigned *stackcost)
Definition aihunt.c:400
eval_hunter_want
static void eval_hunter_want(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, struct unit_type *best_type, int veteran)
Definition aihunt.c:228
dai_hunter_find
static struct unit * dai_hunter_find(struct player *pplayer, struct city *pcity)
Definition aihunt.c:64
dai_hunter_qualify
bool dai_hunter_qualify(struct player *pplayer, struct unit *punit)
Definition aihunt.c:289
dai_hunter_missile_want
static void dai_hunter_missile_want(struct player *pplayer, struct city *pcity, struct adv_choice *choice)
Definition aihunt.c:148
dai_hunter_guess_best
static struct unit_type * dai_hunter_guess_best(struct city *pcity, enum terrain_class tc, struct ai_type *ait, bool allow_gold_upkeep)
Definition aihunt.c:84
dai_hunter_choice
void dai_hunter_choice(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, bool allow_gold_upkeep)
Definition aihunt.c:253
dai_hunter_manage
int dai_hunter_manage(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition aihunt.c:437
dai_hunter_try_launch
static void dai_hunter_try_launch(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct unit *target)
Definition aihunt.c:305
aihunt.h
ailog.h
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_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_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
aitools.h
dai_unit_can_strike_my_unit
bool dai_unit_can_strike_my_unit(const struct unit *attacker, const struct unit *defender)
Definition aiunit.c:3438
aiunit.h
AIUNIT_NONE
@ AIUNIT_NONE
Definition aiunit.h:27
AIUNIT_HUNTER
@ AIUNIT_HUNTER
Definition aiunit.h:29
DEFENSE_POWER
#define DEFENSE_POWER(ptype)
Definition aiunit.h:66
ATTACK_POWER
#define ATTACK_POWER(ptype)
Definition aiunit.h:68
UNITTYPE_COSTS
#define UNITTYPE_COSTS(ut)
Definition aiunit.h:75
autosettlers.h
bitvector.h
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
city_production_unit_veteran_level
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:788
can_city_build_unit_now
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:925
city.h
city_owner
#define city_owner(_pcity_)
Definition city.h:543
citytools.h
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
unit_win_chance
double unit_win_chance(const struct civ_map *nmap, const struct unit *attacker, const struct unit *defender)
Definition combat.c:438
can_unit_attack_tile
bool can_unit_attack_tile(const struct unit *punit, const struct action *paction, const struct tile *dest_tile)
Definition combat.c:271
get_defender
struct unit * get_defender(const struct civ_map *nmap, const struct unit *attacker, const struct tile *ptile)
Definition combat.c:781
combat.h
daicity.h
target_tile
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:56
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
adv_want
float adv_want
Definition fc_types.h:1206
ADV_WANT_PRINTF
#define ADV_WANT_PRINTF
Definition fc_types.h:1207
O_SHIELD
@ O_SHIELD
Definition fc_types.h:91
O_GOLD
@ O_GOLD
Definition fc_types.h:91
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
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps.h
H_MAP
@ H_MAP
Definition handicaps.h:28
H_TARGETS
@ H_TARGETS
Definition handicaps.h:24
log.h
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
is_tiles_adjacent
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Definition map.c:929
real_map_distance
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:628
map.h
index_to_map_pos_y
static int index_to_map_pos_y(int mindex)
Definition map.h:696
index_to_map_pos_x
static int index_to_map_pos_x(int mindex)
Definition map.h:687
unit_move_rate
int unit_move_rate(const struct unit *punit)
Definition movement.c:90
can_unit_type_transport
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:826
can_attack_non_native
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:202
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
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_costs_iterate_end
#define pf_map_move_costs_iterate_end
Definition path_finding.h:592
pf_map_move_costs_iterate
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
Definition path_finding.h:582
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
pf_tools.h
player_index
int player_index(const struct player *pplayer)
Definition player.c:820
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
player.h
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
MIN
#define MIN(x, y)
Definition shared.h:55
MAX
#define MAX(x, y)
Definition shared.h:54
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
adv_choice
Definition advchoice.h:45
adv_choice::type
enum choice_type type
Definition advchoice.h:46
adv_choice::want
adv_want want
Definition advchoice.h:48
adv_choice::value
universals_u value
Definition advchoice.h:47
adv_choice::need_boat
bool need_boat
Definition advchoice.h:49
ai_type
Definition ai.h:50
city
Definition city.h:309
city::surplus
int surplus[O_LAST]
Definition city.h:343
city::tile
struct tile * tile
Definition city.h:311
city::units_supported
struct unit_list * units_supported
Definition city.h:391
civ_map
Definition map_types.h:71
pf_map
Definition path_finding.c:78
pf_parameter
Definition path_finding.h:357
pf_parameter::omniscience
bool omniscience
Definition path_finding.h:376
pf_path
Definition path_finding.h:344
player_diplstate::type
enum diplstate_type type
Definition player.h:201
player
Definition player.h:249
player::is_alive
bool is_alive
Definition player.h:268
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
unit_ai
Definition aiunit.h:32
unit_ai::prev_pos
struct tile ** prev_pos
Definition aiunit.h:40
unit_ai::hunted
bv_player hunted
Definition aiunit.h:43
unit_ai::done
bool done
Definition aiunit.h:44
unit_ai::cur_pos
struct tile ** cur_pos
Definition aiunit.h:40
unit_ai::target
int target
Definition aiunit.h:42
unit_type_ai
Definition aiunit.h:50
unit_type_ai::missile_platform
bool missile_platform
Definition aiunit.h:53
unit_type
Definition unittype.h:481
unit
Definition unit.h:138
unit::id
int id
Definition unit.h:145
unit::transporting
struct unit_list * transporting
Definition unit.h:184
unit::veteran
int veteran
Definition unit.h:152
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_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
unit_transport_get
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2421
unit_virtual_create
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1613
get_transporter_capacity
int get_transporter_capacity(const struct unit *punit)
Definition unit.c:301
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1709
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2405
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
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_safe
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_list_iterate_safe_end
#define unit_list_iterate_safe_end
Definition unitlist.h:61
unittools.h
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
utype_upkeep_cost
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
unit_rule_name
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1639
unit_build_shield_cost_base
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1536
unit_has_type_role
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Definition unittype.c:202
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
utype_ai_data
void * utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
Definition unittype.c:2741
utype_build_shield_cost
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1490
utype_acts_hostile
bool utype_acts_hostile(const struct unit_type *putype)
Definition unittype.c:515
utype_can_do_action
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:443
utype_class
#define utype_class(_t_)
Definition unittype.h:736
MOVE_NONE
@ MOVE_NONE
Definition unittype.h:131
utype_has_flag
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604
unit_type_iterate
#define unit_type_iterate(_p)
Definition unittype.h:838
unit_type_iterate_end
#define unit_type_iterate_end
Definition unittype.h:845