Freeciv21
Develop your civilization from humble roots to a global empire
aidata.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9  */
10 
11 // common
12 #include "game.h"
13 #include "government.h"
14 #include "multipliers.h"
15 #include "research.h"
16 
17 // aicore
18 #include "aiactions.h"
19 
20 // server
21 #include "cityturn.h"
22 #include "plrhand.h"
23 
24 /* server/advisors */
25 #include "advdata.h"
26 
27 /* ai/default */
28 #include "aiferry.h"
29 #include "aiplayer.h"
30 #include "aisettler.h"
31 #include "aiunit.h"
32 #include "daicity.h"
33 #include "daidiplomacy.h"
34 #include "daieffects.h"
35 
36 #include "aidata.h"
37 
38 static void dai_diplomacy_new(struct ai_type *ait, const struct player *plr1,
39  const struct player *plr2);
40 static void dai_diplomacy_defaults(struct ai_type *ait,
41  const struct player *plr1,
42  const struct player *plr2);
43 static void dai_diplomacy_destroy(struct ai_type *ait,
44  const struct player *plr1,
45  const struct player *plr2);
46 
50 void dai_data_init(struct ai_type *ait, struct player *pplayer)
51 {
52  struct ai_plr *ai = def_ai_player_data(pplayer, ait);
53 
54  ai->phase_initialized = false;
55 
56  ai->last_num_continents = -1;
57  ai->last_num_oceans = -1;
58 
60  new const ai_dip_intel *[MAX_NUM_PLAYER_SLOTS]();
62  {
63  const struct ai_dip_intel **player_intel_slot =
65  *player_intel_slot = nullptr;
66  }
68 
69  players_iterate(aplayer)
70  {
71  // create ai diplomacy states for all other players
72  dai_diplomacy_new(ait, pplayer, aplayer);
73  dai_diplomacy_defaults(ait, pplayer, aplayer);
74  // create ai diplomacy state of this player
75  if (aplayer != pplayer) {
76  dai_diplomacy_new(ait, aplayer, pplayer);
77  dai_diplomacy_defaults(ait, aplayer, pplayer);
78  }
79  }
81 
83  ai->diplomacy.timer = 0;
84  ai->diplomacy.love_coeff = 4; // 4%
85  ai->diplomacy.love_incr = MAX_AI_LOVE * 3 / 100;
88 
89  ai->settler = nullptr;
90 
91  // Initialise autosettler.
93 }
94 
98 void dai_data_close(struct ai_type *ait, struct player *pplayer)
99 {
100  struct ai_plr *ai = def_ai_player_data(pplayer, ait);
101 
102  /* Finish the phase if it's open - free resources related to
103  * open/finish cycle */
104  dai_data_phase_finished(ait, pplayer);
105 
106  // Free autosettler.
108 
109  if (ai->diplomacy.player_intel_slots != nullptr) {
110  players_iterate(aplayer)
111  {
112  // destroy the ai diplomacy states of this player with others ...
113  dai_diplomacy_destroy(ait, pplayer, aplayer);
114  // and of others with this player.
115  if (aplayer != pplayer) {
116  dai_diplomacy_destroy(ait, aplayer, pplayer);
117  }
118  }
120  delete[] ai->diplomacy.player_intel_slots;
121  }
122 }
123 
128 bool is_ai_data_phase_open(struct ai_type *ait, struct player *pplayer)
129 {
130  struct ai_plr *ai = def_ai_player_data(pplayer, ait);
131 
132  return ai->phase_initialized;
133 }
134 
138 void dai_data_phase_begin(struct ai_type *ait, struct player *pplayer,
139  bool is_new_phase)
140 {
141  struct ai_plr *ai = def_ai_player_data(pplayer, ait);
142  bool caller_closes;
143 
144  /* Note that this refreshes advisor data if needed. ai_plr_data_get()
145  is expected to refresh advisor data if needed, and ai_plr_data_get()
146  depends on this call
147  ai_plr_data_get()->ai_data_phase_begin()->adv_data_get() to do it.
148  If you change this, you may need to adjust ai_plr_data_get() also. */
149  struct adv_data *adv;
150 
151  if (ai->phase_initialized) {
152  return;
153  }
154 
155  ai->phase_initialized = true;
156 
157  adv = adv_data_get(pplayer, &caller_closes);
158 
159  /* Store current number of known continents and oceans so we can compare
160  against it later in order to see if ai data needs refreshing. */
162  ai->last_num_oceans = adv->num_oceans;
163 
164  /*** Diplomacy ***/
165  if (is_ai(pplayer) && !is_barbarian(pplayer) && is_new_phase) {
166  dai_diplomacy_begin_new_phase(ait, pplayer);
167  }
168 
169  /* Set per-player variables. We must set all players, since players
170  * can be created during a turn, and we don't want those to have
171  * invalid values. */
172  players_iterate(aplayer)
173  {
174  struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer);
175 
176  adip->is_allied_with_enemy = nullptr;
177  adip->at_war_with_ally = nullptr;
178  adip->is_allied_with_ally = nullptr;
179 
180  players_iterate(check_pl)
181  {
182  if (check_pl == pplayer || check_pl == aplayer
183  || !check_pl->is_alive) {
184  continue;
185  }
186  if (pplayers_allied(aplayer, check_pl)
187  && player_diplstate_get(pplayer, check_pl)->type == DS_WAR) {
188  adip->is_allied_with_enemy = check_pl;
189  }
190  if (pplayers_allied(pplayer, check_pl)
191  && player_diplstate_get(aplayer, check_pl)->type == DS_WAR) {
192  adip->at_war_with_ally = check_pl;
193  }
194  if (pplayers_allied(aplayer, check_pl)
195  && pplayers_allied(pplayer, check_pl)) {
196  adip->is_allied_with_ally = check_pl;
197  }
198  }
200  }
202 
203  /*** Statistics ***/
204 
205  ai->stats.workers = new int[adv->num_continents + 1]();
206  ai->stats.ocean_workers = new int[adv->num_oceans + 1]();
207 
208  unit_list_iterate(pplayer->units, punit)
209  {
210  struct tile *ptile = unit_tile(punit);
211 
212  if (unit_has_type_flag(punit, UTYF_SETTLERS)) {
213  if (is_ocean_tile(ptile)) {
214  ai->stats.ocean_workers[-tile_continent(ptile)]++;
215  } else {
216  ai->stats.workers[static_cast<int> tile_continent(ptile)]++;
217  }
218  }
219  }
221 
222  ai->stats.diplomat_reservations.clear();
223  unit_list_iterate(pplayer->units, punit)
224  {
226  && def_ai_unit_data(punit, ait)->task == AIUNIT_ATTACK) {
227  fc_assert_msg(punit->goto_tile != nullptr,
228  "No target city for spy action");
229 
230  if (punit->goto_tile != nullptr) {
231  struct city *pcity = tile_city(punit->goto_tile);
232 
233  if (pcity != nullptr) {
234  // Heading somewhere on a mission, reserve target.
235  ai->stats.diplomat_reservations.insert(pcity->id);
236  }
237  }
238  }
239  }
241 
242  aiferry_init_stats(ait, pplayer);
243 
244  /*** Interception engine ***/
245 
246  /* We are tracking a unit if punit->server.ai->cur_pos is not nullptr. If
247  * we are not tracking, start tracking by setting cur_pos. If we are, fill
248  * prev_pos with previous cur_pos. This way we get the necessary
249  * coordinates to calculate a probable trajectory. */
250  players_iterate_alive(aplayer)
251  {
252  if (aplayer == pplayer) {
253  continue;
254  }
255  unit_list_iterate(aplayer->units, punit)
256  {
257  struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
258 
259  if (!unit_data->cur_pos) {
260  // Start tracking
261  unit_data->cur_pos = &unit_data->cur_struct;
262  unit_data->prev_pos = nullptr;
263  } else {
264  unit_data->prev_struct = unit_data->cur_struct;
265  unit_data->prev_pos = &unit_data->prev_struct;
266  }
267  *unit_data->cur_pos = unit_tile(punit);
268  }
270  }
272 
273  if (caller_closes) {
274  adv_data_phase_done(pplayer);
275  }
276 }
277 
281 void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
282 {
283  struct ai_plr *ai = def_ai_player_data(pplayer, ait);
284 
285  if (!ai->phase_initialized) {
286  return;
287  }
288 
289  delete[] ai->stats.workers;
290  ai->stats.workers = nullptr;
291 
292  delete[] ai->stats.ocean_workers;
293  ai->stats.ocean_workers = nullptr;
294 
295  ai->phase_initialized = false;
296 }
297 
304 struct ai_plr *dai_plr_data_get(struct ai_type *ait, struct player *pplayer,
305  bool *caller_closes)
306 {
307  struct ai_plr *ai = def_ai_player_data(pplayer, ait);
308 
309  fc_assert_ret_val(ai != nullptr, nullptr);
310 
311  /* This assert really is required. See longer comment
312  in adv_data_get() for equivalent code. */
313 #if defined(FREECIV_DEBUG) || IS_DEVEL_VERSION
314  fc_assert(caller_closes != nullptr || ai->phase_initialized);
315 #endif
316 
317  if (caller_closes != nullptr) {
318  *caller_closes = false;
319  }
320 
322  || ai->last_num_oceans != wld.map.num_oceans) {
323  // We have discovered more continents, recalculate!
324 
325  // See adv_data_get()
326  if (ai->phase_initialized) {
327  dai_data_phase_finished(ait, pplayer);
328  dai_data_phase_begin(ait, pplayer, false);
329  } else {
330  // wrong order
331  log_debug("%s ai data phase closed when dai_plr_data_get() called",
332  player_name(pplayer));
333  dai_data_phase_begin(ait, pplayer, false);
334  if (caller_closes != nullptr) {
335  *caller_closes = true;
336  } else {
337  dai_data_phase_finished(ait, pplayer);
338  }
339  }
340  } else {
341  if (!ai->phase_initialized && caller_closes != nullptr) {
342  dai_data_phase_begin(ait, pplayer, false);
343  *caller_closes = true;
344  }
345  }
346 
347  return ai;
348 }
349 
353 static void dai_diplomacy_new(struct ai_type *ait, const struct player *plr1,
354  const struct player *plr2)
355 {
356  struct ai_dip_intel *player_intel;
357 
358  fc_assert_ret(plr1 != nullptr);
359  fc_assert_ret(plr2 != nullptr);
360 
361  const struct ai_dip_intel **player_intel_slot =
363  + player_index(plr2);
364 
365  fc_assert_ret(*player_intel_slot == nullptr);
366 
367  player_intel = new ai_dip_intel[1]();
368  *player_intel_slot = player_intel;
369 }
370 
374 static void dai_diplomacy_defaults(struct ai_type *ait,
375  const struct player *plr1,
376  const struct player *plr2)
377 {
378  struct ai_dip_intel *player_intel = dai_diplomacy_get(ait, plr1, plr2);
379 
380  fc_assert_ret(player_intel != nullptr);
381 
382  // pseudorandom value
383  player_intel->spam = (player_index(plr1) + player_index(plr2)) % 5;
384  player_intel->countdown = -1;
385  player_intel->war_reason = DAI_WR_NONE;
386  player_intel->distance = 1;
387  player_intel->ally_patience = 0;
388  player_intel->asked_about_peace = 0;
389  player_intel->asked_about_alliance = 0;
390  player_intel->asked_about_ceasefire = 0;
391  player_intel->warned_about_space = 0;
392 }
393 
398  const struct player *plr1,
399  const struct player *plr2)
400 {
401  fc_assert_ret_val(plr1 != nullptr, nullptr);
402  fc_assert_ret_val(plr2 != nullptr, nullptr);
403 
404  const struct ai_dip_intel **player_intel_slot =
406  + player_index(plr2);
407 
408  fc_assert_ret_val(player_intel_slot != nullptr, nullptr);
409 
410  return const_cast<struct ai_dip_intel *>(*player_intel_slot);
411 }
412 
416 static void dai_diplomacy_destroy(struct ai_type *ait,
417  const struct player *plr1,
418  const struct player *plr2)
419 {
420  fc_assert_ret(plr1 != nullptr);
421  fc_assert_ret(plr2 != nullptr);
422 
423  const struct ai_dip_intel **player_intel_slot =
425  + player_index(plr2);
426 
427  if (*player_intel_slot != nullptr) {
428  delete[] dai_diplomacy_get(ait, plr1, plr2);
429  }
430 
431  *player_intel_slot = nullptr;
432 }
433 
437 void dai_adjust_policies(struct ai_type *ait, struct player *pplayer)
438 {
439  bool needs_back_rearrange = false;
440  struct adv_data *adv;
441 
442  adv = adv_data_get(pplayer, nullptr);
443 
444  multipliers_iterate(ppol)
445  {
446  if (multiplier_can_be_changed(ppol, pplayer)) {
447  int orig_value = 0;
448  int mp_val = player_multiplier_value(pplayer, ppol);
449  int pidx = multiplier_index(ppol);
450  bool better_found = false;
451 
452  city_list_iterate(pplayer->cities, pcity)
453  {
454  orig_value += dai_city_want(pplayer, pcity, adv, nullptr);
455  }
457 
458  // Consider reducing policy value
459  if (mp_val > ppol->start) {
460  int new_value = 0;
461 
462  pplayer->multipliers[pidx] = MAX(mp_val - ppol->step, ppol->start);
463 
464  city_list_iterate(pplayer->cities, acity)
465  {
466  auto_arrange_workers(acity);
467  }
469 
470  city_list_iterate(pplayer->cities, pcity)
471  {
472  new_value += dai_city_want(pplayer, pcity, adv, nullptr);
473  }
475 
476  if (new_value > orig_value) {
477  // This is step to right direction, leave it in effect.
478  pplayer->multipliers_target[pidx] = pplayer->multipliers[pidx];
479 
480  needs_back_rearrange = false;
481  better_found = true;
482  }
483  }
484 
485  // Consider increasing policy value
486  if (!better_found && mp_val < ppol->stop) {
487  int new_value = 0;
488 
489  pplayer->multipliers[pidx] = MIN(mp_val + ppol->step, ppol->stop);
490 
491  city_list_iterate(pplayer->cities, acity)
492  {
493  auto_arrange_workers(acity);
494  }
496 
497  city_list_iterate(pplayer->cities, pcity)
498  {
499  new_value += dai_city_want(pplayer, pcity, adv, nullptr);
500  }
502 
503  if (new_value > orig_value) {
504  // This is step to right direction, leave it in effect.
505  pplayer->multipliers_target[pidx] = pplayer->multipliers[pidx];
506 
507  needs_back_rearrange = false;
508  better_found = true;
509  }
510  }
511 
512  if (!better_found) {
513  // Restore original multiplier value
514  pplayer->multipliers[pidx] = mp_val;
515  needs_back_rearrange = true;
516  }
517  }
518  }
520 
521  if (needs_back_rearrange) {
522  city_list_iterate(pplayer->cities, acity)
523  {
524  auto_arrange_workers(acity);
525  }
527  }
528 }
529 
533 void dai_gov_value(struct ai_type *ait, struct player *pplayer,
534  struct government *gov, adv_want *val, bool *override)
535 {
536  int dist;
537  int bonus = 0; // in percentage
538  int revolution_turns;
539  struct universal source = {.value = {.govern = gov},
540  .kind = VUT_GOVERNMENT};
541  struct adv_data *adv;
542  int turns = 9999; // TODO: Set to correct value
543  int nplayers;
544  const struct research *presearch;
545 
546  // Use default handling of no-cities case
547  if (city_list_size(pplayer->cities) == 0) {
548  *override = false;
549  return;
550  }
551 
552  adv = adv_data_get(pplayer, nullptr);
553  nplayers = normal_player_count();
554  presearch = research_get(pplayer);
555 
556  pplayer->government = gov;
557  /* Ideally we should change national budget here, but since
558  * this is a rather big CPU operation, we'd rather not. */
559  check_player_max_rates(pplayer);
560  city_list_iterate(pplayer->cities, acity) { auto_arrange_workers(acity); }
562  city_list_iterate(pplayer->cities, pcity)
563  {
564  bool capital;
565 
566  *val += dai_city_want(pplayer, pcity, adv, nullptr);
567  capital = is_capital(pcity);
568 
570  {
571  bool present = true;
572  bool active = true;
573 
574  requirement_vector_iterate(&peffect->reqs, preq)
575  {
576  /* Check if all the requirements for the currently evaluated effect
577  * are met, except for having the tech that we are evaluating.
578  * TODO: Consider requirements that could be met later. */
579  if (VUT_GOVERNMENT == preq->source.kind
580  && preq->source.value.govern == gov) {
581  present = preq->present;
582  continue;
583  }
584  if (!is_req_active(pplayer, nullptr, pcity, nullptr, nullptr,
585  nullptr, nullptr, nullptr, nullptr, nullptr, preq,
586  RPT_POSSIBLE)) {
587  active = false;
588  break; // presence doesn't matter for inactive effects.
589  }
590  }
592 
593  if (active) {
594  adv_want v1;
595 
596  v1 = dai_effect_value(pplayer, gov, adv, pcity, capital, turns,
597  peffect, 1, nplayers);
598 
599  if (!present) {
600  // Tech removes the effect
601  *val -= v1;
602  } else {
603  *val += v1;
604  }
605  }
606  }
608  }
610 
611  revolution_turns = get_player_bonus(pplayer, EFT_REVOLUTION_UNHAPPINESS);
612  if (revolution_turns > 0) {
613  bonus -= int(6 / revolution_turns);
614  }
615 
616  *val += (*val * bonus) / 100;
617 
618  // FIXME: handle reqs other than technologies.
619  dist = 0;
620  requirement_vector_iterate(&gov->reqs, preq)
621  {
622  if (VUT_ADVANCE == preq->source.kind) {
623  dist +=
625  presearch, advance_number(preq->source.value.advance)));
626  }
627  }
629  *val = amortize(*val, dist);
630 
631  *override = true;
632 }
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Return a pointer to our data.
Definition: advdata.cpp:591
void adv_data_phase_done(struct player *pplayer)
Clean up our mess.
Definition: advdata.cpp:556
adv_want amortize(adv_want benefit, int delay)
Amortize means gradually paying off a cost or debt over time.
Definition: advtools.cpp:25
bool aia_utype_is_considered_spy_vs_city(const struct unit_type *putype)
Returns TRUE if the specified unit type is able to perform diplomatic actions against cities.
Definition: aiactions.cpp:21
bool is_ai_data_phase_open(struct ai_type *ait, struct player *pplayer)
Return whether data phase is currently open.
Definition: aidata.cpp:128
void dai_gov_value(struct ai_type *ait, struct player *pplayer, struct government *gov, adv_want *val, bool *override)
Set value of the government.
Definition: aidata.cpp:533
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
Definition: aidata.cpp:397
static void dai_diplomacy_destroy(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Free resources allocated for diplomacy information between two players.
Definition: aidata.cpp:416
void dai_adjust_policies(struct ai_type *ait, struct player *pplayer)
Adjust multiplier values.
Definition: aidata.cpp:437
static void dai_diplomacy_new(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Allocate new ai diplomacy slot.
Definition: aidata.cpp:353
void dai_data_init(struct ai_type *ait, struct player *pplayer)
Initialize ai data structure.
Definition: aidata.cpp:50
void dai_data_phase_begin(struct ai_type *ait, struct player *pplayer, bool is_new_phase)
Make and cache lots of calculations needed for other functions.
Definition: aidata.cpp:138
static void dai_diplomacy_defaults(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Set diplomacy data between two players to its default values.
Definition: aidata.cpp:374
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Clean up ai data after phase finished.
Definition: aidata.cpp:281
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Get current default ai data related to player.
Definition: aidata.cpp:304
void dai_data_close(struct ai_type *ait, struct player *pplayer)
Deinitialize ai data structure.
Definition: aidata.cpp:98
@ WIN_OPEN
Definition: aidata.h:26
void aiferry_init_stats(struct ai_type *ait, struct player *pplayer)
Call to initialize the ferryboat statistics.
Definition: aiferry.cpp:84
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition: aiplayer.h:47
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition: aiplayer.h:41
void dai_auto_settler_init(struct ai_plr *ai)
Initialize ai settler engine.
Definition: aisettler.cpp:945
void dai_auto_settler_free(struct ai_plr *ai)
Deinitialize ai settler engine.
Definition: aisettler.cpp:1158
@ AIUNIT_ATTACK
Definition: aiunit.h:30
bool is_capital(const struct city *pcity)
Return TRUE iff this city is its nation's capital.
Definition: city.cpp:1495
#define city_list_iterate(citylist, pcity)
Definition: city.h:482
#define city_list_iterate_end
Definition: city.h:484
void auto_arrange_workers(struct city *pcity)
Call sync_cities() to send the affected cities to the clients.
Definition: cityturn.cpp:359
adv_want dai_city_want(struct player *pplayer, struct city *acity, struct adv_data *adv, struct impr_type *pimprove)
Calculates city want from some input values.
Definition: daicity.cpp:1419
void dai_diplomacy_begin_new_phase(struct ai_type *ait, struct player *pplayer)
Calculate our diplomatic predispositions here.
adv_want dai_effect_value(struct player *pplayer, struct government *gov, const struct adv_data *adv, const struct city *pcity, const bool capital, int turns, const struct effect *peffect, const int c, const int nplayers)
How desirable is a particular effect for a particular city, given the number of cities in range (c).
Definition: daieffects.cpp:130
struct effect_list * get_req_source_effects(struct universal *psource)
Get a list of effects with this requirement source.
Definition: effects.cpp:132
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
Definition: effects.cpp:673
#define effect_list_iterate_end
Definition: effects.h:349
#define effect_list_iterate(effect_list, peffect)
Definition: effects.h:347
float adv_want
Definition: fc_types.h:1144
@ RPT_POSSIBLE
Definition: fc_types.h:567
#define MAX_NUM_PLAYER_SLOTS
Definition: fc_types.h:24
struct world wld
Definition: game.cpp:48
#define fc_assert_msg(condition, message,...)
Definition: log.h:96
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
#define log_debug(message,...)
Definition: log.h:65
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
Can player change multiplier value.
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Returns multiplier index.
Definition: multipliers.cpp:77
#define multipliers_iterate(_mul_)
Definition: multipliers.h:45
#define multipliers_iterate_end
Definition: multipliers.h:51
int player_multiplier_value(const struct player *pplayer, const struct multiplier *pmul)
Return the multiplier value currently in effect for pplayer (in display units).
Definition: player.cpp:1856
int player_slot_index(const struct player_slot *pslot)
Returns the index of the player slot.
Definition: player.cpp:373
int player_index(const struct player *pplayer)
Return the player index.
Definition: player.cpp:748
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
Definition: player.cpp:816
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
Definition: player.cpp:1334
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
Definition: player.cpp:288
#define players_iterate_end
Definition: player.h:520
#define players_iterate(_pplayer)
Definition: player.h:514
#define MAX_AI_LOVE
Definition: player.h:546
static bool is_barbarian(const struct player *pplayer)
Definition: player.h:474
#define player_slots_iterate(_pslot)
Definition: player.h:505
#define is_ai(plr)
Definition: player.h:227
#define players_iterate_alive_end
Definition: player.h:532
#define player_slots_iterate_end
Definition: player.h:509
#define players_iterate_alive(_pplayer)
Definition: player.h:526
void check_player_max_rates(struct player *pplayer)
The following checks that government rates are acceptable for the present form of government.
Definition: plrhand.cpp:637
int normal_player_count()
Return the number of non-barbarian players.
Definition: plrhand.cpp:3140
bool is_req_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement *req, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement to see if it is active on the given target.
#define requirement_vector_iterate_end
Definition: requirements.h:80
#define requirement_vector_iterate(req_vec, preq)
Definition: requirements.h:78
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Returns the number of technologies the player need to research to get the goal technology.
Definition: research.cpp:745
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
Definition: research.cpp:110
#define MIN(x, y)
Definition: shared.h:49
#define MAX(x, y)
Definition: shared.h:48
adv_want val
Definition: advdata.h:121
int num_oceans
Definition: advdata.h:99
int num_continents
Definition: advdata.h:98
struct government * gov
Definition: advdata.h:120
struct player * at_war_with_ally
Definition: aidata.h:49
signed char asked_about_alliance
Definition: aidata.h:58
enum war_reason war_reason
Definition: aidata.h:55
signed char spam
Definition: aidata.h:52
signed char asked_about_peace
Definition: aidata.h:57
int distance
Definition: aidata.h:53
struct player * is_allied_with_ally
Definition: aidata.h:50
signed char warned_about_space
Definition: aidata.h:60
int countdown
Definition: aidata.h:54
signed char ally_patience
Definition: aidata.h:56
struct player * is_allied_with_enemy
Definition: aidata.h:48
signed char asked_about_ceasefire
Definition: aidata.h:59
Definition: aidata.h:63
int * ocean_workers
Definition: aidata.h:75
int last_num_oceans
Definition: aidata.h:67
int * workers
Definition: aidata.h:74
int last_num_continents
Definition: aidata.h:66
bool phase_initialized
Definition: aidata.h:64
struct ai_plr::@156 diplomacy
struct ai_settler * settler
Definition: aidata.h:92
int req_love_for_alliance
Definition: aidata.h:88
int timer
Definition: aidata.h:84
char love_incr
Definition: aidata.h:86
char love_coeff
Definition: aidata.h:85
QSet< int > diplomat_reservations
Definition: aidata.h:77
const struct ai_dip_intel ** player_intel_slots
Definition: aidata.h:82
struct ai_plr::@155 stats
int req_love_for_peace
Definition: aidata.h:87
enum winning_strategy strategy
Definition: aidata.h:83
Definition: ai.h:42
Definition: city.h:291
int id
Definition: city.h:296
int num_continents
Definition: map_types.h:74
int num_oceans
Definition: map_types.h:75
struct requirement_vector reqs
Definition: government.h:41
Definition: player.h:231
struct city_list * cities
Definition: player.h:263
struct government * government
Definition: player.h:240
struct unit_list * units
Definition: player.h:264
bool is_alive
Definition: player.h:250
int multipliers[MAX_NUM_MULTIPLIERS]
Definition: player.h:296
int multipliers_target[MAX_NUM_MULTIPLIERS]
Definition: player.h:298
Definition: tile.h:42
Definition: aiunit.h:39
struct tile ** prev_pos
Definition: aiunit.h:47
struct tile * cur_struct
Definition: aiunit.h:46
struct tile ** cur_pos
Definition: aiunit.h:47
struct tile * prev_struct
Definition: aiunit.h:46
universals_u value
Definition: fc_types.h:739
struct civ_map map
Definition: world_object.h:21
Tech_type_id advance_number(const struct advance *padvance)
Return the advance index.
Definition: tech.cpp:85
#define is_ocean_tile(ptile)
Definition: terrain.h:279
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
Definition: tile.cpp:72
#define tile_continent(_tile)
Definition: tile.h:74
struct government * govern
Definition: fc_types.h:578
#define unit_tile(_pu)
Definition: unit.h:371
#define unit_list_iterate(unitlist, punit)
Definition: unitlist.h:25
#define unit_list_iterate_end
Definition: unitlist.h:27
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
Definition: unittype.cpp:176