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