Freeciv-3.2: /fast/freeciv/nightly/S3_2/ai/default/aihunt.c Source File

Freeciv-3.2

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