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:
468 case VUT_GOOD:
469 case VUT_TERRAINCLASS:
470 case VUT_TERRFLAG:
471 case VUT_TERRAINALTER:
474 case VUT_TILE_REL:
475 case VUT_NONE:
477 case VUT_COUNT:
478 /* Not implemented. */
479 break;
480 }
482
483 return TRI_NO;
484}
485
486/**********************************************************************/
493static bool
495 const struct unit *actor,
496 const struct city *pcity,
497 int turns)
498{
499 const struct player *target_player = city_owner(pcity),
501 const struct unit_type *utype = unit_type_get(actor);
502 const struct req_context target_ctx = {
504 .city = pcity,
506 }, actor_ctx = {
507 .player = actor_player,
508 .unit = actor,
509 .unittype = utype
510 };
511
512 if (!utype_can_do_action(utype, wanted_action)) {
513 return FALSE;
514 }
516 enabler) {
517 /* We assume that we could build or move units into the city
518 * that are not present there yet */
520 &enabler->actor_reqs, NULL,
521 tactical_req_cb, NULL, turns)
522 &&
524 &enabler->target_reqs, NULL,
525 tactical_req_cb, NULL, turns)) {
526 return TRUE;
527 }
529
530 return FALSE;
531}
532
533/**********************************************************************/
536static unsigned int assess_danger_unit(const struct civ_map *nmap,
537 const struct city *pcity,
539 const struct unit *punit,
540 int *move_time)
541{
542 struct pf_position pos;
543 const struct unit_type *punittype = unit_type_get(punit);
544 const struct tile *ptile = city_tile(pcity);
545 const struct player *uowner = unit_owner(punit);
546 const struct unit *ferry;
547 unsigned int danger;
548 int amod = -99, dmod;
549 bool attack_danger = FALSE;
550
552
555 && 0 < punittype->paratroopers_range) {
557 / punittype->paratroopers_range);
558 }
559
562 || *move_time > pos.turn)) {
563 *move_time = pos.turn;
564 }
565
567 && (ferry = unit_transport_get(punit))
570 || *move_time > pos.turn)) {
571 *move_time = pos.turn;
573 (*move_time)++;
574 }
575 }
576 }
577
578 if (PF_IMPOSSIBLE_MC == *move_time) {
579 return 0;
580 }
581 if (!is_native_tile(punittype, ptile)
583 return 0;
584 }
586 return 0;
587 }
588
589 /* Find the worst attack action to expect */
591 /* Is it possible that punit will do action id to the city? */
592 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
593
595 int b;
596
598
600 if (b > amod) {
601 amod = b;
602 }
603 }
605
606 /* FIXME: it's a dummy support for anti-bombard defense just to do something against
607 * approaching bombarders. Some better logic is needed, see OSDN#41778 */
608 if (!attack_danger) {
610 /* FIXME: some unit parameters (notably, veterancy) may meddle in */
611
613 *move_time)) {
614 int b;
615
617
619 if (b > amod) {
620 amod = b;
621 }
622 }
624 /* Here something should be done cuz the modifier affects
625 * more than one unit but not their full hp, but is not done yet...*/
626 }
627 if (!attack_danger) {
628 /* If the unit is dangerous, it's not about its combat strength */
629 return 0;
630 }
631
632 danger = adv_unit_att_rating(punit);
633 dmod = 100 + get_unittype_bonus(city_owner(pcity), ptile,
635 return danger * (amod + 100) / MAX(dmod, 1);
636}
637
638/**********************************************************************/
644 const struct civ_map *nmap,
645 struct player *pplayer)
646{
647 /* Do nothing if game is not running */
648 if (S_S_RUNNING == server_state()) {
649 city_list_iterate(pplayer->cities, pcity) {
650 (void) assess_danger(ait, nmap, pcity, NULL);
652 }
653}
654
655/**********************************************************************/
674static void dai_reevaluate_building(struct city *pcity, adv_want *value,
675 unsigned int urgency, unsigned int danger,
676 int defense)
677{
678 if (*value == 0 || danger <= 0) {
679 return;
680 }
681
682 *value = MAX(*value, 100 + urgency); /* default */
683
684 if (urgency > 0 && danger > defense * 2) {
685 *value += 100;
686 } else if (defense != 0 && danger > defense) {
687 *value = MAX(danger * 100 / defense, *value);
688 }
689}
690
691/**********************************************************************/
709static unsigned int assess_danger(struct ai_type *ait,
710 const struct civ_map *nmap,
711 struct city *pcity,
713{
714 struct player *pplayer = city_owner(pcity);
715 struct tile *ptile = city_tile(pcity);
716 struct ai_city *city_data = def_ai_city_data(pcity, ait);
717 /* How much such danger there is that building would help against. */
718 unsigned int danger_reduced[B_LAST];
719 int i;
720 int defender;
721 unsigned int urgency = 0;
722 int defense;
723 int total_danger = 0;
724
725 /* TODO: Presumably most, or even all, of these arrays
726 * could be of size game.control.num_unit_types instead
727 * of full U_LAST */
733 int assess_turns;
734 bool omnimap;
735
737
738 /* Initialize data. */
740 if (has_handicap(pplayer, H_DANGER)) {
741 /* Always thinks that city is in grave danger */
742 city_data->grave_danger = 1;
743 } else {
744 city_data->grave_danger = 0;
745 }
746 city_data->diplomat_threat = FALSE;
747 city_data->has_diplomat = FALSE;
748
749 unit_type_iterate(utype) {
750 int idx = utype_index(utype);
751
752 defense_bonuses_pct[idx] = 0;
754 best_non_scramble[idx] = -1;
755 /* FIXME: cache it somewhere? */
757 = 100 + get_unittype_bonus(pplayer, ptile, utype, NULL,
759 city_def_against[idx] = MAX(city_def_against[idx], 1);
761
762 /* What flag-specific bonuses do our units have. */
763 /* We value them less than general defense increment */
764 unit_list_iterate(ptile->units, punit) {
765 const struct unit_type *def = unit_type_get(punit);
766
768 city_data->has_diplomat = TRUE;
769 }
771 /* This is first defender of this type. Check defender type
772 * specific bonuses. */
773
774 /* Skip defenders that have no bonuses at all. Acceptable
775 * side-effect is that we can't consider negative bonuses at
776 * all ("No bonuses" should be better than "negative bonus") */
777 if (def->cache.max_defense_mp_bonus_pct > 0) {
778 unit_type_iterate(utype) {
779 int idx = utype_index(utype);
780 int coeff = def->cache.scramble_coeff[idx];
781 int bonus;
782
783 /* FIXME: consider EFT_FORTIFY_DEFENSE_BONUS */
784 if (coeff) {
785 bonus = coeff / city_def_against[idx] - 100;
786 } else {
787 bonus = def->cache.defense_mp_bonuses_pct[idx];
788 }
789
790 if (bonus > defense_bonuses_pct[idx]) {
791 if (!coeff) {
792 best_non_scramble[idx] = bonus;
793 }
794 defense_bonuses_pct[idx] = bonus;
795 } else if (!coeff) {
796 best_non_scramble[idx] = MAX(best_non_scramble[idx], bonus);
797 }
799 } else {
800 /* Just remember that such a unit exists and hope its bonuses are just 0 */
802 }
803
805 }
807 if (sth_does_not_scramble || unit_list_size(ptile->units) <= 0) {
808 /* Scrambling units tend to be expensive. If we have a barenaked city, we'll
809 * need at least a cheap unit. If we have only scramblers,
810 * maybe it's OK. */
813
816 }
817
818 if (player_is_cpuhog(pplayer)) {
819 assess_turns = 6;
820 } else {
822 }
823
824 omnimap = !has_handicap(pplayer, H_MAP);
825
826 /* Check. */
829 struct unit_list *units;
830
831 if (!adv_is_player_dangerous(pplayer, aplayer)) {
832 continue;
833 }
834 /* Note that we still consider the units of players we are not (yet)
835 * at war with. */
836
838 omnimap);
839
840 if (ul_cb != NULL) {
841 units = ul_cb(aplayer);
842 } else {
843 units = aplayer->units;
844 }
845 unit_list_iterate(units, punit) {
846 int move_time;
847 unsigned int vulnerability;
848 int defbonus_pct;
849 const struct unit_type *utype = unit_type_get(punit);
850 struct unit_type_ai *utai = utype_ai_data(utype, ait);
851
852#ifdef FREECIV_WEB
853 /* freeciv-web ignores danger that is far in distance,
854 * no matter how quickly it would reach us; even if
855 * that's *immediately* over a road type that allows
856 * unlimited movement. */
858
862 /* Too far away. */
863 continue;
864 }
865#endif /* FREECIV_WEB */
866
867 if (!utai->carries_occupiers
868 && !utype_acts_hostile(utype)) {
869 /* Harmless unit. */
870 continue;
871 }
872
873 /* Defender unspecific vulnerability and potential move time */
875 punit, &move_time);
876
878 continue;
879 }
880
881 if (unit_can_take_over(punit) || utai->carries_occupiers) {
882 /* Even if there is no attack strength,
883 * we need ANY protector for the city */
885 if (3 >= move_time) {
886 urgency++;
887 if (1 >= move_time) {
888 city_data->grave_danger++;
889 }
890 }
891 }
892
894 if (defbonus_pct > 100) {
895 defbonus_pct = (defbonus_pct + 100) / 2;
896 }
897 /* Reduce vulnerability for specific bonuses we do have */
898 vulnerability = vulnerability * 100 / (defbonus_pct + 100);
899 /* Pass the order for a new defender type against it
900 * to the scientific advisor, urgency considered */
901 (void) dai_wants_defender_against(ait, nmap, pplayer, pcity, utype,
903
905 city_data->diplomat_threat = TRUE;
906 }
907
908 vulnerability *= vulnerability; /* positive feedback */
909 if (1 < move_time) {
911 }
912
917 if (defender != B_LAST) {
918 danger_reduced[defender] += vulnerability / MAX(move_time, 1);
919 }
920 } else if (best_non_scramble[utype_index(utype)] >= 0) {
921 /* To consider building a defensive building,
922 * build first a defender that gets any profit of it */
924 if (defender != B_LAST) {
925 int danred = vulnerability / MAX(move_time, 1);
926 /* Maybe we can build an improvement
927 * that gets normal defender over scrambling one?
928 * Effectively a sqrt-scale because we don't test how high
929 * the effect is. */
932 danred = danred * (100 + best_non_scramble[utype_index(utype)])
933 / (100 + defense_bonuses_pct[utype_index(utype)]);
934 }
935 danger_reduced[defender] += danred;
936 }
937 }
938
941
943
945
946 if (total_danger) {
947 /* If any hostile player has any dangerous unit that can in any time
948 * reach the city, we consider building walls here, if none yet.
949 * FIXME: this value assumes that walls give x3 defense. */
950 city_data->wallvalue = 90;
951 } else {
952 /* No danger.
953 * This is half of the wallvalue of what danger 1 would produce. */
954 city_data->wallvalue = 5;
955 }
956
957 if (0 < city_data->grave_danger) {
958 /* really, REALLY urgent to defend */
959 urgency += 10 * city_data->grave_danger;
960 }
961
962 /* HACK: This needs changing if multiple improvements provide
963 * this effect. */
964 /* FIXME: Accept only buildings helping unit classes we actually use.
965 * Now we consider any land mover helper suitable. */
966 /* Sum of squared defense ratings */
967 defense = assess_defense_igwall(ait, pcity);
968
969 for (i = 0; i < B_LAST; i++) {
970 if (0 < danger_reduced[i]) {
971 dai_reevaluate_building(pcity, &pcity->server.adv->building_want[i],
972 urgency, danger_reduced[i], defense);
973 }
974 }
975
976 if (has_handicap(pplayer, H_DANGER) && 0 == total_danger) {
977 /* Has to have some danger
978 * Otherwise grave_danger will be ignored. */
979 city_data->danger = 1;
980 } else {
981 city_data->danger = total_danger;
982 }
983 city_data->urgency = urgency;
984
986
987 return urgency;
988}
989
990/**********************************************************************/
995 const struct unit_type *punittype)
996{
998 int attack = punittype->attack_strength;
999 int defense = punittype->defense_strength;
1000 int maxbonus_pct = 0;
1001 int fp = punittype->firepower;
1002
1003 /* Sea and helicopters often have their firepower set to low firepower when
1004 * defending. We can't have such units as defenders. */
1007 }
1008 if (((struct unit_type_ai *)utype_ai_data(punittype, ait))->low_firepower) {
1010 }
1011 desire *= fp;
1012 desire *= defense;
1013 desire += punittype->move_rate / SINGLE_MOVE;
1014 desire += attack;
1015
1016 maxbonus_pct = punittype->cache.max_defense_mp_bonus_pct;
1017 if (maxbonus_pct > 100) {
1018 maxbonus_pct = (maxbonus_pct + 100) / 2;
1019 }
1020 desire += desire * maxbonus_pct / 100;
1022 desire /= 10; /* But might actually be worth it */
1023 }
1024
1025 return desire;
1026}
1027
1028/**********************************************************************/
1032 const struct unit_type *punittype)
1033{
1035 int attack = punittype->attack_strength;
1036 int defense = punittype->defense_strength;
1037
1038 desire *= punittype->move_rate;
1039 desire *= punittype->firepower;
1040 desire *= attack;
1041 desire += defense;
1043 desire += desire / 2;
1044 }
1046 desire /= 10; /* But might actually be worth it */
1047 }
1049 desire += desire / 2;
1050 }
1052 desire += desire / 4;
1053 }
1054 if (punittype->adv.igwall) {
1055 desire += desire / 4;
1056 }
1057
1058 return desire;
1059}
1060
1061/**********************************************************************/
1066bool dai_process_defender_want(struct ai_type *ait, const struct civ_map *nmap,
1067 struct player *pplayer,
1068 struct city *pcity, unsigned int danger,
1069 struct adv_choice *choice, adv_want extra_want)
1070{
1071 const struct research *presearch = research_get(pplayer);
1072 /* FIXME: We check if the city has *some* defensive structure,
1073 * but not whether the city has a defensive structure against
1074 * any specific attacker. The actual danger may not be mitigated
1075 * by the defense selected... */
1076 bool walls = city_got_defense_effect(pcity, NULL);
1077 /* Technologies we would like to have. */
1079 /* Our favourite unit. */
1080 adv_want best = -1;
1081 struct unit_type *best_unit_type = NULL;
1082 int best_unit_cost = 1;
1083 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1084 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1085 adv_want total_want = danger + extra_want;
1086
1087 memset(tech_desire, 0, sizeof(tech_desire));
1088
1090 adv_want desire; /* How much we want the unit? */
1091
1092 /* Only consider proper defenders - otherwise waste CPU and
1093 * bump tech want needlessly. */
1096 continue;
1097 }
1098
1100
1102 desire /= 2; /* Not good, just ok */
1103 }
1104
1106 /* Causes unhappiness even when in defense, so not a good
1107 * idea for a defender, unless it is _really_ good.
1108 * Downright counter productive, if we want unit just for
1109 * maintaining peace. */
1110 if (danger == 0) {
1111 desire = -50;
1112 } else {
1113 desire /= 2;
1114 }
1115 }
1116
1117 if (desire > 0) {
1118 desire /= POWER_DIVIDER / 2; /* Good enough, no rounding errors. */
1119 desire *= desire;
1120
1122 /* We can build the unit now... */
1123
1124 int build_cost = utype_build_shield_cost(pcity, NULL, punittype);
1125 int limit_cost = pcity->shield_stock + 40;
1126
1128 desire *= city_data->wallvalue;
1129 /* TODO: More use of POWER_FACTOR ! */
1131 }
1132
1134 && build_cost < best_unit_cost)
1135 || ((desire > best
1136 || (ADV_WANTS_EQ(desire, best)
1137 && build_cost <= best_unit_cost))
1138 && (best_unit_type == NULL
1139 /* In case all units are more expensive than limit_cost */
1140 || limit_cost <= pcity->shield_stock + 40))) {
1141 best = desire;
1143 best_unit_cost = build_cost;
1144 }
1146 /* We first need to develop the tech required by the unit... */
1147
1148 /* Cost (shield equivalent) of gaining these techs. */
1149 /* FIXME? Katvrr advises that this should be weighted more heavily in
1150 * big danger. */
1151 int tech_cost = 0;
1152
1157
1158 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1159
1160 /* Contrary to the above, we don't care if walls are actually built
1161 * - we're looking into the future now. */
1163 desire *= city_data->wallvalue;
1165 }
1166
1167 /* Yes, there's some similarity with kill_desire(). */
1168 /* TODO: Explain what shield cost has to do with tech want. */
1172 }
1173 }
1175
1176 if (best == -1) {
1177 CITY_LOG(LOG_DEBUG, pcity, "Ooops - we cannot build any defender!");
1178 }
1179
1180 if (best_unit_type != NULL) {
1182 best *= city_data->wallvalue;
1183 best /= POWER_FACTOR;
1184 }
1185 } else {
1186 best_unit_cost = 100; /* Building impossible is considered costly.
1187 * This should increase want for tech providing
1188 * first defender type. */
1189 }
1190
1191 if (best <= 0) {
1192 best = 1; /* Avoid division by zero below. */
1193 }
1194
1195 /* Update tech_want for appropriate techs for units we want to build. */
1197 if (tech_desire[utype_index(punittype)] > 0) {
1198 /* TODO: Document or fix the algorithm below. I have no idea why
1199 * it is written this way, and the results seem strange to me. - Per */
1201
1203 plr_data->tech_want[advance_index(padv)]
1204 += desire;
1205 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1206 "+ " ADV_WANT_PRINTF " for %s to defend %s",
1207 desire,
1211 }
1213
1214 if (!best_unit_type) {
1215 return FALSE;
1216 }
1217
1218 choice->value.utype = best_unit_type;
1219 choice->want = danger; /* FIXME: Not 'total_want' because of the way callers
1220 * are constructed. They may overwrite this value,
1221 * and then the value will NOT contain 'extra_want'.
1222 * Later we may add 'extra_want', and don't want it
1223 * already included in case this was NOT overwritten. */
1224 choice->type = CT_DEFENDER;
1225
1226 return TRUE;
1227}
1228
1229/**********************************************************************/
1246static void process_attacker_want(struct ai_type *ait,
1247 struct city *pcity,
1248 adv_want value,
1249 const struct unit_type *victim_unit_type,
1250 struct player *victim_player,
1251 int veteran, struct tile *ptile,
1252 struct adv_choice *best_choice,
1253 struct pf_map *ferry_map,
1254 struct unit *boat,
1255 const struct unit_type *boattype)
1256{
1257 struct player *pplayer = city_owner(pcity);
1258 const struct research *presearch = research_get(pplayer);
1259 /* The enemy city. acity == NULL means stray enemy unit */
1260 struct city *acity = tile_city(ptile);
1261 struct pf_parameter parameter;
1262 struct pf_map *pfm;
1263 struct pf_position pos;
1264 const struct unit_type *orig_utype = best_choice->value.utype;
1265 int victim_count = 1;
1266 int needferry = 0;
1267 bool unhap;
1268 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
1269 const struct civ_map *nmap = &(wld.map);
1270
1271 /* Has to be initialized to make gcc happy */
1272 struct ai_city *acity_data = NULL;
1273
1275
1276 if (acity != NULL) {
1278 }
1279
1280 if (utype_class(orig_utype)->adv.sea_move == MOVE_NONE
1281 && !boat && boattype != NULL) {
1282 /* Cost of ferry */
1284 }
1285
1286 if (!is_stack_vulnerable(ptile)) {
1287 /* If it is a city, a fortress or an air base,
1288 * we may have to whack it many times */
1290 }
1291
1295 && (U_NOT_OBSOLETED == punittype->obsoleted_by
1296 || !can_city_build_unit_direct(nmap, pcity, punittype->obsoleted_by,
1297 RPT_CERTAIN))
1298 && punittype->attack_strength > 0 /* Or we'll get SIGFPE */) {
1299 /* Values to be computed */
1301 adv_want want;
1302 int move_time;
1303 int vuln;
1304 int veteran_level
1306 &(const struct req_context) {
1307 .player = pplayer,
1308 .city = pcity,
1309 .tile = city_tile(pcity),
1310 .unittype = punittype,
1311 },
1312 NULL,
1314 /* Levels start from zero, so max level is 'number of levels - 1' */
1316 /* Cost (shield equivalent) of gaining these techs. */
1317 /* FIXME? Katvrr advises that this should be weighted more heavily in big
1318 * danger. */
1319 int tech_cost = 0;
1321 /* See description of kill_desire() for info about this variables. */
1323 int attack;
1324 int tech_dist = 0;
1325
1328 SINGLE_MOVE, punittype->hp);
1329
1332
1334 if (tech_dist == 0) {
1336 }
1338
1339 tech_cost = tech_cost / 4 / city_list_size(pplayer->cities);
1340
1341 /* Take into account reinforcements strength */
1342 if (acity) {
1343 attack += acity_data->attack;
1344 }
1345
1346 if (attack == 0) {
1347 /* Yes, it can happen that a military unit has attack = 1,
1348 * for example militia with HP = 1 (in civ1 ruleset). */
1349 continue;
1350 }
1351
1352 attack *= attack;
1353
1355 pplayer);
1356 parameter.omniscience = !has_handicap(pplayer, H_MAP);
1357 pfm = pf_map_new(&parameter);
1358
1359 /* Set the move_time appropriately. */
1360 move_time = -1;
1361 if (NULL != ferry_map) {
1362 struct tile *dest_tile;
1363
1364 if (find_beachhead(pplayer, ferry_map, ptile, punittype,
1365 boattype, &dest_tile, NULL)
1366 && pf_map_position(ferry_map, dest_tile, &pos)) {
1367 move_time = pos.turn;
1370 if (atile == dest_tile) {
1372 move_time += pos.turn;
1373 break;
1374 } else if (atile == ptile) {
1375 /* Reaching directly seems better. */
1377 move_time = pos.turn;
1378 break;
1379 }
1381 }
1382 }
1383
1384 if (-1 == move_time) {
1385 if (pf_map_position(pfm, ptile, &pos)) {
1386 move_time = pos.turn;
1387 } else {
1389 continue;
1390 }
1391 }
1393
1394 /* Estimate strength of the enemy. */
1395
1396 if (victim_unit_type) {
1399 ptile, FALSE, veteran);
1400 } else {
1401 vuln = 0;
1402 }
1403
1404 /* Not bothering to s/!vuln/!pdef/ here for the time being. -- Syela
1405 * (this is noted elsewhere as terrible bug making warships yoyoing)
1406 * as the warships will go to enemy cities hoping that the enemy builds
1407 * something for them to kill. */
1408 if (vuln == 0
1409 && (utype_class(punittype)->adv.land_move == MOVE_NONE
1410 || 0 < utype_fuel(punittype))) {
1411 desire = 0;
1412
1413 } else {
1414 if (acity
1416 && acity_data->invasion.attack > 0
1417 && acity_data->invasion.occupy == 0) {
1419 float finishing_factor = 1;
1420
1423 }
1425 } else {
1426 desire = 0;
1427 }
1428
1429 if (!acity) {
1430 desire = kill_desire(value, attack, bcost, vuln, victim_count);
1431 } else {
1432 adv_want kd;
1433 int city_attack = acity_data->attack * acity_data->attack;
1434
1435 /* See daiunit.c:find_something_to_kill() for comments. */
1436 kd = kill_desire(value, attack,
1437 (bcost + acity_data->bcost), vuln,
1438 victim_count);
1439
1440 if (value * city_attack > acity_data->bcost * vuln) {
1441 kd -= kill_desire(value, city_attack,
1442 acity_data->bcost, vuln,
1443 victim_count);
1444 }
1445
1446 desire = MAX(desire, kd);
1447 }
1448 }
1449
1451 /* We can be possibly making some people of our homecity unhappy - then
1452 * we don't want to travel too far away to our victims. */
1453 /* TODO: Unify the 'unhap' dependency to some common function. */
1456
1457 want = military_amortize(pplayer, pcity, desire, MAX(1, move_time),
1459
1460 if (want > 0) {
1461 if (tech_dist > 0) {
1462 /* This is a future unit, tell the scientist how much we need it */
1464 plr_data->tech_want[advance_index(padv)]
1465 += want;
1466 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
1467 "+ " ADV_WANT_PRINTF " for %s vs %s(%d,%d)",
1468 want,
1471 TILE_XY(ptile));
1473 } else if (want > best_choice->want) {
1474 const struct impr_type *impr_req;
1475
1477 /* This is a real unit and we really want it */
1478
1479 CITY_LOG(LOG_DEBUG, pcity, "overriding %s(" ADV_WANT_PRINTF
1480 ") with %s(" ADV_WANT_PRINTF ")"
1481 " [attack=%d,value=" ADV_WANT_PRINTF
1482 ",move_time=%d,vuln=%d,bcost=%d]",
1483 utype_rule_name(best_choice->value.utype),
1484 best_choice->want,
1486 want,
1487 attack, value, move_time, vuln, bcost);
1488
1489 best_choice->value.utype = punittype;
1490 best_choice->want = want;
1491 best_choice->type = CT_ATTACKER;
1493 pcity)))) {
1494 CITY_LOG(LOG_DEBUG, pcity, "cannot build unit %s",
1497 RPT_CERTAIN)) {
1498 /* Building this unit requires a specific type of improvement.
1499 * So we build this improvement instead. This may not be the
1500 * best behavior. */
1501 CITY_LOG(LOG_DEBUG, pcity, "building %s to build unit %s",
1504 best_choice->value.building = impr_req;
1505 best_choice->want = want;
1506 best_choice->type = CT_BUILDING;
1507 } else {
1508 /* This should never happen? */
1509 CITY_LOG(LOG_DEBUG, pcity, "cannot build %s or unit %s",
1512 }
1513 }
1514 }
1515 }
1517}
1518
1519/**********************************************************************/
1530static struct adv_choice *kill_something_with(struct ai_type *ait,
1531 const struct civ_map *nmap,
1532 struct player *pplayer,
1533 struct city *pcity, struct unit *myunit,
1534 struct adv_choice *choice)
1535{
1536 /* Our attack rating (with reinforcements) */
1537 int attack;
1538 /* Benefit from fighting the target */
1540 /* Defender of the target city/tile */
1541 struct unit *pdef;
1542 const struct unit_type *def_type;
1543 struct player *def_owner;
1544 int def_vet; /* Is the defender veteran? */
1545 /* Target coordinates */
1546 struct tile *ptile;
1547 /* Our transport */
1548 struct unit *ferryboat;
1549 /* Our target */
1550 struct city *acity;
1551 /* Type of the boat (real or a future one) */
1552 const struct unit_type *boattype;
1553 struct pf_map *ferry_map = NULL;
1554 int move_time;
1555 struct adv_choice *best_choice;
1556 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1557 struct ai_city *acity_data;
1558
1560 best_choice->value.utype = unit_type_get(myunit);
1561 best_choice->type = CT_ATTACKER;
1562 adv_choice_set_use(best_choice, "attacker");
1563
1566
1567 if (city_data->danger != 0 && assess_defense(ait, pcity) == 0) {
1568 /* Defense comes first! */
1569 goto cleanup;
1570 }
1571
1572 best_choice->want = find_something_to_kill(ait, pplayer, myunit, &ptile, NULL,
1573 &ferry_map, &ferryboat,
1574 &boattype, &move_time);
1575 if (NULL == ptile
1576 || ptile == unit_tile(myunit)
1577 || !can_unit_attack_tile(myunit, NULL, ptile)) {
1578 goto cleanup;
1579 }
1580
1581 acity = tile_city(ptile);
1582
1583 if (myunit->id != 0) {
1584 log_error("%s(): non-virtual unit!", __FUNCTION__);
1585 goto cleanup;
1586 }
1587
1589 if (acity) {
1591 attack += acity_data->attack;
1592 }
1593 attack *= attack;
1594
1595 if (NULL != acity) {
1596 /* Rating of enemy defender */
1597 int vulnerability;
1598
1599 if (!POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, city_owner(acity))) {
1600 /* Not a valid target */
1601 goto cleanup;
1602 }
1603
1606 if (1 < move_time && def_type) {
1609 city_owner(acity), ptile,
1610 FALSE, def_vet);
1612 } else {
1613 vulnerability = 0;
1614 benefit = 0;
1615 def_vet = 0;
1616 }
1617
1618 pdef = get_defender(nmap, myunit, ptile, NULL);
1619 if (pdef) {
1621 city_owner(acity), ptile, FALSE,
1622 pdef->veteran);
1623 if (vulnerability < m) {
1625 def_vet = pdef->veteran;
1628 }
1629 }
1630 if (unit_can_take_over(myunit) || acity_data->invasion.occupy > 0) {
1631 /* Bonus for getting the city */
1633 float finishing_factor = 1;
1634
1637 }
1639 }
1640
1641 /* end dealing with cities */
1642 } else {
1643
1644 if (NULL != ferry_map) {
1646 ferry_map = NULL;
1647 }
1648
1649 pdef = get_defender(nmap, myunit, ptile, NULL);
1650 if (!pdef) {
1651 /* Nobody to attack! */
1652 goto cleanup;
1653 }
1654
1656
1658 def_vet = pdef->veteran;
1660 /* end dealing with units */
1661 }
1662
1663 if (NULL == ferry_map) {
1665 def_vet, ptile,
1667 } else {
1668 /* Attract a boat to our city or retain the one that's already here */
1670 best_choice->need_boat = TRUE;
1672 def_vet, ptile,
1673 best_choice, ferry_map, ferryboat, boattype);
1674 }
1675
1676 if (best_choice->want > choice->want) {
1677 /* We want attacker more than what we have selected before */
1680 CITY_LOG(LOG_DEBUG, pcity, "kill_something_with()"
1681 " %s has chosen attacker, %s, want=" ADV_WANT_PRINTF,
1683 utype_rule_name(best_choice->value.utype),
1684 best_choice->want);
1685
1686 if (NULL != ferry_map && !ferryboat) { /* need a new ferry */
1687 /* We might need a new boat even if there are boats free,
1688 * if they are blockaded or in inland seas*/
1690 if (dai_choose_role_unit(ait, pplayer, pcity, choice, CT_ATTACKER,
1692 && dai_is_ferry_type(choice->value.utype, ait)) {
1693#ifdef FREECIV_DEBUG
1694 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
1695
1696 log_debug("kill_something_with() %s has chosen attacker ferry, "
1697 "%s, want=" ADV_WANT_PRINTF ", %d of %d free",
1699 utype_rule_name(choice->value.utype),
1700 choice->want,
1701 ai->stats.available_boats, ai->stats.boats);
1702#endif /* FREECIV_DEBUG */
1703
1704 adv_choice_set_use(choice, "attacker ferry");
1705 } /* else can not build ferries yet */
1706 }
1707 }
1708
1709cleanup:
1710 if (best_choice != choice) {
1711 /* It was not taken to use.
1712 * This hackery needed since 'goto cleanup:' might skip
1713 * sensible points to do adv_free_choice(). */
1715 }
1716 if (NULL != ferry_map) {
1718 }
1719
1720 return choice;
1721}
1722
1723/**********************************************************************/
1729static void dai_unit_consider_bodyguard(struct ai_type *ait,
1730 const struct civ_map *nmap,
1731 struct city *pcity,
1732 struct unit_type *punittype,
1733 struct adv_choice *choice)
1734{
1735 if (choice->want < DAI_WANT_MILITARY_EMERGENCY) {
1736 struct player *pplayer = city_owner(pcity);
1737 struct unit *aunit = NULL;
1738 struct city *acity = NULL;
1739 struct unit *virtualunit
1742 punittype));
1743 const adv_want want = look_for_charge(ait, nmap, pplayer, virtualunit,
1744 &aunit, &acity);
1745
1746 if (want > choice->want) {
1747 choice->want = want;
1748 choice->value.utype = punittype;
1749 choice->type = CT_DEFENDER;
1750 adv_choice_set_use(choice, "bodyguard");
1751 }
1752
1754 }
1755}
1756
1757/**********************************************************************/
1766 struct adv_choice *choice)
1767{
1769
1770 /* Sanity */
1771 if (!is_unit_choice_type(choice->type)
1774 return;
1775 }
1776
1777 /* N.B.: have to check that we haven't already built the building --mck */
1779 choice->value.utype)) != B_LAST
1781 choice->value.building = improvement_by_number(id);
1782 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER,
1784 / TRAIT_DEFAULT_VALUE / 2));
1785 choice->type = CT_BUILDING;
1786 adv_choice_set_use(choice, "veterancy building");
1787 }
1788}
1789
1790/**********************************************************************/
1796 const struct civ_map *nmap,
1797 struct player *pplayer,
1798 struct city *pcity,
1800{
1801 struct adv_data *ai = adv_data_get(pplayer, NULL);
1802 struct unit_type *punittype;
1803 unsigned int our_def, urgency;
1804 struct tile *ptile = pcity->tile;
1805 struct unit *virtualunit;
1806 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1808 bool martial_need = FALSE;
1809 struct adv_choice *choice = adv_new_choice();
1810 bool allow_gold_upkeep;
1811
1812 urgency = assess_danger(ait, nmap, pcity, ul_cb);
1813 /* Changing to quadratic to stop AI from building piles
1814 * of small units -- Syela */
1815 /* It has to be AFTER assess_danger() thanks to wallvalue. */
1817
1818 dai_choose_diplomat_defensive(ait, pplayer, pcity, choice, our_def);
1819
1821 + pcity->feel[CITIZEN_ANGRY][FEELING_NATIONALITY] > 0) {
1823 }
1824
1825 if (!martial_need) {
1827 if (pcity->specialists[sp] > 0
1830 break;
1831 }
1833 }
1834
1835 if (martial_need
1839 1, FEELING_FINAL);
1840 }
1841
1842 /* Otherwise no need to defend yet */
1843 if (city_data->danger != 0 || martial_value > 0) {
1844 struct impr_type *pimprove;
1845 int num_defenders = unit_list_size(ptile->units);
1846 int wall_id, danger;
1847 bool build_walls = TRUE;
1848 bool def_unit_selected = FALSE;
1849 int qdanger = city_data->danger * city_data->danger;
1850
1851 if (qdanger <= 0) {
1852 /* We only need these defenders because of Martial Law value */
1853 danger = 0;
1854 build_walls = FALSE; /* Walls don't provide Martial Law */
1855 } else {
1856 /* First determine the danger. It is measured in percents of our
1857 * defensive strength, capped at 200 + urgency */
1858 if (qdanger >= our_def) {
1859 if (urgency == 0) {
1860 /* Don't waste money */
1861 danger = 100;
1862 } else if (our_def == 0) {
1863 danger = 200 + urgency;
1864 } else {
1865 danger = MIN(200, 100 * qdanger / our_def) + urgency;
1866 }
1867 } else {
1868 danger = 100 * qdanger / our_def;
1869 }
1870
1871 if (pcity->surplus[O_SHIELD] <= 0 && our_def != 0) {
1872 /* Won't be able to support anything */
1873 danger = 0;
1874 }
1875 }
1876
1877 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d urgency=%d danger=%d num_def=%d "
1878 "our_def=%d", urgency, danger, num_defenders, our_def);
1879
1880 if (our_def == 0 && danger > 0) {
1881 /* Build defensive unit first! Walls will help nothing if there's
1882 * nobody behind them. */
1883 if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger, choice,
1884 martial_value)) {
1885 choice->want = DAI_WANT_BELOW_MIL_EMERGENCY + danger;
1886 adv_choice_set_use(choice, "first defender");
1889
1890 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants first defender with " ADV_WANT_PRINTF,
1891 choice->want);
1892 }
1893 }
1894 if (build_walls) {
1895 /* FIXME: 1. Does not consider what kind of future danger is likely, so
1896 * may build SAM batteries when enemy has only land units. */
1897 /* We will build walls if we can and want and (have "enough" defenders or
1898 * can just buy the walls straight away) */
1899
1900 /* HACK: This needs changing if multiple improvements provide
1901 * this effect. */
1903 pimprove = improvement_by_number(wall_id);
1904
1905 if (wall_id != B_LAST
1906 && pcity->server.adv->building_want[wall_id] != 0 && our_def != 0
1909 || (city_data->grave_danger == 0
1910 && pplayer->economic.gold
1911 > impr_buy_gold_cost(pcity, pimprove, pcity->shield_stock)))
1912 && ai_fuzzy(pplayer, TRUE)) {
1913 if (pcity->server.adv->building_want[wall_id] > 0) {
1914 /* NB: great wall is under domestic */
1915 choice->value.building = pimprove;
1916 /* building_want is hacked by assess_danger() */
1917 choice->want = pcity->server.adv->building_want[wall_id];
1918 choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER, pplayer)
1919 / TRAIT_DEFAULT_VALUE / 2));
1920 if (urgency == 0 && choice->want > DAI_WANT_BELOW_MIL_EMERGENCY) {
1922 }
1923 choice->type = CT_BUILDING;
1924 adv_choice_set_use(choice, "defense building");
1926 "m_a_c_d wants defense building with " ADV_WANT_PRINTF,
1927 choice->want);
1928 } else {
1930 }
1931 } else {
1933 }
1934 }
1935
1936 /* If our choice isn't defender unit already, consider one */
1937 if (!def_unit_selected) {
1938 if ((danger > 0 && num_defenders <= urgency) || martial_value > 0) {
1939 struct adv_choice uchoice;
1940
1942
1943 /* Consider building defensive units */
1944 if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger,
1946 /* Potential defender found */
1947 if (urgency == 0
1948 && uchoice.value.utype->defense_strength == 1) {
1949 /* FIXME: check other reqs (unit class?) */
1950 if (get_city_bonus(pcity, EFT_HP_REGEN) > 0) {
1951 /* Unlikely */
1952 uchoice.want = MIN(49, danger);
1953 } else {
1954 uchoice.want = MIN(25, danger);
1955 }
1956 } else {
1957 uchoice.want = danger;
1958 }
1959
1960 uchoice.want += martial_value;
1961 if (danger > 0) {
1962 adv_choice_set_use(&uchoice, "defender");
1963 } else {
1964 adv_choice_set_use(&uchoice, "police");
1965 }
1966
1967 if (!build_walls || uchoice.want > choice->want) {
1968 adv_choice_copy(choice, &uchoice);
1969 }
1971
1972 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants %s with desire " ADV_WANT_PRINTF,
1973 utype_rule_name(choice->value.utype),
1974 choice->want);
1975 } else {
1976 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d cannot select defender");
1977 }
1978 } else {
1979 CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d does not want defenders");
1980 }
1981 }
1982 } /* Ok, don't need to defend */
1983
1984 if (pcity->surplus[O_SHIELD] <= 0
1986 || pcity->id == ai->wonder_city) {
1987 /* Things we consider below are not life-saving so we don't want to
1988 * build them if our populace doesn't feel like it */
1989 return choice;
1990 }
1991
1992 if (pplayer->economic.tax <= 50 || city_total_unit_gold_upkeep(pcity) <= 0) {
1993 /* Always allow one unit with real gold upkeep (after EFT_UNIT_UPKEEP_FREE_PER_CITY)
1994 * Allow more if economics is so strong that we have not increased taxes. */
1996 } else {
1998 }
1999
2000 /* Consider making a land bodyguard */
2003 if (punittype) {
2005 }
2006
2007 /* If we are in severe danger, don't consider attackers. This is probably
2008 too general. In many cases we will want to buy attackers to counterattack.
2009 -- Per */
2011 && city_data->grave_danger > 0) {
2013 "severe danger (want " ADV_WANT_PRINTF "), force defender",
2014 choice->want);
2015 return choice;
2016 }
2017
2018 /* Consider making an offensive diplomat */
2019 dai_choose_diplomat_offensive(ait, nmap, pplayer, pcity, choice);
2020
2021 /* Consider making a sea bodyguard */
2024 if (punittype) {
2026 }
2027
2028 /* Consider making an airplane */
2029 (void) dai_choose_attacker_air(ait, nmap, pplayer, pcity, choice,
2031
2032 /* Consider making a paratrooper */
2033 dai_choose_paratrooper(ait, nmap, pplayer, pcity, choice, allow_gold_upkeep);
2034
2035 /* Check if we want a sailing attacker. Have to put sailing first
2036 before we mung the seamap */
2038 if (punittype) {
2040 pplayer, pcity, punittype,
2042 choice = kill_something_with(ait, nmap, pplayer, pcity, virtualunit, choice);
2044 }
2045
2046 /* Consider a land attacker or a ferried land attacker
2047 * (in which case, we might want a ferry before an attacker)
2048 */
2050 if (punittype) {
2052 choice = kill_something_with(ait, nmap, pplayer, pcity, virtualunit, choice);
2054 }
2055
2056 /* Consider a hunter */
2057 dai_hunter_choice(ait, pplayer, pcity, choice, allow_gold_upkeep);
2058
2059 /* Consider veteran level enhancing buildings before non-urgent units */
2061
2062 if (choice->want <= 0) {
2063 CITY_LOG(LOGLEVEL_BUILD, pcity, "military advisor has no advice");
2064 } else {
2066 "military advisor choice: %s (want " ADV_WANT_PRINTF ")",
2067 adv_choice_rule_name(choice),
2068 choice->want);
2069 }
2070
2071 return choice;
2072}
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:614
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1121
int adv_unittype_att_rating(const struct unit_type *punittype, int veteran, int moves_left, int hp)
Definition advgoto.c:387
int adv_unit_att_rating(const struct unit *punit)
Definition advgoto.c:398
#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:1296
const char * city_name_get(const struct city *pcity)
Definition city.c:1157
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:808
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1653
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:860
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:911
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:957
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:982
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1278
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:565
@ CITIZEN_ANGRY
Definition city.h:269
@ CITIZEN_UNHAPPY
Definition city.h:268
#define city_owner(_pcity_)
Definition city.h:564
#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:590
Impr_type_id dai_find_source_building(struct city *pcity, enum effect_type effect_type, const struct unit_type *utype)
Definition daicity.c:2197
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:1444
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:1373
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:1135
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Definition daiunit.c:2997
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:1214
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:784
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:903
#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:3055
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:1036
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_CERTAIN
Definition fc_types.h:516
@ 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
static enum log_level max_level
Definition log.c:49
#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:121
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 CLIP(lower, current, upper)
Definition shared.h:57
#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:341
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
int boats
Definition daidata.h:79
struct ai_plr::@279 stats
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:90
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:100
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:2525
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:1682
bool is_special_unit(const struct unit *punit)
Definition unit.c:369
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1786
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2511
#define unit_tile(_pu)
Definition unit.h:408
#define unit_owner(_pu)
Definition unit.h:407
#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
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2662
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:2535
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:2776
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:849
#define unit_tech_reqs_iterate_end
Definition unittype.h:891
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:885
@ 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:865
#define U_LAST
Definition unittype.h:40
#define unit_type_iterate_end
Definition unittype.h:872
#define U_NOT_OBSOLETED
Definition unittype.h:535