Freeciv-3.1: /fast/freeciv/nightly/S3_1/ai/default/daidomestic.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
daidomestic.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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#include <string.h>
19#include <math.h> /* pow, ceil */
20
21/* utility */
22#include "log.h"
23#include "mem.h"
24
25/* common */
26#include "city.h"
27#include "game.h"
28#include "government.h"
29#include "map.h"
30#include "movement.h"
31#include "traderoutes.h"
32#include "unit.h"
33#include "unitlist.h"
34#include "unittype.h"
35
36/* common/aicore */
37#include "pf_tools.h"
38
39/* server */
40#include "citytools.h"
41#include "unittools.h"
42#include "srv_log.h"
43
44/* server/advisors */
45#include "advbuilding.h"
46#include "advchoice.h"
47#include "advdata.h"
48#include "autosettlers.h"
49#include "infracache.h" /* adv_city */
50
51/* ai */
52#include "aitraits.h"
53#include "handicaps.h"
54
55/* ai/default */
56#include "aidata.h"
57#include "ailog.h"
58#include "aiplayer.h"
59#include "aitech.h"
60#include "aitools.h"
61#include "aiunit.h"
62#include "daicity.h"
63#include "daimilitary.h"
64
65#include "daidomestic.h"
66
67
68/***********************************************************************/
74 static void dai_choose_help_wonder(struct ai_type *ait,
75 struct city *pcity,
76 struct adv_choice *choice,
77 struct adv_data *ai)
78{
79 struct player *pplayer = city_owner(pcity);
80 Continent_id continent = tile_continent(pcity->tile);
81 struct ai_city *city_data = def_ai_city_data(pcity, ait);
82 /* Total count of caravans available or already being built
83 * on this continent */
84 int caravans = 0;
85 /* The type of the caravan */
86 struct unit_type *unit_type;
87 struct city *wonder_city = game_city_by_number(ai->wonder_city);
88
89 if (num_role_units(action_id_get_role(ACTION_HELP_WONDER)) == 0) {
90 /* No such units available in the ruleset */
91 return;
92 }
93
94 if (pcity == wonder_city
95 || wonder_city == NULL
96 || city_data->distance_to_wonder_city <= 0
97 || !city_production_gets_caravan_shields(&wonder_city->production)
98 /* TODO: Should helping to build a unit be considered when legal? */
99 || VUT_UTYPE == wonder_city->production.kind
100 /* TODO: Should helping to build an improvement be considered when
101 * legal? */
102 || !is_wonder(wonder_city->production.value.building)) {
103 /* A distance of zero indicates we are very far away, possibly
104 * on another continent. */
105 return;
106 }
107
108 /* Count existing caravans */
109 unit_list_iterate(pplayer->units, punit) {
110 if (unit_can_do_action(punit, ACTION_HELP_WONDER)
111 && tile_continent(unit_tile(punit)) == continent)
112 caravans++;
113 } unit_list_iterate_end;
114
115 /* Count caravans being built */
116 city_list_iterate(pplayer->cities, acity) {
117 if (VUT_UTYPE == acity->production.kind
118 && utype_can_do_action(acity->production.value.utype,
119 ACTION_HELP_WONDER)
120 && tile_continent(acity->tile) == continent) {
121 caravans++;
122 }
123 } city_list_iterate_end;
124
125 unit_type = best_role_unit(pcity, action_id_get_role(ACTION_HELP_WONDER));
126
127 if (!unit_type) {
128 /* We cannot build such units yet
129 * but we will consider it to stimulate science */
130 unit_type = get_role_unit(action_id_get_role(ACTION_HELP_WONDER), 0);
131 }
132
133 fc_assert_msg(utype_can_do_action(unit_type, ACTION_HELP_WONDER),
134 "Non existence of wonder helper unit not caught");
135
136 /* Check if wonder needs a little help. */
137 if (build_points_left(wonder_city)
138 > utype_build_shield_cost_base(unit_type) * caravans) {
139 const struct impr_type *wonder = wonder_city->production.value.building;
140 adv_want want = wonder_city->server.adv->building_want[improvement_index(wonder)];
141 int dist = city_data->distance_to_wonder_city /
142 unit_type->move_rate;
143
144 fc_assert_ret(VUT_IMPROVEMENT == wonder_city->production.kind);
145
146 want /= MAX(dist, 1);
147 CITY_LOG(LOG_DEBUG, pcity, "want %s to help wonder in %s with " ADV_WANT_PRINTF,
148 utype_rule_name(unit_type),
149 city_name_get(wonder_city),
150 want);
151 if (want > choice->want) {
152 /* This sets our tech want in cases where we cannot actually build
153 * the unit. */
154 unit_type = dai_wants_role_unit(ait, pplayer, pcity,
155 action_id_get_role(ACTION_HELP_WONDER),
156 want);
157 if (unit_type != NULL) {
158 choice->want = want;
159 choice->type = CT_CIVILIAN;
160 choice->value.utype = unit_type;
161 } else {
162 CITY_LOG(LOG_DEBUG, pcity,
163 "would but could not build ACTION_HELP_WONDER unit, "
164 "bumped reqs");
165 }
166 }
167 }
168}
169
170/***********************************************************************/
175 static void dai_choose_trade_route(struct ai_type *ait, struct city *pcity,
176 struct adv_choice *choice,
177 struct adv_data *ai)
178{
179 struct player *pplayer = city_owner(pcity);
180 struct unit_type *unit_type;
181 adv_want want;
182 int income, bonus;
183 int trade_routes;
184 int caravan_units;
185 int unassigned_caravans;
186 int max_routes;
187 Continent_id continent = tile_continent(pcity->tile);
188 bool dest_city_found = FALSE;
189 bool dest_city_nat_different_cont = FALSE;
190 bool dest_city_nat_same_cont = FALSE;
191 bool dest_city_in_different_cont = FALSE;
192 bool dest_city_in_same_cont = FALSE;
193 bool prefer_different_cont;
194 int pct = 0;
195 int trader_trait;
196 bool can_move_ic = FALSE, has_boats = TRUE;
197 bool need_boat = FALSE;
198 int trade_action;
199
200 if (city_list_size(pplayer->cities) < 5) {
201 /* Consider trade routes only if enough destination cities.
202 * This is just a quick check. We make more detailed check below. */
203 return;
204 }
205
206 if (num_role_units(action_id_get_role(ACTION_TRADE_ROUTE)) == 0
207 && num_role_units(action_id_get_role(ACTION_MARKETPLACE)) == 0) {
208 /* No such units available in the ruleset */
209 return;
210 }
211
212 unit_type = best_role_unit(pcity,
213 action_id_get_role(ACTION_TRADE_ROUTE));
214
215 if (!unit_type) {
216 /* Can't establish trade route yet. What about entering a marketplace? */
217 /* TODO: Should a future unit capable of establishing trade routes be
218 * prioritized above a present unit capable of entering a market place?
219 * In that case this should be below the check for a future unit
220 * capable of establishing a trade route. */
221 unit_type = best_role_unit(pcity,
222 action_id_get_role(ACTION_MARKETPLACE));
223 }
224
225 if (!unit_type) {
226 /* We cannot build such units yet
227 * but we will consider it to stimulate science */
228 unit_type = get_role_unit(action_id_get_role(ACTION_TRADE_ROUTE), 0);
229 }
230
231 if (!unit_type) {
232 /* We'll never be able to establish a trade route. Consider a unit that
233 * can enter the marketplace instead, to stimulate science. */
234 unit_type = get_role_unit(action_id_get_role(ACTION_MARKETPLACE), 0);
235 }
236
237 fc_assert_msg(unit_type,
238 "Non-existence of trade unit not caught");
239
240 if (unit_type) {
241 struct unit_class *pclass = utype_class(unit_type);
242
243 /* Hope there is no "water cities in lakes" ruleset? */
244 can_move_ic = pclass->adv.sea_move != MOVE_NONE;
245 has_boats = pclass->adv.ferry_types > 0;
246 }
247
248 if (trade_route_type_trade_pct(TRT_NATIONAL_IC) >
249 trade_route_type_trade_pct(TRT_NATIONAL)
250 && (can_move_ic || has_boats)) {
251 prefer_different_cont = TRUE;
252 } else {
253 prefer_different_cont = FALSE;
254 }
255
256 /* Look for proper destination city for trade. */
257 if (trade_route_type_trade_pct(TRT_NATIONAL) > 0
258 || trade_route_type_trade_pct(TRT_NATIONAL_IC) > 0) {
259 /* National trade routes have value */
260 city_list_iterate(pplayer->cities, acity) {
261 if (can_cities_trade(pcity, acity)) {
262 if (tile_continent(acity->tile) != continent) {
263 if (!(can_move_ic || has_boats)) {
264 /* FIXME: get by roads/rivers? */
265 continue;
266 }
267 dest_city_found = TRUE;
268 dest_city_nat_different_cont = TRUE;
269 if (prefer_different_cont) {
270 break;
271 }
272 } else {
273 dest_city_found = TRUE;
274 dest_city_nat_same_cont = TRUE;
275 if (!prefer_different_cont) {
276 break;
277 }
278 }
279 }
280 } city_list_iterate_end;
281 }
282
283 /* FIXME: This check should consider more about relative
284 * income from different trade route types. This works just
285 * with more typical ruleset setups. */
286 if (prefer_different_cont && !dest_city_nat_different_cont) {
287 if (trade_route_type_trade_pct(TRT_IN_IC) >
288 trade_route_type_trade_pct(TRT_IN)) {
289 prefer_different_cont = TRUE;
290 } else {
291 prefer_different_cont = FALSE;
292 }
293
294 players_iterate(aplayer) {
295 if (aplayer == pplayer || !aplayer->is_alive) {
296 continue;
297 }
298 if (pplayers_allied(pplayer, aplayer)) {
299 city_list_iterate(aplayer->cities, acity) {
300 if (can_cities_trade(pcity, acity)) {
301 if (tile_continent(acity->tile) != continent) {
302 if (!(can_move_ic || has_boats)) {
303 /* FIXME: get by roads/rivers? */
304 continue;
305 }
306 dest_city_found = TRUE;
307 dest_city_in_different_cont = TRUE;
308 if (prefer_different_cont) {
309 break;
310 }
311 } else {
312 dest_city_found = TRUE;
313 dest_city_in_same_cont = TRUE;
314 if (!prefer_different_cont) {
315 break;
316 }
317 }
318 }
319 } city_list_iterate_end;
320 }
321 if ((dest_city_in_different_cont && prefer_different_cont)
322 || (dest_city_in_same_cont && !prefer_different_cont)) {
323 break;
324 }
325 } players_iterate_end;
326 }
327
328 if (!dest_city_found) {
329 /* No proper destination city. */
330 return;
331 }
332
333 trade_routes = city_num_trade_routes(pcity);
334 /* Count also caravans enroute to establish trade routes */
335 caravan_units = 0;
336 unit_list_iterate(pcity->units_supported, punit) {
337 if (unit_can_do_action(punit, ACTION_TRADE_ROUTE)) {
338 caravan_units++;
339 }
340 } unit_list_iterate_end;
341
342 max_routes = max_trade_routes(pcity);
343 unassigned_caravans = caravan_units - (max_routes - trade_routes);
344 trade_routes += caravan_units;
345
346 /* We consider only initial benefit from establishing trade route.
347 * We may actually get only initial benefit if both cities already
348 * have four trade routes, if there already is route between them
349 * or if the Establish Trade Route action is illegal. */
350
351 /* The calculations of get_caravan_enter_city_trade_bonus() have to be
352 * duplicated here because the city traded with is imaginary. */
353
354 /* We assume that we are creating trade route to city with 75% of
355 * pcitys trade 10 squares away (FIXME: another estimation?). */
356 if (CBS_LOGARITHMIC == game.info.caravan_bonus_style) {
357 int wd = ((100 - game.info.trade_world_rel_pct) * 10
358 + game.info.trade_world_rel_pct
359 * (10 * 40 / MAX(wld.map.xsize, wld.map.ysize))) / 100;
360
361 income = pow(log(wd + 20 + 1.75 * max_trade_prod(pcity)) * 2, 2);
362 } else /* assume CBS_CLASSIC */ {
363 income = (10 + 10) * (1.75 * pcity->surplus[O_TRADE]) / 24;
364 }
365
366 /* A ruleset may use the Trade_Revenue_Bonus effect to reduce the one
367 * time bonus if no trade route is established. Make sure it gets the
368 * correct action. */
369 trade_action = utype_can_do_action(unit_type, ACTION_TRADE_ROUTE) ?
370 ACTION_TRADE_ROUTE : ACTION_MARKETPLACE;
371 bonus = get_target_bonus_effects(NULL,
372 &(const struct req_context) {
373 .player = pplayer,
374 .city = pcity,
375 .tile = city_tile(pcity),
376 .action =
377 action_by_number(trade_action),
378 },
379 NULL,
380 EFT_TRADE_REVENUE_BONUS);
381
382 /* Be mercy full to players with small amounts. Round up. */
383 income = ceil((float)income * pow(2.0, (double)bonus / 1000.0));
384
385 if (dest_city_nat_same_cont) {
386 pct = trade_route_type_trade_pct(TRT_NATIONAL);
387 }
388 if (dest_city_in_same_cont) {
389 int typepct = trade_route_type_trade_pct(TRT_IN);
390
391 pct = MAX(pct, typepct);
392 }
393 if (dest_city_nat_different_cont) {
394 int typepct = trade_route_type_trade_pct(TRT_NATIONAL_IC);
395
396 if (typepct > pct) {
397 pct = typepct;
398 need_boat = TRUE;
399 }
400 }
401 if (dest_city_in_different_cont) {
402 int typepct = trade_route_type_trade_pct(TRT_IN_IC);
403
404 if (typepct > pct) {
405 pct = typepct;
406 need_boat = TRUE;
407 }
408 }
409
410 need_boat = need_boat && !can_move_ic;
411 income = pct * income / 100;
412
413 want = income * ai->gold_priority + income * ai->science_priority;
414
415 /* We get this income only once after all.
416 * This value is adjusted for most interesting gameplay.
417 * For optimal performance AI should build more caravans, but
418 * we want it to build less valued buildings too. */
419 trader_trait = ai_trait_get_value(TRAIT_TRADER, pplayer);
420 want /= (130 * TRAIT_DEFAULT_VALUE / trader_trait);
421
422 /* Increase want for trade routes if our economy is very weak.
423 * We may have enough gold, but only because we have already set
424 * tax rate to 100%. So don't check gold directly, but tax rate.
425 * This method helps us out of deadlocks of completely stalled
426 * scientific progress.
427 */
428 if (pplayer->economic.science < 50 && trade_routes < max_routes
429 && utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) {
430 want *=
431 (6 - pplayer->economic.science / 10) * (6 - pplayer->economic.science / 10);
432 }
433
434 if (trade_routes == 0 && max_routes > 0
435 && utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) {
436 /* If we have no trade routes at all, we are certainly creating a new one. */
437 want += trader_trait;
438 } else if (trade_routes < max_routes
439 && utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) {
440 /* Possibly creating a new trade route */
441 want += trader_trait / 4;
442 }
443
444 want -= utype_build_shield_cost(pcity, NULL, unit_type) * SHIELD_WEIGHTING / 150;
445
446 /* Don't pile too many of them */
447 if (unassigned_caravans * 10 > want && want > 0.0) {
448 want = 0.1;
449 } else {
450 want -= unassigned_caravans * 10; /* Don't pile too many of them */
451 }
452
453 CITY_LOG(LOG_DEBUG, pcity,
454 "want for trade route unit is " ADV_WANT_PRINTF " (expected initial income %d)",
455 want,
456 income);
457
458 if (want > choice->want) {
459 /* This sets our tech want in cases where we cannot actually build
460 * the unit. */
461 unit_type = dai_wants_role_unit(ait, pplayer, pcity,
462 action_id_get_role(ACTION_TRADE_ROUTE),
463 want);
464
465 if (unit_type == NULL) {
466 unit_type = dai_wants_role_unit(ait, pplayer, pcity,
467 action_id_get_role(ACTION_MARKETPLACE),
468 want);
469 }
470
471 /* We don't want to build caravan that wouldn't be able to reach the
472 * destination by any means. It would be useless. */
473 if (unit_type != NULL && (!need_boat || has_boats)) {
474 choice->want = want;
475 choice->type = CT_CIVILIAN;
476 choice->value.utype = unit_type;
477 choice->need_boat = need_boat;
478 } else {
479 CITY_LOG(LOG_DEBUG, pcity,
480 "would but could not build trade route unit, bumped reqs");
481 }
482 }
483}
484
485/***********************************************************************/
490 struct adv_choice *domestic_advisor_choose_build(struct ai_type *ait,
491 struct player *pplayer,
492 struct city *pcity)
493{
494 struct adv_data *adv = adv_data_get(pplayer, NULL);
495 /* Unit type with certain role */
496 struct unit_type *worker_type;
497 struct unit_type *founder_type;
498 adv_want worker_want, founder_want;
499 struct ai_city *city_data = def_ai_city_data(pcity, ait);
500 struct adv_choice *choice = adv_new_choice();
501
502 /* Find out desire for workers (terrain improvers) */
503 worker_type = city_data->worker_type;
504
505 /* The worker want is calculated in daicity.c called from
506 * dai_manage_cities(). The expand value is the % that the AI should
507 * value expansion (basically to handicap easier difficulty levels)
508 * and is set when the difficulty level is changed (difficulty.c). */
509 worker_want = city_data->worker_want * pplayer->ai_common.expand / 100;
510
511 if (adv->wonder_city == pcity->id) {
512 if (worker_type == NULL || worker_type->pop_cost > 0) {
513 worker_want /= 5;
514 } else {
515 worker_want /= 2;
516 }
517 }
518
519 if (worker_type != NULL
520 && pcity->surplus[O_FOOD] > utype_upkeep_cost(worker_type,
521 pplayer, O_FOOD)) {
522 if (worker_want > 0) {
523 CITY_LOG(LOG_DEBUG, pcity,
524 "desires terrain improvers with passion " ADV_WANT_PRINTF,
525 worker_want);
526 dai_choose_role_unit(ait, pplayer, pcity, choice, CT_CIVILIAN,
527 UTYF_SETTLERS, worker_want, FALSE);
528 adv_choice_set_use(choice, "worker");
529 }
530 /* Terrain improvers don't use boats (yet) */
531
532 } else if (worker_type == NULL && worker_want > 0) {
533 /* Can't build workers. Lets stimulate science */
534 dai_wants_role_unit(ait, pplayer, pcity, UTYF_SETTLERS, worker_want);
535 }
536
537 /* Find out desire for city founders */
538 /* Basically, copied from above and adjusted. -- jjm */
539 if (!game.scenario.prevent_new_cities) {
540 founder_type = best_role_unit(pcity,
541 action_id_get_role(ACTION_FOUND_CITY));
542
543 /* founder_want calculated in daisettlers.c */
544 founder_want = city_data->founder_want;
545
546 if (adv->wonder_city == pcity->id) {
547 if (founder_type == NULL || founder_type->pop_cost > 0) {
548 founder_want /= 5;
549 } else {
550 founder_want /= 2;
551 }
552 }
553
554 if (adv->max_num_cities <= city_list_size(pplayer->cities)) {
555 founder_want /= 100;
556 }
557
558 /* Adjust founder want by traits */
559 founder_want *= (double)ai_trait_get_value(TRAIT_EXPANSIONIST, pplayer)
560 / TRAIT_DEFAULT_VALUE;
561
562 if (founder_type
563 && pcity->surplus[O_FOOD] >= utype_upkeep_cost(founder_type,
564 pplayer, O_FOOD)) {
565
566 if (founder_want > choice->want) {
567 CITY_LOG(LOG_DEBUG, pcity,
568 "desires founders with passion " ADV_WANT_PRINTF,
569 founder_want);
570 dai_choose_role_unit(ait, pplayer, pcity, choice, CT_CIVILIAN,
571 action_id_get_role(ACTION_FOUND_CITY),
572 founder_want,
573 city_data->founder_boat);
574 adv_choice_set_use(choice, "founder");
575
576 } else if (founder_want < -choice->want) {
577 /* We need boats to colonize! */
578 /* We might need boats even if there are boats free,
579 * if they are blockaded or in inland seas. */
580 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, NULL);
581
582 CITY_LOG(LOG_DEBUG, pcity,
583 "desires founders with passion " ADV_WANT_PRINTF
584 " and asks for a new boat (%d of %d free)",
585 -founder_want, ai->stats.available_boats, ai->stats.boats);
586
587 /* First fill choice with founder information */
588 choice->want = 0 - founder_want;
589 choice->type = CT_CIVILIAN;
590 choice->value.utype = founder_type; /* Default */
591 choice->need_boat = TRUE;
592
593 /* Then try to overwrite it with ferryboat information
594 * If no ferryboat is found, above founder choice stays. */
595 dai_choose_role_unit(ait, pplayer, pcity, choice, CT_CIVILIAN,
596 L_FERRYBOAT, -founder_want, TRUE);
597 adv_choice_set_use(choice, "founder's boat");
598 }
599 } else if (!founder_type
600 && (founder_want > choice->want || founder_want < -choice->want)) {
601 /* Can't build founders. Lets stimulate science */
602 dai_wants_role_unit(ait, pplayer, pcity,
603 action_id_get_role(ACTION_FOUND_CITY),
604 founder_want);
605 }
606 }
607
608 {
609 struct adv_choice *cur;
610
611 /* Consider building caravan-type units to aid wonder construction */
612 cur = adv_new_choice();
613 adv_choice_set_use(cur, "wonder");
614 dai_choose_help_wonder(ait, pcity, cur, adv);
615 choice = adv_better_choice_free(choice, cur);
616
617 /* Consider city improvements */
618 cur = adv_new_choice();
619 adv_choice_set_use(cur, "improvement");
620 building_advisor_choose(pcity, cur);
621 cur->want = cur->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER, pplayer)
622 / TRAIT_DEFAULT_VALUE / 2));
623 choice = adv_better_choice_free(choice, cur);
624
625 /* Consider building caravan-type units for trade route */
626 cur = adv_new_choice();
627 adv_choice_set_use(cur, "trade route");
628 dai_choose_trade_route(ait, pcity, cur, adv);
629 choice = adv_better_choice_free(choice, cur);
630 }
631
632 if (choice->want > DAI_WANT_DOMESTIC_MAX) {
633 /* If we don't do following, we buy caravans in city X when we should be
634 * saving money to buy defenses for city Y. -- Syela */
635 choice->want = DAI_WANT_DOMESTIC_MAX;
636 }
637
638 return choice;
639}
640
641/***********************************************************************/
644 void dai_wonder_city_distance(struct ai_type *ait, struct player *pplayer,
645 struct adv_data *adv)
646{
647 struct pf_map *pfm;
648 struct pf_parameter parameter;
649 struct unit_type *punittype;
650 struct unit *ghost;
651 int maxrange;
652 struct city *wonder_city = game_city_by_number(adv->wonder_city);
653 const struct civ_map *nmap = &(wld.map);
654
655 city_list_iterate(pplayer->cities, acity) {
656 /* Mark unavailable */
657 def_ai_city_data(acity, ait)->distance_to_wonder_city = 0;
658 } city_list_iterate_end;
659
660 if (wonder_city == NULL) {
661 return;
662 }
663
664 punittype = best_role_unit_for_player(pplayer,
665 action_id_get_role(ACTION_HELP_WONDER));
666
667 if (!punittype) {
668 return;
669 }
670
671 fc_assert_msg(utype_can_do_action(punittype, ACTION_HELP_WONDER),
672 "Non existence of wonder helper unit not caught");
673
674 ghost = unit_virtual_create(pplayer, wonder_city, punittype, 0);
675 maxrange = unit_move_rate(ghost) * 7;
676
677 pft_fill_unit_parameter(&parameter, nmap, ghost);
678 parameter.omniscience = !has_handicap(pplayer, H_MAP);
679 pfm = pf_map_new(&parameter);
680
681 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
682 struct city *acity = tile_city(ptile);
683
684 if (move_cost > maxrange) {
685 break;
686 }
687 if (!acity) {
688 continue;
689 }
690 if (city_owner(acity) == pplayer) {
691 def_ai_city_data(acity, ait)->distance_to_wonder_city = move_cost;
692 }
693 } pf_map_move_costs_iterate_end;
694
695 pf_map_destroy(pfm);
696 unit_virtual_destroy(ghost);
697}
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
action_id_get_role
#define action_id_get_role(act_id)
Definition actions.h:708
building_advisor_choose
void building_advisor_choose(struct city *pcity, struct adv_choice *choice)
Definition advbuilding.c:278
advbuilding.h
SHIELD_WEIGHTING
#define SHIELD_WEIGHTING
Definition advbuilding.h:20
adv_better_choice_free
struct adv_choice * adv_better_choice_free(struct adv_choice *first, struct adv_choice *second)
Definition advchoice.c:98
adv_new_choice
struct adv_choice * adv_new_choice(void)
Definition advchoice.c:59
advchoice.h
adv_choice_set_use
#define adv_choice_set_use(_choice, _use)
Definition advchoice.h:85
CT_CIVILIAN
@ CT_CIVILIAN
Definition advchoice.h:39
adv_data_get
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:593
advdata.h
dai_plr_data_get
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition aidata.c:308
aidata.h
ailog.h
aiplayer.h
def_ai_city_data
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition aiplayer.h:42
dai_wants_role_unit
struct unit_type * dai_wants_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, int role, int want)
Definition aitech.c:512
aitech.h
dai_choose_role_unit
bool dai_choose_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, enum choice_type type, int role, int want, bool need_boat)
Definition aitools.c:1326
aitools.h
DAI_WANT_DOMESTIC_MAX
#define DAI_WANT_DOMESTIC_MAX
Definition aitools.h:33
ai_trait_get_value
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:68
aitraits.h
aiunit.h
autosettlers.h
city_production_gets_caravan_shields
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1825
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1106
city.h
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:488
city_tile
#define city_tile(_pcity_)
Definition city.h:544
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:490
build_points_left
int build_points_left(struct city *pcity)
Definition citytools.c:569
citytools.h
daicity.h
dai_wonder_city_distance
void dai_wonder_city_distance(struct ai_type *ait, struct player *pplayer, struct adv_data *adv)
Definition daidomestic.c:644
domestic_advisor_choose_build
struct adv_choice * domestic_advisor_choose_build(struct ai_type *ait, struct player *pplayer, struct city *pcity)
Definition daidomestic.c:490
dai_choose_trade_route
static void dai_choose_trade_route(struct ai_type *ait, struct city *pcity, struct adv_choice *choice, struct adv_data *ai)
Definition daidomestic.c:175
dai_choose_help_wonder
static void dai_choose_help_wonder(struct ai_type *ait, struct city *pcity, struct adv_choice *choice, struct adv_data *ai)
Definition daidomestic.c:74
daidomestic.h
daimilitary.h
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:73
get_target_bonus_effects
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:691
adv_want
float adv_want
Definition fc_types.h:1206
ADV_WANT_PRINTF
#define ADV_WANT_PRINTF
Definition fc_types.h:1207
O_FOOD
@ O_FOOD
Definition fc_types.h:91
O_TRADE
@ O_TRADE
Definition fc_types.h:91
Continent_id
signed short Continent_id
Definition fc_types.h:342
game
struct civ_game game
Definition game.c:57
wld
struct world wld
Definition game.c:58
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:102
game.h
government.h
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps.h
H_MAP
@ H_MAP
Definition handicaps.h:28
improvement_index
Impr_type_id improvement_index(const struct impr_type *pimprove)
Definition improvement.c:173
is_wonder
bool is_wonder(const struct impr_type *pimprove)
Definition improvement.c:341
infracache.h
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
LOG_DEBUG
@ LOG_DEBUG
Definition log.h:34
map.h
mem.h
unit_move_rate
int unit_move_rate(const struct unit *punit)
Definition movement.c:90
movement.h
pf_map_new
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
Definition path_finding.c:3182
pf_map_destroy
void pf_map_destroy(struct pf_map *pfm)
Definition path_finding.c:3206
pf_map_move_costs_iterate_end
#define pf_map_move_costs_iterate_end
Definition path_finding.h:592
pf_map_move_costs_iterate
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
Definition path_finding.h:582
pft_fill_unit_parameter
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:840
pf_tools.h
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
players_iterate_end
#define players_iterate_end
Definition player.h:535
players_iterate
#define players_iterate(_pplayer)
Definition player.h:530
MAX
#define MAX(x, y)
Definition shared.h:54
srv_log.h
CITY_LOG
#define CITY_LOG(loglevel, pcity, msg,...)
Definition srv_log.h:83
adv_choice
Definition advchoice.h:45
adv_choice::type
enum choice_type type
Definition advchoice.h:46
adv_choice::want
adv_want want
Definition advchoice.h:48
adv_choice::value
universals_u value
Definition advchoice.h:47
adv_choice::need_boat
bool need_boat
Definition advchoice.h:49
adv_city::building_want
adv_want building_want[B_LAST]
Definition infracache.h:32
adv_data
Definition advdata.h:45
adv_data::max_num_cities
int max_num_cities
Definition advdata.h:139
adv_data::wonder_city
int wonder_city
Definition advdata.h:50
adv_data::science_priority
int science_priority
Definition advdata.h:111
adv_data::gold_priority
int gold_priority
Definition advdata.h:110
ai_city
Definition daicity.h:34
ai_city::founder_boat
bool founder_boat
Definition daicity.h:64
ai_city::founder_want
int founder_want
Definition daicity.h:66
ai_city::worker_want
int worker_want
Definition daicity.h:67
ai_city::distance_to_wonder_city
int distance_to_wonder_city
Definition daicity.h:54
ai_city::worker_type
struct unit_type * worker_type
Definition daicity.h:68
ai_plr
Definition aidata.h:71
ai_plr::stats
struct ai_plr::@267 stats
ai_plr::boats
int boats
Definition aidata.h:79
ai_plr::available_boats
int available_boats
Definition aidata.h:80
ai_type
Definition ai.h:50
city
Definition city.h:309
city::surplus
int surplus[O_LAST]
Definition city.h:343
city::id
int id
Definition city.h:315
city::production
struct universal production
Definition city.h:382
city::adv
struct adv_city * adv
Definition city.h:435
city::tile
struct tile * tile
Definition city.h:311
city::server
struct city::@17::@19 server
city::units_supported
struct unit_list * units_supported
Definition city.h:391
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::scenario
struct packet_scenario_info scenario
Definition game.h:87
civ_map
Definition map_types.h:71
civ_map::xsize
int xsize
Definition map_types.h:77
civ_map::ysize
int ysize
Definition map_types.h:77
impr_type
Definition improvement.h:68
packet_game_info::trade_world_rel_pct
int trade_world_rel_pct
Definition packets_gen.h:159
packet_game_info::caravan_bonus_style
enum caravan_bonus_style caravan_bonus_style
Definition packets_gen.h:135
packet_scenario_info::prevent_new_cities
bool prevent_new_cities
Definition packets_gen.h:1611
pf_map
Definition path_finding.c:78
pf_parameter
Definition path_finding.h:357
pf_parameter::omniscience
bool omniscience
Definition path_finding.h:376
player_ai::expand
int expand
Definition player.h:124
player_economic::science
int science
Definition player.h:72
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::ai_common
struct player_ai ai_common
Definition player.h:288
player::units
struct unit_list * units
Definition player.h:282
player::is_alive
bool is_alive
Definition player.h:268
player::economic
struct player_economic economic
Definition player.h:284
req_context
Definition requirements.h:99
unit_class
Definition unittype.h:136
unit_class::sea_move
enum move_level sea_move
Definition unittype.h:150
unit_class::ferry_types
int ferry_types
Definition unittype.h:151
unit_class::adv
struct unit_class::@84 adv
unit_type
Definition unittype.h:481
unit_type::pop_cost
int pop_cost
Definition unittype.h:493
unit_type::move_rate
int move_rate
Definition unittype.h:497
unit
Definition unit.h:138
universal::kind
enum universals_n kind
Definition fc_types.h:758
universal::value
universals_u value
Definition fc_types.h:757
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
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_continent
#define tile_continent(_tile)
Definition tile.h:91
max_trade_prod
int max_trade_prod(const struct city *pcity)
Definition traderoutes.c:444
can_cities_trade
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:214
trade_route_type_trade_pct
int trade_route_type_trade_pct(enum trade_route_type type)
Definition traderoutes.c:122
city_num_trade_routes
int city_num_trade_routes(const struct city *pcity)
Definition traderoutes.c:383
max_trade_routes
unsigned max_trade_routes(const struct city *pcity)
Definition traderoutes.c:48
traderoutes.h
TRT_NATIONAL_IC
@ TRT_NATIONAL_IC
Definition traderoutes.h:39
TRT_IN_IC
@ TRT_IN_IC
Definition traderoutes.h:41
TRT_NATIONAL
@ TRT_NATIONAL
Definition traderoutes.h:38
TRT_IN
@ TRT_IN
Definition traderoutes.h:40
TRAIT_DEFAULT_VALUE
#define TRAIT_DEFAULT_VALUE
Definition traits.h:32
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:604
universals_u::building
const struct impr_type * building
Definition fc_types.h:598
unit_can_do_action
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:330
unit_virtual_create
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1613
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1709
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
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
best_role_unit
struct unit_type * best_role_unit(const struct city *pcity, int role)
Definition unittype.c:2319
utype_upkeep_cost
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
get_role_unit
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2301
utype_build_shield_cost_base
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1520
num_role_units
int num_role_units(int role)
Definition unittype.c:2251
best_role_unit_for_player
struct unit_type * best_role_unit_for_player(const struct player *pplayer, int role)
Definition unittype.c:2345
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
utype_build_shield_cost
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1490
utype_can_do_action
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:443
unittype.h
utype_class
#define utype_class(_t_)
Definition unittype.h:736
MOVE_NONE
@ MOVE_NONE
Definition unittype.h:131