Freeciv-3.2
Loading...
Searching...
No Matches
daisettler.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Team
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 <stdio.h>
19#include <string.h>
20
21/* utility */
22#include "mem.h"
23#include "log.h"
24#include "support.h"
25#include "timing.h"
26
27/* common */
28#include "city.h"
29#include "game.h"
30#include "government.h"
31#include "map.h"
32#include "movement.h"
33#include "packets.h"
34#include "player.h"
35
36/* common/aicore */
37#include "citymap.h"
38#include "pf_tools.h"
39
40/* server */
41#include "citytools.h"
42#include "maphand.h"
43#include "srv_log.h"
44#include "unithand.h"
45#include "unittools.h"
46
47/* server/advisors */
48#include "advdata.h"
49#include "advgoto.h"
50#include "advtools.h"
51#include "autosettlers.h"
52#include "infracache.h"
53
54/* ai */
55#include "handicaps.h"
56
57/* ai/default */
58#include "aiferry.h"
59#include "aitools.h"
60#include "daicity.h"
61#include "daidata.h"
62#include "dailog.h"
63#include "daiplayer.h"
64
65#include "daisettler.h"
66
67
68/* COMMENTS */
69/*
70 This code tries hard to do the right thing, including looking
71 into the future (wrt to government), and also doing this in a
72 modpack friendly manner. However, there are some pieces missing.
73
74 A tighter integration into the city management code would
75 give more optimal city placements, since existing cities could
76 move their workers around to give a new city better placement.
77 Occasionally you will see cities being placed sub-optimally
78 because the best city center tile is taken when another tile
79 could have been worked instead by the city that took it.
80
81 The code is not generic enough. It assumes smallpox too much,
82 and should calculate with a future city of a bigger size.
83
84 We need to stop the build code from running this code all the
85 time and instead try to complete what it has started.
86*/
87
88/* Stop looking too hard for better tiles to found a new city at when
89 * settler finds location with at least RESULT_IS_ENOUGH want
90 * points. See city_desirability() for how base want is computed
91 * before amortizing it.
92 *
93 * This is a big WAG to save a big amount of CPU. */
94#define RESULT_IS_ENOUGH 250
95
96#define FERRY_TECH_WANT 500
97
98#define GROWTH_PRIORITY 15
99
100/* Perfection gives us an idea of how long to search for optimal
101 * solutions, instead of going for quick and dirty solutions that
102 * waste valuable time. Decrease for maps where good city placements
103 * are hard to find. Lower means more perfection. */
104#define PERFECTION 3
105
106/* How much to deemphasise the potential for city growth for city
107 * placements. Decrease this value if large cities are important
108 * or planned. Increase if running strict smallpox. */
109#define GROWTH_POTENTIAL_DEEMPHASIS 8
110
111/* Percentage bonus to city locations near an ocean. */
112#define NAVAL_EMPHASIS 20
113
114/* Modifier for defense bonus that is applied to city location want.
115 * This is % of defense % to increase want by. */
116#define DEFENSE_EMPHASIS 20
117
119 char food; /* food output of the tile */
120 char trade; /* trade output of the tile */
121 char shield; /* shield output of the tile */
122
123 int sum; /* weighted sum of the tile output (used by AI) */
124
125 int reserved; /* reservation for this tile; used by print_citymap() */
126
127 int turn; /* the turn the values were calculated */
128};
129
130
132struct tile_data_cache *
134static void tile_data_cache_destroy(struct tile_data_cache *ptdc);
135
136/* struct tdcache_hash. */
137#define SPECHASH_TAG tile_data_cache
138#define SPECHASH_INT_KEY_TYPE
139#define SPECHASH_IDATA_TYPE struct tile_data_cache *
140#define SPECHASH_IDATA_FREE tile_data_cache_destroy
141#include "spechash.h"
142
145
146#ifdef FREECIV_DEBUG
147 struct {
148 int hit;
149 int old;
150 int miss;
151 int save;
152 } cache;
153#endif /* FREECIV_DEBUG */
154};
155
157 struct tile *tile;
158 adv_want total; /* Total value of position */
159 adv_want result; /* Amortized and adjusted total value */
161 bool overseas; /* Have to use boat to get there */
162 bool virt_boat; /* Virtual boat was used in search,
163 * so need to build one */
164
165 struct {
166 struct tile_data_cache *tdc; /* Values of city center; link to the data
167 * in tdc_hash. */
169
170 struct {
171 struct tile *tile; /* Best other tile */
172 int cindex; /* City-relative index for other tile */
173 struct tile_data_cache *tdc; /* Value of best other tile; link to the
174 * data in tdc_hash. */
176
177 adv_want remaining; /* Value of all other tiles */
178
179 /* Save the result for print_citymap(). */
181
182 int city_radius_sq; /* Current squared radius of the city */
183};
184
186
187static const struct tile_data_cache *tdc_plr_get(struct ai_type *ait,
188 struct player *plr,
189 int tindex);
190static void tdc_plr_set(struct ai_type *ait, struct player *plr, int tindex,
191 const struct tile_data_cache *tdcache);
192
193static struct cityresult *cityresult_new(struct tile *ptile);
194static void cityresult_destroy(struct cityresult *result);
195
196static struct cityresult *cityresult_fill(struct ai_type *ait,
197 struct player *pplayer,
198 struct tile *center);
199static bool food_starvation(const struct cityresult *result);
200static bool shield_starvation(const struct cityresult *result);
201static adv_want result_defense_bonus(struct player *pplayer,
202 const struct cityresult *result);
203static adv_want naval_bonus(const struct cityresult *result);
204static void print_cityresult(struct player *pplayer,
205 const struct cityresult *cr);
206struct cityresult *city_desirability(struct ai_type *ait,
207 struct player *pplayer,
208 struct unit *punit, struct tile *ptile);
209static struct cityresult *settler_map_iterate(struct ai_type *ait,
210 struct pf_parameter *parameter,
211 struct unit *punit,
212 int boat_cost);
213static struct cityresult *find_best_city_placement(struct ai_type *ait,
214 struct unit *punit,
215 bool look_for_boat,
216 bool use_virt_boat);
217static enum cb_error_level dai_do_build_city(struct ai_type *ait,
218 struct player *pplayer,
219 struct unit *punit);
220
221/*************************************************************************/
224static struct cityresult *cityresult_new(struct tile *ptile)
225{
226 struct cityresult *result;
227
228 fc_assert_ret_val(ptile != NULL, NULL);
229
230 result = fc_calloc(1, sizeof(*result));
231 result->tile = ptile;
232 result->total = 0;
233 result->result = -666;
234 result->corruption = 0;
235 result->waste = 0;
236 result->overseas = FALSE;
237 result->virt_boat = FALSE;
238
239 /* City centre */
240 result->city_center.tdc = NULL;
241
242 /* First worked tile */
243 result->best_other.tile = NULL;
244 result->best_other.tdc = NULL;
245 result->best_other.cindex = 0;
246
247 result->remaining = 0;
248 result->tdc_hash = tile_data_cache_hash_new();
249 result->city_radius_sq = game.info.init_city_radius_sq;
250
251 return result;
252}
253
254/*************************************************************************/
258{
259 if (result != NULL) {
260 if (result->tdc_hash != NULL) {
262 }
263 free(result);
264 }
265}
266
267/*************************************************************************/
275static struct cityresult *cityresult_fill(struct ai_type *ait,
276 struct player *pplayer,
277 struct tile *center)
278{
279 struct city *pcity = tile_city(center);
280 struct government *curr_govt = government_of_player(pplayer);
281 struct player *saved_owner = NULL;
282 struct tile *saved_claimer = NULL;
283 bool virtual_city = FALSE;
284 bool handicap = has_handicap(pplayer, H_MAP);
285 struct adv_data *adv = adv_data_get(pplayer, NULL);
286 struct cityresult *result;
287 const struct civ_map *nmap = &(wld.map);
288
289 fc_assert_ret_val(adv != NULL, NULL);
290 fc_assert_ret_val(center != NULL, NULL);
291
292 pplayer->government = adv->goal.govt.gov;
293
294 /* Create a city result and set default values. */
295 result = cityresult_new(center);
296
297 if (pcity == NULL) {
298 pcity = create_city_virtual(pplayer, result->tile, "Virtuaville");
299 saved_owner = tile_owner(result->tile);
301 tile_set_owner(result->tile, pplayer, result->tile); /* Temporarily */
302 city_choose_build_default(pcity); /* ?? */
304 }
305
306 result->city_radius_sq = city_map_radius_sq_get(pcity);
307
308 city_tile_iterate_index(nmap, result->city_radius_sq, result->tile, ptile,
309 cindex) {
310 int tindex = tile_index(ptile);
311 int reserved = citymap_read(ptile);
312 bool city_center = (result->tile == ptile); /* is_city_center() */
313 struct tile_data_cache *ptdc;
314
315 if (reserved < 0
316 || (handicap && !map_is_known(ptile, pplayer))
317 || tile_worked(ptile) != NULL) {
318 /* Tile is reserved or we can't see it */
320 ptdc->shield = 0;
321 ptdc->trade = 0;
322 ptdc->food = 0;
323 ptdc->sum = -1;
324 ptdc->reserved = reserved;
325 /* ptdc->turn was set by tile_data_cache_new(). */
326 } else {
327 const struct tile_data_cache *ptdc_hit = tdc_plr_get(ait, pplayer, tindex);
328
329 if (!ptdc_hit || city_center) {
330 /* We cannot read city center from cache */
332
333 /* Food */
334 ptdc->food = city_tile_output(pcity, ptile, FALSE, O_FOOD);
335 /* Shields */
336 ptdc->shield = city_tile_output(pcity, ptile, FALSE, O_SHIELD);
337 /* Trade */
338 ptdc->trade = city_tile_output(pcity, ptile, FALSE, O_TRADE);
339 /* Weighted sum */
340 ptdc->sum = ptdc->food * adv->food_priority
341 + ptdc->trade * adv->science_priority
342 + ptdc->shield * adv->shield_priority;
343 /* Balance perfection */
344 ptdc->sum *= PERFECTION / 2;
345 if (ptdc->food >= 2) {
346 ptdc->sum *= 2; /* we need this to grow */
347 }
348
349 if (!city_center && virtual_city) {
350 /* Real cities and any city center will give us possibly
351 * skewed results */
352 tdc_plr_set(ait, pplayer, tindex, tile_data_cache_copy(ptdc));
353 }
354 } else {
356 }
357 }
358
359 /* Save reservation status for debugging. */
360 ptdc->reserved = reserved;
361
362 /* Avoid crowdedness, except for city center. */
363 if (ptdc->sum > 0) {
364 ptdc->sum -= MIN(reserved * GROWTH_PRIORITY, ptdc->sum - 1);
365 }
366
367 /* Calculate city center and best other than city center */
368 if (city_center) {
369 /* Set city center. */
370 result->city_center.tdc = ptdc;
371 } else if (!result->best_other.tdc) {
372 /* Set best other tile. */
373 result->best_other.tdc = ptdc;
374 result->best_other.tile = ptile;
375 result->best_other.cindex = cindex;
376 } else if (ptdc->sum > result->best_other.tdc->sum) {
377 /* First add other other to remaining */
378 result->remaining += result->best_other.tdc->sum
380 /* Then make new best other */
381 result->best_other.tdc = ptdc;
382 result->best_other.tile = ptile;
383 result->best_other.cindex = cindex;
384 } else {
385 /* Save total remaining calculation, divided by crowdedness
386 * of the area and the emphasis placed on space for growth. */
388 }
389
392
393 /* We need a city center. */
394 if (result->city_center.tdc == NULL) {
395 fc_assert(result->city_center.tdc != NULL);
396
397 return NULL;
398 }
399
400 if (virtual_city) {
401 /* Baseline is a size one city (city center + best extra tile). */
402 result->total = result->city_center.tdc->sum
403 + (result->best_other.tdc != NULL
404 ? result->best_other.tdc->sum : 0);
405 } else if (result->best_other.tdc != NULL) {
406 /* Baseline is best extra tile only. This is why making new cities
407 * is so darn good. */
408 result->total = result->best_other.tdc->sum;
409 } else {
410 /* There is no available tile in this city. All is worked. */
411 result->total = 0;
412 return result;
413 }
414
415 /* Now we have a valid city center as well as best other tile. */
416
417 if (virtual_city) {
418 /* Corruption and waste of a size one city deducted. Notice that we
419 * don't do this if 'fulltradesize' is changed, since then we'd
420 * never make cities. */
421 int shield = result->city_center.tdc->shield
422 + result->best_other.tdc->shield;
423 result->waste = adv->shield_priority
424 * city_waste(pcity, O_SHIELD, shield, NULL);
425
426 if (game.info.fulltradesize == 1) {
427 int trade = result->city_center.tdc->trade
428 + result->best_other.tdc->trade;
429 result->corruption = adv->science_priority
430 * city_waste(pcity, O_TRADE, trade, NULL);
431 } else {
432 result->corruption = 0;
433 }
434 } else {
435 /* Deduct difference in corruption and waste for real cities. Note that it
436 * is possible (with notradesize) that we _gain_ value here. */
437 city_size_add(pcity, 1);
438 result->corruption = adv->science_priority
439 * (city_waste(pcity, O_TRADE, result->best_other.tdc->trade, NULL)
440 - pcity->waste[O_TRADE]);
441 result->waste = adv->shield_priority
442 * (city_waste(pcity, O_SHIELD, result->best_other.tdc->shield, NULL)
443 - pcity->waste[O_SHIELD]);
444 city_size_add(pcity, -1);
445 }
446 result->total -= result->corruption;
447 result->total -= result->waste;
448 result->total = MAX(0, result->total);
449
450 pplayer->government = curr_govt;
451 if (virtual_city) {
454 }
455
456 fc_assert_ret_val(result->city_center.tdc->sum >= 0, NULL);
457 fc_assert_ret_val(result->remaining >= 0, NULL);
458
459 return result;
460}
461
462/*************************************************************************/
466{
467 struct tile_data_cache *ptdc_copy = fc_calloc(1, sizeof(*ptdc_copy));
468
469 /* Set the turn the tile data cache was created. */
470 ptdc_copy->turn = game.info.turn;
471
472 return ptdc_copy;
473}
474
475/*************************************************************************/
478struct tile_data_cache *
480{
482
484
485 ptdc_copy->shield = ptdc->shield;
486 ptdc_copy->trade = ptdc->trade;
487 ptdc_copy->food = ptdc->food;
488
489 ptdc_copy->sum = ptdc->sum;
490 ptdc_copy->reserved = ptdc->reserved;
491 ptdc_copy->turn = ptdc->turn;
492
493 return ptdc_copy;
494}
495
496/*************************************************************************/
500{
501 if (ptdc != NULL) {
502 free(ptdc);
503 }
504}
505
506/*************************************************************************/
509static const struct tile_data_cache *tdc_plr_get(struct ai_type *ait,
510 struct player *plr,
511 int tindex)
512{
513 struct ai_plr *ai = dai_plr_data_get(ait, plr, NULL);
514
518
519 struct tile_data_cache *ptdc;
520
522
523 if (!ptdc) {
524#ifdef FREECIV_DEBUG
525 ai->settler->cache.miss++;
526#endif /* FREECIV_DEBUG */
527 return NULL;
528 } else if (ptdc->turn != game.info.turn) {
529#ifdef FREECIV_DEBUG
530 ai->settler->cache.old++;
531#endif /* FREECIV_DEBUG */
532 return NULL;
533 } else {
534#ifdef FREECIV_DEBUG
535 ai->settler->cache.hit++;
536#endif /* FREECIV_DEBUG */
537 return ptdc;
538 }
539}
540
541/*************************************************************************/
544static void tdc_plr_set(struct ai_type *ait, struct player *plr, int tindex,
545 const struct tile_data_cache *ptdc)
546{
547 struct ai_plr *ai = dai_plr_data_get(ait, plr, NULL);
548
549 fc_assert_ret(ai != NULL);
550 fc_assert_ret(ai->settler != NULL);
553
554#ifdef FREECIV_DEBUG
555 ai->settler->cache.save++;
556#endif /* FREECIV_DEBUG */
557
559}
560
561/*************************************************************************/
564static bool food_starvation(const struct cityresult *result)
565{
566 /* Avoid starvation: We must have enough food to grow.
567 * Note: this does not handle the case of a newly founded city breaking
568 * even but being immediately able to build an improvement increasing its
569 * yield (such as supermarkets and harbors in the classic ruleset).
570 * /MSS */
571 return (result->city_center.tdc->food
572 + (result->best_other.tdc ? result->best_other.tdc->food
573 : 0) <= game.info.food_cost);
574}
575
576/*************************************************************************/
579static bool shield_starvation(const struct cityresult *result)
580{
581 /* Avoid resource starvation. */
582 return (result->city_center.tdc->shield
583 + (result->best_other.tdc ? result->best_other.tdc->shield
584 : 0) == 0);
585}
586
587/*************************************************************************/
591static adv_want result_defense_bonus(struct player *pplayer,
592 const struct cityresult *result)
593{
594 /* Defense modification (as tie breaker mostly) */
595 int defense_bonus
596 = 10 + tile_terrain(result->tile)->defense_bonus / 10;
597 int extra_bonus = 0;
598 struct tile *vtile = tile_virtual_new(result->tile);
599 struct city *vcity = create_city_virtual(pplayer, vtile, "");
600
601 tile_set_worked(vtile, vcity); /* Link tile_city(vtile) to vcity. */
602 upgrade_city_extras(vcity, NULL); /* Give city free extras. */
603 extra_type_iterate(pextra) {
604 if (tile_has_extra(vtile, pextra)) {
605 /* TODO: Do not use full bonus of those road types
606 * that are not native to all important units. */
607 extra_bonus += pextra->defense_bonus;
608 }
611
612 defense_bonus += (defense_bonus * extra_bonus) / 100;
613
614 return 100 / (result->total + 1) * (100 / defense_bonus * DEFENSE_EMPHASIS);
615}
616
617/*************************************************************************/
620static adv_want naval_bonus(const struct cityresult *result)
621{
623 result->tile, TC_OCEAN);
624
625 /* Adjust for ocean adjacency, which is nice */
626 if (ocean_adjacent) {
627 return (result->total * NAVAL_EMPHASIS) / 100;
628 } else {
629 return 0;
630 }
631}
632
633/*************************************************************************/
636static void print_cityresult(struct player *pplayer,
637 const struct cityresult *cr)
638{
640 int tiles = city_map_tiles(cr->city_radius_sq);
641 struct tile_data_cache *ptdc;
642
644 fc_assert_ret(tiles > 0);
645
647 city_map_food = fc_calloc(tiles, sizeof(*city_map_food));
648 city_map_shield = fc_calloc(tiles, sizeof(*city_map_shield));
649 city_map_trade = fc_calloc(tiles, sizeof(*city_map_trade));
650
651 city_map_iterate(cr->city_radius_sq, cindex, x, y) {
654 city_map_reserved[cindex] = ptdc->reserved;
655 city_map_food[cindex] = ptdc->reserved;
656 city_map_shield[cindex] = ptdc->reserved;
657 city_map_trade[cindex] = ptdc->reserved;
659
660 /* Print reservations */
661 log_test("cityresult for (x, y, radius_sq) = (%d, %d, %d) - Reservations:",
662 TILE_XY(cr->tile), cr->city_radius_sq);
664
665 /* Print food */
666 log_test("cityresult for (x, y, radius_sq) = (%d, %d, %d) - Food:",
667 TILE_XY(cr->tile), cr->city_radius_sq);
669
670 /* Print shield */
671 log_test("cityresult for (x, y, radius_sq) = (%d, %d, %d) - Shield:",
672 TILE_XY(cr->tile), cr->city_radius_sq);
674
675 /* Print trade */
676 log_test("cityresult for (x, y, radius_sq) = (%d, %d, %d) - Trade:",
677 TILE_XY(cr->tile), cr->city_radius_sq);
679
684
685 log_test("city center (%d, %d) %d + best other (abs: %d, %d)"
686 " (cindex: %d) %d", TILE_XY(cr->tile),
689 log_test("- corr %d - waste %d + remaining " ADV_WANT_PRINTF
690 " + defense bonus " ADV_WANT_PRINTF " + naval bonus " ADV_WANT_PRINTF,
691 cr->corruption, cr->waste, cr->remaining,
692 result_defense_bonus(pplayer, cr), naval_bonus(cr));
693 log_test("= " ADV_WANT_PRINTF " (" ADV_WANT_PRINTF ")", cr->total, cr->result);
694
695 if (food_starvation(cr)) {
696 log_test(" ** FOOD STARVATION **");
697 }
698 if (shield_starvation(cr)) {
699 log_test(" ** RESOURCE STARVATION **");
700 }
701}
702
703/*************************************************************************/
708struct cityresult *city_desirability(struct ai_type *ait, struct player *pplayer,
709 struct unit *punit, struct tile *ptile)
710{
711 struct city *pcity = tile_city(ptile);
712 struct cityresult *cr = NULL;
713
715 fc_assert_ret_val(pplayer, NULL);
716
718 || (has_handicap(pplayer, H_MAP)
719 && !map_is_known(ptile, pplayer))) {
720 return NULL;
721 }
722
723 /* Check if another settler has taken a spot within mindist */
726 return NULL;
727 }
729
730 if (adv_danger_at(punit, ptile)) {
731 return NULL;
732 }
733
734 if (pcity && (city_size_get(pcity) + unit_pop_value(punit)
736 /* Can't exceed population limit. */
737 return NULL;
738 }
739
740 if (!pcity && citymap_is_reserved(ptile)) {
741 return NULL; /* reserved, go away */
742 }
743
744 /* If (x, y) is an existing city, consider immigration */
745 if (pcity && city_owner(pcity) == pplayer) {
746 return NULL;
747 }
748
749 cr = cityresult_fill(ait, pplayer, ptile); /* Burn CPU, burn! */
750 if (!cr) {
751 /* Failed to find a good spot */
752 return NULL;
753 }
754
755 /*** Alright: Now consider building a new city ***/
756
757 if (food_starvation(cr) || shield_starvation(cr)) {
759 return NULL;
760 }
761
762 cr->total += result_defense_bonus(pplayer, cr);
763 cr->total += naval_bonus(cr);
764
765 /* Add remaining points, which is our potential */
766 cr->total += cr->remaining;
767
768 fc_assert_ret_val(cr->total >= 0, NULL); /* Does not free cr! */
769
770 return cr;
771}
772
773/*************************************************************************/
784static struct cityresult *settler_map_iterate(struct ai_type *ait,
785 struct pf_parameter *parameter,
786 struct unit *punit,
787 int boat_cost)
788{
789 struct cityresult *cr = NULL, *best = NULL;
790 int best_turn = 0; /* Which turn we found the best fit */
791 struct player *pplayer = unit_owner(punit);
792 struct pf_map *pfm;
796
797 pfm = pf_map_new(parameter);
798 pf_map_move_costs_iterate(pfm, ptile, move_cost, FALSE) {
799 int turns;
800
801 if (boat_cost == 0 && pclass->adv.sea_move == MOVE_NONE
802 && tile_continent(ptile) != curcont) {
803 /* We have an accidential land bridge. Ignore it. It will in all
804 * likelihood go away next turn, or even in a few nanoseconds. */
805 continue;
806 }
808 struct player *powner = tile_owner(ptile);
809
810 if (NULL != powner
811 && powner != pplayer
812 && pplayers_in_peace(powner, pplayer)) {
813 /* Land theft does not make for good neighbors. */
814 continue;
815 }
816 }
817
818 /* Calculate worth */
819 cr = city_desirability(ait, pplayer, punit, ptile);
820
821 /* Check if actually found something */
822 if (cr == NULL) {
823 continue;
824 }
825
826 /* This algorithm punishes long treks */
827 turns = move_cost / parameter->move_rate;
828 cr->result = amortize(cr->total, PERFECTION * turns);
829
830 /* Reduce want by settler cost. Easier than amortize, but still
831 * weeds out very small wants. ie we create a threshold here. */
832 /* We also penalise here for using a boat (either virtual or real)
833 * it's crude but what isn't?
834 * Settler gets used, boat can make multiple trips. */
835 cr->result -= cost + boat_cost / 3;
836
837 /* Find best spot */
838 if ((!best && cr->result > 0)
839 || (best && cr->result > best->result)) {
840 /* Destroy the old 'best' value. */
841 cityresult_destroy(best);
842 /* Save the new 'best' value. */
843 best = cr;
844 cr = NULL;
845 best_turn = turns;
846
847 log_debug("settler map search (search): (%d, %d) " ADV_WANT_PRINTF,
848 TILE_XY(best->tile), best->result);
849 } else {
850 /* Destroy the unused result. */
852 cr = NULL;
853 }
854
855 /* Can we terminate early? We have a 'good enough' spot, and
856 * we don't block the establishment of a better city just one
857 * further step away. */
858 if (best && best->result > RESULT_IS_ENOUGH
859 && turns > parameter->move_rate /* sic -- yeah what an explanation! */
860 && best_turn < turns /*+ game.info.min_dist_bw_cities*/) {
861 break;
862 }
864
866
867 if (best) {
868 log_debug("settler map search (final): (%d, %d) " ADV_WANT_PRINTF,
869 TILE_XY(best->tile), best->result);
870 } else {
871 log_debug("settler map search (final): no result");
872 }
873
874 return best;
875}
876
877/*************************************************************************/
890static struct cityresult *find_best_city_placement(struct ai_type *ait,
891 struct unit *punit,
892 bool look_for_boat,
893 bool use_virt_boat)
894{
895 struct pf_parameter parameter;
896 struct player *pplayer = unit_owner(punit);
897 struct unit *ferry = NULL;
898 struct cityresult *cr1 = NULL, *cr2 = NULL;
899 const struct civ_map *nmap = &(wld.map);
900
901 fc_assert_ret_val(is_ai(pplayer), NULL);
902 /* Only virtual units may use virtual boats: */
904
905 /* Phase 1: Consider building cities on our continent */
906
907 pft_fill_unit_parameter(&parameter, nmap, punit);
908 parameter.omniscience = !has_handicap(pplayer, H_MAP);
909 cr1 = settler_map_iterate(ait, &parameter, punit, 0);
910
911 if (cr1 && cr1->result > RESULT_IS_ENOUGH) {
912 /* skip further searches */
913 return cr1;
914 }
915
916 /* Phase 2: Consider travelling to another continent */
917
918 if (look_for_boat) {
919 int ferry_id = aiferry_find_boat(ait, punit, 1, NULL);
920
922 }
923
924 if (ferry || (use_virt_boat
927 && tile_city(unit_tile(punit)))) {
928 if (!ferry) {
929 /* No boat? Get a virtual one! */
930 struct unit_type *boattype
932
933 if (boattype == NULL) {
934 /* Sea travel not possible yet. Bump tech want for ferries. */
936
937 if (NULL != boattype) {
938 struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
939
941 plr_data->tech_want[advance_index(padv)]
943 TECH_LOG(ait, LOG_DEBUG, pplayer, padv,
944 "+ %d for %s to ferry settler",
948 }
949
950 /* Return the result from the search on our current continent */
951 return cr1;
952 }
953 ferry = unit_virtual_create(pplayer, NULL, boattype, 0);
955 }
956
957 fc_assert(dai_is_ferry(ferry, ait));
958 pft_fill_unit_overlap_param(&parameter, nmap, ferry);
959 parameter.omniscience = !has_handicap(pplayer, H_MAP);
960 parameter.get_TB = no_fights_or_unknown;
961
962 /* FIXME: Maybe penalty for using an existing boat is too high?
963 * We shouldn't make the penalty for building a new boat too high though.
964 * Building a new boat is like a war against a weaker enemy --
965 * good for the economy. (c) Bush family */
966 cr2 = settler_map_iterate(ait, &parameter, punit,
968 if (cr2) {
969 cr2->overseas = TRUE;
970 cr2->virt_boat = (ferry->id == 0);
971 }
972
973 if (ferry->id == 0) {
975 }
976
977 /* If we use a virtual boat, we must have permission and be emigrating: */
978 /* FIXME: These assert do not free cr2! */
979 fc_assert_ret_val(!cr2 || (!cr2->virt_boat || use_virt_boat), NULL);
980 fc_assert_ret_val(!cr2 || (!cr2->virt_boat || cr2->overseas), NULL);
981 }
982
983 if (!cr1) {
984 /* No want for a new city on our current continent; return the result for
985 * traveling by boat. */
986 return cr2;
987 } else if (!cr2) {
988 /* No want for an overseas city; return the result for a city on our
989 * current continent. */
990 return cr1;
991 }
992
993 /* We want an overseas city and a city on the current continent - select the
994 * best! */
995 if (cr1->result > cr2->result) {
997 return cr1;
998 } else {
1000 return cr2;
1001 }
1002}
1003
1004/*************************************************************************/
1008{
1009 fc_assert_ret(ai != NULL);
1010 fc_assert_ret(ai->settler == NULL);
1011
1012 ai->settler = fc_calloc(1, sizeof(*ai->settler));
1014
1015#ifdef FREECIV_DEBUG
1016 ai->settler->cache.hit = 0;
1017 ai->settler->cache.old = 0;
1018 ai->settler->cache.miss = 0;
1019 ai->settler->cache.save = 0;
1020#endif /* FREECIV_DEBUG */
1021}
1022
1023/*************************************************************************/
1026void dai_auto_settler_run(struct ai_type *ait, const struct civ_map *nmap,
1027 struct player *pplayer,
1028 struct unit *punit, struct settlermap *state)
1029{
1030 adv_want best_impr = 0; /* Value of best terrain improvement we can do */
1032 struct extra_type *best_target;
1033 struct tile *best_tile = NULL;
1034 struct pf_path *path = NULL;
1035 struct city *pcity = NULL;
1036
1037 /* Time it will take worker to complete its given task */
1038 int completion_time = 0;
1039
1041
1042 /*** If we are on a city mission: Go where we should ***/
1043
1045
1046 if (def_ai_unit_data(punit, ait)->task == AIUNIT_BUILD_CITY) {
1047 struct tile *ptile = punit->goto_tile;
1048 int sanity = punit->id;
1049
1050 /* Check that the mission is still possible. If the tile has become
1051 * unavailable, call it off. */
1052 if (!city_can_be_built_here(ptile, punit, FALSE)) {
1056
1057 return; /* Avoid recursion at all cost */
1058 } else {
1059 /* Go there */
1060 if ((!dai_gothere(ait, pplayer, punit, ptile)
1062 || punit->moves_left <= 0) {
1063 return;
1064 }
1065 if (same_pos(unit_tile(punit), ptile)) {
1066 enum cb_error_level elevel = dai_do_build_city(ait, pplayer, punit);
1067
1068 if (elevel != CBE_OK) {
1069 UNIT_LOG(LOG_DEBUG, punit, "could not make city on %s",
1072
1073 if (elevel == CBE_RECOVERABLE) {
1074 /* Only known way to end in here is that hut turned in to a city
1075 * when settler entered tile. So this is not going to lead in any
1076 * serious recursion. */
1077 dai_auto_settler_run(ait, nmap, pplayer, punit, state);
1078 }
1079
1080 return;
1081 } else {
1082 return; /* We came, we saw, we built... */
1083 }
1084 } else {
1085 UNIT_LOG(LOG_DEBUG, punit, "could not go to target");
1086 /* dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL); */
1087 return;
1088 }
1089 }
1090 }
1091
1092 /*** Try find some work ***/
1093
1095 struct worker_task *best_task;
1096
1098
1099 /* Have nearby cities requests? */
1100 pcity = settler_evaluate_city_requests(punit, &best_task, &path, state);
1101
1102 if (pcity != NULL) {
1103 if (path != NULL) {
1105 best_impr = 1;
1106 best_act = best_task->act;
1107 best_target = best_task->tgt;
1108 best_tile = best_task->ptile;
1109 } else {
1110 pcity = NULL;
1111 }
1112 }
1113
1114 if (pcity == NULL) {
1117 &best_tile, &path, state);
1118 if (path) {
1120 }
1121 }
1124 }
1125
1127 struct cityresult *result;
1128
1129 /* May use a boat: */
1133 if (result && result->result > best_impr) {
1134 UNIT_LOG(LOG_DEBUG, punit, "city want " ADV_WANT_PRINTF, result->result);
1135 if (tile_city(result->tile)) {
1136 UNIT_LOG(LOG_DEBUG, punit, "immigrates to %s (%d, %d)",
1138 TILE_XY(result->tile));
1139 } else {
1140 UNIT_LOG(LOG_DEBUG, punit, "makes city at (%d, %d)",
1141 TILE_XY(result->tile));
1142 if (punit->server.debug) {
1143 print_cityresult(pplayer, result);
1144 }
1145 }
1146 /* Go make a city! */
1148 if (result->best_other.tile && result->best_other.tdc->sum >= 0) {
1149 /* Reserve best other tile (if there is one). It is the tile where the
1150 * first citizen of the city is working. */
1151 citymap_reserve_tile(result->best_other.tile, punit->id);
1152 }
1153 punit->goto_tile = result->tile; /* TMP */
1154
1156
1157 /*** Go back to and found a city ***/
1158 pf_path_destroy(path);
1159 path = NULL;
1160 goto BUILD_CITY;
1161 } else if (best_impr > 0) {
1162 UNIT_LOG(LOG_DEBUG, punit, "improves terrain instead of founding");
1163 /* Terrain improvements follows the old model, and is recalculated
1164 * each turn. */
1165 if (result) {
1166 /* We had a city result, just worse than best impr */
1168 }
1170 } else {
1171 UNIT_LOG(LOG_DEBUG, punit, "cannot find work");
1172 fc_assert(result == NULL);
1174 goto CLEANUP;
1175 }
1176 } else {
1177 /* We are a worker or engineer */
1179 }
1180
1181 if (best_tile != NULL
1182 && auto_settler_setup_work(nmap, pplayer, punit, state, 0, path,
1184 completion_time)) {
1185 if (pcity != NULL) {
1186 clear_worker_tasks(pcity);
1187 }
1188 }
1189
1190CLEANUP:
1191
1192 if (NULL != path) {
1193 pf_path_destroy(path);
1194 }
1195}
1196
1197/*************************************************************************/
1200void dai_auto_settler_cont(struct ai_type *ait, const struct civ_map *nmap,
1201 struct player *pplayer,
1202 struct unit *punit, struct settlermap *state)
1203{
1204 if (!adv_settler_safe_tile(nmap, pplayer, punit,
1205 unit_tile(punit))) {
1207 }
1208}
1209
1210/*************************************************************************/
1213void dai_auto_settler_reset(struct ai_type *ait, struct player *pplayer)
1214{
1215 bool caller_closes;
1216 struct ai_plr *ai = dai_plr_data_get(ait, pplayer, &caller_closes);
1217
1218 fc_assert_ret(ai != NULL);
1219 fc_assert_ret(ai->settler != NULL);
1221
1222#ifdef FREECIV_DEBUG
1223 log_debug("[aisettler cache for %s] save: %d, miss: %d, old: %d, hit: %d",
1224 player_name(pplayer), ai->settler->cache.save,
1225 ai->settler->cache.miss, ai->settler->cache.old,
1226 ai->settler->cache.hit);
1227
1228 ai->settler->cache.hit = 0;
1229 ai->settler->cache.old = 0;
1230 ai->settler->cache.miss = 0;
1231 ai->settler->cache.save = 0;
1232#endif /* FREECIV_DEBUG */
1233
1235
1236 if (caller_closes) {
1237 dai_data_phase_finished(ait, pplayer);
1238 }
1239}
1240
1241/*************************************************************************/
1245{
1246 fc_assert_ret(ai != NULL);
1247
1248 if (ai->settler) {
1249 if (ai->settler->tdc_hash) {
1251 }
1252 free(ai->settler);
1253 }
1254 ai->settler = NULL;
1255}
1256
1257/*************************************************************************/
1261 struct player *pplayer,
1262 struct unit *punit)
1263{
1264 struct tile *ptile = unit_tile(punit);
1265 struct city *pcity;
1266
1269
1270 /* Free city reservations */
1272
1273 pcity = tile_city(ptile);
1274 if (pcity) {
1275 /* This can happen for instance when there was hut at this tile
1276 * and it turned in to a city when settler entered tile. */
1277 log_debug("%s: There is already a city at (%d, %d)!",
1278 player_name(pplayer), TILE_XY(ptile));
1279 return CBE_RECOVERABLE;
1280 }
1281 unit_do_action(pplayer, punit->id, ptile->index,
1282 0, city_name_suggestion(pplayer, ptile),
1284 pcity = tile_city(ptile);
1285 if (!pcity && punit) {
1288 ptile, NULL, NULL);
1289
1291 /* This is acceptable. A hut in the path to the tile may have created
1292 * a city that now is too close. */
1293 log_debug("%s: Failed to build city at (%d, %d)",
1294 player_name(pplayer), TILE_XY(ptile));
1295 } else {
1296 /* The request was illegal to begin with. */
1297 log_error("%s: Failed to build city at (%d, %d). Reason id: %d",
1298 player_name(pplayer), TILE_XY(ptile), reason);
1299 return CBE_FATAL;
1300 }
1301
1302 return CBE_RECOVERABLE;
1303 }
1304
1305 /* We have to rebuild at least the cache for this city. This event is
1306 * rare enough we might as well build the whole thing. Who knows what
1307 * else might be cached in the future? */
1308 fc_assert_ret_val(pplayer == city_owner(pcity), FALSE);
1310
1311 /* Init ai.choice. Handling ferryboats might use it. */
1312 adv_init_choice(&def_ai_city_data(pcity, ait)->choice);
1313
1314 return CBE_OK;
1315}
1316
1317/*************************************************************************/
1321void contemplate_new_city(struct ai_type *ait, struct city *pcity)
1322{
1323 struct unit *virtualunit;
1324 struct tile *pcenter = city_tile(pcity);
1325 struct player *pplayer = city_owner(pcity);
1326 struct unit_type *unit_type;
1327
1329 return;
1330 }
1331
1333
1334 if (unit_type == NULL) {
1335 log_debug("No ACTION_FOUND_CITY role unit available");
1336 return;
1337 }
1338
1339 /* Create a localized "virtual" unit to do operations with. */
1340 virtualunit = unit_virtual_create(pplayer, pcity, unit_type, 0);
1342
1343 if (is_ai(pplayer)) {
1344 struct cityresult *result;
1346 struct ai_city *city_data = def_ai_city_data(pcity, ait);
1347
1349
1350 if (result) {
1351 fc_assert_ret(0 <= result->result); /* 'result' is not freed! */
1352
1353 CITY_LOG(LOG_DEBUG, pcity, "want(" ADV_WANT_PRINTF ") to establish city at"
1354 " (%d, %d) and will %s to get there", result->result,
1355 TILE_XY(result->tile),
1356 (result->virt_boat ? "build a boat" :
1357 (result->overseas ? "use a boat" : "walk")));
1358
1359 city_data->founder_want = (result->virt_boat ?
1360 -result->result : result->result);
1361 city_data->founder_boat = result->overseas;
1362
1363 cityresult_destroy(result);
1364 } else {
1365 CITY_LOG(LOG_DEBUG, pcity, "want no city");
1366 city_data->founder_want = 0;
1367 }
1368 } else {
1369 /* Always failing */
1370 fc_assert_ret(is_ai(pplayer));
1371 }
1372
1374}
#define action_id_get_role(act_id)
Definition actions.h:694
void adv_init_choice(struct adv_choice *choice)
Definition advchoice.c:31
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:605
bool adv_danger_at(struct unit *punit, struct tile *ptile)
Definition advgoto.c:420
adv_want amortize(adv_want benefit, int delay)
Definition advtools.c:29
int aiferry_find_boat(struct ai_type *ait, struct unit *punit, int cap, struct pf_path **path)
Definition aiferry.c:495
bool dai_is_ferry(struct unit *pferry, struct ai_type *ait)
Definition aiferry.c:159
void dai_unit_new_task(struct ai_type *ait, struct unit *punit, enum ai_unit_task task, struct tile *ptile)
Definition aitools.c:642
bool dai_gothere(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile)
Definition aitools.c:243
void adv_unit_new_task(struct unit *punit, enum adv_unit_task task, struct tile *ptile)
bool auto_settler_setup_work(const struct civ_map *nmap, struct player *pplayer, struct unit *punit, struct settlermap *state, int recursion, struct pf_path *path, struct tile *best_tile, enum unit_activity best_act, struct extra_type **best_target, int completion_time)
struct city * settler_evaluate_city_requests(struct unit *punit, struct worker_task **best_task, struct pf_path **path, struct settlermap *state)
adv_want settler_evaluate_improvements(const struct civ_map *nmap, struct unit *punit, enum unit_activity *best_act, struct extra_type **best_target, struct tile **best_tile, struct pf_path **path, struct settlermap *state)
bool adv_settler_safe_tile(const struct civ_map *nmap, const struct player *pplayer, struct unit *punit, struct tile *ptile)
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3216
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
bool city_can_be_built_here(const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1478
void city_size_add(struct city *pcity, int add)
Definition city.c:1155
void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
Definition city.c:410
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3418
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:136
void destroy_city_virtual(struct city *pcity)
Definition city.c:3504
void city_choose_build_default(struct city *pcity)
Definition city.c:1078
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1274
int city_map_tiles(int city_radius_sq)
Definition city.c:170
#define city_tile(_pcity_)
Definition city.h:564
#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, _index)
Definition city.h:201
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define city_tile_iterate_index_end
Definition city.h:209
#define city_owner(_pcity_)
Definition city.h:563
#define city_map_iterate_end
Definition city.h:177
#define city_map_iterate(_radius_sq, _index, _x, _y)
Definition city.h:173
void citymap_reserve_tile(struct tile *ptile, int id)
Definition citymap.c:167
bool citymap_is_reserved(struct tile *ptile)
Definition citymap.c:190
int citymap_read(struct tile *ptile)
Definition citymap.c:181
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Definition citytools.c:453
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3576
char * incite_cost
Definition comments.c:74
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition daidata.c:308
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:285
#define TECH_LOG(ait, loglevel, pplayer, padvance, msg,...)
Definition dailog.h:36
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition daiplayer.h:42
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition daiplayer.h:48
#define PERFECTION
Definition daisettler.c:104
#define GROWTH_PRIORITY
Definition daisettler.c:98
static adv_want result_defense_bonus(struct player *pplayer, const struct cityresult *result)
Definition daisettler.c:591
static void tdc_plr_set(struct ai_type *ait, struct player *plr, int tindex, const struct tile_data_cache *tdcache)
Definition daisettler.c:544
cb_error_level
Definition daisettler.c:185
@ CBE_OK
Definition daisettler.c:185
@ CBE_FATAL
Definition daisettler.c:185
@ CBE_RECOVERABLE
Definition daisettler.c:185
static struct cityresult * cityresult_new(struct tile *ptile)
Definition daisettler.c:224
static bool food_starvation(const struct cityresult *result)
Definition daisettler.c:564
static struct cityresult * cityresult_fill(struct ai_type *ait, struct player *pplayer, struct tile *center)
Definition daisettler.c:275
#define RESULT_IS_ENOUGH
Definition daisettler.c:94
#define GROWTH_POTENTIAL_DEEMPHASIS
Definition daisettler.c:109
static void print_cityresult(struct player *pplayer, const struct cityresult *cr)
Definition daisettler.c:636
static adv_want naval_bonus(const struct cityresult *result)
Definition daisettler.c:620
#define DEFENSE_EMPHASIS
Definition daisettler.c:116
void dai_auto_settler_init(struct ai_plr *ai)
#define NAVAL_EMPHASIS
Definition daisettler.c:112
struct tile_data_cache * tile_data_cache_copy(const struct tile_data_cache *ptdc)
Definition daisettler.c:479
void dai_auto_settler_cont(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct unit *punit, struct settlermap *state)
static bool shield_starvation(const struct cityresult *result)
Definition daisettler.c:579
static struct cityresult * settler_map_iterate(struct ai_type *ait, struct pf_parameter *parameter, struct unit *punit, int boat_cost)
Definition daisettler.c:784
void dai_auto_settler_free(struct ai_plr *ai)
#define FERRY_TECH_WANT
Definition daisettler.c:96
static enum cb_error_level dai_do_build_city(struct ai_type *ait, struct player *pplayer, struct unit *punit)
static void cityresult_destroy(struct cityresult *result)
Definition daisettler.c:257
void dai_auto_settler_reset(struct ai_type *ait, struct player *pplayer)
struct cityresult * city_desirability(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *ptile)
Definition daisettler.c:708
static const struct tile_data_cache * tdc_plr_get(struct ai_type *ait, struct player *plr, int tindex)
Definition daisettler.c:509
void contemplate_new_city(struct ai_type *ait, struct city *pcity)
static struct cityresult * find_best_city_placement(struct ai_type *ait, struct unit *punit, bool look_for_boat, bool use_virt_boat)
Definition daisettler.c:890
void dai_auto_settler_run(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct unit *punit, struct settlermap *state)
static void tile_data_cache_destroy(struct tile_data_cache *ptdc)
Definition daisettler.c:499
struct tile_data_cache * tile_data_cache_new(void)
Definition daisettler.c:465
@ AIUNIT_BUILD_CITY
Definition daiunit.h:27
@ AIUNIT_NONE
Definition daiunit.h:27
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
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 int cost
Definition dialogs_g.h:74
ane_kind
Definition explanation.h:22
@ ANEK_CITY_TOO_CLOSE_TGT
Definition explanation.h:83
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
float adv_want
Definition fc_types.h:1355
@ AUT_BUILD_CITY
Definition fc_types.h:373
@ AUT_AUTO_SETTLER
Definition fc_types.h:373
#define ADV_WANT_PRINTF
Definition fc_types.h:1356
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
signed short Continent_id
Definition fc_types.h:375
@ BORDERS_DISABLED
Definition fc_types.h:1038
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:116
struct government * government_of_player(const struct player *pplayer)
Definition government.c:114
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
@ H_MAP
Definition handicaps.h:28
void initialize_infrastructure_cache(struct player *pplayer)
Definition infracache.c:250
#define fc_assert_ret(condition)
Definition log.h:191
#define log_test
Definition log.h:136
#define fc_assert(condition)
Definition log.h:176
#define LOG_TEST
Definition log.h:139
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_debug(message,...)
Definition log.h:115
@ LOG_DEBUG
Definition log.h:34
#define log_error(message,...)
Definition log.h:103
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:940
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:391
#define square_iterate_end
Definition map.h:394
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:894
bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
Definition maphand.c:241
#define fc_calloc(n, esz)
Definition mem.h:38
const struct pf_position * pf_path_last_position(const struct pf_path *path)
void pf_path_destroy(struct pf_path *path)
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
void pf_map_destroy(struct pf_map *pfm)
#define pf_map_move_costs_iterate_end
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:840
void pft_fill_unit_overlap_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:891
enum tile_behavior no_fights_or_unknown(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:493
const char * player_name(const struct player *pplayer)
Definition player.c:895
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1426
#define is_ai(plr)
Definition player.h:230
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
#define CITY_LOG(loglevel, pcity, msg,...)
Definition srv_log.h:83
#define UNIT_LOG(loglevel, punit, msg,...)
Definition srv_log.h:98
@ AIT_SETTLERS
Definition srv_log.h:44
@ AIT_WORKERS
Definition srv_log.h:45
@ TIMER_STOP
Definition srv_log.h:76
@ TIMER_START
Definition srv_log.h:76
#define TIMING_LOG(timer, activity)
Definition srv_log.h:125
int shield_priority
Definition advdata.h:113
int food_priority
Definition advdata.h:114
struct government * gov
Definition advdata.h:131
struct adv_data::@93 goal
struct adv_data::@93::@95 govt
int science_priority
Definition advdata.h:117
struct ai_settler * settler
Definition daidata.h:100
struct tile_data_cache_hash * tdc_hash
Definition daisettler.c:144
Definition ai.h:50
Definition city.h:320
int waste[O_LAST]
Definition city.h:356
struct tile_data_cache * tdc
Definition daisettler.c:166
adv_want total
Definition daisettler.c:158
bool virt_boat
Definition daisettler.c:162
struct cityresult::@254 best_other
struct cityresult::@253 city_center
adv_want result
Definition daisettler.c:159
bool overseas
Definition daisettler.c:161
int city_radius_sq
Definition daisettler.c:182
adv_want remaining
Definition daisettler.c:177
struct tile * tile
Definition daisettler.c:157
struct tile_data_cache_hash * tdc_hash
Definition daisettler.c:180
struct packet_game_info info
Definition game.h:89
struct packet_scenario_info scenario
Definition game.h:87
enum borders_mode borders
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
struct government * government
Definition player.h:256
Definition tile.h:50
int index
Definition tile.h:51
Definition unit.h:138
int moves_left
Definition unit.h:150
int id
Definition unit.h:145
bool debug
Definition unit.h:234
struct unit::@81::@84 server
struct tile * tile
Definition unit.h:140
struct tile * goto_tile
Definition unit.h:155
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:612
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1033
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:981
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Definition tile.c:771
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
#define tile_claimer(_tile)
Definition tile.h:100
#define tile_index(_pt_)
Definition tile.h:88
#define tile_worked(_tile)
Definition tile.h:114
#define tile_terrain(_tile)
Definition tile.h:110
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_continent(_tile)
Definition tile.h:92
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
#define tile_owner(_tile)
Definition tile.h:96
void set_unit_activity(struct unit *punit, enum unit_activity new_activity)
Definition unit.c:1085
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2637
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1620
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1725
void unit_tile_set(struct unit *punit, struct tile *ptile)
Definition unit.c:1252
#define unit_tile(_pu)
Definition unit.h:390
#define CHECK_UNIT(punit)
Definition unit.h:270
#define unit_owner(_pu)
Definition unit.h:389
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Definition unithand.c:6468
void unit_do_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id, const char *name, const action_id action_type)
Definition unithand.c:3291
enum ane_kind action_not_enabled_reason(struct unit *punit, action_id act_id, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit)
Definition unithand.c:1913
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2725
struct unit_type * best_role_unit(const struct city *pcity, int role)
Definition unittype.c:2271
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2253
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1484
struct unit_type * best_role_unit_for_player(const struct player *pplayer, int role)
Definition unittype.c:2297
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2498
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
int unit_pop_value(const struct unit *punit)
Definition unittype.c:1543
#define unit_tech_reqs_iterate_end
Definition unittype.h:878
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:872
@ MOVE_NONE
Definition unittype.h:144