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_GOOD:
467 case VUT_TERRAINCLASS:
468 case VUT_TERRFLAG:
469 case VUT_TERRAINALTER:
472 case VUT_TILE_REL:
473 case VUT_NONE:
475 case VUT_COUNT:
476 /* Not implemented. */
477 break;
478 }
480
481 return TRI_NO;
482}
483
484/**********************************************************************/
491static bool
493 const struct unit *actor,
494 const struct city *pcity,
495 int turns)
496{
497 const struct player *target_player = city_owner(pcity),
499 const struct unit_type *utype = unit_type_get(actor);
500 const struct req_context target_ctx = {
502 .city = pcity,
504 }, actor_ctx = {
505 .player = actor_player,
506 .unit = actor,
507 .unittype = utype
508 };
509
510 if (!utype_can_do_action(utype, wanted_action)) {
511 return FALSE;
512 }
514 enabler) {
515 /* We assume that we could build or move units into the city
516 * that are not present there yet */
518 &enabler->actor_reqs, NULL,
519 tactical_req_cb, NULL, turns)
520 &&
522 &enabler->target_reqs, NULL,
523 tactical_req_cb, NULL, turns)) {
524 return TRUE;
525 }
527
528 return FALSE;
529}
530
531/**********************************************************************/
534static unsigned int assess_danger_unit(const struct civ_map *nmap,
535 const struct city *pcity,
537 const struct unit *punit,
538 int *move_time)
539{
540 struct pf_position pos;
541 const struct unit_type *punittype = unit_type_get(punit);
542 const struct tile *ptile = city_tile(pcity);
543 const struct player *uowner = unit_owner(punit);
544 const struct unit *ferry;
545 unsigned int danger;
546 int amod = -99, dmod;
547 bool attack_danger = FALSE;
548
550
553 && 0 < punittype->paratroopers_range) {
555 / punittype->paratroopers_range);
556 }
557
560 || *move_time > pos.turn)) {
561 *move_time = pos.turn;
562 }
563
565 && (ferry = unit_transport_get(punit))
568 || *move_time > pos.turn)) {
569 *move_time = pos.turn;
571 (*move_time)++;
572 }
573 }
574 }
575
576 if (PF_IMPOSSIBLE_MC == *move_time) {
577 return 0;
578 }
579 if (!is_native_tile(punittype, ptile)
581 return 0;
582 }
584 return 0;
585 }
586
587 /* Find the worst attack action to expect */
589 /* Is it possible that punit will do action id to the city? */
590 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
591
593 int b;
594
596
598 if (b > amod) {
599 amod = b;
600 }
601 }
603
604 /* FIXME: it's a dummy support for anti-bombard defense just to do something against
605 * approaching bombarders. Some better logic is needed, see OSDN#41778 */
606 if (!attack_danger) {
608 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
609
611 *move_time)) {
612 int b;
613
615
617 if (b > amod) {
618 amod = b;
619 }
620 }
622 /* Here something should be done cuz the modifier affects
623 * more than one unit but not their full hp, but is not done yet...*/
624 }
625 if (!attack_danger) {
626 /* If the unit is dangerous, it's not about its combat strength */
627 return 0;
628 }
629
630 danger = adv_unit_att_rating(punit);
631 dmod = 100 + get_unittype_bonus(city_owner(pcity), ptile,
633 return danger * (amod + 100) / MAX(dmod, 1);
634}
635
636/**********************************************************************/
642 const struct civ_map *nmap,
643 struct player *pplayer)
644{
645 /* Do nothing if game is not running */
646 if (S_S_RUNNING == server_state()) {
647 city_list_iterate(pplayer->cities, pcity) {
648 (void) assess_danger(ait, nmap, pcity, NULL);
650 }
651}
652
653/**********************************************************************/
672static void dai_reevaluate_building(struct city *pcity, adv_want *value,
673 unsigned int urgency, unsigned int danger,
674 int defense)
675{
676 if (*value == 0 || danger <= 0) {
677 return;
678 }
679
680 *value = MAX(*value, 100 + urgency); /* default */
681
682 if (urgency > 0 && danger > defense * 2) {
683 *value += 100;
684 } else if (defense != 0 && danger > defense) {
685 *value = MAX(danger * 100 / defense, *value);
686 }
687}
688
689/**********************************************************************/
707static unsigned int assess_danger(struct ai_type *ait,
708 const struct civ_map *nmap,
709 struct city *pcity,
711{
712 struct player *pplayer = city_owner(pcity);
713 struct tile *ptile = city_tile(pcity);
714 struct ai_city *city_data = def_ai_city_data(pcity, ait);
715 /* How much such danger there is that building would help against. */
716 unsigned int danger_reduced[B_LAST];
717 int i;
718 int defender;
719 unsigned int urgency = 0;
720 int defense;
721 int total_danger = 0;
722
723 /* TODO: Presumably most, or even all, of these arrays
724 * could be of size game.control.num_unit_types instead
725 * of full U_LAST */
731 int assess_turns;
732 bool omnimap;
733
735
736 /* Initialize data. */
738 if (has_handicap(pplayer, H_DANGER)) {
739 /* Always thinks that city is in grave danger */
740 city_data->grave_danger = 1;
741 } else {
742 city_data->grave_danger = 0;
743 }
744 city_data->diplomat_threat = FALSE;
745 city_data->has_diplomat = FALSE;
746
747 unit_type_iterate(utype) {
748 int idx = utype_index(utype);
749
750 defense_bonuses_pct[idx] = 0;
752 best_non_scramble[idx] = -1;
753 /* FIXME: cache it somewhere? */
755 = 100 + get_unittype_bonus(pplayer, ptile, utype, NULL,
757 city_def_against[idx] = MAX(city_def_against[idx], 1);
759
760 /* What flag-specific bonuses do our units have. */
761 /* We value them less than general defense increment */
762 unit_list_iterate(ptile->units, punit) {
763 const struct unit_type *def = unit_type_get(punit);
764
766 city_data->has_diplomat = TRUE;
767 }
769 /* This is first defender of this type. Check defender type
770 * specific bonuses. */
771
772 /* Skip defenders that have no bonuses at all. Acceptable
773 * side-effect is that we can't consider negative bonuses at
774 * all ("No bonuses" should be better than "negative bonus") */
775 if (def->cache.max_defense_mp_bonus_pct > 0) {
776 unit_type_iterate(utype) {
777 int idx = utype_index(utype);
778 int coeff = def->cache.scramble_coeff[idx];
779 int bonus;
780
781 /* FIXME: consider EFT_FORTIFY_DEFENSE_BONUS */
782 if (coeff) {
783 bonus = coeff / city_def_against[idx] - 100;
784 } else {
785 bonus = def->cache.defense_mp_bonuses_pct[idx];
786 }
787
788 if (bonus > defense_bonuses_pct[idx]) {
789 if (!coeff) {
790 best_non_scramble[idx] = bonus;
791 }
792 defense_bonuses_pct[idx] = bonus;
793 } else if (!coeff) {
794 best_non_scramble[idx] = MAX(best_non_scramble[idx], bonus);
795 }
797 } else {
798 /* Just remember that such a unit exists and hope its bonuses are just 0 */
800 }
801
803 }
805 if (sth_does_not_scramble || unit_list_size(ptile->units) <= 0) {
806 /* Scrambling units tend to be expensive. If we have a barenaked city, we'll
807 * need at least a cheap unit. If we have only scramblers,
808 * maybe it's OK. */
811
814 }
815
816 if (player_is_cpuhog(pplayer)) {
817 assess_turns = 6;
818 } else {
820 }
821
822 omnimap = !has_handicap(pplayer, H_MAP);
823
824 /* Check. */
827 struct unit_list *units;
828
829 if (!adv_is_player_dangerous(pplayer, aplayer)) {
830 continue;
831 }
832 /* Note that we still consider the units of players we are not (yet)
833 * at war with. */
834
836 omnimap);
837
838 if (ul_cb != NULL) {
839 units = ul_cb(aplayer);
840 } else {
841 units = aplayer->units;
842 }
843 unit_list_iterate(units, punit) {
844 int move_time;
845 unsigned int vulnerability;
846 int defbonus_pct;
847 const struct unit_type *utype = unit_type_get(punit);
848 struct unit_type_ai *utai = utype_ai_data(utype, ait);
849
850#ifdef FREECIV_WEB
851 /* freeciv-web ignores danger that is far in distance,
852 * no matter how quickly it would reach us; even if
853 * that's *immediately* over a road type that allows
854 * unlimited movement. */
856
860 /* Too far away. */
861 continue;
862 }
863#endif /* FREECIV_WEB */
864
865 if (!utai->carries_occupiers
866 && !utype_acts_hostile(utype)) {
867 /* Harmless unit. */
868 continue;
869 }
870
871 /* Defender unspecific vulnerability and potential move time */
873 punit, &move_time);
874
876 continue;
877 }
878
879 if (unit_can_take_over(punit) || utai->carries_occupiers) {
880 /* Even if there is no attack strength,
881 * we need ANY protector for the city */
883 if (3 >= move_time) {
884 urgency++;
885 if (1 >= move_time) {
886 city_data->grave_danger++;
887 }
888 }
889 }
890
892 if (defbonus_pct > 100) {
893 defbonus_pct = (defbonus_pct + 100) / 2;
894 }
895 /* Reduce vulnerability for specific bonuses we do have */
896 vulnerability = vulnerability * 100 / (defbonus_pct + 100);
897 /* Pass the order for a new defender type against it
898 * to the scientific advisor, urgency considered */
899 (void) dai_wants_defender_against(ait, nmap, pplayer, pcity, utype,
901
903 city_data->diplomat_threat = TRUE;
904 }
905
906 vulnerability *= vulnerability; /* positive feedback */
907 if (1 < move_time) {
909 }
910
915 if (defender != B_LAST) {
916 danger_reduced[defender] += vulnerability / MAX(move_time, 1);
917 }
918 } else if (best_non_scramble[utype_index(utype)] >= 0) {
919 /* To consider building a defensive building,
920 * build first a defender that gets any profit of it */
922 if (defender != B_LAST) {
923 int danred = vulnerability / MAX(move_time, 1);
924 /* Maybe we can build an improvement
925 * that gets normal defender over scrambling one?
926 * Effectively a sqrt-scale because we don't test how high
927 * the effect is. */
930 danred = danred * (100 + best_non_scramble[utype_index(utype)])
931 / (100 + defense_bonuses_pct[utype_index(utype)]);
932 }
933 danger_reduced[defender] += danred;
934 }
935 }
936
939
941
943
944 if (total_danger) {
945 /* If any hostile player has any dangerous unit that can in any time
946 * reach the city, we consider building walls here, if none yet.
947 * FIXME: this value assumes that walls give x3 defense. */
948 city_data->wallvalue = 90;
949 } else {
950 /* No danger.
951 * This is half of the wallvalue of what danger 1 would produce. */
952 city_data->wallvalue = 5;
953 }
954
955 if (0 < city_data->grave_danger) {
956 /* really, REALLY urgent to defend */
957 urgency += 10 * city_data->grave_danger;
958 }
959
960 /* HACK: This needs changing if multiple improvements provide
961 * this effect. */
962 /* FIXME: Accept only buildings helping unit classes we actually use.
963 * Now we consider any land mover helper suitable. */
964 /* Sum of squared defense ratings */
965 defense = assess_defense_igwall(ait, pcity);
966
967 for (i = 0; i < B_LAST; i++) {
968 if (0 < danger_reduced[i]) {
969 dai_reevaluate_building(pcity, &pcity->server.adv->building_want[i],
970 urgency, danger_reduced[i], defense);
971 }
972 }
973
974 if (has_handicap(pplayer, H_DANGER) && 0 == total_danger) {
975 /* Has to have some danger
976 * Otherwise grave_danger will be ignored. */
977 city_data->danger = 1;
978 } else {
979 city_data->danger = total_danger;
980 }
981 city_data->urgency = urgency;
982
984
985 return urgency;
986}
987
988/**********************************************************************/
993 const struct unit_type *punittype)
994{
996 int attack = punittype->attack_strength;
997 int defense = punittype->defense_strength;
998 int maxbonus_pct = 0;
999 int fp = punittype->firepower;
1000
1001 /* Sea and helicopters often have their firepower set to low firepower when
1002 * defending. We can't have such units as defenders. */
1005 }
1006 if (((struct unit_type_ai *)utype_ai_data(punittype, ait))->low_firepower) {
1008 }
1009 desire *= fp;
1010 desire *= defense;
1011 desire += punittype->move_rate / SINGLE_MOVE;
1012 desire += attack;
1013
1014 maxbonus_pct = punittype->cache.max_defense_mp_bonus_pct;
1015 if (maxbonus_pct > 100) {
1016 maxbonus_pct = (maxbonus_pct + 100) / 2;
1017 }
1018 desire += desire * maxbonus_pct / 100;
1020 desire /= 10; /* But might actually be worth it */
1021 }
1022
1023 return desire;
1024}
1025
1026/**********************************************************************/
1030 const struct unit_type *punittype)
1031{
1033 int attack = punittype->attack_strength;
1034 int defense = punittype->defense_strength;
1035
1036 desire *= punittype->move_rate;
1037 desire *= punittype->firepower;
1038 desire *= attack;
1039 desire += defense;
1041 desire += desire / 2;
1042 }
1044 desire /= 10; /* But might actually be worth it */
1045 }
1047 desire += desire / 2;
1048 }
1050 desire += desire / 4;
1051 }
1052 if (punittype->adv.igwall) {
1053 desire += desire / 4;
1054 }
1055
1056 return desire;
1057}
1058
1059/**********************************************************************/
1064bool dai_process_defender_want(struct ai_type *ait, const struct civ_map *nmap,
1065 struct player *pplayer,
1066 struct city *pcity, unsigned int danger,
1067 struct adv_choice *choice, adv_want extra_want)
1068{
1069 const struct research *presearch = research_get(pplayer);
1070 /* FIXME: We check if the city has *some* defensive structure,
1071 * but not whether the city has a defensive structure against
1072 * any specific attacker. The actual danger may not be mitigated
1073 * by the defense selected... */
1074 bool walls = city_got_defense_effect(pcity, NULL);
1075 /* Technologies we would like to have. */
1077 /* Our favourite unit. */
1078 adv_want best = -1;
1079 struct unit_type *best_unit_type = NULL;
1080 int best_unit_cost = 1;
1081 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1082 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1083 adv_want total_want = danger + extra_want;
1084
1085 memset(tech_desire, 0, sizeof(tech_desire));
1086
1088 adv_want desire; /* How much we want the unit? */
1089
1090 /* Only consider proper defenders - otherwise waste CPU and
1091 * bump tech want needlessly. */
1094 continue;
1095 }
1096
1098
1100 desire /= 2; /* Not good, just ok */
1101 }
1102
1104 /* Causes unhappiness even when in defense, so not a good
1105 * idea for a defender, unless it is _really_ good.
1106 * Downright counter productive, if we want unit just for
1107 * maintaining peace. */
1108 if (danger == 0) {
1109 desire = -50;
1110 } else {
1111 desire /= 2;
1112 }
1113 }
1114
1115 if (desire > 0) {
1116 desire /= POWER_DIVIDER / 2; /* Good enough, no rounding errors. */
1117 desire *= desire;
1118
1120 /* We can build the unit now... */
1121
1122 int build_cost = utype_build_shield_cost(pcity, NULL, punittype);
1123 int limit_cost = pcity->shield_stock + 40;
1124
1126 desire *= city_data->wallvalue;
1127 /* TODO: More use of POWER_FACTOR ! */
1129 }
1130
1132 && build_cost < best_unit_cost)
1133 || ((desire > best
1134 || (ADV_WANTS_EQ(desire, best)
1135 && build_cost <= best_unit_cost))
1136 && (best_unit_type == NULL
1137 /* In case all units are more expensive than limit_cost */
1138 || limit_cost <= pcity->shield_stock + 40))) {
1139 best = desire;
1141 best_unit_cost = build_cost;
1142 }
1144 /* We first need to develop the tech required by the unit... */
1145
1146 /* Cost (shield equivalent) of gaining these techs. */
1147 /* FIXME? Katvrr advises that this should be weighted more heavily in
1148 * big danger. */
1149 int tech_cost = 0;
1150
1155
1156 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1157
1158 /* Contrary to the above, we don't care if walls are actually built
1159 * - we're looking into the future now. */
1161 desire *= city_data->wallvalue;
1163 }
1164
1165 /* Yes, there's some similarity with kill_desire(). */
1166 /* TODO: Explain what shield cost has to do with tech want. */
1170 }
1171 }
1173
1174 if (best == -1) {
1175 CITY_LOG(LOG_DEBUG, pcity, "Ooops - we cannot build any defender!");
1176 }
1177
1178 if (best_unit_type != NULL) {
1180 best *= city_data->wallvalue;
1181 best /= POWER_FACTOR;
1182 }
1183 } else {
1184 best_unit_cost = 100; /* Building impossible is considered costly.
1185 * This should increase want for tech providing
1186 * first defender type. */
1187 }
1188
1189 if (best <= 0) {
1190 best = 1; /* Avoid division by zero below. */
1191 }
1192
1193 /* Update tech_want for appropriate techs for units we want to build. */
1195 if (tech_desire[utype_index(punittype)] > 0) {
1196 /* TODO: Document or fix the algorithm below. I have no idea why
1197 * it is written this way, and the results seem strange to me. - Per */
1199
1201 plr_data->tech_want[advance_index(padv)]
1202 += desire;
1203 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1204 "+ " ADV_WANT_PRINTF " for %s to defend %s",
1205 desire,
1209 }
1211
1212 if (!best_unit_type) {
1213 return FALSE;
1214 }
1215
1216 choice->value.utype = best_unit_type;
1217 choice->want = danger; /* FIXME: Not 'total_want' because of the way callers
1218 * are constructed. They may overwrite this value,
1219 * and then the value will NOT contain 'extra_want'.
1220 * Later we may add 'extra_want', and don't want it
1221 * already included in case this was NOT overwritten. */
1222 choice->type = CT_DEFENDER;
1223
1224 return TRUE;
1225}
1226
1227/**********************************************************************/
1244static void process_attacker_want(struct ai_type *ait,
1245 struct city *pcity,
1246 adv_want value,
1247 const struct unit_type *victim_unit_type,
1248 struct player *victim_player,
1249 int veteran, struct tile *ptile,
1250 struct adv_choice *best_choice,
1251 struct pf_map *ferry_map,
1252 struct unit *boat,
1253 const struct unit_type *boattype)
1254{
1255 struct player *pplayer = city_owner(pcity);
1256 const struct research *presearch = research_get(pplayer);
1257 /* The enemy city. acity == NULL means stray enemy unit */
1258 struct city *acity = tile_city(ptile);
1259 struct pf_parameter parameter;
1260 struct pf_map *pfm;
1261 struct pf_position pos;
1262 const struct unit_type *orig_utype = best_choice->value.utype;
1263 int victim_count = 1;
1264 int needferry = 0;
1265 bool unhap;
1266 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1267 const struct civ_map *nmap = &(wld.map);
1268
1269 /* Has to be initialized to make gcc happy */
1270 struct ai_city *acity_data = NULL;
1271
1273
1274 if (acity != NULL) {
1276 }
1277
1278 if (utype_class(orig_utype)->adv.sea_move == MOVE_NONE
1279 && !boat && boattype != NULL) {
1280 /* Cost of ferry */
1282 }
1283
1284 if (!is_stack_vulnerable(ptile)) {
1285 /* If it is a city, a fortress or an air base,
1286 * we may have to whack it many times */
1288 }
1289
1293 && (U_NOT_OBSOLETED == punittype->obsoleted_by
1294 || !can_city_build_unit_direct(nmap, pcity, punittype->obsoleted_by))
1295 && punittype->attack_strength > 0 /* Or we'll get SIGFPE */) {
1296 /* Values to be computed */
1298 adv_want want;
1299 int move_time;
1300 int vuln;
1301 int veteran_level
1303 &(const struct req_context) {
1304 .player = pplayer,
1305 .city = pcity,
1306 .tile = city_tile(pcity),
1307 .unittype = punittype,
1308 },
1309 NULL,
1311 /* Cost (shield equivalent) of gaining these techs. */
1312 /* FIXME? Katvrr advises that this should be weighted more heavily in big
1313 * danger. */
1314 int tech_cost = 0;
1316 /* See description of kill_desire() for info about this variables. */
1320 punittype->hp);
1321 int tech_dist = 0;
1322
1325
1327 if (tech_dist == 0) {
1329 }
1331
1332 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1333
1334 /* Take into account reinforcements strength */
1335 if (acity) {
1336 attack += acity_data->attack;
1337 }
1338
1339 if (attack == 0) {
1340 /* Yes, it can happen that a military unit has attack = 1,
1341 * for example militia with HP = 1 (in civ1 ruleset). */
1342 continue;
1343 }
1344
1345 attack *= attack;
1346
1348 pplayer);
1349 parameter.omniscience = !has_handicap(pplayer, H_MAP);
1350 pfm = pf_map_new(&parameter);
1351
1352 /* Set the move_time appropriately. */
1353 move_time = -1;
1354 if (NULL != ferry_map) {
1355 struct tile *dest_tile;
1356
1357 if (find_beachhead(pplayer, ferry_map, ptile, punittype,
1358 boattype, &dest_tile, NULL)
1359 && pf_map_position(ferry_map, dest_tile, &pos)) {
1360 move_time = pos.turn;
1363 if (atile == dest_tile) {
1365 move_time += pos.turn;
1366 break;
1367 } else if (atile == ptile) {
1368 /* Reaching directly seems better. */
1370 move_time = pos.turn;
1371 break;
1372 }
1374 }
1375 }
1376
1377 if (-1 == move_time) {
1378 if (pf_map_position(pfm, ptile, &pos)) {
1379 move_time = pos.turn;
1380 } else {
1382 continue;
1383 }
1384 }
1386
1387 /* Estimate strength of the enemy. */
1388
1389 if (victim_unit_type) {
1392 ptile, FALSE, veteran);
1393 } else {
1394 vuln = 0;
1395 }
1396
1397 /* Not bothering to s/!vuln/!pdef/ here for the time being. -- Syela
1398 * (this is noted elsewhere as terrible bug making warships yoyoing)
1399 * as the warships will go to enemy cities hoping that the enemy builds
1400 * something for them to kill. */
1401 if (vuln == 0
1402 && (utype_class(punittype)->adv.land_move == MOVE_NONE
1403 || 0 < utype_fuel(punittype))) {
1404 desire = 0;
1405
1406 } else {
1407 if (acity
1409 && acity_data->invasion.attack > 0
1410 && acity_data->invasion.occupy == 0) {
1412 float finishing_factor = 1;
1413
1416 }
1418 } else {
1419 desire = 0;
1420 }
1421
1422 if (!acity) {
1423 desire = kill_desire(value, attack, bcost, vuln, victim_count);
1424 } else {
1425 adv_want kd;
1426 int city_attack = acity_data->attack * acity_data->attack;
1427
1428 /* See daiunit.c:find_something_to_kill() for comments. */
1429 kd = kill_desire(value, attack,
1430 (bcost + acity_data->bcost), vuln,
1431 victim_count);
1432
1433 if (value * city_attack > acity_data->bcost * vuln) {
1434 kd -= kill_desire(value, city_attack,
1435 acity_data->bcost, vuln,
1436 victim_count);
1437 }
1438
1439 desire = MAX(desire, kd);
1440 }
1441 }
1442
1444 /* We can be possibly making some people of our homecity unhappy - then
1445 * we don't want to travel too far away to our victims. */
1446 /* TODO: Unify the 'unhap' dependency to some common function. */
1449
1450 want = military_amortize(pplayer, pcity, desire, MAX(1, move_time),
1452
1453 if (want > 0) {
1454 if (tech_dist > 0) {
1455 /* This is a future unit, tell the scientist how much we need it */
1457 plr_data->tech_want[advance_index(padv)]
1458 += want;
1459 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1460 "+ " ADV_WANT_PRINTF " for %s vs %s(%d,%d)",
1461 want,
1464 TILE_XY(ptile));
1466 } else if (want > best_choice->want) {
1467 const struct impr_type *impr_req;
1468
1470 /* This is a real unit and we really want it */
1471
1472 CITY_LOG(LOG_DEBUG, pcity, "overriding %s(" ADV_WANT_PRINTF
1473 ") with %s(" ADV_WANT_PRINTF ")"
1474 " [attack=%d,value=" ADV_WANT_PRINTF
1475 ",move_time=%d,vuln=%d,bcost=%d]",
1476 utype_rule_name(best_choice->value.utype),
1477 best_choice->want,
1479 want,
1480 attack, value, move_time, vuln, bcost);
1481
1482 best_choice->value.utype = punittype;
1483 best_choice->want = want;
1484 best_choice->type = CT_ATTACKER;
1486 pcity)))) {
1487 CITY_LOG(LOG_DEBUG, pcity, "cannot build unit %s",
1490 /* Building this unit requires a specific type of improvement.
1491 * So we build this improvement instead. This may not be the
1492 * best behavior. */
1493 CITY_LOG(LOG_DEBUG, pcity, "building %s to build unit %s",
1496 best_choice->value.building = impr_req;
1497 best_choice->want = want;
1498 best_choice->type = CT_BUILDING;
1499 } else {
1500 /* This should never happen? */
1501 CITY_LOG(LOG_DEBUG, pcity, "cannot build %s or unit %s",
1504 }
1505 }
1506 }
1507 }
1509}
1510
1511/**********************************************************************/
1522static struct adv_choice *kill_something_with(struct ai_type *ait,
1523 const struct civ_map *nmap,
1524 struct player *pplayer,
1525 struct city *pcity, struct unit *myunit,
1526 struct adv_choice *choice)
1527{
1528 /* Our attack rating (with reinforcements) */
1529 int attack;
1530 /* Benefit from fighting the target */
1532 /* Defender of the target city/tile */
1533 struct unit *pdef;
1534 const struct unit_type *def_type;
1535 struct player *def_owner;
1536 int def_vet; /* Is the defender veteran? */
1537 /* Target coordinates */
1538 struct tile *ptile;
1539 /* Our transport */
1540 struct unit *ferryboat;
1541 /* Our target */
1542 struct city *acity;
1543 /* Type of the boat (real or a future one) */
1544 const struct unit_type *boattype;
1545 struct pf_map *ferry_map = NULL;
1546 int move_time;
1547 struct adv_choice *best_choice;
1548 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1549 struct ai_city *acity_data;
1550
1552 best_choice->value.utype = unit_type_get(myunit);
1553 best_choice->type = CT_ATTACKER;
1554 adv_choice_set_use(best_choice, "attacker");
1555
1558
1559 if (city_data->danger != 0 && assess_defense(ait, pcity) == 0) {
1560 /* Defense comes first! */
1561 goto cleanup;
1562 }
1563
1564 best_choice->want = find_something_to_kill(ait, pplayer, myunit, &ptile, NULL,
1565 &ferry_map, &ferryboat,
1566 &boattype, &move_time);
1567 if (NULL == ptile
1568 || ptile == unit_tile(myunit)
1569 || !can_unit_attack_tile(myunit, NULL, ptile)) {
1570 goto cleanup;
1571 }
1572
1573 acity = tile_city(ptile);
1574
1575 if (myunit->id != 0) {
1576 log_error("%s(): non-virtual unit!", __FUNCTION__);
1577 goto cleanup;
1578 }
1579
1581 if (acity) {
1583 attack += acity_data->attack;
1584 }
1585 attack *= attack;
1586
1587 if (NULL != acity) {
1588 /* Rating of enemy defender */
1589 int vulnerability;
1590
1591 if (!POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, city_owner(acity))) {
1592 /* Not a valid target */
1593 goto cleanup;
1594 }
1595
1598 if (1 < move_time && def_type) {
1601 city_owner(acity), ptile,
1602 FALSE, def_vet);
1604 } else {
1605 vulnerability = 0;
1606 benefit = 0;
1607 def_vet = 0;
1608 }
1609
1610 pdef = get_defender(nmap, myunit, ptile, NULL);
1611 if (pdef) {
1613 city_owner(acity), ptile, FALSE,
1614 pdef->veteran);
1615 if (vulnerability < m) {
1617 def_vet = pdef->veteran;
1620 }
1621 }
1622 if (unit_can_take_over(myunit) || acity_data->invasion.occupy > 0) {
1623 /* Bonus for getting the city */
1625 float finishing_factor = 1;
1626
1629 }
1631 }
1632
1633 /* end dealing with cities */
1634 } else {
1635
1636 if (NULL != ferry_map) {
1638 ferry_map = NULL;
1639 }
1640
1641 pdef = get_defender(nmap, myunit, ptile, NULL);
1642 if (!pdef) {
1643 /* Nobody to attack! */
1644 goto cleanup;
1645 }
1646
1648
1650 def_vet = pdef->veteran;
1652 /* end dealing with units */
1653 }
1654
1655 if (NULL == ferry_map) {
1657 def_vet, ptile,
1659 } else {
1660 /* Attract a boat to our city or retain the one that's already here */
1662 best_choice->need_boat = TRUE;
1664 def_vet, ptile,
1665 best_choice, ferry_map, ferryboat, boattype);
1666 }
1667
1668 if (best_choice->want > choice->want) {
1669 /* We want attacker more than what we have selected before */
1672 CITY_LOG(LOG_DEBUG, pcity, "kill_something_with()"
1673 " %s has chosen attacker, %s, want=" ADV_WANT_PRINTF,
1675 utype_rule_name(best_choice->value.utype),
1676 best_choice->want);
1677
1678 if (NULL != ferry_map && !ferryboat) { /* need a new ferry */
1679 /* We might need a new boat even if there are boats free,
1680 * if they are blockaded or in inland seas*/
1682 if (dai_choose_role_unit(ait, pplayer, pcity, choice, CT_ATTACKER,
1684 && dai_is_ferry_type(choice->value.utype, ait)) {
1685#ifdef FREECIV_DEBUG
1686 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1687
1688 log_debug("kill_something_with() %s has chosen attacker ferry, "
1689 "%s, want=" ADV_WANT_PRINTF ", %d of %d free",
1691 utype_rule_name(choice->value.utype),
1692 choice->want,
1693 ai->stats.available_boats, ai->stats.boats);
1694#endif /* FREECIV_DEBUG */
1695
1696 adv_choice_set_use(choice, "attacker ferry");
1697 } /* else can not build ferries yet */
1698 }
1699 }
1700
1701cleanup:
1702 if (best_choice != choice) {
1703 /* It was not taken to use.
1704 * This hackery needed since 'goto cleanup:' might skip
1705 * sensible points to do adv_free_choice(). */
1707 }
1708 if (NULL != ferry_map) {
1710 }
1711
1712 return choice;
1713}
1714
1715/**********************************************************************/
1721static void dai_unit_consider_bodyguard(struct ai_type *ait,
1722 const struct civ_map *nmap,
1723 struct city *pcity,
1724 struct unit_type *punittype,
1725 struct adv_choice *choice)
1726{
1727 if (choice->want < DAI_WANT_MILITARY_EMERGENCY) {
1728 struct player *pplayer = city_owner(pcity);
1729 struct unit *aunit = NULL;
1730 struct city *acity = NULL;
1731 struct unit *virtualunit
1734 punittype));
1735 const adv_want want = look_for_charge(ait, nmap, pplayer, virtualunit,
1736 &aunit, &acity);
1737
1738 if (want > choice->want) {
1739 choice->want = want;
1740 choice->value.utype = punittype;
1741 choice->type = CT_DEFENDER;
1742 adv_choice_set_use(choice, "bodyguard");
1743 }
1744
1746 }
1747}
1748
1749/**********************************************************************/
1758 struct adv_choice *choice)
1759{
1761
1762 /* Sanity */
1763 if (!is_unit_choice_type(choice->type)
1766 return;
1767 }
1768
1769 /* N.B.: have to check that we haven't already built the building --mck */
1771 choice->value.utype)) != B_LAST
1773 choice->value.building = improvement_by_number(id);
1774 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER,
1776 / TRAIT_DEFAULT_VALUE / 2));
1777 choice->type = CT_BUILDING;
1778 adv_choice_set_use(choice, "veterancy building");
1779 }
1780}
1781
1782/**********************************************************************/
1788 const struct civ_map *nmap,
1789 struct player *pplayer,
1790 struct city *pcity,
1792{
1793 struct adv_data *ai = adv_data_get(pplayer, NULL);
1794 struct unit_type *punittype;
1795 unsigned int our_def, urgency;
1796 struct tile *ptile = pcity->tile;
1797 struct unit *virtualunit;
1798 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1800 bool martial_need = FALSE;
1801 struct adv_choice *choice = adv_new_choice();
1802 bool allow_gold_upkeep;
1803
1804 urgency = assess_danger(ait, nmap, pcity, ul_cb);
1805 /* Changing to quadratic to stop AI from building piles
1806 * of small units -- Syela */
1807 /* It has to be AFTER assess_danger() thanks to wallvalue. */
1809
1810 dai_choose_diplomat_defensive(ait, pplayer, pcity, choice, our_def);
1811
1813 + pcity->feel[CITIZEN_ANGRY][FEELING_NATIONALITY] > 0) {
1815 }
1816
1817 if (!martial_need) {
1819 if (pcity->specialists[sp] > 0
1822 break;
1823 }
1825 }
1826
1827 if (martial_need
1831 1, FEELING_FINAL);
1832 }
1833
1834 /* Otherwise no need to defend yet */
1835 if (city_data->danger != 0 || martial_value > 0) {
1836 struct impr_type *pimprove;
1837 int num_defenders = unit_list_size(ptile->units);
1838 int wall_id, danger;
1839 bool build_walls = TRUE;
1840 bool def_unit_selected = FALSE;
1841 int qdanger = city_data->danger * city_data->danger;
1842
1843 if (qdanger <= 0) {
1844 /* We only need these defenders because of Martial Law value */
1845 danger = 0;
1846 build_walls = FALSE; /* Walls don't provide Martial Law */
1847 } else {
1848 /* First determine the danger. It is measured in percents of our
1849 * defensive strength, capped at 200 + urgency */
1850 if (qdanger >= our_def) {
1851 if (urgency == 0) {
1852 /* Don't waste money */
1853 danger = 100;
1854 } else if (our_def == 0) {
1855 danger = 200 + urgency;
1856 } else {
1857 danger = MIN(200, 100 * qdanger / our_def) + urgency;
1858 }
1859 } else {
1860 danger = 100 * qdanger / our_def;
1861 }
1862
1863 if (pcity->surplus[O_SHIELD] <= 0 && our_def != 0) {
1864 /* Won't be able to support anything */
1865 danger = 0;
1866 }
1867 }
1868
1869 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d urgency=%d danger=%d num_def=%d "
1870 "our_def=%d", urgency, danger, num_defenders, our_def);
1871
1872 if (our_def == 0 && danger > 0) {
1873 /* Build defensive unit first! Walls will help nothing if there's
1874 * nobody behind them. */
1875 if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger, choice,
1876 martial_value)) {
1877 choice->want = DAI_WANT_BELOW_MIL_EMERGENCY + danger;
1878 adv_choice_set_use(choice, "first defender");
1881
1882 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants first defender with " ADV_WANT_PRINTF,
1883 choice->want);
1884 }
1885 }
1886 if (build_walls) {
1887 /* FIXME: 1. Does not consider what kind of future danger is likely, so
1888 * may build SAM batteries when enemy has only land units. */
1889 /* We will build walls if we can and want and (have "enough" defenders or
1890 * can just buy the walls straight away) */
1891
1892 /* HACK: This needs changing if multiple improvements provide
1893 * this effect. */
1895 pimprove = improvement_by_number(wall_id);
1896
1897 if (wall_id != B_LAST
1898 && pcity->server.adv->building_want[wall_id] != 0 && our_def != 0
1901 || (city_data->grave_danger == 0
1902 && pplayer->economic.gold
1903 > impr_buy_gold_cost(pcity, pimprove, pcity->shield_stock)))
1904 && ai_fuzzy(pplayer, TRUE)) {
1905 if (pcity->server.adv->building_want[wall_id] > 0) {
1906 /* NB: great wall is under domestic */
1907 choice->value.building = pimprove;
1908 /* building_want is hacked by assess_danger() */
1909 choice->want = pcity->server.adv->building_want[wall_id];
1910 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER, pplayer)
1911 / TRAIT_DEFAULT_VALUE / 2));
1912 if (urgency == 0 && choice->want > DAI_WANT_BELOW_MIL_EMERGENCY) {
1914 }
1915 choice->type = CT_BUILDING;
1916 adv_choice_set_use(choice, "defense building");
1918 "m_a_c_d wants defense building with " ADV_WANT_PRINTF,
1919 choice->want);
1920 } else {
1922 }
1923 } else {
1925 }
1926 }
1927
1928 /* If our choice isn't defender unit already, consider one */
1929 if (!def_unit_selected) {
1930 if ((danger > 0 && num_defenders <= urgency) || martial_value > 0) {
1931 struct adv_choice uchoice;
1932
1934
1935 /* Consider building defensive units */
1936 if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger,
1938 /* Potential defender found */
1939 if (urgency == 0
1940 && uchoice.value.utype->defense_strength == 1) {
1941 /* FIXME: check other reqs (unit class?) */
1942 if (get_city_bonus(pcity, EFT_HP_REGEN) > 0) {
1943 /* Unlikely */
1944 uchoice.want = MIN(49, danger);
1945 } else {
1946 uchoice.want = MIN(25, danger);
1947 }
1948 } else {
1949 uchoice.want = danger;
1950 }
1951
1952 uchoice.want += martial_value;
1953 if (danger > 0) {
1954 adv_choice_set_use(&uchoice, "defender");
1955 } else {
1956 adv_choice_set_use(&uchoice, "police");
1957 }
1958
1959 if (!build_walls || uchoice.want > choice->want) {
1960 adv_choice_copy(choice, &uchoice);
1961 }
1963
1964 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants %s with desire " ADV_WANT_PRINTF,
1965 utype_rule_name(choice->value.utype),
1966 choice->want);
1967 } else {
1968 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d cannot select defender");
1969 }
1970 } else {
1971 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d does not want defenders");
1972 }
1973 }
1974 } /* Ok, don't need to defend */
1975
1976 if (pcity->surplus[O_SHIELD] <= 0
1978 || pcity->id == ai->wonder_city) {
1979 /* Things we consider below are not life-saving so we don't want to
1980 * build them if our populace doesn't feel like it */
1981 return choice;
1982 }
1983
1984 if (pplayer->economic.tax <= 50 || city_total_unit_gold_upkeep(pcity) <= 0) {
1985 /* Always allow one unit with real gold upkeep (after EFT_UNIT_UPKEEP_FREE_PER_CITY)
1986 * Allow more if economics is so strong that we have not increased taxes. */
1988 } else {
1990 }
1991
1992 /* Consider making a land bodyguard */
1995 if (punittype) {
1997 }
1998
1999 /* If we are in severe danger, don't consider attackers. This is probably
2000 too general. In many cases we will want to buy attackers to counterattack.
2001 -- Per */
2003 && city_data->grave_danger > 0) {
2005 "severe danger (want " ADV_WANT_PRINTF "), force defender",
2006 choice->want);
2007 return choice;
2008 }
2009
2010 /* Consider making an offensive diplomat */
2011 dai_choose_diplomat_offensive(ait, nmap, pplayer, pcity, choice);
2012
2013 /* Consider making a sea bodyguard */
2016 if (punittype) {
2018 }
2019
2020 /* Consider making an airplane */
2021 (void) dai_choose_attacker_air(ait, nmap, pplayer, pcity, choice,
2023
2024 /* Consider making a paratrooper */
2025 dai_choose_paratrooper(ait, nmap, pplayer, pcity, choice, allow_gold_upkeep);
2026
2027 /* Check if we want a sailing attacker. Have to put sailing first
2028 before we mung the seamap */
2030 if (punittype) {
2032 pplayer, pcity, punittype,
2034 choice = kill_something_with(ait, nmap, pplayer, pcity, virtualunit, choice);
2036 }
2037
2038 /* Consider a land attacker or a ferried land attacker
2039 * (in which case, we might want a ferry before an attacker)
2040 */
2042 if (punittype) {
2044 choice = kill_something_with(ait, nmap, pplayer, pcity, virtualunit, choice);
2046 }
2047
2048 /* Consider a hunter */
2049 dai_hunter_choice(ait, pplayer, pcity, choice, allow_gold_upkeep);
2050
2051 /* Consider veteran level enhancing buildings before non-urgent units */
2053
2054 if (choice->want <= 0) {
2055 CITY_LOG(LOGLEVEL_BUILD, pcity, "military advisor has no advice");
2056 } else {
2058 "military advisor choice: %s (want " ADV_WANT_PRINTF ")",
2059 adv_choice_rule_name(choice),
2060 choice->want);
2061 }
2062
2063 return choice;
2064}
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:76
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:2194
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:1048
int Tech_type_id
Definition fc_types.h:237
int Impr_type_id
Definition fc_types.h:236
@ RPT_POSSIBLE
Definition fc_types.h:514
int action_id
Definition fc_types.h:249
#define ADV_WANT_PRINTF
Definition fc_types.h:1049
int Unit_type_id
Definition fc_types.h:242
@ O_SHIELD
Definition fc_types.h:102
@ O_LUXURY
Definition fc_types.h:102
@ O_GOLD
Definition fc_types.h:102
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: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: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:593
universals_u value
Definition fc_types.h:592
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:535
enum citystatus_type citystatus
Definition fc_types.h:545
const struct impr_type * building
Definition fc_types.h:528
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