Freeciv21
Develop your civilization from humble roots to a global empire
barbarian.cpp
Go to the documentation of this file.
1 /*
2 _ ._ Copyright (c) 1996-2021 Freeciv21 and Freeciv contributors.
3  \ | This file is part of Freeciv21. Freeciv21 is free software: you
4  \_| can redistribute it and/or modify it under the terms of the
5  .' '. GNU General Public License as published by the Free
6  :O O: Software Foundation, either version 3 of the License,
7  '/ \' or (at your option) any later version. You should have
8  :X: received a copy of the GNU General Public License along with
9  :X: Freeciv21. If not, see https://www.gnu.org/licenses/.
10  */
11 
18 // utility
19 #include "fcintl.h"
20 #include "log.h"
21 #include "rand.h"
22 #include "support.h"
23 
24 // common
25 #include "effects.h"
26 #include "events.h"
27 #include "game.h"
28 #include "government.h"
29 #include "map.h"
30 #include "movement.h"
31 #include "nation.h"
32 #include "research.h"
33 #include "terrain.h"
34 
35 // server
36 #include "aiiface.h"
37 #include "citytools.h"
38 #include "maphand.h"
39 #include "notify.h"
40 #include "plrhand.h"
41 #include "srv_main.h"
42 #include "techtools.h"
43 #include "unithand.h"
44 #include "unittools.h"
45 
46 /* server/advisors */
47 #include "advdata.h"
48 
49 // ai
50 #include "difficulty.h"
51 
52 #include "barbarian.h"
53 
54 #define BARBARIAN_INITIAL_VISION_RADIUS 3
55 #define BARBARIAN_INITIAL_VISION_RADIUS_SQ 9
56 
60 bool is_land_barbarian(struct player *pplayer)
61 {
62  return (pplayer->ai_common.barbarian_type == LAND_BARBARIAN
63  || pplayer->ai_common.barbarian_type == LAND_AND_SEA_BARBARIAN);
64 }
65 
69 bool is_sea_barbarian(struct player *pplayer)
70 {
71  return (pplayer->ai_common.barbarian_type == SEA_BARBARIAN
72  || pplayer->ai_common.barbarian_type == LAND_AND_SEA_BARBARIAN);
73 }
74 
82 struct player *create_barbarian_player(enum barbarian_type type)
83 {
84  struct player *barbarians;
85  struct nation_type *nation = nullptr;
86  struct research *presearch;
87 
88  players_iterate(old_barbs)
89  {
90  if ((type == LAND_BARBARIAN && is_land_barbarian(old_barbs))
91  || (type == SEA_BARBARIAN && is_sea_barbarian(old_barbs))) {
92  if (!old_barbs->is_alive) {
93  old_barbs->economic.gold = 0;
94  old_barbs->is_alive = true;
95  player_status_reset(old_barbs);
96 
97  /* Free old name so pick_random_player_name() can select it again.
98  * This is needed in case ruleset defines just one leader for
99  * barbarian nation. */
100  old_barbs->name[0] = '\0';
102  old_barbs, pick_random_player_name(nation_of_player(old_barbs)));
103  sz_strlcpy(old_barbs->username, _(ANON_USER_NAME));
104  old_barbs->unassigned_user = true;
105  // I need to make them to forget the map, I think
106  whole_map_iterate(&(wld.map), ptile)
107  {
108  map_clear_known(ptile, old_barbs);
109  }
111  }
112  old_barbs->economic.gold += 100; // New leader, new money
113 
114  return old_barbs;
115  }
116  }
118 
119  // make a new player, or not
120  barbarians =
121  server_create_player(-1, default_ai_type_name(), nullptr, false);
122  if (!barbarians) {
123  return nullptr;
124  }
125  server_player_init(barbarians, true, true);
126 
127  if (type == LAND_BARBARIAN || type == SEA_BARBARIAN) {
128  /* Try LAND_AND_SEA *FIRST*, so that we don't end up
129  * with one of the Land/Sea barbarians created first and
130  * then LAND_AND_SEA created instead of the second. */
131  nation = pick_a_nation(nullptr, false, false, LAND_AND_SEA_BARBARIAN);
132  if (nation != nullptr) {
133  type = LAND_AND_SEA_BARBARIAN;
134  }
135  }
136 
137  if (nation == nullptr) {
138  nation = pick_a_nation(nullptr, false, false, type);
139  }
140 
141  /* Ruleset loading time checks should guarantee that there always is
142  suitable nation available */
143  fc_assert(nation != nullptr);
144 
145  player_nation_defaults(barbarians, nation, true);
146  if (game_was_started()) {
147  // Find a color for the new player.
149  }
150 
151  server.nbarbarians++;
152 
153  sz_strlcpy(barbarians->username, _(ANON_USER_NAME));
154  barbarians->unassigned_user = true;
155  barbarians->is_connected = false;
156  barbarians->government = init_government_of_nation(nation);
157  fc_assert(barbarians->revolution_finishes < 0);
158  barbarians->server.got_first_city = false;
159  barbarians->economic.gold = 100;
160 
161  barbarians->phase_done = true;
162 
163  // Do the ai
164  set_as_ai(barbarians);
165  barbarians->ai_common.barbarian_type = type;
166  set_ai_level_directer(barbarians, ai_level(game.info.skill_level));
167 
168  presearch = research_get(barbarians);
169  init_tech(presearch, true);
170  give_initial_techs(presearch, 0);
171 
172  // Ensure that we are at war with everyone else
173  players_iterate(pplayer)
174  {
175  if (pplayer != barbarians) {
176  player_diplstate_get(pplayer, barbarians)->type = DS_WAR;
177  player_diplstate_get(barbarians, pplayer)->type = DS_WAR;
178  }
179  }
181 
182  CALL_PLR_AI_FUNC(gained_control, barbarians, barbarians);
183 
184  qDebug("Created barbarian %s, player %d", player_name(barbarians),
185  player_number(barbarians));
186  notify_player(nullptr, nullptr, E_UPRISING, ftc_server,
187  _("%s gain a leader by the name %s. Dangerous "
188  "times may lie ahead."),
189  nation_plural_for_player(barbarians),
190  player_name(barbarians));
191 
192  send_player_all_c(barbarians, nullptr);
193  /* Send research info after player info, else the client will complain
194  * about invalid team. */
195  send_research_info(presearch, nullptr);
196 
197  return barbarians;
198 }
199 
203 static void init_dir_checked_status(bool *checked,
204  enum terrain_class *terrainc,
205  enum terrain_class tclass)
206 {
207  int dir;
208 
209  for (dir = 0; dir < 8; dir++) {
210  if (terrainc[dir] == tclass) {
211  checked[dir] = false;
212  } else {
213  checked[dir] = true;
214  }
215  }
216 }
217 
221 static int random_unchecked_direction(int possibilities, const bool *checked)
222 {
223  int j = -1;
224  int i;
225 
226  int num = fc_rand(possibilities);
227  for (i = 0; i <= num; i++) {
228  j++;
229  while (checked[j]) {
230  j++;
231  fc_assert(j < 8);
232  }
233  }
234 
235  return j;
236 }
237 
248 bool unleash_barbarians(struct tile *ptile)
249 {
250  struct player *barbarians;
251  int unit_cnt;
252  int i;
253  bool alive = true; // explorer survived
254  enum terrain_class terrainc[8];
255  struct tile *dir_tiles[8];
256  int land_tiles = 0;
257  int ocean_tiles = 0;
258  bool checked[8];
259  int checked_count;
260  int dir;
261  bool barbarian_stays = false;
262 
263  /* FIXME: When there is no L_BARBARIAN unit,
264  * but L_BARBARIAN_TECH is already available,
265  * we should unleash those.
266  * Doesn't affect any ruleset I'm aware of. */
267  if (BARBS_DISABLED == game.server.barbarianrate
268  || game.info.turn < game.server.onsetbarbarian
269  || num_role_units(L_BARBARIAN) == 0) {
270  unit_list_iterate_safe((ptile)->units, punit)
271  {
272  wipe_unit(punit, ULR_BARB_UNLEASH, nullptr);
273  }
275  return false;
276  }
277 
278  barbarians = create_barbarian_player(LAND_BARBARIAN);
279  if (!barbarians) {
280  return false;
281  }
282 
283  adv_data_phase_init(barbarians, true);
284  CALL_PLR_AI_FUNC(phase_begin, barbarians, barbarians, true);
285 
286  unit_cnt = 3 + fc_rand(4);
287  for (i = 0; i < unit_cnt; i++) {
288  struct unit_type *punittype =
289  find_a_unit_type(L_BARBARIAN, L_BARBARIAN_TECH);
290 
291  /* If unit cannot live on this tile, we just don't create one.
292  * Maybe find_a_unit_type() should take tile parameter, so
293  * we could get suitable unit if one exist. */
294  if (is_native_tile(punittype, ptile)) {
295  struct unit *barb_unit;
296 
297  barb_unit = create_unit(barbarians, ptile, punittype, 0, 0, -1);
298  log_debug("Created barbarian unit %s", utype_rule_name(punittype));
299  send_unit_info(nullptr, barb_unit);
300  }
301  }
302 
303  /* Get information about surrounding terrains in terrain class level.
304  * Only needed if we consider moving units away to random directions. */
305  for (dir = 0; dir < 8; dir++) {
306  dir_tiles[dir] = mapstep(&(wld.map), ptile, direction8(dir));
307  if (dir_tiles[dir] == nullptr) {
308  terrainc[dir] = terrain_class_invalid();
309  } else if (!is_non_allied_unit_tile(dir_tiles[dir], barbarians)) {
310  if (is_ocean_tile(dir_tiles[dir])) {
311  terrainc[dir] = TC_OCEAN;
312  ocean_tiles++;
313  } else {
314  terrainc[dir] = TC_LAND;
315  land_tiles++;
316  }
317  } else {
318  terrainc[dir] = terrain_class_invalid();
319  }
320  }
321 
322  if (land_tiles >= 3) {
323  // Enough land, scatter guys around
324  unit_list_iterate_safe((ptile)->units, punit2)
325  {
326  if (unit_owner(punit2) == barbarians) {
327  bool dest_found = false;
328 
329  // Initialize checked status for checking free land tiles
330  init_dir_checked_status(checked, terrainc, TC_LAND);
331 
332  // Search tile to move to
333  for (checked_count = 0; !dest_found && checked_count < land_tiles;
334  checked_count++) {
335  int rdir = random_unchecked_direction(land_tiles - checked_count,
336  checked);
337 
338  if (unit_can_move_to_tile(&(wld.map), punit2, dir_tiles[rdir],
339  true, false)) {
340  // Move
341  (void) unit_move_handling(punit2, dir_tiles[rdir], true, true);
342  log_debug("Moved barbarian unit from (%d, %d) to (%d, %d)",
343  TILE_XY(ptile), TILE_XY(dir_tiles[rdir]));
344  dest_found = true;
345  }
346 
347  checked[rdir] = true;
348  }
349  if (!dest_found) {
350  // This barbarian failed to move out of hut tile.
351  barbarian_stays = true;
352  }
353  }
354  }
356 
357  } else {
358  if (ocean_tiles > 0) {
359  // maybe it's an island, try to get on boats
360  struct unit *boat = nullptr; // Boat
361 
362  // Initialize checked status for checking Ocean tiles
363  init_dir_checked_status(checked, terrainc, TC_OCEAN);
364 
365  // Search tile for boat. We always create just one boat.
366  for (checked_count = 0; boat == nullptr && checked_count < ocean_tiles;
367  checked_count++) {
368  struct unit_type *candidate;
369  int rdir =
370  random_unchecked_direction(ocean_tiles - checked_count, checked);
371 
372  candidate = find_a_unit_type(L_BARBARIAN_BOAT, unit_role_id(-1));
373  if (is_native_tile(candidate, dir_tiles[rdir])) {
374  boat =
375  create_unit(barbarians, dir_tiles[rdir], candidate, 0, 0, -1);
376  }
377 
378  checked[rdir] = true;
379  }
380 
381  if (boat) {
382  // We do have a boat. Try to get everybody in
383  unit_list_iterate_safe((ptile)->units, punit2)
384  {
385  if (unit_owner(punit2) == barbarians) {
386  if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
387  punit2, boat)) {
388  // Load
389  unit_do_action(unit_owner(punit2), punit2->id, boat->id, 0, "",
390  ACTION_TRANSPORT_EMBARK);
391  }
392  }
393  }
395  }
396 
397  // Move rest of the barbarians to random land tiles
398  unit_list_iterate_safe((ptile)->units, punit2)
399  {
400  if (unit_owner(punit2) == barbarians) {
401  bool dest_found = false;
402 
403  // Initialize checked status for checking Land tiles
404  init_dir_checked_status(checked, terrainc, TC_LAND);
405 
406  // Search tile to move to
407  for (checked_count = 0; !dest_found && checked_count < land_tiles;
408  checked_count++) {
409  int rdir;
410 
411  rdir = random_unchecked_direction(land_tiles - checked_count,
412  checked);
413 
414  if (unit_can_move_to_tile(&(wld.map), punit2, dir_tiles[rdir],
415  true, false)) {
416  // Move
417  (void) unit_move_handling(punit2, dir_tiles[rdir], true, true);
418  dest_found = true;
419  }
420 
421  checked[rdir] = true;
422  }
423  if (!dest_found) {
424  // This barbarian failed to move out of hut tile.
425  barbarian_stays = true;
426  }
427  }
428  }
430  } else {
431  // The village is surrounded! Barbarians cannot leave.
432  barbarian_stays = true;
433  }
434  }
435 
436  if (barbarian_stays) {
437  // There's barbarian in this village! Kill the explorer.
438  unit_list_iterate_safe((ptile)->units, punit2)
439  {
440  if (unit_owner(punit2) != barbarians) {
441  wipe_unit(punit2, ULR_BARB_UNLEASH, nullptr);
442  alive = false;
443  } else {
444  send_unit_info(nullptr, punit2);
445  }
446  }
448  }
449 
450  // FIXME: I don't know if this is needed
451  if (ptile) {
453  }
454 
455  return alive;
456 }
457 
461 static bool is_near_land(struct tile *tile0)
462 {
463  square_iterate(&(wld.map), tile0, 4, ptile)
464  {
465  if (!is_ocean_tile(ptile)) {
466  return true;
467  }
468  }
470 
471  return false;
472 }
473 
477 static struct tile *find_empty_tile_nearby(struct tile *ptile)
478 {
479  square_iterate(&(wld.map), ptile, 1, tile1)
480  {
481  if (unit_list_size(tile1->units) == 0) {
482  return tile1;
483  }
484  }
486 
487  return nullptr;
488 }
489 
509 {
510  struct tile *ptile, *utile;
511  int i, dist;
512  int uprise;
513  struct city *pc;
514  struct player *barbarians, *victim;
515  struct unit_type *leader_type;
516  int barb_count, really_created = 0;
517  bool hut_present = false;
518  int city_count;
519  int city_max;
520 
521  /* We attempt the summons on a particular, random position. If this is
522  * an invalid position then the summons simply fails this time. This means
523  * that a particular tile's chance of being summoned on is independent of
524  * all the other tiles on the map - which is essential for balanced
525  * gameplay. */
526  ptile = rand_map_pos(&(wld.map));
527 
528  if (terrain_has_flag(tile_terrain(ptile), TER_NO_BARBS)) {
529  return;
530  }
531 
532  pc = find_closest_city(ptile, nullptr, nullptr, false, false, false, false,
533  false, nullptr);
534  if (!pc) {
535  // any city
536  return;
537  }
538 
539  victim = city_owner(pc);
540 
541  dist = real_map_distance(ptile, pc->tile);
542  log_debug("Closest city (to %d,%d) is %s (at %d,%d) distance %d.",
543  TILE_XY(ptile), city_name_get(pc), TILE_XY(pc->tile), dist);
544  if (dist > MAX_UNREST_DIST || dist < MIN_UNREST_DIST) {
545  return;
546  }
547 
548  // I think Sea Raiders can come out of unknown sea territory
549  if (!(utile = find_empty_tile_nearby(ptile))
550  || (!map_is_known(utile, victim) && !is_ocean_tile(utile))
551  || !is_near_land(utile)) {
552  return;
553  }
554 
555  fc_assert(1 < game.server.barbarianrate);
556 
557  /* do not harass small civs - in practice: do not uprise at the beginning
558  */
559  if (static_cast<int>(fc_rand(30)) + 1
560  > city_list_size(victim->cities) * (game.server.barbarianrate - 1)
561  || fc_rand(100) > get_player_bonus(victim, EFT_CIVIL_WAR_CHANCE)) {
562  return;
563  }
564  log_debug("Barbarians are willing to fight");
565 
566  // Remove huts in place of uprising
567  // FIXME: Should we really always do it?
568  extra_type_by_rmcause_iterate(ERM_ENTER, pextra)
569  {
570  if (tile_has_extra(utile, pextra)) {
571  tile_extra_rm_apply(utile, pextra);
572  hut_present = true;
573  }
574  }
576 
577  if (hut_present) {
578  update_tile_knowledge(utile);
579  }
580 
581  city_count = city_list_size(victim->cities);
582  city_max = UPRISE_CIV_SIZE;
583  uprise = 1;
584 
585  while (city_max <= city_count) {
586  uprise++;
587  city_max *= 1.2 + UPRISE_CIV_SIZE;
588  }
589 
590  barb_count = fc_rand(3) + uprise * game.server.barbarianrate;
591  leader_type = get_role_unit(L_BARBARIAN_LEADER, 0);
592 
593  if (!is_ocean_tile(utile)) {
594  // land (disembark) barbarians
595  barbarians = create_barbarian_player(LAND_BARBARIAN);
596  if (!barbarians) {
597  return;
598  }
599  for (i = 0; i < barb_count; i++) {
600  struct unit_type *punittype =
601  find_a_unit_type(L_BARBARIAN, L_BARBARIAN_TECH);
602 
603  /* If unit cannot live on this tile, we just don't create one.
604  * Maybe find_a_unit_type() should take tile parameter, so
605  * we could get suitable unit if one exist. */
606  if (is_native_tile(punittype, utile)) {
607  (void) create_unit(barbarians, utile, punittype, 0, 0, -1);
608  really_created++;
609  log_debug("Created barbarian unit %s", utype_rule_name(punittype));
610  }
611  }
612 
613  if (is_native_tile(leader_type, utile)) {
614  (void) create_unit(barbarians, utile, leader_type, 0, 0, -1);
615  really_created++;
616  }
617  } else { // sea raiders - their units will be veteran
618  struct unit *ptrans;
619  struct unit_type *boat;
620  bool miniphase;
621 
622  barbarians = create_barbarian_player(SEA_BARBARIAN);
623  if (!barbarians) {
624  return;
625  }
626  /* Setup data phase if it's not already set up. Created ferries may
627  need that data.
628  We don't know if create_barbarian_player() above created completely
629  new player or did it just return existing one. If it was existing
630  one, phase has already been set up at turn begin and will be closed
631  at turn end. If this is completely new player, we have to take care
632  of both opening and closing the data phase. Return value of
633  adv_data_phase_init() tells us if data phase was already initialized
634  at turn beginning. */
635  miniphase = adv_data_phase_init(barbarians, true);
636  if (miniphase) {
637  CALL_PLR_AI_FUNC(phase_begin, barbarians, barbarians, true);
638  }
639 
640  boat = find_a_unit_type(L_BARBARIAN_BOAT, unit_role_id(-1));
641 
642  if (is_native_tile(boat, utile)
643  && (is_safe_ocean(&(wld.map), utile)
644  || (!utype_has_flag(boat, UTYF_COAST_STRICT)
645  && !utype_has_flag(boat, UTYF_COAST)))) {
646  int cap;
647 
648  ptrans = create_unit(barbarians, utile, boat, 0, 0, -1);
649  really_created++;
650  cap = get_transporter_capacity(ptrans);
651 
652  /* Fill boat with barb_count barbarians at max, leave space for leader
653  */
654  for (i = 0; i < cap - 1 && i < barb_count; i++) {
655  struct unit_type *barb =
656  find_a_unit_type(L_BARBARIAN_SEA, L_BARBARIAN_SEA_TECH);
657 
658  if (can_unit_type_transport(boat, utype_class(barb))) {
659  (void) create_unit_full(barbarians, utile, barb, 0, 0, -1, -1,
660  ptrans);
661  really_created++;
662  log_debug("Created barbarian unit %s", utype_rule_name(barb));
663  }
664  }
665 
666  if (can_unit_type_transport(boat, utype_class(leader_type))) {
667  (void) create_unit_full(barbarians, utile, leader_type, 0, 0, -1, -1,
668  ptrans);
669  really_created++;
670  }
671  }
672 
673  if (miniphase) {
674  CALL_PLR_AI_FUNC(phase_finished, barbarians, barbarians);
675  adv_data_phase_done(barbarians);
676  }
677  }
678 
679  if (really_created == 0) {
680  // No barbarians found suitable spot
681  return;
682  }
683 
684  // Is this necessary? create_unit_full already sends unit info.
685  unit_list_iterate(utile->units, punit2)
686  {
687  send_unit_info(nullptr, punit2);
688  }
690 
691  // to let them know where to get you
694 
695  // There should probably be a different message about Sea Raiders
696  if (is_land_barbarian(barbarians)) {
697  notify_player(victim, utile, E_UPRISING, ftc_server,
698  _("Native unrest near %s led by %s."), city_link(pc),
699  player_name(barbarians));
700  } else if (map_is_known_and_seen(utile, victim, V_MAIN)) {
701  notify_player(victim, utile, E_UPRISING, ftc_server,
702  _("Sea raiders seen near %s!"), city_link(pc));
703  }
704 }
705 
711 {
712  int i, n;
713 
714  if (BARBS_DISABLED == game.server.barbarianrate
715  || BARBS_HUTS_ONLY == game.server.barbarianrate) {
716  return;
717  }
718 
719  if (game.info.turn < game.server.onsetbarbarian) {
720  return;
721  }
722 
723  n = map_num_tiles() / MAP_FACTOR;
724  if (n == 0) {
725  // Allow barbarians on maps smaller than MAP_FACTOR
726  n = 1;
727  }
728 
729  for (i = 0; i < n * (game.server.barbarianrate - 1); i++) {
731  }
732 }
bool is_action_enabled_unit_on_unit(const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Returns TRUE if actor_unit can do wanted_action to target_unit as far as action enablers are concerne...
Definition: actions.cpp:4007
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Make and cache lots of calculations needed for other functions.
Definition: advdata.cpp:250
void adv_data_phase_done(struct player *pplayer)
Clean up our mess.
Definition: advdata.cpp:556
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition: ai.h:383
const char * default_ai_type_name()
Return name of default ai type.
Definition: aiiface.cpp:265
struct player * create_barbarian_player(enum barbarian_type type)
Creates the land/sea barbarian player and inits some stuff.
Definition: barbarian.cpp:82
static struct tile * find_empty_tile_nearby(struct tile *ptile)
Return this or a neighbouring tile that is free of any units.
Definition: barbarian.cpp:477
bool unleash_barbarians(struct tile *ptile)
Unleash barbarians means give barbarian player some units and move them out of the hut,...
Definition: barbarian.cpp:248
static void try_summon_barbarians()
The barbarians are summoned at a randomly chosen place if:
Definition: barbarian.cpp:508
#define BARBARIAN_INITIAL_VISION_RADIUS_SQ
Definition: barbarian.cpp:55
static void init_dir_checked_status(bool *checked, enum terrain_class *terrainc, enum terrain_class tclass)
(Re)initialize direction checked status array based on terrain class.
Definition: barbarian.cpp:203
bool is_sea_barbarian(struct player *pplayer)
Is player a sea barbarian?
Definition: barbarian.cpp:69
void summon_barbarians()
Summon barbarians out of the blue.
Definition: barbarian.cpp:710
static bool is_near_land(struct tile *tile0)
Is sea not further than a couple of tiles away from land?
Definition: barbarian.cpp:461
bool is_land_barbarian(struct player *pplayer)
Is player a land barbarian?
Definition: barbarian.cpp:60
static int random_unchecked_direction(int possibilities, const bool *checked)
Return random directory from not yet checked ones.
Definition: barbarian.cpp:221
#define MAP_FACTOR
Definition: barbarian.h:27
#define UPRISE_CIV_SIZE
Definition: barbarian.h:25
#define MIN_UNREST_DIST
Definition: barbarian.h:22
#define MAX_UNREST_DIST
Definition: barbarian.h:23
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
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Find the city closest to 'ptile'.
Definition: citytools.cpp:849
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Set an AI level and related quantities, with no feedback.
Definition: difficulty.cpp:36
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
Definition: effects.cpp:673
#define extra_type_by_rmcause_iterate_end
Definition: extras.h:330
#define extra_type_by_rmcause_iterate(_rmcause, _extra)
Definition: extras.h:324
#define _(String)
Definition: fcintl.h:50
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
Get a text link to a city.
struct civ_game game
Definition: game.cpp:47
struct world wld
Definition: game.cpp:48
@ BARBS_HUTS_ONLY
Definition: game.h:33
@ BARBS_DISABLED
Definition: game.h:32
#define fc_assert(condition)
Definition: log.h:89
#define log_debug(message,...)
Definition: log.h:65
struct tile * rand_map_pos(const struct civ_map *nmap)
Random square anywhere on the map.
Definition: map.cpp:1026
int map_num_tiles()
Returns the total number of (real) positions (or tiles) on the map.
Definition: map.cpp:954
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Return TRUE if this ocean terrain is adjacent to a safe coastline.
Definition: map.cpp:636
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
Definition: map.cpp:599
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Step from the given tile in the given direction.
Definition: map.cpp:342
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition: map.h:312
#define square_iterate_end
Definition: map.h:315
#define whole_map_iterate(_map, _tile)
Definition: map.h:473
#define whole_map_iterate_end
Definition: map.h:480
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Return whether the player knows the tile.
Definition: maphand.cpp:884
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Returns whether the layer 'vlayer' of the tile 'ptile' is known and seen by the player 'pplayer'.
Definition: maphand.cpp:894
void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
Shows the area to the player.
Definition: maphand.cpp:852
void update_tile_knowledge(struct tile *ptile)
Update playermap knowledge for everybody who sees the tile, and send a packet to everyone whose info ...
Definition: maphand.cpp:1395
void map_clear_known(struct tile *ptile, struct player *pplayer)
Clear known status of the tile.
Definition: maphand.cpp:1141
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
This tile is native to unit.
Definition: movement.cpp:279
bool unit_can_move_to_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *dst_tile, bool igzoc, bool enter_enemy_city)
Returns whether the unit can move from its current tile to the destination tile.
Definition: movement.cpp:531
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Return TRUE iff transporter type has ability to transport transported class.
Definition: movement.cpp:698
struct government * init_government_of_nation(const struct nation_type *pnation)
Returns initial government type for this nation.
Definition: nation.cpp:545
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
Definition: nation.cpp:155
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
Definition: nation.cpp:419
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Similar to notify_conn_packet (see also), but takes player as "destination".
Definition: notify.cpp:284
int player_number(const struct player *pplayer)
Return the player index/number/id.
Definition: player.cpp:756
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
Definition: player.cpp:816
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
Definition: player.cpp:288
#define players_iterate_end
Definition: player.h:520
#define players_iterate(_pplayer)
Definition: player.h:514
#define ANON_USER_NAME
Definition: player.h:31
#define set_as_ai(plr)
Definition: player.h:229
void server_player_set_name(struct player *pplayer, const char *name)
Try to set the player name to 'name'.
Definition: plrhand.cpp:2159
void send_player_all_c(struct player *src, struct conn_list *dest)
Send all information about a player (player_info and all player_diplstates) to the given connections.
Definition: plrhand.cpp:1031
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Creates a new, uninitialized, used player slot.
Definition: plrhand.cpp:1776
void assign_player_colors()
Permanently assign colors to any players that don't already have them.
Definition: plrhand.cpp:1608
void player_status_reset(struct player *plr)
Reset player status to 'normal'.
Definition: plrhand.cpp:3161
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
This function returns a random-ish nation that is suitable for 'barb_type' and is usable (not already...
Definition: plrhand.cpp:2377
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Initialize ANY newly-created player on the server.
Definition: plrhand.cpp:1494
#define fc_rand(_size)
Definition: rand.h:16
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
Definition: research.cpp:110
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Set nation for player with nation default values.
Definition: srv_main.cpp:2545
bool game_was_started()
Returns iff the game was started once upon a time.
Definition: srv_main.cpp:251
const char * pick_random_player_name(const struct nation_type *pnation)
Returns a random ruler name picked from given nation's ruler names that is not already in use.
Definition: srv_main.cpp:2787
Definition: city.h:291
struct tile * tile
Definition: city.h:293
struct civ_game::@28::@32 server
struct packet_game_info info
Definition: game.h:80
enum barbarian_type barbarian_type
Definition: player.h:115
enum diplstate_type type
Definition: player.h:193
Definition: player.h:231
struct city_list * cities
Definition: player.h:263
struct player_ai ai_common
Definition: player.h:270
char username[MAX_LEN_NAME]
Definition: player.h:234
bool is_connected
Definition: player.h:278
int revolution_finishes
Definition: player.h:255
struct player::@65::@67 server
struct government * government
Definition: player.h:240
struct player_economic economic
Definition: player.h:266
bool phase_done
Definition: player.h:245
bool unassigned_user
Definition: player.h:235
Definition: servers.h:55
Definition: tile.h:42
struct unit_list * units
Definition: tile.h:50
Definition: unit.h:134
int id
Definition: unit.h:141
struct civ_map map
Definition: world_object.h:21
#define sz_strlcpy(dest, src)
Definition: support.h:140
void init_tech(struct research *research, bool update)
Initializes tech data for the research.
Definition: techtools.cpp:1075
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Send research info for 'presearch' to 'dest'.
Definition: techtools.cpp:273
void give_initial_techs(struct research *presearch, int num_random_techs)
Gives global (read from the game ruleset file) and nation (read from the nation ruleset files) initia...
Definition: techtools.cpp:1179
#define is_ocean_tile(ptile)
Definition: terrain.h:279
#define terrain_has_flag(terr, flag)
Definition: terrain.h:260
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Remove extra and adjust other extras accordingly.
Definition: tile.cpp:605
#define tile_terrain(_tile)
Definition: tile.h:93
#define TILE_XY(ptile)
Definition: tile.h:36
#define tile_has_extra(ptile, pextra)
Definition: tile.h:130
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
Definition: unit.cpp:1252
int get_transporter_capacity(const struct unit *punit)
Return the number of units the transporter can hold (or 0).
Definition: unit.cpp:280
#define unit_owner(_pu)
Definition: unit.h:370
bool unit_move_handling(struct unit *punit, struct tile *pdesttile, bool igzoc, bool move_do_not_act)
Will try to move to/attack the tile dest_x,dest_y.
Definition: unithand.cpp:4654
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)
Handle unit action.
Definition: unithand.cpp:2718
#define unit_list_iterate(unitlist, punit)
Definition: unitlist.h:25
#define unit_list_iterate_safe(unitlist, _unit)
Definition: unitlist.h:33
#define unit_list_iterate_end
Definition: unitlist.h:27
#define unit_list_iterate_safe_end
Definition: unitlist.h:54
struct unit * create_unit(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left)
Wrapper of the below.
Definition: unittools.cpp:1762
void send_unit_info(struct conn_list *dest, struct unit *punit)
Send the unit to the players who need the info.
Definition: unittools.cpp:2808
struct unit_type * find_a_unit_type(enum unit_role_id role, enum unit_role_id role_tech)
Returns a unit type that matches the role_tech or role roles.
Definition: unittools.cpp:159
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Remove the unit, and passengers if it is a carrying any.
Definition: unittools.cpp:2248
struct unit * create_unit_full(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left, int hp_left, struct unit *ptrans)
Creates a unit, and set it's initial values, and put it into the right lists.
Definition: unittools.cpp:1789
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
Definition: unittype.cpp:1274
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
#define utype_class(_t_)
Definition: unittype.h:691
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition: unittype.h:584