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

Freeciv-3.2

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