Freeciv-3.4
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 "daiair.h"
57#include "daicity.h"
58#include "daidata.h"
59#include "daidiplomat.h"
60#include "daieffects.h"
61#include "daiferry.h"
62#include "daihunter.h"
63#include "dailog.h"
64#include "daiparadrop.h"
65#include "daiplayer.h"
66#include "daitech.h"
67#include "daitools.h"
68
69#include "daimilitary.h"
70
71/* Size 1 city gets destroyed when conquered. It's still a good thing
72 * stop enemy from having it. */
73#define CITY_CONQUEST_WORTH(_city_, _data_) \
74 (_data_->worth * 0.9 + (city_size_get(_city_) - 0.5) * 10)
75
76static unsigned int assess_danger(struct ai_type *ait,
77 const struct civ_map *nmap,
78 struct city *pcity,
80
82 const struct unit_type *punittype);
84 const struct unit_type *punittype);
85
86/**********************************************************************/
90 struct unit *attacker)
91{
92 struct unit_type *bestunit = NULL;
93 double best = 0;
95 struct player *pplayer = city_owner(pcity);
96 struct civ_map *nmap = &(wld.map);
97
100 int fpatt, fpdef, defense, attack;
102 struct unit *defender;
106
107 defender = unit_virtual_create(pplayer, pcity, punittype, veteran);
108 defense = get_total_defense_power(attacker, defender);
109 attack = get_total_attack_power(attacker, defender, NULL);
110 get_modified_firepower(nmap, attacker, defender, &fpatt, &fpdef);
111
112 /* Greg's algorithm. loss is the average number of health lost by
113 * defender. If loss > attacker's hp then we should win the fight,
114 * which is always a good thing, since we avoid shield loss. */
115 loss = (double) defense * punittype->hp * fpdef / (attack * fpatt);
116 want = (loss + MAX(0, loss - attacker->hp)) / cost;
117
118#ifdef NEVER
119 CITY_LOG(LOG_DEBUG, pcity, "desire for %s against %s(%d,%d) is %.2f",
121 unit_rule_name(attacker),
122 TILE_XY(attacker->tile), want);
123#endif /* NEVER */
124
125 if (want > best || (ADV_WANTS_EQ(want, best)
126 && cost <= best_cost)) {
127 best = want;
129 best_cost = cost;
130 }
131 unit_virtual_destroy(defender);
132 }
134
135 return bestunit;
136}
137
138/**********************************************************************/
143static struct unit_type *dai_choose_attacker(struct ai_type *ait,
144 const struct civ_map *nmap,
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
156 && utype_upkeep_cost(putype, nullptr, 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
206 && utype_upkeep_cost(putype, nullptr, pplayer, O_GOLD) > 0) {
207 continue;
208 }
209
210 /* Only consider units of same move type */
211 if ((tc == TC_LAND && utype_class(putype)->adv.land_move == MOVE_NONE)
212 || (tc == TC_OCEAN
213 && utype_class(putype)->adv.sea_move == MOVE_NONE)) {
214 continue;
215 }
216
217 /* Now find best */
220
221 if (desire > best
224 best = desire;
225 bestid = putype;
226 }
227 }
229
230 return bestid;
231}
232
233/**********************************************************************/
236static int base_assess_defense_unit(struct city *pcity, struct unit *punit,
237 bool igwall, bool quadratic,
238 int wall_value)
239{
240 int defense;
241 int fp;
242
243 if (is_special_unit(punit)) {
244 return 0;
245 }
246
250 /* Attacker firepower doubled, defender firepower set to
251 * game.info.low_firepower_pearl_harbor at max. */
252 defense *= MIN(fp, game.info.low_firepower_pearl_harbor);
253 defense /= 2;
254 } else {
255 defense *= fp;
256 }
257
258 defense /= POWER_DIVIDER;
259
260 if (quadratic) {
261 defense *= defense;
262 }
263
264 if (pcity != NULL && !igwall && city_got_defense_effect(pcity, NULL)) {
265 /* FIXME: We checked if city got defense effect against *some*
266 * unit type. Sea unit danger might cause us to build defenses
267 * against air units... */
268
269 /* TODO: What about wall_value < 10? Do we really want walls to
270 * result in decrease in the returned value? */
271 defense *= wall_value;
272 defense /= 10;
273 }
274
275 return defense;
276}
277
278/**********************************************************************/
282{
283 int defense = 0, walls = 0;
284 /* This can be an arg if needed, but we don't need to change it now. */
285 const bool igwall = FALSE;
286 struct ai_city *city_data = def_ai_city_data(pcity, ait);
287
288 /* wallvalue = 10, walls = 10,
289 * wallvalue = 40, walls = 20,
290 * wallvalue = 90, walls = 30 */
291
292 while (walls * walls < city_data->wallvalue * 10) {
293 walls++;
294 }
295
297 defense += base_assess_defense_unit(pcity, punit, igwall, FALSE,
298 walls);
300
301 if (defense > 1<<12) {
302 CITY_LOG(LOG_VERBOSE, pcity, "Overflow danger in assess_defense_quadratic:"
303 " %d", defense);
304 if (defense > 1<<15) {
305 defense = 1<<15; /* more defense than we know what to do with! */
306 }
307 }
308
309 return defense * defense;
310}
311
312/**********************************************************************/
315int assess_defense_unit(struct ai_type *ait, struct city *pcity,
316 struct unit *punit, bool igwall)
317{
318 return base_assess_defense_unit(pcity, punit, igwall, TRUE,
320}
321
322/**********************************************************************/
329static int assess_defense_backend(struct ai_type *ait, struct city *pcity,
330 bool igwall)
331{
332 /* Estimate of our total city defensive might */
333 int defense = 0;
334
336 defense += assess_defense_unit(ait, pcity, punit, igwall);
338
339 return defense;
340}
341
342/**********************************************************************/
345int assess_defense(struct ai_type *ait, struct city *pcity)
346{
347 return assess_defense_backend(ait, pcity, FALSE);
348}
349
350/**********************************************************************/
354static int assess_defense_igwall(struct ai_type *ait, struct city *pcity)
355{
356 return assess_defense_backend(ait, pcity, TRUE);
357}
358
359/**********************************************************************/
365static enum fc_tristate
367 const struct req_context *other_context,
368 const struct requirement *req,
369 void *data, int n_data)
370{
371 switch (req->source.kind) {
372 case VUT_IMPROVEMENT:
373 case VUT_SITE:
374 {
375 const struct impr_type *b = req->source.value.building;
376
377 /* FIXME: in actor_reqs, may allow attack _from_ a city with... */
378 if (req->survives || NULL == context->city || is_great_wonder(b)
379 || !city_has_building(context->city, b) || b->sabotage <= 0) {
381 }
382 /* Else may be sabotaged */
383 }
385 case VUT_UNITSTATE:
386 case VUT_ACTIVITY:
387 case VUT_MINSIZE:
390 case VUT_MINHP:
391 case VUT_MINMOVES:
392 case VUT_COUNTER:
393 /* Can be changed back or forth quickly */
394 return TRI_MAYBE;
395 case VUT_MINVETERAN:
396 /* Can be changed forth but not back */
400 case VUT_NATIONALITY:
401 /* Can be changed back but hardly forth (foreign citizens reduced first) */
402 switch (tri_req_active(context, other_context, req)) {
403 case TRI_NO:
404 return req->present ? TRI_NO : TRI_MAYBE;
405 case TRI_YES:
406 return req->present ? TRI_MAYBE : TRI_YES;
407 default:
408 return TRI_MAYBE;
409 }
410 case VUT_DIPLREL:
411 case VUT_DIPLREL_TILE:
415 /* If the attack happens, there is a diplrel that allows it */
416 return TRI_YES;
417 case VUT_AGE:
418 case VUT_FORM_AGE:
419 case VUT_MINCALFRAG:
420 case VUT_MINYEAR:
421 /* If it is not near, won't change */
422 return tri_req_active_turns(n_data, 5 /* WAG */,
423 context, other_context, req);
424 case VUT_CITYSTATUS:
427 return TRI_MAYBE;
428 }
430 case VUT_UTYPE:
431 case VUT_UTFLAG:
432 case VUT_UCLASS:
433 case VUT_UCFLAG:
434 /* FIXME: Support converting siege machines (needs hard reqs checked) */
435 case VUT_ACTION:
436 case VUT_OTYPE:
437 case VUT_SPECIALIST:
438 case VUT_EXTRAFLAG:
439 case VUT_MINLATITUDE:
440 case VUT_MAXLATITUDE:
441 case VUT_AI_LEVEL:
442 case VUT_CITYTILE:
443 case VUT_STYLE:
444 case VUT_TOPO:
445 case VUT_WRAP:
447 case VUT_NATION:
448 case VUT_NATIONGROUP:
449 case VUT_ADVANCE:
450 case VUT_TECHFLAG:
451 case VUT_GOVERNMENT:
452 case VUT_GOVFLAG:
453 case VUT_ACHIEVEMENT:
454 case VUT_IMPR_GENUS:
455 case VUT_IMPR_FLAG:
456 case VUT_PLAYER_FLAG:
457 case VUT_PLAYER_STATE:
458 case VUT_MINCULTURE:
459 case VUT_MINTECHS:
460 case VUT_FUTURETECHS:
461 case VUT_MINCITIES:
463 case VUT_ROADFLAG:
464 case VUT_TERRAIN:
465 case VUT_EXTRA:
466 case VUT_TILEDEF:
467 case VUT_GOOD:
468 case VUT_TERRAINCLASS:
469 case VUT_TERRFLAG:
470 case VUT_TERRAINALTER:
473 case VUT_TILE_REL:
474 case VUT_NONE:
476 case VUT_COUNT:
477 /* Not implemented. */
478 break;
479 }
481
482 return TRI_NO;
483}
484
485/**********************************************************************/
492static bool
494 const struct unit *actor,
495 const struct city *pcity,
496 int turns)
497{
498 const struct player *target_player = city_owner(pcity),
500 const struct unit_type *utype = unit_type_get(actor);
501 const struct req_context target_ctx = {
503 .city = pcity,
505 }, actor_ctx = {
506 .player = actor_player,
507 .unit = actor,
508 .unittype = utype
509 };
510
511 if (!utype_can_do_action(utype, wanted_action)) {
512 return FALSE;
513 }
515 enabler) {
516 /* We assume that we could build or move units into the city
517 * that are not present there yet */
519 &enabler->actor_reqs, NULL,
520 tactical_req_cb, NULL, turns)
521 &&
523 &enabler->target_reqs, NULL,
524 tactical_req_cb, NULL, turns)) {
525 return TRUE;
526 }
528
529 return FALSE;
530}
531
532/**********************************************************************/
535static unsigned int assess_danger_unit(const struct civ_map *nmap,
536 const struct city *pcity,
538 const struct unit *punit,
539 int *move_time)
540{
541 struct pf_position pos;
542 const struct unit_type *punittype = unit_type_get(punit);
543 const struct tile *ptile = city_tile(pcity);
544 const struct player *uowner = unit_owner(punit);
545 const struct unit *ferry;
546 unsigned int danger;
547 int amod = -99, dmod;
548 bool attack_danger = FALSE;
549
551
554 && 0 < punittype->paratroopers_range) {
556 / punittype->paratroopers_range);
557 }
558
561 || *move_time > pos.turn)) {
562 *move_time = pos.turn;
563 }
564
566 && (ferry = unit_transport_get(punit))
569 || *move_time > pos.turn)) {
570 *move_time = pos.turn;
572 (*move_time)++;
573 }
574 }
575 }
576
577 if (PF_IMPOSSIBLE_MC == *move_time) {
578 return 0;
579 }
580 if (!is_native_tile(punittype, ptile)
582 return 0;
583 }
585 return 0;
586 }
587
588 /* Find the worst attack action to expect */
590 /* Is it possible that punit will do action id to the city? */
591 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
592
594 int b;
595
597
599 if (b > amod) {
600 amod = b;
601 }
602 }
604
605 /* FIXME: it's a dummy support for anti-bombard defense just to do something against
606 * approaching bombarders. Some better logic is needed, see OSDN#41778 */
607 if (!attack_danger) {
609 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
610
612 *move_time)) {
613 int b;
614
616
618 if (b > amod) {
619 amod = b;
620 }
621 }
623 /* Here something should be done cuz the modifier affects
624 * more than one unit but not their full hp, but is not done yet...*/
625 }
626 if (!attack_danger) {
627 /* If the unit is dangerous, it's not about its combat strength */
628 return 0;
629 }
630
631 danger = adv_unit_att_rating(punit);
632 dmod = 100 + get_unittype_bonus(city_owner(pcity), ptile,
634 return danger * (amod + 100) / MAX(dmod, 1);
635}
636
637/**********************************************************************/
643 const struct civ_map *nmap,
644 struct player *pplayer)
645{
646 /* Do nothing if game is not running */
647 if (S_S_RUNNING == server_state()) {
648 city_list_iterate(pplayer->cities, pcity) {
649 (void) assess_danger(ait, nmap, pcity, NULL);
651 }
652}
653
654/**********************************************************************/
673static void dai_reevaluate_building(struct city *pcity, adv_want *value,
674 unsigned int urgency, unsigned int danger,
675 int defense)
676{
677 if (*value == 0 || danger <= 0) {
678 return;
679 }
680
681 *value = MAX(*value, 100 + urgency); /* default */
682
683 if (urgency > 0 && danger > defense * 2) {
684 *value += 100;
685 } else if (defense != 0 && danger > defense) {
686 *value = MAX(danger * 100 / defense, *value);
687 }
688}
689
690/**********************************************************************/
708static unsigned int assess_danger(struct ai_type *ait,
709 const struct civ_map *nmap,
710 struct city *pcity,
712{
713 struct player *pplayer = city_owner(pcity);
714 struct tile *ptile = city_tile(pcity);
715 struct ai_city *city_data = def_ai_city_data(pcity, ait);
716 /* How much such danger there is that building would help against. */
717 unsigned int danger_reduced[B_LAST];
718 int i;
719 int defender;
720 unsigned int urgency = 0;
721 int defense;
722 int total_danger = 0;
723
724 /* TODO: Presumably most, or even all, of these arrays
725 * could be of size game.control.num_unit_types instead
726 * of full U_LAST */
732 int assess_turns;
733 bool omnimap;
734
736
737 /* Initialize data. */
739 if (has_handicap(pplayer, H_DANGER)) {
740 /* Always thinks that city is in grave danger */
741 city_data->grave_danger = 1;
742 } else {
743 city_data->grave_danger = 0;
744 }
745 city_data->diplomat_threat = FALSE;
746 city_data->has_diplomat = FALSE;
747
748 unit_type_iterate(utype) {
749 int idx = utype_index(utype);
750
751 defense_bonuses_pct[idx] = 0;
753 best_non_scramble[idx] = -1;
754 /* FIXME: cache it somewhere? */
756 = 100 + get_unittype_bonus(pplayer, ptile, utype, NULL,
758 city_def_against[idx] = MAX(city_def_against[idx], 1);
760
761 /* What flag-specific bonuses do our units have. */
762 /* We value them less than general defense increment */
763 unit_list_iterate(ptile->units, punit) {
764 const struct unit_type *def = unit_type_get(punit);
765
767 city_data->has_diplomat = TRUE;
768 }
770 /* This is first defender of this type. Check defender type
771 * specific bonuses. */
772
773 /* Skip defenders that have no bonuses at all. Acceptable
774 * side-effect is that we can't consider negative bonuses at
775 * all ("No bonuses" should be better than "negative bonus") */
776 if (def->cache.max_defense_mp_bonus_pct > 0) {
777 unit_type_iterate(utype) {
778 int idx = utype_index(utype);
779 int coeff = def->cache.scramble_coeff[idx];
780 int bonus;
781
782 /* FIXME: consider EFT_FORTIFY_DEFENSE_BONUS */
783 if (coeff) {
784 bonus = coeff / city_def_against[idx] - 100;
785 } else {
786 bonus = def->cache.defense_mp_bonuses_pct[idx];
787 }
788
789 if (bonus > defense_bonuses_pct[idx]) {
790 if (!coeff) {
791 best_non_scramble[idx] = bonus;
792 }
793 defense_bonuses_pct[idx] = bonus;
794 } else if (!coeff) {
795 best_non_scramble[idx] = MAX(best_non_scramble[idx], bonus);
796 }
798 } else {
799 /* Just remember that such a unit exists and hope its bonuses are just 0 */
801 }
802
804 }
806 if (sth_does_not_scramble || unit_list_size(ptile->units) <= 0) {
807 /* Scrambling units tend to be expensive. If we have a barenaked city, we'll
808 * need at least a cheap unit. If we have only scramblers,
809 * maybe it's OK. */
812
815 }
816
817 if (player_is_cpuhog(pplayer)) {
818 assess_turns = 6;
819 } else {
821 }
822
823 omnimap = !has_handicap(pplayer, H_MAP);
824
825 /* Check. */
828 struct unit_list *units;
829
830 if (!adv_is_player_dangerous(pplayer, aplayer)) {
831 continue;
832 }
833 /* Note that we still consider the units of players we are not (yet)
834 * at war with. */
835
837 omnimap);
838
839 if (ul_cb != NULL) {
840 units = ul_cb(aplayer);
841 } else {
842 units = aplayer->units;
843 }
844 unit_list_iterate(units, punit) {
845 int move_time;
846 unsigned int vulnerability;
847 int defbonus_pct;
848 const struct unit_type *utype = unit_type_get(punit);
849 struct unit_type_ai *utai = utype_ai_data(utype, ait);
850
851#ifdef FREECIV_WEB
852 /* freeciv-web ignores danger that is far in distance,
853 * no matter how quickly it would reach us; even if
854 * that's *immediately* over a road type that allows
855 * unlimited movement. */
857
861 /* Too far away. */
862 continue;
863 }
864#endif /* FREECIV_WEB */
865
866 if (!utai->carries_occupiers
867 && !utype_acts_hostile(utype)) {
868 /* Harmless unit. */
869 continue;
870 }
871
872 /* Defender unspecific vulnerability and potential move time */
874 punit, &move_time);
875
877 continue;
878 }
879
880 if (unit_can_take_over(punit) || utai->carries_occupiers) {
881 /* Even if there is no attack strength,
882 * we need ANY protector for the city */
884 if (3 >= move_time) {
885 urgency++;
886 if (1 >= move_time) {
887 city_data->grave_danger++;
888 }
889 }
890 }
891
893 if (defbonus_pct > 100) {
894 defbonus_pct = (defbonus_pct + 100) / 2;
895 }
896 /* Reduce vulnerability for specific bonuses we do have */
897 vulnerability = vulnerability * 100 / (defbonus_pct + 100);
898 /* Pass the order for a new defender type against it
899 * to the scientific advisor, urgency considered */
900 (void) dai_wants_defender_against(ait, nmap, pplayer, pcity, utype,
902
904 city_data->diplomat_threat = TRUE;
905 }
906
907 vulnerability *= vulnerability; /* positive feedback */
908 if (1 < move_time) {
910 }
911
916 if (defender != B_LAST) {
917 danger_reduced[defender] += vulnerability / MAX(move_time, 1);
918 }
919 } else if (best_non_scramble[utype_index(utype)] >= 0) {
920 /* To consider building a defensive building,
921 * build first a defender that gets any profit of it */
923 if (defender != B_LAST) {
924 int danred = vulnerability / MAX(move_time, 1);
925 /* Maybe we can build an improvement
926 * that gets normal defender over scrambling one?
927 * Effectively a sqrt-scale because we don't test how high
928 * the effect is. */
931 danred = danred * (100 + best_non_scramble[utype_index(utype)])
932 / (100 + defense_bonuses_pct[utype_index(utype)]);
933 }
934 danger_reduced[defender] += danred;
935 }
936 }
937
940
942
944
945 if (total_danger) {
946 /* If any hostile player has any dangerous unit that can in any time
947 * reach the city, we consider building walls here, if none yet.
948 * FIXME: this value assumes that walls give x3 defense. */
949 city_data->wallvalue = 90;
950 } else {
951 /* No danger.
952 * This is half of the wallvalue of what danger 1 would produce. */
953 city_data->wallvalue = 5;
954 }
955
956 if (0 < city_data->grave_danger) {
957 /* really, REALLY urgent to defend */
958 urgency += 10 * city_data->grave_danger;
959 }
960
961 /* HACK: This needs changing if multiple improvements provide
962 * this effect. */
963 /* FIXME: Accept only buildings helping unit classes we actually use.
964 * Now we consider any land mover helper suitable. */
965 /* Sum of squared defense ratings */
966 defense = assess_defense_igwall(ait, pcity);
967
968 for (i = 0; i < B_LAST; i++) {
969 if (0 < danger_reduced[i]) {
970 dai_reevaluate_building(pcity, &pcity->server.adv->building_want[i],
971 urgency, danger_reduced[i], defense);
972 }
973 }
974
975 if (has_handicap(pplayer, H_DANGER) && 0 == total_danger) {
976 /* Has to have some danger
977 * Otherwise grave_danger will be ignored. */
978 city_data->danger = 1;
979 } else {
980 city_data->danger = total_danger;
981 }
982 city_data->urgency = urgency;
983
985
986 return urgency;
987}
988
989/**********************************************************************/
994 const struct unit_type *punittype)
995{
997 int attack = punittype->attack_strength;
998 int defense = punittype->defense_strength;
999 int maxbonus_pct = 0;
1000 int fp = punittype->firepower;
1001
1002 /* Sea and helicopters often have their firepower set to low firepower when
1003 * defending. We can't have such units as defenders. */
1006 }
1007 if (((struct unit_type_ai *)utype_ai_data(punittype, ait))->low_firepower) {
1009 }
1010 desire *= fp;
1011 desire *= defense;
1012 desire += punittype->move_rate / SINGLE_MOVE;
1013 desire += attack;
1014
1015 maxbonus_pct = punittype->cache.max_defense_mp_bonus_pct;
1016 if (maxbonus_pct > 100) {
1017 maxbonus_pct = (maxbonus_pct + 100) / 2;
1018 }
1019 desire += desire * maxbonus_pct / 100;
1021 desire /= 10; /* But might actually be worth it */
1022 }
1023
1024 return desire;
1025}
1026
1027/**********************************************************************/
1031 const struct unit_type *punittype)
1032{
1034 int attack = punittype->attack_strength;
1035 int defense = punittype->defense_strength;
1036
1037 desire *= punittype->move_rate;
1038 desire *= punittype->firepower;
1039 desire *= attack;
1040 desire += defense;
1042 desire += desire / 2;
1043 }
1045 desire /= 10; /* But might actually be worth it */
1046 }
1048 desire += desire / 2;
1049 }
1051 desire += desire / 4;
1052 }
1053 if (punittype->adv.igwall) {
1054 desire += desire / 4;
1055 }
1056
1057 return desire;
1058}
1059
1060/**********************************************************************/
1065bool dai_process_defender_want(struct ai_type *ait, const struct civ_map *nmap,
1066 struct player *pplayer,
1067 struct city *pcity, unsigned int danger,
1068 struct adv_choice *choice, adv_want extra_want)
1069{
1070 const struct research *presearch = research_get(pplayer);
1071 /* FIXME: We check if the city has *some* defensive structure,
1072 * but not whether the city has a defensive structure against
1073 * any specific attacker. The actual danger may not be mitigated
1074 * by the defense selected... */
1075 bool walls = city_got_defense_effect(pcity, NULL);
1076 /* Technologies we would like to have. */
1078 /* Our favourite unit. */
1079 adv_want best = -1;
1080 struct unit_type *best_unit_type = NULL;
1081 int best_unit_cost = 1;
1082 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1083 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1084 adv_want total_want = danger + extra_want;
1085
1086 memset(tech_desire, 0, sizeof(tech_desire));
1087
1089 adv_want desire; /* How much we want the unit? */
1090
1091 /* Only consider proper defenders - otherwise waste CPU and
1092 * bump tech want needlessly. */
1095 continue;
1096 }
1097
1099
1101 desire /= 2; /* Not good, just ok */
1102 }
1103
1105 /* Causes unhappiness even when in defense, so not a good
1106 * idea for a defender, unless it is _really_ good.
1107 * Downright counter productive, if we want unit just for
1108 * maintaining peace. */
1109 if (danger == 0) {
1110 desire = -50;
1111 } else {
1112 desire /= 2;
1113 }
1114 }
1115
1116 if (desire > 0) {
1117 desire /= POWER_DIVIDER / 2; /* Good enough, no rounding errors. */
1118 desire *= desire;
1119
1121 /* We can build the unit now... */
1122
1123 int build_cost = utype_build_shield_cost(pcity, NULL, punittype);
1124 int limit_cost = pcity->shield_stock + 40;
1125
1127 desire *= city_data->wallvalue;
1128 /* TODO: More use of POWER_FACTOR ! */
1130 }
1131
1133 && build_cost < best_unit_cost)
1134 || ((desire > best
1135 || (ADV_WANTS_EQ(desire, best)
1136 && build_cost <= best_unit_cost))
1137 && (best_unit_type == NULL
1138 /* In case all units are more expensive than limit_cost */
1139 || limit_cost <= pcity->shield_stock + 40))) {
1140 best = desire;
1142 best_unit_cost = build_cost;
1143 }
1145 /* We first need to develop the tech required by the unit... */
1146
1147 /* Cost (shield equivalent) of gaining these techs. */
1148 /* FIXME? Katvrr advises that this should be weighted more heavily in
1149 * big danger. */
1150 int tech_cost = 0;
1151
1156
1157 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1158
1159 /* Contrary to the above, we don't care if walls are actually built
1160 * - we're looking into the future now. */
1162 desire *= city_data->wallvalue;
1164 }
1165
1166 /* Yes, there's some similarity with kill_desire(). */
1167 /* TODO: Explain what shield cost has to do with tech want. */
1171 }
1172 }
1174
1175 if (best == -1) {
1176 CITY_LOG(LOG_DEBUG, pcity, "Ooops - we cannot build any defender!");
1177 }
1178
1179 if (best_unit_type != NULL) {
1181 best *= city_data->wallvalue;
1182 best /= POWER_FACTOR;
1183 }
1184 } else {
1185 best_unit_cost = 100; /* Building impossible is considered costly.
1186 * This should increase want for tech providing
1187 * first defender type. */
1188 }
1189
1190 if (best <= 0) {
1191 best = 1; /* Avoid division by zero below. */
1192 }
1193
1194 /* Update tech_want for appropriate techs for units we want to build. */
1196 if (tech_desire[utype_index(punittype)] > 0) {
1197 /* TODO: Document or fix the algorithm below. I have no idea why
1198 * it is written this way, and the results seem strange to me. - Per */
1200
1202 plr_data->tech_want[advance_index(padv)]
1203 += desire;
1204 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1205 "+ " ADV_WANT_PRINTF " for %s to defend %s",
1206 desire,
1210 }
1212
1213 if (!best_unit_type) {
1214 return FALSE;
1215 }
1216
1217 choice->value.utype = best_unit_type;
1218 choice->want = danger; /* FIXME: Not 'total_want' because of the way callers
1219 * are constructed. They may overwrite this value,
1220 * and then the value will NOT contain 'extra_want'.
1221 * Later we may add 'extra_want', and don't want it
1222 * already included in case this was NOT overwritten. */
1223 choice->type = CT_DEFENDER;
1224
1225 return TRUE;
1226}
1227
1228/**********************************************************************/
1245static void process_attacker_want(struct ai_type *ait,
1246 struct city *pcity,
1247 adv_want value,
1248 const struct unit_type *victim_unit_type,
1249 struct player *victim_player,
1250 int veteran, struct tile *ptile,
1251 struct adv_choice *best_choice,
1252 struct pf_map *ferry_map,
1253 struct unit *boat,
1254 const struct unit_type *boattype)
1255{
1256 struct player *pplayer = city_owner(pcity);
1257 const struct research *presearch = research_get(pplayer);
1258 /* The enemy city. acity == NULL means stray enemy unit */
1259 struct city *acity = tile_city(ptile);
1260 struct pf_parameter parameter;
1261 struct pf_map *pfm;
1262 struct pf_position pos;
1263 const struct unit_type *orig_utype = best_choice->value.utype;
1264 int victim_count = 1;
1265 int needferry = 0;
1266 bool unhap;
1267 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1268 const struct civ_map *nmap = &(wld.map);
1269
1270 /* Has to be initialized to make gcc happy */
1271 struct ai_city *acity_data = NULL;
1272
1274
1275 if (acity != NULL) {
1277 }
1278
1279 if (utype_class(orig_utype)->adv.sea_move == MOVE_NONE
1280 && !boat && boattype != NULL) {
1281 /* Cost of ferry */
1283 }
1284
1285 if (!is_stack_vulnerable(ptile)) {
1286 /* If it is a city, a fortress or an air base,
1287 * we may have to whack it many times */
1289 }
1290
1294 && (U_NOT_OBSOLETED == punittype->obsoleted_by
1295 || !can_city_build_unit_direct(nmap, pcity, punittype->obsoleted_by))
1296 && punittype->attack_strength > 0 /* Or we'll get SIGFPE */) {
1297 /* Values to be computed */
1299 adv_want want;
1300 int move_time;
1301 int vuln;
1302 int veteran_level
1304 &(const struct req_context) {
1305 .player = pplayer,
1306 .city = pcity,
1307 .tile = city_tile(pcity),
1308 .unittype = punittype,
1309 },
1310 NULL,
1312 /* Cost (shield equivalent) of gaining these techs. */
1313 /* FIXME? Katvrr advises that this should be weighted more heavily in big
1314 * danger. */
1315 int tech_cost = 0;
1317 /* See description of kill_desire() for info about this variables. */
1321 punittype->hp);
1322 int tech_dist = 0;
1323
1326
1328 if (tech_dist == 0) {
1330 }
1332
1333 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1334
1335 /* Take into account reinforcements strength */
1336 if (acity) {
1337 attack += acity_data->attack;
1338 }
1339
1340 if (attack == 0) {
1341 /* Yes, it can happen that a military unit has attack = 1,
1342 * for example militia with HP = 1 (in civ1 ruleset). */
1343 continue;
1344 }
1345
1346 attack *= attack;
1347
1349 pplayer);
1350 parameter.omniscience = !has_handicap(pplayer, H_MAP);
1351 pfm = pf_map_new(&parameter);
1352
1353 /* Set the move_time appropriately. */
1354 move_time = -1;
1355 if (NULL != ferry_map) {
1356 struct tile *dest_tile;
1357
1358 if (find_beachhead(pplayer, ferry_map, ptile, punittype,
1359 boattype, &dest_tile, NULL)
1360 && pf_map_position(ferry_map, dest_tile, &pos)) {
1361 move_time = pos.turn;
1364 if (atile == dest_tile) {
1366 move_time += pos.turn;
1367 break;
1368 } else if (atile == ptile) {
1369 /* Reaching directly seems better. */
1371 move_time = pos.turn;
1372 break;
1373 }
1375 }
1376 }
1377
1378 if (-1 == move_time) {
1379 if (pf_map_position(pfm, ptile, &pos)) {
1380 move_time = pos.turn;
1381 } else {
1383 continue;
1384 }
1385 }
1387
1388 /* Estimate strength of the enemy. */
1389
1390 if (victim_unit_type) {
1393 ptile, FALSE, veteran);
1394 } else {
1395 vuln = 0;
1396 }
1397
1398 /* Not bothering to s/!vuln/!pdef/ here for the time being. -- Syela
1399 * (this is noted elsewhere as terrible bug making warships yoyoing)
1400 * as the warships will go to enemy cities hoping that the enemy builds
1401 * something for them to kill. */
1402 if (vuln == 0
1403 && (utype_class(punittype)->adv.land_move == MOVE_NONE
1404 || 0 < utype_fuel(punittype))) {
1405 desire = 0;
1406
1407 } else {
1408 if (acity
1410 && acity_data->invasion.attack > 0
1411 && acity_data->invasion.occupy == 0) {
1413 float finishing_factor = 1;
1414
1417 }
1419 } else {
1420 desire = 0;
1421 }
1422
1423 if (!acity) {
1424 desire = kill_desire(value, attack, bcost, vuln, victim_count);
1425 } else {
1426 adv_want kd;
1427 int city_attack = acity_data->attack * acity_data->attack;
1428
1429 /* See daiunit.c:find_something_to_kill() for comments. */
1430 kd = kill_desire(value, attack,
1431 (bcost + acity_data->bcost), vuln,
1432 victim_count);
1433
1434 if (value * city_attack > acity_data->bcost * vuln) {
1435 kd -= kill_desire(value, city_attack,
1436 acity_data->bcost, vuln,
1437 victim_count);
1438 }
1439
1440 desire = MAX(desire, kd);
1441 }
1442 }
1443
1445 /* We can be possibly making some people of our homecity unhappy - then
1446 * we don't want to travel too far away to our victims. */
1447 /* TODO: Unify the 'unhap' dependency to some common function. */
1450
1451 want = military_amortize(pplayer, pcity, desire, MAX(1, move_time),
1453
1454 if (want > 0) {
1455 if (tech_dist > 0) {
1456 /* This is a future unit, tell the scientist how much we need it */
1458 plr_data->tech_want[advance_index(padv)]
1459 += want;
1460 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1461 "+ " ADV_WANT_PRINTF " for %s vs %s(%d,%d)",
1462 want,
1465 TILE_XY(ptile));
1467 } else if (want > best_choice->want) {
1468 const struct impr_type *impr_req;
1469
1471 /* This is a real unit and we really want it */
1472
1473 CITY_LOG(LOG_DEBUG, pcity, "overriding %s(" ADV_WANT_PRINTF
1474 ") with %s(" ADV_WANT_PRINTF ")"
1475 " [attack=%d,value=" ADV_WANT_PRINTF
1476 ",move_time=%d,vuln=%d,bcost=%d]",
1477 utype_rule_name(best_choice->value.utype),
1478 best_choice->want,
1480 want,
1481 attack, value, move_time, vuln, bcost);
1482
1483 best_choice->value.utype = punittype;
1484 best_choice->want = want;
1485 best_choice->type = CT_ATTACKER;
1487 pcity)))) {
1488 CITY_LOG(LOG_DEBUG, pcity, "cannot build unit %s",
1491 /* Building this unit requires a specific type of improvement.
1492 * So we build this improvement instead. This may not be the
1493 * best behavior. */
1494 CITY_LOG(LOG_DEBUG, pcity, "building %s to build unit %s",
1497 best_choice->value.building = impr_req;
1498 best_choice->want = want;
1499 best_choice->type = CT_BUILDING;
1500 } else {
1501 /* This should never happen? */
1502 CITY_LOG(LOG_DEBUG, pcity, "cannot build %s or unit %s",
1505 }
1506 }
1507 }
1508 }
1510}
1511
1512/**********************************************************************/
1523static struct adv_choice *kill_something_with(struct ai_type *ait,
1524 const struct civ_map *nmap,
1525 struct player *pplayer,
1526 struct city *pcity, struct unit *myunit,
1527 struct adv_choice *choice)
1528{
1529 /* Our attack rating (with reinforcements) */
1530 int attack;
1531 /* Benefit from fighting the target */
1533 /* Defender of the target city/tile */
1534 struct unit *pdef;
1535 const struct unit_type *def_type;
1536 struct player *def_owner;
1537 int def_vet; /* Is the defender veteran? */
1538 /* Target coordinates */
1539 struct tile *ptile;
1540 /* Our transport */
1541 struct unit *ferryboat;
1542 /* Our target */
1543 struct city *acity;
1544 /* Type of the boat (real or a future one) */
1545 const struct unit_type *boattype;
1546 struct pf_map *ferry_map = NULL;
1547 int move_time;
1548 struct adv_choice *best_choice;
1549 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1550 struct ai_city *acity_data;
1551
1553 best_choice->value.utype = unit_type_get(myunit);
1554 best_choice->type = CT_ATTACKER;
1555 adv_choice_set_use(best_choice, "attacker");
1556
1559
1560 if (city_data->danger != 0 && assess_defense(ait, pcity) == 0) {
1561 /* Defense comes first! */
1562 goto cleanup;
1563 }
1564
1565 best_choice->want = find_something_to_kill(ait, pplayer, myunit, &ptile, NULL,
1566 &ferry_map, &ferryboat,
1567 &boattype, &move_time);
1568 if (NULL == ptile
1569 || ptile == unit_tile(myunit)
1570 || !can_unit_attack_tile(myunit, NULL, ptile)) {
1571 goto cleanup;
1572 }
1573
1574 acity = tile_city(ptile);
1575
1576 if (myunit->id != 0) {
1577 log_error("%s(): non-virtual unit!", __FUNCTION__);
1578 goto cleanup;
1579 }
1580
1582 if (acity) {
1584 attack += acity_data->attack;
1585 }
1586 attack *= attack;
1587
1588 if (NULL != acity) {
1589 /* Rating of enemy defender */
1590 int vulnerability;
1591
1592 if (!POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, city_owner(acity))) {
1593 /* Not a valid target */
1594 goto cleanup;
1595 }
1596
1599 if (1 < move_time && def_type) {
1602 city_owner(acity), ptile,
1603 FALSE, def_vet);
1605 } else {
1606 vulnerability = 0;
1607 benefit = 0;
1608 def_vet = 0;
1609 }
1610
1611 pdef = get_defender(nmap, myunit, ptile, NULL);
1612 if (pdef) {
1614 city_owner(acity), ptile, FALSE,
1615 pdef->veteran);
1616 if (vulnerability < m) {
1618 def_vet = pdef->veteran;
1621 }
1622 }
1623 if (unit_can_take_over(myunit) || acity_data->invasion.occupy > 0) {
1624 /* Bonus for getting the city */
1626 float finishing_factor = 1;
1627
1630 }
1632 }
1633
1634 /* end dealing with cities */
1635 } else {
1636
1637 if (NULL != ferry_map) {
1639 ferry_map = NULL;
1640 }
1641
1642 pdef = get_defender(nmap, myunit, ptile, NULL);
1643 if (!pdef) {
1644 /* Nobody to attack! */
1645 goto cleanup;
1646 }
1647
1649
1651 def_vet = pdef->veteran;
1653 /* end dealing with units */
1654 }
1655
1656 if (NULL == ferry_map) {
1658 def_vet, ptile,
1660 } else {
1661 /* Attract a boat to our city or retain the one that's already here */
1663 best_choice->need_boat = TRUE;
1665 def_vet, ptile,
1666 best_choice, ferry_map, ferryboat, boattype);
1667 }
1668
1669 if (best_choice->want > choice->want) {
1670 /* We want attacker more than what we have selected before */
1673 CITY_LOG(LOG_DEBUG, pcity, "kill_something_with()"
1674 " %s has chosen attacker, %s, want=" ADV_WANT_PRINTF,
1676 utype_rule_name(best_choice->value.utype),
1677 best_choice->want);
1678
1679 if (NULL != ferry_map && !ferryboat) { /* need a new ferry */
1680 /* We might need a new boat even if there are boats free,
1681 * if they are blockaded or in inland seas*/
1683 if (dai_choose_role_unit(ait, pplayer, pcity, choice, CT_ATTACKER,
1685 && dai_is_ferry_type(choice->value.utype, ait)) {
1686#ifdef FREECIV_DEBUG
1687 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1688
1689 log_debug("kill_something_with() %s has chosen attacker ferry, "
1690 "%s, want=" ADV_WANT_PRINTF ", %d of %d free",
1692 utype_rule_name(choice->value.utype),
1693 choice->want,
1694 ai->stats.available_boats, ai->stats.boats);
1695#endif /* FREECIV_DEBUG */
1696
1697 adv_choice_set_use(choice, "attacker ferry");
1698 } /* else can not build ferries yet */
1699 }
1700 }
1701
1702cleanup:
1703 if (best_choice != choice) {
1704 /* It was not taken to use.
1705 * This hackery needed since 'goto cleanup:' might skip
1706 * sensible points to do adv_free_choice(). */
1708 }
1709 if (NULL != ferry_map) {
1711 }
1712
1713 return choice;
1714}
1715
1716/**********************************************************************/
1722static void dai_unit_consider_bodyguard(struct ai_type *ait,
1723 const struct civ_map *nmap,
1724 struct city *pcity,
1725 struct unit_type *punittype,
1726 struct adv_choice *choice)
1727{
1728 if (choice->want < DAI_WANT_MILITARY_EMERGENCY) {
1729 struct player *pplayer = city_owner(pcity);
1730 struct unit *aunit = NULL;
1731 struct city *acity = NULL;
1732 struct unit *virtualunit
1735 punittype));
1736 const adv_want want = look_for_charge(ait, nmap, pplayer, virtualunit,
1737 &aunit, &acity);
1738
1739 if (want > choice->want) {
1740 choice->want = want;
1741 choice->value.utype = punittype;
1742 choice->type = CT_DEFENDER;
1743 adv_choice_set_use(choice, "bodyguard");
1744 }
1745
1747 }
1748}
1749
1750/**********************************************************************/
1759 struct adv_choice *choice)
1760{
1762
1763 /* Sanity */
1764 if (!is_unit_choice_type(choice->type)
1767 return;
1768 }
1769
1770 /* N.B.: have to check that we haven't already built the building --mck */
1772 choice->value.utype)) != B_LAST
1774 choice->value.building = improvement_by_number(id);
1775 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER,
1777 / TRAIT_DEFAULT_VALUE / 2));
1778 choice->type = CT_BUILDING;
1779 adv_choice_set_use(choice, "veterancy building");
1780 }
1781}
1782
1783/**********************************************************************/
1789 const struct civ_map *nmap,
1790 struct player *pplayer,
1791 struct city *pcity,
1793{
1794 struct adv_data *ai = adv_data_get(pplayer, NULL);
1795 struct unit_type *punittype;
1796 unsigned int our_def, urgency;
1797 struct tile *ptile = pcity->tile;
1798 struct unit *virtualunit;
1799 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1801 bool martial_need = FALSE;
1802 struct adv_choice *choice = adv_new_choice();
1803 bool allow_gold_upkeep;
1804
1805 urgency = assess_danger(ait, nmap, pcity, ul_cb);
1806 /* Changing to quadratic to stop AI from building piles
1807 * of small units -- Syela */
1808 /* It has to be AFTER assess_danger() thanks to wallvalue. */
1810
1811 dai_choose_diplomat_defensive(ait, pplayer, pcity, choice, our_def);
1812
1814 + pcity->feel[CITIZEN_ANGRY][FEELING_NATIONALITY] > 0) {
1816 }
1817
1818 if (!martial_need) {
1820 if (pcity->specialists[sp] > 0
1823 break;
1824 }
1826 }
1827
1828 if (martial_need
1832 1, FEELING_FINAL);
1833 }
1834
1835 /* Otherwise no need to defend yet */
1836 if (city_data->danger != 0 || martial_value > 0) {
1837 struct impr_type *pimprove;
1838 int num_defenders = unit_list_size(ptile->units);
1839 int wall_id, danger;
1840 bool build_walls = TRUE;
1841 bool def_unit_selected = FALSE;
1842 int qdanger = city_data->danger * city_data->danger;
1843
1844 if (qdanger <= 0) {
1845 /* We only need these defenders because of Martial Law value */
1846 danger = 0;
1847 build_walls = FALSE; /* Walls don't provide Martial Law */
1848 } else {
1849 /* First determine the danger. It is measured in percents of our
1850 * defensive strength, capped at 200 + urgency */
1851 if (qdanger >= our_def) {
1852 if (urgency == 0) {
1853 /* Don't waste money */
1854 danger = 100;
1855 } else if (our_def == 0) {
1856 danger = 200 + urgency;
1857 } else {
1858 danger = MIN(200, 100 * qdanger / our_def) + urgency;
1859 }
1860 } else {
1861 danger = 100 * qdanger / our_def;
1862 }
1863
1864 if (pcity->surplus[O_SHIELD] <= 0 && our_def != 0) {
1865 /* Won't be able to support anything */
1866 danger = 0;
1867 }
1868 }
1869
1870 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d urgency=%d danger=%d num_def=%d "
1871 "our_def=%d", urgency, danger, num_defenders, our_def);
1872
1873 if (our_def == 0 && danger > 0) {
1874 /* Build defensive unit first! Walls will help nothing if there's
1875 * nobody behind them. */
1876 if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger, choice,
1877 martial_value)) {
1878 choice->want = DAI_WANT_BELOW_MIL_EMERGENCY + danger;
1879 adv_choice_set_use(choice, "first defender");
1882
1883 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants first defender with " ADV_WANT_PRINTF,
1884 choice->want);
1885 }
1886 }
1887 if (build_walls) {
1888 /* FIXME: 1. Does not consider what kind of future danger is likely, so
1889 * may build SAM batteries when enemy has only land units. */
1890 /* We will build walls if we can and want and (have "enough" defenders or
1891 * can just buy the walls straight away) */
1892
1893 /* HACK: This needs changing if multiple improvements provide
1894 * this effect. */
1896 pimprove = improvement_by_number(wall_id);
1897
1898 if (wall_id != B_LAST
1899 && pcity->server.adv->building_want[wall_id] != 0 && our_def != 0
1902 || (city_data->grave_danger == 0
1903 && pplayer->economic.gold
1904 > impr_buy_gold_cost(pcity, pimprove, pcity->shield_stock)))
1905 && ai_fuzzy(pplayer, TRUE)) {
1906 if (pcity->server.adv->building_want[wall_id] > 0) {
1907 /* NB: great wall is under domestic */
1908 choice->value.building = pimprove;
1909 /* building_want is hacked by assess_danger() */
1910 choice->want = pcity->server.adv->building_want[wall_id];
1911 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER, pplayer)
1912 / TRAIT_DEFAULT_VALUE / 2));
1913 if (urgency == 0 && choice->want > DAI_WANT_BELOW_MIL_EMERGENCY) {
1915 }
1916 choice->type = CT_BUILDING;
1917 adv_choice_set_use(choice, "defense building");
1919 "m_a_c_d wants defense building with " ADV_WANT_PRINTF,
1920 choice->want);
1921 } else {
1923 }
1924 } else {
1926 }
1927 }
1928
1929 /* If our choice isn't defender unit already, consider one */
1930 if (!def_unit_selected) {
1931 if ((danger > 0 && num_defenders <= urgency) || martial_value > 0) {
1932 struct adv_choice uchoice;
1933
1935
1936 /* Consider building defensive units */
1937 if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger,
1939 /* Potential defender found */
1940 if (urgency == 0
1941 && uchoice.value.utype->defense_strength == 1) {
1942 /* FIXME: check other reqs (unit class?) */
1943 if (get_city_bonus(pcity, EFT_HP_REGEN) > 0) {
1944 /* Unlikely */
1945 uchoice.want = MIN(49, danger);
1946 } else {
1947 uchoice.want = MIN(25, danger);
1948 }
1949 } else {
1950 uchoice.want = danger;
1951 }
1952
1953 uchoice.want += martial_value;
1954 if (danger > 0) {
1955 adv_choice_set_use(&uchoice, "defender");
1956 } else {
1957 adv_choice_set_use(&uchoice, "police");
1958 }
1959
1960 if (!build_walls || uchoice.want > choice->want) {
1961 adv_choice_copy(choice, &uchoice);
1962 }
1964
1965 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants %s with desire " ADV_WANT_PRINTF,
1966 utype_rule_name(choice->value.utype),
1967 choice->want);
1968 } else {
1969 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d cannot select defender");
1970 }
1971 } else {
1972 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d does not want defenders");
1973 }
1974 }
1975 } /* Ok, don't need to defend */
1976
1977 if (pcity->surplus[O_SHIELD] <= 0
1979 || pcity->id == ai->wonder_city) {
1980 /* Things we consider below are not life-saving so we don't want to
1981 * build them if our populace doesn't feel like it */
1982 return choice;
1983 }
1984
1985 if (pplayer->economic.tax <= 50 || city_total_unit_gold_upkeep(pcity) <= 0) {
1986 /* Always allow one unit with real gold upkeep (after EFT_UNIT_UPKEEP_FREE_PER_CITY)
1987 * Allow more if economics is so strong that we have not increased taxes. */
1989 } else {
1991 }
1992
1993 /* Consider making a land bodyguard */
1996 if (punittype) {
1998 }
1999
2000 /* If we are in severe danger, don't consider attackers. This is probably
2001 too general. In many cases we will want to buy attackers to counterattack.
2002 -- Per */
2004 && city_data->grave_danger > 0) {
2006 "severe danger (want " ADV_WANT_PRINTF "), force defender",
2007 choice->want);
2008 return choice;
2009 }
2010
2011 /* Consider making an offensive diplomat */
2012 dai_choose_diplomat_offensive(ait, nmap, pplayer, pcity, choice);
2013
2014 /* Consider making a sea bodyguard */
2017 if (punittype) {
2019 }
2020
2021 /* Consider making an airplane */
2022 (void) dai_choose_attacker_air(ait, nmap, pplayer, pcity, choice,
2024
2025 /* Consider making a paratrooper */
2026 dai_choose_paratrooper(ait, nmap, pplayer, pcity, choice, allow_gold_upkeep);
2027
2028 /* Check if we want a sailing attacker. Have to put sailing first
2029 before we mung the seamap */
2031 if (punittype) {
2033 pplayer, pcity, punittype,
2035 choice = kill_something_with(ait, nmap, pplayer, pcity, virtualunit, choice);
2037 }
2038
2039 /* Consider a land attacker or a ferried land attacker
2040 * (in which case, we might want a ferry before an attacker)
2041 */
2043 if (punittype) {
2045 choice = kill_something_with(ait, nmap, pplayer, pcity, virtualunit, choice);
2047 }
2048
2049 /* Consider a hunter */
2050 dai_hunter_choice(ait, pplayer, pcity, choice, allow_gold_upkeep);
2051
2052 /* Consider veteran level enhancing buildings before non-urgent units */
2054
2055 if (choice->want <= 0) {
2056 CITY_LOG(LOGLEVEL_BUILD, pcity, "military advisor has no advice");
2057 } else {
2059 "military advisor choice: %s (want " ADV_WANT_PRINTF ")",
2060 adv_choice_rule_name(choice),
2061 choice->want);
2062 }
2063
2064 return choice;
2065}
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1580
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:245
#define action_enabler_list_iterate_end
Definition actions.h:194
#define action_by_result_iterate_end
Definition actions.h:249
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:192
#define action_id(_act_)
Definition actions.h:426
#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
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:508
#define city_tile(_pcity_)
Definition city.h:564
@ CITIZEN_ANGRY
Definition city.h:269
@ CITIZEN_UNHAPPY
Definition city.h:268
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
@ FEELING_EFFECT
Definition city.h:279
@ FEELING_FINAL
Definition city.h:282
@ FEELING_NATIONALITY
Definition city.h:280
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:77
bool dai_choose_attacker_air(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, struct adv_choice *choice, bool allow_gold_upkeep)
Definition daiair.c:588
Impr_type_id dai_find_source_building(struct city *pcity, enum effect_type effect_type, const struct unit_type *utype)
Definition daicity.c:2195
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition daidata.c:308
void dai_choose_diplomat_defensive(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, int def)
void dai_choose_diplomat_offensive(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, struct adv_choice *choice)
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
bool dai_is_ferry_type(const struct unit_type *pferry, struct ai_type *ait)
Definition daiferry.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 daihunter.c:252
#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:89
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)
static struct unit_type * dai_choose_attacker(struct ai_type *ait, const struct civ_map *nmap, struct city *pcity, enum terrain_class tc, bool allow_gold_upkeep)
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)
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:73
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)
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)
static struct adv_choice * kill_something_with(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, struct unit *myunit, struct adv_choice *choice)
static void dai_unit_consider_bodyguard(struct ai_type *ait, const struct civ_map *nmap, struct city *pcity, struct unit_type *punittype, struct adv_choice *choice)
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, const struct civ_map *nmap, 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:1419
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:1348
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: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
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:1065
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Definition daiunit.c:2927
int build_cost_balanced(const struct unit_type *punittype)
Definition daiunit.c:249
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:1144
adv_want look_for_charge(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct unit *punit, struct unit **aunit, struct city **acity)
Definition daiunit.c:718
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:837
#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer)
Definition daiunit.h:72
#define simple_ai_unit_type_iterate_end
Definition daiunit.h:153
#define simple_ai_unit_type_iterate(_ut)
Definition daiunit.h:147
static void attack(QVariant data1, QVariant data2)
Definition dialogs.cpp:3044
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:1050
int Tech_type_id
Definition fc_types.h:238
int Impr_type_id
Definition fc_types.h:237
@ RPT_POSSIBLE
Definition fc_types.h:515
int action_id
Definition fc_types.h:250
#define ADV_WANT_PRINTF
Definition fc_types.h:1051
int Unit_type_id
Definition fc_types.h:243
@ O_SHIELD
Definition fc_types.h:103
@ O_LUXURY
Definition fc_types.h:103
@ O_GOLD
Definition fc_types.h:103
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: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:362
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:496
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:120
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:552
#define players_iterate(_pplayer)
Definition player.h:547
static bool player_is_cpuhog(const struct player *pplayer)
Definition player.h:590
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:753
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:775
struct research * research_get(const struct player *pplayer)
Definition research.c:130
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:270
#define normal_specialist_type_iterate(sp)
Definition specialist.h:89
#define normal_specialist_type_iterate_end
Definition specialist.h:95
#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:339
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
struct adv_choice choice
Definition daicity.h:41
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:318
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:595
universals_u value
Definition fc_types.h:594
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:107
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:536
enum citystatus_type citystatus
Definition fc_types.h:547
const struct impr_type * building
Definition fc_types.h:529
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2545
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:402
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1688
bool is_special_unit(const struct unit *punit)
Definition unit.c:369
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1793
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2529
#define unit_tile(_pu)
Definition unit.h:407
#define unit_owner(_pu)
Definition unit.h:406
#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:126
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1613
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:224
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1493
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1509
int utype_upkeep_cost(const struct unit_type *ut, const struct unit *punit, struct player *pplayer, Output_type_id otype)
Definition unittype.c:136
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1604
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2530
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:412
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:215
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:289
void * utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
Definition unittype.c:2771
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:93
bool utype_can_take_over(const struct unit_type *punittype)
Definition unittype.c:301
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1463
bool utype_acts_hostile(const struct unit_type *putype)
Definition unittype.c:468
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
#define utype_class(_t_)
Definition unittype.h:756
#define utype_fuel(ptype)
Definition unittype.h:847
#define unit_tech_reqs_iterate_end
Definition unittype.h:889
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:883
@ 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:863
#define U_LAST
Definition unittype.h:40
#define unit_type_iterate_end
Definition unittype.h:870
#define U_NOT_OBSOLETED
Definition unittype.h:535