Freeciv-3.3: /fast/freeciv/nightly/main/server/advisors/advdata.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
advdata.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2002 - The Freeciv Project
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/* utility */
19#include "log.h"
20#include "mem.h"
21
22/* common */
23#include "actions.h"
24#include "ai.h"
25#include "city.h"
26#include "effects.h"
27#include "game.h"
28#include "government.h"
29#include "map.h"
30#include "movement.h"
31#include "research.h"
32#include "unit.h"
33#include "unitlist.h"
34
35/* common/aicore */
36#include "aisupport.h"
37#include "path_finding.h"
38#include "pf_tools.h"
39
40/* server */
41#include "cityturn.h"
42#include "diplhand.h"
43#include "maphand.h"
44#include "plrhand.h"
45#include "srv_log.h"
46#include "unittools.h"
47
48/* server/advisors */
49#include "advbuilding.h"
50#include "advcity.h"
51#include "advtools.h"
52
53/* ai */
54#include "handicaps.h"
55
56#include "advdata.h"
57
58static void adv_dipl_new(const struct player *plr1,
59 const struct player *plr2);
60static void adv_dipl_free(const struct player *plr1,
61 const struct player *plr2);
62static struct adv_dipl *adv_dipl_get(const struct player *plr1,
63 const struct player *plr2);
64
65/**********************************************************************/
73 static void adv_data_city_impr_calc(struct player *pplayer,
74 struct adv_data *adv)
75{
76 int count[ADV_IMPR_LAST];
77
78 memset(count, 0, sizeof(count));
79
80 improvement_iterate(pimprove) {
81 struct universal source = {
82 .kind = VUT_IMPROVEMENT,
83 .value = {.building = pimprove}
84 };
85
86 adv->impr_calc[improvement_index(pimprove)] = ADV_IMPR_ESTIMATE;
87
88 /* Find largest extension */
89 effect_list_iterate(get_req_source_effects(&source), peffect) {
90 switch (peffect->type) {
91#if 0
92 /* TODO */
93 case EFT_FORCE_CONTENT:
94 case EFT_FORCE_CONTENT_PCT:
95 case EFT_MAKE_CONTENT:
96 case EFT_MAKE_CONTENT_MIL:
97 case EFT_MAKE_CONTENT_MIL_PER:
98 case EFT_MAKE_CONTENT_PCT:
99 case EFT_MAKE_HAPPY:
100#endif
101 case EFT_CAPITAL_CITY:
102 case EFT_POLLU_POP_PCT:
103 case EFT_POLLU_POP_PCT_2:
104 case EFT_POLLU_PROD_PCT:
105 case EFT_OUTPUT_BONUS:
106 case EFT_OUTPUT_BONUS_2:
107 case EFT_OUTPUT_WASTE_PCT:
108 case EFT_UPKEEP_FREE:
109 requirement_vector_iterate(&peffect->reqs, preq) {
110 if (VUT_IMPROVEMENT == preq->source.kind
111 && preq->source.value.building == pimprove) {
112 if (adv->impr_calc[improvement_index(pimprove)] != ADV_IMPR_CALCULATE_FULL) {
113 adv->impr_calc[improvement_index(pimprove)] = ADV_IMPR_CALCULATE;
114 }
115 if (preq->range > adv->impr_range[improvement_index(pimprove)]) {
116 adv->impr_range[improvement_index(pimprove)] = preq->range;
117 }
118 }
119 } requirement_vector_iterate_end;
120 break;
121 case EFT_OUTPUT_ADD_TILE:
122 case EFT_OUTPUT_PER_TILE:
123 case EFT_OUTPUT_INC_TILE:
124 requirement_vector_iterate(&peffect->reqs, preq) {
125 if (VUT_IMPROVEMENT == preq->source.kind
126 && preq->source.value.building == pimprove) {
127 adv->impr_calc[improvement_index(pimprove)] = ADV_IMPR_CALCULATE_FULL;
128 if (preq->range > adv->impr_range[improvement_index(pimprove)]) {
129 adv->impr_range[improvement_index(pimprove)] = preq->range;
130 }
131 }
132 } requirement_vector_iterate_end;
133 break;
134 default:
135 /* Nothing! */
136 break;
137 }
138 } effect_list_iterate_end;
139 } improvement_iterate_end;
140}
141
142/**********************************************************************/
147 static bool player_has_really_useful_tech_parasite(struct player* pplayer)
148{
149 struct research *presearch, *aresearch;
150 int players_needed = get_player_bonus(pplayer, EFT_TECH_PARASITE);
151
152 if (players_needed == 0) {
153 return FALSE;
154 }
155
156 presearch = research_get(pplayer);
157 advance_index_iterate(A_FIRST, tech) {
158 int players_having;
159
160 if (!research_invention_gettable(presearch, tech,
161 game.info.tech_parasite_allow_holes)
162 || TECH_KNOWN == research_invention_state(presearch, tech)) {
163 continue;
164 }
165
166 players_having = 0;
167
168 players_iterate_alive(aplayer) {
169 if (aplayer == pplayer) {
170 continue;
171 }
172
173 aresearch = research_get(aplayer);
174 if (TECH_KNOWN == research_invention_state(aresearch, tech)
175 || aresearch->researching == tech) {
176 players_having++;
177 if (players_having >= players_needed) {
178 return TRUE;
179 }
180 }
181 } players_iterate_alive_end;
182 } advance_index_iterate_end;
183 return FALSE;
184}
185
186/**********************************************************************/
191 void adv_data_analyze_rulesets(struct player *pplayer)
192{
193 struct adv_data *adv = pplayer->server.adv;
194
195 fc_assert_ret(adv != NULL);
196
197 adv_data_city_impr_calc(pplayer, adv);
198}
199
200/**********************************************************************/
203 static void count_my_units(struct player *pplayer)
204{
205 struct adv_data *adv = adv_data_get(pplayer, NULL);
206
207 memset(&adv->stats.units, 0, sizeof(adv->stats.units));
208
209 unit_list_iterate(pplayer->units, punit) {
210 struct unit_class *pclass = unit_class_get(punit);
211
212 adv->stats.units.byclass[uclass_index(pclass)]++;
213
214 if (unit_has_type_flag(punit, UTYF_COAST_STRICT)) {
215 adv->stats.units.coast_strict++;
216 }
217 if (utype_can_do_action(unit_type_get(punit), ACTION_SUICIDE_ATTACK)) {
218 adv->stats.units.suicide_attackers++;
219 }
220 if (unit_can_do_action(punit, ACTION_PARADROP)
221 || unit_can_do_action(punit, ACTION_PARADROP_CONQUER)
222 || unit_can_do_action(punit, ACTION_PARADROP_FRIGHTEN)
223 || unit_can_do_action(punit, ACTION_PARADROP_FRIGHTEN_CONQUER)
224 || unit_can_do_action(punit, ACTION_PARADROP_ENTER)
225 || unit_can_do_action(punit, ACTION_PARADROP_ENTER_CONQUER)) {
226 /* TODO: Cover also teleporting */
227 adv->stats.units.paratroopers++;
228 }
229 if (utype_can_do_action(punit->utype, ACTION_AIRLIFT)) {
230 adv->stats.units.airliftable++;
231 }
232 if (can_upgrade_unittype(pplayer, unit_type_get(punit)) >= 0) {
233 adv->stats.units.upgradeable++;
234 }
235 } unit_list_iterate_end;
236}
237
238/**********************************************************************/
242 bool is_adv_data_phase_open(struct player *pplayer)
243{
244 struct adv_data *adv = pplayer->server.adv;
245
246 return adv->phase_is_initialized;
247}
248
249/**********************************************************************/
262 bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
263{
264 struct adv_data *adv = pplayer->server.adv;
265 bool danger_of_nukes;
266 action_id nuke_actions[MAX_NUM_ACTIONS];
267
268 {
269 int i = 0;
270
271 /* Conventional nukes */
272 action_array_add_all_by_result(nuke_actions, &i, ACTRES_NUKE);
273 action_array_add_all_by_result(nuke_actions, &i, ACTRES_NUKE_UNITS);
274 /* TODO: worry about spy nuking too? */
275 action_array_end(nuke_actions, i);
276 }
277
278 fc_assert_ret_val(adv != NULL, FALSE);
279
280 if (adv->phase_is_initialized) {
281 return FALSE;
282 }
283 adv->phase_is_initialized = TRUE;
284
285 TIMING_LOG(AIT_AIDATA, TIMER_START);
286
287 danger_of_nukes = FALSE;
288
289 /*** Threats ***/
290
291 adv->num_continents = wld.map.num_continents;
292 adv->num_oceans = wld.map.num_oceans;
293 adv->continents = fc_calloc(adv->num_continents + 1, sizeof(struct adv_area_info));
294 adv->oceans = fc_calloc(adv->num_oceans + 1, sizeof(struct adv_area_info));
295 adv->threats.invasions = FALSE;
296 adv->threats.nuclear = 0; /* None */
297 adv->threats.igwall = FALSE;
298
299 whole_map_iterate(&(wld.map), ptile) {
300 Continent_id cont = tile_continent(ptile);
301
302 if (cont >= 0) {
303 adv->continents[cont].size++;
304 } else {
305 adv->oceans[-cont].size++;
306 }
307 } whole_map_iterate_end;
308
309 players_iterate(aplayer) {
310 if (!adv_is_player_dangerous(pplayer, aplayer)) {
311 continue;
312 }
313
314 /* The idea is that if there aren't any hostile cities on
315 * our continent, the danger of land attacks is not big
316 * enough to warrant city walls. Concentrate instead on
317 * coastal fortresses and hunting down enemy transports. */
318 city_list_iterate(aplayer->cities, acity) {
319 Continent_id continent = tile_continent(acity->tile);
320
321 if (continent >= 0) {
322 adv->continents[continent].threat = TRUE;
323 }
324 } city_list_iterate_end;
325
326 unit_list_iterate(aplayer->units, punit) {
327 const struct unit_class *pclass = unit_class_get(punit);
328
329 if (unit_type_get(punit)->adv.igwall) {
330 adv->threats.igwall = TRUE;
331 }
332
333 if (pclass->adv.sea_move != MOVE_NONE) {
334 /* If the enemy has not started sailing yet, or we have total
335 * control over the seas, don't worry, keep attacking. */
336 if (unit_can_take_over(punit)) {
337 /* Enemy represents a cross-continental threat! */
338 adv->threats.invasions = TRUE;
339 } else if (get_transporter_capacity(punit) > 0) {
340 unit_type_iterate(cargotype) {
341 if (can_unit_type_transport(unit_type_get(punit),
342 cargotype->uclass)
343 && utype_can_take_over(cargotype)) {
344 /* Enemy can transport some threatening units! */
345 adv->threats.invasions = TRUE;
346 break;
347 }
348 } unit_type_iterate_end;
349 }
350
351 /* The idea is that while our enemies don't have any offensive
352 * seaborne units, we don't have to worry. Go on the offensive! */
353 if (unit_type_get(punit)->attack_strength > 1) {
354 if (is_ocean_tile(unit_tile(punit))) {
355 Continent_id continent = tile_continent(unit_tile(punit));
356
357 adv->oceans[-continent].threat = TRUE;
358 } else {
359 adjc_iterate(&(wld.map), unit_tile(punit), tile2) {
360 if (is_ocean_tile(tile2)) {
361 Continent_id continent = tile_continent(tile2);
362
363 adv->oceans[-continent].threat = TRUE;
364 }
365 } adjc_iterate_end;
366 }
367 }
368 continue;
369 }
370
371 /* If our enemy builds missiles, worry about missile defense. */
372 if (utype_can_do_action(unit_type_get(punit), ACTION_SUICIDE_ATTACK)
373 && unit_type_get(punit)->attack_strength > 1) {
374 adv->threats.suicide_attack = TRUE;
375 }
376
377 /* If they build nukes, worry a lot. */
378 action_array_iterate(nuke_actions, act_id) {
379 if (unit_can_do_action(punit, act_id)) {
380 danger_of_nukes = TRUE;
381 }
382 } action_array_iterate_end;
383 } unit_list_iterate_end;
384
385 /* Check for nuke capability */
386 action_array_iterate(nuke_actions, act_id) {
387 int i;
388 int nuke_units = num_role_units(action_id_get_role(act_id));
389
390 for (i = 0; i < nuke_units; i++) {
391 struct unit_type *nuke =
392 get_role_unit(action_id_get_role(act_id), i);
393
394 if (can_player_build_unit_direct(aplayer, nuke, FALSE)) {
395 adv->threats.nuclear = 1;
396 }
397 }
398 } action_array_iterate_end;
399 } players_iterate_end;
400
401 /* Increase from fear to terror if opponent actually has nukes */
402 if (danger_of_nukes) {
403 adv->threats.nuclear++; /* sum of both fears */
404 }
405
406 /*** Exploration ***/
407
408 adv->explore.land_done = TRUE;
409 adv->explore.sea_done = TRUE;
410 adv->explore.continent = fc_calloc(adv->num_continents + 1, sizeof(bool));
411 adv->explore.ocean = fc_calloc(adv->num_oceans + 1, sizeof(bool));
412
413 whole_map_iterate(&(wld.map), ptile) {
414 Continent_id continent = tile_continent(ptile);
415
416 if (is_ocean_tile(ptile)) {
417 if (adv->explore.sea_done && has_handicap(pplayer, H_TARGETS)
418 && !map_is_known(ptile, pplayer)) {
419 /* We're not done there. */
420 adv->explore.sea_done = FALSE;
421 adv->explore.ocean[-continent] = TRUE;
422 }
423 /* skip rest, which is land only */
424 continue;
425 }
426 if (adv->explore.continent[tile_continent(ptile)]) {
427 /* we don't need more explaining, we got the point */
428 continue;
429 }
430 if (hut_on_tile(ptile)
431 && (!has_handicap(pplayer, H_HUTS)
432 || map_is_known(ptile, pplayer))) {
433 adv->explore.land_done = FALSE;
434 adv->explore.continent[continent] = TRUE;
435 continue;
436 }
437 if (has_handicap(pplayer, H_TARGETS) && !map_is_known(ptile, pplayer)) {
438 /* this AI must explore */
439 adv->explore.land_done = FALSE;
440 adv->explore.continent[continent] = TRUE;
441 }
442 } whole_map_iterate_end;
443
444 /*** Statistics ***/
445
446 adv->stats.cities = fc_calloc(adv->num_continents + 1, sizeof(int));
447 adv->stats.ocean_cities = fc_calloc(adv->num_oceans + 1, sizeof(int));
448 adv->stats.average_production = 0;
449 city_list_iterate(pplayer->cities, pcity) {
450 Continent_id continent = tile_continent(pcity->tile);
451
452 if (continent >= 0) {
453 adv->stats.cities[continent]++;
454 } else {
455 adv->stats.ocean_cities[-continent]++;
456 }
457 adv->stats.average_production += pcity->surplus[O_SHIELD];
458 } city_list_iterate_end;
459 adv->stats.average_production /= MAX(1, city_list_size(pplayer->cities));
460
461 /*** Diplomacy ***/
462
463 players_iterate(aplayer) {
464 struct adv_dipl *dip = adv_dipl_get(pplayer, aplayer);
465
466 dip->allied_with_enemy = FALSE;
467 players_iterate(check_pl) {
468 if (pplayers_allied(aplayer, check_pl)
469 && player_diplstate_get(pplayer, check_pl)->type == DS_WAR) {
470 dip->allied_with_enemy = TRUE;
471 }
472 } players_iterate_end;
473 } players_iterate_end;
474
475 adv->dipl.spacerace_leader = player_leading_spacerace();
476
477 adv->dipl.production_leader = NULL;
478 players_iterate(aplayer) {
479 if (adv->dipl.production_leader == NULL
480 || adv->dipl.production_leader->score.mfg < aplayer->score.mfg) {
481 adv->dipl.production_leader = aplayer;
482 }
483 } players_iterate_end;
484
485 adv->dipl.tech_leader = NULL;
486 players_iterate(aplayer) {
487 if (adv->dipl.tech_leader == NULL
488 || adv->dipl.tech_leader->score.techs < aplayer->score.techs) {
489 adv->dipl.tech_leader = aplayer;
490 }
491 } players_iterate_end;
492
493 /*** Priorities ***/
494
495 /* NEVER set these to zero! Weight values are usually multiplied by
496 * these values, so be careful with them. They are used in city
497 * and government calculations, and food and shields should be
498 * slightly bigger because we only look at surpluses there. They
499 * are all WAGs. */
500 adv->food_priority = FOOD_WEIGHTING;
501 adv->shield_priority = SHIELD_WEIGHTING;
502 if (adv_wants_science(pplayer)) {
503 adv->luxury_priority = 1;
504 adv->science_priority = TRADE_WEIGHTING * 1.2;
505 } else {
506 adv->luxury_priority = TRADE_WEIGHTING;
507 adv->science_priority = 1;
508 }
509 adv->gold_priority = TRADE_WEIGHTING;
510 adv->happy_priority = 1;
511 adv->unhappy_priority = TRADE_WEIGHTING; /* danger */
512 adv->angry_priority = TRADE_WEIGHTING * 3; /* grave danger */
513 adv->pollution_priority = POLLUTION_WEIGHTING;
514 adv->infra_priority = INFRA_WEIGHTING;
515
516 /* Research want */
517 if (is_future_tech(research_get(pplayer)->researching)
518 || player_has_really_useful_tech_parasite(pplayer)) {
519 adv->wants_science = FALSE;
520 } else {
521 adv->wants_science = TRUE;
522 }
523
524 /* max num cities
525 * The idea behind this code is that novice players don't understand that
526 * expansion is critical and find it very annoying.
527 * With the following code AI players will try to be only a bit better
528 * than the best human players. This should lead to more exciting games
529 * for the beginners.
530 */
531 if (has_handicap(pplayer, H_EXPANSION)) {
532 bool found_human = FALSE;
533 adv->max_num_cities = 3;
534 players_iterate_alive(aplayer) {
535 if (aplayer == pplayer || is_ai(aplayer)) {
536 continue;
537 }
538 adv->max_num_cities = MAX(adv->max_num_cities,
539 city_list_size(aplayer->cities) + 3);
540 found_human = TRUE;
541 } players_iterate_alive_end;
542 if (!found_human) {
543 adv->max_num_cities = MAP_INDEX_SIZE;
544 }
545 } else {
546 adv->max_num_cities = MAP_INDEX_SIZE;
547 }
548
549 count_my_units(pplayer);
550
551 TIMING_LOG(AIT_AIDATA, TIMER_STOP);
552
553 /* Government */
554 TIMING_LOG(AIT_GOVERNMENT, TIMER_START);
555 adv_best_government(pplayer);
556 TIMING_LOG(AIT_GOVERNMENT, TIMER_STOP);
557
558 return TRUE;
559}
560
561/**********************************************************************/
564 void adv_data_phase_done(struct player *pplayer)
565{
566 struct adv_data *adv = pplayer->server.adv;
567
568 fc_assert_ret(adv != NULL);
569
570 if (!adv->phase_is_initialized) {
571 return;
572 }
573
574 free(adv->explore.ocean);
575 adv->explore.ocean = NULL;
576
577 free(adv->explore.continent);
578 adv->explore.continent = NULL;
579
580 free(adv->continents);
581 adv->continents = NULL;
582
583 free(adv->oceans);
584 adv->oceans = NULL;
585
586 free(adv->stats.cities);
587 adv->stats.cities = NULL;
588
589 free(adv->stats.ocean_cities);
590 adv->stats.ocean_cities = NULL;
591
592 adv->num_continents = 0;
593 adv->num_oceans = 0;
594
595 adv->phase_is_initialized = FALSE;
596}
597
598/**********************************************************************/
604 struct adv_data *adv_data_get(struct player *pplayer, bool *caller_closes)
605{
606 struct adv_data *adv = pplayer->server.adv;
607
608 fc_assert_ret_val(adv != NULL, NULL);
609
610 /* It's certainly indication of bug causing problems
611 if this adv_data_get() gets called between adv_data_phase_done() and
612 adv_data_phase_init(), since we may end up calling those
613 functions if number of known continents has changed.
614
615 Consider following case:
616 Correct call order would be:
617 a) adv_data_phase_init()
618 b) adv_data_get() -> adv_data_phase_done()
619 c) adv_data_get() -> adv_data_phase_init()
620 d) adv_data_phase_done()
621 e) do something
622 f) adv_data_phase_init()
623
624 In (e) data phase would be closed and data would be
625 correctly initialized at (f), which is probably beginning
626 next turn.
627
628 Buggy version where adv_data_get() (b&c) gets called after (d):
629 a) adv_data_phase_init()
630 d) adv_data_phase_done()
631 b) adv_data_get() -> adv_data_phase_done()
632 c) adv_data_get() -> adv_data_phase_init()
633 e) do something
634 f) adv_data_phase_init()
635
636 Now in (e) data phase would be open. When adv_data_phase_init()
637 then finally gets called and it really should recreate data
638 to match situation of new turn, it detects that data phase
639 is already initialized and does nothing.
640
641 So, this assertion is here for a reason!
642
643 Code below tries to fix the situation best it can if such a bug is
644 encountered. Since we are probably going to trust that to be enough
645 instead of making intrusive fixes for actual bug in stable branch,
646 do not assert for non-debug builds of stable versions. */
647#if defined(FREECIV_DEBUG) || defined(IS_DEVEL_VERSION)
648 fc_assert(caller_closes != NULL || adv->phase_is_initialized);
649#endif
650
651 if (caller_closes != NULL) {
652 *caller_closes = FALSE;
653 }
654
655 if (adv->num_continents != wld.map.num_continents
656 || adv->num_oceans != wld.map.num_oceans) {
657 /* we discovered more continents, recalculate! */
658
659 if (adv->phase_is_initialized) {
660 /* Only call these in this order if inside data phase.
661 This is blanket "fix" for all cases where adv_data_get() is called
662 at illegal time. This at least minimize bad effects of such calls. */
663 adv_data_phase_done(pplayer);
664 adv_data_phase_init(pplayer, FALSE);
665 } else {
666 /* Call them in "wrong" order so we return recalculated data to caller,
667 but leave data phase closed.
668 This is blanket "fix" for all cases where adv_data_get() is called
669 at illegal time. This at least minimize bad effects of such calls.
670
671 Arguably this is not buggy at all but works just as designed in
672 case of being called in alternate movement mode for players
673 other than currently moving one (for diplomacy between the two,
674 for example) */
675 log_debug("%s advisor data phase closed when adv_data_get() called",
676 player_name(pplayer));
677 adv_data_phase_init(pplayer, FALSE);
678 if (caller_closes != NULL) {
679 *caller_closes = TRUE;
680 } else {
681 adv_data_phase_done(pplayer);
682 }
683 }
684 } else {
685 if (!adv->phase_is_initialized && caller_closes != NULL) {
686 adv_data_phase_init(pplayer, FALSE);
687 *caller_closes = TRUE;
688 }
689 }
690
691 return adv;
692}
693
694/**********************************************************************/
697 void adv_data_init(struct player *pplayer)
698{
699 struct adv_data *adv;
700
701 if (pplayer->server.adv == NULL) {
702 pplayer->server.adv = fc_calloc(1, sizeof(*pplayer->server.adv));
703 }
704 adv = pplayer->server.adv;
705
706 adv->government_want = NULL;
707
708 adv->dipl.adv_dipl_slots = fc_calloc(player_slot_count(),
709 sizeof(*adv->dipl.adv_dipl_slots));
710 player_slots_iterate(pslot) {
711 struct adv_dipl **dip_slot =
712 adv->dipl.adv_dipl_slots + player_slot_index(pslot);
713 *dip_slot = NULL;
714 } player_slots_iterate_end;
715
716 players_iterate(aplayer) {
717 adv_dipl_new(pplayer, aplayer);
718 if (aplayer != pplayer) {
719 adv_dipl_new(aplayer, pplayer);
720 }
721 } players_iterate_end;
722
723 adv_data_default(pplayer);
724}
725
726/**********************************************************************/
729 void adv_data_default(struct player *pplayer)
730{
731 struct adv_data *adv = pplayer->server.adv;
732
733 fc_assert_ret(adv != NULL);
734
735 adv->govt_reeval = 0;
736 adv->government_want = fc_realloc(adv->government_want,
737 (government_count() + 1)
738 * sizeof(*adv->government_want));
739 memset(adv->government_want, 0,
740 (government_count() + 1) * sizeof(*adv->government_want));
741
742 adv->wonder_city = 0;
743
744 adv->wants_science = TRUE;
745 adv->celebrate = FALSE;
746 adv->max_num_cities = 10000;
747}
748
749/**********************************************************************/
752 void adv_data_close(struct player *pplayer)
753{
754 struct adv_data *adv = pplayer->server.adv;
755
756 fc_assert_ret(NULL != adv);
757
758 adv_data_phase_done(pplayer);
759
760 if (adv->government_want != NULL) {
761 free(adv->government_want);
762 }
763
764 if (adv->dipl.adv_dipl_slots != NULL) {
765 players_iterate(aplayer) {
766 adv_dipl_free(pplayer, aplayer);
767 if (aplayer != pplayer) {
768 adv_dipl_free(aplayer, pplayer);
769 }
770 } players_iterate_end;
771 FC_FREE(adv->dipl.adv_dipl_slots);
772 }
773
774 if (adv != NULL) {
775 free(adv);
776 }
777
778 pplayer->server.adv = NULL;
779}
780
781/**********************************************************************/
784 static void adv_dipl_new(const struct player *plr1,
785 const struct player *plr2)
786{
787 struct adv_dipl **dip_slot =
788 plr1->server.adv->dipl.adv_dipl_slots + player_index(plr2);
789
790 *dip_slot = fc_calloc(1, sizeof(struct adv_dipl));
791}
792
793/**********************************************************************/
796 static void adv_dipl_free(const struct player *plr1,
797 const struct player *plr2)
798{
799 struct adv_dipl **dip_slot =
800 plr1->server.adv->dipl.adv_dipl_slots + player_index(plr2);
801
802 if (*dip_slot != NULL) {
803 FC_FREE(*dip_slot);
804 *dip_slot = NULL;
805 }
806}
807
808/**********************************************************************/
811 static struct adv_dipl *adv_dipl_get(const struct player *plr1,
812 const struct player *plr2)
813{
814 struct adv_dipl **dip_slot =
815 plr1->server.adv->dipl.adv_dipl_slots + player_index(plr2);
816
817 return *dip_slot;
818}
819
820/**********************************************************************/
823 adv_want adv_gov_action_immunity_want(struct government *gov)
824{
825 adv_want bonus = 0;
826
827 /* TODO: Individual and well balanced value. */
828 action_iterate(act) {
829 struct action *paction = action_by_number(act);
830
831 if (!action_immune_government(gov, act)) {
832 /* This government doesn't provide immunity against this
833 * action. */
834 continue;
835 }
836
837 switch (paction->result) {
838 case ACTRES_ATTACK:
839 case ACTRES_SPY_INCITE_CITY:
840 case ACTRES_CONQUER_CITY:
841 case ACTRES_COLLECT_RANSOM:
842 bonus += 4;
843 break;
844 case ACTRES_SPY_BRIBE_UNIT:
845 bonus += 2;
846 break;
847 case ACTRES_TRANSFORM_TERRAIN:
848 bonus += 1.5;
849 break;
850 case ACTRES_CULTIVATE:
851 case ACTRES_PLANT:
852 bonus += 0.3;
853 break;
854 case ACTRES_CONQUER_EXTRAS:
855 case ACTRES_PILLAGE:
856 case ACTRES_WIPE_UNITS:
857 bonus += 0.2;
858 break;
859 case ACTRES_HUT_ENTER:
860 case ACTRES_HUT_FRIGHTEN:
861 /* It is mine. My own. My precious. */
862 bonus += 0.1;
863 break;
864 case ACTRES_SPY_INVESTIGATE_CITY:
865 case ACTRES_SPY_POISON:
866 case ACTRES_SPY_SPREAD_PLAGUE:
867 case ACTRES_SPY_STEAL_GOLD:
868 case ACTRES_SPY_SABOTAGE_CITY:
869 case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
870 case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
871 case ACTRES_SPY_STEAL_TECH:
872 case ACTRES_SPY_TARGETED_STEAL_TECH:
873 case ACTRES_SPY_SABOTAGE_UNIT:
874 case ACTRES_CAPTURE_UNITS:
875 case ACTRES_STEAL_MAPS:
876 case ACTRES_BOMBARD:
877 case ACTRES_SPY_NUKE:
878 case ACTRES_NUKE:
879 case ACTRES_NUKE_UNITS:
880 case ACTRES_DESTROY_CITY:
881 case ACTRES_EXPEL_UNIT:
882 case ACTRES_STRIKE_BUILDING:
883 case ACTRES_STRIKE_PRODUCTION:
884 case ACTRES_SPY_ATTACK:
885 /* Being a target of this is usually undesirable */
886 /* TODO: Individual and well balanced values. */
887 bonus += 0.1;
888 break;
889
890 case ACTRES_UNIT_MOVE:
891 case ACTRES_TELEPORT:
892 case ACTRES_TELEPORT_CONQUER:
893 case ACTRES_ENABLER_CHECK:
894 case ACTRES_MARKETPLACE:
895 case ACTRES_FOUND_CITY:
896 case ACTRES_DISBAND_UNIT:
897 case ACTRES_PARADROP:
898 case ACTRES_PARADROP_CONQUER:
899 case ACTRES_FORTIFY:
900 case ACTRES_SPY_ESCAPE:
901 /* Wants the ability to do this to it self. Don't want others
902 * to target it. Do nothing since action_immune_government()
903 * doesn't separate based on who the actor is. */
904 break;
905
906 case ACTRES_NONE:
907 /* Ruleset defined */
908 break;
909
910 case ACTRES_ESTABLISH_EMBASSY:
911 case ACTRES_TRADE_ROUTE:
912 case ACTRES_JOIN_CITY:
913 case ACTRES_HELP_WONDER:
914 case ACTRES_DISBAND_UNIT_RECOVER:
915 case ACTRES_HOME_CITY:
916 case ACTRES_HOMELESS:
917 case ACTRES_UPGRADE_UNIT:
918 case ACTRES_AIRLIFT:
919 case ACTRES_HEAL_UNIT:
920 case ACTRES_ROAD:
921 case ACTRES_CONVERT:
922 case ACTRES_BASE:
923 case ACTRES_MINE:
924 case ACTRES_IRRIGATE:
925 case ACTRES_CLEAN:
926 case ACTRES_TRANSPORT_DEBOARD:
927 case ACTRES_TRANSPORT_UNLOAD:
928 case ACTRES_TRANSPORT_DISEMBARK:
929 case ACTRES_TRANSPORT_BOARD:
930 case ACTRES_TRANSPORT_LOAD:
931 case ACTRES_TRANSPORT_EMBARK:
932 /* Could be good. An embassy gives permanent contact. A trade
933 * route gives gold per turn. Join city gives population.
934 * Help wonder gives shields. */
935 /* TODO: Individual and well balanced values. */
936 break;
937
938 ASSERT_UNUSED_ACTRES_CASES;
939 }
940 } action_iterate_end;
941
942 return bonus;
943}
944
945/**********************************************************************/
951 adv_want adv_gov_player_bonus_want(struct player *pplayer)
952{
953 adv_want bonus = 0;
954
955 /* Bonuses for non-economic abilities. We increase val by
956 * a very small amount here to choose govt in cases where
957 * we have no cities yet. */
958 bonus += get_player_bonus(pplayer, EFT_VETERAN_BUILD) > 0 ? 3 : 0;
959 bonus += get_player_bonus(pplayer, EFT_INSPIRE_PARTISANS) > 0 ? 3 : 0;
960 bonus += get_player_bonus(pplayer, EFT_RAPTURE_GROW) > 0 ? 2 : 0;
961 bonus += get_player_bonus(pplayer, EFT_FANATICS) > 0 ? 3 : 0;
962 bonus += get_player_bonus(pplayer, EFT_OUTPUT_INC_TILE) * 8;
963
964 return bonus;
965}
966
967/**********************************************************************/
979 void adv_best_government(struct player *pplayer)
980{
981 struct adv_data *adv = adv_data_get(pplayer, NULL);
982 int best_val = 0;
983 struct government *current_gov = government_of_player(pplayer);
984
985 adv->goal.govt.gov = current_gov;
986 adv->goal.govt.val = 0;
987 adv->goal.govt.req = A_UNSET;
988 adv->goal.revolution = current_gov;
989
990 if (has_handicap(pplayer, H_AWAY) || !pplayer->is_alive) {
991 return;
992 }
993
994 if (adv->govt_reeval == 0) {
995 const struct research *presearch = research_get(pplayer);
996
997 governments_iterate(gov) {
998 adv_want val = 0;
999 bool override = FALSE;
1000
1001 if (gov == game.government_during_revolution) {
1002 continue; /* pointless */
1003 }
1004 if (gov->ai.better
1005 && can_change_to_government(pplayer, gov->ai.better)) {
1006 continue; /* we have better governments available */
1007 }
1008
1009 CALL_PLR_AI_FUNC(gov_value, pplayer, pplayer, gov, &val, &override);
1010
1011 if (!override) {
1012 int dist;
1013 adv_want bonus = 0; /* in percentage */
1014 int revolution_turns;
1015
1016 pplayer->government = gov;
1017 /* Ideally we should change tax rates here, but since
1018 * this is a rather big CPU operation, we'd rather not. */
1019 check_player_max_rates(pplayer);
1020 city_list_iterate(pplayer->cities, acity) {
1021 auto_arrange_workers(acity);
1022 } city_list_iterate_end;
1023 city_list_iterate(pplayer->cities, pcity) {
1024 val += adv_eval_calc_city(pcity, adv);
1025 } city_list_iterate_end;
1026
1027 bonus += adv_gov_action_immunity_want(gov);
1028 bonus += adv_gov_player_bonus_want(pplayer);
1029
1030 revolution_turns = get_player_bonus(pplayer, EFT_REVOLUTION_UNHAPPINESS);
1031 if (revolution_turns > 0) {
1032 bonus -= 6 / revolution_turns;
1033 }
1034
1035 val += (val * bonus) / 100;
1036
1037 /* FIXME: handle reqs other than technologies. */
1038 dist = 0;
1039 requirement_vector_iterate(&gov->reqs, preq) {
1040 if (VUT_ADVANCE == preq->source.kind) {
1041 int gut = research_goal_unknown_techs(presearch,
1042 advance_number(preq->source.value.advance));
1043
1044 dist += MAX(1, gut);
1045 }
1046 } requirement_vector_iterate_end;
1047 val = amortize(val, dist);
1048 }
1049
1050 adv->government_want[government_index(gov)] = val; /* Save want */
1051 } governments_iterate_end;
1052 /* Now reset our gov to it's real state. */
1053 pplayer->government = current_gov;
1054 city_list_iterate(pplayer->cities, acity) {
1055 auto_arrange_workers(acity);
1056 } city_list_iterate_end;
1057 if (player_is_cpuhog(pplayer)) {
1058 adv->govt_reeval = 1;
1059 } else {
1060 adv->govt_reeval = CLIP(5, city_list_size(pplayer->cities), 20);
1061 }
1062 }
1063 adv->govt_reeval--;
1064
1065 /* Figure out which government is the best for us this turn. */
1066 governments_iterate(gov) {
1067 int gi = government_index(gov);
1068 if (adv->government_want[gi] > best_val
1069 && can_change_to_government(pplayer, gov)) {
1070 best_val = adv->government_want[gi];
1071 adv->goal.revolution = gov;
1072 }
1073 if (adv->government_want[gi] > adv->goal.govt.val) {
1074 adv->goal.govt.gov = gov;
1075 adv->goal.govt.val = adv->government_want[gi];
1076
1077 /* FIXME: handle reqs other than technologies. */
1078 adv->goal.govt.req = A_NONE;
1079 requirement_vector_iterate(&gov->reqs, preq) {
1080 if (VUT_ADVANCE == preq->source.kind) {
1081 adv->goal.govt.req = advance_number(preq->source.value.advance);
1082 break;
1083 }
1084 } requirement_vector_iterate_end;
1085 }
1086 } governments_iterate_end;
1087 /* Goodness of the ideal gov is calculated relative to the goodness of the
1088 * best of the available ones. */
1089 adv->goal.govt.val -= best_val;
1090}
1091
1092/**********************************************************************/
1095 bool adv_wants_science(struct player *pplayer)
1096{
1097 return adv_data_get(pplayer, NULL)->wants_science;
1098}
1099
1100/**********************************************************************/
1106 bool adv_is_player_dangerous(struct player *pplayer,
1107 struct player *aplayer)
1108{
1109 struct adv_dipl *dip;
1110 enum diplstate_type ds;
1111 enum override_bool dang = NO_OVERRIDE;
1112
1113 if (is_ai(pplayer)) {
1114 /* Give AI code possibility to decide itself */
1115 CALL_PLR_AI_FUNC(consider_plr_dangerous, pplayer, pplayer, aplayer, &dang);
1116 }
1117
1118 if (dang == OVERRIDE_FALSE) {
1119 return FALSE;
1120 }
1121
1122 if (dang == OVERRIDE_TRUE) {
1123 return TRUE;
1124 }
1125
1126 if (pplayer == aplayer) {
1127 /* We always trust ourself */
1128 return FALSE;
1129 }
1130
1131 ds = player_diplstate_get(pplayer, aplayer)->type;
1132
1133 if (ds == DS_WAR || ds == DS_CEASEFIRE) {
1134 /* It's already a war or aplayer can declare it soon */
1135 return TRUE;
1136 }
1137
1138 dip = adv_dipl_get(pplayer, aplayer);
1139
1140 if (dip->allied_with_enemy) {
1141 /* Don't trust someone who will declare war on us soon */
1142 return TRUE;
1143 }
1144
1145 if (player_diplstate_get(pplayer, aplayer)->has_reason_to_cancel > 0) {
1146 return TRUE;
1147 }
1148
1149 if (pplayer->ai_common.love[player_index(aplayer)] < MAX_AI_LOVE / 10) {
1150 /* We don't trust players who we don't like. Note that
1151 * aplayer's units inside pplayer's borders decreases AI's love */
1152 return TRUE;
1153 }
1154
1155 return FALSE;
1156}
action_array_add_all_by_result
void action_array_add_all_by_result(action_id *act_array, int *position, enum action_result result)
Definition actions.c:5723
action_array_end
void action_array_end(action_id *act_array, int size)
Definition actions.c:5706
action_immune_government
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:5386
actions.h
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:390
action_array_iterate
#define action_array_iterate(_act_array_, _act_id_)
Definition actions.h:252
action_id_get_role
#define action_id_get_role(act_id)
Definition actions.h:451
action_array_iterate_end
#define action_array_iterate_end
Definition actions.h:264
action_iterate_end
#define action_iterate_end
Definition actions.h:209
MAX_NUM_ACTIONS
#define MAX_NUM_ACTIONS
Definition actions.h:58
action_iterate
#define action_iterate(_act_)
Definition actions.h:205
ASSERT_UNUSED_ACTRES_CASES
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
advbuilding.h
TRADE_WEIGHTING
#define TRADE_WEIGHTING
Definition advbuilding.h:21
INFRA_WEIGHTING
#define INFRA_WEIGHTING
Definition advbuilding.h:29
FOOD_WEIGHTING
#define FOOD_WEIGHTING
Definition advbuilding.h:19
SHIELD_WEIGHTING
#define SHIELD_WEIGHTING
Definition advbuilding.h:20
POLLUTION_WEIGHTING
#define POLLUTION_WEIGHTING
Definition advbuilding.h:28
adv_eval_calc_city
int adv_eval_calc_city(struct city *pcity, struct adv_data *adv)
Definition advcity.c:32
advcity.h
adv_data_city_impr_calc
static void adv_data_city_impr_calc(struct player *pplayer, struct adv_data *adv)
Definition advdata.c:73
adv_data_analyze_rulesets
void adv_data_analyze_rulesets(struct player *pplayer)
Definition advdata.c:191
adv_data_close
void adv_data_close(struct player *pplayer)
Definition advdata.c:752
adv_gov_player_bonus_want
adv_want adv_gov_player_bonus_want(struct player *pplayer)
Definition advdata.c:951
adv_data_init
void adv_data_init(struct player *pplayer)
Definition advdata.c:697
adv_dipl_free
static void adv_dipl_free(const struct player *plr1, const struct player *plr2)
Definition advdata.c:796
adv_data_get
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:604
is_adv_data_phase_open
bool is_adv_data_phase_open(struct player *pplayer)
Definition advdata.c:242
adv_wants_science
bool adv_wants_science(struct player *pplayer)
Definition advdata.c:1095
adv_data_phase_init
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:262
adv_data_phase_done
void adv_data_phase_done(struct player *pplayer)
Definition advdata.c:564
adv_is_player_dangerous
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
Definition advdata.c:1106
adv_dipl_new
static void adv_dipl_new(const struct player *plr1, const struct player *plr2)
Definition advdata.c:784
count_my_units
static void count_my_units(struct player *pplayer)
Definition advdata.c:203
adv_gov_action_immunity_want
adv_want adv_gov_action_immunity_want(struct government *gov)
Definition advdata.c:823
adv_dipl_get
static struct adv_dipl * adv_dipl_get(const struct player *plr1, const struct player *plr2)
Definition advdata.c:811
player_has_really_useful_tech_parasite
static bool player_has_really_useful_tech_parasite(struct player *pplayer)
Definition advdata.c:147
adv_best_government
void adv_best_government(struct player *pplayer)
Definition advdata.c:979
adv_data_default
void adv_data_default(struct player *pplayer)
Definition advdata.c:729
advdata.h
ADV_IMPR_CALCULATE_FULL
@ ADV_IMPR_CALCULATE_FULL
Definition advdata.h:35
ADV_IMPR_LAST
@ ADV_IMPR_LAST
Definition advdata.h:37
ADV_IMPR_ESTIMATE
@ ADV_IMPR_ESTIMATE
Definition advdata.h:36
ADV_IMPR_CALCULATE
@ ADV_IMPR_CALCULATE
Definition advdata.h:34
amortize
adv_want amortize(adv_want benefit, int delay)
Definition advtools.c:29
advtools.h
ai.h
CALL_PLR_AI_FUNC
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
player_leading_spacerace
struct player * player_leading_spacerace(void)
Definition aisupport.c:38
aisupport.h
city.h
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
auto_arrange_workers
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:365
cityturn.h
incite_cost
char * incite_cost
Definition comments.c:74
nuke_units
static void nuke_units(QVariant data1, QVariant data2)
Definition dialogs.cpp:2724
nuke
static void nuke(QVariant data1, QVariant data2)
Definition dialogs.cpp:3000
punit
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
diplhand.h
get_req_source_effects
struct effect_list * get_req_source_effects(const struct universal *psource)
Definition effects.c:153
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
effects.h
effect_list_iterate_end
#define effect_list_iterate_end
Definition effects.h:81
effect_list_iterate
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:79
hut_on_tile
bool hut_on_tile(const struct tile *ptile)
Definition extras.c:697
adv_want
float adv_want
Definition fc_types.h:1365
action_id
int action_id
Definition fc_types.h:393
ACTRES_NONE
#define ACTRES_NONE
Definition fc_types.h:331
O_SHIELD
@ O_SHIELD
Definition fc_types.h:101
Continent_id
signed short Continent_id
Definition fc_types.h:376
override_bool
override_bool
Definition fc_types.h:94
OVERRIDE_TRUE
@ OVERRIDE_TRUE
Definition fc_types.h:94
NO_OVERRIDE
@ NO_OVERRIDE
Definition fc_types.h:94
OVERRIDE_FALSE
@ OVERRIDE_FALSE
Definition fc_types.h:94
game
struct civ_game game
Definition game.c:62
wld
struct world wld
Definition game.c:63
game.h
government_count
Government_type_id government_count(void)
Definition government.c:71
government_of_player
struct government * government_of_player(const struct player *pplayer)
Definition government.c:114
can_change_to_government
bool can_change_to_government(struct player *pplayer, const struct government *gov)
Definition government.c:166
government_index
Government_type_id government_index(const struct government *pgovern)
Definition government.c:82
government.h
governments_iterate
#define governments_iterate(NAME_pgov)
Definition government.h:120
governments_iterate_end
#define governments_iterate_end
Definition government.h:123
source
static GtkWidget * source
Definition gotodlg.c:58
type
GType type
Definition repodlgs.c:1313
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps.h
H_TARGETS
@ H_TARGETS
Definition handicaps.h:24
H_AWAY
@ H_AWAY
Definition handicaps.h:19
H_HUTS
@ H_HUTS
Definition handicaps.h:25
H_EXPANSION
@ H_EXPANSION
Definition handicaps.h:31
improvement_index
Impr_type_id improvement_index(const struct impr_type *pimprove)
Definition improvement.c:175
improvement_iterate_end
#define improvement_iterate_end
Definition improvement.h:205
improvement_iterate
#define improvement_iterate(_p)
Definition improvement.h:199
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
log_debug
#define log_debug(message,...)
Definition log.h:115
map.h
adjc_iterate_end
#define adjc_iterate_end
Definition map.h:419
adjc_iterate
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:414
whole_map_iterate
#define whole_map_iterate(_map, _tile)
Definition map.h:531
whole_map_iterate_end
#define whole_map_iterate_end
Definition map.h:540
map_is_known
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:901
maphand.h
mem.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_realloc
#define fc_realloc(ptr, sz)
Definition mem.h:36
can_unit_type_transport
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:869
movement.h
path_finding.h
pf_tools.h
player_slot_count
int player_slot_count(void)
Definition player.c:418
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:895
player_slot_index
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
player_index
int player_index(const struct player *pplayer)
Definition player.c:829
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
players_iterate_end
#define players_iterate_end
Definition player.h:539
players_iterate
#define players_iterate(_pplayer)
Definition player.h:534
MAX_AI_LOVE
#define MAX_AI_LOVE
Definition player.h:563
player_slots_iterate
#define player_slots_iterate(_pslot)
Definition player.h:525
is_ai
#define is_ai(plr)
Definition player.h:232
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:549
player_slots_iterate_end
#define player_slots_iterate_end
Definition player.h:529
player_is_cpuhog
static bool player_is_cpuhog(const struct player *pplayer)
Definition player.h:577
players_iterate_alive
#define players_iterate_alive(_pplayer)
Definition player.h:544
check_player_max_rates
void check_player_max_rates(struct player *pplayer)
Definition plrhand.c:776
plrhand.h
requirement_vector_iterate_end
#define requirement_vector_iterate_end
Definition requirements.h:94
requirement_vector_iterate
#define requirement_vector_iterate(req_vec, preq)
Definition requirements.h:92
research_goal_unknown_techs
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:750
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
research_invention_gettable
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:693
research.h
CLIP
#define CLIP(lower, current, upper)
Definition shared.h:57
MAX
#define MAX(x, y)
Definition shared.h:54
srv_log.h
AIT_GOVERNMENT
@ AIT_GOVERNMENT
Definition srv_log.h:47
AIT_AIDATA
@ AIT_AIDATA
Definition srv_log.h:46
TIMER_STOP
@ TIMER_STOP
Definition srv_log.h:76
TIMER_START
@ TIMER_START
Definition srv_log.h:76
TIMING_LOG
#define TIMING_LOG(timer, activity)
Definition srv_log.h:125
action
Definition actions.h:106
adv_area_info
Definition advdata.h:45
adv_area_info::size
int size
Definition advdata.h:46
adv_area_info::threat
bool threat
Definition advdata.h:47
adv_data
Definition advdata.h:50
adv_data::wants_science
bool wants_science
Definition advdata.h:139
adv_data::req
int req
Definition advdata.h:133
adv_data::govt_reeval
short govt_reeval
Definition advdata.h:126
adv_data::val
adv_want val
Definition advdata.h:132
adv_data::pollution_priority
int pollution_priority
Definition advdata.h:121
adv_data::shield_priority
int shield_priority
Definition advdata.h:113
adv_data::ocean
bool * ocean
Definition advdata.h:74
adv_data::threats
struct adv_data::@89 threats
adv_data::cities
int * cities
Definition advdata.h:96
adv_data::ocean_cities
int * ocean_cities
Definition advdata.h:97
adv_data::invasions
bool invasions
Definition advdata.h:66
adv_data::revolution
struct government * revolution
Definition advdata.h:135
adv_data::infra_priority
int infra_priority
Definition advdata.h:122
adv_data::adv_dipl_slots
struct adv_dipl ** adv_dipl_slots
Definition advdata.h:102
adv_data::igwall
bool igwall
Definition advdata.h:69
adv_data::celebrate
bool celebrate
Definition advdata.h:142
adv_data::dipl
struct adv_data::@92 dipl
adv_data::units
struct adv_data::@91::@94 units
adv_data::num_oceans
int num_oceans
Definition advdata.h:110
adv_data::unhappy_priority
int unhappy_priority
Definition advdata.h:119
adv_data::luxury_priority
int luxury_priority
Definition advdata.h:115
adv_data::nuclear
int nuclear
Definition advdata.h:68
adv_data::angry_priority
int angry_priority
Definition advdata.h:120
adv_data::food_priority
int food_priority
Definition advdata.h:114
adv_data::max_num_cities
int max_num_cities
Definition advdata.h:145
adv_data::num_continents
int num_continents
Definition advdata.h:109
adv_data::government_want
adv_want * government_want
Definition advdata.h:125
adv_data::oceans
struct adv_area_info * oceans
Definition advdata.h:62
adv_data::production_leader
struct player * production_leader
Definition advdata.h:106
adv_data::gov
struct government * gov
Definition advdata.h:131
adv_data::goal
struct adv_data::@93 goal
adv_data::continents
struct adv_area_info * continents
Definition advdata.h:61
adv_data::happy_priority
int happy_priority
Definition advdata.h:118
adv_data::continent
bool * continent
Definition advdata.h:75
adv_data::stats
struct adv_data::@91 stats
adv_data::govt
struct adv_data::@93::@95 govt
adv_data::impr_calc
enum adv_improvement_status impr_calc[B_LAST]
Definition advdata.h:58
adv_data::phase_is_initialized
bool phase_is_initialized
Definition advdata.h:52
adv_data::wonder_city
int wonder_city
Definition advdata.h:55
adv_data::impr_range
enum req_range impr_range[B_LAST]
Definition advdata.h:59
adv_data::explore
struct adv_data::@90 explore
adv_data::science_priority
int science_priority
Definition advdata.h:117
adv_data::gold_priority
int gold_priority
Definition advdata.h:116
adv_data::tech_leader
struct player * tech_leader
Definition advdata.h:105
adv_data::spacerace_leader
struct player * spacerace_leader
Definition advdata.h:104
adv_dipl
Definition advdata.h:40
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::government_during_revolution
struct government * government_during_revolution
Definition game.h:94
civ_map::num_continents
int num_continents
Definition map_types.h:82
civ_map::num_oceans
int num_oceans
Definition map_types.h:83
government
Definition government.h:52
packet_game_info::tech_parasite_allow_holes
bool tech_parasite_allow_holes
Definition packets_gen.h:220
player_ai::love
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:124
player_diplstate::type
enum diplstate_type type
Definition player.h:199
player_score::mfg
int mfg
Definition player.h:102
player_score::techs
int techs
Definition player.h:92
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::ai_common
struct player_ai ai_common
Definition player.h:288
player::government
struct government * government
Definition player.h:258
player::ai
const struct ai_type * ai
Definition player.h:289
player::units
struct unit_list * units
Definition player.h:282
player::is_alive
bool is_alive
Definition player.h:268
player::score
struct player_score score
Definition player.h:283
player::adv
struct adv_data * adv
Definition player.h:334
player::server
struct player::@70::@72 server
research
Definition research.h:39
unit_class
Definition unittype.h:149
unit_class::adv
struct unit_class::@85 adv
unit_type
Definition unittype.h:507
unit_type::adv
struct unit_type::@87 adv
unit_type::uclass
struct unit_class * uclass
Definition unittype.h:563
unit_type::igwall
bool igwall
Definition unittype.h:581
unit::utype
const struct unit_type * utype
Definition unit.h:141
universal
Definition fc_types.h:908
universal::kind
enum universals_n kind
Definition fc_types.h:910
world::map
struct civ_map map
Definition world_object.h:38
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
is_future_tech
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
advance_number
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
advance_index_iterate_end
#define advance_index_iterate_end
Definition tech.h:249
A_FIRST
#define A_FIRST
Definition tech.h:44
A_NONE
#define A_NONE
Definition tech.h:43
A_UNSET
#define A_UNSET
Definition tech.h:48
advance_index_iterate
#define advance_index_iterate(_start, _index)
Definition tech.h:245
is_ocean_tile
#define is_ocean_tile(ptile)
Definition terrain.h:196
tile_continent
#define tile_continent(_tile)
Definition tile.h:93
unit_can_do_action
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:385
get_transporter_capacity
int get_transporter_capacity(const struct unit *punit)
Definition unit.c:299
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:397
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unittools.h
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
can_player_build_unit_direct
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype, bool consider_reg_impr_req)
Definition unittype.c:1968
get_role_unit
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2253
num_role_units
int num_role_units(int role)
Definition unittype.c:2203
can_upgrade_unittype
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1703
unit_class_get
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2498
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
unit_can_take_over
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:264
utype_can_take_over
bool utype_can_take_over(const struct unit_type *punittype)
Definition unittype.c:276
utype_can_do_action
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
MOVE_NONE
@ MOVE_NONE
Definition unittype.h:144
unit_type_iterate
#define unit_type_iterate(_p)
Definition unittype.h:859
uclass_index
#define uclass_index(_c_)
Definition unittype.h:749
unit_type_iterate_end
#define unit_type_iterate_end
Definition unittype.h:866
MAP_INDEX_SIZE
#define MAP_INDEX_SIZE
Definition world_object.h:52