Freeciv21
Develop your civilization from humble roots to a global empire
daieffects.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 "city.h"
13 #include "effects.h"
14 #include "game.h"
15 #include "government.h"
16 #include "map.h"
17 #include "movement.h"
18 #include "multipliers.h"
19 #include "player.h"
20 #include "research.h"
21 #include "specialist.h"
22 #include "traderoutes.h"
23 #include "victory.h"
24 
25 // server
26 #include "plrhand.h"
27 
28 /* server/advisors */
29 #include "advdata.h"
30 #include "advtools.h"
31 
32 // ai
33 #include "aitraits.h"
34 #include "handicaps.h"
35 
36 #include "daieffects.h"
37 
52 static int get_entertainers(const struct city *pcity)
53 {
54  int providers = 0;
55 
57  {
58  if (get_specialist_output(pcity, i, O_LUXURY) >= game.info.happy_cost) {
59  providers += pcity->specialists[i];
60  }
61  }
63 
64  return providers;
65 }
66 
72  const struct city *pcity, int amount,
73  int num_cities, int happiness_step)
74 {
75  adv_want v = 0;
76 
77  if (get_city_bonus(pcity, EFT_NO_UNHAPPY) <= 0) {
78  int i;
79  int max_converted = pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL];
80 
81  // See if some step of happiness calculation gets capped
82  for (i = happiness_step; i < FEELING_FINAL; i++) {
83  max_converted = MIN(max_converted, pcity->feel[CITIZEN_UNHAPPY][i]);
84  }
85 
86  v = MIN(amount, max_converted + get_entertainers(pcity)) * 35;
87  }
88 
89  if (num_cities > 1) {
90  int factor = 2;
91 
92  // Try to build wonders to offset empire size unhappiness
93  if (city_list_size(pplayer->cities)
94  > get_player_bonus(pplayer, EFT_EMPIRE_SIZE_BASE)) {
95  if (get_player_bonus(pplayer, EFT_EMPIRE_SIZE_BASE) > 0) {
96  factor += city_list_size(pplayer->cities)
97  / MAX(get_player_bonus(pplayer, EFT_EMPIRE_SIZE_STEP), 1);
98  }
99  factor += 2;
100  }
101  v += factor * num_cities * amount;
102  }
103 
104  return v;
105 }
106 
110 static int num_affected_units(const struct effect *peffect,
111  const struct adv_data *ai)
112 {
113  int unit_count = 0;
114 
115  unit_class_iterate(pclass)
116  {
117  if (requirement_fulfilled_by_unit_class(pclass, &(peffect->reqs))) {
118  unit_count += ai->stats.units.byclass[uclass_index(pclass)];
119  }
120  }
122 
123  return unit_count;
124 }
125 
130 adv_want dai_effect_value(struct player *pplayer, struct government *gov,
131  const struct adv_data *adv,
132  const struct city *pcity, const bool capital,
133  int turns, const struct effect *peffect,
134  const int c, const int nplayers)
135 {
136  int amount = peffect->value;
137  bool affects_sea_capable_units = false;
138  bool affects_land_capable_units = false;
139  int num;
140  int trait;
141  adv_want v = 0;
142 
143  if (peffect->multiplier) {
144  if (pplayer) {
145  amount = (player_multiplier_effect_value(pplayer, peffect->multiplier)
146  * amount)
147  / 100;
148  } else {
149  amount = 0;
150  }
151  }
152 
153  if (amount == 0) {
154  /* We could prune such effects in ruleset loading already,
155  * but we allow people tuning their rulesets to temporarily disable
156  * the effect by setting value to 0 without need to completely
157  * remove the effect.
158  * Shortcutting these effects here is not only for performance,
159  * more importantly it makes sure code below assuming amount to
160  * be positive does not assign positive value. */
161  return 0;
162  }
163 
164  switch (peffect->type) {
165  // These effects have already been evaluated in base_want()
166  case EFT_CAPITAL_CITY:
167  case EFT_GOV_CENTER:
168  case EFT_UPKEEP_FREE:
169  case EFT_TECH_UPKEEP_FREE:
170  case EFT_POLLU_POP_PCT:
171  case EFT_POLLU_POP_PCT_2:
172  case EFT_POLLU_PROD_PCT:
173  case EFT_POLLU_TRADE_PCT:
174  case EFT_OUTPUT_BONUS:
175  case EFT_OUTPUT_BONUS_2:
176  case EFT_OUTPUT_ADD_TILE:
177  case EFT_OUTPUT_INC_TILE:
178  case EFT_OUTPUT_PER_TILE:
179  case EFT_OUTPUT_WASTE:
180  case EFT_OUTPUT_WASTE_BY_DISTANCE:
181  case EFT_OUTPUT_WASTE_BY_REL_DISTANCE:
182  case EFT_OUTPUT_WASTE_PCT:
183  case EFT_SPECIALIST_OUTPUT:
184  case EFT_ENEMY_CITIZEN_UNHAPPY_PCT:
185  case EFT_IRRIGATION_PCT:
186  case EFT_MINING_PCT:
187  case EFT_OUTPUT_TILE_PUNISH_PCT:
188  break;
189 
190  case EFT_CITY_VISION_RADIUS_SQ:
191  case EFT_UNIT_VISION_RADIUS_SQ:
192  /* Wild guess. "Amount" is the number of tiles (on average) that
193  * will be revealed by the effect. Note that with an omniscient
194  * AI this effect is actually not useful at all. */
195  v += c * amount;
196  break;
197 
198  case EFT_TURN_YEARS:
199  case EFT_TURN_FRAGMENTS:
200  case EFT_SLOW_DOWN_TIMELINE:
201  // AI doesn't care about these.
202  break;
203 
204  // WAG evaluated effects
205  case EFT_INCITE_COST_PCT:
206  v += c * amount / 100;
207  break;
208  case EFT_MAKE_HAPPY:
209  v += (get_entertainers(pcity)
211  * 5 * amount;
212  if (city_list_size(pplayer->cities)
213  > get_player_bonus(pplayer, EFT_EMPIRE_SIZE_BASE)) {
214  v += c * amount; // offset large empire size
215  }
216  v += c * amount;
217  break;
218  case EFT_UNIT_RECOVER:
219  // TODO
220  break;
221  case EFT_NO_UNHAPPY:
222  v += (get_entertainers(pcity)
224  * 30;
225  break;
226  case EFT_FORCE_CONTENT:
227  v += dai_content_effect_value(pplayer, pcity, amount, c, FEELING_FINAL);
228  break;
229  case EFT_MAKE_CONTENT:
230  v += dai_content_effect_value(pplayer, pcity, amount, c, FEELING_EFFECT);
231  break;
232  case EFT_MAKE_CONTENT_MIL_PER:
233  if (get_city_bonus(pcity, EFT_NO_UNHAPPY) <= 0) {
234  v += MIN(pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
235  + get_entertainers(pcity),
236  amount)
237  * 25;
238  v += MIN(amount, 5) * c;
239  }
240  break;
241  case EFT_MAKE_CONTENT_MIL:
242  if (get_city_bonus(pcity, EFT_NO_UNHAPPY) <= 0) {
243  v += pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] * amount
244  * MAX(unit_list_size(pcity->units_supported), 0) * 2;
245  v += c * MAX(amount + 2, 1);
246  }
247  break;
248  case EFT_TECH_PARASITE: {
249  int bulbs;
250  int value;
251 
252  if (nplayers <= amount) {
253  break;
254  }
255 
256  bulbs = 0;
257  players_iterate(aplayer)
258  {
259  int potential = (aplayer->server.bulbs_last_turn
260  + city_list_size(aplayer->cities) + 1);
261 
262  if (players_on_same_team(aplayer, pplayer)) {
263  continue;
264  }
265  bulbs += potential;
266  }
268 
269  /* For some number of turns we will be receiving bulbs for free
270  * Bulbs should be amortized properly for each turn.
271  * We use formula for the sum of geometric series:
272  */
273  value = bulbs * (1.0 - pow(1.0 - (1.0 / MORT), turns)) * MORT;
274 
275  value = value * (100 - game.server.freecost) * (nplayers - amount)
276  / (nplayers * amount * 100);
277 
278  // WAG
279  value /= 3;
280 
281  v += value;
282  break;
283  }
284  case EFT_CONQUEST_TECH_PCT:
285  /* Compare to EFT_GIVE_IMM_TECH which gives game.info.sciencebox *
286  * num_techs */
287  v += game.info.sciencebox * (100 - game.server.conquercost) / 200
288  * amount / 100;
289  break;
290  case EFT_GROWTH_FOOD:
291  v += c * 4 + (amount / 7) * pcity->surplus[O_FOOD];
292  break;
293  case EFT_GROWTH_SURPLUS_PCT:
294  v += c * (amount / 7) * pcity->surplus[O_FOOD]; // Guessed
295  break;
296  case EFT_HEALTH_PCT:
297  // Is plague possible
298  if (game.info.illness_on) {
299  v += c * 5 + (amount / 5) * pcity->server.illness;
300  }
301  break;
302  case EFT_AIRLIFT:
303  /* FIXME: We need some smart algorithm here. The below is
304  * totally braindead. */
305  v += c + MIN(adv->stats.units.airliftable, 13);
306  break;
307  case EFT_ANY_GOVERNMENT:
308  if (!can_change_to_government(pplayer, adv->goal.govt.gov)) {
309  v += MIN(MIN(adv->goal.govt.val, 65),
311  adv->goal.govt.req)
312  * 10);
313  }
314  break;
315  case EFT_ENABLE_NUKE:
316  // Treat nuke as a Cruise Missile upgrade
317  v += 20 + adv->stats.units.suicide_attackers * 5;
318  break;
319  case EFT_ENABLE_SPACE:
321  v += 10;
322  if (adv->dipl.production_leader == pplayer) {
323  v += 150;
324  }
325  }
326  break;
327  case EFT_VICTORY:
328  v += 250;
329  break;
330  case EFT_GIVE_IMM_TECH:
331  if (adv_wants_science(pplayer)) {
332  v += amount * (game.info.sciencebox + 1);
333  }
334  break;
335  case EFT_HAVE_CONTACTS: {
336  int new_contacts = 0;
337 
338  players_iterate_alive(theother)
339  {
340  if (player_diplstate_get(pplayer, theother)->contact_turns_left <= 0) {
341  new_contacts++;
342  }
343  }
345 
346  v += 30 * new_contacts;
347  } break;
348  case EFT_HAVE_EMBASSIES:
349  v += 2 * nplayers;
350  break;
351  case EFT_REVEAL_CITIES:
352  case EFT_NO_ANARCHY:
353  break; // Useless for AI
354  case EFT_NUKE_PROOF:
355  if (adv->threats.nuclear) {
356  v += city_size_get(pcity) * unit_list_size(pcity->tile->units)
357  * (capital + 1) * amount / 100;
358  }
359  break;
360  case EFT_REVEAL_MAP:
361  if (!adv->explore.land_done || !adv->explore.sea_done) {
362  v += 10;
363  }
364  break;
365  case EFT_UNIT_SLOTS:
366  v += 8 * c;
367  break;
368  case EFT_SIZE_UNLIMIT:
369  /* Note we look up the SIZE_UNLIMIT again right below. This could
370  * be avoided... */
371  if (amount > 0) {
372  if (get_city_bonus(pcity, EFT_SIZE_UNLIMIT) <= 0) {
373  amount = 20; // really big city
374  }
375  } else {
376  // Effect trying to remove unlimit.
377  v -= 30 * c * adv->food_priority;
378  break;
379  }
380  fc__fallthrough; /* there not being a break here is deliberate, mind you
381  */
382  case EFT_SIZE_ADJ:
383  if (get_city_bonus(pcity, EFT_SIZE_UNLIMIT) <= 0) {
384  const int aqueduct_size = get_city_bonus(pcity, EFT_SIZE_ADJ);
385  int extra_food = pcity->surplus[O_FOOD];
386 
387  if (city_granary_size(city_size_get(pcity)) == pcity->food_stock) {
388  /* The idea being that if we have a full granary, we have an
389  * automatic surplus of our granary excess in addition to anything
390  * collected by city workers. */
391  extra_food +=
392  pcity->food_stock - city_granary_size(city_size_get(pcity) - 1);
393  }
394 
395  if (amount > 0 && !city_can_grow_to(pcity, city_size_get(pcity) + 1)) {
396  v += extra_food * adv->food_priority * amount;
397  if (city_size_get(pcity) == aqueduct_size) {
398  v += 30 * extra_food;
399  }
400  }
401  fc_assert_ret_val(aqueduct_size, 0);
402  v += c * amount * 4 / aqueduct_size;
403  }
404  break;
405  case EFT_SS_STRUCTURAL:
406  case EFT_SS_COMPONENT:
407  case EFT_SS_MODULE:
409  /* If someone has started building spaceship already or
410  * we have chance to win a spacerace */
411  && (adv->dipl.spacerace_leader
412  || adv->dipl.production_leader == pplayer)) {
413  v += 140;
414  }
415  break;
416  case EFT_SPY_RESISTANT:
417  case EFT_SABOTEUR_RESISTANT:
418  // Uhm, problem: City Wall has -50% here!!
419  break;
420  case EFT_MOVE_BONUS:
421  num = num_affected_units(peffect, adv);
422  v += (8 * v * amount + num);
423  break;
424  case EFT_UNIT_NO_LOSE_POP:
425  v += unit_list_size(pcity->tile->units) * 2;
426  break;
427  case EFT_HP_REGEN:
428  case EFT_HP_REGEN_MIN:
429  num = num_affected_units(peffect, adv);
430  v += (5 * c + num);
431  break;
432  case EFT_VETERAN_COMBAT:
433  num = num_affected_units(peffect, adv);
434  v += (2 * c + num);
435  break;
436  case EFT_VETERAN_BUILD:
437  // FIXME: check other reqs (e.g., unitflag)
438  num = num_affected_units(peffect, adv);
439  v += amount * (3 * c + num);
440  break;
441  case EFT_UPGRADE_UNIT:
442  if (amount == 1) {
443  v += adv->stats.units.upgradeable * 2;
444  } else if (amount == 2) {
445  v += adv->stats.units.upgradeable * 3;
446  } else {
447  v += adv->stats.units.upgradeable * 4;
448  }
449  break;
450  case EFT_UNIT_BRIBE_COST_PCT:
451  num = num_affected_units(peffect, adv);
452  v += ((2 * c + num) * amount) / 400;
453  break;
454  case EFT_ATTACK_BONUS:
455  num = num_affected_units(peffect, adv);
456  v += (num + 4) * amount / 200;
457  break;
458  case EFT_DEFEND_BONUS:
459  if (has_handicap(pplayer, H_DEFENSIVE)) {
460  v += amount / 10; // make AI slow
461  }
462 
463  /* TODO: Really should consider how many affected enemy units there is.
464  */
465  unit_class_iterate(pclass)
466  {
467  if (requirement_fulfilled_by_unit_class(pclass, &peffect->reqs)) {
468  if (pclass->adv.sea_move != MOVE_NONE) {
469  affects_sea_capable_units = true;
470  }
471  if (pclass->adv.land_move != MOVE_NONE) {
472  affects_land_capable_units = true;
473  }
474  }
475  if (affects_sea_capable_units && affects_land_capable_units) {
476  // Don't bother searching more if we already know enough.
477  break;
478  }
479  }
481 
482  if (affects_sea_capable_units) {
483  if (is_ocean_tile(pcity->tile)) {
484  v += adv->threats.ocean[-tile_continent(pcity->tile)] ? amount / 6
485  : amount / 25;
486  } else {
487  adjc_iterate(&(wld.map), pcity->tile, tile2)
488  {
489  if (is_ocean_tile(tile2)) {
490  if (adv->threats.ocean[-tile_continent(tile2)]) {
491  v += amount / 6;
492  break;
493  }
494  }
495  }
497  }
498  }
499  v += (amount / 25 + adv->threats.invasions - 1) * c; // for wonder
500  if (capital || affects_land_capable_units) {
501  Continent_id place = tile_continent(pcity->tile);
502 
503  if ((place > 0 && adv->threats.continent[place]) || capital
504  || (adv->threats.invasions
505  /* FIXME: This ignores riverboats on some rulesets.
506  We should analyze rulesets when game starts
507  and have relevant checks here. */
508  && is_terrain_class_near_tile(pcity->tile, TC_OCEAN))) {
509  if (place > 0 && adv->threats.continent[place]) {
510  v += amount * 4 / 5;
511  } else {
512  v += amount / (!adv->threats.igwall ? (18 - capital * 6) : 18);
513  }
514  }
515  }
516  break;
517  case EFT_FORTIFY_DEFENSE_BONUS:
518  num = num_affected_units(peffect, adv);
519  v += (num + 4) * amount / 250; /* Divisor 250 is a bit bigger than one
520  * for EFT_ATTACK_BONUS that is always
521  * active. Fortify bonus applies only in
522  * special case that unit is fortified. */
523  break;
524  case EFT_BOMBARD_LIMIT_PCT:
525  /* TODO: ideally should track bombard threats in adv */
526  num = num_affected_units(peffect, adv);
527  v += (num + 4) * amount / 250;
528  break;
529  case EFT_GAIN_AI_LOVE:
530  players_iterate(aplayer)
531  {
532  if (is_ai(aplayer)) {
533  if (has_handicap(pplayer, H_DEFENSIVE)) {
534  v += amount / 10;
535  } else {
536  v += amount / 20;
537  }
538  }
539  }
541  break;
542  case EFT_UPGRADE_PRICE_PCT:
543  // This is based on average base upgrade price of 50.
544  v -= adv->stats.units.upgradeable * amount / 2;
545  break;
546  // Currently not supported for building AI - wait for modpack users
547  case EFT_CITY_UNHAPPY_SIZE:
548  case EFT_UNHAPPY_FACTOR:
549  case EFT_UPKEEP_FACTOR:
550  case EFT_UNIT_UPKEEP_FREE_PER_CITY:
551  case EFT_CIVIL_WAR_CHANCE:
552  case EFT_EMPIRE_SIZE_BASE:
553  case EFT_EMPIRE_SIZE_STEP:
554  case EFT_MAX_RATES:
555  case EFT_MARTIAL_LAW_EACH:
556  case EFT_MARTIAL_LAW_MAX:
557  case EFT_RAPTURE_GROW:
558  case EFT_REVOLUTION_UNHAPPINESS:
559  case EFT_HAS_SENATE:
560  case EFT_INSPIRE_PARTISANS:
561  case EFT_HAPPINESS_TO_GOLD:
562  case EFT_FANATICS:
563  case EFT_NO_DIPLOMACY:
564  case EFT_NOT_TECH_SOURCE:
565  case EFT_OUTPUT_PENALTY_TILE:
566  case EFT_OUTPUT_INC_TILE_CELEBRATE:
567  case EFT_TRADE_REVENUE_BONUS:
568  case EFT_TRADE_REVENUE_EXPONENT:
569  case EFT_TILE_WORKABLE:
570  case EFT_COMBAT_ROUNDS:
571  case EFT_ILLEGAL_ACTION_MOVE_COST:
572  case EFT_ILLEGAL_ACTION_HP_COST:
573  case EFT_CASUS_BELLI_CAUGHT:
574  case EFT_CASUS_BELLI_SUCCESS:
575  case EFT_CASUS_BELLI_COMPLETE:
576  case EFT_ACTION_ODDS_PCT:
577  case EFT_BORDER_VISION:
578  case EFT_STEALINGS_IGNORE:
579  case EFT_MAPS_STOLEN_PCT:
580  case EFT_UNIT_SHIELD_VALUE_PCT:
581  case EFT_WONDER_VISIBLE:
582  case EFT_NATION_INTELLIGENCE:
583  case EFT_NUKE_INFRASTRUCTURE_PCT:
584  break;
585  // This has no effect for AI
586  case EFT_VISIBLE_WALLS:
587  case EFT_CITY_IMAGE:
588  case EFT_SHIELD2GOLD_FACTOR:
589  break;
590  case EFT_PERFORMANCE:
591  case EFT_NATION_PERFORMANCE:
592  /* Consider each culture point worth 1/10 point, minimum of 1 point... */
593  v += amount / 10 + 1;
594  break;
595  case EFT_HISTORY:
596  case EFT_NATION_HISTORY:
597  // ...and history effect to accumulate those points for 50 turns.
598  v += amount * 5;
599  break;
600  case EFT_TECH_COST_FACTOR:
601  v -= amount * 50;
602  break;
603  case EFT_IMPR_BUILD_COST_PCT:
604  case EFT_UNIT_BUILD_COST_PCT:
605  v -= amount * 30;
606  break;
607  case EFT_IMPR_BUY_COST_PCT:
608  case EFT_NUKE_IMPROVEMENT_PCT:
609  case EFT_UNIT_BUY_COST_PCT:
610  v -= amount * 25;
611  break;
612  case EFT_CITY_RADIUS_SQ:
613  v += amount * 10; // AI wants bigger city radii
614  break;
615  case EFT_CITY_BUILD_SLOTS:
616  v += amount * 10;
617  break;
618  case EFT_MIGRATION_PCT:
619  // Consider all foreign cities within set distance
620  iterate_outward(&(wld.map), city_tile(pcity),
621  game.server.mgr_distance
622  + (int) sqrt(MAX(city_map_radius_sq_get(pcity), 0)),
623  ptile)
624  {
625  struct city *acity = tile_city(ptile);
626 
627  if (!acity || acity == pcity || city_owner(acity) == pplayer) {
628  // No city, the city in the center, or our own city
629  continue;
630  }
631 
632  v += amount; // AI wants migration into its cities!
633  }
635  break;
636  case EFT_MAX_TRADE_ROUTES:
637  trait = ai_trait_get_value(TRAIT_TRADER, pplayer);
638  v += amount
639  * (pow(2.0, static_cast<double>(
640  get_city_bonus(pcity, EFT_TRADE_REVENUE_BONUS))
641  / 1000.0)
642  + c)
643  * trait / TRAIT_DEFAULT_VALUE;
644  if (city_num_trade_routes(pcity) >= max_trade_routes(pcity)
645  && amount > 0) {
646  // Has no free trade routes before this
647  v += trait;
648  }
649  break;
650  case EFT_TRADEROUTE_PCT: {
651  int trade = 0;
652 
653  trait = ai_trait_get_value(TRAIT_TRADER, pplayer);
654 
655  trade_partners_iterate(pcity, tgt)
656  {
657  trade += trade_base_between_cities(pcity, tgt);
658  }
660 
661  v += trade * amount * trait / 100 / TRAIT_DEFAULT_VALUE;
662 
663  if (city_num_trade_routes(pcity) < max_trade_routes(pcity)
664  && amount > 0) {
665  // Space for future routes
666  v += trait * 5 / TRAIT_DEFAULT_VALUE;
667  }
668  } break;
669  case EFT_MAX_STOLEN_GOLD_PM:
670  v -= amount / 40;
671  break;
672  case EFT_THIEFS_SHARE_PM:
673  v -= amount / 80;
674  break;
675  case EFT_RETIRE_PCT:
676  num = num_affected_units(peffect, adv);
677  v -= amount * num / 20;
678  break;
679  case EFT_ACTION_SUCCESS_MOVE_COST:
680  case EFT_ACTION_SUCCESS_TARGET_MOVE_COST: {
681  // Taking MAX_MOVE_FRAGS takes all the move fragments.
682  adv_want move_fragment_cost = MIN(MAX_MOVE_FRAGS, amount);
683 
684  // Lose all movement => 1.
685  v -= move_fragment_cost / static_cast<adv_want>(MAX_MOVE_FRAGS);
686  } break;
687  case EFT_INFRA_POINTS:
688  v += amount * adv->infra_priority;
689  break;
690  case EFT_COUNT:
691  qCritical("Bad effect type.");
692  break;
693  }
694 
695  return v;
696 }
697 
701 static bool have_better_government(const struct player *pplayer,
702  const struct government *pgov)
703 {
704  if (pgov->ai.better) {
705  if (pplayer->government == pgov->ai.better) {
706  return true;
707  } else {
708  return have_better_government(pplayer, pgov->ai.better);
709  }
710  }
711  return false;
712 }
724  const struct player *pplayer,
725  const struct city *pcity)
726 {
727  switch (preq->source.kind) {
728  case VUT_GOVERNMENT:
729  // We can't meet a government requirement if we have a better one.
730  return !have_better_government(pplayer, preq->source.value.govern);
731 
732  case VUT_IMPROVEMENT: {
733  const struct impr_type *pimprove = preq->source.value.building;
734 
735  if (preq->present && improvement_obsolete(pplayer, pimprove, pcity)) {
736  // Would need to unobsolete a building, which is too hard.
737  return false;
738  } else if (!preq->present && pcity != nullptr
739  && I_NEVER < pcity->built[improvement_index(pimprove)].turn
740  && !can_improvement_go_obsolete(pimprove)) {
741  /* Would need to unbuild an unobsoleteable building, which is too hard.
742  */
743  return false;
744  } else if (preq->present) {
745  requirement_vector_iterate(&pimprove->reqs, ireq)
746  {
747  if (!dai_can_requirement_be_met_in_city(ireq, pplayer, pcity)) {
748  return false;
749  }
750  }
752  }
753  break;
754  } // VUT_IMPROVEMENT inline block
755 
756  case VUT_SPECIALIST:
757  if (preq->present) {
759  sreq)
760  {
761  if (!dai_can_requirement_be_met_in_city(sreq, pplayer, pcity)) {
762  return false;
763  }
764  }
766  } // It is always possible to remove a specialist.
767  break;
768 
769  case VUT_NATIONALITY:
770  // Crude, but the right answer needs to consider civil wars.
772 
773  case VUT_CITYSTATUS:
774  if (pcity == nullptr) {
775  return preq->present;
776  }
777  if (preq->present) {
778  return city_owner(pcity) == pcity->original;
779  } else {
780  return city_owner(pcity) != pcity->original;
781  }
782 
783  case VUT_TERRAIN:
784  case VUT_TERRAINCLASS:
785  case VUT_TERRAINALTER:
786  case VUT_TERRFLAG:
787  case VUT_BASEFLAG:
788  case VUT_ROADFLAG:
789  case VUT_EXTRAFLAG:
790  case VUT_EXTRA:
791  /* TODO: These could be determined by building a map of all
792  * possible futures (e.g. terrain transformations, etc.),
793  * and traversing it for all tiles in largest possible range
794  * of city, and using that to check requirements. */
795  break;
796 
797  case VUT_ADVANCE:
798  case VUT_MINSIZE:
799  case VUT_MINYEAR:
800  case VUT_TOPO:
801  case VUT_AGE:
802  case VUT_TECHFLAG:
803  case VUT_ACHIEVEMENT:
804  case VUT_MINCULTURE:
805  case VUT_MINTECHS:
806  // No way to remove once present.
807  return preq->present;
808 
809  case VUT_MINFOREIGNPCT:
810  // No way to add once lost.
811  return !preq->present;
812 
813  case VUT_NATION:
814  case VUT_NATIONGROUP:
815  case VUT_AI_LEVEL:
816  case VUT_SERVERSETTING:
817  // Beyond player control.
818  return false;
819 
820  case VUT_OTYPE:
821  case VUT_CITYTILE:
822  case VUT_IMPR_GENUS:
823  // Can always be achieved.
824  return true;
825 
826  case VUT_NONE:
827  case VUT_UTYPE:
828  case VUT_UTFLAG:
829  case VUT_UCLASS:
830  case VUT_UCFLAG:
831  case VUT_DIPLREL:
832  case VUT_MAXTILEUNITS:
833  case VUT_STYLE:
834  case VUT_UNITSTATE:
835  case VUT_ACTIVITY:
836  case VUT_MINMOVES:
837  case VUT_MINVETERAN:
838  case VUT_MINHP:
839  case VUT_ACTION:
840  case VUT_GOOD:
841  case VUT_MINCALFRAG:
842  case VUT_VISIONLAYER:
843  case VUT_NINTEL:
844  case VUT_COUNT:
845  // No sensible implementation possible with data available.
846  break;
847  }
848  return true;
849 }
bool adv_wants_science(struct player *pplayer)
Return whether science would help us at all.
Definition: advdata.cpp:1051
#define MORT
Definition: advtools.h:16
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Get current value of player trait.
Definition: aitraits.cpp:62
int city_granary_size(int city_size)
Generalized formula used to calculate granary size.
Definition: city.cpp:2034
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
Definition: city.cpp:1095
bool city_can_grow_to(const struct city *pcity, int pop_size)
Return TRUE iff the city can grow to the given size.
Definition: city.cpp:1914
int city_map_radius_sq_get(const struct city *pcity)
Returns the current squared radius of the city.
Definition: city.cpp:130
citizens city_size_get(const struct city *pcity)
Get the city size.
Definition: city.cpp:1101
@ CITIZEN_UNHAPPY
Definition: city.h:242
@ FEELING_EFFECT
Definition: city.h:253
@ FEELING_FINAL
Definition: city.h:256
bool dai_can_requirement_be_met_in_city(const struct requirement *preq, const struct player *pplayer, const struct city *pcity)
Does the AI expect to ever be able to meet this requirement.
Definition: daieffects.cpp:723
adv_want dai_content_effect_value(const struct player *pplayer, const struct city *pcity, int amount, int num_cities, int happiness_step)
How desirable particular effect making people content is for a particular city?
Definition: daieffects.cpp:71
static int num_affected_units(const struct effect *peffect, const struct adv_data *ai)
Number of AI stats units affected by effect.
Definition: daieffects.cpp:110
static bool have_better_government(const struct player *pplayer, const struct government *pgov)
Checks recursively to see if the player already has a better government.
Definition: daieffects.cpp:701
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
static int get_entertainers(const struct city *pcity)
Return the number of "luxury specialists".
Definition: daieffects.cpp:52
int get_city_bonus(const struct city *pcity, enum effect_type effect_type, enum vision_layer vlayer)
Returns the effect bonus at a city.
Definition: effects.cpp:688
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
Definition: effects.cpp:673
float adv_want
Definition: fc_types.h:1144
@ VC_SPACERACE
Definition: fc_types.h:1083
@ O_FOOD
Definition: fc_types.h:85
@ O_LUXURY
Definition: fc_types.h:89
signed short Continent_id
Definition: fc_types.h:289
struct civ_game game
Definition: game.cpp:47
struct world wld
Definition: game.cpp:48
bool can_change_to_government(struct player *pplayer, const struct government *gov)
Can change to government if appropriate tech exists, and one of:
Definition: government.cpp:159
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
AI players may have handicaps - allowing them to cheat or preventing them from using certain algorith...
Definition: handicaps.cpp:62
@ H_DEFENSIVE
Definition: handicaps.h:20
bool can_improvement_go_obsolete(const struct impr_type *pimprove)
Return TRUE if the improvement can ever go obsolete.
Impr_type_id improvement_index(const struct impr_type *pimprove)
Return the improvement index.
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
Returns TRUE if the improvement or wonder is obsolete.
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
#define iterate_outward(nmap, start_tile, max_dist, itr_tile)
Definition: map.h:288
#define iterate_outward_end
Definition: map.h:291
#define adjc_iterate_end
Definition: map.h:358
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition: map.h:351
#define MAX_MOVE_FRAGS
Definition: movement.h:20
int player_multiplier_effect_value(const struct player *pplayer, const struct multiplier *pmul)
Return the multiplier value currently in effect for pplayer, scaled from display units to the units u...
Definition: player.cpp:1867
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Return TRUE if players are in the same team.
Definition: player.cpp:1405
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 is_ai(plr)
Definition: player.h:227
#define players_iterate_alive_end
Definition: player.h:532
#define players_iterate_alive(_pplayer)
Definition: player.h:526
bool nation_is_in_current_set(const struct nation_type *pnation)
Is the nation in the currently selected nationset? If not, it's not allowed to appear in the game.
Definition: plrhand.cpp:2520
#define requirement_vector_iterate_end
Definition: requirements.h:80
#define requirement_vector_iterate(req_vec, preq)
Definition: requirements.h:78
#define requirement_fulfilled_by_unit_class(_uc_, _rqs_)
Definition: requirements.h:302
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
int get_specialist_output(const struct city *pcity, Specialist_type_id sp, Output_type_id otype)
Return the output for the specialist type with this output type.
Definition: specialist.cpp:218
#define specialist_type_iterate_end
Definition: specialist.h:73
#define specialist_type_iterate(sp)
Definition: specialist.h:67
bool * ocean
Definition: advdata.h:56
struct adv_data::@85 threats
bool invasions
Definition: advdata.h:54
bool igwall
Definition: advdata.h:59
struct adv_data::@87 stats
int nuclear
Definition: advdata.h:58
int food_priority
Definition: advdata.h:103
struct player * production_leader
Definition: advdata.h:95
struct adv_data::@89 goal
struct adv_data::@88 dipl
struct adv_data::@89::@91 govt
struct adv_data::@87::@90 units
bool * continent
Definition: advdata.h:55
bool sea_done
Definition: advdata.h:67
bool land_done
Definition: advdata.h:66
struct adv_data::@86 explore
struct player * spacerace_leader
Definition: advdata.h:94
Definition: city.h:291
int surplus[O_LAST]
Definition: city.h:324
int food_stock
Definition: city.h:338
struct player * original
Definition: city.h:295
struct adv_city * adv
Definition: city.h:422
struct city::@15::@17 server
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition: city.h:302
citizens specialists[SP_MAX]
Definition: city.h:305
struct tile * tile
Definition: city.h:293
struct unit_list * units_supported
Definition: city.h:377
struct civ_game::@28::@32 server
struct packet_game_info info
Definition: game.h:80
int value
Definition: effects.h:336
struct multiplier * multiplier
Definition: effects.h:331
struct requirement_vector reqs
Definition: effects.h:340
enum effect_type type
Definition: effects.h:328
struct government * better
Definition: government.h:48
struct government::@38 ai
struct requirement_vector reqs
Definition: improvement.h:66
Definition: player.h:231
struct city_list * cities
Definition: player.h:263
struct government * government
Definition: player.h:240
struct universal source
Definition: requirements.h:68
struct unit_list * units
Definition: tile.h:50
enum universals_n kind
Definition: fc_types.h:740
universals_u value
Definition: fc_types.h:739
struct civ_map map
Definition: world_object.h:21
#define fc__fallthrough
Definition: support.h:49
bool is_terrain_class_near_tile(const struct tile *ptile, enum terrain_class tclass)
Is there terrain of the given class near tile? (Does not check ptile itself.)
Definition: terrain.cpp:495
#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
int max_trade_routes(const struct city *pcity)
Return current maximum number of trade routes city can have.
Definition: traderoutes.cpp:41
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
Return the trade that exists between these cities, assuming they have a trade route.
int city_num_trade_routes(const struct city *pcity)
Return number of trade route city has.
#define trade_partners_iterate_end
Definition: traderoutes.h:163
#define trade_partners_iterate(c, p)
Definition: traderoutes.h:153
#define TRAIT_DEFAULT_VALUE
Definition: traits.h:27
struct specialist * specialist
Definition: fc_types.h:582
struct nation_type * nation
Definition: fc_types.h:580
struct government * govern
Definition: fc_types.h:578
const struct impr_type * building
Definition: fc_types.h:579
#define unit_class_iterate(_p)
Definition: unittype.h:823
@ MOVE_NONE
Definition: unittype.h:115
#define uclass_index(_c_)
Definition: unittype.h:684
#define unit_class_iterate_end
Definition: unittype.h:829
bool victory_enabled(enum victory_condition_type victory)
Whether victory condition is enabled.
Definition: victory.cpp:20