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

Freeciv-3.1

Loading...
Searching...
No Matches
aiair.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2002 - 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 "log.h"
20
21/* common */
22#include "combat.h"
23#include "game.h"
24#include "map.h"
25#include "movement.h"
26#include "player.h"
27#include "pf_tools.h"
28#include "unit.h"
29
30/* server */
31#include "citytools.h"
32#include "maphand.h"
33#include "srv_log.h"
34#include "unithand.h"
35#include "unittools.h"
36
37/* server/advisors */
38#include "advbuilding.h"
39#include "advgoto.h"
40
41/* ai */
42#include "handicaps.h"
43
44/* ai/default */
45#include "aiplayer.h"
46#include "ailog.h"
47#include "aitools.h"
48#include "aiunit.h"
49#include "daicity.h"
50
51#include "aiair.h"
52
53/******************************************************************/
57 static inline int regen_turns(struct unit *punit, struct tile *ptile,
58 int lost_hp)
59{
60 struct tile *real_tile = unit_tile(punit);
61 int res, regen, recov;
62
63 punit->tile = ptile;
64 /* unit_list_prepend(ptile, punit); ... (handle "MaxUnitsOnTile" etc.) */
65 regen = hp_gain_coord(punit);
66 recov = get_unit_bonus(punit, EFT_UNIT_RECOVER);
67 if (lost_hp - recov <= 0) {
68 res = 0;
69 } else {
70 res = 1 + (lost_hp - recov) / (recov + regen);
71 }
72 punit->tile = real_tile;
73
74 return res;
75}
76
77/******************************************************************/
88 static struct tile *find_nearest_airbase(struct unit *punit,
89 struct pf_path **path)
90{
91 struct player *pplayer = unit_owner(punit);
92 struct pf_parameter parameter;
93 struct pf_map *pfm;
94 struct tile *best = NULL;
95 int lost_hp = unit_type_get(punit)->hp - punit->hp;
96 int best_regt = FC_INFINITY;
97 const struct civ_map *nmap = &(wld.map);
98
99 pft_fill_unit_parameter(&parameter, nmap, punit);
100 parameter.omniscience = !has_handicap(pplayer, H_MAP);
101 pfm = pf_map_new(&parameter);
102
103 pf_map_move_costs_iterate(pfm, ptile, move_cost, TRUE) {
104 if (move_cost > punit->moves_left) {
105 /* Too far! */
106 break;
107 }
108
109 if (is_refuel_point(ptile, pplayer, punit)) {
110 if (lost_hp > 0) {
111 int regt = regen_turns(punit, ptile, lost_hp);
112
113 if (regt <= 0) {
114 /* Nothing better to search */
115 best = ptile;
116 break;
117 } else if (!best || regt < best_regt) {
118 /* Regenerates faster */
119 best_regt = regt;
120 best = ptile;
121 }
122 } else {
123 best = ptile;
124 break;
125 }
126 }
127 } pf_map_move_costs_iterate_end;
128
129 if (path && best) {
130 *path = pf_map_path(pfm, best);
131 }
132 pf_map_destroy(pfm);
133 return best;
134}
135
136/******************************************************************/
140 static bool dai_should_we_air_attack_tile(struct ai_type *ait,
141 struct unit *punit, struct tile *ptile)
142{
143 struct city *acity = tile_city(ptile);
144
145 /* For a virtual unit (punit->id == 0), all targets are good */
146 /* TODO: There is a danger of producing too many units that will not
147 * attack anything. Production should not happen if there is an idle
148 * unit of the same type nearby */
149 if (acity && punit->id != 0
150 && def_ai_city_data(acity, ait)->invasion.occupy == 0
151 && !unit_can_take_over(punit)) {
152 /* No units capable of occupying are invading */
153 log_debug("Don't want to attack %s, although we could",
154 city_name_get(acity));
155 return FALSE;
156 }
157
158 return TRUE;
159}
160
161/******************************************************************/
165 static adv_want dai_evaluate_tile_for_air_attack(struct unit *punit,
166 struct tile *dst_tile)
167{
168 struct unit *pdefender;
169 /* Unit costs in shields */
170 int balanced_cost, unit_cost, victim_cost = 0;
171 /* Unit stats */
172 int unit_attack, victim_defense;
173 /* Final answer */
174 adv_want profit;
175 /* Time spent in the air */
176 int sortie_time;
177 struct civ_map *nmap = &(wld.map);
178
179#define PROB_MULTIPLIER 100 /* Should unify with those in combat.c */
180
181 if (!can_unit_attack_tile(punit, NULL, dst_tile)
182 || !(pdefender = get_defender(nmap, punit, dst_tile))) {
183 return 0;
184 }
185
186 /* Ok, we can attack, but is it worth it? */
187
188 /* Cost of our unit */
189 unit_cost = unit_build_shield_cost_base(punit);
190 /* This is to say "wait, ill unit will get better!" */
191 unit_cost = unit_cost * unit_type_get(punit)->hp / punit->hp;
192
193 /* Determine cost of enemy units */
194 victim_cost = stack_cost(punit, pdefender);
195 if (0 == victim_cost) {
196 return 0;
197 }
198
199 /* Missile would die 100% so we adjust the victim_cost -- GB */
200 if (utype_can_do_action(unit_type_get(punit), ACTION_SUICIDE_ATTACK)) {
201 /* Assume that the attack will be a suicide attack even if a regular
202 * attack may be legal. */
203 victim_cost -= unit_build_shield_cost_base(punit);
204 }
205
206 unit_attack = (int) (PROB_MULTIPLIER
207 * unit_win_chance(nmap, punit, pdefender));
208
209 victim_defense = PROB_MULTIPLIER - unit_attack;
210
211 balanced_cost = build_cost_balanced(unit_type_get(punit));
212
213 sortie_time
214 = (utype_pays_mp_for_action_estimate(nmap,
215 action_by_number(ACTION_ATTACK),
216 unit_type_get(punit), unit_owner(punit),
217 /* Assume that dst_tile is closer to the tile the actor
218 * unit will attack from than its current tile. */
219 dst_tile,
220 dst_tile) >= MAX_MOVE_FRAGS ? 1 : 0);
221
222 profit = kill_desire(victim_cost, unit_attack, unit_cost, victim_defense, 1)
223 - SHIELD_WEIGHTING + 2 * TRADE_WEIGHTING;
224 if (profit > 0) {
225 profit = military_amortize(unit_owner(punit),
226 game_city_by_number(punit->homecity),
227 profit, sortie_time, balanced_cost);
228 log_debug("%s at (%d, %d) is a worthy target with profit " ADV_WANT_PRINTF,
229 unit_rule_name(pdefender), TILE_XY(dst_tile), profit);
230 } else {
231 log_debug("%s(%d, %d): %s at (%d, %d) is unworthy with profit " ADV_WANT_PRINTF,
232 unit_rule_name(punit), TILE_XY(unit_tile(punit)),
233 unit_rule_name(pdefender), TILE_XY(dst_tile), profit);
234 profit = 0;
235 }
236
237 return profit;
238}
239
240/******************************************************************/
249 static adv_want find_something_to_bomb(struct ai_type *ait, struct unit *punit,
250 struct pf_path **path, struct tile **pptile)
251{
252 struct player *pplayer = unit_owner(punit);
253 struct pf_parameter parameter;
254 struct pf_map *pfm;
255 struct tile *best_tile = NULL;
256 adv_want best = 0;
257 const struct civ_map *nmap = &(wld.map);
258
259 pft_fill_unit_parameter(&parameter, nmap, punit);
260 parameter.omniscience = !has_handicap(pplayer, H_MAP);
261 pfm = pf_map_new(&parameter);
262
263 /* Let's find something to bomb */
264 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
265 if (move_cost >= punit->moves_left) {
266 /* Too far! */
267 break;
268 }
269
270 if (has_handicap(pplayer, H_MAP) && !map_is_known(ptile, pplayer)) {
271 /* The target tile is unknown */
272 continue;
273 }
274
275 if (has_handicap(pplayer, H_FOG)
276 && !map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
277 /* The tile is fogged */
278 continue;
279 }
280
281 if (is_enemy_unit_tile(ptile, pplayer)
282 && dai_should_we_air_attack_tile(ait, punit, ptile)
283 && can_unit_attack_tile(punit, NULL, ptile)) {
284 adv_want new_best = dai_evaluate_tile_for_air_attack(punit, ptile);
285
286 if (new_best > best) {
287 best_tile = ptile;
288 best = new_best;
289 log_debug("%s wants to attack tile (%d, %d)",
290 unit_rule_name(punit), TILE_XY(ptile));
291 }
292 }
293 } pf_map_move_costs_iterate_end;
294
295 /* Return the best values. */
296 if (pptile) {
297 *pptile = best_tile;
298 }
299 if (path) {
300 *path = best_tile ? pf_map_path(pfm, best_tile) : NULL;
301 }
302
303 pf_map_destroy(pfm);
304
305 return best;
306}
307
308/******************************************************************/
319 static struct tile *dai_find_strategic_airbase(struct ai_type *ait,
320 struct unit *punit,
321 struct pf_path **path)
322{
323 struct player *pplayer = unit_owner(punit);
324 struct pf_parameter parameter;
325 struct pf_map *pfm;
326 struct tile *best_tile = NULL;
327 struct city *pcity;
328 struct unit *pvirtual = NULL;
329 adv_want best_worth = 0, target_worth;
330 int lost_hp = unit_type_get(punit)->hp - punit->hp;
331 int regen_turns_min = FC_INFINITY;
332 bool defend = FALSE; /* Used only for lost_hp > 0 */
333 bool refuel_start = FALSE; /* Used for not a "grave danger" start */
334 const struct civ_map *nmap = &(wld.map);
335
336 /* Consider staying at the current position
337 * before we generate the map, maybe we should not */
338 if (is_unit_being_refueled(punit)) {
339 /* We suppose here for speed that the recovery effect is global.
340 * It's so in the standard rulesets but might be not elsewhere */
341 int recov = get_unit_bonus(punit, EFT_UNIT_RECOVER);
342 int regen = hp_gain_coord(punit);
343 const struct tile *ptile = unit_tile(punit);
344
345 if (lost_hp > 0 && regen + recov > 0) {
346 regen_turns_min =
347 punit->moved ? lost_hp - recov : lost_hp - (regen + recov);
348 if (regen_turns_min <= 0) {
349 if (lost_hp - recov > 0) {
350 /* Probably, nothing can repair us faster */
351 log_debug("Repairment of %s is almost finished, stays here",
352 unit_rule_name(punit));
353 def_ai_unit_data(punit, ait)->done = TRUE;
354 return NULL;
355 } else {
356 regen_turns_min = 0;
357 }
358 } else {
359 regen_turns_min /= regen + recov;
360 regen_turns_min += 1;
361 }
362 }
363 pcity = tile_city(ptile);
364 if (pcity
365 && def_ai_city_data(pcity, ait)->grave_danger
366 > (unit_list_size(ptile->units) - 1) << 1) {
367 if (lost_hp <= 0 || regen_turns_min <= 1) {
368 log_debug("%s stays defending %s",
369 unit_rule_name(punit), city_name_get(pcity));
370 return NULL;
371 } else {
372 /* We may find a city in grave danger that restores faster */
373 defend = TRUE;
374 }
375 } else {
376 refuel_start = TRUE;
377 }
378 }
379
380 pft_fill_unit_parameter(&parameter, nmap, punit);
381 parameter.omniscience = !has_handicap(pplayer, H_MAP);
382 pfm = pf_map_new(&parameter);
383 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
384 bool chg_for_regen = FALSE;
385
386 if (move_cost >= punit->moves_left) {
387 break; /* Too far! */
388 }
389
390 if (!is_refuel_point(ptile, pplayer, punit)) {
391 continue; /* Cannot refuel here. */
392 }
393
394 if (lost_hp > 0) {
395 /* Don't fly to a point where we'll regenerate longer */
396 int regen_tn = regen_turns(punit, ptile, lost_hp);
397
398 if (regen_turns_min < regen_tn) {
399 log_debug("%s knows a better repair base than %d,%d",
400 unit_rule_name(punit), TILE_XY(ptile));
401 continue;
402 } else if (regen_turns_min > regen_tn) {
403 regen_turns_min = regen_tn;
404 best_tile = ptile;
405 best_worth = 0; /* to be calculated if necessary */
406 chg_for_regen = TRUE;
407 }
408 }
409
410 if ((pcity = tile_city(ptile))
411 /* Two defenders per attacker is enough,
412 * at least considering that planes are usually
413 * expensive and weak city defenders */
414 && def_ai_city_data(pcity, ait)->grave_danger
415 > unit_list_size(ptile->units) << 1) {
416 if (lost_hp <= 0) {
417 best_tile = ptile;
418 break; /* Fly there immediately!! */
419 } else {
420 if (!defend) {
421 /* We maybe have equally regenerating base but not in danger */
422 best_tile = ptile;
423 defend = TRUE;
424 }
425 continue;
426 }
427 } else if (defend) {
428 if (chg_for_regen) {
429 /* We better regenerate faster and take a revenge a bit later */
430 defend = FALSE;
431 } else {
432 /* We already have a base in grave danger that restores not worse */
433 continue;
434 }
435 }
436
437 if (!pvirtual) {
438 pvirtual =
439 unit_virtual_create(pplayer,
440 player_city_by_number(pplayer, punit->homecity),
441 unit_type_get(punit), punit->veteran);
442 if (refuel_start) {
443 /* What worth really worth moving out? */
444 adv_want start_worth;
445
446 unit_tile_set(pvirtual, unit_tile(punit));
447 start_worth = find_something_to_bomb(ait, pvirtual, NULL, NULL);
448 best_worth = MAX(start_worth, 0);
449 }
450 }
451
452 unit_tile_set(pvirtual, ptile);
453 target_worth = find_something_to_bomb(ait, pvirtual, NULL, NULL);
454 if (target_worth > best_worth) {
455 /* It's either a first find or it's better than the previous. */
456 best_worth = target_worth;
457 best_tile = ptile;
458 /* We can still look for something better. */
459 }
460 } pf_map_move_costs_iterate_end;
461
462 if (pvirtual) {
463 unit_virtual_destroy(pvirtual);
464 }
465
466 if (path) {
467 /* Stores the path. */
468 *path = best_tile ? pf_map_path(pfm, best_tile) : NULL;
469 }
470 pf_map_destroy(pfm);
471
472 return best_tile;
473}
474
475/******************************************************************/
488 void dai_manage_airunit(struct ai_type *ait, struct player *pplayer,
489 struct unit *punit)
490{
491 struct tile *dst_tile = unit_tile(punit);
492 /* Loop prevention */
493 int moves = punit->moves_left;
494 int id = punit->id;
495 struct pf_parameter parameter;
496 struct pf_map *pfm;
497 struct pf_path *path;
498
499 CHECK_UNIT(punit);
500
501 if (!is_unit_being_refueled(punit)) {
502 /* We are out in the open, what shall we do? */
503 if (punit->activity == ACTIVITY_GOTO
504 /* We are on a GOTO. Check if it will get us anywhere */
505 && NULL != punit->goto_tile
506 && !same_pos(unit_tile(punit), punit->goto_tile)
507 && is_refuel_point(punit->goto_tile, pplayer, punit)) {
508 pfm = pf_map_new(&parameter);
509 path = pf_map_path(pfm, punit->goto_tile);
510 if (path) {
511 bool alive = adv_follow_path(punit, path, punit->goto_tile);
512
513 pf_path_destroy(path);
514 pf_map_destroy(pfm);
515 if (alive && punit->moves_left > 0) {
516 /* Maybe do something else. */
517 dai_manage_airunit(ait, pplayer, punit);
518 }
519 return;
520 }
521 pf_map_destroy(pfm);
522 } else if ((dst_tile = find_nearest_airbase(punit, &path))) {
523 /* Go refuelling */
524 if (!adv_follow_path(punit, path, dst_tile)) {
525 pf_path_destroy(path);
526 return; /* The unit died. */
527 }
528 pf_path_destroy(path);
529 } else {
530 if (punit->fuel == 1) {
531 UNIT_LOG(LOG_DEBUG, punit, "Oops, fallin outta the sky");
532 }
533 def_ai_unit_data(punit, ait)->done = TRUE; /* Won't help trying again */
534 return;
535 }
536
537 } else if (punit->fuel == unit_type_get(punit)->fuel) {
538 /* We only leave a refuel point when we are on full fuel */
539
540 if (find_something_to_bomb(ait, punit, &path, &dst_tile) > 0) {
541 /* Found target, coordinates are in punit's goto_dest.
542 * TODO: separate attacking into a function, check for the best
543 * tile to attack from */
544 fc_assert_ret(path != NULL && dst_tile != NULL);
545 if (!adv_follow_path(punit, path, dst_tile)) {
546 pf_path_destroy(path);
547 return; /* The unit died. */
548 }
549 pf_path_destroy(path);
550 unit_activity_handling(punit, ACTIVITY_IDLE);
551 } else if ((dst_tile = dai_find_strategic_airbase(ait, punit, &path))) {
552 log_debug("%s will fly to (%i, %i) (%s) to fight there",
553 unit_rule_name(punit), TILE_XY(dst_tile),
554 tile_city(dst_tile) ? city_name_get(tile_city(dst_tile)) : "");
555 def_ai_unit_data(punit, ait)->done = TRUE; /* Wait for next turn */
556 if (!adv_follow_path(punit, path, dst_tile)) {
557 pf_path_destroy(path);
558 return; /* The unit died. */
559 }
560 pf_path_destroy(path);
561 } else {
562 log_debug("%s cannot find anything to kill and is staying put",
563 unit_rule_name(punit));
564 def_ai_unit_data(punit, ait)->done = TRUE;
565 unit_activity_handling(punit, ACTIVITY_IDLE);
566 }
567 }
568
569 if ((punit = game_unit_by_number(id)) != NULL && punit->moves_left > 0
570 && punit->moves_left != moves) {
571 /* We have moved this turn, might have ended up stuck out in the fields
572 * so, as a safety measure, let's manage again */
573 dai_manage_airunit(ait, pplayer, punit);
574 }
575
576}
577
578/******************************************************************/
584 bool dai_choose_attacker_air(struct ai_type *ait, struct player *pplayer,
585 struct city *pcity, struct adv_choice *choice,
586 bool allow_gold_upkeep)
587{
588 bool want_something = FALSE;
589
590 /* This AI doesn't know how to build planes */
591 if (has_handicap(pplayer, H_NOPLANES)) {
592 return FALSE;
593 }
594
595 /* military_advisor_choose_build() does something idiotic,
596 * this function should not be called if there is danger... */
597 if (choice->want >= DAI_WANT_MILITARY_EMERGENCY
598 && choice->type != CT_ATTACKER) {
599 return FALSE;
600 }
601
602 if (!player_knows_techs_with_flag(pplayer, TF_BUILD_AIRBORNE)) {
603 return FALSE;
604 }
605
606 unit_type_iterate(punittype) {
607 struct unit_class *pclass = utype_class(punittype);
608
609 if (pclass->adv.land_move == MOVE_NONE
610 || pclass->adv.sea_move == MOVE_NONE
611 || uclass_has_flag(pclass, UCF_TERRAIN_SPEED)
612 || unit_type_is_losing_hp(pplayer, punittype)) {
613 /* We don't consider this a plane */
614 continue;
615 }
616
617 if (!allow_gold_upkeep && utype_upkeep_cost(punittype, pplayer, O_GOLD) > 0) {
618 continue;
619 }
620
621 if (can_city_build_unit_now(pcity, punittype)) {
622 struct unit *virtual_unit =
623 unit_virtual_create(
624 pplayer, pcity, punittype,
625 city_production_unit_veteran_level(pcity, punittype));
626 adv_want profit = find_something_to_bomb(ait, virtual_unit, NULL, NULL);
627
628 if (profit > choice->want) {
629 /* Update choice */
630 choice->want = profit;
631 choice->value.utype = punittype;
632 choice->type = CT_ATTACKER;
633 choice->need_boat = FALSE;
634 adv_choice_set_use(choice, "offensive air");
635 want_something = TRUE;
636 log_debug("%s wants to build %s (want = " ADV_WANT_PRINTF ")",
637 city_name_get(pcity), utype_rule_name(punittype), profit);
638 } else {
639 log_debug("%s doesn't want to build %s (want = " ADV_WANT_PRINTF ")",
640 city_name_get(pcity), utype_rule_name(punittype), profit);
641 }
642 unit_virtual_destroy(virtual_unit);
643 }
644 } unit_type_iterate_end;
645
646 return want_something;
647}
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
advbuilding.h
TRADE_WEIGHTING
#define TRADE_WEIGHTING
Definition advbuilding.h:21
SHIELD_WEIGHTING
#define SHIELD_WEIGHTING
Definition advbuilding.h:20
adv_choice_set_use
#define adv_choice_set_use(_choice, _use)
Definition advchoice.h:85
CT_ATTACKER
@ CT_ATTACKER
Definition advchoice.h:40
adv_follow_path
bool adv_follow_path(struct unit *punit, struct pf_path *path, struct tile *ptile)
Definition advgoto.c:47
advgoto.h
find_nearest_airbase
static struct tile * find_nearest_airbase(struct unit *punit, struct pf_path **path)
Definition aiair.c:88
find_something_to_bomb
static adv_want find_something_to_bomb(struct ai_type *ait, struct unit *punit, struct pf_path **path, struct tile **pptile)
Definition aiair.c:249
dai_manage_airunit
void dai_manage_airunit(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition aiair.c:488
PROB_MULTIPLIER
#define PROB_MULTIPLIER
regen_turns
static int regen_turns(struct unit *punit, struct tile *ptile, int lost_hp)
Definition aiair.c:57
dai_choose_attacker_air
bool dai_choose_attacker_air(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, bool allow_gold_upkeep)
Definition aiair.c:584
dai_should_we_air_attack_tile
static bool dai_should_we_air_attack_tile(struct ai_type *ait, struct unit *punit, struct tile *ptile)
Definition aiair.c:140
dai_find_strategic_airbase
static struct tile * dai_find_strategic_airbase(struct ai_type *ait, struct unit *punit, struct pf_path **path)
Definition aiair.c:319
dai_evaluate_tile_for_air_attack
static adv_want dai_evaluate_tile_for_air_attack(struct unit *punit, struct tile *dst_tile)
Definition aiair.c:165
aiair.h
ailog.h
aiplayer.h
def_ai_city_data
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition aiplayer.h:42
def_ai_unit_data
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition aiplayer.h:48
stack_cost
int stack_cost(struct unit *pattacker, struct unit *pdefender)
Definition aitools.c:1262
military_amortize
adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
Definition aitools.c:118
aitools.h
DAI_WANT_MILITARY_EMERGENCY
#define DAI_WANT_MILITARY_EMERGENCY
Definition aitools.h:32
kill_desire
adv_want kill_desire(adv_want benefit, int attack, int loss, int vuln, int victim_count)
Definition aiunit.c:340
build_cost_balanced
int build_cost_balanced(const struct unit_type *punittype)
Definition aiunit.c:248
aiunit.h
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1111
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_unit_now
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:928
citytools.h
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
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
get_unit_bonus
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:992
adv_want
float adv_want
Definition fc_types.h:1206
ADV_WANT_PRINTF
#define ADV_WANT_PRINTF
Definition fc_types.h:1207
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_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:102
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_NOPLANES
@ H_NOPLANES
Definition handicaps.h:27
H_FOG
@ H_FOG
Definition handicaps.h:26
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
log_debug
#define log_debug(message,...)
Definition log.h:115
LOG_DEBUG
@ LOG_DEBUG
Definition log.h:34
same_pos
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:938
map.h
map_is_known
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:886
map_is_known_and_seen
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:900
maphand.h
movement.h
MAX_MOVE_FRAGS
#define MAX_MOVE_FRAGS
Definition movement.h:27
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_knows_techs_with_flag
bool player_knows_techs_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1304
player_city_by_number
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1179
player.h
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
MAX
#define MAX(x, y)
Definition shared.h:54
srv_log.h
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
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
Definition player.h:249
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
unit_ai::done
bool done
Definition aiunit.h:44
unit_class
Definition unittype.h:136
unit_class::sea_move
enum move_level sea_move
Definition unittype.h:150
unit_class::land_move
enum move_level land_move
Definition unittype.h:149
unit_class::adv
struct unit_class::@84 adv
unit_type::hp
int hp
Definition unittype.h:505
unit
Definition unit.h:138
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::moved
bool moved
Definition unit.h:173
unit::hp
int hp
Definition unit.h:151
unit::fuel
int fuel
Definition unit.h:153
unit::tile
struct tile * tile
Definition unit.h:140
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
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_XY
#define TILE_XY(ptile)
Definition tile.h:42
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:604
unit_type_is_losing_hp
bool unit_type_is_losing_hp(const struct player *pplayer, const struct unit_type *punittype)
Definition unit.c:2226
hp_gain_coord
int hp_gain_coord(const struct unit *punit)
Definition unit.c:2148
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:1619
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1715
unit_tile_set
void unit_tile_set(struct unit *punit, struct tile *ptile)
Definition unit.c:1282
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
unithand.h
is_refuel_point
bool is_refuel_point(const struct tile *ptile, const struct player *pplayer, const struct unit *punit)
Definition unittools.c:1547
is_unit_being_refueled
bool is_unit_being_refueled(const struct unit *punit)
Definition unittools.c:1538
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
utype_pays_mp_for_action_estimate
int utype_pays_mp_for_action_estimate(const struct civ_map *nmap, const struct action *paction, const struct unit_type *putype, const struct player *act_player, const struct tile *act_tile, const struct tile *tgt_tile)
Definition unittype.c:1445
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
unit_can_take_over
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:258
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_class
#define utype_class(_t_)
Definition unittype.h:736
MOVE_NONE
@ MOVE_NONE
Definition unittype.h:131
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