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 "daiair.h"
60#include "daicity.h"
61#include "daidata.h"
62#include "daieffects.h"
63#include "daihunter.h"
64#include "dailog.h"
65#include "daiparadrop.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,
78 const struct civ_map *nmap,
79 struct city *pcity,
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;
103 struct unit *defender;
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 const struct civ_map *nmap = &(wld.map);
154
156 if (!allow_gold_upkeep && utype_upkeep_cost(putype, pplayer, O_GOLD) > 0) {
157 continue;
158 }
159
161 if ((tc == TC_LAND && utype_class(putype)->adv.land_move != MOVE_NONE)
162 || (tc == TC_OCEAN
163 && utype_class(putype)->adv.sea_move != MOVE_NONE)) {
165 && (cur > best
166 || (ADV_WANTS_EQ(cur, best)
169 best = cur;
170 bestid = putype;
171 }
172 }
174
175 return bestid;
176}
177
178/**********************************************************************/
186static struct unit_type *dai_choose_bodyguard(struct ai_type *ait,
187 const struct civ_map *nmap,
188 struct city *pcity,
189 enum terrain_class tc,
190 enum unit_role_id role,
192{
193 struct unit_type *bestid = NULL;
194 adv_want best = 0;
195 struct player *pplayer = city_owner(pcity);
196
198 /* Only consider units of given role, or any if invalid given */
200 if (!utype_has_role(putype, role)) {
201 continue;
202 }
203 }
204
205 if (!allow_gold_upkeep && utype_upkeep_cost(putype, pplayer, O_GOLD) > 0) {
206 continue;
207 }
208
209 /* Only consider units of same move type */
210 if ((tc == TC_LAND && utype_class(putype)->adv.land_move == MOVE_NONE)
211 || (tc == TC_OCEAN
212 && utype_class(putype)->adv.sea_move == MOVE_NONE)) {
213 continue;
214 }
215
216 /* Now find best */
219
220 if (desire > best
223 best = desire;
224 bestid = putype;
225 }
226 }
228
229 return bestid;
230}
231
232/**********************************************************************/
235static int base_assess_defense_unit(struct city *pcity, struct unit *punit,
236 bool igwall, bool quadratic,
237 int wall_value)
238{
239 int defense;
240 int fp;
241
242 if (is_special_unit(punit)) {
243 return 0;
244 }
245
249 /* Attacker firepower doubled, defender firepower set to
250 * game.info.low_firepower_pearl_harbor at max. */
251 defense *= MIN(fp, game.info.low_firepower_pearl_harbor);
252 defense /= 2;
253 } else {
254 defense *= fp;
255 }
256
257 defense /= POWER_DIVIDER;
258
259 if (quadratic) {
260 defense *= defense;
261 }
262
263 if (pcity != NULL && !igwall && city_got_defense_effect(pcity, NULL)) {
264 /* FIXME: We checked if city got defense effect against *some*
265 * unit type. Sea unit danger might cause us to build defenses
266 * against air units... */
267
268 /* TODO: What about wall_value < 10? Do we really want walls to
269 * result in decrease in the returned value? */
270 defense *= wall_value;
271 defense /= 10;
272 }
273
274 return defense;
275}
276
277/**********************************************************************/
281{
282 int defense = 0, walls = 0;
283 /* This can be an arg if needed, but we don't need to change it now. */
284 const bool igwall = FALSE;
285 struct ai_city *city_data = def_ai_city_data(pcity, ait);
286
287 /* wallvalue = 10, walls = 10,
288 * wallvalue = 40, walls = 20,
289 * wallvalue = 90, walls = 30 */
290
291 while (walls * walls < city_data->wallvalue * 10) {
292 walls++;
293 }
294
296 defense += base_assess_defense_unit(pcity, punit, igwall, FALSE,
297 walls);
299
300 if (defense > 1<<12) {
301 CITY_LOG(LOG_VERBOSE, pcity, "Overflow danger in assess_defense_quadratic:"
302 " %d", defense);
303 if (defense > 1<<15) {
304 defense = 1<<15; /* more defense than we know what to do with! */
305 }
306 }
307
308 return defense * defense;
309}
310
311/**********************************************************************/
314int assess_defense_unit(struct ai_type *ait, struct city *pcity,
315 struct unit *punit, bool igwall)
316{
317 return base_assess_defense_unit(pcity, punit, igwall, TRUE,
319}
320
321/**********************************************************************/
328static int assess_defense_backend(struct ai_type *ait, struct city *pcity,
329 bool igwall)
330{
331 /* Estimate of our total city defensive might */
332 int defense = 0;
333
335 defense += assess_defense_unit(ait, pcity, punit, igwall);
337
338 return defense;
339}
340
341/**********************************************************************/
344int assess_defense(struct ai_type *ait, struct city *pcity)
345{
346 return assess_defense_backend(ait, pcity, FALSE);
347}
348
349/**********************************************************************/
353static int assess_defense_igwall(struct ai_type *ait, struct city *pcity)
354{
355 return assess_defense_backend(ait, pcity, TRUE);
356}
357
358/**********************************************************************/
364static enum fc_tristate
366 const struct req_context *other_context,
367 const struct requirement *req,
368 void *data, int n_data)
369{
370 switch (req->source.kind) {
371 case VUT_IMPROVEMENT:
372 case VUT_SITE:
373 {
374 const struct impr_type *b = req->source.value.building;
375
376 /* FIXME: in actor_reqs, may allow attack _from_ a city with... */
377 if (req->survives || NULL == context->city || is_great_wonder(b)
378 || !city_has_building(context->city, b) || b->sabotage <= 0) {
380 }
381 /* Else may be sabotaged */
382 }
384 case VUT_UNITSTATE:
385 case VUT_ACTIVITY:
386 case VUT_MINSIZE:
387 case VUT_MAXTILEUNITS:
388 case VUT_MINHP:
389 case VUT_MINMOVES:
390 case VUT_COUNTER:
391 /* Can be changed back or forth quickly */
392 return TRI_MAYBE;
393 case VUT_MINVETERAN:
394 /* Can be changed forth but not back */
398 case VUT_NATIONALITY:
399 /* Can be changed back but hardly forth (foreign citizens reduced first) */
400 switch (tri_req_active(context, other_context, req)) {
401 case TRI_NO:
402 return req->present ? TRI_NO : TRI_MAYBE;
403 case TRI_YES:
404 return req->present ? TRI_MAYBE : TRI_YES;
405 default:
406 return TRI_MAYBE;
407 }
408 case VUT_DIPLREL:
409 case VUT_DIPLREL_TILE:
413 /* If the attack happens, there is a diplrel that allows it */
414 return TRI_YES;
415 case VUT_AGE:
416 case VUT_FORM_AGE:
417 case VUT_MINCALFRAG:
418 case VUT_MINYEAR:
419 /* If it is not near, won't change */
420 return tri_req_active_turns(n_data, 5 /* WAG */,
421 context, other_context, req);
422 case VUT_CITYSTATUS:
425 return TRI_MAYBE;
426 }
428 case VUT_UTYPE:
429 case VUT_UTFLAG:
430 case VUT_UCLASS:
431 case VUT_UCFLAG:
432 /* FIXME: support converting siege machines (needs hard reqs checked) */
433 case VUT_ACTION:
434 case VUT_OTYPE:
435 case VUT_SPECIALIST:
436 case VUT_EXTRAFLAG:
437 case VUT_MINLATITUDE:
438 case VUT_MAXLATITUDE:
439 case VUT_AI_LEVEL:
440 case VUT_CITYTILE:
441 case VUT_STYLE:
442 case VUT_TOPO:
443 case VUT_WRAP:
445 case VUT_NATION:
446 case VUT_NATIONGROUP:
447 case VUT_ADVANCE:
448 case VUT_TECHFLAG:
449 case VUT_GOVERNMENT:
450 case VUT_ACHIEVEMENT:
451 case VUT_IMPR_GENUS:
452 case VUT_IMPR_FLAG:
453 case VUT_PLAYER_FLAG:
454 case VUT_PLAYER_STATE:
455 case VUT_MINCULTURE:
456 case VUT_MINTECHS:
457 case VUT_MINCITIES:
459 case VUT_ROADFLAG:
460 case VUT_TERRAIN:
461 case VUT_EXTRA:
462 case VUT_GOOD:
463 case VUT_TERRAINCLASS:
464 case VUT_TERRFLAG:
465 case VUT_TERRAINALTER:
468 case VUT_TILE_REL:
469 case VUT_NONE:
471 case VUT_COUNT:
472 /* Not implemented. */
473 break;
474 }
476
477 return TRI_NO;
478}
479
480/**********************************************************************/
487static bool
489 const struct unit *actor,
490 const struct city *pcity,
491 int turns)
492{
493 const struct player *target_player = city_owner(pcity),
495 const struct unit_type *utype = unit_type_get(actor);
496 const struct req_context target_ctx = {
498 .city = pcity,
500 }, actor_ctx = {
501 .player = actor_player,
502 .unit = actor,
503 .unittype = utype
504 };
505
506 if (!utype_can_do_action(utype, wanted_action)) {
507 return FALSE;
508 }
510 enabler) {
511 /* We assume that we could build or move units into the city
512 * that are not present there yet */
514 &enabler->actor_reqs, NULL,
515 tactical_req_cb, NULL, turns)
516 &&
518 &enabler->target_reqs, NULL,
519 tactical_req_cb, NULL, turns)) {
520 return TRUE;
521 }
523
524 return FALSE;
525}
526
527/**********************************************************************/
530static unsigned int assess_danger_unit(const struct civ_map *nmap,
531 const struct city *pcity,
533 const struct unit *punit,
534 int *move_time)
535{
536 struct pf_position pos;
537 const struct unit_type *punittype = unit_type_get(punit);
538 const struct tile *ptile = city_tile(pcity);
539 const struct player *uowner = unit_owner(punit);
540 const struct unit *ferry;
541 unsigned int danger;
542 int amod = -99, dmod;
543 bool attack_danger = FALSE;
544
546
549 && 0 < punittype->paratroopers_range) {
551 / punittype->paratroopers_range);
552 }
553
556 || *move_time > pos.turn)) {
557 *move_time = pos.turn;
558 }
559
561 && (ferry = unit_transport_get(punit))
564 || *move_time > pos.turn)) {
565 *move_time = pos.turn;
567 (*move_time)++;
568 }
569 }
570 }
571
572 if (PF_IMPOSSIBLE_MC == *move_time) {
573 return 0;
574 }
575 if (!is_native_tile(punittype, ptile)
577 return 0;
578 }
580 return 0;
581 }
582
583 /* Find the worst attack action to expect */
585 /* Is it possible that punit will do action id to the city? */
586 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
587
589 int b;
590
592
594 if (b > amod) {
595 amod = b;
596 }
597 }
599
600 /* FIXME: it's a dummy support for anti-bombard defense just to do something against
601 * approaching bombarders. Some better logic is needed, see OSDN#41778 */
602 if (!attack_danger) {
604 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
605
607 *move_time)) {
608 int b;
609
611
613 if (b > amod) {
614 amod = b;
615 }
616 }
618 /* Here something should be done cuz the modifier affects
619 * more than one unit but not their full hp, but is not done yet...*/
620 }
621 if (!attack_danger) {
622 /* If the unit is dangerous, it's not about its combat strength */
623 return 0;
624 }
625
626 danger = adv_unit_att_rating(punit);
627 dmod = 100 + get_unittype_bonus(city_owner(pcity), ptile,
629 return danger * (amod + 100) / MAX(dmod, 1);
630}
631
632/**********************************************************************/
638 const struct civ_map *nmap,
639 struct player *pplayer)
640{
641 /* Do nothing if game is not running */
642 if (S_S_RUNNING == server_state()) {
643 city_list_iterate(pplayer->cities, pcity) {
644 (void) assess_danger(ait, nmap, pcity, NULL);
646 }
647}
648
649/**********************************************************************/
668static void dai_reevaluate_building(struct city *pcity, adv_want *value,
669 unsigned int urgency, unsigned int danger,
670 int defense)
671{
672 if (*value == 0 || danger <= 0) {
673 return;
674 }
675
676 *value = MAX(*value, 100 + urgency); /* default */
677
678 if (urgency > 0 && danger > defense * 2) {
679 *value += 100;
680 } else if (defense != 0 && danger > defense) {
681 *value = MAX(danger * 100 / defense, *value);
682 }
683}
684
685/**********************************************************************/
703static unsigned int assess_danger(struct ai_type *ait,
704 const struct civ_map *nmap,
705 struct city *pcity,
707{
708 struct player *pplayer = city_owner(pcity);
709 struct tile *ptile = city_tile(pcity);
710 struct ai_city *city_data = def_ai_city_data(pcity, ait);
711 /* How much such danger there is that building would help against. */
712 unsigned int danger_reduced[B_LAST];
713 int i;
714 int defender;
715 unsigned int urgency = 0;
716 int defense;
717 int total_danger = 0;
718
719 /* TODO: Presumably most, or even all, of these arrays
720 * could be of size game.control.num_unit_types instead
721 * of full U_LAST */
727 int assess_turns;
728 bool omnimap;
729
731
732 /* Initialize data. */
734 if (has_handicap(pplayer, H_DANGER)) {
735 /* Always thinks that city is in grave danger */
736 city_data->grave_danger = 1;
737 } else {
738 city_data->grave_danger = 0;
739 }
740 city_data->diplomat_threat = FALSE;
741 city_data->has_diplomat = FALSE;
742
743 unit_type_iterate(utype) {
744 int idx = utype_index(utype);
745
746 defense_bonuses_pct[idx] = 0;
748 best_non_scramble[idx] = -1;
749 /* FIXME: cache it somewhere? */
751 = 100 + get_unittype_bonus(pplayer, ptile, utype, NULL,
753 city_def_against[idx] = MAX(city_def_against[idx], 1);
755
756 /* What flag-specific bonuses do our units have. */
757 /* We value them less than general defense increment */
758 unit_list_iterate(ptile->units, punit) {
759 const struct unit_type *def = unit_type_get(punit);
760
762 city_data->has_diplomat = TRUE;
763 }
765 /* This is first defender of this type. Check defender type
766 * specific bonuses. */
767
768 /* Skip defenders that have no bonuses at all. Acceptable
769 * side-effect is that we can't consider negative bonuses at
770 * all ("No bonuses" should be better than "negative bonus") */
771 if (def->cache.max_defense_mp_bonus_pct > 0) {
772 unit_type_iterate(utype) {
773 int idx = utype_index(utype);
774 int coeff = def->cache.scramble_coeff[idx];
775 int bonus;
776
777 /* FIXME: consider EFT_FORTIFY_DEFENSE_BONUS */
778 if (coeff) {
779 bonus = coeff / city_def_against[idx] - 100;
780 } else {
781 bonus = def->cache.defense_mp_bonuses_pct[idx];
782 }
783
784 if (bonus > defense_bonuses_pct[idx]) {
785 if (!coeff) {
786 best_non_scramble[idx] = bonus;
787 }
788 defense_bonuses_pct[idx] = bonus;
789 } else if (!coeff) {
790 best_non_scramble[idx] = MAX(best_non_scramble[idx], bonus);
791 }
793 } else {
794 /* Just remember that such a unit exists and hope its bonuses are just 0 */
796 }
797
799 }
801 if (sth_does_not_scramble || unit_list_size(ptile->units) <= 0) {
802 /* Scrambling units tend to be expensive. If we have a barenaked city, we'll
803 * need at least a cheap unit. If we have only scramblers,
804 * maybe it's OK. */
807
810 }
811
812 if (player_is_cpuhog(pplayer)) {
813 assess_turns = 6;
814 } else {
816 }
817
818 omnimap = !has_handicap(pplayer, H_MAP);
819
820 /* Check. */
823 struct unit_list *units;
824
825 if (!adv_is_player_dangerous(pplayer, aplayer)) {
826 continue;
827 }
828 /* Note that we still consider the units of players we are not (yet)
829 * at war with. */
830
832 omnimap);
833
834 if (ul_cb != NULL) {
835 units = ul_cb(aplayer);
836 } else {
837 units = aplayer->units;
838 }
839 unit_list_iterate(units, punit) {
840 int move_time;
841 unsigned int vulnerability;
842 int defbonus_pct;
843 const struct unit_type *utype = unit_type_get(punit);
844 struct unit_type_ai *utai = utype_ai_data(utype, ait);
845
846#ifdef FREECIV_WEB
847 /* freeciv-web ignores danger that is far in distance,
848 * no matter how quickly it would reach us; even if
849 * that's *immediately* over a road type that allows
850 * unlimited movement. */
852
856 /* Too far away. */
857 continue;
858 }
859#endif /* FREECIV_WEB */
860
861 if (!utai->carries_occupiers
862 && !utype_acts_hostile(utype)) {
863 /* Harmless unit. */
864 continue;
865 }
866
867 /* Defender unspecific vulnerability and potential move time */
869 punit, &move_time);
870
872 continue;
873 }
874
875 if (unit_can_take_over(punit) || utai->carries_occupiers) {
876 /* Even if there is no attack strength,
877 * we need ANY protector for the city */
879 if (3 >= move_time) {
880 urgency++;
881 if (1 >= move_time) {
882 city_data->grave_danger++;
883 }
884 }
885 }
886
888 if (defbonus_pct > 100) {
889 defbonus_pct = (defbonus_pct + 100) / 2;
890 }
891 /* Reduce vulnerability for specific bonuses we do have */
892 vulnerability = vulnerability * 100 / (defbonus_pct + 100);
893 /* Pass the order for a new defender type against it
894 * to the scientific advisor, urgency considered */
895 (void) dai_wants_defender_against(ait, nmap, pplayer, pcity, utype,
897
899 city_data->diplomat_threat = TRUE;
900 }
901
902 vulnerability *= vulnerability; /* positive feedback */
903 if (1 < move_time) {
905 }
906
911 if (defender != B_LAST) {
912 danger_reduced[defender] += vulnerability / MAX(move_time, 1);
913 }
914 } else if (best_non_scramble[utype_index(utype)] >= 0) {
915 /* To consider building a defensive building,
916 * build first a defender that gets any profit of it */
918 if (defender != B_LAST) {
919 int danred = vulnerability / MAX(move_time, 1);
920 /* Maybe we can build an improvement
921 * that gets normal defender over scrambling one?
922 * Effectively a sqrt-scale because we don't test how high
923 * the effect is. */
926 danred = danred * (100 + best_non_scramble[utype_index(utype)])
927 / (100 + defense_bonuses_pct[utype_index(utype)]);
928 }
929 danger_reduced[defender] += danred;
930 }
931 }
932
935
937
939
940 if (total_danger) {
941 /* If any hostile player has any dangerous unit that can in any time
942 * reach the city, we consider building walls here, if none yet.
943 * FIXME: this value assumes that walls give x3 defense. */
944 city_data->wallvalue = 90;
945 } else {
946 /* No danger.
947 * This is half of the wallvalue of what danger 1 would produce. */
948 city_data->wallvalue = 5;
949 }
950
951 if (0 < city_data->grave_danger) {
952 /* really, REALLY urgent to defend */
953 urgency += 10 * city_data->grave_danger;
954 }
955
956 /* HACK: This needs changing if multiple improvements provide
957 * this effect. */
958 /* FIXME: Accept only buildings helping unit classes we actually use.
959 * Now we consider any land mover helper suitable. */
960 /* Sum of squared defense ratings */
961 defense = assess_defense_igwall(ait, pcity);
962
963 for (i = 0; i < B_LAST; i++) {
964 if (0 < danger_reduced[i]) {
965 dai_reevaluate_building(pcity, &pcity->server.adv->building_want[i],
966 urgency, danger_reduced[i], defense);
967 }
968 }
969
970 if (has_handicap(pplayer, H_DANGER) && 0 == total_danger) {
971 /* Has to have some danger
972 * Otherwise grave_danger will be ignored. */
973 city_data->danger = 1;
974 } else {
975 city_data->danger = total_danger;
976 }
977 city_data->urgency = urgency;
978
980
981 return urgency;
982}
983
984/**********************************************************************/
989 const struct unit_type *punittype)
990{
992 int attack = punittype->attack_strength;
993 int defense = punittype->defense_strength;
994 int maxbonus_pct = 0;
995 int fp = punittype->firepower;
996
997 /* Sea and helicopters often have their firepower set to low firepower when
998 * defending. We can't have such units as defenders. */
1001 }
1002 if (((struct unit_type_ai *)utype_ai_data(punittype, ait))->low_firepower) {
1004 }
1005 desire *= fp;
1006 desire *= defense;
1007 desire += punittype->move_rate / SINGLE_MOVE;
1008 desire += attack;
1009
1010 maxbonus_pct = punittype->cache.max_defense_mp_bonus_pct;
1011 if (maxbonus_pct > 100) {
1012 maxbonus_pct = (maxbonus_pct + 100) / 2;
1013 }
1014 desire += desire * maxbonus_pct / 100;
1016 desire /= 10; /* But might actually be worth it */
1017 }
1018
1019 return desire;
1020}
1021
1022/**********************************************************************/
1026 const struct unit_type *punittype)
1027{
1029 int attack = punittype->attack_strength;
1030 int defense = punittype->defense_strength;
1031
1032 desire *= punittype->move_rate;
1033 desire *= punittype->firepower;
1034 desire *= attack;
1035 desire += defense;
1037 desire += desire / 2;
1038 }
1040 desire /= 10; /* But might actually be worth it */
1041 }
1043 desire += desire / 2;
1044 }
1046 desire += desire / 4;
1047 }
1048 if (punittype->adv.igwall) {
1049 desire += desire / 4;
1050 }
1051
1052 return desire;
1053}
1054
1055/**********************************************************************/
1060bool dai_process_defender_want(struct ai_type *ait, const struct civ_map *nmap,
1061 struct player *pplayer,
1062 struct city *pcity, unsigned int danger,
1063 struct adv_choice *choice, adv_want extra_want)
1064{
1065 const struct research *presearch = research_get(pplayer);
1066 /* FIXME: We check if the city has *some* defensive structure,
1067 * but not whether the city has a defensive structure against
1068 * any specific attacker. The actual danger may not be mitigated
1069 * by the defense selected... */
1070 bool walls = city_got_defense_effect(pcity, NULL);
1071 /* Technologies we would like to have. */
1073 /* Our favourite unit. */
1074 adv_want best = -1;
1075 struct unit_type *best_unit_type = NULL;
1076 int best_unit_cost = 1;
1077 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1078 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1079 adv_want total_want = danger + extra_want;
1080
1081 memset(tech_desire, 0, sizeof(tech_desire));
1082
1084 adv_want desire; /* How much we want the unit? */
1085
1086 /* Only consider proper defenders - otherwise waste CPU and
1087 * bump tech want needlessly. */
1090 continue;
1091 }
1092
1094
1096 desire /= 2; /* Not good, just ok */
1097 }
1098
1100 /* Causes unhappiness even when in defense, so not a good
1101 * idea for a defender, unless it is _really_ good.
1102 * Downright counter productive, if we want unit just for
1103 * maintaining peace. */
1104 if (danger == 0) {
1105 desire = -50;
1106 } else {
1107 desire /= 2;
1108 }
1109 }
1110
1111 if (desire > 0) {
1112 desire /= POWER_DIVIDER / 2; /* Good enough, no rounding errors. */
1113 desire *= desire;
1114
1116 /* We can build the unit now... */
1117
1118 int build_cost = utype_build_shield_cost(pcity, NULL, punittype);
1119 int limit_cost = pcity->shield_stock + 40;
1120
1122 desire *= city_data->wallvalue;
1123 /* TODO: More use of POWER_FACTOR ! */
1125 }
1126
1128 && build_cost < best_unit_cost)
1129 || ((desire > best
1130 || (ADV_WANTS_EQ(desire, best)
1131 && build_cost <= best_unit_cost))
1132 && (best_unit_type == NULL
1133 /* In case all units are more expensive than limit_cost */
1134 || limit_cost <= pcity->shield_stock + 40))) {
1135 best = desire;
1137 best_unit_cost = build_cost;
1138 }
1140 /* We first need to develop the tech required by the unit... */
1141
1142 /* Cost (shield equivalent) of gaining these techs. */
1143 /* FIXME? Katvrr advises that this should be weighted more heavily in
1144 * big danger. */
1145 int tech_cost = 0;
1146
1151
1152 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1153
1154 /* Contrary to the above, we don't care if walls are actually built
1155 * - we're looking into the future now. */
1157 desire *= city_data->wallvalue;
1159 }
1160
1161 /* Yes, there's some similarity with kill_desire(). */
1162 /* TODO: Explain what shield cost has to do with tech want. */
1166 }
1167 }
1169
1170 if (best == -1) {
1171 CITY_LOG(LOG_DEBUG, pcity, "Ooops - we cannot build any defender!");
1172 }
1173
1174 if (best_unit_type != NULL) {
1176 best *= city_data->wallvalue;
1177 best /= POWER_FACTOR;
1178 }
1179 } else {
1180 best_unit_cost = 100; /* Building impossible is considered costly.
1181 * This should increase want for tech providing
1182 * first defender type. */
1183 }
1184
1185 if (best <= 0) {
1186 best = 1; /* Avoid division by zero below. */
1187 }
1188
1189 /* Update tech_want for appropriate techs for units we want to build. */
1191 if (tech_desire[utype_index(punittype)] > 0) {
1192 /* TODO: Document or fix the algorithm below. I have no idea why
1193 * it is written this way, and the results seem strange to me. - Per */
1195
1197 plr_data->tech_want[advance_index(padv)]
1198 += desire;
1199 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1200 "+ " ADV_WANT_PRINTF " for %s to defend %s",
1201 desire,
1205 }
1207
1208 if (!best_unit_type) {
1209 return FALSE;
1210 }
1211
1212 choice->value.utype = best_unit_type;
1213 choice->want = danger; /* FIXME: Not 'total_want' because of the way callers
1214 * are constructed. They may overwrite this value,
1215 * and then the value will NOT contain 'extra_want'.
1216 * Later we may add 'extra_want', and don't want it
1217 * already included in case this was NOT overwritten. */
1218 choice->type = CT_DEFENDER;
1219
1220 return TRUE;
1221}
1222
1223/**********************************************************************/
1240static void process_attacker_want(struct ai_type *ait,
1241 struct city *pcity,
1242 adv_want value,
1243 const struct unit_type *victim_unit_type,
1244 struct player *victim_player,
1245 int veteran, struct tile *ptile,
1246 struct adv_choice *best_choice,
1247 struct pf_map *ferry_map,
1248 struct unit *boat,
1249 const struct unit_type *boattype)
1250{
1251 struct player *pplayer = city_owner(pcity);
1252 const struct research *presearch = research_get(pplayer);
1253 /* The enemy city. acity == NULL means stray enemy unit */
1254 struct city *acity = tile_city(ptile);
1255 struct pf_parameter parameter;
1256 struct pf_map *pfm;
1257 struct pf_position pos;
1258 const struct unit_type *orig_utype = best_choice->value.utype;
1259 int victim_count = 1;
1260 int needferry = 0;
1261 bool unhap;
1262 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1263 const struct civ_map *nmap = &(wld.map);
1264
1265 /* Has to be initialized to make gcc happy */
1266 struct ai_city *acity_data = NULL;
1267
1269
1270 if (acity != NULL) {
1272 }
1273
1274 if (utype_class(orig_utype)->adv.sea_move == MOVE_NONE
1275 && !boat && boattype != NULL) {
1276 /* Cost of ferry */
1278 }
1279
1280 if (!is_stack_vulnerable(ptile)) {
1281 /* If it is a city, a fortress or an air base,
1282 * we may have to whack it many times */
1284 }
1285
1289 && (U_NOT_OBSOLETED == punittype->obsoleted_by
1290 || !can_city_build_unit_direct(nmap, pcity, punittype->obsoleted_by))
1291 && punittype->attack_strength > 0 /* Or we'll get SIGFPE */) {
1292 /* Values to be computed */
1294 adv_want want;
1295 int move_time;
1296 int vuln;
1297 int veteran_level
1299 &(const struct req_context) {
1300 .player = pplayer,
1301 .city = pcity,
1302 .tile = city_tile(pcity),
1303 .unittype = punittype,
1304 },
1305 NULL,
1307 /* Cost (shield equivalent) of gaining these techs. */
1308 /* FIXME? Katvrr advises that this should be weighted more heavily in big
1309 * danger. */
1310 int tech_cost = 0;
1312 /* See description of kill_desire() for info about this variables. */
1316 punittype->hp);
1317 int tech_dist = 0;
1318
1321
1323 if (tech_dist == 0) {
1325 }
1327
1328 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1329
1330 /* Take into account reinforcements strength */
1331 if (acity) {
1332 attack += acity_data->attack;
1333 }
1334
1335 if (attack == 0) {
1336 /* Yes, it can happen that a military unit has attack = 1,
1337 * for example militia with HP = 1 (in civ1 ruleset). */
1338 continue;
1339 }
1340
1341 attack *= attack;
1342
1344 pplayer);
1345 parameter.omniscience = !has_handicap(pplayer, H_MAP);
1346 pfm = pf_map_new(&parameter);
1347
1348 /* Set the move_time appropriately. */
1349 move_time = -1;
1350 if (NULL != ferry_map) {
1351 struct tile *dest_tile;
1352
1353 if (find_beachhead(pplayer, ferry_map, ptile, punittype,
1354 boattype, &dest_tile, NULL)
1355 && pf_map_position(ferry_map, dest_tile, &pos)) {
1356 move_time = pos.turn;
1359 if (atile == dest_tile) {
1361 move_time += pos.turn;
1362 break;
1363 } else if (atile == ptile) {
1364 /* Reaching directly seems better. */
1366 move_time = pos.turn;
1367 break;
1368 }
1370 }
1371 }
1372
1373 if (-1 == move_time) {
1374 if (pf_map_position(pfm, ptile, &pos)) {
1375 move_time = pos.turn;
1376 } else {
1378 continue;
1379 }
1380 }
1382
1383 /* Estimate strength of the enemy. */
1384
1385 if (victim_unit_type) {
1388 ptile, FALSE, veteran);
1389 } else {
1390 vuln = 0;
1391 }
1392
1393 /* Not bothering to s/!vuln/!pdef/ here for the time being. -- Syela
1394 * (this is noted elsewhere as terrible bug making warships yoyoing)
1395 * as the warships will go to enemy cities hoping that the enemy builds
1396 * something for them to kill. */
1397 if (vuln == 0
1398 && (utype_class(punittype)->adv.land_move == MOVE_NONE
1399 || 0 < utype_fuel(punittype))) {
1400 desire = 0;
1401
1402 } else {
1403 if (acity
1405 && acity_data->invasion.attack > 0
1406 && acity_data->invasion.occupy == 0) {
1408 float finishing_factor = 1;
1409
1412 }
1414 } else {
1415 desire = 0;
1416 }
1417
1418 if (!acity) {
1419 desire = kill_desire(value, attack, bcost, vuln, victim_count);
1420 } else {
1421 adv_want kd;
1422 int city_attack = acity_data->attack * acity_data->attack;
1423
1424 /* See aiunit.c:find_something_to_kill() for comments. */
1425 kd = kill_desire(value, attack,
1426 (bcost + acity_data->bcost), vuln,
1427 victim_count);
1428
1429 if (value * city_attack > acity_data->bcost * vuln) {
1430 kd -= kill_desire(value, city_attack,
1431 acity_data->bcost, vuln,
1432 victim_count);
1433 }
1434
1435 desire = MAX(desire, kd);
1436 }
1437 }
1438
1440 /* We can be possibly making some people of our homecity unhappy - then
1441 * we don't want to travel too far away to our victims. */
1442 /* TODO: Unify the 'unhap' dependency to some common function. */
1445
1446 want = military_amortize(pplayer, pcity, desire, MAX(1, move_time),
1448
1449 if (want > 0) {
1450 if (tech_dist > 0) {
1451 /* This is a future unit, tell the scientist how much we need it */
1453 plr_data->tech_want[advance_index(padv)]
1454 += want;
1455 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1456 "+ " ADV_WANT_PRINTF " for %s vs %s(%d,%d)",
1457 want,
1460 TILE_XY(ptile));
1462 } else if (want > best_choice->want) {
1463 const struct impr_type *impr_req;
1464
1466 /* This is a real unit and we really want it */
1467
1468 CITY_LOG(LOG_DEBUG, pcity, "overriding %s(" ADV_WANT_PRINTF
1469 ") with %s(" ADV_WANT_PRINTF ")"
1470 " [attack=%d,value=" ADV_WANT_PRINTF
1471 ",move_time=%d,vuln=%d,bcost=%d]",
1472 utype_rule_name(best_choice->value.utype),
1473 best_choice->want,
1475 want,
1476 attack, value, move_time, vuln, bcost);
1477
1478 best_choice->value.utype = punittype;
1479 best_choice->want = want;
1480 best_choice->type = CT_ATTACKER;
1482 pcity)))) {
1483 CITY_LOG(LOG_DEBUG, pcity, "cannot build unit %s",
1486 /* Building this unit requires a specific type of improvement.
1487 * So we build this improvement instead. This may not be the
1488 * best behavior. */
1489 CITY_LOG(LOG_DEBUG, pcity, "building %s to build unit %s",
1492 best_choice->value.building = impr_req;
1493 best_choice->want = want;
1494 best_choice->type = CT_BUILDING;
1495 } else {
1496 /* This should never happen? */
1497 CITY_LOG(LOG_DEBUG, pcity, "cannot build %s or unit %s",
1500 }
1501 }
1502 }
1503 }
1505}
1506
1507/**********************************************************************/
1518static struct adv_choice *kill_something_with(struct ai_type *ait,
1519 struct player *pplayer,
1520 struct city *pcity, struct unit *myunit,
1521 struct adv_choice *choice)
1522{
1523 /* Our attack rating (with reinforcements) */
1524 int attack;
1525 /* Benefit from fighting the target */
1527 /* Defender of the target city/tile */
1528 struct unit *pdef;
1529 const struct unit_type *def_type;
1530 struct player *def_owner;
1531 int def_vet; /* Is the defender veteran? */
1532 /* Target coordinates */
1533 struct tile *ptile;
1534 /* Our transport */
1535 struct unit *ferryboat;
1536 /* Our target */
1537 struct city *acity;
1538 /* Type of the boat (real or a future one) */
1539 const struct unit_type *boattype;
1540 struct pf_map *ferry_map = NULL;
1541 int move_time;
1542 struct adv_choice *best_choice;
1543 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1544 struct ai_city *acity_data;
1545 struct civ_map *nmap = &(wld.map);
1546
1548 best_choice->value.utype = unit_type_get(myunit);
1549 best_choice->type = CT_ATTACKER;
1550 adv_choice_set_use(best_choice, "attacker");
1551
1553 && !utype_fuel(unit_type_get(myunit)), choice);
1554
1555 if (city_data->danger != 0 && assess_defense(ait, pcity) == 0) {
1556 /* Defense comes first! */
1557 goto cleanup;
1558 }
1559
1560 best_choice->want = find_something_to_kill(ait, pplayer, myunit, &ptile, NULL,
1561 &ferry_map, &ferryboat,
1562 &boattype, &move_time);
1563 if (NULL == ptile
1564 || ptile == unit_tile(myunit)
1565 || !can_unit_attack_tile(myunit, NULL, ptile)) {
1566 goto cleanup;
1567 }
1568
1569 acity = tile_city(ptile);
1570
1571 if (myunit->id != 0) {
1572 log_error("%s(): non-virtual unit!", __FUNCTION__);
1573 goto cleanup;
1574 }
1575
1577 if (acity) {
1579 attack += acity_data->attack;
1580 }
1581 attack *= attack;
1582
1583 if (NULL != acity) {
1584 /* Rating of enemy defender */
1585 int vulnerability;
1586
1587 if (!POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, city_owner(acity))) {
1588 /* Not a valid target */
1589 goto cleanup;
1590 }
1591
1594 if (1 < move_time && def_type) {
1597 city_owner(acity), ptile,
1598 FALSE, def_vet);
1600 } else {
1601 vulnerability = 0;
1602 benefit = 0;
1603 def_vet = 0;
1604 }
1605
1606 pdef = get_defender(nmap, myunit, ptile, NULL);
1607 if (pdef) {
1609 city_owner(acity), ptile, FALSE,
1610 pdef->veteran);
1611 if (vulnerability < m) {
1613 def_vet = pdef->veteran;
1616 }
1617 }
1618 if (unit_can_take_over(myunit) || acity_data->invasion.occupy > 0) {
1619 /* Bonus for getting the city */
1621 float finishing_factor = 1;
1622
1625 }
1627 }
1628
1629 /* end dealing with cities */
1630 } else {
1631
1632 if (NULL != ferry_map) {
1634 ferry_map = NULL;
1635 }
1636
1637 pdef = get_defender(nmap, myunit, ptile, NULL);
1638 if (!pdef) {
1639 /* Nobody to attack! */
1640 goto cleanup;
1641 }
1642
1644
1646 def_vet = pdef->veteran;
1648 /* end dealing with units */
1649 }
1650
1651 if (NULL == ferry_map) {
1653 def_vet, ptile,
1655 } else {
1656 /* Attract a boat to our city or retain the one that's already here */
1658 best_choice->need_boat = TRUE;
1660 def_vet, ptile,
1661 best_choice, ferry_map, ferryboat, boattype);
1662 }
1663
1664 if (best_choice->want > choice->want) {
1665 /* We want attacker more than what we have selected before */
1666 adv_free_choice(choice);
1667 choice = best_choice;
1668 CITY_LOG(LOG_DEBUG, pcity, "kill_something_with()"
1669 " %s has chosen attacker, %s, want=" ADV_WANT_PRINTF,
1671 utype_rule_name(best_choice->value.utype),
1672 best_choice->want);
1673
1674 if (NULL != ferry_map && !ferryboat) { /* need a new ferry */
1675 /* We might need a new boat even if there are boats free,
1676 * if they are blockaded or in inland seas*/
1678 if (dai_choose_role_unit(ait, pplayer, pcity, choice, CT_ATTACKER,
1679 L_FERRYBOAT, choice->want, TRUE)
1680 && dai_is_ferry_type(choice->value.utype, ait)) {
1681#ifdef FREECIV_DEBUG
1682 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1683
1684 log_debug("kill_something_with() %s has chosen attacker ferry, "
1685 "%s, want=" ADV_WANT_PRINTF ", %d of %d free",
1687 utype_rule_name(choice->value.utype),
1688 choice->want,
1689 ai->stats.available_boats, ai->stats.boats);
1690#endif /* FREECIV_DEBUG */
1691
1692 adv_choice_set_use(choice, "attacker ferry");
1693 } /* else can not build ferries yet */
1694 }
1695 }
1696
1697cleanup:
1698 if (best_choice != choice) {
1699 /* It was not taken to use.
1700 * This hackery needed since 'goto cleanup:' might skip
1701 * sensible points to do adv_free_choice(). */
1703 }
1704 if (NULL != ferry_map) {
1706 }
1707
1708 return choice;
1709}
1710
1711/**********************************************************************/
1717static void dai_unit_consider_bodyguard(struct ai_type *ait,
1718 struct city *pcity,
1719 struct unit_type *punittype,
1720 struct adv_choice *choice)
1721{
1722 if (choice->want < DAI_WANT_MILITARY_EMERGENCY) {
1723 struct player *pplayer = city_owner(pcity);
1724 struct unit *aunit = NULL;
1725 struct city *acity = NULL;
1726 struct unit *virtualunit
1729 punittype));
1730 const adv_want want = look_for_charge(ait, pplayer, virtualunit,
1731 &aunit, &acity);
1732
1733 if (want > choice->want) {
1734 choice->want = want;
1735 choice->value.utype = punittype;
1736 choice->type = CT_DEFENDER;
1737 adv_choice_set_use(choice, "bodyguard");
1738 }
1739
1741 }
1742}
1743
1744/**********************************************************************/
1752static void adjust_ai_unit_choice(struct city *pcity,
1753 struct adv_choice *choice)
1754{
1756
1757 /* Sanity */
1758 if (!is_unit_choice_type(choice->type)
1761 return;
1762 }
1763
1764 /* N.B.: have to check that we haven't already built the building --mck */
1766 choice->value.utype)) != B_LAST
1768 choice->value.building = improvement_by_number(id);
1769 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER,
1771 / TRAIT_DEFAULT_VALUE / 2));
1772 choice->type = CT_BUILDING;
1773 adv_choice_set_use(choice, "veterancy building");
1774 }
1775}
1776
1777/**********************************************************************/
1783 const struct civ_map *nmap,
1784 struct player *pplayer,
1785 struct city *pcity,
1787{
1788 struct adv_data *ai = adv_data_get(pplayer, NULL);
1789 struct unit_type *punittype;
1790 unsigned int our_def, urgency;
1791 struct tile *ptile = pcity->tile;
1792 struct unit *virtualunit;
1793 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1795 bool martial_need = FALSE;
1796 struct adv_choice *choice = adv_new_choice();
1797 bool allow_gold_upkeep;
1798
1799 urgency = assess_danger(ait, nmap, pcity, ul_cb);
1800 /* Changing to quadratic to stop AI from building piles
1801 * of small units -- Syela */
1802 /* It has to be AFTER assess_danger() thanks to wallvalue. */
1804
1805 dai_choose_diplomat_defensive(ait, pplayer, pcity, choice, our_def);
1806
1808 + pcity->feel[CITIZEN_ANGRY][FEELING_NATIONALITY] > 0) {
1810 }
1811
1812 if (!martial_need) {
1814 if (pcity->specialists[sp] > 0
1817 break;
1818 }
1820 }
1821
1822 if (martial_need
1826 1, FEELING_FINAL);
1827 }
1828
1829 /* Otherwise no need to defend yet */
1830 if (city_data->danger != 0 || martial_value > 0) {
1831 struct impr_type *pimprove;
1832 int num_defenders = unit_list_size(ptile->units);
1833 int wall_id, danger;
1834 bool build_walls = TRUE;
1835 bool def_unit_selected = FALSE;
1836 int qdanger = city_data->danger * city_data->danger;
1837
1838 if (qdanger <= 0) {
1839 /* We only need these defenders because of Martial Law value */
1840 danger = 0;
1841 build_walls = FALSE; /* Walls don't provide Martial Law */
1842 } else {
1843 /* First determine the danger. It is measured in percents of our
1844 * defensive strength, capped at 200 + urgency */
1845 if (qdanger >= our_def) {
1846 if (urgency == 0) {
1847 /* Don't waste money */
1848 danger = 100;
1849 } else if (our_def == 0) {
1850 danger = 200 + urgency;
1851 } else {
1852 danger = MIN(200, 100 * qdanger / our_def) + urgency;
1853 }
1854 } else {
1855 danger = 100 * qdanger / our_def;
1856 }
1857
1858 if (pcity->surplus[O_SHIELD] <= 0 && our_def != 0) {
1859 /* Won't be able to support anything */
1860 danger = 0;
1861 }
1862 }
1863
1864 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d urgency=%d danger=%d num_def=%d "
1865 "our_def=%d", urgency, danger, num_defenders, our_def);
1866
1867 if (our_def == 0 && danger > 0) {
1868 /* Build defensive unit first! Walls will help nothing if there's
1869 * nobody behind them. */
1870 if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger, choice,
1871 martial_value)) {
1872 choice->want = DAI_WANT_BELOW_MIL_EMERGENCY + danger;
1873 adv_choice_set_use(choice, "first defender");
1876
1877 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants first defender with " ADV_WANT_PRINTF,
1878 choice->want);
1879 }
1880 }
1881 if (build_walls) {
1882 /* FIXME: 1. Does not consider what kind of future danger is likely, so
1883 * may build SAM batteries when enemy has only land units. */
1884 /* We will build walls if we can and want and (have "enough" defenders or
1885 * can just buy the walls straight away) */
1886
1887 /* HACK: This needs changing if multiple improvements provide
1888 * this effect. */
1890 pimprove = improvement_by_number(wall_id);
1891
1892 if (wall_id != B_LAST
1893 && pcity->server.adv->building_want[wall_id] != 0 && our_def != 0
1896 || (city_data->grave_danger == 0
1897 && pplayer->economic.gold
1898 > impr_buy_gold_cost(pcity, pimprove, pcity->shield_stock)))
1899 && ai_fuzzy(pplayer, TRUE)) {
1900 if (pcity->server.adv->building_want[wall_id] > 0) {
1901 /* NB: great wall is under domestic */
1902 choice->value.building = pimprove;
1903 /* building_want is hacked by assess_danger() */
1904 choice->want = pcity->server.adv->building_want[wall_id];
1905 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER, pplayer)
1906 / TRAIT_DEFAULT_VALUE / 2));
1907 if (urgency == 0 && choice->want > DAI_WANT_BELOW_MIL_EMERGENCY) {
1909 }
1910 choice->type = CT_BUILDING;
1911 adv_choice_set_use(choice, "defense building");
1913 "m_a_c_d wants defense building with " ADV_WANT_PRINTF,
1914 choice->want);
1915 } else {
1917 }
1918 } else {
1920 }
1921 }
1922
1923 /* If our choice isn't defender unit already, consider one */
1924 if (!def_unit_selected) {
1925 if ((danger > 0 && num_defenders <= urgency) || martial_value > 0) {
1926 struct adv_choice uchoice;
1927
1929
1930 /* Consider building defensive units */
1931 if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger,
1933 /* Potential defender found */
1934 if (urgency == 0
1935 && uchoice.value.utype->defense_strength == 1) {
1936 /* FIXME: check other reqs (unit class?) */
1937 if (get_city_bonus(pcity, EFT_HP_REGEN) > 0) {
1938 /* Unlikely */
1939 uchoice.want = MIN(49, danger);
1940 } else {
1941 uchoice.want = MIN(25, danger);
1942 }
1943 } else {
1944 uchoice.want = danger;
1945 }
1946
1947 uchoice.want += martial_value;
1948 if (danger > 0) {
1949 adv_choice_set_use(&uchoice, "defender");
1950 } else {
1951 adv_choice_set_use(&uchoice, "police");
1952 }
1953
1954 if (!build_walls || uchoice.want > choice->want) {
1955 adv_choice_copy(choice, &uchoice);
1956 }
1958
1959 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants %s with desire " ADV_WANT_PRINTF,
1960 utype_rule_name(choice->value.utype),
1961 choice->want);
1962 } else {
1963 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d cannot select defender");
1964 }
1965 } else {
1966 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d does not want defenders");
1967 }
1968 }
1969 } /* Ok, don't need to defend */
1970
1971 if (pcity->surplus[O_SHIELD] <= 0
1973 || pcity->id == ai->wonder_city) {
1974 /* Things we consider below are not life-saving so we don't want to
1975 * build them if our populace doesn't feel like it */
1976 return choice;
1977 }
1978
1979 if (pplayer->economic.tax <= 50 || city_total_unit_gold_upkeep(pcity) <= 0) {
1980 /* Always allow one unit with real gold upkeep (after EFT_UNIT_UPKEEP_FREE_PER_CITY)
1981 * Allow more if economics is so strong that we have not increased taxes. */
1983 } else {
1985 }
1986
1987 /* Consider making a land bodyguard */
1990 if (punittype) {
1992 }
1993
1994 /* If we are in severe danger, don't consider attackers. This is probably
1995 too general. In many cases we will want to buy attackers to counterattack.
1996 -- Per */
1998 && city_data->grave_danger > 0) {
2000 "severe danger (want " ADV_WANT_PRINTF "), force defender",
2001 choice->want);
2002 return choice;
2003 }
2004
2005 /* Consider making an offensive diplomat */
2006 dai_choose_diplomat_offensive(ait, pplayer, pcity, choice);
2007
2008 /* Consider making a sea bodyguard */
2011 if (punittype) {
2013 }
2014
2015 /* Consider making an airplane */
2016 (void) dai_choose_attacker_air(ait, pplayer, pcity, choice, allow_gold_upkeep);
2017
2018 /* Consider making a paratrooper */
2019 dai_choose_paratrooper(ait, pplayer, pcity, choice, allow_gold_upkeep);
2020
2021 /* Check if we want a sailing attacker. Have to put sailing first
2022 before we mung the seamap */
2024 if (punittype) {
2026 pplayer, pcity, punittype,
2028 choice = kill_something_with(ait, pplayer, pcity, virtualunit, choice);
2030 }
2031
2032 /* Consider a land attacker or a ferried land attacker
2033 * (in which case, we might want a ferry before an attacker)
2034 */
2036 if (punittype) {
2038 choice = kill_something_with(ait, pplayer, pcity, virtualunit, choice);
2040 }
2041
2042 /* Consider a hunter */
2043 dai_hunter_choice(ait, pplayer, pcity, choice, allow_gold_upkeep);
2044
2045 /* Consider veteran level enhancing buildings before non-urgent units */
2047
2048 if (choice->want <= 0) {
2049 CITY_LOG(LOGLEVEL_BUILD, pcity, "military advisor has no advice");
2050 } else {
2052 "military advisor choice: %s (want " ADV_WANT_PRINTF ")",
2053 adv_choice_rule_name(choice),
2054 choice->want);
2055 }
2056
2057 return choice;
2058}
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1559
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:241
#define action_enabler_list_iterate_end
Definition actions.h:190
#define action_by_result_iterate_end
Definition actions.h:245
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:188
#define action_id(_act_)
Definition actions.h:422
#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:606
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1113
int adv_unittype_att_rating(const struct unit_type *punittype, int veteran, int moves_left, int hp)
Definition advgoto.c:385
int adv_unit_att_rating(const struct unit *punit)
Definition advgoto.c:396
#define POWER_DIVIDER
Definition advtools.h:32
#define ADV_WANTS_EQ(_w1, _w2)
Definition advtools.h:23
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
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:68
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1240
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:804
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:854
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1596
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:903
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:947
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:970
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1222
#define city_list_iterate(citylist, pcity)
Definition city.h:505
#define city_tile(_pcity_)
Definition city.h:561
@ CITIZEN_ANGRY
Definition city.h:268
@ CITIZEN_UNHAPPY
Definition city.h:267
#define city_owner(_pcity_)
Definition city.h:560
#define city_list_iterate_end
Definition city.h:507
@ FEELING_EFFECT
Definition city.h:278
@ FEELING_FINAL
Definition city.h:281
@ FEELING_NATIONALITY
Definition city.h:279
bool is_stack_vulnerable(const struct tile *ptile)
Definition combat.c:994
int get_fortified_defense_power(const struct unit *attacker, struct unit *defender)
Definition combat.c:786
int get_total_defense_power(const struct unit *attacker, const struct unit *defender)
Definition combat.c:772
int get_total_attack_power(const struct unit *attacker, const struct unit *defender, const struct action *paction)
Definition combat.c:615
struct unit * get_defender(const struct civ_map *nmap, const struct unit *attacker, const struct tile *ptile, const struct action *paction)
Definition combat.c:841
bool can_unit_attack_tile(const struct unit *punit, const struct action *paction, const struct tile *dest_tile)
Definition combat.c:312
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
#define POWER_FACTOR
Definition combat.h:32
char * incite_cost
Definition comments.c:76
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
Impr_type_id dai_find_source_building(struct city *pcity, enum effect_type effect_type, const struct unit_type *utype)
Definition daicity.c:2160
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
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:251
#define TECH_LOG(ait, loglevel, pplayer, padvance, msg,...)
Definition dailog.h:36
struct unit_type * dai_choose_defender_versus(struct city *pcity, struct unit *attacker)
Definition daimilitary.c:90
static enum fc_tristate tactical_req_cb(const struct req_context *context, const struct req_context *other_context, const struct requirement *req, void *data, int n_data)
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)
struct adv_choice * military_advisor_choose_build(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, player_unit_list_getter ul_cb)
static unsigned int assess_danger(struct ai_type *ait, const struct civ_map *nmap, struct city *pcity, player_unit_list_getter ul_cb)
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)
bool dai_process_defender_want(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, unsigned int danger, struct adv_choice *choice, adv_want extra_want)
static void adjust_ai_unit_choice(struct city *pcity, struct adv_choice *choice)
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:74
int assess_defense_quadratic(struct ai_type *ait, struct city *pcity)
static struct unit_type * dai_choose_bodyguard(struct ai_type *ait, const struct civ_map *nmap, struct city *pcity, enum terrain_class tc, enum unit_role_id role, bool allow_gold_upkeep)
static int base_assess_defense_unit(struct city *pcity, struct unit *punit, bool igwall, bool quadratic, int wall_value)
static unsigned int assess_danger_unit(const struct civ_map *nmap, const struct city *pcity, struct pf_reverse_map *pcity_map, const struct unit *punit, int *move_time)
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)
void dai_assess_danger_player(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer)
int assess_defense_unit(struct ai_type *ait, struct city *pcity, struct unit *punit, bool igwall)
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
void dai_choose_paratrooper(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, bool allow_gold_upkeep)
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
struct unit_type * dai_wants_defender_against(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, const struct unit_type *att, int want)
Definition daitech.c:390
bool dai_assess_military_unhappiness(const struct civ_map *nmap, struct city *pcity)
Definition daitools.c:1416
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:1345
adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
Definition daitools.c:117
#define DAI_WANT_BELOW_MIL_EMERGENCY
Definition daitools.h:31
#define DAI_WANT_MILITARY_EMERGENCY
Definition daitools.h:32
adv_want kill_desire(adv_want benefit, int attack, int loss, int vuln, int victim_count)
Definition daiunit.c:342
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:304
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:1062
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Definition daiunit.c:2902
int build_cost_balanced(const struct unit_type *punittype)
Definition daiunit.c:250
adv_want look_for_charge(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct unit **aunit, struct city **acity)
Definition daiunit.c:715
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:1140
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:835
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
Definition daiunit.h:72
#define simple_ai_unit_type_iterate_end
Definition daiunit.h:152
#define simple_ai_unit_type_iterate(_ut)
Definition daiunit.h:146
static void attack(QVariant data1, QVariant data2)
Definition dialogs.cpp:3034
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 const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
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:1031
float adv_want
Definition fc_types.h:1063
int Tech_type_id
Definition fc_types.h:236
int Impr_type_id
Definition fc_types.h:235
@ RPT_POSSIBLE
Definition fc_types.h:532
int action_id
Definition fc_types.h:248
#define ADV_WANT_PRINTF
Definition fc_types.h:1064
int Unit_type_id
Definition fc_types.h:241
@ 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:61
struct world wld
Definition game.c:62
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:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_debug(message,...)
Definition log.h:116
@ LOG_DEBUG
Definition log.h:35
@ LOG_VERBOSE
Definition log.h:34
#define log_error(message,...)
Definition log.h:104
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:675
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:330
bool can_attack_from_non_native(const struct unit_type *utype)
Definition movement.c:226
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:464
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:213
#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)
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)
struct pf_reverse_map * pf_reverse_map_new_for_city(const struct civ_map *nmap, const struct city *pcity, const struct player *attacker, int max_turns, bool omniscient)
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:829
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
static bool player_is_cpuhog(const struct player *pplayer)
Definition player.h:580
enum fc_tristate tri_req_active(const struct req_context *context, const struct req_context *other_context, const struct requirement *req)
enum fc_tristate tri_reqs_cb_active(const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, struct requirement_vector *maybe_reqs, req_tester_cb tester, void *data, int n_data)
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct req_context *other_context, const struct requirement *req, enum req_problem_type prob_type)
enum fc_tristate tri_req_active_turns(int pass, int period, const struct req_context *context, const struct req_context *other_context, const struct requirement *req)
@ 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:338
enum choice_type type
Definition advchoice.h:46
adv_want want
Definition advchoice.h:48
universals_u value
Definition advchoice.h:47
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::@282 stats
int boats
Definition daidata.h:79
int available_boats
Definition daidata.h:80
Definition ai.h:50
Definition city.h:317
struct packet_game_info info
Definition game.h:89
int low_firepower_pearl_harbor
int low_firepower_combat_bonus
struct tile * start_tile
struct city_list * cities
Definition player.h:281
struct player_economic economic
Definition player.h:284
struct adv_data * adv
Definition player.h:334
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:586
int firepower
Definition unittype.h:532
struct unit_type::@91 cache
int scramble_coeff[U_LAST]
Definition unittype.h:590
int defense_mp_bonuses_pct[U_LAST]
Definition unittype.h:589
Definition unit.h:140
int id
Definition unit.h:147
int hp
Definition unit.h:153
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:142
struct unit_adv * adv
Definition unit.h:239
int veteran
Definition unit.h:154
enum universals_n kind
Definition fc_types.h:608
universals_u value
Definition fc_types.h:607
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:105
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:553
enum citystatus_type citystatus
Definition fc_types.h:563
const struct impr_type * building
Definition fc_types.h:546
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2518
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:383
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1661
bool is_special_unit(const struct unit *punit)
Definition unit.c:350
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1766
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2502
#define unit_tile(_pu)
Definition unit.h:404
#define unit_owner(_pu)
Definition unit.h:403
#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:205
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1474
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1490
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1584
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2505
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:393
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:196
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:270
void * utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
Definition unittype.c:2745
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:282
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1444
bool utype_acts_hostile(const struct unit_type *putype)
Definition unittype.c:449
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:377
#define utype_class(_t_)
Definition unittype.h:756
#define utype_fuel(ptype)
Definition unittype.h:846
#define unit_tech_reqs_iterate_end
Definition unittype.h:888
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:882
@ 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:624
#define unit_type_iterate(_p)
Definition unittype.h:862
#define U_LAST
Definition unittype.h:40
#define unit_type_iterate_end
Definition unittype.h:869
#define U_NOT_OBSOLETED
Definition unittype.h:535