Freeciv-3.2
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 "autosettlers.h"
49#include "infracache.h" /* adv_city */
50
51/* ai */
52#include "aitraits.h"
53#include "difficulty.h"
54#include "handicaps.h"
55
56/* ai/default */
57#include "aiair.h"
58#include "aidiplomat.h"
59#include "aiferry.h"
60#include "aihand.h"
61#include "aihunt.h"
62#include "aiparatrooper.h"
63#include "aitech.h"
64#include "aitools.h"
65#include "daicity.h"
66#include "daidata.h"
67#include "daieffects.h"
68#include "dailog.h"
69#include "daiplayer.h"
70
71#include "daimilitary.h"
72
73/* Size 1 city gets destroyed when conquered. It's still a good thing
74 * stop enemy from having it. */
75#define CITY_CONQUEST_WORTH(_city_, _data_) \
76 (_data_->worth * 0.9 + (city_size_get(_city_) - 0.5) * 10)
77
78static unsigned int assess_danger(struct ai_type *ait, struct city *pcity,
79 const struct civ_map *dmap,
81
83 const struct unit_type *punittype);
85 const struct unit_type *punittype);
86
87/**********************************************************************/
91 struct unit *attacker)
92{
93 struct unit_type *bestunit = NULL;
94 double best = 0;
96 struct player *pplayer = city_owner(pcity);
97 struct civ_map *nmap = &(wld.map);
98
101 int fpatt, fpdef, defense, attack;
102 double want, loss, cost = utype_build_shield_cost(pcity, NULL, punittype);
103 struct unit *defender;
104 int veteran = get_unittype_bonus(city_owner(pcity), pcity->tile,
107
108 defender = unit_virtual_create(pplayer, pcity, punittype, veteran);
109 defense = get_total_defense_power(attacker, defender);
110 attack = get_total_attack_power(attacker, defender, NULL);
111 get_modified_firepower(nmap, attacker, defender, &fpatt, &fpdef);
112
113 /* Greg's algorithm. loss is the average number of health lost by
114 * defender. If loss > attacker's hp then we should win the fight,
115 * which is always a good thing, since we avoid shield loss. */
116 loss = (double) defense * punittype->hp * fpdef / (attack * fpatt);
117 want = (loss + MAX(0, loss - attacker->hp)) / cost;
118
119#ifdef NEVER
120 CITY_LOG(LOG_DEBUG, pcity, "desire for %s against %s(%d,%d) is %.2f",
122 unit_name_orig(unit_type_get(attacker)),
123 TILE_XY(attacker->tile), want);
124#endif /* NEVER */
125
126 if (want > best || (ADV_WANTS_EQ(want, best)
127 && cost <= best_cost)) {
128 best = want;
130 best_cost = cost;
131 }
132 unit_virtual_destroy(defender);
133 }
135
136 return bestunit;
137}
138
139/**********************************************************************/
144static struct unit_type *dai_choose_attacker(struct ai_type *ait,
145 struct city *pcity,
146 enum terrain_class tc,
148{
149 struct unit_type *bestid = NULL;
150 adv_want best = -1;
152 struct player *pplayer = city_owner(pcity);
153
155 if (!allow_gold_upkeep && utype_upkeep_cost(putype, pplayer, O_GOLD) > 0) {
156 continue;
157 }
158
160 if ((tc == TC_LAND && utype_class(putype)->adv.land_move != MOVE_NONE)
161 || (tc == TC_OCEAN
162 && utype_class(putype)->adv.sea_move != MOVE_NONE)) {
164 && (cur > best
165 || (ADV_WANTS_EQ(cur, best)
167 <= utype_build_shield_cost(pcity, NULL, bestid)))) {
168 best = cur;
169 bestid = putype;
170 }
171 }
173
174 return bestid;
175}
176
177/**********************************************************************/
185static struct unit_type *dai_choose_bodyguard(struct ai_type *ait,
186 struct city *pcity,
187 enum terrain_class tc,
188 enum unit_role_id role,
190{
191 struct unit_type *bestid = NULL;
192 adv_want best = 0;
193 struct player *pplayer = city_owner(pcity);
194
196 /* Only consider units of given role, or any if invalid given */
198 if (!utype_has_role(putype, role)) {
199 continue;
200 }
201 }
202
203 if (!allow_gold_upkeep && utype_upkeep_cost(putype, pplayer, O_GOLD) > 0) {
204 continue;
205 }
206
207 /* Only consider units of same move type */
208 if ((tc == TC_LAND && utype_class(putype)->adv.land_move == MOVE_NONE)
209 || (tc == TC_OCEAN
210 && utype_class(putype)->adv.sea_move == MOVE_NONE)) {
211 continue;
212 }
213
214 /* Now find best */
215 if (can_city_build_unit_now(pcity, putype)) {
217
218 if (desire > best
219 || (ADV_WANTS_EQ(desire, best) && utype_build_shield_cost(pcity, NULL, putype) <=
221 best = desire;
222 bestid = putype;
223 }
224 }
226
227 return bestid;
228}
229
230/**********************************************************************/
233static int base_assess_defense_unit(struct city *pcity, struct unit *punit,
234 bool igwall, bool quadratic,
235 int wall_value)
236{
237 int defense;
238 int fp;
239
240 if (is_special_unit(punit)) {
241 return 0;
242 }
243
247 /* Attacker firepower doubled, defender firepower set to
248 * game.info.low_firepower_pearl_harbour at max. */
250 defense /= 2;
251 } else {
252 defense *= fp;
253 }
254
255 defense /= POWER_DIVIDER;
256
257 if (quadratic) {
258 defense *= defense;
259 }
260
261 if (pcity != NULL && !igwall && city_got_defense_effect(pcity, NULL)) {
262 /* FIXME: We checked if city got defense effect against *some*
263 * unit type. Sea unit danger might cause us to build defenses
264 * against air units... */
265
266 /* TODO: What about wall_value < 10? Do we really want walls to
267 * result in decrease in the returned value? */
268 defense *= wall_value;
269 defense /= 10;
270 }
271
272 return defense;
273}
274
275/**********************************************************************/
278int assess_defense_quadratic(struct ai_type *ait, struct city *pcity)
279{
280 int defense = 0, walls = 0;
281 /* This can be an arg if needed, but we don't need to change it now. */
282 const bool igwall = FALSE;
283 struct ai_city *city_data = def_ai_city_data(pcity, ait);
284
285 /* wallvalue = 10, walls = 10,
286 * wallvalue = 40, walls = 20,
287 * wallvalue = 90, walls = 30 */
288
289 while (walls * walls < city_data->wallvalue * 10) {
290 walls++;
291 }
292
294 defense += base_assess_defense_unit(pcity, punit, igwall, FALSE,
295 walls);
297
298 if (defense > 1<<12) {
299 CITY_LOG(LOG_VERBOSE, pcity, "Overflow danger in assess_defense_quadratic:"
300 " %d", defense);
301 if (defense > 1<<15) {
302 defense = 1<<15; /* more defense than we know what to do with! */
303 }
304 }
305
306 return defense * defense;
307}
308
309/**********************************************************************/
312int assess_defense_unit(struct ai_type *ait, struct city *pcity,
313 struct unit *punit, bool igwall)
314{
315 return base_assess_defense_unit(pcity, punit, igwall, TRUE,
316 def_ai_city_data(pcity, ait)->wallvalue);
317}
318
319/**********************************************************************/
326static int assess_defense_backend(struct ai_type *ait, struct city *pcity,
327 bool igwall)
328{
329 /* Estimate of our total city defensive might */
330 int defense = 0;
331
333 defense += assess_defense_unit(ait, pcity, punit, igwall);
335
336 return defense;
337}
338
339/**********************************************************************/
342int assess_defense(struct ai_type *ait, struct city *pcity)
343{
344 return assess_defense_backend(ait, pcity, FALSE);
345}
346
347/**********************************************************************/
351static int assess_defense_igwall(struct ai_type *ait, struct city *pcity)
352{
353 return assess_defense_backend(ait, pcity, TRUE);
354}
355
356/**********************************************************************/
362static enum fc_tristate
364 const struct player *other_player,
365 const struct requirement *req,
366 void *data, int n_data)
367{
368 switch (req->source.kind) {
369 case VUT_IMPROVEMENT:
370 {
371 const struct impr_type *b = req->source.value.building;
372
373 /* FIXME: in actor_reqs, may allow attack _from_ a city with... */
374 if (req->survives || NULL == context->city || is_great_wonder(b)
375 || !city_has_building(context->city, b) || b->sabotage <= 0) {
376 return tri_req_active(context, other_player, req);
377 }
378 /* Else may be sabotaged */
379 }
381 case VUT_UNITSTATE:
382 case VUT_ACTIVITY:
383 case VUT_MINSIZE:
384 case VUT_MAXTILEUNITS:
385 case VUT_MINHP:
386 case VUT_MINMOVES:
387 case VUT_COUNTER:
388 /* Can be changed back or forth quickly */
389 return TRI_MAYBE;
390 case VUT_MINVETERAN:
391 /* Can be changed forth but not back */
392 return is_req_preventing(context, other_player, req, RPT_POSSIBLE)
395 case VUT_NATIONALITY:
396 /* Can be changed back but hardly forth (foreign citizens reduced first) */
397 switch (tri_req_active(context, other_player, req)) {
398 case TRI_NO:
399 return req->present ? TRI_NO : TRI_MAYBE;
400 case TRI_YES:
401 return req->present ? TRI_MAYBE : TRI_YES;
402 default:
403 return TRI_MAYBE;
404 }
405 case VUT_DIPLREL:
406 case VUT_DIPLREL_TILE:
410 /* If the attack happens, there is a diplrel that allows it */
411 return TRI_YES;
412 case VUT_AGE:
413 case VUT_FORM_AGE:
414 case VUT_MINCALFRAG:
415 case VUT_MINYEAR:
416 /* If it is not near, won't change */
417 return tri_req_active_turns(n_data, 5 /* WAG */,
418 context, other_player, req);
419 case VUT_CITYSTATUS:
422 return TRI_MAYBE;
423 }
425 case VUT_UTYPE:
426 case VUT_UTFLAG:
427 case VUT_UCLASS:
428 case VUT_UCFLAG:
429 /* FIXME: support converting siege machines (needs hard reqs checked) */
430 case VUT_ACTION:
431 case VUT_OTYPE:
432 case VUT_SPECIALIST:
433 case VUT_EXTRAFLAG:
434 case VUT_MINLATITUDE:
435 case VUT_MAXLATITUDE:
436 case VUT_AI_LEVEL:
437 case VUT_CITYTILE:
438 case VUT_STYLE:
439 case VUT_TOPO:
440 case VUT_WRAP:
442 case VUT_NATION:
443 case VUT_NATIONGROUP:
444 case VUT_ADVANCE:
445 case VUT_TECHFLAG:
446 case VUT_GOVERNMENT:
447 case VUT_ACHIEVEMENT:
448 case VUT_IMPR_GENUS:
449 case VUT_IMPR_FLAG:
450 case VUT_PLAYER_FLAG:
451 case VUT_PLAYER_STATE:
452 case VUT_MINCULTURE:
453 case VUT_MINTECHS:
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 }
469
470 return TRI_NO;
471}
472
473/**********************************************************************/
480static bool
482 const struct unit *actor,
483 const struct city *pcity,
484 int turns)
485{
486 const struct player *target_player = city_owner(pcity),
488 const struct unit_type *utype = unit_type_get(actor);
489 const struct req_context target_ctx = {
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 }
503 enabler) {
504 /* We assume that we could build or move units into the city
505 * that are not present there yet */
507 &enabler->actor_reqs, NULL,
508 tactical_req_cb, NULL, turns)
509 &&
511 &enabler->target_reqs, NULL,
512 tactical_req_cb, NULL, turns)) {
513 return TRUE;
514 }
516
517 return FALSE;
518}
519
520/**********************************************************************/
523static unsigned int assess_danger_unit(const struct city *pcity,
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
539
542 && 0 < punittype->paratroopers_range) {
544 / punittype->paratroopers_range);
545 }
546
549 || *move_time > pos.turn)) {
550 *move_time = pos.turn;
551 }
552
554 && (ferry = unit_transport_get(punit))
557 || *move_time > pos.turn)) {
558 *move_time = pos.turn;
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)
570 return 0;
571 }
573 return 0;
574 }
575
576 /* Find the worst attack action to expect */
578 /* Is it possible that punit will do action id to the city? */
579 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
580
582 int b;
583
585
587 if (b > amod) {
588 amod = b;
589 }
590 }
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) {
597 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
598
600 *move_time)) {
601 int b;
602
604
606 if (b > amod) {
607 amod = b;
608 }
609 }
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,
622 return danger * (amod + 100) / MAX(dmod, 1);
623}
624
625/**********************************************************************/
630void 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);
638 }
639}
640
641/**********************************************************************/
660static 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/**********************************************************************/
695static unsigned int assess_danger(struct ai_type *ait, struct city *pcity,
696 const struct civ_map *dmap,
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 */
718 int assess_turns;
719 bool omnimap;
720
722
723 /* Initialize data. */
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;
739 best_non_scramble[idx] = -1;
740 /* FIXME: cache it somewhere? */
742 = 100 + get_unittype_bonus(pplayer, ptile, utype, NULL,
744 city_def_against[idx] = MAX(city_def_against[idx], 1);
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
753 city_data->has_diplomat = TRUE;
754 }
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 }
784 } else {
785 /* Just remember that such a unit exists and hope its bonuses are just 0 */
787 }
788
790 }
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. */
798
801 }
802
803 if (player_is_cpuhog(pplayer)) {
804 assess_turns = 6;
805 } else {
807 }
808
809 omnimap = !has_handicap(pplayer, H_MAP);
810
811 /* Check. */
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
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. */
843
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 */
860 punit, &move_time);
861
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 */
870 if (3 >= move_time) {
871 urgency++;
872 if (1 >= move_time) {
873 city_data->grave_danger++;
874 }
875 }
876 }
877
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,
888
890 city_data->diplomat_threat = TRUE;
891 }
892
893 vulnerability *= vulnerability; /* positive feedback */
894 if (1 < move_time) {
896 }
897
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. */
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
926
928
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]) {
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
971
972 return urgency;
973}
974
975/**********************************************************************/
980 const struct unit_type *punittype)
981{
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. */
992 }
993 if (((struct unit_type_ai *)utype_ai_data(punittype, ait))->low_firepower) {
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;
1007 desire /= 10; /* But might actually be worth it */
1008 }
1009
1010 return desire;
1011}
1012
1013/**********************************************************************/
1017 const struct unit_type *punittype)
1018{
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;
1028 desire += desire / 2;
1029 }
1031 desire /= 10; /* But might actually be worth it */
1032 }
1034 desire += desire / 2;
1035 }
1037 desire += desire / 4;
1038 }
1039 if (punittype->adv.igwall) {
1040 desire += desire / 4;
1041 }
1042
1043 return desire;
1044}
1045
1046/**********************************************************************/
1051bool 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. */
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
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. */
1080 continue;
1081 }
1082
1084
1086 desire /= 2; /* Not good, just ok */
1087 }
1088
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
1112 desire *= city_data->wallvalue;
1113 /* TODO: More use of POWER_FACTOR ! */
1115 }
1116
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;
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
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. */
1147 desire *= city_data->wallvalue;
1149 }
1150
1151 /* Yes, there's some similarity with kill_desire(). */
1152 /* TODO: Explain what shield cost has to do with tech want. */
1156 }
1157 }
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) {
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. */
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 */
1185
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,
1193 city_name_get(pcity));
1195 }
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/**********************************************************************/
1230static 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;
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) {
1260 }
1261
1262 if (utype_class(orig_utype)->adv.sea_move == MOVE_NONE
1263 && !boat && boattype) {
1264 /* Cost of ferry */
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 */
1272 }
1273
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 */
1282 adv_want want;
1283 int move_time;
1284 int vuln;
1285 int veteran_level
1287 &(const struct req_context) {
1288 .player = pplayer,
1289 .city = pcity,
1290 .tile = city_tile(pcity),
1291 .unittype = punittype,
1292 },
1293 NULL,
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;
1300 /* See description of kill_desire() for info about this variables. */
1304 punittype->hp);
1305 int tech_dist = 0;
1306
1309
1311 if (tech_dist == 0) {
1313 }
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 &dest_tile, NULL)
1343 && pf_map_position(ferry_map, dest_tile, &pos)) {
1344 move_time = pos.turn;
1347 if (atile == dest_tile) {
1349 move_time += pos.turn;
1350 break;
1351 } else if (atile == ptile) {
1352 /* Reaching directly seems better. */
1354 move_time = pos.turn;
1355 break;
1356 }
1358 }
1359 }
1360
1361 if (-1 == move_time) {
1362 if (pf_map_position(pfm, ptile, &pos)) {
1363 move_time = pos.turn;
1364 } else {
1366 continue;
1367 }
1368 }
1370
1371 /* Estimate strength of the enemy. */
1372
1373 if (victim_unit_type) {
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
1393 && acity_data->invasion.attack > 0
1394 && acity_data->invasion.occupy == 0) {
1396 float finishing_factor = 1;
1397
1400 }
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
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. */
1433
1434 want = military_amortize(pplayer, pcity, desire, MAX(1, move_time),
1436
1437 if (want > 0) {
1438 if (tech_dist > 0) {
1439 /* This is a future unit, tell the scientist how much we need it */
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,
1448 TILE_XY(ptile));
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,
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;
1470 pcity)))) {
1471 CITY_LOG(LOG_DEBUG, pcity, "cannot build unit %s",
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",
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",
1488 }
1489 }
1490 }
1491 }
1493}
1494
1495/**********************************************************************/
1506static 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 */
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
1536 best_choice->value.utype = unit_type_get(myunit);
1537 best_choice->type = CT_ATTACKER;
1538 adv_choice_set_use(best_choice, "attacker");
1539
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
1565 if (acity) {
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
1582 if (1 < move_time && def_type) {
1585 city_owner(acity), ptile,
1586 FALSE, def_vet);
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) {
1597 city_owner(acity), ptile, FALSE,
1598 pdef->veteran);
1599 if (vulnerability < m) {
1601 def_vet = pdef->veteran;
1604 }
1605 }
1606 if (unit_can_take_over(myunit) || acity_data->invasion.occupy > 0) {
1607 /* Bonus for getting the city */
1609 float finishing_factor = 1;
1610
1613 }
1615 }
1616
1617 /* end dealing with cities */
1618 } else {
1619
1620 if (NULL != 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
1632
1634 def_vet = pdef->veteran;
1636 /* end dealing with units */
1637 }
1638
1639 if (NULL == ferry_map) {
1641 def_vet, ptile,
1643 } else {
1644 /* Attract a boat to our city or retain the one that's already here */
1646 best_choice->need_boat = TRUE;
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*/
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
1685cleanup:
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(). */
1691 }
1692 if (NULL != ferry_map) {
1694 }
1695
1696 return choice;
1697}
1698
1699/**********************************************************************/
1705static 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,
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
1729 }
1730}
1731
1732/**********************************************************************/
1740static void adjust_ai_unit_choice(struct city *pcity,
1741 struct adv_choice *choice)
1742{
1744
1745 /* Sanity */
1746 if (!is_unit_choice_type(choice->type)
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 */
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/**********************************************************************/
1771 struct player *pplayer,
1772 struct city *pcity,
1773 const struct civ_map *mamap,
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);
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
1796 + pcity->feel[CITIZEN_ANGRY][FEELING_NATIONALITY] > 0) {
1798 }
1799
1800 if (!martial_need) {
1802 if (pcity->specialists[sp] > 0
1803 && get_specialist_output(pcity, sp, O_LUXURY) > 0) {
1805 break;
1806 }
1808 }
1809
1810 if (martial_need
1812 martial_value = dai_content_effect_value(pplayer, pcity,
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");
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. */
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)
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) {
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 {
1905 }
1906 } else {
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
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 }
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
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. */
1971 } else {
1973 }
1974
1975 /* Consider making a land bodyguard */
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 */
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 */
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 */
2012 if (punittype) {
2014 pplayer, pcity, punittype,
2016 choice = kill_something_with(ait, pplayer, pcity, virtualunit, choice);
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 */
2024 if (punittype) {
2025 virtualunit = unit_virtual_create(pplayer, pcity, punittype, 1);
2026 choice = kill_something_with(ait, pplayer, pcity, virtualunit, choice);
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}
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2306
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:479
#define action_enabler_list_iterate_end
Definition actions.h:439
#define action_by_result_iterate_end
Definition actions.h:483
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:437
#define action_id(_act_)
Definition actions.h:659
#define TRADE_WEIGHTING
Definition advbuilding.h:21
#define SHIELD_WEIGHTING
Definition advbuilding.h:20
void adv_deinit_choice(struct adv_choice *choice)
Definition advchoice.c:46
void adv_init_choice(struct adv_choice *choice)
Definition advchoice.c:31
void adv_free_choice(struct adv_choice *choice)
Definition advchoice.c:71
struct adv_choice * adv_new_choice(void)
Definition advchoice.c:59
bool is_unit_choice_type(enum choice_type type)
Definition advchoice.c:115
const char * adv_choice_rule_name(const struct adv_choice *choice)
Definition advchoice.c:124
#define adv_choice_set_use(_choice, _use)
Definition advchoice.h:85
static void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src)
Definition advchoice.h:79
@ CT_DEFENDER
Definition advchoice.h:41
@ CT_ATTACKER
Definition advchoice.h:40
@ CT_BUILDING
Definition advchoice.h:38
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:605
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1107
int adv_unittype_att_rating(const struct unit_type *punittype, int veteran, int moves_left, int hp)
Definition advgoto.c:380
int adv_unit_att_rating(const struct unit *punit)
Definition advgoto.c:391
#define POWER_DIVIDER
Definition advtools.h:32
#define ADV_WANTS_EQ(_w1, _w2)
Definition advtools.h:23
bool dai_choose_attacker_air(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, bool allow_gold_upkeep)
Definition aiair.c:582
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
void dai_choose_diplomat_offensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice)
Definition aidiplomat.c:166
bool dai_is_ferry_type(const struct unit_type *pferry, struct ai_type *ait)
Definition aiferry.c:149
void dai_hunter_choice(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, bool allow_gold_upkeep)
Definition aihunt.c:252
void dai_choose_paratrooper(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, bool allow_gold_upkeep)
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 aitech.c:390
bool dai_assess_military_unhappiness(struct city *pcity)
Definition aitools.c:1415
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 aitools.c:1344
adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
Definition aitools.c:118
#define DAI_WANT_BELOW_MIL_EMERGENCY
Definition aitools.h:31
#define DAI_WANT_MILITARY_EMERGENCY
Definition aitools.h:32
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:69
bool can_city_build_unit_later(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:965
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1231
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:803
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:853
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1588
bool can_city_build_unit_direct(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:902
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1213
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:945
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
@ CITIZEN_ANGRY
Definition city.h:271
@ CITIZEN_UNHAPPY
Definition city.h:270
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
@ FEELING_EFFECT
Definition city.h:281
@ FEELING_FINAL
Definition city.h:284
@ FEELING_NATIONALITY
Definition city.h:282
bool is_stack_vulnerable(const struct tile *ptile)
Definition combat.c:987
int get_fortified_defense_power(const struct unit *attacker, struct unit *defender)
Definition combat.c:779
int get_total_defense_power(const struct unit *attacker, const struct unit *defender)
Definition combat.c:765
int get_total_attack_power(const struct unit *attacker, const struct unit *defender, const struct action *paction)
Definition combat.c:608
struct unit * get_defender(const struct civ_map *nmap, const struct unit *attacker, const struct tile *ptile, const struct action *paction)
Definition combat.c:834
bool can_unit_attack_tile(const struct unit *punit, const struct action *paction, const struct tile *dest_tile)
Definition combat.c:311
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:409
#define POWER_FACTOR
Definition combat.h:32
char * incite_cost
Definition comments.c:74
Impr_type_id dai_find_source_building(struct city *pcity, enum effect_type effect_type, const struct unit_type *utype)
Definition daicity.c:2156
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition daidata.c:308
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
#define TECH_LOG(ait, loglevel, pplayer, padvance, msg,...)
Definition dailog.h:36
void dai_assess_danger_player(struct ai_type *ait, struct player *pplayer, const struct civ_map *dmap)
struct unit_type * dai_choose_defender_versus(struct city *pcity, struct unit *attacker)
Definition daimilitary.c:90
int assess_defense(struct ai_type *ait, struct city *pcity)
static adv_want dai_unit_attack_desirability(struct ai_type *ait, const struct unit_type *punittype)
static bool action_may_happen_unit_on_city(const action_id wanted_action, const struct unit *actor, const struct city *pcity, int turns)
static void dai_reevaluate_building(struct city *pcity, adv_want *value, unsigned int urgency, unsigned int danger, int defense)
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)
static void dai_unit_consider_bodyguard(struct ai_type *ait, struct city *pcity, struct unit_type *punittype, struct adv_choice *choice)
static struct adv_choice * kill_something_with(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct unit *myunit, struct adv_choice *choice)
static void adjust_ai_unit_choice(struct city *pcity, struct adv_choice *choice)
static unsigned int assess_danger(struct ai_type *ait, struct city *pcity, const struct civ_map *dmap, player_unit_list_getter ul_cb)
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)
static adv_want dai_unit_defense_desirability(struct ai_type *ait, const struct unit_type *punittype)
#define CITY_CONQUEST_WORTH(_city_, _data_)
Definition daimilitary.c:75
static unsigned int assess_danger_unit(const struct city *pcity, struct pf_reverse_map *pcity_map, const struct unit *punit, int *move_time)
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)
int assess_defense_quadratic(struct ai_type *ait, struct city *pcity)
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)
static int base_assess_defense_unit(struct city *pcity, struct unit *punit, bool igwall, bool quadratic, int wall_value)
static int assess_defense_backend(struct ai_type *ait, struct city *pcity, bool igwall)
static struct unit_type * dai_choose_attacker(struct ai_type *ait, struct city *pcity, enum terrain_class tc, bool allow_gold_upkeep)
int assess_defense_unit(struct ai_type *ait, struct city *pcity, struct unit *punit, bool igwall)
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)
static int assess_defense_igwall(struct ai_type *ait, struct city *pcity)
struct unit_list *() player_unit_list_getter(struct player *pplayer)
Definition daimilitary.h:34
#define FINISH_HIM_CITY_COUNT
Definition daimilitary.h:32
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition daiplayer.h:42
adv_want kill_desire(adv_want benefit, int attack, int loss, int vuln, int victim_count)
Definition daiunit.c:341
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
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Definition daiunit.c:2892
int build_cost_balanced(const struct unit_type *punittype)
Definition daiunit.c:249
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
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:1135
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
bool find_beachhead(const struct player *pplayer, struct pf_map *ferry_map, struct tile *dest_tile, const struct unit_type *cargo_type, struct tile **ferry_dest, struct tile **beachhead_tile)
Definition daiunit.c:1060
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
Definition daiunit.h:72
#define simple_ai_unit_type_iterate_end
Definition daiunit.h:151
#define simple_ai_unit_type_iterate(_ut)
Definition daiunit.h:145
static void attack(QVariant data1, QVariant data2)
Definition dialogs.cpp:3009
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
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
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
bool ai_fuzzy(const struct player *pplayer, bool normal_decision)
Definition difficulty.c:339
int int id
Definition editgui_g.h:28
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
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
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
float adv_want
Definition fc_types.h:1355
int Tech_type_id
Definition fc_types.h:380
int Impr_type_id
Definition fc_types.h:379
@ RPT_POSSIBLE
Definition fc_types.h:703
int action_id
Definition fc_types.h:392
#define ADV_WANT_PRINTF
Definition fc_types.h:1356
int Unit_type_id
Definition fc_types.h:385
@ O_SHIELD
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
static struct tile * pos
Definition finddlg.c:53
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
@ H_MAP
Definition handicaps.h:28
@ H_DANGER
Definition handicaps.h:32
@ H_ASSESS_DANGER_LIMITED
Definition handicaps.h:36
struct impr_type * improvement_by_number(const Impr_type_id id)
const char * improvement_rule_name(const struct impr_type *pimprove)
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
bool is_great_wonder(const struct impr_type *pimprove)
#define B_LAST
Definition improvement.h:42
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_debug(message,...)
Definition log.h:115
@ LOG_DEBUG
Definition log.h:34
@ LOG_VERBOSE
Definition log.h:33
#define log_error(message,...)
Definition log.h:103
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:630
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:331
bool can_attack_from_non_native(const struct unit_type *utype)
Definition movement.c:227
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:465
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:214
#define SINGLE_MOVE
Definition movement.h:26
struct city_list * cities
Definition packhand.c:119
bool pf_reverse_map_unit_position(struct pf_reverse_map *pfrm, const struct unit *punit, struct pf_position *pos)
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)
const struct pf_parameter * pf_map_parameter(const struct pf_map *pfm)
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
bool pf_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
void pf_map_iter_position(struct pf_map *pfm, struct pf_position *pos)
void pf_reverse_map_destroy(struct pf_reverse_map *pfrm)
void pf_map_destroy(struct pf_map *pfm)
#define PF_IMPOSSIBLE_MC
#define pf_map_tiles_iterate(ARG_pfm, NAME_tile, COND_from_start)
#define pf_map_tiles_iterate_end
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:826
#define players_iterate_end
Definition player.h:537
#define players_iterate(_pplayer)
Definition player.h:532
static bool player_is_cpuhog(const struct player *pplayer)
Definition player.h:575
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)
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)
enum fc_tristate tri_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req)
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)
@ REQUCH_CTRL
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:750
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:772
struct research * research_get(const struct player *pplayer)
Definition research.c:128
fc_tristate
Definition shared.h:46
@ TRI_YES
Definition shared.h:46
@ TRI_NO
Definition shared.h:46
@ TRI_MAYBE
Definition shared.h:46
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
#define MAX(x, y)
Definition shared.h:54
int get_specialist_output(const struct city *pcity, Specialist_type_id sp, Output_type_id otype)
Definition specialist.c:217
#define specialist_type_iterate_end
Definition specialist.h:79
#define specialist_type_iterate(sp)
Definition specialist.h:73
#define CITY_LOG(loglevel, pcity, msg,...)
Definition srv_log.h:83
@ AIT_DANGER
Definition srv_log.h:52
#define LOGLEVEL_BUILD
Definition srv_log.h:34
@ TIMER_STOP
Definition srv_log.h:76
@ TIMER_START
Definition srv_log.h:76
#define TIMING_LOG(timer, activity)
Definition srv_log.h:125
enum server_states server_state(void)
Definition srv_main.c:333
enum choice_type type
Definition advchoice.h:46
adv_want want
Definition advchoice.h:48
universals_u value
Definition advchoice.h:47
adv_want building_want[B_LAST]
Definition infracache.h:32
int wonder_city
Definition advdata.h:55
int bcost
Definition daicity.h:44
unsigned int urgency
Definition daicity.h:49
int wallvalue
Definition daicity.h:51
struct ai_plr::@251 stats
int boats
Definition daidata.h:79
int available_boats
Definition daidata.h:80
Definition ai.h:50
Definition city.h:320
int surplus[O_LAST]
Definition city.h:355
int id
Definition city.h:326
struct adv_city * adv
Definition city.h:452
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:333
citizens specialists[SP_MAX]
Definition city.h:336
struct tile * tile
Definition city.h:322
int shield_stock
Definition city.h:368
struct city::@17::@19 server
struct packet_game_info info
Definition game.h:89
int low_firepower_pearl_harbour
int low_firepower_combat_bonus
struct tile * start_tile
struct city_list * cities
Definition player.h:279
struct player_economic economic
Definition player.h:282
struct adv_data * adv
Definition player.h:332
const struct player * player
struct universal source
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
enum move_level sea_move
Definition unittype.h:163
bool low_firepower
Definition daiunit.h:51
int max_defense_mp_bonus_pct
Definition unittype.h:579
int firepower
Definition unittype.h:525
int scramble_coeff[U_LAST]
Definition unittype.h:583
struct unit_type::@88 cache
int defense_mp_bonuses_pct[U_LAST]
Definition unittype.h:582
Definition unit.h:138
int hp
Definition unit.h:151
struct tile * tile
Definition unit.h:140
int veteran
Definition unit.h:152
enum universals_n kind
Definition fc_types.h:903
universals_u value
Definition fc_types.h:902
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define fc__fallthrough
Definition support.h:119
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
tech_req
Definition tech.h:110
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define TILE_XY(ptile)
Definition tile.h:43
#define TRAIT_DEFAULT_VALUE
Definition traits.h:32
const struct unit_type * utype
Definition fc_types.h:724
enum citystatus_type citystatus
Definition fc_types.h:734
const struct impr_type * building
Definition fc_types.h:717
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2437
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:361
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1620
bool is_special_unit(const struct unit *punit)
Definition unit.c:352
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1725
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2421
#define unit_tile(_pu)
Definition unit.h:390
#define unit_owner(_pu)
Definition unit.h:389
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:199
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1468
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1484
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2498
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:387
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:264
void * utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
Definition unittype.c:2725
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
bool utype_can_take_over(const struct unit_type *punittype)
Definition unittype.c:276
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1438
bool utype_acts_hostile(const struct unit_type *putype)
Definition unittype.c:443
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
#define utype_class(_t_)
Definition unittype.h:749
#define utype_fuel(ptype)
Definition unittype.h:836
#define unit_tech_reqs_iterate_end
Definition unittype.h:878
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:872
@ MOVE_FULL
Definition unittype.h:144
@ MOVE_NONE
Definition unittype.h:144
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:617
#define unit_type_iterate(_p)
Definition unittype.h:852
#define U_LAST
Definition unittype.h:40
#define unit_type_iterate_end
Definition unittype.h:859
#define U_NOT_OBSOLETED
Definition unittype.h:528