Freeciv-3.3: /fast/freeciv/nightly/main/ai/default/daimilitary.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
daimilitary.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <string.h>
19
20/* utility */
21#include "log.h"
22
23/* common */
24#include "combat.h"
25#include "game.h"
26#include "government.h"
27#include "map.h"
28#include "movement.h"
29#include "research.h"
30#include "specialist.h"
31#include "unitlist.h"
32
33/* common/aicore */
34#include "pf_tools.h"
35
36/* server */
37#include "citytools.h"
38#include "cityturn.h"
39#include "srv_log.h"
40#include "srv_main.h"
41
42/* server/advisors */
43#include "advbuilding.h"
44#include "advchoice.h"
45#include "advdata.h"
46#include "advgoto.h"
47#include "advtools.h"
48#include "infracache.h"
49
50/* ai */
51#include "aitraits.h"
52#include "difficulty.h"
53#include "handicaps.h"
54
55/* ai/default */
56#include "aidiplomat.h"
57#include "aiferry.h"
58#include "aihand.h"
59#include "aiparatrooper.h"
60#include "daiair.h"
61#include "daicity.h"
62#include "daidata.h"
63#include "daieffects.h"
64#include "daihunter.h"
65#include "dailog.h"
66#include "daiplayer.h"
67#include "daitech.h"
68#include "daitools.h"
69
70#include "daimilitary.h"
71
72/* Size 1 city gets destroyed when conquered. It's still a good thing
73 * stop enemy from having it. */
74#define CITY_CONQUEST_WORTH(_city_, _data_) \
75 (_data_->worth * 0.9 + (city_size_get(_city_) - 0.5) * 10)
76
77static unsigned int assess_danger(struct ai_type *ait, struct city *pcity,
78 const struct civ_map *dmap,
79 player_unit_list_getter ul_cb);
80
81static adv_want dai_unit_attack_desirability(struct ai_type *ait,
82 const struct unit_type *punittype);
83static adv_want dai_unit_defense_desirability(struct ai_type *ait,
84 const struct unit_type *punittype);
85
86/**********************************************************************/
89 struct unit_type *dai_choose_defender_versus(struct city *pcity,
90 struct unit *attacker)
91{
92 struct unit_type *bestunit = NULL;
93 double best = 0;
94 int best_cost = FC_INFINITY;
95 struct player *pplayer = city_owner(pcity);
96 struct civ_map *nmap = &(wld.map);
97
98 simple_ai_unit_type_iterate(punittype) {
99 if (can_city_build_unit_now(pcity, punittype)) {
100 int fpatt, fpdef, defense, attack;
101 double want, loss, cost = utype_build_shield_cost(pcity, NULL, punittype);
102 struct unit *defender;
103 int veteran = get_unittype_bonus(city_owner(pcity), pcity->tile,
104 punittype, NULL,
105 EFT_VETERAN_BUILD);
106
107 defender = unit_virtual_create(pplayer, pcity, punittype, veteran);
108 defense = get_total_defense_power(attacker, defender);
109 attack = get_total_attack_power(attacker, defender, NULL);
110 get_modified_firepower(nmap, attacker, defender, &fpatt, &fpdef);
111
112 /* Greg's algorithm. loss is the average number of health lost by
113 * defender. If loss > attacker's hp then we should win the fight,
114 * which is always a good thing, since we avoid shield loss. */
115 loss = (double) defense * punittype->hp * fpdef / (attack * fpatt);
116 want = (loss + MAX(0, loss - attacker->hp)) / cost;
117
118#ifdef NEVER
119 CITY_LOG(LOG_DEBUG, pcity, "desire for %s against %s(%d,%d) is %.2f",
120 unit_name_orig(punittype),
121 unit_name_orig(unit_type_get(attacker)),
122 TILE_XY(attacker->tile), want);
123#endif /* NEVER */
124
125 if (want > best || (ADV_WANTS_EQ(want, best)
126 && cost <= best_cost)) {
127 best = want;
128 bestunit = punittype;
129 best_cost = cost;
130 }
131 unit_virtual_destroy(defender);
132 }
133 } simple_ai_unit_type_iterate_end;
134
135 return bestunit;
136}
137
138/**********************************************************************/
143 static struct unit_type *dai_choose_attacker(struct ai_type *ait,
144 struct city *pcity,
145 enum terrain_class tc,
146 bool allow_gold_upkeep)
147{
148 struct unit_type *bestid = NULL;
149 adv_want best = -1;
150 adv_want cur;
151 struct player *pplayer = city_owner(pcity);
152
153 simple_ai_unit_type_iterate(putype) {
154 if (!allow_gold_upkeep && utype_upkeep_cost(putype, pplayer, O_GOLD) > 0) {
155 continue;
156 }
157
158 cur = dai_unit_attack_desirability(ait, putype);
159 if ((tc == TC_LAND && utype_class(putype)->adv.land_move != MOVE_NONE)
160 || (tc == TC_OCEAN
161 && utype_class(putype)->adv.sea_move != MOVE_NONE)) {
162 if (can_city_build_unit_now(pcity, putype)
163 && (cur > best
164 || (ADV_WANTS_EQ(cur, best)
165 && utype_build_shield_cost(pcity, NULL, putype)
166 <= utype_build_shield_cost(pcity, NULL, bestid)))) {
167 best = cur;
168 bestid = putype;
169 }
170 }
171 } simple_ai_unit_type_iterate_end;
172
173 return bestid;
174}
175
176/**********************************************************************/
184 static struct unit_type *dai_choose_bodyguard(struct ai_type *ait,
185 struct city *pcity,
186 enum terrain_class tc,
187 enum unit_role_id role,
188 bool allow_gold_upkeep)
189{
190 struct unit_type *bestid = NULL;
191 adv_want best = 0;
192 struct player *pplayer = city_owner(pcity);
193
194 simple_ai_unit_type_iterate(putype) {
195 /* Only consider units of given role, or any if invalid given */
196 if (unit_role_id_is_valid(role)) {
197 if (!utype_has_role(putype, role)) {
198 continue;
199 }
200 }
201
202 if (!allow_gold_upkeep && utype_upkeep_cost(putype, pplayer, O_GOLD) > 0) {
203 continue;
204 }
205
206 /* Only consider units of same move type */
207 if ((tc == TC_LAND && utype_class(putype)->adv.land_move == MOVE_NONE)
208 || (tc == TC_OCEAN
209 && utype_class(putype)->adv.sea_move == MOVE_NONE)) {
210 continue;
211 }
212
213 /* Now find best */
214 if (can_city_build_unit_now(pcity, putype)) {
215 const adv_want desire = dai_unit_defense_desirability(ait, putype);
216
217 if (desire > best
218 || (ADV_WANTS_EQ(desire, best) && utype_build_shield_cost(pcity, NULL, putype) <=
219 utype_build_shield_cost(pcity, NULL, bestid))) {
220 best = desire;
221 bestid = putype;
222 }
223 }
224 } simple_ai_unit_type_iterate_end;
225
226 return bestid;
227}
228
229/**********************************************************************/
232 static int base_assess_defense_unit(struct city *pcity, struct unit *punit,
233 bool igwall, bool quadratic,
234 int wall_value)
235{
236 int defense;
237 int fp;
238
239 if (is_special_unit(punit)) {
240 return 0;
241 }
242
243 defense = get_fortified_defense_power(NULL, punit) * punit->hp;
244 fp = unit_type_get(punit)->firepower;
245 if (unit_has_type_flag(punit, UTYF_BADCITYDEFENDER)) {
246 /* Attacker firepower doubled, defender firepower set to
247 * game.info.low_firepower_pearl_harbour at max. */
248 defense *= MIN(fp, game.info.low_firepower_pearl_harbour);
249 defense /= 2;
250 } else {
251 defense *= fp;
252 }
253
254 defense /= POWER_DIVIDER;
255
256 if (quadratic) {
257 defense *= defense;
258 }
259
260 if (pcity != NULL && !igwall && city_got_defense_effect(pcity, NULL)) {
261 /* FIXME: We checked if city got defense effect against *some*
262 * unit type. Sea unit danger might cause us to build defenses
263 * against air units... */
264
265 /* TODO: What about wall_value < 10? Do we really want walls to
266 * result in decrease in the returned value? */
267 defense *= wall_value;
268 defense /= 10;
269 }
270
271 return defense;
272}
273
274/**********************************************************************/
277 int assess_defense_quadratic(struct ai_type *ait, struct city *pcity)
278{
279 int defense = 0, walls = 0;
280 /* This can be an arg if needed, but we don't need to change it now. */
281 const bool igwall = FALSE;
282 struct ai_city *city_data = def_ai_city_data(pcity, ait);
283
284 /* wallvalue = 10, walls = 10,
285 * wallvalue = 40, walls = 20,
286 * wallvalue = 90, walls = 30 */
287
288 while (walls * walls < city_data-> wallvalue * 10) {
289 walls++;
290 }
291
292 unit_list_iterate(pcity->tile->units, punit) {
293 defense += base_assess_defense_unit(pcity, punit, igwall, FALSE,
294 walls);
295 } unit_list_iterate_end;
296
297 if (defense > 1<<12) {
298 CITY_LOG(LOG_VERBOSE, pcity, "Overflow danger in assess_defense_quadratic:"
299 " %d", defense);
300 if (defense > 1<<15) {
301 defense = 1<<15; /* more defense than we know what to do with! */
302 }
303 }
304
305 return defense * defense;
306}
307
308/**********************************************************************/
311 int assess_defense_unit(struct ai_type *ait, struct city *pcity,
312 struct unit *punit, bool igwall)
313{
314 return base_assess_defense_unit(pcity, punit, igwall, TRUE,
315 def_ai_city_data(pcity, ait)->wallvalue);
316}
317
318/**********************************************************************/
325 static int assess_defense_backend(struct ai_type *ait, struct city *pcity,
326 bool igwall)
327{
328 /* Estimate of our total city defensive might */
329 int defense = 0;
330
331 unit_list_iterate(pcity->tile->units, punit) {
332 defense += assess_defense_unit(ait, pcity, punit, igwall);
333 } unit_list_iterate_end;
334
335 return defense;
336}
337
338/**********************************************************************/
341 int assess_defense(struct ai_type *ait, struct city *pcity)
342{
343 return assess_defense_backend(ait, pcity, FALSE);
344}
345
346/**********************************************************************/
350 static int assess_defense_igwall(struct ai_type *ait, struct city *pcity)
351{
352 return assess_defense_backend(ait, pcity, TRUE);
353}
354
355/**********************************************************************/
361static enum fc_tristate
362tactical_req_cb(const struct req_context *context,
363 const struct player *other_player,
364 const struct requirement *req,
365 void *data, int n_data)
366{
367 switch (req->source.kind) {
368 case VUT_IMPROVEMENT:
369 {
370 const struct impr_type *b = req->source.value.building;
371
372 /* FIXME: in actor_reqs, may allow attack _from_ a city with... */
373 if (req->survives || NULL == context->city || is_great_wonder(b)
374 || !city_has_building(context->city, b) || b->sabotage <= 0) {
375 return tri_req_active(context, other_player, req);
376 }
377 /* Else may be sabotaged */
378 }
379 fc__fallthrough;
380 case VUT_UNITSTATE:
381 case VUT_ACTIVITY:
382 case VUT_MINSIZE:
383 case VUT_MAXTILEUNITS:
384 case VUT_MINHP:
385 case VUT_MINMOVES:
386 case VUT_COUNTER:
387 /* Can be changed back or forth quickly */
388 return TRI_MAYBE;
389 case VUT_MINVETERAN:
390 /* Can be changed forth but not back */
391 return is_req_preventing(context, other_player, req, RPT_POSSIBLE)
392 > REQUCH_CTRL ? TRI_NO : TRI_MAYBE;
393 case VUT_MINFOREIGNPCT:
394 case VUT_NATIONALITY:
395 /* Can be changed back but hardly forth (foreign citizens reduced first) */
396 switch (tri_req_active(context, other_player, req)) {
397 case TRI_NO:
398 return req->present ? TRI_NO : TRI_MAYBE;
399 case TRI_YES:
400 return req->present ? TRI_MAYBE : TRI_YES;
401 default:
402 return TRI_MAYBE;
403 }
404 case VUT_DIPLREL:
405 case VUT_DIPLREL_TILE:
406 case VUT_DIPLREL_TILE_O:
407 case VUT_DIPLREL_UNITANY:
408 case VUT_DIPLREL_UNITANY_O:
409 /* If the attack happens, there is a diplrel that allows it */
410 return TRI_YES;
411 case VUT_AGE:
412 case VUT_FORM_AGE:
413 case VUT_MINCALFRAG:
414 case VUT_MINYEAR:
415 /* If it is not near, won't change */
416 return tri_req_active_turns(n_data, 5 /* WAG */,
417 context, other_player, req);
418 case VUT_CITYSTATUS:
419 if (CITYS_OWNED_BY_ORIGINAL != req->source.value.citystatus
420 && CITYS_TRANSFERRED != req->source.value.citystatus) {
421 return TRI_MAYBE;
422 }
423 fc__fallthrough;
424 case VUT_UTYPE:
425 case VUT_UTFLAG:
426 case VUT_UCLASS:
427 case VUT_UCFLAG:
428 /* FIXME: support converting siege machines (needs hard reqs checked) */
429 case VUT_ACTION:
430 case VUT_OTYPE:
431 case VUT_SPECIALIST:
432 case VUT_EXTRAFLAG:
433 case VUT_MINLATITUDE:
434 case VUT_MAXLATITUDE:
435 case VUT_AI_LEVEL:
436 case VUT_CITYTILE:
437 case VUT_STYLE:
438 case VUT_TOPO:
439 case VUT_WRAP:
440 case VUT_SERVERSETTING:
441 case VUT_NATION:
442 case VUT_NATIONGROUP:
443 case VUT_ADVANCE:
444 case VUT_TECHFLAG:
445 case VUT_GOVERNMENT:
446 case VUT_ACHIEVEMENT:
447 case VUT_IMPR_GENUS:
448 case VUT_IMPR_FLAG:
449 case VUT_PLAYER_FLAG:
450 case VUT_PLAYER_STATE:
451 case VUT_MINCULTURE:
452 case VUT_MINTECHS:
453 case VUT_MINCITIES:
454 case VUT_ORIGINAL_OWNER:
455 case VUT_ROADFLAG:
456 case VUT_TERRAIN:
457 case VUT_EXTRA:
458 case VUT_GOOD:
459 case VUT_TERRAINCLASS:
460 case VUT_TERRFLAG:
461 case VUT_TERRAINALTER:
462 case VUT_NONE:
463 return tri_req_active(context, other_player, req);
464 case VUT_COUNT:
465 /* Not implemented. */
466 break;
467 }
468 fc_assert(FALSE);
469
470 return TRI_NO;
471}
472
473/**********************************************************************/
480static bool
481action_may_happen_unit_on_city(const action_id wanted_action,
482 const struct unit *actor,
483 const struct city *pcity,
484 int turns)
485{
486 const struct player *target_player = city_owner(pcity),
487 *actor_player = unit_owner(actor);
488 const struct unit_type *utype = unit_type_get(actor);
489 const struct req_context target_ctx = {
490 .player = target_player,
491 .city = pcity,
492 .tile = city_tile(pcity)
493 }, actor_ctx = {
494 .player = actor_player,
495 .unit = actor,
496 .unittype = utype
497 };
498
499 if (!utype_can_do_action(utype, wanted_action)) {
500 return FALSE;
501 }
502 action_enabler_list_iterate(action_enablers_for_action(wanted_action),
503 enabler) {
504 /* We assume that we could build or move units into the city
505 * that are not present there yet */
506 if (TRI_NO != tri_reqs_cb_active(&actor_ctx, target_player,
507 &enabler->actor_reqs, NULL,
508 tactical_req_cb, NULL, turns)
509 &&
510 TRI_NO != tri_reqs_cb_active(&target_ctx, actor_player,
511 &enabler->target_reqs, NULL,
512 tactical_req_cb, NULL, turns)) {
513 return TRUE;
514 }
515 } action_enabler_list_iterate_end;
516
517 return FALSE;
518}
519
520/**********************************************************************/
523 static unsigned int assess_danger_unit(const struct city *pcity,
524 struct pf_reverse_map *pcity_map,
525 const struct unit *punit,
526 int *move_time)
527{
528 struct pf_position pos;
529 const struct unit_type *punittype = unit_type_get(punit);
530 const struct tile *ptile = city_tile(pcity);
531 const struct player *uowner = unit_owner(punit);
532 const struct unit *ferry;
533 unsigned int danger;
534 int amod = -99, dmod;
535 struct civ_map *nmap = &(wld.map);
536 bool attack_danger = FALSE;
537
538 *move_time = PF_IMPOSSIBLE_MC;
539
540 if ((utype_can_do_action_result(punittype, ACTRES_PARADROP)
541 || utype_can_do_action_result(punittype, ACTRES_PARADROP_CONQUER))
542 && 0 < punittype->paratroopers_range) {
543 *move_time = (real_map_distance(ptile, unit_tile(punit))
544 / punittype->paratroopers_range);
545 }
546
547 if (pf_reverse_map_unit_position(pcity_map, punit, &pos)
548 && (PF_IMPOSSIBLE_MC == *move_time
549 || *move_time > pos.turn)) {
550 *move_time = pos.turn;
551 }
552
553 if (unit_transported(punit)
554 && (ferry = unit_transport_get(punit))
555 && pf_reverse_map_unit_position(pcity_map, ferry, &pos)) {
556 if ((PF_IMPOSSIBLE_MC == *move_time
557 || *move_time > pos.turn)) {
558 *move_time = pos.turn;
559 if (!can_attack_from_non_native(punittype)) {
560 (*move_time)++;
561 }
562 }
563 }
564
565 if (PF_IMPOSSIBLE_MC == *move_time) {
566 return 0;
567 }
568 if (!is_native_tile(punittype, ptile)
569 && !can_attack_non_native(punittype)) {
570 return 0;
571 }
572 if (!is_native_near_tile(nmap, unit_class_get(punit), ptile)) {
573 return 0;
574 }
575
576 /* Find the worst attack action to expect */
577 action_by_result_iterate(paction, ACTRES_ATTACK) {
578 /* Is it possible that punit will do action id to the city? */
579 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
580
581 if (action_may_happen_unit_on_city(action_id(paction), punit, pcity, *move_time)) {
582 int b;
583
584 attack_danger = TRUE;
585
586 b = get_unittype_bonus(uowner, ptile, punittype, paction, EFT_ATTACK_BONUS);
587 if (b > amod) {
588 amod = b;
589 }
590 }
591 } action_by_result_iterate_end;
592
593 /* FIXME: it's a dummy support for anti-bombard defense just to do something against
594 * approaching bombarders. Some better logic is needed, see OSDN#41778 */
595 if (!attack_danger) {
596 action_by_result_iterate(paction, ACTRES_BOMBARD) {
597 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
598
599 if (action_may_happen_unit_on_city(action_id(paction), punit, pcity,
600 *move_time)) {
601 int b;
602
603 attack_danger = TRUE;
604
605 b = get_unittype_bonus(uowner, ptile, punittype, paction, EFT_ATTACK_BONUS);
606 if (b > amod) {
607 amod = b;
608 }
609 }
610 } action_by_result_iterate_end;
611 /* Here something should be done cuz the modifier affects
612 * more than one unit but not their full hp, but is not done yet...*/
613 }
614 if (!attack_danger) {
615 /* If the unit is dangerous, it's not about its combat strength */
616 return 0;
617 }
618
619 danger = adv_unit_att_rating(punit);
620 dmod = 100 + get_unittype_bonus(city_owner(pcity), ptile,
621 punittype, NULL, EFT_DEFEND_BONUS);
622 return danger * (amod + 100) / MAX(dmod, 1);
623}
624
625/**********************************************************************/
630 void dai_assess_danger_player(struct ai_type *ait, struct player *pplayer,
631 const struct civ_map *dmap)
632{
633 /* Do nothing if game is not running */
634 if (S_S_RUNNING == server_state()) {
635 city_list_iterate(pplayer->cities, pcity) {
636 (void) assess_danger(ait, pcity, dmap, NULL);
637 } city_list_iterate_end;
638 }
639}
640
641/**********************************************************************/
660 static void dai_reevaluate_building(struct city *pcity, adv_want *value,
661 unsigned int urgency, unsigned int danger,
662 int defense)
663{
664 if (*value == 0 || danger <= 0) {
665 return;
666 }
667
668 *value = MAX(*value, 100 + urgency); /* default */
669
670 if (urgency > 0 && danger > defense * 2) {
671 *value += 100;
672 } else if (defense != 0 && danger > defense) {
673 *value = MAX(danger * 100 / defense, *value);
674 }
675}
676
677/**********************************************************************/
695 static unsigned int assess_danger(struct ai_type *ait, struct city *pcity,
696 const struct civ_map *dmap,
697 player_unit_list_getter ul_cb)
698{
699 struct player *pplayer = city_owner(pcity);
700 struct tile *ptile = city_tile(pcity);
701 struct ai_city *city_data = def_ai_city_data(pcity, ait);
702 /* How much such danger there is that building would help against. */
703 unsigned int danger_reduced[B_LAST];
704 int i;
705 int defender;
706 unsigned int urgency = 0;
707 int defense;
708 int total_danger = 0;
709
710 /* TODO: Presumably most, or even all, of these arrays
711 * could be of size game.control.num_unit_types instead
712 * of full U_LAST */
713 int defense_bonuses_pct[U_LAST];
714 bool defender_type_handled[U_LAST];
715 int best_non_scramble[U_LAST];
716 bool sth_does_not_scramble = FALSE;
717 int city_def_against[U_LAST];
718 int assess_turns;
719 bool omnimap;
720
721 TIMING_LOG(AIT_DANGER, TIMER_START);
722
723 /* Initialize data. */
724 memset(&danger_reduced, 0, sizeof(danger_reduced));
725 if (has_handicap(pplayer, H_DANGER)) {
726 /* Always thinks that city is in grave danger */
727 city_data->grave_danger = 1;
728 } else {
729 city_data->grave_danger = 0;
730 }
731 city_data->diplomat_threat = FALSE;
732 city_data->has_diplomat = FALSE;
733
734 unit_type_iterate(utype) {
735 int idx = utype_index(utype);
736
737 defense_bonuses_pct[idx] = 0;
738 defender_type_handled[idx] = FALSE;
739 best_non_scramble[idx] = -1;
740 /* FIXME: cache it somewhere? */
741 city_def_against[idx]
742 = 100 + get_unittype_bonus(pplayer, ptile, utype, NULL,
743 EFT_DEFEND_BONUS);
744 city_def_against[idx] = MAX(city_def_against[idx], 1);
745 } unit_type_iterate_end;
746
747 /* What flag-specific bonuses do our units have. */
748 /* We value them less than general defense increment */
749 unit_list_iterate(ptile->units, punit) {
750 const struct unit_type *def = unit_type_get(punit);
751
752 if (unit_has_type_flag(punit, UTYF_DIPLOMAT)) {
753 city_data->has_diplomat = TRUE;
754 }
755 if (!defender_type_handled[utype_index(def)]) {
756 /* This is first defender of this type. Check defender type
757 * specific bonuses. */
758
759 /* Skip defenders that have no bonuses at all. Acceptable
760 * side-effect is that we can't consider negative bonuses at
761 * all ("No bonuses" should be better than "negative bonus") */
762 if (def->cache.max_defense_mp_bonus_pct > 0) {
763 unit_type_iterate(utype) {
764 int idx = utype_index(utype);
765 int coeff = def->cache.scramble_coeff[idx];
766 int bonus;
767
768 /* FIXME: consider EFT_FORTIFY_DEFENSE_BONUS */
769 if (coeff) {
770 bonus = coeff / city_def_against[idx] - 100;
771 } else {
772 bonus = def->cache.defense_mp_bonuses_pct[idx];
773 }
774
775 if (bonus > defense_bonuses_pct[idx]) {
776 if (!coeff) {
777 best_non_scramble[idx] = bonus;
778 }
779 defense_bonuses_pct[idx] = bonus;
780 } else if (!coeff) {
781 best_non_scramble[idx] = MAX(best_non_scramble[idx], bonus);
782 }
783 } unit_type_iterate_end;
784 } else {
785 /* Just remember that such a unit exists and hope its bonuses are just 0 */
786 sth_does_not_scramble = TRUE;
787 }
788
789 defender_type_handled[utype_index(def)] = TRUE;
790 }
791 } unit_list_iterate_end;
792 if (sth_does_not_scramble || unit_list_size(ptile->units) <= 0) {
793 /* Scrambling units tend to be expensive. If we have a barenaked city, we'll
794 * need at least a cheap unit. If we have only scramblers,
795 * maybe it's OK. */
796 unit_type_iterate(scrambler_type) {
797 Unit_type_id id = utype_index(scrambler_type);
798
799 best_non_scramble[id] = MAX(best_non_scramble[id], 0);
800 } unit_type_iterate_end;
801 }
802
803 if (player_is_cpuhog(pplayer)) {
804 assess_turns = 6;
805 } else {
806 assess_turns = has_handicap(pplayer, H_ASSESS_DANGER_LIMITED) ? 2 : 3;
807 }
808
809 omnimap = !has_handicap(pplayer, H_MAP);
810
811 /* Check. */
812 players_iterate(aplayer) {
813 struct pf_reverse_map *pcity_map;
814 struct unit_list *units;
815
816 if (!adv_is_player_dangerous(pplayer, aplayer)) {
817 continue;
818 }
819 /* Note that we still consider the units of players we are not (yet)
820 * at war with. */
821
822 pcity_map = pf_reverse_map_new_for_city(pcity, aplayer, assess_turns,
823 omnimap, dmap);
824
825 if (ul_cb != NULL) {
826 units = ul_cb(aplayer);
827 } else {
828 units = aplayer->units;
829 }
830 unit_list_iterate(units, punit) {
831 int move_time;
832 unsigned int vulnerability;
833 int defbonus_pct;
834 const struct unit_type *utype = unit_type_get(punit);
835 struct unit_type_ai *utai = utype_ai_data(utype, ait);
836
837#ifdef FREECIV_WEB
838 /* freeciv-web ignores danger that is far in distance,
839 * no matter how quickly it would reach us; even if
840 * that's *immediately* over a road type that allows
841 * unlimited movement. */
842 int unit_distance = real_map_distance(ptile, unit_tile(punit));
843
844 if (unit_distance > ASSESS_DANGER_MAX_DISTANCE
845 || (has_handicap(pplayer, H_ASSESS_DANGER_LIMITED)
846 && unit_distance > AI_HANDICAP_DISTANCE_LIMIT)) {
847 /* Too far away. */
848 continue;
849 }
850#endif /* FREECIV_WEB */
851
852 if (!utai->carries_occupiers
853 && !utype_acts_hostile(utype)) {
854 /* Harmless unit. */
855 continue;
856 }
857
858 /* Defender unspecific vulnerability and potential move time */
859 vulnerability = assess_danger_unit(pcity, pcity_map,
860 punit, &move_time);
861
862 if (PF_IMPOSSIBLE_MC == move_time) {
863 continue;
864 }
865
866 if (unit_can_take_over(punit) || utai->carries_occupiers) {
867 /* Even if there is no attack strength,
868 * we need ANY protector for the city */
869 vulnerability = MAX(vulnerability, 1);
870 if (3 >= move_time) {
871 urgency++;
872 if (1 >= move_time) {
873 city_data->grave_danger++;
874 }
875 }
876 }
877
878 defbonus_pct = defense_bonuses_pct[utype_index(utype)];
879 if (defbonus_pct > 100) {
880 defbonus_pct = (defbonus_pct + 100) / 2;
881 }
882 /* Reduce vulnerability for specific bonuses we do have */
883 vulnerability = vulnerability * 100 / (defbonus_pct + 100);
884 /* Pass the order for a new defender type against it
885 * to the scientific advisor, urgency considered */
886 (void) dai_wants_defender_against(ait, pplayer, pcity, utype,
887 vulnerability / MAX(move_time, 1));
888
889 if (utype_acts_hostile(unit_type_get(punit)) && 2 >= move_time) {
890 city_data->diplomat_threat = TRUE;
891 }
892
893 vulnerability *= vulnerability; /* positive feedback */
894 if (1 < move_time) {
895 vulnerability /= move_time;
896 }
897
898 if (unit_can_do_action(punit, ACTION_NUKE)
899 || unit_can_do_action(punit, ACTION_NUKE_CITY)
900 || unit_can_do_action(punit, ACTION_NUKE_UNITS)) {
901 defender = dai_find_source_building(pcity, EFT_NUKE_PROOF, utype);
902 if (defender != B_LAST) {
903 danger_reduced[defender] += vulnerability / MAX(move_time, 1);
904 }
905 } else if (best_non_scramble[utype_index(utype)] >= 0) {
906 /* To consider building a defensive building,
907 * build first a defender that gets any profit of it */
908 defender = dai_find_source_building(pcity, EFT_DEFEND_BONUS, utype);
909 if (defender != B_LAST) {
910 int danred = vulnerability / MAX(move_time, 1);
911 /* Maybe we can build an improvement
912 * that gets normal defender over scrambling one?
913 * Effectively a sqrt-scale because we don't test how high
914 * the effect is. */
915 if (best_non_scramble[utype_index(utype)]
916 < defense_bonuses_pct[utype_index(utype)]) {
917 danred = danred * (100 + best_non_scramble[utype_index(utype)])
918 / (100 + defense_bonuses_pct[utype_index(utype)]);
919 }
920 danger_reduced[defender] += danred;
921 }
922 }
923
924 total_danger += vulnerability;
925 } unit_list_iterate_end;
926
927 pf_reverse_map_destroy(pcity_map);
928
929 } players_iterate_end;
930
931 if (total_danger) {
932 /* If any hostile player has any dangerous unit that can in any time
933 * reach the city, we consider building walls here, if none yet.
934 * FIXME: this value assumes that walls give x3 defense. */
935 city_data->wallvalue = 90;
936 } else {
937 /* No danger.
938 * This is half of the wallvalue of what danger 1 would produce. */
939 city_data->wallvalue = 5;
940 }
941
942 if (0 < city_data->grave_danger) {
943 /* really, REALLY urgent to defend */
944 urgency += 10 * city_data->grave_danger;
945 }
946
947 /* HACK: This needs changing if multiple improvements provide
948 * this effect. */
949 /* FIXME: Accept only buildings helping unit classes we actually use.
950 * Now we consider any land mover helper suitable. */
951 /* Sum of squared defense ratings */
952 defense = assess_defense_igwall(ait, pcity);
953
954 for (i = 0; i < B_LAST; i++) {
955 if (0 < danger_reduced[i]) {
956 dai_reevaluate_building(pcity, &pcity->server.adv->building_want[i],
957 urgency, danger_reduced[i], defense);
958 }
959 }
960
961 if (has_handicap(pplayer, H_DANGER) && 0 == total_danger) {
962 /* Has to have some danger
963 * Otherwise grave_danger will be ignored. */
964 city_data->danger = 1;
965 } else {
966 city_data->danger = total_danger;
967 }
968 city_data->urgency = urgency;
969
970 TIMING_LOG(AIT_DANGER, TIMER_STOP);
971
972 return urgency;
973}
974
975/**********************************************************************/
979 static adv_want dai_unit_defense_desirability(struct ai_type *ait,
980 const struct unit_type *punittype)
981{
982 adv_want desire = punittype->hp;
983 int attack = punittype->attack_strength;
984 int defense = punittype->defense_strength;
985 int maxbonus_pct = 0;
986 int fp = punittype->firepower;
987
988 /* Sea and helicopters often have their firepower set to low firepower when
989 * defending. We can't have such units as defenders. */
990 if (utype_has_flag(punittype, UTYF_BADCITYDEFENDER)) {
991 fp = MIN(fp, game.info.low_firepower_pearl_harbour);
992 }
993 if (((struct unit_type_ai *)utype_ai_data(punittype, ait))->low_firepower) {
994 fp = MIN(fp, game.info.low_firepower_combat_bonus);
995 }
996 desire *= fp;
997 desire *= defense;
998 desire += punittype->move_rate / SINGLE_MOVE;
999 desire += attack;
1000
1001 maxbonus_pct = punittype->cache.max_defense_mp_bonus_pct;
1002 if (maxbonus_pct > 100) {
1003 maxbonus_pct = (maxbonus_pct + 100) / 2;
1004 }
1005 desire += desire * maxbonus_pct / 100;
1006 if (utype_has_flag(punittype, UTYF_GAMELOSS)) {
1007 desire /= 10; /* But might actually be worth it */
1008 }
1009
1010 return desire;
1011}
1012
1013/**********************************************************************/
1016 static adv_want dai_unit_attack_desirability(struct ai_type *ait,
1017 const struct unit_type *punittype)
1018{
1019 adv_want desire = punittype->hp;
1020 int attack = punittype->attack_strength;
1021 int defense = punittype->defense_strength;
1022
1023 desire *= punittype->move_rate;
1024 desire *= punittype->firepower;
1025 desire *= attack;
1026 desire += defense;
1027 if (utype_has_flag(punittype, UTYF_IGTER)) {
1028 desire += desire / 2;
1029 }
1030 if (utype_has_flag(punittype, UTYF_GAMELOSS)) {
1031 desire /= 10; /* But might actually be worth it */
1032 }
1033 if (utype_has_flag(punittype, UTYF_CITYBUSTER)) {
1034 desire += desire / 2;
1035 }
1036 if (can_attack_from_non_native(punittype)) {
1037 desire += desire / 4;
1038 }
1039 if (punittype->adv.igwall) {
1040 desire += desire / 4;
1041 }
1042
1043 return desire;
1044}
1045
1046/**********************************************************************/
1051 bool dai_process_defender_want(struct ai_type *ait, struct player *pplayer,
1052 struct city *pcity, unsigned int danger,
1053 struct adv_choice *choice, adv_want extra_want)
1054{
1055 const struct research *presearch = research_get(pplayer);
1056 /* FIXME: We check if the city has *some* defensive structure,
1057 * but not whether the city has a defensive structure against
1058 * any specific attacker. The actual danger may not be mitigated
1059 * by the defense selected... */
1060 bool walls = city_got_defense_effect(pcity, NULL);
1061 /* Technologies we would like to have. */
1062 adv_want tech_desire[U_LAST];
1063 /* Our favourite unit. */
1064 adv_want best = -1;
1065 struct unit_type *best_unit_type = NULL;
1066 int best_unit_cost = 1;
1067 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1068 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1069 adv_want total_want = danger + extra_want;
1070
1071 memset(tech_desire, 0, sizeof(tech_desire));
1072
1073 simple_ai_unit_type_iterate(punittype) {
1074 adv_want desire; /* How much we want the unit? */
1075
1076 /* Only consider proper defenders - otherwise waste CPU and
1077 * bump tech want needlessly. */
1078 if (!utype_has_role(punittype, L_DEFEND_GOOD)
1079 && !utype_has_role(punittype, L_DEFEND_OK)) {
1080 continue;
1081 }
1082
1083 desire = dai_unit_defense_desirability(ait, punittype);
1084
1085 if (!utype_has_role(punittype, L_DEFEND_GOOD)) {
1086 desire /= 2; /* Not good, just ok */
1087 }
1088
1089 if (utype_has_flag(punittype, UTYF_FIELDUNIT)) {
1090 /* Causes unhappiness even when in defense, so not a good
1091 * idea for a defender, unless it is _really_ good.
1092 * Downright counter productive, if we want unit just for
1093 * maintaining peace. */
1094 if (danger == 0) {
1095 desire = -50;
1096 } else {
1097 desire /= 2;
1098 }
1099 }
1100
1101 if (desire > 0) {
1102 desire /= POWER_DIVIDER / 2; /* Good enough, no rounding errors. */
1103 desire *= desire;
1104
1105 if (can_city_build_unit_now(pcity, punittype)) {
1106 /* We can build the unit now... */
1107
1108 int build_cost = utype_build_shield_cost(pcity, NULL, punittype);
1109 int limit_cost = pcity->shield_stock + 40;
1110
1111 if (walls && !utype_has_flag(punittype, UTYF_BADCITYDEFENDER)) {
1112 desire *= city_data->wallvalue;
1113 /* TODO: More use of POWER_FACTOR ! */
1114 desire /= POWER_FACTOR;
1115 }
1116
1117 if ((best_unit_cost > limit_cost
1118 && build_cost < best_unit_cost)
1119 || ((desire > best
1120 || (ADV_WANTS_EQ(desire, best)
1121 && build_cost <= best_unit_cost))
1122 && (best_unit_type == NULL
1123 /* In case all units are more expensive than limit_cost */
1124 || limit_cost <= pcity->shield_stock + 40))) {
1125 best = desire;
1126 best_unit_type = punittype;
1127 best_unit_cost = build_cost;
1128 }
1129 } else if (can_city_build_unit_later(pcity, punittype)) {
1130 /* We first need to develop the tech required by the unit... */
1131
1132 /* Cost (shield equivalent) of gaining these techs. */
1133 /* FIXME? Katvrr advises that this should be weighted more heavily in
1134 * big danger. */
1135 int tech_cost = 0;
1136
1137 unit_tech_reqs_iterate(punittype, padv) {
1138 tech_cost = research_goal_bulbs_required(presearch,
1139 advance_number(padv));
1140 } unit_tech_reqs_iterate_end;
1141
1142 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1143
1144 /* Contrary to the above, we don't care if walls are actually built
1145 * - we're looking into the future now. */
1146 if (!utype_has_flag(punittype, UTYF_BADCITYDEFENDER)) {
1147 desire *= city_data->wallvalue;
1148 desire /= POWER_FACTOR;
1149 }
1150
1151 /* Yes, there's some similarity with kill_desire(). */
1152 /* TODO: Explain what shield cost has to do with tech want. */
1153 tech_desire[utype_index(punittype)] =
1154 (desire * total_want
1155 / (utype_build_shield_cost(pcity, NULL, punittype) + tech_cost));
1156 }
1157 }
1158 } simple_ai_unit_type_iterate_end;
1159
1160 if (best == -1) {
1161 CITY_LOG(LOG_DEBUG, pcity, "Ooops - we cannot build any defender!");
1162 }
1163
1164 if (best_unit_type != NULL) {
1165 if (!walls && !utype_has_flag(best_unit_type, UTYF_BADCITYDEFENDER)) {
1166 best *= city_data->wallvalue;
1167 best /= POWER_FACTOR;
1168 }
1169 } else {
1170 best_unit_cost = 100; /* Building impossible is considered costly.
1171 * This should increase want for tech providing
1172 * first defender type. */
1173 }
1174
1175 if (best <= 0) {
1176 best = 1; /* Avoid division by zero below. */
1177 }
1178
1179 /* Update tech_want for appropriate techs for units we want to build. */
1180 simple_ai_unit_type_iterate(punittype) {
1181 if (tech_desire[utype_index(punittype)] > 0) {
1182 /* TODO: Document or fix the algorithm below. I have no idea why
1183 * it is written this way, and the results seem strange to me. - Per */
1184 adv_want desire = tech_desire[utype_index(punittype)] * best_unit_cost / best;
1185
1186 unit_tech_reqs_iterate(punittype, padv) {
1187 plr_data->tech_want[advance_index(padv)]
1188 += desire;
1189 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1190 "+ " ADV_WANT_PRINTF " for %s to defend %s",
1191 desire,
1192 utype_rule_name(punittype),
1193 city_name_get(pcity));
1194 } unit_tech_reqs_iterate_end;
1195 }
1196 } simple_ai_unit_type_iterate_end;
1197
1198 if (!best_unit_type) {
1199 return FALSE;
1200 }
1201
1202 choice->value.utype = best_unit_type;
1203 choice->want = danger; /* FIXME: Not 'total_want' because of the way callers
1204 * are constructed. They may overwrite this value,
1205 * and then the value will NOT contain 'extra_want'.
1206 * Later we may add 'extra_want', and don't want it
1207 * already included in case this was NOT overwritten. */
1208 choice->type = CT_DEFENDER;
1209
1210 return TRUE;
1211}
1212
1213/**********************************************************************/
1230 static void process_attacker_want(struct ai_type *ait,
1231 struct city *pcity,
1232 adv_want value,
1233 const struct unit_type *victim_unit_type,
1234 struct player *victim_player,
1235 int veteran, struct tile *ptile,
1236 struct adv_choice *best_choice,
1237 struct pf_map *ferry_map,
1238 struct unit *boat,
1239 const struct unit_type *boattype)
1240{
1241 struct player *pplayer = city_owner(pcity);
1242 const struct research *presearch = research_get(pplayer);
1243 /* The enemy city. acity == NULL means stray enemy unit */
1244 struct city *acity = tile_city(ptile);
1245 struct pf_parameter parameter;
1246 struct pf_map *pfm;
1247 struct pf_position pos;
1248 const struct unit_type *orig_utype = best_choice->value.utype;
1249 int victim_count = 1;
1250 int needferry = 0;
1251 bool unhap = dai_assess_military_unhappiness(pcity);
1252 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1253 const struct civ_map *nmap = &(wld.map);
1254
1255 /* Has to be initialized to make gcc happy */
1256 struct ai_city *acity_data = NULL;
1257
1258 if (acity != NULL) {
1259 acity_data = def_ai_city_data(acity, ait);
1260 }
1261
1262 if (utype_class(orig_utype)->adv.sea_move == MOVE_NONE
1263 && !boat && boattype != NULL) {
1264 /* Cost of ferry */
1265 needferry = utype_build_shield_cost(pcity, NULL, boattype);
1266 }
1267
1268 if (!is_stack_vulnerable(ptile)) {
1269 /* If it is a city, a fortress or an air base,
1270 * we may have to whack it many times */
1271 victim_count += unit_list_size(ptile->units);
1272 }
1273
1274 simple_ai_unit_type_iterate(punittype) {
1275 if (dai_can_unit_type_follow_unit_type(punittype, orig_utype, ait)
1276 && is_native_near_tile(&(wld.map), utype_class(punittype), ptile)
1277 && (U_NOT_OBSOLETED == punittype->obsoleted_by
1278 || !can_city_build_unit_direct(pcity, punittype->obsoleted_by))
1279 && punittype->attack_strength > 0 /* or we'll get SIGFPE */) {
1280 /* Values to be computed */
1281 adv_want desire;
1282 adv_want want;
1283 int move_time;
1284 int vuln;
1285 int veteran_level
1286 = get_target_bonus_effects(NULL,
1287 &(const struct req_context) {
1288 .player = pplayer,
1289 .city = pcity,
1290 .tile = city_tile(pcity),
1291 .unittype = punittype,
1292 },
1293 NULL,
1294 EFT_VETERAN_BUILD);
1295 /* Cost (shield equivalent) of gaining these techs. */
1296 /* FIXME? Katvrr advises that this should be weighted more heavily in big
1297 * danger. */
1298 int tech_cost = 0;
1299 int bcost_balanced = build_cost_balanced(punittype);
1300 /* See description of kill_desire() for info about this variables. */
1301 int bcost = utype_build_shield_cost(pcity, NULL, punittype);
1302 int attack = adv_unittype_att_rating(punittype, veteran_level,
1303 SINGLE_MOVE,
1304 punittype->hp);
1305 int tech_dist = 0;
1306
1307 unit_tech_reqs_iterate(punittype, padv) {
1308 Tech_type_id tech_req = advance_number(padv);
1309
1310 tech_cost += research_goal_bulbs_required(presearch, tech_req);
1311 if (tech_dist == 0) {
1312 tech_dist = research_goal_unknown_techs(presearch, tech_req);
1313 }
1314 } unit_tech_reqs_iterate_end;
1315
1316 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1317
1318 /* Take into account reinforcements strength */
1319 if (acity) {
1320 attack += acity_data->attack;
1321 }
1322
1323 if (attack == 0) {
1324 /* Yes, it can happen that a military unit has attack = 1,
1325 * for example militia with HP = 1 (in civ1 ruleset). */
1326 continue;
1327 }
1328
1329 attack *= attack;
1330
1331 pft_fill_utype_parameter(&parameter, nmap, punittype, city_tile(pcity),
1332 pplayer);
1333 parameter.omniscience = !has_handicap(pplayer, H_MAP);
1334 pfm = pf_map_new(&parameter);
1335
1336 /* Set the move_time appropriately. */
1337 move_time = -1;
1338 if (NULL != ferry_map) {
1339 struct tile *dest_tile;
1340
1341 if (find_beachhead(pplayer, ferry_map, ptile, punittype,
1342 boattype, &dest_tile, NULL)
1343 && pf_map_position(ferry_map, dest_tile, &pos)) {
1344 move_time = pos.turn;
1345 dest_tile = pf_map_parameter(ferry_map)->start_tile;
1346 pf_map_tiles_iterate(pfm, atile, FALSE) {
1347 if (atile == dest_tile) {
1348 pf_map_iter_position(pfm, &pos);
1349 move_time += pos.turn;
1350 break;
1351 } else if (atile == ptile) {
1352 /* Reaching directly seems better. */
1353 pf_map_iter_position(pfm, &pos);
1354 move_time = pos.turn;
1355 break;
1356 }
1357 } pf_map_tiles_iterate_end;
1358 }
1359 }
1360
1361 if (-1 == move_time) {
1362 if (pf_map_position(pfm, ptile, &pos)) {
1363 move_time = pos.turn;
1364 } else {
1365 pf_map_destroy(pfm);
1366 continue;
1367 }
1368 }
1369 pf_map_destroy(pfm);
1370
1371 /* Estimate strength of the enemy. */
1372
1373 if (victim_unit_type) {
1374 vuln = unittype_def_rating_squared(punittype, victim_unit_type,
1375 victim_player,
1376 ptile, FALSE, veteran);
1377 } else {
1378 vuln = 0;
1379 }
1380
1381 /* Not bothering to s/!vuln/!pdef/ here for the time being. -- Syela
1382 * (this is noted elsewhere as terrible bug making warships yoyoing)
1383 * as the warships will go to enemy cities hoping that the enemy builds
1384 * something for them to kill. */
1385 if (vuln == 0
1386 && (utype_class(punittype)->adv.land_move == MOVE_NONE
1387 || 0 < utype_fuel(punittype))) {
1388 desire = 0;
1389
1390 } else {
1391 if (acity
1392 && utype_can_take_over(punittype)
1393 && acity_data->invasion.attack > 0
1394 && acity_data->invasion.occupy == 0) {
1395 int owner_size = city_list_size(city_owner(acity)->cities);
1396 float finishing_factor = 1;
1397
1398 if (owner_size <= FINISH_HIM_CITY_COUNT) {
1399 finishing_factor = (2 - (float)owner_size / FINISH_HIM_CITY_COUNT);
1400 }
1401 desire = CITY_CONQUEST_WORTH(acity, acity_data) * 10 * finishing_factor;
1402 } else {
1403 desire = 0;
1404 }
1405
1406 if (!acity) {
1407 desire = kill_desire(value, attack, bcost, vuln, victim_count);
1408 } else {
1409 adv_want kd;
1410 int city_attack = acity_data->attack * acity_data->attack;
1411
1412 /* See aiunit.c:find_something_to_kill() for comments. */
1413 kd = kill_desire(value, attack,
1414 (bcost + acity_data->bcost), vuln,
1415 victim_count);
1416
1417 if (value * city_attack > acity_data->bcost * vuln) {
1418 kd -= kill_desire(value, city_attack,
1419 acity_data->bcost, vuln,
1420 victim_count);
1421 }
1422
1423 desire = MAX(desire, kd);
1424 }
1425 }
1426
1427 desire -= tech_cost * SHIELD_WEIGHTING;
1428 /* We can be possibly making some people of our homecity unhappy - then
1429 * we don't want to travel too far away to our victims. */
1430 /* TODO: Unify the 'unhap' dependency to some common function. */
1431 desire -= move_time * (unhap ? SHIELD_WEIGHTING + 2 * TRADE_WEIGHTING
1432 : SHIELD_WEIGHTING);
1433
1434 want = military_amortize(pplayer, pcity, desire, MAX(1, move_time),
1435 bcost_balanced + needferry);
1436
1437 if (want > 0) {
1438 if (tech_dist > 0) {
1439 /* This is a future unit, tell the scientist how much we need it */
1440 unit_tech_reqs_iterate(punittype, padv) {
1441 plr_data->tech_want[advance_index(padv)]
1442 += want;
1443 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1444 "+ " ADV_WANT_PRINTF " for %s vs %s(%d,%d)",
1445 want,
1446 utype_rule_name(punittype),
1447 (acity ? city_name_get(acity) : utype_rule_name(victim_unit_type)),
1448 TILE_XY(ptile));
1449 } unit_tech_reqs_iterate_end;
1450 } else if (want > best_choice->want) {
1451 const struct impr_type *impr_req;
1452
1453 if (can_city_build_unit_now(pcity, punittype)) {
1454 /* This is a real unit and we really want it */
1455
1456 CITY_LOG(LOG_DEBUG, pcity, "overriding %s(" ADV_WANT_PRINTF
1457 ") with %s(" ADV_WANT_PRINTF ")"
1458 " [attack=%d,value=" ADV_WANT_PRINTF
1459 ",move_time=%d,vuln=%d,bcost=%d]",
1460 utype_rule_name(best_choice->value.utype),
1461 best_choice->want,
1462 utype_rule_name(punittype),
1463 want,
1464 attack, value, move_time, vuln, bcost);
1465
1466 best_choice->value.utype = punittype;
1467 best_choice->want = want;
1468 best_choice->type = CT_ATTACKER;
1469 } else if (!((impr_req = utype_needs_improvement(punittype,
1470 pcity)))) {
1471 CITY_LOG(LOG_DEBUG, pcity, "cannot build unit %s",
1472 utype_rule_name(punittype));
1473 } else if (can_city_build_improvement_now(pcity, impr_req)) {
1474 /* Building this unit requires a specific type of improvement.
1475 * So we build this improvement instead. This may not be the
1476 * best behavior. */
1477 CITY_LOG(LOG_DEBUG, pcity, "building %s to build unit %s",
1478 improvement_rule_name(impr_req),
1479 utype_rule_name(punittype));
1480 best_choice->value.building = impr_req;
1481 best_choice->want = want;
1482 best_choice->type = CT_BUILDING;
1483 } else {
1484 /* This should never happen? */
1485 CITY_LOG(LOG_DEBUG, pcity, "cannot build %s or unit %s",
1486 improvement_rule_name(impr_req),
1487 utype_rule_name(punittype));
1488 }
1489 }
1490 }
1491 }
1492 } simple_ai_unit_type_iterate_end;
1493}
1494
1495/**********************************************************************/
1506 static struct adv_choice *kill_something_with(struct ai_type *ait,
1507 struct player *pplayer,
1508 struct city *pcity, struct unit *myunit,
1509 struct adv_choice *choice)
1510{
1511 /* Our attack rating (with reinforcements) */
1512 int attack;
1513 /* Benefit from fighting the target */
1514 adv_want benefit;
1515 /* Defender of the target city/tile */
1516 struct unit *pdef;
1517 const struct unit_type *def_type;
1518 struct player *def_owner;
1519 int def_vet; /* Is the defender veteran? */
1520 /* Target coordinates */
1521 struct tile *ptile;
1522 /* Our transport */
1523 struct unit *ferryboat;
1524 /* Our target */
1525 struct city *acity;
1526 /* Type of the boat (real or a future one) */
1527 const struct unit_type *boattype;
1528 struct pf_map *ferry_map = NULL;
1529 int move_time;
1530 struct adv_choice *best_choice;
1531 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1532 struct ai_city *acity_data;
1533 struct civ_map *nmap = &(wld.map);
1534
1535 best_choice = adv_new_choice();
1536 best_choice->value.utype = unit_type_get(myunit);
1537 best_choice->type = CT_ATTACKER;
1538 adv_choice_set_use(best_choice, "attacker");
1539
1540 fc_assert_ret_val(!is_special_unit(myunit)
1541 && !utype_fuel(unit_type_get(myunit)), choice);
1542
1543 if (city_data->danger != 0 && assess_defense(ait, pcity) == 0) {
1544 /* Defense comes first! */
1545 goto cleanup;
1546 }
1547
1548 best_choice->want = find_something_to_kill(ait, pplayer, myunit, &ptile, NULL,
1549 &ferry_map, &ferryboat,
1550 &boattype, &move_time);
1551 if (NULL == ptile
1552 || ptile == unit_tile(myunit)
1553 || !can_unit_attack_tile(myunit, NULL, ptile)) {
1554 goto cleanup;
1555 }
1556
1557 acity = tile_city(ptile);
1558
1559 if (myunit->id != 0) {
1560 log_error("%s(): non-virtual unit!", __FUNCTION__);
1561 goto cleanup;
1562 }
1563
1564 attack = adv_unit_att_rating(myunit);
1565 if (acity) {
1566 acity_data = def_ai_city_data(acity, ait);
1567 attack += acity_data->attack;
1568 }
1569 attack *= attack;
1570
1571 if (NULL != acity) {
1572 /* Rating of enemy defender */
1573 int vulnerability;
1574
1575 if (!POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, city_owner(acity))) {
1576 /* Not a valid target */
1577 goto cleanup;
1578 }
1579
1580 def_type = dai_choose_defender_versus(acity, myunit);
1581 def_owner = city_owner(acity);
1582 if (1 < move_time && def_type) {
1583 def_vet = city_production_unit_veteran_level(acity, def_type);
1584 vulnerability = unittype_def_rating_squared(unit_type_get(myunit), def_type,
1585 city_owner(acity), ptile,
1586 FALSE, def_vet);
1587 benefit = utype_build_shield_cost_base(def_type);
1588 } else {
1589 vulnerability = 0;
1590 benefit = 0;
1591 def_vet = 0;
1592 }
1593
1594 pdef = get_defender(nmap, myunit, ptile, NULL);
1595 if (pdef) {
1596 int m = unittype_def_rating_squared(unit_type_get(myunit), unit_type_get(pdef),
1597 city_owner(acity), ptile, FALSE,
1598 pdef->veteran);
1599 if (vulnerability < m) {
1600 benefit = unit_build_shield_cost_base(pdef);
1601 def_vet = pdef->veteran;
1602 def_type = unit_type_get(pdef);
1603 def_owner = unit_owner(pdef);
1604 }
1605 }
1606 if (unit_can_take_over(myunit) || acity_data->invasion.occupy > 0) {
1607 /* Bonus for getting the city */
1608 int owner_size = city_list_size(city_owner(acity)->cities);
1609 float finishing_factor = 1;
1610
1611 if (owner_size <= FINISH_HIM_CITY_COUNT) {
1612 finishing_factor = (2 - (float)owner_size / FINISH_HIM_CITY_COUNT);
1613 }
1614 benefit += CITY_CONQUEST_WORTH(acity, acity_data) * finishing_factor / 3;
1615 }
1616
1617 /* end dealing with cities */
1618 } else {
1619
1620 if (NULL != ferry_map) {
1621 pf_map_destroy(ferry_map);
1622 ferry_map = NULL;
1623 }
1624
1625 pdef = get_defender(nmap, myunit, ptile, NULL);
1626 if (!pdef) {
1627 /* Nobody to attack! */
1628 goto cleanup;
1629 }
1630
1631 benefit = unit_build_shield_cost_base(pdef);
1632
1633 def_type = unit_type_get(pdef);
1634 def_vet = pdef->veteran;
1635 def_owner = unit_owner(pdef);
1636 /* end dealing with units */
1637 }
1638
1639 if (NULL == ferry_map) {
1640 process_attacker_want(ait, pcity, benefit, def_type, def_owner,
1641 def_vet, ptile,
1642 best_choice, NULL, NULL, NULL);
1643 } else {
1644 /* Attract a boat to our city or retain the one that's already here */
1645 fc_assert_ret_val(unit_class_get(myunit)->adv.sea_move != MOVE_FULL, choice);
1646 best_choice->need_boat = TRUE;
1647 process_attacker_want(ait, pcity, benefit, def_type, def_owner,
1648 def_vet, ptile,
1649 best_choice, ferry_map, ferryboat, boattype);
1650 }
1651
1652 if (best_choice->want > choice->want) {
1653 /* We want attacker more than what we have selected before */
1654 adv_free_choice(choice);
1655 choice = best_choice;
1656 CITY_LOG(LOG_DEBUG, pcity, "kill_something_with()"
1657 " %s has chosen attacker, %s, want=" ADV_WANT_PRINTF,
1658 city_name_get(pcity),
1659 utype_rule_name(best_choice->value.utype),
1660 best_choice->want);
1661
1662 if (NULL != ferry_map && !ferryboat) { /* need a new ferry */
1663 /* We might need a new boat even if there are boats free,
1664 * if they are blockaded or in inland seas*/
1665 fc_assert_ret_val(unit_class_get(myunit)->adv.sea_move != MOVE_FULL, choice);
1666 if (dai_choose_role_unit(ait, pplayer, pcity, choice, CT_ATTACKER,
1667 L_FERRYBOAT, choice->want, TRUE)
1668 && dai_is_ferry_type(choice->value.utype, ait)) {
1669#ifdef FREECIV_DEBUG
1670 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1671
1672 log_debug("kill_something_with() %s has chosen attacker ferry, "
1673 "%s, want=" ADV_WANT_PRINTF ", %d of %d free",
1674 city_name_get(pcity),
1675 utype_rule_name(choice->value.utype),
1676 choice->want,
1677 ai->stats.available_boats, ai->stats.boats);
1678#endif /* FREECIV_DEBUG */
1679
1680 adv_choice_set_use(choice, "attacker ferry");
1681 } /* else can not build ferries yet */
1682 }
1683 }
1684
1685 cleanup:
1686 if (best_choice != choice) {
1687 /* It was not taken to use.
1688 * This hackery needed since 'goto cleanup:' might skip
1689 * sensible points to do adv_free_choice(). */
1690 adv_free_choice(best_choice);
1691 }
1692 if (NULL != ferry_map) {
1693 pf_map_destroy(ferry_map);
1694 }
1695
1696 return choice;
1697}
1698
1699/**********************************************************************/
1705 static void dai_unit_consider_bodyguard(struct ai_type *ait,
1706 struct city *pcity,
1707 struct unit_type *punittype,
1708 struct adv_choice *choice)
1709{
1710 if (choice->want < DAI_WANT_MILITARY_EMERGENCY) {
1711 struct player *pplayer = city_owner(pcity);
1712 struct unit *aunit = NULL;
1713 struct city *acity = NULL;
1714 struct unit *virtualunit
1715 = unit_virtual_create(pplayer, pcity, punittype,
1716 city_production_unit_veteran_level(pcity,
1717 punittype));
1718 const adv_want want = look_for_charge(ait, pplayer, virtualunit,
1719 &aunit, &acity);
1720
1721 if (want > choice->want) {
1722 choice->want = want;
1723 choice->value.utype = punittype;
1724 choice->type = CT_DEFENDER;
1725 adv_choice_set_use(choice, "bodyguard");
1726 }
1727
1728 unit_virtual_destroy(virtualunit);
1729 }
1730}
1731
1732/**********************************************************************/
1740 static void adjust_ai_unit_choice(struct city *pcity,
1741 struct adv_choice *choice)
1742{
1743 Impr_type_id id;
1744
1745 /* Sanity */
1746 if (!is_unit_choice_type(choice->type)
1747 || utype_has_flag(choice->value.utype, UTYF_CIVILIAN)
1748 || city_production_unit_veteran_level(pcity, choice->value.utype)) {
1749 return;
1750 }
1751
1752 /* N.B.: have to check that we haven't already built the building --mck */
1753 if ((id = dai_find_source_building(pcity, EFT_VETERAN_BUILD,
1754 choice->value.utype)) != B_LAST
1755 && !city_has_building(pcity, improvement_by_number(id))) {
1756 choice->value.building = improvement_by_number(id);
1757 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER,
1758 city_owner(pcity))
1759 / TRAIT_DEFAULT_VALUE / 2));
1760 choice->type = CT_BUILDING;
1761 adv_choice_set_use(choice, "veterancy building");
1762 }
1763}
1764
1765/**********************************************************************/
1770 struct adv_choice *military_advisor_choose_build(struct ai_type *ait,
1771 struct player *pplayer,
1772 struct city *pcity,
1773 const struct civ_map *mamap,
1774 player_unit_list_getter ul_cb)
1775{
1776 struct adv_data *ai = adv_data_get(pplayer, NULL);
1777 struct unit_type *punittype;
1778 unsigned int our_def, urgency;
1779 struct tile *ptile = pcity->tile;
1780 struct unit *virtualunit;
1781 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1782 adv_want martial_value = 0;
1783 bool martial_need = FALSE;
1784 struct adv_choice *choice = adv_new_choice();
1785 bool allow_gold_upkeep;
1786
1787 urgency = assess_danger(ait, pcity, mamap, ul_cb);
1788 /* Changing to quadratic to stop AI from building piles
1789 * of small units -- Syela */
1790 /* It has to be AFTER assess_danger thanks to wallvalue. */
1791 our_def = assess_defense_quadratic(ait, pcity);
1792
1793 dai_choose_diplomat_defensive(ait, pplayer, pcity, choice, our_def);
1794
1795 if (pcity->feel[CITIZEN_UNHAPPY][FEELING_NATIONALITY]
1796 + pcity->feel[CITIZEN_ANGRY][FEELING_NATIONALITY] > 0) {
1797 martial_need = TRUE;
1798 }
1799
1800 if (!martial_need) {
1801 specialist_type_iterate(sp) {
1802 if (pcity->specialists[sp] > 0
1803 && get_specialist_output(pcity, sp, O_LUXURY) > 0) {
1804 martial_need = TRUE;
1805 break;
1806 }
1807 } specialist_type_iterate_end;
1808 }
1809
1810 if (martial_need
1811 && unit_list_size(pcity->tile->units) < get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX)) {
1812 martial_value = dai_content_effect_value(pplayer, pcity,
1813 get_city_bonus(pcity, EFT_MARTIAL_LAW_EACH),
1814 1, FEELING_FINAL);
1815 }
1816
1817 /* Otherwise no need to defend yet */
1818 if (city_data->danger != 0 || martial_value > 0) {
1819 struct impr_type *pimprove;
1820 int num_defenders = unit_list_size(ptile->units);
1821 int wall_id, danger;
1822 bool build_walls = TRUE;
1823 bool def_unit_selected = FALSE;
1824 int qdanger = city_data->danger * city_data->danger;
1825
1826 if (qdanger <= 0) {
1827 /* We only need these defenders because of Martial Law value */
1828 danger = 0;
1829 build_walls = FALSE; /* Walls don't provide Martial Law */
1830 } else {
1831 /* First determine the danger. It is measured in percents of our
1832 * defensive strength, capped at 200 + urgency */
1833 if (qdanger >= our_def) {
1834 if (urgency == 0) {
1835 /* Don't waste money */
1836 danger = 100;
1837 } else if (our_def == 0) {
1838 danger = 200 + urgency;
1839 } else {
1840 danger = MIN(200, 100 * qdanger / our_def) + urgency;
1841 }
1842 } else {
1843 danger = 100 * qdanger / our_def;
1844 }
1845
1846 if (pcity->surplus[O_SHIELD] <= 0 && our_def != 0) {
1847 /* Won't be able to support anything */
1848 danger = 0;
1849 }
1850 }
1851
1852 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d urgency=%d danger=%d num_def=%d "
1853 "our_def=%d", urgency, danger, num_defenders, our_def);
1854
1855 if (our_def == 0 && danger > 0) {
1856 /* Build defensive unit first! Walls will help nothing if there's
1857 * nobody behind them. */
1858 if (dai_process_defender_want(ait, pplayer, pcity, danger, choice,
1859 martial_value)) {
1860 choice->want = DAI_WANT_BELOW_MIL_EMERGENCY + danger;
1861 adv_choice_set_use(choice, "first defender");
1862 build_walls = FALSE;
1863 def_unit_selected = TRUE;
1864
1865 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants first defender with " ADV_WANT_PRINTF,
1866 choice->want);
1867 }
1868 }
1869 if (build_walls) {
1870 /* FIXME: 1. Does not consider what kind of future danger is likely, so
1871 * may build SAM batteries when enemy has only land units. */
1872 /* We will build walls if we can and want and (have "enough" defenders or
1873 * can just buy the walls straight away) */
1874
1875 /* HACK: This needs changing if multiple improvements provide
1876 * this effect. */
1877 wall_id = dai_find_source_building(pcity, EFT_DEFEND_BONUS, NULL);
1878 pimprove = improvement_by_number(wall_id);
1879
1880 if (wall_id != B_LAST
1881 && pcity->server.adv->building_want[wall_id] != 0 && our_def != 0
1882 && can_city_build_improvement_now(pcity, pimprove)
1883 && (danger < 101 || num_defenders > 1
1884 || (city_data->grave_danger == 0
1885 && pplayer->economic.gold
1886 > impr_buy_gold_cost(pcity, pimprove, pcity->shield_stock)))
1887 && ai_fuzzy(pplayer, TRUE)) {
1888 if (pcity->server.adv->building_want[wall_id] > 0) {
1889 /* NB: great wall is under domestic */
1890 choice->value.building = pimprove;
1891 /* building_want is hacked by assess_danger */
1892 choice->want = pcity->server.adv->building_want[wall_id];
1893 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER, pplayer)
1894 / TRAIT_DEFAULT_VALUE / 2));
1895 if (urgency == 0 && choice->want > DAI_WANT_BELOW_MIL_EMERGENCY) {
1896 choice->want = DAI_WANT_BELOW_MIL_EMERGENCY;
1897 }
1898 choice->type = CT_BUILDING;
1899 adv_choice_set_use(choice, "defense building");
1900 CITY_LOG(LOG_DEBUG, pcity,
1901 "m_a_c_d wants defense building with " ADV_WANT_PRINTF,
1902 choice->want);
1903 } else {
1904 build_walls = FALSE;
1905 }
1906 } else {
1907 build_walls = FALSE;
1908 }
1909 }
1910
1911 /* If our choice isn't defender unit already, consider one */
1912 if (!def_unit_selected) {
1913 if ((danger > 0 && num_defenders <= urgency) || martial_value > 0) {
1914 struct adv_choice uchoice;
1915
1916 adv_init_choice(&uchoice);
1917
1918 /* Consider building defensive units */
1919 if (dai_process_defender_want(ait, pplayer, pcity, danger, &uchoice,
1920 martial_value)) {
1921 /* Potential defender found */
1922 if (urgency == 0
1923 && uchoice.value.utype->defense_strength == 1) {
1924 /* FIXME: check other reqs (unit class?) */
1925 if (get_city_bonus(pcity, EFT_HP_REGEN) > 0) {
1926 /* Unlikely */
1927 uchoice.want = MIN(49, danger);
1928 } else {
1929 uchoice.want = MIN(25, danger);
1930 }
1931 } else {
1932 uchoice.want = danger;
1933 }
1934
1935 uchoice.want += martial_value;
1936 if (danger > 0) {
1937 adv_choice_set_use(&uchoice, "defender");
1938 } else {
1939 adv_choice_set_use(&uchoice, "police");
1940 }
1941
1942 if (!build_walls || uchoice.want > choice->want) {
1943 adv_choice_copy(choice, &uchoice);
1944 }
1945 adv_deinit_choice(&uchoice);
1946
1947 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants %s with desire " ADV_WANT_PRINTF,
1948 utype_rule_name(choice->value.utype),
1949 choice->want);
1950 } else {
1951 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d cannot select defender");
1952 }
1953 } else {
1954 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d does not want defenders");
1955 }
1956 }
1957 } /* Ok, don't need to defend */
1958
1959 if (pcity->surplus[O_SHIELD] <= 0
1960 || pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] > pcity->feel[CITIZEN_UNHAPPY][FEELING_EFFECT]
1961 || pcity->id == ai->wonder_city) {
1962 /* Things we consider below are not life-saving so we don't want to
1963 * build them if our populace doesn't feel like it */
1964 return choice;
1965 }
1966
1967 if (pplayer->economic.tax <= 50 || city_total_unit_gold_upkeep(pcity) <= 0) {
1968 /* Always allow one unit with real gold upkeep (after EFT_UNIT_UPKEEP_FREE_PER_CITY)
1969 * Allow more if economics is so strong that we have not increased taxes. */
1970 allow_gold_upkeep = TRUE;
1971 } else {
1972 allow_gold_upkeep = FALSE;
1973 }
1974
1975 /* Consider making a land bodyguard */
1976 punittype = dai_choose_bodyguard(ait, pcity, TC_LAND, L_DEFEND_GOOD,
1977 allow_gold_upkeep);
1978 if (punittype) {
1979 dai_unit_consider_bodyguard(ait, pcity, punittype, choice);
1980 }
1981
1982 /* If we are in severe danger, don't consider attackers. This is probably
1983 too general. In many cases we will want to buy attackers to counterattack.
1984 -- Per */
1985 if (choice->want - martial_value >= DAI_WANT_MILITARY_EMERGENCY
1986 && city_data->grave_danger > 0) {
1987 CITY_LOG(LOGLEVEL_BUILD, pcity,
1988 "severe danger (want " ADV_WANT_PRINTF "), force defender",
1989 choice->want);
1990 return choice;
1991 }
1992
1993 /* Consider making an offensive diplomat */
1994 dai_choose_diplomat_offensive(ait, pplayer, pcity, choice);
1995
1996 /* Consider making a sea bodyguard */
1997 punittype = dai_choose_bodyguard(ait, pcity, TC_OCEAN, L_DEFEND_GOOD,
1998 allow_gold_upkeep);
1999 if (punittype) {
2000 dai_unit_consider_bodyguard(ait, pcity, punittype, choice);
2001 }
2002
2003 /* Consider making an airplane */
2004 (void) dai_choose_attacker_air(ait, pplayer, pcity, choice, allow_gold_upkeep);
2005
2006 /* Consider making a paratrooper */
2007 dai_choose_paratrooper(ait, pplayer, pcity, choice, allow_gold_upkeep);
2008
2009 /* Check if we want a sailing attacker. Have to put sailing first
2010 before we mung the seamap */
2011 punittype = dai_choose_attacker(ait, pcity, TC_OCEAN, allow_gold_upkeep);
2012 if (punittype) {
2013 virtualunit = unit_virtual_create(
2014 pplayer, pcity, punittype,
2015 city_production_unit_veteran_level(pcity, punittype));
2016 choice = kill_something_with(ait, pplayer, pcity, virtualunit, choice);
2017 unit_virtual_destroy(virtualunit);
2018 }
2019
2020 /* Consider a land attacker or a ferried land attacker
2021 * (in which case, we might want a ferry before an attacker)
2022 */
2023 punittype = dai_choose_attacker(ait, pcity, TC_LAND, allow_gold_upkeep);
2024 if (punittype) {
2025 virtualunit = unit_virtual_create(pplayer, pcity, punittype, 1);
2026 choice = kill_something_with(ait, pplayer, pcity, virtualunit, choice);
2027 unit_virtual_destroy(virtualunit);
2028 }
2029
2030 /* Consider a hunter */
2031 dai_hunter_choice(ait, pplayer, pcity, choice, allow_gold_upkeep);
2032
2033 /* Consider veteran level enhancing buildings before non-urgent units */
2034 adjust_ai_unit_choice(pcity, choice);
2035
2036 if (choice->want <= 0) {
2037 CITY_LOG(LOGLEVEL_BUILD, pcity, "military advisor has no advice");
2038 } else {
2039 CITY_LOG(LOGLEVEL_BUILD, pcity,
2040 "military advisor choice: %s (want " ADV_WANT_PRINTF ")",
2041 adv_choice_rule_name(choice),
2042 choice->want);
2043 }
2044
2045 return choice;
2046}
action_enablers_for_action
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1519
action_by_result_iterate
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:236
action_enabler_list_iterate_end
#define action_enabler_list_iterate_end
Definition actions.h:185
action_by_result_iterate_end
#define action_by_result_iterate_end
Definition actions.h:240
action_enabler_list_iterate
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:183
action_id
#define action_id(_act_)
Definition actions.h:416
advbuilding.h
TRADE_WEIGHTING
#define TRADE_WEIGHTING
Definition advbuilding.h:21
SHIELD_WEIGHTING
#define SHIELD_WEIGHTING
Definition advbuilding.h:20
adv_deinit_choice
void adv_deinit_choice(struct adv_choice *choice)
Definition advchoice.c:46
adv_init_choice
void adv_init_choice(struct adv_choice *choice)
Definition advchoice.c:31
adv_free_choice
void adv_free_choice(struct adv_choice *choice)
Definition advchoice.c:71
adv_new_choice
struct adv_choice * adv_new_choice(void)
Definition advchoice.c:59
is_unit_choice_type
bool is_unit_choice_type(enum choice_type type)
Definition advchoice.c:115
adv_choice_rule_name
const char * adv_choice_rule_name(const struct adv_choice *choice)
Definition advchoice.c:124
advchoice.h
adv_choice_set_use
#define adv_choice_set_use(_choice, _use)
Definition advchoice.h:85
adv_choice_copy
static void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src)
Definition advchoice.h:79
CT_DEFENDER
@ CT_DEFENDER
Definition advchoice.h:41
CT_ATTACKER
@ CT_ATTACKER
Definition advchoice.h:40
CT_BUILDING
@ CT_BUILDING
Definition advchoice.h:38
adv_data_get
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:604
adv_is_player_dangerous
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1106
advdata.h
adv_unittype_att_rating
int adv_unittype_att_rating(const struct unit_type *punittype, int veteran, int moves_left, int hp)
Definition advgoto.c:385
adv_unit_att_rating
int adv_unit_att_rating(const struct unit *punit)
Definition advgoto.c:396
advgoto.h
advtools.h
POWER_DIVIDER
#define POWER_DIVIDER
Definition advtools.h:32
ADV_WANTS_EQ
#define ADV_WANTS_EQ(_w1, _w2)
Definition advtools.h:23
dai_choose_diplomat_defensive
void dai_choose_diplomat_defensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, int def)
Definition aidiplomat.c:115
dai_choose_diplomat_offensive
void dai_choose_diplomat_offensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice)
Definition aidiplomat.c:166
aidiplomat.h
dai_is_ferry_type
bool dai_is_ferry_type(const struct unit_type *pferry, struct ai_type *ait)
Definition aiferry.c:149
aiferry.h
aihand.h
dai_choose_paratrooper
void dai_choose_paratrooper(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, bool allow_gold_upkeep)
Definition aiparatrooper.c:382
aiparatrooper.h
ai_trait_get_value
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:68
aitraits.h
can_city_build_unit_later
bool can_city_build_unit_later(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:965
city_has_building
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1231
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_improvement_now
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:853
city_got_defense_effect
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1588
can_city_build_unit_direct
bool can_city_build_unit_direct(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:902
city_total_unit_gold_upkeep
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1213
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_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_tile
#define city_tile(_pcity_)
Definition city.h:564
CITIZEN_ANGRY
@ CITIZEN_ANGRY
Definition city.h:271
CITIZEN_UNHAPPY
@ CITIZEN_UNHAPPY
Definition city.h:270
city_owner
#define city_owner(_pcity_)
Definition city.h:563
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
FEELING_EFFECT
@ FEELING_EFFECT
Definition city.h:281
FEELING_FINAL
@ FEELING_FINAL
Definition city.h:284
FEELING_NATIONALITY
@ FEELING_NATIONALITY
Definition city.h:282
citytools.h
cityturn.h
is_stack_vulnerable
bool is_stack_vulnerable(const struct tile *ptile)
Definition combat.c:989
get_fortified_defense_power
int get_fortified_defense_power(const struct unit *attacker, struct unit *defender)
Definition combat.c:781
get_total_defense_power
int get_total_defense_power(const struct unit *attacker, const struct unit *defender)
Definition combat.c:767
get_total_attack_power
int get_total_attack_power(const struct unit *attacker, const struct unit *defender, const struct action *paction)
Definition combat.c:610
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:836
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:312
get_modified_firepower
void get_modified_firepower(const struct civ_map *nmap, const struct unit *attacker, const struct unit *defender, int *att_fp, int *def_fp)
Definition combat.c:411
combat.h
POWER_FACTOR
#define POWER_FACTOR
Definition combat.h:32
incite_cost
char * incite_cost
Definition comments.c:74
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 daiair.c:583
daiair.h
dai_find_source_building
Impr_type_id dai_find_source_building(struct city *pcity, enum effect_type effect_type, const struct unit_type *utype)
Definition daicity.c:2157
daicity.h
dai_plr_data_get
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition daidata.c:308
daidata.h
dai_content_effect_value
adv_want dai_content_effect_value(const struct player *pplayer, const struct city *pcity, int amount, int num_cities, int happiness_step)
Definition daieffects.c:77
daieffects.h
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 daihunter.c:249
daihunter.h
dailog.h
TECH_LOG
#define TECH_LOG(ait, loglevel, pplayer, padvance, msg,...)
Definition dailog.h:36
dai_assess_danger_player
void dai_assess_danger_player(struct ai_type *ait, struct player *pplayer, const struct civ_map *dmap)
Definition daimilitary.c:630
dai_choose_defender_versus
struct unit_type * dai_choose_defender_versus(struct city *pcity, struct unit *attacker)
Definition daimilitary.c:89
assess_defense
int assess_defense(struct ai_type *ait, struct city *pcity)
Definition daimilitary.c:341
dai_unit_attack_desirability
static adv_want dai_unit_attack_desirability(struct ai_type *ait, const struct unit_type *punittype)
Definition daimilitary.c:1016
action_may_happen_unit_on_city
static bool action_may_happen_unit_on_city(const action_id wanted_action, const struct unit *actor, const struct city *pcity, int turns)
Definition daimilitary.c:481
dai_reevaluate_building
static void dai_reevaluate_building(struct city *pcity, adv_want *value, unsigned int urgency, unsigned int danger, int defense)
Definition daimilitary.c:660
process_attacker_want
static void process_attacker_want(struct ai_type *ait, struct city *pcity, adv_want value, const struct unit_type *victim_unit_type, struct player *victim_player, int veteran, struct tile *ptile, struct adv_choice *best_choice, struct pf_map *ferry_map, struct unit *boat, const struct unit_type *boattype)
Definition daimilitary.c:1230
dai_unit_consider_bodyguard
static void dai_unit_consider_bodyguard(struct ai_type *ait, struct city *pcity, struct unit_type *punittype, struct adv_choice *choice)
Definition daimilitary.c:1705
kill_something_with
static struct adv_choice * kill_something_with(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct unit *myunit, struct adv_choice *choice)
Definition daimilitary.c:1506
adjust_ai_unit_choice
static void adjust_ai_unit_choice(struct city *pcity, struct adv_choice *choice)
Definition daimilitary.c:1740
assess_danger
static unsigned int assess_danger(struct ai_type *ait, struct city *pcity, const struct civ_map *dmap, player_unit_list_getter ul_cb)
Definition daimilitary.c:695
dai_choose_bodyguard
static struct unit_type * dai_choose_bodyguard(struct ai_type *ait, struct city *pcity, enum terrain_class tc, enum unit_role_id role, bool allow_gold_upkeep)
Definition daimilitary.c:184
dai_unit_defense_desirability
static adv_want dai_unit_defense_desirability(struct ai_type *ait, const struct unit_type *punittype)
Definition daimilitary.c:979
CITY_CONQUEST_WORTH
#define CITY_CONQUEST_WORTH(_city_, _data_)
Definition daimilitary.c:74
assess_danger_unit
static unsigned int assess_danger_unit(const struct city *pcity, struct pf_reverse_map *pcity_map, const struct unit *punit, int *move_time)
Definition daimilitary.c:523
tactical_req_cb
static enum fc_tristate tactical_req_cb(const struct req_context *context, const struct player *other_player, const struct requirement *req, void *data, int n_data)
Definition daimilitary.c:362
assess_defense_quadratic
int assess_defense_quadratic(struct ai_type *ait, struct city *pcity)
Definition daimilitary.c:277
dai_process_defender_want
bool dai_process_defender_want(struct ai_type *ait, struct player *pplayer, struct city *pcity, unsigned int danger, struct adv_choice *choice, adv_want extra_want)
Definition daimilitary.c:1051
base_assess_defense_unit
static int base_assess_defense_unit(struct city *pcity, struct unit *punit, bool igwall, bool quadratic, int wall_value)
Definition daimilitary.c:232
assess_defense_backend
static int assess_defense_backend(struct ai_type *ait, struct city *pcity, bool igwall)
Definition daimilitary.c:325
dai_choose_attacker
static struct unit_type * dai_choose_attacker(struct ai_type *ait, struct city *pcity, enum terrain_class tc, bool allow_gold_upkeep)
Definition daimilitary.c:143
assess_defense_unit
int assess_defense_unit(struct ai_type *ait, struct city *pcity, struct unit *punit, bool igwall)
Definition daimilitary.c:311
military_advisor_choose_build
struct adv_choice * military_advisor_choose_build(struct ai_type *ait, struct player *pplayer, struct city *pcity, const struct civ_map *mamap, player_unit_list_getter ul_cb)
Definition daimilitary.c:1770
assess_defense_igwall
static int assess_defense_igwall(struct ai_type *ait, struct city *pcity)
Definition daimilitary.c:350
daimilitary.h
player_unit_list_getter
struct unit_list *() player_unit_list_getter(struct player *pplayer)
Definition daimilitary.h:34
FINISH_HIM_CITY_COUNT
#define FINISH_HIM_CITY_COUNT
Definition daimilitary.h:32
daiplayer.h
def_ai_player_data
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
def_ai_city_data
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition daiplayer.h:42
dai_wants_defender_against
struct unit_type * dai_wants_defender_against(struct ai_type *ait, struct player *pplayer, struct city *pcity, const struct unit_type *att, int want)
Definition daitech.c:390
daitech.h
dai_assess_military_unhappiness
bool dai_assess_military_unhappiness(struct city *pcity)
Definition daitools.c:1414
dai_choose_role_unit
bool dai_choose_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, enum choice_type type, int role, int want, bool need_boat)
Definition daitools.c:1343
military_amortize
adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
Definition daitools.c:117
daitools.h
DAI_WANT_BELOW_MIL_EMERGENCY
#define DAI_WANT_BELOW_MIL_EMERGENCY
Definition daitools.h:31
DAI_WANT_MILITARY_EMERGENCY
#define DAI_WANT_MILITARY_EMERGENCY
Definition daitools.h:32
kill_desire
adv_want kill_desire(adv_want benefit, int attack, int loss, int vuln, int victim_count)
Definition daiunit.c:341
unittype_def_rating_squared
int unittype_def_rating_squared(const struct unit_type *att_type, const struct unit_type *def_type, struct player *def_player, struct tile *ptile, bool fortified, int veteran)
Definition daiunit.c:303
find_beachhead
bool find_beachhead(const struct player *pplayer, struct pf_map *ferry_map, struct tile *dest_tile, const struct unit_type *cargo_type, const struct unit_type *ferry_type, struct tile **ferry_dest, struct tile **beachhead_tile)
Definition daiunit.c:1061
utype_needs_improvement
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Definition daiunit.c:2898
build_cost_balanced
int build_cost_balanced(const struct unit_type *punittype)
Definition daiunit.c:249
look_for_charge
adv_want look_for_charge(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct unit **aunit, struct city **acity)
Definition daiunit.c:714
find_something_to_kill
adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile **pdest_tile, struct pf_path **ppath, struct pf_map **pferrymap, struct unit **pferryboat, const struct unit_type **pboattype, int *pmove_time)
Definition daiunit.c:1139
dai_can_unit_type_follow_unit_type
bool dai_can_unit_type_follow_unit_type(const struct unit_type *follower, const struct unit_type *followee, struct ai_type *ait)
Definition daiunit.c:834
POTENTIALLY_HOSTILE_PLAYER
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
Definition daiunit.h:72
simple_ai_unit_type_iterate_end
#define simple_ai_unit_type_iterate_end
Definition daiunit.h:152
simple_ai_unit_type_iterate
#define simple_ai_unit_type_iterate(_ut)
Definition daiunit.h:146
attack
static void attack(QVariant data1, QVariant data2)
Definition dialogs.cpp:3015
actor
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:73
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
cost
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 int cost
Definition dialogs_g.h:74
ai_fuzzy
bool ai_fuzzy(const struct player *pplayer, bool normal_decision)
Definition difficulty.c:339
difficulty.h
id
int int id
Definition editgui_g.h:28
get_target_bonus_effects
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
get_unittype_bonus
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, const struct action *paction, enum effect_type effect_type)
Definition effects.c:1035
adv_want
float adv_want
Definition fc_types.h:1365
Tech_type_id
int Tech_type_id
Definition fc_types.h:381
Impr_type_id
int Impr_type_id
Definition fc_types.h:380
RPT_POSSIBLE
@ RPT_POSSIBLE
Definition fc_types.h:707
action_id
int action_id
Definition fc_types.h:393
ADV_WANT_PRINTF
#define ADV_WANT_PRINTF
Definition fc_types.h:1366
Unit_type_id
int Unit_type_id
Definition fc_types.h:386
O_SHIELD
@ O_SHIELD
Definition fc_types.h:101
O_LUXURY
@ O_LUXURY
Definition fc_types.h:101
O_GOLD
@ O_GOLD
Definition fc_types.h:101
game
struct civ_game game
Definition game.c:62
wld
struct world wld
Definition game.c:63
game.h
government.h
pos
static struct tile * pos
Definition finddlg.c:53
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_DANGER
@ H_DANGER
Definition handicaps.h:32
H_ASSESS_DANGER_LIMITED
@ H_ASSESS_DANGER_LIMITED
Definition handicaps.h:36
improvement_by_number
struct impr_type * improvement_by_number(const Impr_type_id id)
Definition improvement.c:194
improvement_rule_name
const char * improvement_rule_name(const struct impr_type *pimprove)
Definition improvement.c:252
impr_buy_gold_cost
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
Definition improvement.c:306
is_great_wonder
bool is_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:772
B_LAST
#define B_LAST
Definition improvement.h:42
infracache.h
log.h
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
log_debug
#define log_debug(message,...)
Definition log.h:115
LOG_DEBUG
@ LOG_DEBUG
Definition log.h:34
LOG_VERBOSE
@ LOG_VERBOSE
Definition log.h:33
log_error
#define log_error(message,...)
Definition log.h:103
real_map_distance
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:636
map.h
is_native_tile
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:330
can_attack_from_non_native
bool can_attack_from_non_native(const struct unit_type *utype)
Definition movement.c:226
is_native_near_tile
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:464
can_attack_non_native
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:213
movement.h
SINGLE_MOVE
#define SINGLE_MOVE
Definition movement.h:26
cities
struct city_list * cities
Definition packhand.c:119
pf_reverse_map_unit_position
bool pf_reverse_map_unit_position(struct pf_reverse_map *pfrm, const struct unit *punit, struct pf_position *pos)
Definition path_finding.c:3896
pf_reverse_map_new_for_city
struct pf_reverse_map * pf_reverse_map_new_for_city(const struct city *pcity, const struct player *attacker, int max_turns, bool omniscient, const struct civ_map *nmap)
Definition path_finding.c:3715
pf_map_parameter
const struct pf_parameter * pf_map_parameter(const struct pf_map *pfm)
Definition path_finding.c:3365
pf_map_new
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
Definition path_finding.c:3182
pf_map_position
bool pf_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
Definition path_finding.c:3267
pf_map_iter_position
void pf_map_iter_position(struct pf_map *pfm, struct pf_position *pos)
Definition path_finding.c:3350
pf_reverse_map_destroy
void pf_reverse_map_destroy(struct pf_reverse_map *pfrm)
Definition path_finding.c:3727
pf_map_destroy
void pf_map_destroy(struct pf_map *pfm)
Definition path_finding.c:3206
PF_IMPOSSIBLE_MC
#define PF_IMPOSSIBLE_MC
Definition path_finding.h:266
pf_map_tiles_iterate
#define pf_map_tiles_iterate(ARG_pfm, NAME_tile, COND_from_start)
Definition path_finding.h:561
pf_map_tiles_iterate_end
#define pf_map_tiles_iterate_end
Definition path_finding.h:568
pft_fill_utype_parameter
void pft_fill_utype_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype, struct tile *pstart_tile, struct player *pplayer)
Definition pf_tools.c:829
pf_tools.h
players_iterate_end
#define players_iterate_end
Definition player.h:539
players_iterate
#define players_iterate(_pplayer)
Definition player.h:534
player_is_cpuhog
static bool player_is_cpuhog(const struct player *pplayer)
Definition player.h:577
tri_req_active_turns
enum fc_tristate tri_req_active_turns(int pass, int period, const struct req_context *context, const struct player *other_player, const struct requirement *req)
Definition requirements.c:5748
tri_reqs_cb_active
enum fc_tristate tri_reqs_cb_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, struct requirement_vector *maybe_reqs, req_tester_cb tester, void *data, int n_data)
Definition requirements.c:5901
tri_req_active
enum fc_tristate tri_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req)
Definition requirements.c:5672
is_req_preventing
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct player *other_player, const struct requirement *req, enum req_problem_type prob_type)
Definition requirements.c:5996
REQUCH_CTRL
@ REQUCH_CTRL
Definition requirements.h:118
research_goal_unknown_techs
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:750
research_goal_bulbs_required
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:772
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research.h
fc_tristate
fc_tristate
Definition shared.h:46
TRI_YES
@ TRI_YES
Definition shared.h:46
TRI_NO
@ TRI_NO
Definition shared.h:46
TRI_MAYBE
@ TRI_MAYBE
Definition shared.h:46
MIN
#define MIN(x, y)
Definition shared.h:55
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
MAX
#define MAX(x, y)
Definition shared.h:54
get_specialist_output
int get_specialist_output(const struct city *pcity, Specialist_type_id sp, Output_type_id otype)
Definition specialist.c:217
specialist.h
specialist_type_iterate_end
#define specialist_type_iterate_end
Definition specialist.h:79
specialist_type_iterate
#define specialist_type_iterate(sp)
Definition specialist.h:73
srv_log.h
CITY_LOG
#define CITY_LOG(loglevel, pcity, msg,...)
Definition srv_log.h:83
AIT_DANGER
@ AIT_DANGER
Definition srv_log.h:52
LOGLEVEL_BUILD
#define LOGLEVEL_BUILD
Definition srv_log.h:34
TIMER_STOP
@ TIMER_STOP
Definition srv_log.h:76
TIMER_START
@ TIMER_START
Definition srv_log.h:76
TIMING_LOG
#define TIMING_LOG(timer, activity)
Definition srv_log.h:125
server_state
enum server_states server_state(void)
Definition srv_main.c:337
srv_main.h
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_city::building_want
adv_want building_want[B_LAST]
Definition infracache.h:32
adv_data
Definition advdata.h:50
adv_data::wonder_city
int wonder_city
Definition advdata.h:55
ai_city
Definition daicity.h:34
ai_city::bcost
int bcost
Definition daicity.h:44
ai_city::urgency
unsigned int urgency
Definition daicity.h:49
ai_city::wallvalue
int wallvalue
Definition daicity.h:51
ai_plr
Definition daidata.h:71
ai_plr::boats
int boats
Definition daidata.h:79
ai_plr::available_boats
int available_boats
Definition daidata.h:80
ai_plr::stats
struct ai_plr::@275 stats
ai_type
Definition ai.h:50
city
Definition city.h:320
city::surplus
int surplus[O_LAST]
Definition city.h:355
city::id
int id
Definition city.h:326
city::adv
struct adv_city * adv
Definition city.h:452
city::feel
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:333
city::specialists
citizens specialists[SP_MAX]
Definition city.h:336
city::tile
struct tile * tile
Definition city.h:322
city::shield_stock
int shield_stock
Definition city.h:368
city::server
struct city::@17::@19 server
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_map
Definition map_types.h:71
impr_type
Definition improvement.h:50
impr_type::sabotage
int sabotage
Definition improvement.h:62
packet_game_info::low_firepower_pearl_harbour
int low_firepower_pearl_harbour
Definition packets_gen.h:200
packet_game_info::low_firepower_combat_bonus
int low_firepower_combat_bonus
Definition packets_gen.h:201
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_parameter::start_tile
struct tile * start_tile
Definition path_finding.h:359
pf_position
Definition path_finding.h:327
pf_reverse_map
Definition path_finding.c:3587
player_economic::tax
int tax
Definition player.h:64
player_economic::gold
int gold
Definition player.h:63
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::economic
struct player_economic economic
Definition player.h:284
player::adv
struct adv_data * adv
Definition player.h:334
req_context
Definition requirements.h:100
req_context::player
const struct player * player
Definition requirements.h:101
requirement
Definition requirements.h:81
requirement::survives
bool survives
Definition requirements.h:84
requirement::present
bool present
Definition requirements.h:85
requirement::source
struct universal source
Definition requirements.h:82
research
Definition research.h:39
tile
Definition tile.h:50
tile::units
struct unit_list * units
Definition tile.h:58
unit_class::sea_move
enum move_level sea_move
Definition unittype.h:163
unit_type_ai
Definition daiunit.h:50
unit_type_ai::low_firepower
bool low_firepower
Definition daiunit.h:51
unit_type
Definition unittype.h:507
unit_type::max_defense_mp_bonus_pct
int max_defense_mp_bonus_pct
Definition unittype.h:586
unit_type::firepower
int firepower
Definition unittype.h:532
unit_type::scramble_coeff
int scramble_coeff[U_LAST]
Definition unittype.h:590
unit_type::cache
struct unit_type::@88 cache
unit_type::defense_mp_bonuses_pct
int defense_mp_bonuses_pct[U_LAST]
Definition unittype.h:589
unit
Definition unit.h:140
unit::hp
int hp
Definition unit.h:153
unit::tile
struct tile * tile
Definition unit.h:142
unit::veteran
int veteran
Definition unit.h:154
universal::kind
enum universals_n kind
Definition fc_types.h:910
universal::value
universals_u value
Definition fc_types.h:909
veteran_level
Definition unittype.h:493
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
fc__fallthrough
#define fc__fallthrough
Definition support.h:119
advance_index
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
advance_number
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
tech_req
tech_req
Definition tech.h:110
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:43
TRAIT_DEFAULT_VALUE
#define TRAIT_DEFAULT_VALUE
Definition traits.h:32
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:728
universals_u::citystatus
enum citystatus_type citystatus
Definition fc_types.h:738
universals_u::building
const struct impr_type * building
Definition fc_types.h:721
unit_transport_get
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2485
unit_can_do_action
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:385
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:1657
is_special_unit
bool is_special_unit(const struct unit *punit)
Definition unit.c:352
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1762
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2469
unit_tile
#define unit_tile(_pu)
Definition unit.h:397
unit_owner
#define unit_owner(_pu)
Definition unit.h:396
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
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
utype_has_role
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:199
utype_build_shield_cost_base
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1468
unit_build_shield_cost_base
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1484
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
unit_class_get
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2498
utype_can_do_action_result
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:387
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
unit_can_take_over
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:264
utype_ai_data
void * utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
Definition unittype.c:2725
utype_index
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
utype_can_take_over
bool utype_can_take_over(const struct unit_type *punittype)
Definition unittype.c:276
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:756
utype_fuel
#define utype_fuel(ptype)
Definition unittype.h:843
unit_tech_reqs_iterate_end
#define unit_tech_reqs_iterate_end
Definition unittype.h:885
unit_tech_reqs_iterate
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:879
MOVE_FULL
@ MOVE_FULL
Definition unittype.h:144
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:624
unit_type_iterate
#define unit_type_iterate(_p)
Definition unittype.h:859
U_LAST
#define U_LAST
Definition unittype.h:40
unit_type_iterate_end
#define unit_type_iterate_end
Definition unittype.h:866
U_NOT_OBSOLETED
#define U_NOT_OBSOLETED
Definition unittype.h:535