Freeciv-3.2: /fast/freeciv/nightly/S3_2/server/advisors/advdata.c Source File

Freeciv-3.2

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