Freeciv21
Develop your civilization from humble roots to a global empire
daidomestic.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 // utility
15 #include "log.h"
16 
17 // common
18 #include "city.h"
19 #include "game.h"
20 #include "government.h"
21 #include "movement.h"
22 #include "traderoutes.h"
23 #include "unit.h"
24 #include "unitlist.h"
25 #include "unittype.h"
26 
27 /* common/aicore */
28 #include "pf_tools.h"
29 
30 // server
31 #include "citytools.h"
32 #include "srv_log.h"
33 #include "unittools.h"
34 
35 /* server/advisors */
36 #include "advbuilding.h"
37 #include "advchoice.h"
38 #include "advdata.h"
39 #include "infracache.h" // adv_city
40 
41 // ai
42 #include "aitraits.h"
43 #include "handicaps.h"
44 
45 /* ai/default */
46 #include "aidata.h"
47 #include "ailog.h"
48 #include "aiplayer.h"
49 #include "aitech.h"
50 #include "aitools.h"
51 #include "daicity.h"
52 #include "daidomestic.h"
53 
60 static void dai_choose_help_wonder(struct ai_type *ait, struct city *pcity,
61  struct adv_choice *choice,
62  struct adv_data *ai)
63 {
64  struct player *pplayer = city_owner(pcity);
65  Continent_id continent = tile_continent(pcity->tile);
66  struct ai_city *city_data = def_ai_city_data(pcity, ait);
67  /* Total count of caravans available or already being built
68  * on this continent */
69  int caravans = 0;
70  // The type of the caravan
71  struct unit_type *unit_type;
72  struct city *wonder_city = game_city_by_number(ai->wonder_city);
73 
74  if (num_role_units(action_id_get_role(ACTION_HELP_WONDER)) == 0) {
75  // No such units available in the ruleset
76  return;
77  }
78 
79  if (pcity == wonder_city || wonder_city == nullptr
80  || city_data->distance_to_wonder_city <= 0
82  // TODO: Should helping to build a unit be considered when legal?
83  || VUT_UTYPE == wonder_city->production.kind
84  /* TODO: Should helping to build an improvement be considered when
85  * legal? */
86  || !is_wonder(wonder_city->production.value.building)) {
87  /* A distance of zero indicates we are very far away, possibly
88  * on another continent. */
89  return;
90  }
91 
92  // Count existing caravans
93  unit_list_iterate(pplayer->units, punit)
94  {
95  if (unit_can_do_action(punit, ACTION_HELP_WONDER)
96  && tile_continent(unit_tile(punit)) == continent) {
97  caravans++;
98  }
99  }
101 
102  // Count caravans being built
103  city_list_iterate(pplayer->cities, acity)
104  {
105  if (VUT_UTYPE == acity->production.kind
106  && utype_can_do_action(acity->production.value.utype,
107  ACTION_HELP_WONDER)
108  && tile_continent(acity->tile) == continent) {
109  caravans++;
110  }
111  }
113 
114  unit_type = best_role_unit(pcity, action_id_get_role(ACTION_HELP_WONDER));
115 
116  if (!unit_type) {
117  /* We cannot build such units yet
118  * but we will consider it to stimulate science */
119  unit_type = get_role_unit(action_id_get_role(ACTION_HELP_WONDER), 0);
120  }
121 
122  fc_assert_msg(utype_can_do_action(unit_type, ACTION_HELP_WONDER),
123  "Non existence of wonder helper unit not caught");
124 
125  // Check if wonder needs a little help.
126  if (build_points_left(wonder_city)
127  > utype_build_shield_cost_base(unit_type) * caravans) {
128  const struct impr_type *wonder = wonder_city->production.value.building;
129  adv_want want =
130  wonder_city->server.adv->building_want[improvement_index(wonder)];
131  int dist = city_data->distance_to_wonder_city / unit_type->move_rate;
132 
133  fc_assert_ret(VUT_IMPROVEMENT == wonder_city->production.kind);
134 
135  want /= MAX(dist, 1);
136  CITY_LOG(LOG_DEBUG, pcity,
137  "want %s to help wonder in %s with " ADV_WANT_PRINTF,
138  utype_rule_name(unit_type), city_name_get(wonder_city), want);
139  if (want > choice->want) {
140  /* This sets our tech want in cases where we cannot actually build
141  * the unit. */
143  ait, pplayer, pcity, action_id_get_role(ACTION_HELP_WONDER), want);
144  if (unit_type != nullptr) {
145  choice->want = want;
146  choice->type = CT_CIVILIAN;
147  choice->value.utype = unit_type;
148  } else {
149  CITY_LOG(LOG_DEBUG, pcity,
150  "would but could not build ACTION_HELP_WONDER unit, "
151  "bumped reqs");
152  }
153  }
154  }
155 }
156 
162 static void dai_choose_trade_route(struct ai_type *ait, struct city *pcity,
163  struct adv_choice *choice,
164  struct adv_data *ai)
165 {
166  struct player *pplayer = city_owner(pcity);
167  struct unit_type *unit_type;
168  adv_want want;
169  int income;
170  int trade_routes;
171  int caravan_units;
172  int unassigned_caravans;
173  int max_routes;
174  Continent_id continent = tile_continent(pcity->tile);
175  bool dest_city_found = false;
176  bool dest_city_nat_different_cont = false;
177  bool dest_city_nat_same_cont = false;
178  bool dest_city_in_different_cont = false;
179  bool dest_city_in_same_cont = false;
180  bool prefer_different_cont;
181  int pct = 0;
182  int trader_trait;
183  bool need_boat = false;
184 
185  if (city_list_size(pplayer->cities) < 5) {
186  /* Consider trade routes only if enough destination cities.
187  * This is just a quick check. We make more detailed check below. */
188  return;
189  }
190 
191  if (num_role_units(action_id_get_role(ACTION_TRADE_ROUTE)) == 0
192  && num_role_units(action_id_get_role(ACTION_MARKETPLACE)) == 0) {
193  // No such units available in the ruleset
194  return;
195  }
196 
197  prefer_different_cont = trade_route_type_trade_pct(TRT_NATIONAL_IC)
199 
200  // Look for proper destination city for trade.
203  // National traderoutes have value
204  city_list_iterate(pplayer->cities, acity)
205  {
206  if (can_cities_trade(pcity, acity)) {
207  dest_city_found = true;
208  if (tile_continent(acity->tile) != continent) {
209  dest_city_nat_different_cont = true;
210  if (prefer_different_cont) {
211  break;
212  }
213  } else {
214  dest_city_nat_same_cont = true;
215  if (!prefer_different_cont) {
216  break;
217  }
218  }
219  }
220  }
222  }
223 
224  /* FIXME: This check should consider more about relative
225  * income from different traderoute types. This works just
226  * with more typical ruleset setups. */
227  if (prefer_different_cont && !dest_city_nat_different_cont) {
228  prefer_different_cont = trade_route_type_trade_pct(TRT_IN_IC)
230 
231  players_iterate(aplayer)
232  {
233  if (aplayer == pplayer || !aplayer->is_alive) {
234  continue;
235  }
236  if (pplayers_allied(pplayer, aplayer)) {
237  city_list_iterate(aplayer->cities, acity)
238  {
239  if (can_cities_trade(pcity, acity)) {
240  dest_city_found = true;
241  if (tile_continent(acity->tile) != continent) {
242  dest_city_in_different_cont = true;
243  if (prefer_different_cont) {
244  break;
245  }
246  } else {
247  dest_city_in_same_cont = true;
248  if (!prefer_different_cont) {
249  break;
250  }
251  }
252  }
253  }
255  }
256  if ((dest_city_in_different_cont && prefer_different_cont)
257  || (dest_city_in_same_cont && !prefer_different_cont)) {
258  break;
259  }
260  }
262  }
263 
264  if (!dest_city_found) {
265  // No proper destination city.
266  return;
267  }
268 
269  unit_type = best_role_unit(pcity, action_id_get_role(ACTION_TRADE_ROUTE));
270 
271  if (!unit_type) {
272  // Can't establish trade route yet. What about entering a marketplace?
273  /* TODO: Should a future unit capable of establishing trade routes be
274  * prioritized above a present unit capable of entering a market place?
275  * In that case this should be below the check for a future unit
276  * capable of establishing a trade route. */
277  unit_type =
278  best_role_unit(pcity, action_id_get_role(ACTION_MARKETPLACE));
279  }
280 
281  if (!unit_type) {
282  /* We cannot build such units yet
283  * but we will consider it to stimulate science */
284  unit_type = get_role_unit(action_id_get_role(ACTION_TRADE_ROUTE), 0);
285  }
286 
287  if (!unit_type) {
288  /* We'll never be able to establish a trade route. Consider a unit that
289  * can enter the marketplace in stead to stimulate science. */
290  unit_type = get_role_unit(action_id_get_role(ACTION_MARKETPLACE), 0);
291  }
292 
293  fc_assert_msg(unit_type, "Non existance of trade unit not caught");
294 
295  trade_routes = city_num_trade_routes(pcity);
296  // Count also caravans enroute to establish traderoutes
297  caravan_units = 0;
298  unit_list_iterate(pcity->units_supported, punit)
299  {
300  if (unit_can_do_action(punit, ACTION_TRADE_ROUTE)) {
301  caravan_units++;
302  }
303  }
305 
306  max_routes = max_trade_routes(pcity);
307  unassigned_caravans = caravan_units - (max_routes - trade_routes);
308  trade_routes += caravan_units;
309 
310  /* We consider only initial benefit from establishing trade route.
311  * We may actually get only initial benefit if both cities already
312  * have four trade routes, if there already is route between them
313  * or if the Establish Trade Route action is illegal. */
314 
315  /* We pass a nullptr pc2 to get_caravan_enter_city_trade_bonus() so
316  * it assumes that we are creating trade route to city with 75% of
317  * pcitys trade 10 squares away. */
319  pcity, nullptr, pplayer, nullptr,
320  utype_can_do_action(unit_type, ACTION_TRADE_ROUTE));
321 
322  if (dest_city_nat_same_cont) {
324  }
325  if (dest_city_in_same_cont) {
326  int typepct = trade_route_type_trade_pct(TRT_IN);
327 
328  pct = MAX(pct, typepct);
329  }
330  if (dest_city_nat_different_cont) {
332 
333  if (typepct > pct) {
334  pct = typepct;
335  need_boat = true;
336  }
337  }
338  if (dest_city_in_different_cont) {
339  int typepct = trade_route_type_trade_pct(TRT_IN_IC);
340 
341  if (typepct > pct) {
342  pct = typepct;
343  need_boat = true;
344  }
345  }
346 
347  income = pct * income / 100;
348 
349  want = income * ai->gold_priority + income * ai->science_priority;
350 
351  /* We get this income only once after all.
352  * This value is adjusted for most interesting gameplay.
353  * For optimal performance AI should build more caravans, but
354  * we want it to build less valued buildings too. */
355  trader_trait = ai_trait_get_value(TRAIT_TRADER, pplayer);
356  want /= (130.f * TRAIT_DEFAULT_VALUE / trader_trait);
357 
358  /* Increase want for trade routes if our economy is very weak.
359  * We may have enough gold, but only because we have already set
360  * tax rate to 100%. So don't check gold directly, but tax rate.
361  * This method helps us out of deadlocks of completely stalled
362  * scientific progress.
363  */
364  if (pplayer->economic.science < 50 && trade_routes < max_routes
365  && utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) {
366  want *= (6 - pplayer->economic.science / 10)
367  * (6 - pplayer->economic.science / 10);
368  }
369 
370  if (trade_routes == 0 && max_routes > 0
371  && utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) {
372  /* If we have no trade routes at all, we are certainly creating a new
373  * one. */
374  want += trader_trait;
375  } else if (trade_routes < max_routes
376  && utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) {
377  // Possibly creating a new trade route
378  want += trader_trait / 4;
379  }
380 
381  want -= utype_build_shield_cost(pcity, unit_type) * SHIELD_WEIGHTING / 150;
382 
383  // Don't pile too many of them
384  if (unassigned_caravans * 10 > want && want > 0.0) {
385  want = 0.1;
386  } else {
387  want -= unassigned_caravans * 10; // Don't pile too many of them
388  }
389 
390  CITY_LOG(LOG_DEBUG, pcity,
391  "want for trade route unit is " ADV_WANT_PRINTF
392  " (expected initial income %d)",
393  want, income);
394 
395  if (want > choice->want) {
396  /* This sets our tech want in cases where we cannot actually build
397  * the unit. */
399  ait, pplayer, pcity, action_id_get_role(ACTION_TRADE_ROUTE), want);
400 
401  if (unit_type == nullptr) {
403  ait, pplayer, pcity, action_id_get_role(ACTION_MARKETPLACE), want);
404  }
405 
406  if (unit_type != nullptr) {
407  choice->want = want;
408  choice->type = CT_CIVILIAN;
409  choice->value.utype = unit_type;
410  choice->need_boat = need_boat;
411  } else {
412  CITY_LOG(LOG_DEBUG, pcity,
413  "would but could not build trade route unit, bumped reqs");
414  }
415  }
416 }
417 
424  struct player *pplayer,
425  struct city *pcity)
426 {
427  struct adv_data *adv = adv_data_get(pplayer, nullptr);
428  // Unit type with certain role
429  struct unit_type *worker_type;
430  struct unit_type *founder_type;
431  adv_want worker_want, founder_want;
432  struct ai_city *city_data = def_ai_city_data(pcity, ait);
433  struct adv_choice *choice = adv_new_choice();
434 
435  // Find out desire for workers (terrain improvers)
436  worker_type = city_data->worker_type;
437 
438  /* The worker want is calculated in aicity.c called from
439  * dai_manage_cities. The expand value is the % that the AI should
440  * value expansion (basically to handicap easier difficulty levels)
441  * and is set when the difficulty level is changed (difficulty.c). */
442  worker_want = city_data->worker_want * pplayer->ai_common.expand / 100;
443 
444  if (adv->wonder_city == pcity->id) {
445  if (worker_type == nullptr || worker_type->pop_cost > 0) {
446  worker_want /= 5;
447  } else {
448  worker_want /= 2;
449  }
450  }
451 
452  if (worker_type != nullptr
453  && pcity->surplus[O_FOOD]
454  > utype_upkeep_cost(worker_type, pplayer, O_FOOD)) {
455  if (worker_want > 0) {
456  CITY_LOG(LOG_DEBUG, pcity,
457  "desires terrain improvers with passion " ADV_WANT_PRINTF,
458  worker_want);
459  dai_choose_role_unit(ait, pplayer, pcity, choice, CT_CIVILIAN,
460  UTYF_SETTLERS, worker_want, false);
461  adv_choice_set_use(choice, "worker");
462  }
463  // Terrain improvers don't use boats (yet)
464 
465  } else if (worker_type == nullptr && worker_want > 0) {
466  // Can't build workers. Lets stimulate science
467  dai_wants_role_unit(ait, pplayer, pcity, UTYF_SETTLERS, worker_want);
468  }
469 
470  // Find out desire for city founders
471  // Basically, copied from above and adjusted. -- jjm
472  if (!game.scenario.prevent_new_cities) {
473  founder_type =
474  best_role_unit(pcity, action_id_get_role(ACTION_FOUND_CITY));
475 
476  // founder_want calculated in aisettlers.c
477  founder_want = city_data->founder_want;
478 
479  if (adv->wonder_city == pcity->id) {
480  if (founder_type == nullptr || founder_type->pop_cost > 0) {
481  founder_want /= 5;
482  } else {
483  founder_want /= 2;
484  }
485  }
486 
487  if (adv->max_num_cities <= city_list_size(pplayer->cities)) {
488  founder_want /= 100;
489  }
490 
491  // Adjust founder want by traits
492  founder_want *=
493  static_cast<double>(ai_trait_get_value(TRAIT_EXPANSIONIST, pplayer))
495 
496  if (founder_type
497  && pcity->surplus[O_FOOD]
498  >= utype_upkeep_cost(founder_type, pplayer, O_FOOD)) {
499  if (founder_want > choice->want) {
500  CITY_LOG(LOG_DEBUG, pcity,
501  "desires founders with passion " ADV_WANT_PRINTF,
502  founder_want);
503  dai_choose_role_unit(ait, pplayer, pcity, choice, CT_CIVILIAN,
504  action_id_get_role(ACTION_FOUND_CITY),
505  founder_want, city_data->founder_boat);
506  adv_choice_set_use(choice, "founder");
507 
508  } else if (founder_want < -choice->want) {
509  // We need boats to colonize!
510  /* We might need boats even if there are boats free,
511  * if they are blockaded or in inland seas. */
512  struct ai_plr *ai = dai_plr_data_get(ait, pplayer, nullptr);
513 
514  CITY_LOG(LOG_DEBUG, pcity,
515  "desires founders with passion " ADV_WANT_PRINTF
516  " and asks for a new boat (%d of %d free)",
517  -founder_want, ai->stats.available_boats, ai->stats.boats);
518 
519  // First fill choice with founder information
520  choice->want = 0 - founder_want;
521  choice->type = CT_CIVILIAN;
522  choice->value.utype = founder_type; // default
523  choice->need_boat = true;
524 
525  /* Then try to overwrite it with ferryboat information
526  * If no ferryboat is found, above founder choice stays. */
527  dai_choose_role_unit(ait, pplayer, pcity, choice, CT_CIVILIAN,
528  L_FERRYBOAT, -founder_want, true);
529  adv_choice_set_use(choice, "founder's boat");
530  }
531  } else if (!founder_type
532  && (founder_want > choice->want
533  || founder_want < -choice->want)) {
534  // Can't build founders. Lets stimulate science
535  dai_wants_role_unit(ait, pplayer, pcity,
536  action_id_get_role(ACTION_FOUND_CITY),
537  founder_want);
538  }
539  }
540 
541  {
542  struct adv_choice *cur;
543 
544  // Consider building caravan-type units to aid wonder construction
545  cur = adv_new_choice();
546  adv_choice_set_use(cur, "wonder");
547  dai_choose_help_wonder(ait, pcity, cur, adv);
548  choice = adv_better_choice_free(choice, cur);
549 
550  // Consider city improvements
551  cur = adv_new_choice();
552  adv_choice_set_use(cur, "improvement");
553  building_advisor_choose(pcity, cur);
554  cur->want = cur->want
555  * (0.5
556  + double((ai_trait_get_value(TRAIT_BUILDER, pplayer))
557  / static_cast<double>(TRAIT_DEFAULT_VALUE) / 2));
558  choice = adv_better_choice_free(choice, cur);
559 
560  // Consider building caravan-type units for trade route
561  cur = adv_new_choice();
562  adv_choice_set_use(cur, "trade route");
563  dai_choose_trade_route(ait, pcity, cur, adv);
564  choice = adv_better_choice_free(choice, cur);
565  }
566 
567  if (choice->want >= 200) {
568  /* If we don't do following, we buy caravans in city X when we should be
569  * saving money to buy defenses for city Y. -- Syela */
570  choice->want = 199;
571  }
572 
573  return choice;
574 }
575 
579 void dai_wonder_city_distance(struct ai_type *ait, struct player *pplayer,
580  struct adv_data *adv)
581 {
582  struct pf_map *pfm;
583  struct pf_parameter parameter;
584  struct unit_type *punittype;
585  struct unit *ghost;
586  int maxrange;
587  struct city *wonder_city = game_city_by_number(adv->wonder_city);
588 
589  city_list_iterate(pplayer->cities, acity)
590  {
591  // Mark unavailable
592  def_ai_city_data(acity, ait)->distance_to_wonder_city = 0;
593  }
595 
596  if (wonder_city == nullptr) {
597  return;
598  }
599 
600  punittype = best_role_unit_for_player(
601  pplayer, action_id_get_role(ACTION_HELP_WONDER));
602 
603  if (!punittype) {
604  return;
605  }
606 
607  fc_assert_msg(utype_can_do_action(punittype, ACTION_HELP_WONDER),
608  "Non existence of wonder helper unit not caught");
609 
610  ghost = unit_virtual_create(pplayer, wonder_city, punittype, 0);
611  maxrange = unit_move_rate(ghost) * 7;
612 
613  pft_fill_unit_parameter(&parameter, ghost);
614  parameter.omniscience = !has_handicap(pplayer, H_MAP);
615  pfm = pf_map_new(&parameter);
616 
617  pf_map_move_costs_iterate(pfm, ptile, move_cost, false)
618  {
619  struct city *acity = tile_city(ptile);
620 
621  if (move_cost > maxrange) {
622  break;
623  }
624  if (!acity) {
625  continue;
626  }
627  if (city_owner(acity) == pplayer) {
628  def_ai_city_data(acity, ait)->distance_to_wonder_city = move_cost;
629  }
630  }
632 
633  pf_map_destroy(pfm);
634  unit_virtual_destroy(ghost);
635 }
#define action_id_get_role(act_id)
Definition: actions.h:580
void building_advisor_choose(struct city *pcity, struct adv_choice *choice)
Choose improvement we like most and put it into adv_choice.
#define SHIELD_WEIGHTING
Definition: advbuilding.h:17
struct adv_choice * adv_new_choice()
Dynamically allocate a new choice.
Definition: advchoice.cpp:55
struct adv_choice * adv_better_choice_free(struct adv_choice *first, struct adv_choice *second)
Return better one of the choices given, and free the other.
Definition: advchoice.cpp:94
#define adv_choice_set_use(_choice, _use)
Definition: advchoice.h:69
@ CT_CIVILIAN
Definition: advchoice.h:25
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Return a pointer to our data.
Definition: advdata.cpp:591
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Get current default ai data related to player.
Definition: aidata.cpp:304
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition: aiplayer.h:35
struct unit_type * dai_wants_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, int role, int want)
Returns the best unit we can build, or nullptr if none.
Definition: aitech.cpp:518
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)
Calls dai_wants_role_unit to choose the best unit with the given role and set tech wants.
Definition: aitools.cpp:1131
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Get current value of player trait.
Definition: aitraits.cpp:62
bool city_production_gets_caravan_shields(const struct universal *tgt)
Returns TRUE iff the specified production should get shields from units that has done ACTION_HELP_WON...
Definition: city.cpp:1752
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
const char * city_name_get(const struct city *pcity)
Return the name of the city.
Definition: city.cpp:1077
#define city_list_iterate(citylist, pcity)
Definition: city.h:482
#define city_list_iterate_end
Definition: city.h:484
int build_points_left(struct city *pcity)
Calculate the remaining build points.
Definition: citytools.cpp:575
void dai_wonder_city_distance(struct ai_type *ait, struct player *pplayer, struct adv_data *adv)
Calculate walking distances to wonder city from nearby cities.
static void dai_choose_trade_route(struct ai_type *ait, struct city *pcity, struct adv_choice *choice, struct adv_data *ai)
Evaluate the need for units (like caravans) that create trade routes.
struct adv_choice * domestic_advisor_choose_build(struct ai_type *ait, struct player *pplayer, struct city *pcity)
This function should fill the supplied choice structure.
static void dai_choose_help_wonder(struct ai_type *ait, struct city *pcity, struct adv_choice *choice, struct adv_data *ai)
Evaluate the need for units (like caravans) that aid wonder construction.
Definition: daidomestic.cpp:60
float adv_want
Definition: fc_types.h:1144
#define ADV_WANT_PRINTF
Definition: fc_types.h:1145
@ O_FOOD
Definition: fc_types.h:85
signed short Continent_id
Definition: fc_types.h:289
struct civ_game game
Definition: game.cpp:47
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
Definition: game.cpp:103
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
AI players may have handicaps - allowing them to cheat or preventing them from using certain algorith...
Definition: handicaps.cpp:62
@ H_MAP
Definition: handicaps.h:27
Impr_type_id improvement_index(const struct impr_type *pimprove)
Return the improvement index.
bool is_wonder(const struct impr_type *pimprove)
Returns whether improvement is some kind of wonder.
#define fc_assert_msg(condition, message,...)
Definition: log.h:96
constexpr auto LOG_DEBUG
Definition: log.h:27
#define fc_assert_ret(condition)
Definition: log.h:112
int unit_move_rate(const struct unit *punit)
This function calculates the move rate of the unit.
Definition: movement.cpp:78
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
Factory function to create a new map according to the parameter.
void pf_map_destroy(struct pf_map *pfm)
After usage the map must be destroyed.
#define pf_map_move_costs_iterate_end
Definition: path_finding.h:542
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
Definition: path_finding.h:532
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct unit *punit)
Fill classic parameters for an unit.
Definition: pf_tools.cpp:822
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
Definition: player.cpp:1334
#define players_iterate_end
Definition: player.h:520
#define players_iterate(_pplayer)
Definition: player.h:514
#define MAX(x, y)
Definition: shared.h:48
#define CITY_LOG(_, pcity, msg,...)
Definition: srv_log.h:80
enum choice_type type
Definition: advchoice.h:32
adv_want want
Definition: advchoice.h:34
universals_u value
Definition: advchoice.h:33
bool need_boat
Definition: advchoice.h:35
int max_num_cities
Definition: advdata.h:134
int wonder_city
Definition: advdata.h:46
int science_priority
Definition: advdata.h:106
int gold_priority
Definition: advdata.h:105
bool founder_boat
Definition: daicity.h:61
int founder_want
Definition: daicity.h:63
int worker_want
Definition: daicity.h:64
int distance_to_wonder_city
Definition: daicity.h:51
struct unit_type * worker_type
Definition: daicity.h:65
Definition: aidata.h:63
int boats
Definition: aidata.h:71
int available_boats
Definition: aidata.h:72
struct ai_plr::@155 stats
Definition: ai.h:42
Definition: city.h:291
int surplus[O_LAST]
Definition: city.h:324
int id
Definition: city.h:296
struct universal production
Definition: city.h:368
struct adv_city * adv
Definition: city.h:422
struct city::@15::@17 server
struct tile * tile
Definition: city.h:293
struct unit_list * units_supported
Definition: city.h:377
struct packet_scenario_info scenario
Definition: game.h:78
int expand
Definition: player.h:111
Definition: player.h:231
struct city_list * cities
Definition: player.h:263
struct player_ai ai_common
Definition: player.h:270
struct unit_list * units
Definition: player.h:264
bool is_alive
Definition: player.h:250
struct player_economic economic
Definition: player.h:266
int pop_cost
Definition: unittype.h:477
int move_rate
Definition: unittype.h:481
Definition: unit.h:134
enum universals_n kind
Definition: fc_types.h:740
universals_u value
Definition: fc_types.h:739
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
Definition: tile.cpp:72
#define tile_continent(_tile)
Definition: tile.h:74
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Return TRUE iff the two cities are capable of trade; i.e., if a caravan from one city can enter the o...
int trade_route_type_trade_pct(enum trade_route_type type)
Return percentage bonus for trade route type.
int max_trade_routes(const struct city *pcity)
Return current maximum number of trade routes city can have.
Definition: traderoutes.cpp:41
int city_num_trade_routes(const struct city *pcity)
Return number of trade route city has.
int get_caravan_enter_city_trade_bonus(const struct city *pc1, const struct city *pc2, const player *seen_as, struct goods_type *pgood, const bool establish_trade)
Returns the revenue trade bonus - you get this when establishing a trade route and also when you simp...
@ TRT_NATIONAL_IC
Definition: traderoutes.h:32
@ TRT_IN_IC
Definition: traderoutes.h:34
@ TRT_NATIONAL
Definition: traderoutes.h:31
@ TRT_IN
Definition: traderoutes.h:33
#define TRAIT_DEFAULT_VALUE
Definition: traits.h:27
const struct unit_type * utype
Definition: fc_types.h:585
const struct impr_type * building
Definition: fc_types.h:579
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Return TRUE iff this unit can do the specified generalized (ruleset defined) action enabler controlle...
Definition: unit.cpp:309
void unit_virtual_destroy(struct unit *punit)
Free the memory used by virtual unit.
Definition: unit.cpp:1588
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Create a virtual unit skeleton.
Definition: unit.cpp:1490
#define unit_tile(_pu)
Definition: unit.h:371
#define unit_list_iterate(unitlist, punit)
Definition: unitlist.h:25
#define unit_list_iterate_end
Definition: unitlist.h:27
struct unit_type * best_role_unit(const struct city *pcity, int role)
Return "best" unit this city can build, with given role/flag.
Definition: unittype.cpp:1920
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Returns the upkeep of a unit of this type under the given government.
Definition: unittype.cpp:123
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
Definition: unittype.cpp:1274
struct unit_type * best_role_unit_for_player(const struct player *pplayer, int role)
Return "best" unit the player can build, with given role/flag.
Definition: unittype.cpp:1950
int utype_build_shield_cost(const struct city *pcity, const struct unit_type *punittype)
Returns the number of shields it takes to build this unit type.
Definition: unittype.cpp:1141
int utype_build_shield_cost_base(const struct unit_type *punittype)
Returns the number of shields this unit type represents.
Definition: unittype.cpp:1168
int num_role_units(int role)
How many unit types have specified role/flag.
Definition: unittype.cpp:1866
struct unit_type * get_role_unit(int role, int role_index)
Return index-th unit with specified role/flag.
Definition: unittype.cpp:1900
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Return TRUE iff units of the given type can do the specified generalized (ruleset defined) action ena...
Definition: unittype.cpp:386