Freeciv21
Develop your civilization from humble roots to a global empire
srv_main.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2021 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 #include <fc_config.h>
15 
16 #include <cstring>
17 // Qt
18 #include <QCoreApplication>
19 #include <QDebug>
20 #include <QElapsedTimer>
21 
22 // utility
23 #include "bitvector.h"
24 #include "bugs.h"
25 #include "fciconv.h"
26 #include "fcintl.h"
27 #include "log.h"
28 #include "rand.h"
29 #include "support.h"
30 #include "timing.h"
31 
32 /* common/aicore */
33 #include "citymap.h"
34 
35 // common
36 #include "achievements.h"
37 #include "calendar.h"
38 #include "city.h"
39 #include "culture.h"
40 #include "dataio_raw.h"
41 #include "effects.h"
42 #include "events.h"
43 #include "fc_interface.h"
44 #include "game.h"
45 #include "map.h"
46 #include "mapimg.h"
47 #include "multipliers.h"
48 #include "nation.h"
49 #include "packets.h"
50 #include "player.h"
51 #include "research.h"
52 #include "style.h"
53 #include "tech.h"
54 #include "unit.h"
55 #include "unitlist.h"
56 #include "victory.h"
57 
58 // server
59 #include "aiiface.h"
60 #include "animals.h"
61 #include "auth.h"
62 #include "barbarian.h"
63 #include "cityhand.h"
64 #include "citytools.h"
65 #include "cityturn.h"
66 #include "connecthand.h"
67 #include "console.h"
68 #include "diplhand.h"
69 #include "edithand.h"
70 #include "fcdb.h"
71 #include "gamehand.h"
72 #include "maphand.h"
73 #include "meta.h"
74 #include "notify.h"
75 #include "plrhand.h"
76 #include "report.h"
77 #include "ruleset.h"
78 #include "sanitycheck.h"
79 #include "score.h"
80 #include "sernet.h"
81 #include "server_settings.h"
82 #include "settings.h"
83 #include "spacerace.h"
84 #include "srv_log.h"
85 #include "stdinhand.h"
86 #include "techtools.h"
87 #include "unittools.h"
88 #include "voting.h"
89 
90 /* server/advisors */
91 #include "advbuilding.h"
92 #include "advdata.h"
93 #include "advspace.h"
94 #include "autosettlers.h"
95 #include "infracache.h"
96 
97 /* server/savegame */
98 #include "savemain.h"
99 
100 /* server/scripting */
101 #include "script_server.h"
102 
103 /* server/generator */
104 #include "mapgen.h"
105 #include "mapgen_utils.h"
106 
107 // ai
108 #include "aitraits.h"
109 #include "difficulty.h"
110 
111 #include "srv_main.h"
112 
113 static void announce_player(struct player *pplayer);
114 
115 static void handle_observer_ready(struct connection *pconn);
116 
117 // command-line arguments to server
118 struct server_arguments srvarg;
119 
120 // server aggregate information
121 struct civserver server;
122 
123 // server state information
124 static enum server_states civserver_state = S_S_INITIAL;
125 
126 /* this global is checked deep down the netcode.
127  packets handling functions can set it to none-zero, to
128  force end-of-tick asap
129 */
131 
132 #define IDENTITY_NUMBER_SIZE 250000
133 BV_DEFINE(bv_identity_numbers, IDENTITY_NUMBER_SIZE);
134 bv_identity_numbers identity_numbers_used;
135 
136 // server initialized flag
137 static bool has_been_srv_init = false;
138 
139 // time server processing at end-of-turn
140 static civtimer *eot_timer = nullptr;
141 
142 static civtimer *between_turns = nullptr;
143 
148 {
149  if (game.server.seed_setting == 0) {
150  game.server.seed = 0;
152  fc_rand_set_init(true);
153  } else {
154  game.server.seed = game.server.seed_setting;
155  fc_srand(game.server.seed);
156  }
157 }
158 
162 void srv_init()
163 {
164  if (has_been_srv_init) {
165  return;
166  }
167 
168  i_am_server(); // Tell to libfreeciv that we are server
169 
170  // NLS init
171  init_nls();
172 #ifdef ENABLE_NLS
173  (void) bindtextdomain("freeciv21-nations", get_locale_dir());
174 #endif
175 
176  // We want this before any AI stuff
177  timing_log_init();
178 
179  /* This must be before command line argument parsing.
180  This allocates default ai, and we want that to take place before
181  loading additional ai modules from command line. */
182  ai_init();
183 
184  // init server arguments...
185 
189 
190  srvarg.port = DEFAULT_SOCK_PORT;
191  srvarg.user_specified_port = false;
192 
193  srvarg.saves_pathname = QStringLiteral("");
194  srvarg.scenarios_pathname = QStringLiteral("");
195 
196  srvarg.quitidle = 0;
197 
198  srvarg.fcdb_enabled = false;
199  srvarg.auth_enabled = false;
200  srvarg.auth_allow_guests = false;
201  srvarg.auth_allow_newusers = false;
202 
203  // mark as initialized
204  has_been_srv_init = true;
205 
206  // init character encodings.
208 #ifdef ENABLE_NLS
209  bind_textdomain_codeset("freeciv21-nations", get_internal_encoding());
210 #endif
211 
212  // Initialize callbacks.
214  // Initialize global mutexes
215  QMutex *mutex = new QMutex;
216  game.server.mutexes.city_list = mutex;
217 }
218 
222 void handle_client_info(struct connection *pc, int obsolete,
223  int emerg_version, const char *distribution)
224 {
225  Q_UNUSED(obsolete);
226 
227  if (emerg_version > 0) {
228  log_debug("It's emergency release .%d", emerg_version);
229  }
230  if (strcmp(distribution, "")) {
231  log_debug("It comes from %s distribution.", distribution);
232  }
233 }
234 
238 enum server_states server_state() { return civserver_state; }
239 
243 void set_server_state(enum server_states newstate)
244 {
245  civserver_state = newstate;
246 }
247 
252 {
253  return (!game.info.is_new_game || S_S_INITIAL != server_state());
254 }
255 
266 {
267  int candidates, defeated;
268  struct player *victor;
269  int winners = 0;
270  QString str;
271 
272  /* Check for scenario victory; dead players can win if they are on a team
273  * with the winners. */
274  players_iterate(pplayer)
275  {
276  if (player_status_check(pplayer, PSTATUS_WINNER)
277  || get_player_bonus(pplayer, EFT_VICTORY) > 0) {
278  if (winners) {
279  // TRANS: Another entry in winners list (", the Tibetans")
280  str = QString(Q_("?winners:, the %1"))
281  .arg(nation_plural_for_player(pplayer));
282  } else {
283  // TRANS: Beginning of the winners list ("the French")
284  str = QString(Q_("?winners:the %1"))
285  .arg(nation_plural_for_player(pplayer));
286  }
287  pplayer->is_winner = true;
288  winners++;
289  }
290  }
292  if (winners) {
293  notify_conn(game.est_connections, nullptr, E_GAME_END, ftc_server,
294  // TRANS: There can be several winners listed
295  _("Scenario victory to %s."), qUtf8Printable(str));
296  return true;
297  }
298 
299  // Count candidates for the victory.
300  candidates = 0;
301  defeated = 0;
302  victor = nullptr;
303  /* Do not use player_iterate_alive here - dead player must be counted as
304  * defeated to end the game with a victory. */
305  players_iterate(pplayer)
306  {
307  if (is_barbarian(pplayer)) {
308  continue;
309  }
310 
311  if ((pplayer)->is_alive
312  && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
313  candidates++;
314  victor = pplayer;
315  } else {
316  defeated++;
317  }
318  }
320 
321  if (0 == candidates) {
322  notify_conn(game.est_connections, nullptr, E_GAME_END, ftc_server,
323  _("Game is over."));
324  return true;
325  } else if (0 < defeated) {
326  /* If nobody conceded the game, it mays be a solo game or a single team
327  * game. */
328  fc_assert(nullptr != victor);
329 
330  // Quit if we have team victory.
331  if (1 < team_count()) {
332  teams_iterate(pteam)
333  {
334  const struct player_list *members = team_members(pteam);
335  int team_candidates = 0, team_defeated = 0;
336 
337  if (1 == player_list_size(members)) {
338  // This is not really a team, single players are handled below.
339  continue;
340  }
341 
342  player_list_iterate(members, pplayer)
343  {
344  if (pplayer->is_alive
345  && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
346  team_candidates++;
347  } else {
348  team_defeated++;
349  }
350  }
352 
353  fc_assert(team_candidates + team_defeated
354  == player_list_size(members));
355 
356  if (team_candidates == candidates && team_defeated < defeated) {
357  // We need a player in a other team to conced the game here.
358  notify_conn(game.est_connections, nullptr, E_GAME_END, ftc_server,
359  _("Team victory to %s."),
360  team_name_translation(pteam));
361  // All players of the team win, even dead and surrended ones.
362  player_list_iterate(members, pplayer)
363  {
364  pplayer->is_winner = true;
365  }
367  return true;
368  }
369  }
371  }
372 
373  // Check for allied victory.
374  if (1 < candidates && victory_enabled(VC_ALLIED)) {
375  struct player_list *winner_list = player_list_new();
376 
377  // Try to build a winner list.
378  players_iterate_alive(pplayer)
379  {
380  if (is_barbarian(pplayer)
381  || player_status_check((pplayer), PSTATUS_SURRENDER)) {
382  continue;
383  }
384 
385  player_list_iterate(winner_list, aplayer)
386  {
387  if (!pplayers_allied(aplayer, pplayer)) {
388  player_list_destroy(winner_list);
389  winner_list = nullptr;
390  break;
391  }
392  }
394 
395  if (nullptr == winner_list) {
396  break;
397  }
398  player_list_append(winner_list, pplayer);
399  }
401 
402  if (nullptr != winner_list) {
403  bool first = true;
404 
405  fc_assert(candidates == player_list_size(winner_list));
406 
407  str = QLatin1String("");
408  player_list_iterate(winner_list, pplayer)
409  {
410  if (first) {
411  // TRANS: Beginning of the winners list ("the French")
412  str += QString(Q_("?winners:the %1"))
413  .arg(nation_plural_for_player(pplayer));
414  first = false;
415  } else {
416  // TRANS: Another entry in winners list (", the Tibetans")
417  str += QString(Q_("?winners:, the %1"))
418  .arg(nation_plural_for_player(pplayer));
419  }
420  pplayer->is_winner = true;
421  }
423  notify_conn(game.est_connections, nullptr, E_GAME_END, ftc_server,
424  // TRANS: There can be several winners listed
425  _("Allied victory to %s."), qUtf8Printable(str));
426  player_list_destroy(winner_list);
427  return true;
428  }
429  }
430 
431  // Check for single player victory.
432  if (1 == candidates && nullptr != victor) {
433  bool found = false; // We need at least one enemy defeated.
434 
435  players_iterate(pplayer)
436  {
437  if (pplayer != victor && !is_barbarian(pplayer)
438  && (!pplayer->is_alive
439  || player_status_check((pplayer), PSTATUS_SURRENDER))
440  && pplayer->team != victor->team
442  || !pplayers_allied(victor, pplayer))) {
443  found = true;
444  break;
445  }
446  }
448 
449  if (found) {
450  notify_conn(game.est_connections, nullptr, E_GAME_END, ftc_server,
451  _("Game ended in conquest victory for %s."),
452  player_name(victor));
453  victor->is_winner = true;
454  return true;
455  }
456  }
457  }
458 
459  // Check for culture victory
461  struct player *best = nullptr;
462  int best_value = -1;
463  int second_value = -1;
464 
465  players_iterate(pplayer)
466  {
467  if (is_barbarian(pplayer) || !pplayer->is_alive) {
468  continue;
469  }
470 
471  if (pplayer->score.culture > best_value) {
472  best = pplayer;
473  second_value = best_value;
474  best_value = pplayer->score.culture;
475  } else if (pplayer->score.culture > second_value) {
476  second_value = pplayer->score.culture;
477  }
478  }
480 
481  if (best != nullptr && best_value >= game.info.culture_vic_points
482  && best_value
483  > second_value * (100 + game.info.culture_vic_lead) / 100) {
484  notify_conn(game.est_connections, nullptr, E_GAME_END, ftc_server,
485  _("Game ended in cultural domination victory for %s."),
486  player_name(best));
487  best->is_winner = true;
488 
489  return true;
490  }
491  }
492 
493  // Quit if we are past the turn limit.
494  if (game.info.turn > game.server.end_turn) {
495  notify_conn(game.est_connections, nullptr, E_GAME_END, ftc_server,
496  _("Game ended as the turn limit was exceeded."));
497  return true;
498  } else if (game.info.turn == game.server.end_turn) {
499  // Give them a chance to decide to extend the game
500  notify_conn(game.est_connections, nullptr, E_GAME_END, ftc_server,
501  _("Notice: game will end at the end of this turn due "
502  "to 'endturn' server setting."));
503  }
504 
505  /* Check for a spacerace win (and notify of imminent arrivals).
506  * Check this after checking turn limit, because we are checking for
507  * the spaceship arriving in the year corresponding to the turn
508  * that's about to start. */
509  {
510  int n, i;
511  struct player *arrivals[MAX_NUM_PLAYER_SLOTS];
512 
513  n = rank_spaceship_arrival(arrivals);
514 
515  for (i = 0; i < n; i++) {
516  struct player *pplayer = arrivals[i];
517  const struct player_list *members;
518  bool win;
519 
520  if (game.info.year < static_cast<int>(spaceship_arrival(pplayer))) {
521  // We are into the future arrivals
522  break;
523  }
524 
525  // Mark as arrived and notify everyone.
526  spaceship_arrived(pplayer);
527 
528  if (!game.server.endspaceship) {
529  /* Games does not end on spaceship arrival. At least print all the
530  * arrival messages. */
531  continue;
532  }
533 
534  // This player has won, now check if anybody else wins with them.
535  members = team_members(pplayer->team);
536  win = false;
537  player_list_iterate(members, pteammate)
538  {
539  if (pplayer->is_alive
540  && !player_status_check((pteammate), PSTATUS_SURRENDER)) {
541  /* We need at least one player to be a winner candidate in the
542  * team. */
543  win = true;
544  break;
545  }
546  }
548 
549  if (!win) {
550  // Let's try next arrival.
551  continue;
552  }
553 
554  if (1 < player_list_size(members)) {
555  notify_conn(nullptr, nullptr, E_GAME_END, ftc_server,
556  _("Team victory to %s."),
557  team_name_translation(pplayer->team));
558  // All players of the team win, even dead and surrendered ones.
559  player_list_iterate(members, pteammate)
560  {
561  pteammate->is_winner = true;
562  }
564  } else {
565  notify_conn(nullptr, nullptr, E_GAME_END, ftc_server,
566  _("Game ended in victory for %s."),
567  player_name(pplayer));
568  pplayer->is_winner = true;
569  }
570  return true;
571  }
572 
573  /* Print notice(s) of imminent arrival. These are not infallible
574  * (quite apart from risk of enemy action) because arrival is
575  * year-based, and some effect may change the timeline between
576  * now and the end of the next turn.
577  * (Also the order of messages will not always indicate tie-breaks,
578  * if the shuffled order is changed every turn, as it is for
579  * PMT_CONCURRENT games.) */
580  for (; i < n; i++) {
581  const struct player *pplayer = arrivals[i];
582  struct packet_game_info next_info = game.info; // struct copy
583 
584  // Advance the calendar in a throwaway copy of game.info.
585  game_next_year(&next_info);
586 
587  if (next_info.year < static_cast<int>(spaceship_arrival(pplayer))) {
588  // Even further in the future
589  break;
590  }
591 
592  notify_player(nullptr, nullptr, E_SPACESHIP, ftc_server,
593  _("Notice: the %s spaceship will likely arrive at "
594  "Alpha Centauri next turn."),
595  nation_adjective_for_player(pplayer));
596  }
597  }
598 
599  return false;
600 }
601 
607 void send_all_info(struct conn_list *dest)
608 {
609  conn_list_iterate(dest, pconn)
610  {
611  if (conn_controls_player(pconn)) {
612  send_attribute_block(pconn->playing, pconn);
613  }
614  }
616 
617  // Resend player info because it could have more infos (e.g. embassy).
618  send_player_all_c(nullptr, dest);
619  for (const auto &presearch : research_array) {
620  if (research_is_valid(presearch)) {
621  send_research_info(&presearch, dest);
622  }
623  };
624  send_map_info(dest);
625  send_all_known_tiles(dest);
626  send_all_known_cities(dest);
627  send_all_known_units(dest);
628  send_spaceship_info(nullptr, dest);
629 
632 }
633 
638 static void do_reveal_effects()
639 {
640  phase_players_iterate(pplayer)
641  {
642  if (get_player_bonus(pplayer, EFT_REVEAL_CITIES) > 0) {
643  players_iterate(other_player)
644  {
645  city_list_iterate(other_player->cities, pcity)
646  {
647  map_show_tile(pplayer, pcity->tile);
648  }
650  }
652  }
653  if (get_player_bonus(pplayer, EFT_REVEAL_MAP) > 0) {
654  /* map_know_all will mark all unknown tiles as known and send
655  * tile, unit, and city updates as necessary. No other actions are
656  * needed. */
657  map_show_all(pplayer);
658  }
659  }
661 }
662 
668 {
669  phase_players_iterate(pplayer)
670  {
671  if (get_player_bonus(pplayer, EFT_HAVE_CONTACTS) > 0) {
672  players_iterate(pother)
673  {
674  /* Note this gives pplayer contact with pother, but doesn't give
675  * pother contact with pplayer. This may cause problems in other
676  * parts of the code if we're not careful. */
677  make_contact(pplayer, pother, nullptr);
678  }
680  }
681  }
683 }
684 
689 {
690  if (game.info.borders != BORDERS_ENABLED) {
691  /* Border_Vision is useless. If borders are disabled there are no
692  * borders to see inside. If borders are seen they are seen already.
693  * The borders setting can't change after the game has started. */
694  return;
695  }
696 
698  {
699  bool new_border_vision;
700 
701  // Check the Border_Vision effect for this player.
702  new_border_vision = (0 < get_player_bonus(plr, EFT_BORDER_VISION));
703 
704  if (new_border_vision != plr->server.border_vision) {
705  // Border vision changed.
706 
707  // Update the map
708  map_set_border_vision(plr, new_border_vision);
709  }
710  }
712 }
713 
718  int *current, int *accum, int *level,
719  int percent,
720  void (*upset_action_fn)(int))
721 {
722  int count;
723 
724  count = 0;
725  extra_type_iterate(cause)
726  {
727  if (extra_causes_env_upset(cause, type)) {
728  whole_map_iterate(&(wld.map), ptile)
729  {
730  if (tile_has_extra(ptile, cause)) {
731  count++;
732  }
733  }
735  }
736  }
738 
739  *current = (count * percent) / 100;
740  *accum += count;
741  if (*accum < *level) {
742  *accum = 0;
743  } else {
744  *accum -= *level;
745  if (fc_rand((map_num_tiles() + 19) / 20) < *accum) {
746  upset_action_fn((wld.map.xsize / 10) + (wld.map.ysize / 10)
747  + ((*accum) * 5));
748  *accum = 0;
749  *level += (map_num_tiles() + 999) / 1000;
750  }
751  }
752 
753  log_debug("environmental_upset: type=%-4d current=%-2d "
754  "level=%-2d accum=%-2d",
755  type, *current, *level, *accum);
756 }
757 
761 static void notify_illegal_armistice_units(struct player *phost,
762  struct player *pguest,
763  int turns_left)
764 {
765  int nunits = 0;
766  struct unit *a_unit = nullptr;
767 
768  unit_list_iterate(pguest->units, punit)
769  {
770  if (tile_owner(unit_tile(punit)) == phost && is_military_unit(punit)) {
771  nunits++;
772  a_unit = punit;
773  }
774  }
776  if (nunits > 0) {
777  // TRANS: "... 2 military units in Norwegian territory."
778  QString unitstr =
779  QString(
780  PL_("Warning: you still have %1 military unit in %2 territory.",
781  "Warning: you still have %1 military units in %2 territory.",
782  nunits))
783  .arg(QString::number(nunits),
785  /* If there's one lousy unit left, we may as well include a link for it
786  */
787  notify_player(pguest, nunits == 1 ? unit_tile(a_unit) : nullptr,
788  E_DIPLOMACY, ftc_server,
789  /* TRANS: %s is another, separately translated sentence,
790  * ending in a full stop. */
791  PL_("%s Any such units will be disbanded in %d turn, "
792  "in accordance with peace treaty.",
793  "%s Any such units will be disbanded in %d turns, "
794  "in accordance with peace treaty.",
795  turns_left),
796  qUtf8Printable(unitstr), turns_left);
797  }
798 }
799 
803 static void remove_illegal_armistice_units(struct player *plr1,
804  struct player *plr2)
805 {
806  // Remove illegal units
807  unit_list_iterate_safe(plr1->units, punit)
808  {
809  if (tile_owner(unit_tile(punit)) == plr2 && is_military_unit(punit)) {
810  notify_player(plr1, unit_tile(punit), E_DIPLOMACY, ftc_server,
811  _("Your %s was disbanded in accordance with "
812  "your peace treaty with the %s."),
814  wipe_unit(punit, ULR_ARMISTICE, nullptr);
815  }
816  }
818  unit_list_iterate_safe(plr2->units, punit)
819  {
820  if (tile_owner(unit_tile(punit)) == plr1 && is_military_unit(punit)) {
821  notify_player(plr2, unit_tile(punit), E_DIPLOMACY, ftc_server,
822  _("Your %s was disbanded in accordance with "
823  "your peace treaty with the %s."),
825  wipe_unit(punit, ULR_ARMISTICE, nullptr);
826  }
827  }
829 }
830 
835 static void update_diplomatics()
836 {
837  players_iterate(plr1)
838  {
839  players_iterate(plr2)
840  {
841  struct player_diplstate *state = player_diplstate_get(plr1, plr2);
842 
843  /* Players might just met when first of them was being handled
844  * (pact with third player changed and units got bounced next
845  * to second unit to form first contact)
846  * Do not decrease the counters for the other player yet in this turn
847  */
848  if (state->first_contact_turn != game.info.turn) {
849  struct player_diplstate *state2 = player_diplstate_get(plr2, plr1);
850 
851  state->has_reason_to_cancel =
852  MAX(state->has_reason_to_cancel - 1, 0);
853  state->contact_turns_left = MAX(state->contact_turns_left - 1, 0);
854 
855  if (state->type == DS_ARMISTICE
856  /* Don't count down if auto canceled this turn. Auto canceling
857  * happens in this loop. */
858  && state->auto_cancel_turn != game.info.turn) {
859  state->turns_left--;
860  if (state->turns_left <= 0) {
861  state->type = DS_PEACE;
862  state2->type = DS_PEACE;
863  state->turns_left = 0;
864  state2->turns_left = 0;
865  remove_illegal_armistice_units(plr1, plr2);
866  } else {
867  notify_illegal_armistice_units(plr1, plr2, state->turns_left);
868  }
869  }
870 
871  if (state->type == DS_CEASEFIRE) {
872  state->turns_left--;
873  switch (state->turns_left) {
874  case 1:
876  plr1, nullptr, E_DIPLOMACY, ftc_server,
877  _("Concerned citizens point out that the cease-fire "
878  "with %s will run out soon."),
879  player_name(plr2));
880  /* Message to plr2 will be done when plr1 and plr2 will be
881  * swapped. Else, we will get a message duplication. Note the
882  * case is not the below, because the state will be changed for
883  * both players to war. */
884  break;
885  case 0:
886  /* Automatically extend cease-fires, if both parties share
887  * common allies. We only handle this if both parties are
888  * human, as AI doesn't know how to cancel alliances to
889  * enter war if desired and might get caught in an eternal
890  * cease-fire. */
891  if (is_human(plr1) && is_human(plr2)) {
892  bool extend_ceasefire = false;
893 
895  {
896  if (plr3 != plr1 && plr3 != plr2
897  && pplayers_allied(plr3, plr1)
898  && pplayers_allied(plr3, plr2)) {
900  plr1, nullptr, E_DIPLOMACY, ftc_server,
901  _("The cease-fire with %s would have run out, but "
902  "your common ally %s convinces you to extend it."),
903  player_name(plr2), player_name(plr3));
904 
905  extend_ceasefire = true;
906  }
907  }
909 
910  if (extend_ceasefire) {
911  // Extend cease-fire
913  continue;
914  }
915  }
916 
917  // cease-fire has run out.
918  notify_player(plr1, nullptr, E_DIPLOMACY, ftc_server,
919  _("The cease-fire with %s has run out. "
920  "You are now at war with the %s."),
922  notify_player(plr2, nullptr, E_DIPLOMACY, ftc_server,
923  _("The cease-fire with %s has run out. "
924  "You are now at war with the %s."),
926  state->type = DS_WAR;
927  state2->type = DS_WAR;
928  state->turns_left = 0;
929  state2->turns_left = 0;
930 
931  enter_war(plr1, plr2);
932 
935  sync_cities();
936 
937  // Avoid love-love-hate triangles
939  {
940  if (plr3 != plr1 && plr3 != plr2 && pplayers_allied(plr3, plr1)
941  && pplayers_allied(plr3, plr2)) {
942  struct player_diplstate *to1 =
943  player_diplstate_get(plr3, plr1);
944  struct player_diplstate *from1 =
945  player_diplstate_get(plr1, plr3);
946  struct player_diplstate *to2 =
947  player_diplstate_get(plr3, plr2);
948  struct player_diplstate *from2 =
949  player_diplstate_get(plr2, plr3);
950  const char *plr1name = player_name(plr1);
951  const char *plr2name = player_name(plr2);
952  bool cancel1;
953  bool cancel2;
954 
955  if (players_on_same_team(plr3, plr1)) {
956  fc_assert(!players_on_same_team(plr3, plr2));
957 
958  cancel1 = false;
959  cancel2 = true;
960 
962  plr3, nullptr, E_TREATY_BROKEN, ftc_server,
963  _("The cease-fire between %s and %s has run out. "
964  "They are at war. You cancel your alliance "
965  "with %s."),
966  plr1name, plr2name, plr2name);
967  } else if (players_on_same_team(plr3, plr2)) {
968  cancel1 = true;
969  cancel2 = false;
970 
972  plr3, nullptr, E_TREATY_BROKEN, ftc_server,
973  _("The cease-fire between %s and %s has run out. "
974  "They are at war. You cancel your alliance "
975  "with %s."),
976  plr1name, plr2name, plr1name);
977  } else {
978  cancel1 = true;
979  cancel2 = true;
980 
982  plr3, nullptr, E_TREATY_BROKEN, ftc_server,
983  _("The cease-fire between %s and %s has run out. "
984  "They are at war. You cancel your alliance "
985  "with both."),
986  player_name(plr1), player_name(plr2));
987  }
988 
989  if (cancel1) {
990  // Cancel the alliance.
991  to1->has_reason_to_cancel = 1;
993  plr3, player_number(plr1), CLAUSE_ALLIANCE, false);
994 
995  // Avoid asymmetric turns_left for the armistice.
996  to1->auto_cancel_turn = game.info.turn;
997  from1->auto_cancel_turn = game.info.turn;
998 
999  // Count down for this turn.
1000  to1->turns_left--;
1001  from1->turns_left--;
1002  }
1003 
1004  if (cancel2) {
1005  // Cancel the alliance.
1006  to2->has_reason_to_cancel = 1;
1008  plr3, player_number(plr2), CLAUSE_ALLIANCE, false);
1009 
1010  // Avoid asymmetric turns_left for the armistice.
1011  to2->auto_cancel_turn = game.info.turn;
1012  from2->auto_cancel_turn = game.info.turn;
1013 
1014  // Count down for this turn.
1015  to2->turns_left--;
1016  from2->turns_left--;
1017  }
1018  }
1019  }
1021  break;
1022  }
1023  }
1024  }
1025  }
1027  }
1029 }
1030 
1038 static void kill_dying_players()
1039 {
1040  bool voter_died = false;
1041 
1042  players_iterate_alive(pplayer)
1043  {
1044  // cities or units remain?
1045  if (0 == city_list_size(pplayer->cities)
1046  && 0 == unit_list_size(pplayer->units)) {
1047  player_status_add(pplayer, PSTATUS_DYING);
1048  }
1049  // also UTYF_GAMELOSS in unittools server_remove_unit()
1050  if (player_status_check(pplayer, PSTATUS_DYING)) {
1051  // Can't get more dead than this.
1052  voter_died = voter_died || pplayer->is_connected;
1053  kill_player(pplayer);
1054  }
1055  }
1057 
1058  if (voter_died) {
1059  send_updated_vote_totals(nullptr);
1060  }
1061 }
1062 
1066 static void ai_start_phase()
1067 {
1068  phase_players_iterate(pplayer)
1069  {
1070  if (is_ai(pplayer)) {
1071  CALL_PLR_AI_FUNC(first_activities, pplayer, pplayer);
1072  }
1073  }
1076 }
1077 
1083 void begin_turn(bool is_new_turn)
1084 {
1085  QElapsedTimer timer;
1086  timer.start();
1087  log_debug("Begin turn");
1088 
1090 
1091  // Reset this each turn.
1092  if (is_new_turn) {
1093  if (game.info.phase_mode != game.server.phase_mode_stored) {
1095  game.info.phase_mode = phase_mode_type(game.server.phase_mode_stored);
1096  }
1097  }
1098 
1099  // NB: Phase logic must match is_player_phase().
1100  switch (game.info.phase_mode) {
1101  case PMT_CONCURRENT:
1102  game.server.num_phases = 1;
1103  break;
1104  case PMT_PLAYERS_ALTERNATE:
1105  game.server.num_phases = player_count();
1106  break;
1107  case PMT_TEAMS_ALTERNATE:
1108  game.server.num_phases = team_count();
1109  break;
1110  default:
1111  qCritical("Unrecognized phase mode %d in begin_turn().",
1112  game.info.phase_mode);
1113  game.server.num_phases = 1;
1114  break;
1115  }
1116  send_game_info(nullptr);
1117 
1118  if (is_new_turn) {
1119  script_server_signal_emit("turn_begin", game.info.turn, game.info.year);
1120  script_server_signal_emit("turn_started",
1121  game.info.turn > 0 ? game.info.turn - 1
1122  : game.info.turn,
1123  game.info.year);
1124 
1125  /* We build scores at the beginning of every turn. We have to
1126  * build them at the beginning so that the AI can use the data,
1127  * and we are sure to have it when we need it. */
1128  players_iterate(pplayer) { calc_civ_score(pplayer); }
1131 
1132  // Retire useless barbarian units
1133  players_iterate(pplayer)
1134  {
1135  unit_list_iterate_safe(pplayer->units, punit)
1136  {
1137  struct tile *ptile = punit->tile;
1138 
1139  if (unit_can_be_retired(punit)
1140  && fc_rand(100) < get_unit_bonus(punit, EFT_RETIRE_PCT)) {
1141  notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server,
1142  // TRANS: %s is a unit type
1143  _("%s retired!"), unit_tile_link(punit));
1144  wipe_unit(punit, ULR_RETIRED, nullptr);
1145  continue;
1146  }
1147  }
1149  }
1151  }
1152 
1153  /* find out if users attached to players have been attached to those
1154  * players for long enough. The first user to do so becomes "associated" to
1155  * that player for ranking purposes. */
1156  players_iterate(pplayer)
1157  {
1158  if (pplayer->unassigned_ranked
1159  && pplayer->user_turns++ > TURNS_NEEDED_TO_RANK
1160  && pplayer->is_alive) {
1161  sz_strlcpy(pplayer->ranked_username, pplayer->username);
1162  pplayer->unassigned_ranked = pplayer->unassigned_user;
1163  }
1164  }
1166 
1167  if (is_new_turn) {
1168  // See if the value of fog of war has changed
1169  if (game.info.fogofwar != game.server.fogofwar_old) {
1170  if (game.info.fogofwar) {
1172  game.server.fogofwar_old = true;
1173  } else {
1175  game.server.fogofwar_old = false;
1176  }
1177  }
1178 
1179  if (game.info.phase_mode == PMT_CONCURRENT) {
1180  log_debug("Shuffleplayers");
1181  shuffle_players();
1182  }
1183 
1184  game.info.phase = 0;
1185  }
1186 
1187  sanity_check();
1188 
1189  if (game.server.num_phases != 1) {
1190  // We allow everyone to begin adjusting cities and such
1191  // from the beginning of the turn.
1192  // With simultaneous movement we send begin_turn packet in
1193  // begin_phase() only after AI players have finished their actions.
1194  lsend_packet_begin_turn(game.est_connections);
1195  }
1196  log_time(
1197  QStringLiteral("Begin turn:%1 milliseconds").arg(timer.elapsed()));
1198 }
1199 
1203 static int unit_wait_cmp(const struct unit_wait *const *a,
1204  const struct unit_wait *const *b)
1205 {
1206  return (*a)->wake_up > (*b)->wake_up;
1207 }
1208 
1213 void begin_phase(bool is_new_phase)
1214 {
1215  QElapsedTimer timer;
1216  timer.start();
1217  log_debug("Begin phase");
1218 
1220 
1221  phase_players_iterate(pplayer)
1222  {
1223  if (is_new_phase || !game.server.turnblock) {
1224  // Otherwise respect what was loaded from the savegame.
1225  pplayer->phase_done = false;
1226  }
1227  pplayer->ai_phase_done = false;
1228  }
1230  send_player_all_c(nullptr, nullptr);
1231 
1232  dlsend_packet_start_phase(game.est_connections, game.info.phase);
1233 
1234  if (!is_new_phase) {
1236  {
1237  send_diplomatic_meetings(pconn);
1238  }
1240  }
1241 
1242  // Must be the first thing as it is needed for lots of functions below!
1243  phase_players_iterate(pplayer)
1244  {
1245  // human players also need this for building advice
1246  adv_data_phase_init(pplayer, is_new_phase);
1247  CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, is_new_phase);
1248  }
1250 
1251  if (is_new_phase) {
1252  /* Unit "end of turn" activities - of course these actually go at
1253  * the start of the turn! */
1254  unit_wait_list_clear(server.unit_waits);
1255 
1256  whole_map_iterate(&(wld.map), ptile)
1257  {
1258  if (ptile->placing != nullptr) {
1259  struct player *owner = nullptr;
1260 
1261  if (game.info.borders != BORDERS_DISABLED) {
1262  owner = tile_owner(ptile);
1263  } else {
1264  struct city *pcity = tile_worked(ptile);
1265 
1266  if (pcity != nullptr) {
1267  owner = city_owner(pcity);
1268  }
1269  }
1270 
1271  if (owner == nullptr) {
1272  // Abandoned extra placing, clear it.
1273  ptile->placing = nullptr;
1274  } else {
1275  if (is_player_phase(owner, game.info.phase)) {
1276  fc_assert(ptile->infra_turns > 0);
1277 
1278  ptile->infra_turns--;
1279  if (ptile->infra_turns <= 0) {
1280  create_extra(ptile, ptile->placing, owner);
1281  ptile->placing = nullptr;
1282 
1283  /* Since extra has been added, tile is certainly
1284  * sent by update_tile_knowledge() including the
1285  * placing info, though it would not sent it if placing
1286  * were the only thing changed. */
1287  update_tile_knowledge(ptile);
1288  }
1289  }
1290  }
1291  }
1292  }
1294  phase_players_iterate(pplayer)
1295  {
1296  update_unit_activities(pplayer);
1297  flush_packets();
1298  }
1300 
1301  unit_wait_list_sort(server.unit_waits, unit_wait_cmp);
1302  unit_wait_list_link_iterate(server.unit_waits, plink)
1303  {
1304  struct unit *punit =
1305  game_unit_by_number(unit_wait_list_link_data(plink)->id);
1306  if (punit) {
1307  punit->server.wait = plink;
1308  }
1309  }
1311 
1312  /* Execute orders after activities have been completed (roads built,
1313  * pillage done, etc.). */
1314  phase_players_iterate(pplayer)
1315  {
1316  execute_unit_orders(pplayer);
1317  flush_packets();
1318  }
1320  phase_players_iterate(pplayer)
1321  {
1323  }
1325  flush_packets();
1326  }
1327 
1328  phase_players_iterate(pplayer)
1329  {
1330  log_debug("beginning player turn for #%d (%s)", player_number(pplayer),
1331  player_name(pplayer));
1332  if (is_human(pplayer)) {
1333  building_advisor(pplayer);
1334  }
1335  }
1337 
1338  phase_players_iterate(pplayer) { send_player_cities(pplayer); }
1340 
1341  flush_packets(); // to curb major city spam
1343 
1345  {
1346  update_revolution(pplayer);
1347  update_capital(pplayer);
1348  }
1350 
1351  if (is_new_phase) {
1352  // Try to avoid hiding events under a diplomacy dialog
1353  phase_players_iterate(pplayer)
1354  {
1355  if (is_ai(pplayer)) {
1356  CALL_PLR_AI_FUNC(diplomacy_actions, pplayer, pplayer);
1357  }
1358  }
1360 
1361  log_debug("Aistartturn");
1362  ai_start_phase();
1363  } else {
1364  phase_players_iterate(pplayer)
1365  {
1366  if (is_ai(pplayer)) {
1367  CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
1368  }
1369  }
1371  }
1372 
1373  sanity_check();
1374 
1375  game.tinfo.last_turn_change_time = game.server.turn_change_time;
1376  game.tinfo.seconds_to_phasedone =
1377  static_cast<double>(current_turn_timeout());
1378  game.server.phase_timer =
1380  timer_start(game.server.phase_timer);
1381  send_game_info(nullptr);
1382 
1383  if (game.server.num_phases == 1) {
1384  /* All players in the same phase.
1385  * This means that AI has been handled above, and server
1386  * will be responsive again */
1387  lsend_packet_begin_turn(game.est_connections);
1388  }
1389  log_time(
1390  QStringLiteral("Start phase:%1 milliseconds").arg(timer.elapsed()));
1391 }
1392 
1398 {
1399  QElapsedTimer timer;
1400  timer.start();
1401  log_debug("Endphase");
1402 
1403  /*
1404  * This empties the client Messages window; put this before
1405  * everything else below, since otherwise any messages from the
1406  * following parts get wiped out before the user gets a chance to
1407  * see them. --dwp
1408  */
1409  phase_players_iterate(pplayer)
1410  {
1411  /* Unlike the start_phase packet we only send this one to the active
1412  * player. */
1413  lsend_packet_end_phase(pplayer->connections);
1414  }
1416 
1417  /* Enact any policy changes.
1418  * Do this first so that following end-phase activities take the
1419  * change into account. */
1420  phase_players_iterate(pplayer)
1421  {
1422  multipliers_iterate(pmul)
1423  {
1424  int idx = multiplier_index(pmul);
1425 
1426  if (!multiplier_can_be_changed(pmul, pplayer)) {
1427  if (pplayer->multipliers[idx] != pmul->def) {
1428  notify_player(pplayer, nullptr, E_MULTIPLIER, ftc_server,
1429  _("%s restored to the default value %d"),
1430  multiplier_name_translation(pmul), pmul->def);
1431  pplayer->multipliers[idx] = pmul->def;
1432  }
1433  } else {
1434  if (pplayer->multipliers[idx] != pplayer->multipliers_target[idx]) {
1435  notify_player(pplayer, nullptr, E_MULTIPLIER, ftc_server,
1436  _("%s now at value %d"),
1438  pplayer->multipliers_target[idx]);
1439 
1440  pplayer->multipliers[idx] = pplayer->multipliers_target[idx];
1441  }
1442  }
1443  }
1445  }
1447 
1448  phase_players_iterate(pplayer)
1449  {
1450  struct research *presearch = research_get(pplayer);
1451 
1452  if (A_UNSET == presearch->researching) {
1453  Tech_type_id next_tech =
1454  research_goal_step(presearch, presearch->tech_goal);
1455 
1456  if (A_UNSET != next_tech) {
1457  choose_tech(presearch, next_tech);
1458  } else {
1459  choose_random_tech(presearch);
1460  }
1461  /* add the researched bulbs to the pool; do *NOT* checvk for finished
1462  * research */
1463  update_bulbs(pplayer, 0, false);
1464  }
1465  }
1467 
1468  // Freeze sending of cities.
1469  send_city_suppression(true);
1470 
1471  // AI end of turn activities
1472  players_iterate(pplayer)
1473  {
1474  unit_list_iterate(pplayer->units, punit)
1475  {
1476  CALL_PLR_AI_FUNC(unit_turn_end, pplayer, punit);
1477  }
1479  }
1481  phase_players_iterate(pplayer)
1482  {
1483  auto_settlers_player(pplayer);
1484  if (is_ai(pplayer)) {
1485  CALL_PLR_AI_FUNC(last_activities, pplayer, pplayer);
1486  }
1487  }
1489 
1490  // Refresh cities
1491  phase_players_iterate(pplayer)
1492  {
1493  research_get(pplayer)->got_tech = false;
1494  research_get(pplayer)->got_tech_multi = false;
1495  }
1497 
1499  {
1500  do_tech_parasite_effect(pplayer);
1501  player_restore_units(pplayer);
1502 
1503  /* If player finished spaceship parts last turn already, and didn't place
1504  * them during this entire turn, autoplace them. */
1505  if (adv_spaceship_autoplace(pplayer, &pplayer->spaceship)) {
1506  notify_player(pplayer, nullptr, E_SPACESHIP, ftc_server,
1507  _("Automatically placed spaceship parts that were still "
1508  "not placed."));
1509  }
1510 
1511  update_city_activities(pplayer);
1513  pplayer->history += nation_history_gain(pplayer);
1515  /* reduce the number of bulbs by the amount needed for tech upkeep and
1516  * check for finished research */
1517  update_bulbs(pplayer, -player_tech_upkeep(pplayer), true);
1518  flush_packets();
1519  }
1521 
1522  /* Some player/global effect may have changed cities' vision range */
1525 
1527 
1528  // Unfreeze sending of cities.
1529  send_city_suppression(false);
1530 
1531  phase_players_iterate(pplayer) { send_player_cities(pplayer); }
1533  flush_packets(); // to curb major city spam
1534 
1538 
1539  phase_players_iterate(pplayer)
1540  {
1541  CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1542  // This has to be after all access to advisor data.
1543  /* We used to run this for ai players only, but data phase
1544  is initialized for human players also. */
1545  adv_data_phase_done(pplayer);
1546  }
1548  log_time(QStringLiteral("End phase:%1 milliseconds").arg(timer.elapsed()));
1549 }
1550 
1554 void end_turn()
1555 {
1556  QElapsedTimer timer;
1557  timer.start();
1558  log_debug("Endturn");
1559 
1560  /* Hack: because observer players never get an end-phase packet we send
1561  * one here. */
1563  {
1564  if (nullptr == pconn->playing) {
1565  send_packet_end_phase(pconn);
1566  }
1567  }
1569 
1570  lsend_packet_end_turn(game.est_connections);
1571 
1573 
1574  // Output some AI measurement information
1575  players_iterate(pplayer)
1576  {
1577  if (!is_ai(pplayer) || is_barbarian(pplayer)) {
1578  continue;
1579  }
1580  int settlers = 0;
1581  unit_list_iterate(pplayer->units, punit)
1582  {
1583  if (unit_is_cityfounder(punit)) {
1584  settlers++;
1585  }
1586  }
1588  int food = 0, shields = 0, trade = 0;
1589  city_list_iterate(pplayer->cities, pcity)
1590  {
1591  shields += pcity->prod[O_SHIELD];
1592  food += pcity->prod[O_FOOD];
1593  trade += pcity->prod[O_TRADE];
1594  }
1596  log_debug("%s T%d cities:%d pop:%d food:%d prod:%d "
1597  "trade:%d settlers:%d units:%d",
1598  player_name(pplayer), game.info.turn,
1599  city_list_size(pplayer->cities),
1600  total_player_citizens(pplayer), food, shields, trade, settlers,
1601  unit_list_size(pplayer->units));
1602  }
1604 
1605  log_debug("Season of native unrests");
1606  summon_barbarians(); /* wild guess really, no idea where to put it, but
1607  * I want to give them chance to move their units */
1608 
1609  if (game.server.migration) {
1610  log_debug("Season of migrations");
1611  if (check_city_migrations()) {
1612  /* Make sure everyone has updated information about BOTH ends of the
1613  * migration movements. */
1614  players_iterate(plr)
1615  {
1616  city_list_iterate(plr->cities, pcity)
1617  {
1618  send_city_info(nullptr, pcity);
1619  }
1621  }
1623  }
1624  }
1625 
1626  check_disasters();
1627 
1628  /* Check for new achievements during the turn.
1629  * This is not within phase, as multiple players may
1630  * achieve at the same turn and everyone deserves equal opportunity
1631  * to win. */
1633  {
1634  struct player_list *achievers = player_list_new();
1635  struct player *first = achievement_plr(ach, achievers);
1636  struct packet_achievement_info pack;
1637 
1638  pack.id = achievement_index(ach);
1639  pack.gained = true;
1640 
1641  if (first != nullptr) {
1642  notify_player(first, nullptr, E_ACHIEVEMENT, ftc_server, "%s",
1643  achievement_first_msg(ach));
1644 
1645  pack.first = true;
1646 
1647  lsend_packet_achievement_info(first->connections, &pack);
1648 
1649  script_server_signal_emit("achievement_gained", ach, first, true);
1650  }
1651 
1652  pack.first = false;
1653 
1654  if (!ach->unique) {
1655  player_list_iterate(achievers, pplayer)
1656  {
1657  // Message already sent to first one
1658  if (pplayer != first) {
1659  notify_player(pplayer, nullptr, E_ACHIEVEMENT, ftc_server, "%s",
1660  achievement_later_msg(ach));
1661 
1662  lsend_packet_achievement_info(pplayer->connections, &pack);
1663 
1664  script_server_signal_emit("achievement_gained", ach, pplayer,
1665  false);
1666  }
1667  }
1669  }
1670 
1671  player_list_destroy(achievers);
1672  }
1674 
1675  if (game.info.global_warming) {
1677  EUT_GLOBAL_WARMING, &game.info.heating, &game.info.globalwarming,
1678  &game.info.warminglevel, game.server.global_warming_percent,
1679  global_warming);
1680  }
1681 
1682  if (game.info.nuclear_winter) {
1684  EUT_NUCLEAR_WINTER, &game.info.cooling, &game.info.nuclearwinter,
1685  &game.info.coolinglevel, game.server.nuclear_winter_percent,
1686  nuclear_winter);
1687  }
1688 
1689  /* Handle disappearing extras before appearing extras ->
1690  * Extra never appears only to disappear at the same turn,
1691  * but it can disappear and reappear. */
1692  extra_type_by_rmcause_iterate(ERM_DISAPPEARANCE, pextra)
1693  {
1694  whole_map_iterate(&(wld.map), ptile)
1695  {
1696  if (tile_has_extra(ptile, pextra)
1697  && fc_rand(10000) < pextra->disappearance_chance
1698  && can_extra_disappear(pextra, ptile)) {
1699  tile_extra_rm_apply(ptile, pextra);
1700 
1701  update_tile_knowledge(ptile);
1702 
1703  if (tile_owner(ptile) != nullptr) {
1704  /* TODO: Should notify players nearby even when borders disabled,
1705  * like in case of barbarian uprising */
1706  notify_player(tile_owner(ptile), ptile, E_SPONTANEOUS_EXTRA,
1707  ftc_server,
1708  // TRANS: Small Fish disappears from (32, 72).
1709  _("%s disappears from %s."),
1710  extra_name_translation(pextra), tile_link(ptile));
1711  }
1712 
1713  /* Unit activities at the target tile and its neighbors may now
1714  * be illegal because of present reqs. */
1716  }
1717  }
1719  }
1721 
1722  extra_type_by_cause_iterate(EC_APPEARANCE, pextra)
1723  {
1724  whole_map_iterate(&(wld.map), ptile)
1725  {
1726  if (!tile_has_extra(ptile, pextra)
1727  && fc_rand(10000) < pextra->appearance_chance
1728  && can_extra_appear(pextra, ptile)) {
1729  tile_extra_apply(ptile, pextra);
1730 
1731  update_tile_knowledge(ptile);
1732 
1733  if (tile_owner(ptile) != nullptr) {
1734  /* TODO: Should notify players nearby even when borders disabled,
1735  * like in case of barbarian uprising */
1736  notify_player(tile_owner(ptile), ptile, E_SPONTANEOUS_EXTRA,
1737  ftc_server,
1738  // TRANS: Small Fish appears to (32, 72).
1739  _("%s appears to %s."),
1740  extra_name_translation(pextra), tile_link(ptile));
1741  }
1742 
1743  /* Unit activities at the target tile and its neighbors may now
1744  * be illegal because of !present reqs. */
1746  }
1747  }
1749  }
1751 
1754  settings_turn();
1755  stdinhand_turn();
1756  voting_turn();
1758 
1759  log_debug("Gamenextyear");
1761  players_iterate_alive(pplayer) { pplayer->turns_alive++; }
1763 
1764  log_debug("Updatetimeout");
1765  update_timeout();
1766 
1767  log_debug("Sendgameinfo");
1768  send_game_info(nullptr);
1769 
1770  log_debug("Sendplayerinfo");
1771  send_player_all_c(nullptr, nullptr);
1772 
1773  log_debug("Sendresearchinfo");
1774  for (const auto &presearch : research_array) {
1775  if (research_is_valid(presearch)) {
1776  send_research_info(&presearch, nullptr);
1777  }
1778  };
1779 
1780  log_debug("Sendyeartoclients");
1782  log_time(QStringLiteral("End turn:%1 milliseconds").arg(timer.elapsed()));
1783 }
1784 
1788 void save_game_auto(const char *save_reason, enum autosave_type type)
1789 {
1790  char filename[512];
1791  const char *reason_filename = nullptr;
1792 
1793  if (!(game.server.autosaves & (1 << type))) {
1794  return;
1795  }
1796 
1797  switch (type) {
1798  case AS_TURN:
1799  reason_filename = nullptr;
1800  break;
1801  case AS_GAME_OVER:
1802  reason_filename = "final";
1803  break;
1804  case AS_QUITIDLE:
1805  reason_filename = "quitidle";
1806  break;
1807  case AS_INTERRUPT:
1808  reason_filename = "interrupted";
1809  break;
1810  case AS_TIMER:
1811  reason_filename = "timer";
1812  break;
1813  }
1814 
1815  fc_assert(256 > qstrlen(game.server.save_name));
1816 
1817  if (type != AS_TIMER) {
1818  generate_save_name(game.server.save_name, filename, sizeof(filename),
1819  reason_filename);
1820  } else {
1821  fc_snprintf(filename, sizeof(filename), "%s-timer",
1822  game.server.save_name);
1823  }
1824  save_game(filename, save_reason, false);
1825 }
1826 
1831 {
1832  if (S_S_INITIAL != server_state()) {
1833  con_puts(C_SYNTAX, _("The game is already running."));
1834  return;
1835  }
1836 
1837  // Remove ALLOW_CTRL from whoever has it (gotten from 'first').
1839  {
1840  if (pconn->access_level == ALLOW_CTRL) {
1841  notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
1842  _("%s lost control cmdlevel on "
1843  "game start. Use voting from now on."),
1844  pconn->username);
1845  conn_set_access(pconn, ALLOW_BASIC, false);
1846  }
1847  }
1850 
1851  con_puts(C_OK, _("Starting game."));
1852 
1853  // Prevent problems with commands that only make sense in pregame.
1854  clear_all_votes();
1855 
1856  /* This value defines if the player data should be saved for a scenario. It
1857  * is only FALSE if the editor was used to set it to this value. For
1858  * such scenarios it has to be resetted at game start so that player data
1859  * is saved. */
1860  game.scenario.players = true;
1861 
1862  force_end_of_sniff = true;
1863  // There's no stateful packet set to client until srv_ready().
1864 }
1865 
1870 {
1871  if (server_state() == S_S_RUNNING) {
1872  // Quitting mid-game.
1873 
1874  phase_players_iterate(pplayer)
1875  {
1876  CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1877  // This has to be after all access to advisor data.
1878  /* We used to run this for ai players only, but data phase
1879  is initialized for human players also. */
1880  adv_data_phase_done(pplayer);
1881  }
1883  }
1884 
1885  if (game.server.save_timer != nullptr) {
1886  timer_destroy(game.server.save_timer);
1887  game.server.save_timer = nullptr;
1888  }
1889  if (between_turns != nullptr) {
1891  between_turns = nullptr;
1892  }
1893  if (eot_timer != nullptr) {
1895  }
1896  set_server_state(S_S_OVER);
1897  mapimg_free();
1898  server_game_free();
1899  diplhand_free();
1900  voting_free();
1902  ai_timer_free();
1903 
1904  if (srvarg.fcdb_enabled) {
1905  // If freeciv database has been initialized
1906  fcdb_free();
1907  }
1908 
1909  settings_free();
1910  stdinhand_free();
1911  edithand_free();
1912  generator_free();
1914  rulesets_deinit();
1915  CALL_FUNC_EACH_AI(module_close);
1916  timing_log_free();
1917  delete game.server.mutexes.city_list;
1918  free_libfreeciv();
1919  free_nls();
1920  con_log_close();
1921 
1922  QCoreApplication::exit(EXIT_SUCCESS);
1923 }
1924 
1928 void handle_report_req(struct connection *pconn, enum report_type type)
1929 {
1930  struct conn_list *dest = pconn->self;
1931 
1932  if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
1933  qCritical("Got a report request %d before game start", type);
1934  return;
1935  }
1936 
1937  if (nullptr == pconn->playing && !pconn->observer) {
1938  qCritical("Got a report request %d from detached connection", type);
1939  return;
1940  }
1941 
1942  switch (type) {
1945  return;
1946  case REPORT_TOP_5_CITIES:
1947  report_top_five_cities(dest);
1948  return;
1949  case REPORT_DEMOGRAPHIC:
1950  report_demographics(pconn);
1951  return;
1952  case REPORT_ACHIEVEMENTS:
1953  report_achievements(pconn);
1954  return;
1955  }
1956 
1957  notify_conn(dest, nullptr, E_BAD_COMMAND, ftc_server,
1958  _("request for unknown report (type %d)"), type);
1959 }
1960 
1965 
1970 
1974 static bool identity_number_is_used(int id)
1975 {
1976  return BV_ISSET(identity_numbers_used, id);
1977 }
1978 
1983 {
1984  server.identity_number =
1985  (server.identity_number + 1) % IDENTITY_NUMBER_SIZE;
1986  return server.identity_number;
1987 }
1988 
1994 {
1995  int retries = 0;
1996 
1998  // try again
1999  if (++retries >= IDENTITY_NUMBER_SIZE) {
2000  // Always fails.
2002  "Exhausted city and unit numbers!");
2003  }
2004  }
2005  identity_number_reserve(server.identity_number);
2006  return server.identity_number;
2007 }
2008 
2015 static bool is_client_edit_packet(int type)
2016 {
2017  return PACKET_EDIT_MODE <= type && type <= PACKET_EDIT_GAME;
2018 }
2019 
2024 bool server_packet_input(struct connection *pconn, void *packet, int type)
2025 {
2026  struct player *pplayer;
2027 
2028  // a nullptr packet can be returned from receive_packet_goto_route()
2029  if (!packet) {
2030  return true;
2031  }
2032 
2033  /*
2034  * Old pre-delta clients (before 2003-11-28) send a
2035  * PACKET_LOGIN_REQUEST (type 0) to the server. We catch this and
2036  * reply with an old reject packet. Since there is no struct for
2037  * this old packet anymore we build it by hand.
2038  */
2039  if (type == 0) {
2040  unsigned char buffer[4096];
2041  struct raw_data_out dout;
2042 
2043  qInfo(_("Warning: rejecting old client %s"), conn_description(pconn));
2044 
2045  dio_output_init(&dout, buffer, sizeof(buffer));
2046  dio_put_uint16_raw(&dout, 0);
2047 
2048  // 1 == PACKET_LOGIN_REPLY in the old client
2049  dio_put_uint8_raw(&dout, 1);
2050 
2051  dio_put_bool32_raw(&dout, false);
2052  dio_put_string_raw(&dout,
2053  _("Your client is too old. To use this server, "
2054  "please upgrade your client to a more recent "
2055  "Freeciv21 release."));
2056  dio_put_string_raw(&dout, "");
2057 
2058  {
2059  size_t size = dio_output_used(&dout);
2060  dio_output_rewind(&dout);
2061  dio_put_uint16_raw(&dout, size);
2062 
2063  /*
2064  * Use send_connection_data instead of send_packet_data to avoid
2065  * compression.
2066  */
2067  connection_send_data(pconn, buffer, size);
2068  }
2069 
2070  return false;
2071  }
2072 
2073  if (type == PACKET_SERVER_JOIN_REQ) {
2074  return handle_login_request(
2075  pconn, static_cast<struct packet_server_join_req *>(packet));
2076  }
2077 
2078  // May be received on a non-established connection.
2079  if (type == PACKET_AUTHENTICATION_REPLY) {
2080  return auth_handle_reply(
2081  pconn, (static_cast<struct packet_authentication_reply *>(packet))
2082  ->password);
2083  }
2084 
2085  if (type == PACKET_CONN_PONG) {
2086  handle_conn_pong(pconn);
2087  return true;
2088  }
2089 
2090  if (!pconn->established) {
2091  qCritical("Received game packet %s(%d) from unaccepted connection %s.",
2092  packet_name(packet_type(type)), type, conn_description(pconn));
2093  return true;
2094  }
2095 
2096  // valid packets from established connections but non-players
2097  if (type == PACKET_CHAT_MSG_REQ || type == PACKET_SINGLE_WANT_HACK_REQ
2098  || type == PACKET_NATION_SELECT_REQ || type == PACKET_REPORT_REQ
2099  || type == PACKET_CLIENT_INFO || type == PACKET_CONN_PONG
2100  || type == PACKET_CLIENT_HEARTBEAT || type == PACKET_SAVE_SCENARIO
2101  || is_client_edit_packet(type)) {
2102  /* Except for PACKET_EDIT_MODE (used to set edit mode), check
2103  * that the client is allowed to send the given edit packet. */
2104  if (is_client_edit_packet(type) && type != PACKET_EDIT_MODE
2105  && !can_conn_edit(pconn)) {
2106  notify_conn(pconn->self, nullptr, E_BAD_COMMAND, ftc_editor,
2107  _("You are not allowed to edit."));
2108  return true;
2109  }
2110 
2111  if (!server_handle_packet(packet_type(type), packet, nullptr, pconn)) {
2112  qCritical("Received unknown packet %d from %s.", type,
2113  conn_description(pconn));
2114  }
2115  return true;
2116  }
2117 
2118  pplayer = pconn->playing;
2119 
2120  if (nullptr == pplayer || pconn->observer) {
2121  if (type == PACKET_PLAYER_READY && pconn->observer) {
2122  handle_observer_ready(pconn);
2123  return true;
2124  }
2125  // don't support these yet
2126  qCritical("Received packet %s(%d) from non-player connection %s.",
2127  packet_name(packet_type(type)), type, conn_description(pconn));
2128  return true;
2129  }
2130 
2131  if (S_S_RUNNING != server_state() && type != PACKET_NATION_SELECT_REQ
2132  && type != PACKET_PLAYER_READY && type != PACKET_VOTE_SUBMIT) {
2133  if (S_S_OVER == server_state()) {
2134  /* This can happen by accident, so we don't want to print
2135  * out lots of error messages. Ie, we use log_debug(). */
2136  log_debug("Got a packet of type %s(%d) in %s.",
2137  packet_name(packet_type(type)), type,
2138  server_states_name(S_S_OVER));
2139  } else {
2140  qCritical("Got a packet of type %s(%d) outside %s.",
2141  packet_name(packet_type(type)), type,
2142  server_states_name(S_S_RUNNING));
2143  }
2144  return true;
2145  }
2146 
2147  pplayer->nturns_idle = 0;
2148 
2149  if (!pplayer->is_alive && type != PACKET_REPORT_REQ) {
2150  qCritical("Got a packet of type %s(%d) from a dead player.",
2151  packet_name(packet_type(type)), type);
2152  return true;
2153  }
2154 
2155  // Make sure to set this back to nullptr before leaving this function:
2156  pplayer->current_conn = pconn;
2157 
2158  if (!server_handle_packet(packet_type(type), packet, pplayer, pconn)) {
2159  qCritical("Received unknown packet %d from %s.", type,
2160  conn_description(pconn));
2161  }
2162 
2163  if (S_S_RUNNING == server_state() && type != PACKET_PLAYER_READY) {
2164  /* handle_player_ready() calls start_game(), but the game isn't started
2165  * until the main loop is re-entered, so kill_dying_players would think
2166  * all players are dead. This should be solved by adding a new
2167  * game state (now S_S_GENERATING_WAITING). */
2169  }
2170 
2171  pplayer->current_conn = nullptr;
2172  return true;
2173 }
2174 
2180 {
2181  bool connected = false;
2182 
2183  if (S_S_RUNNING != server_state()) {
2184  // Not in a running state, no turn done.
2185  return;
2186  }
2187 
2188  // fixedlength is only applicable if we have a timeout set
2189  if (game.server.fixedlength && current_turn_timeout() != 0) {
2190  return;
2191  }
2192 
2193  /* If there are no connected players, don't automatically advance. This is
2194  * a hack to prevent all-AI games from running rampant. Note that if
2195  * timeout is set to -1 this function call is skipped entirely and the
2196  * server will run rampant. */
2197  players_iterate_alive(pplayer)
2198  {
2199  if (pplayer->is_connected
2200  && (is_human(pplayer) || pplayer->phase_done)) {
2201  connected = true;
2202  break;
2203  }
2204  }
2206 
2207  if (!connected) {
2208  return;
2209  }
2210 
2211  phase_players_iterate(pplayer)
2212  {
2213  if (!pplayer->phase_done && pplayer->is_alive) {
2214  if (pplayer->is_connected) {
2215  // In all cases, we wait for any connected players.
2216  return;
2217  }
2218  if (game.server.turnblock && is_human(pplayer)) {
2219  /* If turnblock is enabled check for human players, connected
2220  * or not. */
2221  return;
2222  }
2223  if (is_ai(pplayer) && !pplayer->ai_phase_done) {
2224  // AI player has not finished
2225  return;
2226  }
2227  }
2228  }
2230 
2231  force_end_of_sniff = true;
2232 }
2233 
2240 {
2241  if (!game_was_started() && 0 < map_startpos_count()) {
2242  // Restrict nations to those for which start positions are defined.
2243  for (auto &pnation : nations) {
2245  nullptr == pnation.player,
2246  if (pnation.player->nation == &pnation) {
2247  /* At least assignment is consistent. Leave nation assigned,
2248  * and make sure that nation is also marked pickable. */
2249  pnation.server.no_startpos = false;
2250  continue;
2251  } else if (nullptr != pnation.player->nation) {
2252  /* Not consistent. Just initialize the pointer and hope for the
2253  * best. */
2254  pnation.player->nation->player = nullptr;
2255  pnation.player = nullptr;
2256  } else {
2257  /* Not consistent. Just initialize the pointer and hope for the
2258  * best. */
2259  pnation.player = nullptr;
2260  },
2261  "Player assigned to nation before %s()!", __FUNCTION__);
2262 
2263  if (nation_barbarian_type(&pnation) != NOT_A_BARBARIAN) {
2264  /* Always allow land and sea barbarians regardless of start
2265  * positions. */
2266  pnation.server.no_startpos = false;
2267  } else {
2268  /* Restrict the set of nations offered to players, based on
2269  * start positions.
2270  * If there are no start positions for a nation, remove it from the
2271  * available set. */
2272  pnation.server.no_startpos = true;
2273  for (auto *psp : qAsConst(*wld.map.startpos_table)) {
2274  if (psp->exclude) {
2275  continue;
2276  }
2277  if (startpos_nation_allowed(psp, &pnation)) {
2278  /* There is at least one start position that allows this
2279  * nation, so allow it to be picked. (Depending on what nations
2280  * players actually pick, it's not guaranteed that the server
2281  * can always find a match between nations in this subset and
2282  * start positions, in which case the server may create
2283  * mismatches.) */
2284  pnation.server.no_startpos = false;
2285  break;
2286  }
2287  }
2288  }
2289  }
2290  } else {
2291  // Not restricting nations by start positions.
2292  for (auto &pnation : nations) {
2293  pnation.server.no_startpos = false;
2294  }
2295  }
2296 }
2297 
2303 void handle_nation_select_req(struct connection *pc, int player_no,
2304  Nation_type_id nation_no, bool is_male,
2305  const char *name, int style)
2306 {
2307  struct nation_type *new_nation;
2308  struct player *pplayer = player_by_number(player_no);
2309 
2310  if (!pplayer || !can_conn_edit_players_nation(pc, pplayer)) {
2311  return;
2312  }
2313 
2314  new_nation = nation_by_number(nation_no);
2315 
2316  if (new_nation != NO_NATION_SELECTED) {
2317  char message[1024];
2318 
2319  // check sanity of the packet sent by client
2320  if (style < 0 || style >= game.control.num_styles) {
2321  return;
2322  }
2323 
2324  if (!client_can_pick_nation(new_nation)) {
2325  notify_player(pplayer, nullptr, E_NATION_SELECTED, ftc_server,
2326  _("%s nation is not available for user selection."),
2327  nation_adjective_translation(new_nation));
2328  return;
2329  }
2330  if (new_nation->player && new_nation->player != pplayer) {
2331  notify_player(pplayer, nullptr, E_NATION_SELECTED, ftc_server,
2332  _("%s nation is already in use."),
2333  nation_adjective_translation(new_nation));
2334  return;
2335  }
2336 
2337  if (!server_player_set_name_full(pc, pplayer, new_nation, name, message,
2338  sizeof(message))) {
2339  notify_player(pplayer, nullptr, E_NATION_SELECTED, ftc_server, "%s",
2340  message);
2341  return;
2342  }
2343 
2344  // Should be caught by is_nation_pickable()
2346 
2347  notify_conn(nullptr, nullptr, E_NATION_SELECTED, ftc_server,
2348  _("%s is the %s ruler %s."), pplayer->username,
2349  nation_adjective_translation(new_nation),
2350  player_name(pplayer));
2351 
2352  pplayer->is_male = is_male;
2353  pplayer->style = style_by_number(style);
2354  } else if (name[0] == '\0') {
2355  char message[1024];
2356 
2357  server_player_set_name_full(pc, pplayer, nullptr, ANON_PLAYER_NAME,
2358  message, sizeof(message));
2359  }
2360 
2361  (void) player_set_nation(pplayer, new_nation);
2363 }
2364 
2368 static void handle_observer_ready(struct connection *pconn)
2369 {
2370  if (pconn->access_level == ALLOW_HACK) {
2371  players_iterate(plr)
2372  {
2373  if (is_human(plr)) {
2374  return;
2375  }
2376  }
2378 
2379  start_command(nullptr, false, true);
2380  }
2381 }
2382 
2386 void handle_player_ready(struct player *requestor, int player_no,
2387  bool is_ready)
2388 {
2389  struct player *pplayer = player_by_number(player_no);
2390 
2391  if (nullptr == pplayer || S_S_INITIAL != server_state()) {
2392  return;
2393  }
2394 
2395  if (pplayer != requestor) {
2396  // Currently you can only change your own readiness.
2397  return;
2398  }
2399 
2400  pplayer->is_ready = is_ready;
2401  send_player_info_c(pplayer, nullptr);
2402 
2403  /* Note this is called even if the player has pressed /start once
2404  * before. For instance, when a player leaves everyone remaining
2405  * might have pressed /start already but the start won't happen
2406  * until someone presses it again. Also you can press start more
2407  * than once to remind other people to start (which is a good thing
2408  * until somebody does it too much and it gets labeled as spam). */
2409  if (is_ready) {
2410  int num_ready = 0, num_unready = 0;
2411 
2412  players_iterate(other_player)
2413  {
2414  if (other_player->is_connected) {
2415  if (other_player->is_ready) {
2416  num_ready++;
2417  } else {
2418  num_unready++;
2419  }
2420  }
2421  }
2423  if (num_unready > 0) {
2424  notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
2425  _("Waiting to start game: %d out of %d players "
2426  "are ready to start."),
2427  num_ready, num_ready + num_unready);
2428  } else {
2429  // Check minplayers etc. and then start
2430  start_command(nullptr, false, true);
2431  }
2432  }
2433 }
2434 
2440 const char *aifill(int amount)
2441 {
2442  const char *limitreason = nullptr;
2443  int limit;
2444 
2445  if (game_was_started()) {
2446  return nullptr;
2447  }
2448 
2449  limit = MIN(amount, game.server.max_players);
2450  if (limit < amount) {
2451  limitreason = _("requested more than 'maxplayers' setting");
2452  }
2453 
2454  // Limit to nations provided by ruleset
2455  if (limit > server.playable_nations) {
2456  limit = server.playable_nations;
2457  if (nation_set_count() > 1) {
2458  limitreason = _("not enough playable nations in this nation set "
2459  "(see 'nationset' setting)");
2460  } else {
2461  limitreason = _("not enough playable nations");
2462  }
2463  }
2464 
2465  if (limit < player_count()) {
2466  int removal = MAX_NUM_PLAYER_SLOTS - 1;
2467 
2468  while (limit < player_count() && 0 <= removal) {
2469  struct player *pplayer = player_by_number(removal);
2470 
2471  removal--;
2472  if (!pplayer) {
2473  continue;
2474  }
2475 
2476  if (!pplayer->is_connected && !pplayer->was_created) {
2477  server_remove_player(pplayer);
2478  }
2479  }
2480 
2481  /* 'limit' can be different from 'player_count()' at this point if
2482  * there are more human or created players than the 'limit'. */
2483  return limitreason;
2484  }
2485 
2486  while (limit > player_count()) {
2487  char leader_name[MAX_LEN_NAME];
2488  int filled = 1;
2489  struct player *pplayer;
2490 
2491  pplayer =
2492  server_create_player(-1, default_ai_type_name(), nullptr, false);
2493  // !game_was_started() so no need to assign_player_colors()
2494  if (!pplayer) {
2495  break;
2496  }
2497  server_player_init(pplayer, false, true);
2498 
2499  player_set_nation(pplayer, nullptr);
2500 
2501  do {
2502  fc_snprintf(leader_name, sizeof(leader_name), "AI*%d", filled++);
2503  } while (player_by_name(leader_name));
2504  server_player_set_name(pplayer, leader_name);
2505  pplayer->random_name = true;
2506  sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
2507  pplayer->unassigned_user = true;
2508 
2509  pplayer->ai_common.skill_level = ai_level(game.info.skill_level);
2510  set_as_ai(pplayer);
2511  set_ai_level_directer(pplayer, ai_level(game.info.skill_level));
2512 
2513  CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
2514 
2515  qInfo(_("%s has been added as %s level AI-controlled player (%s)."),
2516  player_name(pplayer),
2517  ai_level_translated_name(pplayer->ai_common.skill_level),
2518  ai_name(pplayer->ai));
2519  notify_conn(
2520  nullptr, nullptr, E_SETTING, ftc_server,
2521  _("%s has been added as %s level AI-controlled player (%s)."),
2522  player_name(pplayer),
2523  ai_level_translated_name(pplayer->ai_common.skill_level),
2524  ai_name(pplayer->ai));
2525 
2526  send_player_info_c(pplayer, nullptr);
2527  }
2528 
2529  return limitreason;
2530 }
2531 
2535 static void player_set_nation_full(struct player *pplayer,
2536  struct nation_type *pnation)
2537 {
2538  // Don't change the name of a created player.
2539  player_nation_defaults(pplayer, pnation, pplayer->random_name);
2540 }
2541 
2545 void player_nation_defaults(struct player *pplayer,
2546  struct nation_type *pnation, bool set_name)
2547 {
2548  struct nation_leader *pleader;
2549 
2550  fc_assert(NO_NATION_SELECTED != pnation);
2551  player_set_nation(pplayer, pnation);
2552  fc_assert(pnation == pplayer->nation);
2553 
2554  pplayer->style = style_of_nation(pnation);
2555 
2556  if (set_name) {
2558  }
2559 
2560  if ((pleader = nation_leader_by_name(pnation, player_name(pplayer)))) {
2561  pplayer->is_male = nation_leader_is_male(pleader);
2562  } else {
2563  pplayer->is_male = (fc_rand(2) == 1);
2564  }
2565 
2566  ai_traits_init(pplayer);
2567 }
2568 
2596 static void generate_players()
2597 {
2598  int nations_to_assign = 0;
2599 
2600  /* Announce players who already have nations, and select nations based
2601  * on player names. */
2602  players_iterate(pplayer)
2603  {
2604  if (pplayer->nation != NO_NATION_SELECTED) {
2605  /* Traits are initialized here, and not already when nation gets
2606  * picked, as player may change his/her mind after picking one nation,
2607  * and picks another and we want to init traits only once, for the
2608  * correct nation. */
2609  ai_traits_init(pplayer);
2610  announce_player(pplayer);
2611  continue;
2612  }
2613 
2614  /* See if the player name matches a known leader name.
2615  * If more than one nation has this leader name, pick one at random.
2616  * No attempt is made to avoid clashes to maximise the number of
2617  * nations that can be assigned in this way. */
2618  {
2619  struct nation_list *candidates = nation_list_new();
2620  int n = 0;
2621 
2622  for (auto &pnation : nations) {
2623  if (nation_is_in_current_set(&pnation)) {
2624  if (is_nation_playable(&pnation)
2625  && client_can_pick_nation(&pnation)
2626  && nullptr == pnation.player
2627  && (nation_leader_by_name(&pnation, player_name(pplayer)))) {
2628  nation_list_append(candidates, &pnation);
2629  n++;
2630  }
2631  }
2632  }
2633  if (n > 0) {
2634  player_set_nation_full(pplayer,
2635  nation_list_get(candidates, fc_rand(n)));
2636  }
2637  nation_list_destroy(candidates);
2638  }
2639  if (pplayer->nation != NO_NATION_SELECTED) {
2640  announce_player(pplayer);
2641  } else {
2642  nations_to_assign++;
2643  }
2644  }
2646 
2647  if (0 < nations_to_assign && 0 < map_startpos_count()) {
2648  /* We're running a scenario game with specified start positions.
2649  * Prefer nations assigned to those positions (but we can fall back
2650  * to others, even if game.scenario.startpos_nations is set). */
2651  QHash<struct startpos *, int> hash;
2652  QHash<struct startpos *, int>::const_iterator it;
2653  struct nation_type *picked;
2654  int c, max = -1;
2655  int i, min;
2656 
2657  // Initialization.
2658  for (auto *psp : qAsConst(*wld.map.startpos_table)) {
2659  if (psp->exclude) {
2660  continue;
2661  }
2662  if (startpos_allows_all(psp)) {
2663  continue;
2664  }
2665 
2666  /* Count the already-assigned players whose nations can use this
2667  * start position. */
2668  c = 0;
2669  players_iterate(pplayer)
2670  {
2671  if (NO_NATION_SELECTED != pplayer->nation
2672  && startpos_nation_allowed(psp, pplayer->nation)) {
2673  c++;
2674  }
2675  }
2677 
2678  hash.insert(psp, c);
2679  if (c > max) {
2680  max = c;
2681  }
2682  }
2683 
2684  /* Try to assign nations with start positions to the unassigned
2685  * players, preferring nations whose start positions aren't usable
2686  * by already-assigned players. */
2687  players_iterate(pplayer)
2688  {
2689  if (NO_NATION_SELECTED != pplayer->nation) {
2690  continue;
2691  }
2692 
2693  picked = NO_NATION_SELECTED;
2694  min = max;
2695  i = 0;
2696 
2697  for (auto &pnation : nations) {
2698  if (nation_is_in_current_set(&pnation)) {
2699  if (!is_nation_playable(&pnation) || nullptr != pnation.player) {
2700  // Not available.
2701  continue;
2702  }
2703 
2704  it = hash.constBegin();
2705  while (it != hash.constEnd()) {
2706  if (!startpos_nation_allowed(it.key(), &pnation)) {
2707  ++it;
2708  continue;
2709  }
2710 
2711  if (it.value() < min) {
2712  /* Pick this nation, as fewer nations already in the game
2713  * can use this start position. */
2714  picked = &pnation;
2715  min = it.value();
2716  i = 1;
2717  } else if (it.value() == min && 0 == fc_rand(++i)) {
2718  /* More than one nation is equally desirable. Pick one at
2719  * random. */
2720  picked = &pnation;
2721  }
2722  ++it;
2723  }
2724  }
2725  }
2726 
2727  if (NO_NATION_SELECTED != picked) {
2728  player_set_nation_full(pplayer, picked);
2729  nations_to_assign--;
2730  announce_player(pplayer);
2731  // Update the counts for the newly assigned nation.
2732  it = hash.constBegin();
2733  while (it != hash.constEnd()) {
2734  if (startpos_nation_allowed(it.key(), picked)) {
2735  hash.insert(it.key(), it.value() + 1);
2736  }
2737  ++it;
2738  }
2739  } else {
2740  /* No need to continue; we failed to pick a nation this time,
2741  * so we're not going to succeed next time. Fall back to
2742  * standard nation selection. */
2743  break;
2744  }
2745  }
2747  }
2748 
2749  if (0 < nations_to_assign) {
2750  /* Pick random races. Try to select from the set permitted by
2751  * starting positions -- if we fell through here after failing to
2752  * match start positions, this will at least keep the picked
2753  * nations vaguely in keeping with the scenario.
2754  * However, even this may fail (if there are start positions that
2755  * can only be filled by nations outside the current nationset),
2756  * in which case we fall back to completely random nations. */
2757  bool needs_startpos = true;
2758  players_iterate(pplayer)
2759  {
2760  if (NO_NATION_SELECTED == pplayer->nation) {
2761  struct nation_type *pnation =
2762  pick_a_nation(nullptr, false, needs_startpos, NOT_A_BARBARIAN);
2763  if (pnation == NO_NATION_SELECTED && needs_startpos) {
2764  needs_startpos = false;
2765  pnation =
2766  pick_a_nation(nullptr, false, needs_startpos, NOT_A_BARBARIAN);
2767  }
2768  fc_assert(pnation != NO_NATION_SELECTED);
2769  player_set_nation_full(pplayer, pnation);
2770  nations_to_assign--;
2771  announce_player(pplayer);
2772  }
2773  }
2775  }
2776 
2777  fc_assert(0 == nations_to_assign);
2778 
2780 }
2781 
2787 const char *pick_random_player_name(const struct nation_type *pnation)
2788 {
2789  const char *choice = nullptr;
2790  struct nation_leader_list *candidates = nation_leader_list_new();
2791  int n;
2792 
2793  nation_leader_list_iterate(nation_leaders(pnation), pleader)
2794  {
2795  const char *name = nation_leader_name(pleader);
2796 
2797  if (nullptr == player_by_name(name) && nullptr == player_by_user(name)) {
2798  nation_leader_list_append(candidates, pleader);
2799  }
2800  }
2802 
2803  n = nation_leader_list_size(candidates);
2804  if (n > 0) {
2805  choice =
2806  nation_leader_name(nation_leader_list_get(candidates, fc_rand(n)));
2807  }
2808  nation_leader_list_destroy(candidates);
2809 
2810  return choice;
2811 }
2812 
2816 static void announce_player(struct player *pplayer)
2817 {
2818  qInfo(_("%s rules the %s."), player_name(pplayer),
2819  nation_plural_for_player(pplayer));
2820 
2821  notify_conn(game.est_connections, nullptr, E_GAME_START, ftc_server,
2822  _("%s rules the %s."), player_name(pplayer),
2823  nation_plural_for_player(pplayer));
2824 
2825  /* Let the clients knows the nation of the players as soon as possible.
2826  * When a player's nation is server assigned its client will think of it
2827  * as nullptr until informed about the assigned nation. */
2828  send_player_info_c(pplayer, nullptr);
2829 }
2830 
2835 {
2836  // Recalculate the scores in case of a spaceship victory
2837  players_iterate(pplayer) { calc_civ_score(pplayer); }
2839 
2841 
2842  report_final_scores(nullptr);
2843  show_map_to_all();
2844  notify_player(nullptr, nullptr, E_GAME_END, ftc_server,
2845  _("The game is over..."));
2847 
2848  if (game.server.save_nturns > 0
2849  && conn_list_size(game.est_connections) > 0) {
2850  /* Save game on game_over, but not when the gameover was caused by
2851  * the -q parameter. */
2852  save_game_auto("Game over", AS_GAME_OVER);
2853  }
2854 }
2855 
2862 {
2863  players_iterate(pplayer)
2864  {
2865  struct nation_type *pnation = nation_of_player(pplayer);
2866 
2867  pplayer->government = init_government_of_nation(pnation);
2868 
2870  /* If we do not do this, an assertion will trigger. This enables us to
2871  * select a valid government on game start. */
2872  pplayer->revolution_finishes = 0;
2873  }
2874 
2875  multipliers_iterate(pmul)
2876  {
2877  pplayer->multipliers[multiplier_index(pmul)] =
2878  pplayer->multipliers_target[multiplier_index(pmul)] = pmul->def;
2879  }
2881  }
2883 }
2884 
2889 {
2891 
2892  if (game.server.auto_ai_toggle) {
2893  players_iterate(pplayer)
2894  {
2895  if (!pplayer->is_connected && is_human(pplayer)) {
2896  toggle_ai_player_direct(nullptr, pplayer);
2897  }
2898  }
2900  }
2901 
2902  init_game_seed();
2903 
2904 #ifdef TEST_RANDOM // not defined anywhere, set it if you want it
2905  test_random1(200);
2906  test_random1(2000);
2907  test_random1(20000);
2908  test_random1(200000);
2909 #endif
2910 
2911  if (game.info.is_new_game) {
2912  game.info.turn++; // pregame T0 -> game T1
2913  fc_assert(game.info.turn == 1);
2914  game.info.year = game.server.start_year;
2915  // Must come before assign_player_colors()
2916  generate_players();
2918  }
2919 
2920  /* If we have a tile map, and MAPGEN_SCENARIO == map.server.generator,
2921  * call map_fractal_generate anyway to make the specials, huts and
2922  * continent numbers. */
2923  if (map_is_empty()
2924  || (MAPGEN_SCENARIO == wld.map.server.generator
2925  && game.info.is_new_game)) {
2926  struct {
2927  const char *name;
2928  char value[MAX_LEN_NAME * 2];
2929  char pretty[MAX_LEN_NAME * 2];
2930  } mapgen_settings[] = {{
2931  "generator",
2932  },
2933  {
2934  "startpos",
2935  },
2936  {
2937  "teamplacement",
2938  }};
2939  int i;
2940  /* If a specific seed has been requested, there's no point retrying,
2941  * as the map will be the same every time. */
2942  bool retry_ok = (wld.map.server.seed_setting == 0
2943  && wld.map.server.generator != MAPGEN_SCENARIO);
2944  int max = retry_ok ? 3 : 1;
2945  bool created = false;
2946  struct unit_type *utype = nullptr;
2947  int sucount = qstrlen(game.server.start_units);
2948 
2949  if (sucount > 0) {
2950  for (i = 0; utype == nullptr && i < sucount; i++) {
2951  utype = crole_to_unit_type(game.server.start_units[i], nullptr);
2952  }
2953  } else {
2954  // First unit the initial city might build.
2955  utype = get_role_unit(L_FIRSTBUILD, 0);
2956  }
2957  fc_assert(utype != nullptr);
2958 
2959  // Register map generator setting main values.
2960  for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
2961  const struct setting *pset = setting_by_name(mapgen_settings[i].name);
2962 
2963  fc_assert_action(pset != nullptr, continue);
2964  (void) setting_value_name(pset, false, mapgen_settings[i].value,
2965  sizeof(mapgen_settings[i].value));
2966  (void) setting_value_name(pset, true, mapgen_settings[i].pretty,
2967  sizeof(mapgen_settings[i].pretty));
2968  }
2969 
2970  for (i = 0; !created && i < max; i++) {
2971  created = map_generate(true, utype);
2972  if (!created && max > 1) {
2973  int set;
2974 
2975  /* If we're retrying, seed_setting == 0, which will yield a new map
2976  * next time */
2977  fc_assert(wld.map.server.seed_setting == 0);
2978  if (i == 0) {
2979  // We will retry only if max attempts allow it
2980  qInfo(_("Failed to create suitable map, retrying with "
2981  "another mapseed."));
2982  } else {
2983  /* +1 - start human readable count from 1 and not from 0
2984  * +1 - refers to next round, not to one we just did
2985  * ==
2986  * +2 */
2987  qInfo(_("Attempt %d/%d"), i + 2, max);
2988  }
2989  wld.map.server.have_resources = false;
2990 
2991  // Remove old information already present in tiles
2992  main_map_free();
2994  // Restore the settings.
2995  for (set = 0; set < ARRAY_SIZE(mapgen_settings); set++) {
2996  struct setting *pset = setting_by_name(mapgen_settings[set].name);
2997  char error[128];
2998  bool success;
2999 
3000  fc_assert_action(pset != nullptr, continue);
3001  success = setting_enum_set(pset, mapgen_settings[set].value,
3002  nullptr, error, sizeof(error));
3003  fc_assert_msg(success == true, "Failed to restore '%s': %s",
3004  mapgen_settings[set].name, error);
3005  }
3006  main_map_allocate(); /* NOT map_init() as that would overwrite
3007  settings */
3008  }
3009  }
3010  if (!created) {
3011  qCCritical(bugs_category,
3012  _("Cannot create suitable map with given settings."));
3013 
3014  exit(EXIT_FAILURE);
3015  }
3016 
3017  if (wld.map.server.generator != MAPGEN_SCENARIO) {
3018  script_server_signal_emit("map_generated");
3019  }
3020 
3021  game_map_init();
3022 
3023  // Test if main map generator settings have changed.
3024  for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3025  const struct setting *pset = setting_by_name(mapgen_settings[i].name);
3026  char pretty[sizeof(mapgen_settings[i].pretty)];
3027 
3028  fc_assert_action(pset != nullptr, continue);
3029  if (0
3030  == strcmp(setting_value_name(pset, true, pretty, sizeof(pretty)),
3031  mapgen_settings[i].pretty)) {
3032  continue; // Setting didn't change.
3033  }
3034  notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
3035  _("Setting '%s' has been adjusted from %s to %s."),
3036  setting_name(pset), mapgen_settings[i].pretty, pretty);
3037  qInfo(_("Setting '%s' has been adjusted from %s to %s."),
3038  setting_name(pset), mapgen_settings[i].pretty, pretty);
3039  }
3040  }
3041 
3042  CALL_FUNC_EACH_AI(map_ready);
3043 
3044  // start the game
3045  set_server_state(S_S_RUNNING);
3047 
3048  if (game.info.is_new_game) {
3049  shuffle_players();
3050 
3051  /* If we're starting a new game, reset the max_players to be at
3052  * least the number of players currently in the game. */
3053  game.server.max_players =
3054  MAX(normal_player_count(), game.server.max_players);
3055 
3056  // Before the player map is allocated (and initialized)!
3057  game.server.fogofwar_old = game.info.fogofwar;
3058 
3059  players_iterate(pplayer)
3060  {
3061  player_map_init(pplayer);
3062  pplayer->economic = player_limit_to_max_rates(pplayer);
3063  pplayer->economic.gold = game.info.gold;
3064  }
3066 
3067  /* Give initial technologies, as specified in the ruleset and the
3068  * settings. */
3069  for (auto &presearch : research_array) {
3070  if (research_is_valid(presearch)) {
3071  init_tech(&presearch, true);
3072  give_initial_techs(&presearch, game.info.tech);
3073  }
3074  };
3075 
3076  // Set up alliances based on team selections
3077  players_iterate(pplayer)
3078  {
3079  players_iterate(pdest)
3080  {
3081  if (players_on_same_team(pplayer, pdest)
3082  && player_number(pplayer) != player_number(pdest)) {
3083  player_diplstate_get(pplayer, pdest)->type = DS_TEAM;
3084  give_shared_vision(pplayer, pdest);
3085  BV_SET(pplayer->real_embassy, player_index(pdest));
3086  }
3087  }
3089  }
3091 
3092  /* Assign colors from the ruleset for any players who weren't
3093  * explicitly assigned colors during the pregame.
3094  * This must come after generate_players() since it can depend on
3095  * assigned nations. */
3097 
3098  // Save all settings for the 'reset game' command.
3100  }
3101 
3102  // FIXME: can this be moved?
3103  players_iterate(pplayer) { adv_data_analyze_rulesets(pplayer); }
3105 
3106  if (!game.info.is_new_game) {
3107  players_iterate(pplayer)
3108  {
3109  if (is_ai(pplayer)) {
3110  set_ai_level_direct(pplayer, pplayer->ai_common.skill_level);
3111  }
3112  }
3114  } else {
3115  players_iterate(pplayer)
3116  {
3117  // Initialize this again to be sure
3118  adv_data_default(pplayer);
3119  }
3121  }
3122 
3126 
3127  if (game.info.is_new_game) {
3128  // Place players' initial units, etc
3129  init_new_game();
3130  create_animals();
3131 
3132  if (game.server.revealmap & REVEAL_MAP_START) {
3133  players_iterate(pplayer) { map_show_all(pplayer); }
3135  }
3136  }
3137 
3138  if (game.scenario.is_scenario && game.scenario.players) {
3139  /* This is a heavy scenario. It may include research. The sciencebox
3140  * setting may have been changed. A change to the sciencebox setting
3141  * may have caused the stored amount of bulbs to be enough to finish
3142  * the current research. */
3143 
3144  players_iterate(pplayer)
3145  {
3146  // Check for finished research.
3147  update_bulbs(pplayer, 0, true);
3148  }
3150  }
3151 
3152  CALL_FUNC_EACH_AI(game_start);
3153 
3154  qDebug("srv_running() mostly redundant send_server_settings()");
3155  send_server_settings(nullptr);
3156 
3157  if (game.server.autosaves & (1 << AS_TIMER)) {
3158  game.server.save_timer =
3160  timer_start(game.server.save_timer);
3161  }
3162 }
3163 
3167 static void unit_wait_destroy(struct unit_wait *pwait)
3168 {
3169  struct unit *punit = game_unit_by_number(pwait->id);
3170  if (punit) {
3171  punit->server.wait = NULL;
3172  }
3173  free(pwait);
3174 }
3175 
3179 void server_game_init(bool keep_ruleset_value)
3180 {
3181  // was redundantly in game_load()
3182  server.playable_nations = 0;
3183  server.nbarbarians = 0;
3184  server.identity_number = IDENTITY_NUMBER_SKIP;
3185  server.unit_waits = unit_wait_list_new_full(unit_wait_destroy);
3186 
3189 
3190  event_cache_init();
3191  game_init(keep_ruleset_value);
3192  /* game_init() set game.server.plr_colors to nullptr. So we need to
3193  * initialize the colors after. */
3194  playercolor_init();
3195 
3196  game.server.turn_change_time = 0;
3197 }
3198 
3205 {
3207 
3208  // Free all the treaties that were left open when game finished.
3209  free_treaties();
3210 
3211  // Free the vision data, without sending updates.
3212  players_iterate(pplayer)
3213  {
3214  unit_list_iterate(pplayer->units, punit)
3215  {
3216  // don't bother using vision_clear_sight()
3217  vision_layer_iterate(v) { punit->server.vision->radius_sq[v] = -1; }
3219  vision_free(punit->server.vision);
3220  punit->server.vision = nullptr;
3221  }
3223 
3224  city_list_iterate(pplayer->cities, pcity)
3225  {
3226  // don't bother using vision_clear_sight()
3227  vision_layer_iterate(v) { pcity->server.vision->radius_sq[v] = -1; }
3229  vision_free(pcity->server.vision);
3230  pcity->server.vision = nullptr;
3231  adv_city_free(pcity);
3232  }
3234  }
3236 
3237  /* Destroy all players; with must be separate as the player information is
3238  * needed above. This also sends the information to the clients. */
3239  players_iterate(pplayer) { server_remove_player(pplayer); }
3241 
3242  event_cache_free();
3244  playercolor_free();
3245  citymap_free();
3246  unit_wait_list_destroy(server.unit_waits);
3247  game_free();
3248 }
3249 
3254 int server_plr_tile_city_id_get(const struct tile *ptile,
3255  const struct player *pplayer)
3256 {
3257  const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3258 
3259  return plrtile && plrtile->site ? plrtile->site->identity
3261 }
3262 
3267 {
3268  struct setting *pset = setting_by_name(name);
3269 
3270  if (pset) {
3271  return setting_number(pset);
3272  } else {
3273  qCritical("No server setting named %s exists.", name);
3274  return SERVER_SETTING_NONE;
3275  }
3276 }
3277 
3282 {
3283  struct setting *pset = setting_by_number(id);
3284 
3285  if (pset) {
3286  return setting_name(pset);
3287  } else {
3288  qCritical("No server setting with the id %d exists.", id);
3289  return nullptr;
3290  }
3291 }
3292 
3296 enum sset_type server_ss_type_get(server_setting_id id)
3297 {
3298  struct setting *pset = setting_by_number(id);
3299 
3300  if (pset) {
3301  return setting_type(pset);
3302  } else {
3303  qCritical("No server setting with the id %d exists.", id);
3304  return sset_type_invalid();
3305  }
3306 }
3307 
3312 {
3313  struct setting *pset = setting_by_number(id);
3314 
3315  if (pset) {
3316  return setting_bool_get(pset);
3317  } else {
3318  qCritical("No server setting with the id %d exists.", id);
3319  return false;
3320  }
3321 }
3322 
3327 {
3328  struct setting *pset = setting_by_number(id);
3329 
3330  if (pset) {
3331  return setting_int_get(pset);
3332  } else {
3333  qCritical("No server setting with the id %d exists.", id);
3334  return 0;
3335  }
3336 }
3337 
3342 {
3343  struct setting *pset = setting_by_number(id);
3344 
3345  if (pset) {
3346  return setting_bitwise_get(pset);
3347  } else {
3348  qCritical("No server setting with the id %d exists.", id);
3349  return false;
3350  }
3351 }
3352 
3357  const struct player *pplayer,
3358  bool knowledge)
3359 {
3360  if (knowledge && pplayer) {
3361  return tile_get_known(ptile, pplayer);
3362  }
3363 
3364  return TILE_KNOWN_SEEN;
3365 }
3366 
3371  const struct player *pplayer,
3372  bool knowledge)
3373 {
3374  if (knowledge && pplayer) {
3375  struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3376  return plrtile->terrain;
3377  }
3378 
3379  return tile_terrain(ptile);
3380 }
3381 
3385 player *mapimg_server_tile_owner(const struct tile *ptile,
3386  const struct player *pplayer,
3387  bool knowledge)
3388 {
3389  if (knowledge && pplayer
3390  && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3391  struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3392  return plrtile->owner;
3393  }
3394 
3395  return tile_owner(ptile);
3396 }
3397 
3401 player *mapimg_server_tile_city(const struct tile *ptile,
3402  const struct player *pplayer, bool knowledge)
3403 {
3404  struct city *pcity = tile_city(ptile);
3405 
3406  if (!pcity) {
3407  return nullptr;
3408  }
3409 
3410  if (knowledge && pplayer) {
3411  const vision_site *pdcity = map_get_player_city(ptile, pplayer);
3412 
3413  if (pdcity) {
3414  return pdcity->owner;
3415  } else {
3416  return nullptr;
3417  }
3418  }
3419 
3420  return city_owner(tile_city(ptile));
3421 }
3422 
3426 player *mapimg_server_tile_unit(const struct tile *ptile,
3427  const struct player *pplayer, bool knowledge)
3428 {
3429  int unit_count = unit_list_size(ptile->units);
3430 
3431  if (unit_count == 0) {
3432  return nullptr;
3433  }
3434 
3435  if (knowledge && pplayer
3436  && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3437  return nullptr;
3438  }
3439 
3440  return unit_owner(unit_list_get(ptile->units, 0));
3441 }
3442 
3447 
const char * achievement_first_msg(struct achievement *pach)
Return message to send to first player gaining the achievement.
const char * achievement_later_msg(struct achievement *pach)
Return message to send to other players gaining the achievement.
int achievement_index(const struct achievement *pach)
Return the achievement index.
struct player * achievement_plr(struct achievement *ach, struct player_list *achievers)
Check if some player has now achieved the achievement and return the player in question.
#define achievements_iterate_end
Definition: achievements.h:64
#define achievements_iterate(_ach_)
Definition: achievements.h:58
void building_advisor(struct player *pplayer)
Prime pcity->server.adv.building_want[].
void adv_data_analyze_rulesets(struct player *pplayer)
Analyze rulesets.
Definition: advdata.cpp:194
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
void adv_data_default(struct player *pplayer)
Initialize with sane values.
Definition: advdata.cpp:720
bool adv_spaceship_autoplace(struct player *pplayer, struct player_spaceship *ship)
Place all available spaceship components.
Definition: advspace.cpp:29
const char * ai_name(const struct ai_type *ai)
Return the name of the ai type.
Definition: ai.cpp:99
#define ai_timer_free(...)
Definition: ai.h:362
#define CALL_FUNC_EACH_AI(_func,...)
Definition: ai.h:393
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition: ai.h:383
void ai_init()
Initialize ai stuff.
Definition: aiiface.cpp:132
const char * default_ai_type_name()
Return name of default ai type.
Definition: aiiface.cpp:265
void ai_traits_init(struct player *pplayer)
Initialize ai traits for player.
Definition: aitraits.cpp:28
void create_animals()
Create animal kingdom player and his units.
Definition: animals.cpp:91
bool auth_handle_reply(struct connection *pconn, char *password)
Receives a password from a client and verifies it.
Definition: auth.cpp:147
void auto_settlers_player(struct player *pplayer)
Run through all the players settlers and let those on ai.control work automagically.
void adv_settlers_free()
Free resources allocated for autosettlers system.
void summon_barbarians()
Summon barbarians out of the blue.
Definition: barbarian.cpp:710
#define BV_CLR_ALL(bv)
Definition: bitvector.h:62
#define BV_SET(bv, bit)
Definition: bitvector.h:44
bool BV_ISSET(const BV &bv, int bit)
Definition: bitvector.h:37
#define BV_CLR(bv, bit)
Definition: bitvector.h:49
void game_advance_year()
Advance the game year.
Definition: calendar.cpp:87
void game_next_year(struct packet_game_info *info)
Advance the calendar in the passed game_info structure (may only be a copy of the real one).
Definition: calendar.cpp:24
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
void free_city_map_index()
Free memory allocated by generate_citymap_index.
Definition: city.cpp:581
#define cities_iterate_end
Definition: city.h:493
#define city_list_iterate(citylist, pcity)
Definition: city.h:482
#define cities_iterate(pcity)
Definition: city.h:486
#define city_list_iterate_end
Definition: city.h:484
void citymap_free()
Free resources allocated for citymap.
Definition: citymap.cpp:106
void package_and_send_worker_tasks(struct city *pcity)
Send city worker task to owner.
Definition: citytools.cpp:3433
void send_city_info(struct player *dest, struct city *pcity)
A wrapper, accessing either broadcast_city_info() (dest == nullptr), or a convenience case of send_ci...
Definition: citytools.cpp:2295
void city_thaw_workers_queue()
Process the frozen workers.
Definition: citytools.cpp:171
bool send_city_suppression(bool now)
Suppress sending cities during game_load() and end_phase()
Definition: citytools.cpp:2127
void refresh_player_cities_vision(struct player *pplayer)
Refresh the vision of all cities owned by a player, for empire-wide effects.
Definition: citytools.cpp:3277
void city_map_update_all_cities_for_player(struct player *pplayer)
Update worked map of all cities of given player.
Definition: citytools.cpp:3189
void send_player_cities(struct player *pplayer)
Send information about all his/her cities to player.
Definition: citytools.cpp:2274
void sync_cities()
Make sure all players (clients) have up-to-date information about all their cities.
Definition: citytools.cpp:3150
void send_all_known_cities(struct conn_list *dest)
Send to each client information about the cities it knows about.
Definition: citytools.cpp:2248
bool check_city_migrations()
Check for citizens who want to migrate between the cities that overlap.
Definition: cityturn.cpp:3954
void send_city_turn_notifications(struct connection *pconn)
Send global and player specific city turn notifications.
Definition: cityturn.cpp:548
void update_city_activities(struct player *pplayer)
Update all cities of one nation (costs for buildings, unit upkeep, ...).
Definition: cityturn.cpp:589
void check_disasters()
Check for any disasters hitting any city, and apply those disasters.
Definition: cityturn.cpp:4117
bool handle_login_request(struct connection *pconn, struct packet_server_join_req *req)
Returns FALSE if the clients gets rejected and the connection should be closed.
void conn_set_access(struct connection *pconn, enum cmdlevel new_level, bool granted)
Set the access level of a connection, and re-send some needed info.
Definition: connecthand.cpp:67
void conn_list_do_unbuffer(struct conn_list *dest)
Convenience functions to unbuffer a list of connections.
Definition: connection.cpp:319
bool can_conn_edit(const struct connection *pconn)
Return TRUE iff the connection is currently allowed to edit.
Definition: connection.cpp:472
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Thaw a connection list.
Definition: connection.cpp:665
const char * conn_description(const struct connection *pconn, bool is_private)
° Return pointer to static string containing a description for this ° connection, based on pconn->nam...
Definition: connection.cpp:431
void conn_list_do_buffer(struct conn_list *dest)
Convenience functions to buffer a list of connections.
Definition: connection.cpp:310
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Freeze a connection list.
Definition: connection.cpp:656
bool conn_controls_player(const struct connection *pconn)
Returns TRUE if the given connection is attached to a player which it also controls (i....
Definition: connection.cpp:675
bool connection_send_data(struct connection *pconn, const unsigned char *data, int len)
Write data to socket.
Definition: connection.cpp:245
#define conn_list_iterate(connlist, pconn)
Definition: connection.h:99
#define conn_list_iterate_end
Definition: connection.h:101
void con_log_close()
Deinitialize logging.
Definition: console.cpp:123
void con_puts(enum rfc_status rfc_status, const char *str)
Write to console and add line-break, and show prompt if required.
Definition: console.cpp:162
@ C_SYNTAX
Definition: console.h:45
@ C_OK
Definition: console.h:41
int nation_history_gain(const struct player *pplayer)
How much nation-wide history player gains this turn.
Definition: culture.cpp:54
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
Initializes the output to the given output buffer and the given buffer size.
Definition: dataio_raw.cpp:144
void dio_put_uint16_raw(struct raw_data_out *dout, int value)
Insert value using 16 bits.
Definition: dataio_raw.cpp:248
void dio_put_uint8_raw(struct raw_data_out *dout, int value)
Insert value using 8 bits.
Definition: dataio_raw.cpp:229
void dio_put_string_raw(struct raw_data_out *dout, const char *value)
Insert nullptr-terminated string.
Definition: dataio_raw.cpp:418
size_t dio_output_used(struct raw_data_out *dout)
Return the maximum number of bytes used.
Definition: dataio_raw.cpp:157
void dio_put_bool32_raw(struct raw_data_out *dout, bool value)
Insert value 0 or 1 using 32 bits.
Definition: dataio_raw.cpp:357
void dio_output_rewind(struct raw_data_out *dout)
Rewinds the stream so that the put-functions start from the beginning.
Definition: dataio_raw.cpp:163
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
void send_diplomatic_meetings(struct connection *dest)
Send information on any on-going diplomatic meetings for connection's player.
Definition: diplhand.cpp:859
void free_treaties()
Free all the treaties currently in treaty list.
Definition: diplhand.cpp:89
void diplhand_free()
Free all the resources allocated by diplhand.
Definition: diplhand.cpp:78
const int TURNS_EXTEND_CEASEFIRE
Definition: diplhand.h:27
void edithand_free()
Free all memory used by data structures required for edit mode.
Definition: edithand.cpp:85
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Returns the effect bonus at a unit.
Definition: effects.cpp:869
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
Definition: effects.cpp:673
bool extra_causes_env_upset(struct extra_type *pextra, enum environment_upset_type upset)
Does the extra count toward environment upset?
Definition: extras.cpp:915
bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile)
Are all the requirements for extra to appear on tile fulfilled.
Definition: extras.cpp:1021
const char * extra_name_translation(const struct extra_type *pextra)
Return the (translated) name of the extra type.
Definition: extras.cpp:165
bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile)
Are all the requirements for extra to disappear from tile fulfilled.
Definition: extras.cpp:1036
#define extra_type_iterate(_p)
Definition: extras.h:279
#define extra_type_iterate_end
Definition: extras.h:285
#define extra_type_by_rmcause_iterate_end
Definition: extras.h:330
#define extra_type_by_rmcause_iterate(_rmcause, _extra)
Definition: extras.h:324
#define extra_type_by_cause_iterate_end
Definition: extras.h:307
#define extra_type_by_cause_iterate(_cause, _extra)
Definition: extras.h:299
void free_libfreeciv()
Free misc resources allocated for libfreeciv.
environment_upset_type
Definition: fc_types.h:1085
@ EUT_NUCLEAR_WINTER
Definition: fc_types.h:1085
@ EUT_GLOBAL_WARMING
Definition: fc_types.h:1085
int server_setting_id
Definition: fc_types.h:893
int Tech_type_id
Definition: fc_types.h:294
int Nation_type_id
Definition: fc_types.h:297
#define MAX_NUM_PLAYER_SLOTS
Definition: fc_types.h:24
#define MAX_LEN_NAME
Definition: fc_types.h:61
@ VC_CULTURE
Definition: fc_types.h:1083
@ VC_ALLIED
Definition: fc_types.h:1083
@ O_SHIELD
Definition: fc_types.h:86
@ O_FOOD
Definition: fc_types.h:85
@ O_TRADE
Definition: fc_types.h:87
@ BORDERS_ENABLED
Definition: fc_types.h:864
@ BORDERS_DISABLED
Definition: fc_types.h:863
#define IDENTITY_NUMBER_ZERO
Definition: fc_types.h:76
void fcdb_free(void)
Free resources allocated by fcdb system.
Definition: fcdb.cpp:145
void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
Must be called during the initialization phase of server and client to initialize the character encod...
Definition: fciconv.cpp:39
const char * get_internal_encoding()
Return the internal encoding.
Definition: fciconv.cpp:90
#define FC_DEFAULT_DATA_ENCODING
Definition: fciconv.h:69
const char * get_locale_dir()
Return directory containing locales.
Definition: fcintl.cpp:94
#define Q_(String)
Definition: fcintl.h:53
#define PL_(String1, String2, n)
Definition: fcintl.h:54
#define _(String)
Definition: fcintl.h:50
const char * tile_link(const struct tile *ptile)
Get a text link to a tile.
const char * unit_tile_link(const struct unit *punit)
Get a text link to a unit tile (make a clickable link to a tile with the unit type name as text).
const struct ft_color ftc_server
const struct ft_color ftc_editor
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
Definition: game.cpp:112
struct civ_game game
Definition: game.cpp:47
bool is_player_phase(const struct player *pplayer, int phase)
Return TRUE if it is this player's phase.
Definition: game.cpp:672
void game_map_init()
Initialize map-specific parts of the game structure.
Definition: game.cpp:437
void i_am_server()
Set program type to server.
Definition: game.cpp:62
void game_init(bool keep_ruleset_value)
Initialise all game settings.
Definition: game.cpp:420
struct world wld
Definition: game.cpp:48
int current_turn_timeout()
Return timeout value for the current turn.
Definition: game.cpp:808
int generate_save_name(const char *format, char *buf, int buflen, const char *reason)
Generate a default save file name and place it in the provided buffer.
Definition: game.cpp:756
void game_free()
Frees all memory of the game.
Definition: game.cpp:450
#define TURNS_NEEDED_TO_RANK
Definition: game.h:71
autosave_type
Definition: game.h:54
@ AS_INTERRUPT
Definition: game.h:58
@ AS_GAME_OVER
Definition: game.h:56
@ AS_QUITIDLE
Definition: game.h:57
@ AS_TIMER
Definition: game.h:59
@ AS_TURN
Definition: game.h:55
void init_new_game()
Initialize a new game: place the players' units onto the map, etc.
Definition: gamehand.cpp:416
struct unit_type * crole_to_unit_type(char crole, struct player *pplayer)
Get unit_type for given role character.
Definition: gamehand.cpp:108
void send_game_info(struct conn_list *dest)
Send game_info packet; some server options and various stuff...
Definition: gamehand.cpp:905
void send_year_to_clients()
Tell clients the year, and also update turn_done and nturns_idle fields for all players.
Definition: gamehand.cpp:880
int update_timeout()
adjusts game.info.timeout based on various server options
Definition: gamehand.cpp:989
void adv_city_free(struct city *pcity)
Free advisors related city data.
Definition: infracache.cpp:510
const char * name
Definition: inputfile.cpp:118
void log_time(const QString &msg, bool log)
Definition: log.cpp:253
#define fc_assert_msg(condition, message,...)
Definition: log.h:96
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert_exit_msg(condition, message,...)
Definition: log.h:135
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_action_msg(condition, action, message,...)
Definition: log.h:121
#define fc_assert_action(condition, action)
Definition: log.h:104
#define log_debug(message,...)
Definition: log.h:65
void main_map_free()
Free main map and related global structures.
Definition: map.cpp:525
bool startpos_nation_allowed(const struct startpos *psp, const struct nation_type *pnation)
Returns TRUE if the given nation can start here.
Definition: map.cpp:1428
bool map_is_empty()
Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded.
Definition: map.cpp:124
int map_num_tiles()
Returns the total number of (real) positions (or tiles) on the map.
Definition: map.cpp:954
bool startpos_allows_all(const struct startpos *psp)
Returns TRUE if any nation can start here.
Definition: map.cpp:1439
int map_startpos_count()
Is there start positions set for map.
Definition: map.cpp:1518
void main_map_allocate()
Allocate main map and related global structures.
Definition: map.cpp:487
#define whole_map_iterate(_map, _tile)
Definition: map.h:473
#define whole_map_iterate_end
Definition: map.h:480
@ MAPGEN_SCENARIO
Definition: map_types.h:43
bool map_generate(bool autosize, struct unit_type *initial_unit)
See stdinhand.c for information on map generation methods.
Definition: mapgen.cpp:1232
void generator_free()
Free resources allocated by the generator.
void disable_fog_of_war()
Turns FoW off for everyone.
Definition: maphand.cpp:1736
void player_map_init(struct player *pplayer)
Allocate space for map, and initialise the tiles.
Definition: maphand.cpp:1177
void map_calculate_borders()
Update borders for all sources.
Definition: maphand.cpp:2244
void map_set_border_vision(struct player *pplayer, const bool is_enabled)
Turn a players ability to see inside his borders on or off.
Definition: maphand.cpp:714
void send_map_info(struct conn_list *dest)
Send basic map information: map size, topology, and is_earth.
Definition: maphand.cpp:617
void send_all_known_tiles(struct conn_list *dest)
Send all tiles known to specified clients.
Definition: maphand.cpp:436
void show_map_to_all()
Unfogs all tiles for all players.
Definition: maphand.cpp:1167
void enable_fog_of_war()
Turns FoW on for everyone.
Definition: maphand.cpp:1711
void map_show_all(struct player *pplayer)
Shows the area to the player.
Definition: maphand.cpp:870
void map_show_tile(struct player *src_player, struct tile *ptile)
Shows the area to the player.
Definition: maphand.cpp:743
void nuclear_winter(int effect)
Wrapper for climate_change().
Definition: maphand.cpp:109
void create_extra(struct tile *ptile, const extra_type *pextra, struct player *pplayer)
Create extra to tile.
Definition: maphand.cpp:2405
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 give_shared_vision(struct player *pfrom, struct player *pto)
Starts shared vision between two players.
Definition: maphand.cpp:1568
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Players' information of tiles is tracked so that fogged area can be kept consistent even when the cli...
Definition: maphand.cpp:1341
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Returns city located at given tile from player map.
Definition: maphand.cpp:1317
void global_warming(int effect)
Wrapper for climate_change().
Definition: maphand.cpp:96
void mapimg_free()
Free all memory allocated by the map image subsystem.
Definition: mapimg.cpp:405
bool send_server_info_to_metaserver(enum meta_flag flag)
Control when we send info to the metaserver.
Definition: meta.cpp:469
#define DEFAULT_META_SERVER_ADDR
Definition: meta.h:21
#define DEFAULT_META_SERVER_NO_SEND
Definition: meta.h:20
@ META_INFO
Definition: meta.h:25
const char * multiplier_name_translation(const struct multiplier *pmul)
Return the (translated) name of the multiplier.
Definition: multipliers.cpp:94
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
Can player change multiplier value.
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Returns multiplier index.
Definition: multipliers.cpp:77
#define multipliers_iterate(_mul_)
Definition: multipliers.h:45
#define multipliers_iterate_end
Definition: multipliers.h:51
struct nation_type * nation_by_number(const Nation_type_id nation)
Return the nation with the given index.
Definition: nation.cpp:450
struct nation_style * style_of_nation(const struct nation_type *pnation)
Returns nation's style.
Definition: nation.cpp:558
struct nation_leader * nation_leader_by_name(const struct nation_type *pnation, const char *name)
Returns the nation leader structure which match 'name' or nullptr if not found.
Definition: nation.cpp:241
bool nation_leader_is_male(const struct nation_leader *pleader)
Return the sex of the nation leader.
Definition: nation.cpp:266
struct government * init_government_of_nation(const struct nation_type *pnation)
Returns initial government type for this nation.
Definition: nation.cpp:545
int nation_set_count()
Return the number of nation sets.
Definition: nation.cpp:577
std::vector< nation_type > nations
Definition: nation.cpp:38
bool is_nation_playable(const struct nation_type *nation)
Return whether a nation is "playable"; i.e., whether a human player can choose this nation.
Definition: nation.cpp:177
const char * nation_adjective_translation(const struct nation_type *pnation)
Return the (translated) adjective for the given nation.
Definition: nation.cpp:126
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
const char * nation_adjective_for_player(const struct player *pplayer)
Return the (translated) adjective for the given nation of a player.
Definition: nation.cpp:146
bool can_conn_edit_players_nation(const struct connection *pconn, const struct player *pplayer)
Return TRUE iff the editor is allowed to edit the player's nation in pregame.
Definition: nation.cpp:1046
const char * nation_leader_name(const struct nation_leader *pleader)
Return the name of the nation leader.
Definition: nation.cpp:257
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
Definition: nation.cpp:419
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Returns the list the nation leader names.
Definition: nation.cpp:206
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Returns which kind of barbarians can use this nation.
Definition: nation.cpp:188
#define nation_leader_list_iterate(leaderlist, pleader)
Definition: nation.h:45
#define nation_leader_list_iterate_end
Definition: nation.h:47
#define NO_NATION_SELECTED
Definition: nation.h:21
void event_cache_init()
Initializes the event cache.
Definition: notify.cpp:562
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
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
See notify_conn_packet - this is just the "non-v" version, with varargs.
Definition: notify.cpp:235
void event_cache_remove_old()
Remove the old events from the cache.
Definition: notify.cpp:591
void event_cache_free()
Frees the event cache.
Definition: notify.cpp:574
void event_cache_phases_invalidate()
Mark all existing phase values in event cache invalid.
Definition: notify.cpp:966
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
Split the attribute block into chunks and send them over pconn.
Definition: packets.cpp:681
const char * packet_name(enum packet_type type)
report_type
Definition: packets.h:52
@ REPORT_WONDERS_OF_THE_WORLD
Definition: packets.h:53
@ REPORT_DEMOGRAPHIC
Definition: packets.h:55
@ REPORT_TOP_5_CITIES
Definition: packets.h:54
@ REPORT_ACHIEVEMENTS
Definition: packets.h:56
struct player * player_by_name(const char *name)
Find player by given name.
Definition: player.cpp:800
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Return TRUE if players are in the same team.
Definition: player.cpp:1405
struct player * player_by_number(const int player_id)
Return struct player pointer for the given player index.
Definition: player.cpp:768
int player_number(const struct player *pplayer)
Return the player index/number/id.
Definition: player.cpp:756
int player_count()
Return the number of players.
Definition: player.cpp:739
int player_index(const struct player *pplayer)
Return the player index.
Definition: player.cpp:748
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Set the player's nation to the given nation (may be nullptr).
Definition: player.cpp:780
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
Definition: player.cpp:816
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
Definition: player.cpp:1334
struct player * player_by_user(const char *name)
Find player by its user name (not player/leader name)
Definition: player.cpp:860
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 player_list_iterate(playerlist, pplayer)
Definition: player.h:541
#define ANON_USER_NAME
Definition: player.h:31
static bool is_barbarian(const struct player *pplayer)
Definition: player.h:474
#define is_ai(plr)
Definition: player.h:227
#define player_list_iterate_end
Definition: player.h:543
#define players_iterate_alive_end
Definition: player.h:532
#define set_as_ai(plr)
Definition: player.h:229
#define ANON_PLAYER_NAME
Definition: player.h:26
#define is_human(plr)
Definition: player.h:226
#define players_iterate_alive(_pplayer)
Definition: player.h:526
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
void player_status_add(struct player *plr, enum player_status pstatus)
Add a status flag to a player.
Definition: plrhand.cpp:3145
void playercolor_init()
Initialise the player colors.
Definition: plrhand.cpp:3269
void playercolor_free()
Free the memory allocated for the player color.
Definition: plrhand.cpp:3278
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
bool server_player_set_name_full(const struct connection *caller, struct player *pplayer, const struct nation_type *pnation, const char *name, char *error_buf, size_t error_buf_len)
Try to set the player name to 'name'.
Definition: plrhand.cpp:2059
void assign_player_colors()
Permanently assign colors to any players that don't already have them.
Definition: plrhand.cpp:1608
struct rgbcolor * playercolor_get(int id)
Get the player color with the index 'id'.
Definition: plrhand.cpp:3309
void kill_player(struct player *pplayer)
Murder a player in cold blood.
Definition: plrhand.cpp:103
void send_player_info_c(struct player *src, struct conn_list *dest)
Send information about player slot 'src', or all valid (i.e.
Definition: plrhand.cpp:1048
void handle_diplomacy_cancel_pact_explicit(struct player *pplayer, int other_player_id, enum clause_type clause, bool protect_alliances)
A variant of handle_diplomacy_cancel_pact that allows the caller to explicitely control if war declar...
Definition: plrhand.cpp:761
bool player_status_check(struct player *plr, enum player_status pstatus)
Check player status flag.
Definition: plrhand.cpp:3153
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_remove_player(struct player *pplayer)
This function does not close any connections attached to this player.
Definition: plrhand.cpp:1825
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Initialize ANY newly-created player on the server.
Definition: plrhand.cpp:1494
int normal_player_count()
Return the number of non-barbarian players.
Definition: plrhand.cpp:3140
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Update contact info.
Definition: plrhand.cpp:2197
void update_capital(struct player *pplayer)
Recalculate what city is the named capital.
Definition: plrhand.cpp:590
struct player_economic player_limit_to_max_rates(struct player *pplayer)
The following limits a player's rates to those that are acceptable for the present form of government...
Definition: plrhand.cpp:1942
void shuffle_players()
Shuffle or reshuffle the player order, storing in static variables above.
Definition: plrhand.cpp:2302
int playercolor_count()
Number of player colors defined.
Definition: plrhand.cpp:3319
bool client_can_pick_nation(const struct nation_type *pnation)
Return whether a nation is "pickable" – whether players can select it at game start.
Definition: plrhand.cpp:2546
bool nation_is_in_current_set(const struct nation_type *pnation)
Is the nation in the currently selected nationset? If not, it's not allowed to appear in the game.
Definition: plrhand.cpp:2520
void enter_war(struct player *pplayer, struct player *pplayer2)
Two players enter war.
Definition: plrhand.cpp:711
void update_revolution(struct player *pplayer)
See if the player has finished their revolution.
Definition: plrhand.cpp:527
#define alive_phase_players_iterate(pplayer)
Definition: plrhand.h:113
#define alive_phase_players_iterate_end
Definition: plrhand.h:119
#define phase_players_iterate(pplayer)
Definition: plrhand.h:99
#define phase_players_iterate_end
Definition: plrhand.h:105
void fc_rand_set_init(bool init)
Sets whether the current state has been initialized.
Definition: rand.cpp:83
std::mt19937 & fc_rand_state()
Returns a reference to the current random generator state; eg for save/restore.
Definition: rand.cpp:123
void fc_srand(std::uint_fast32_t seed)
Initialize the generator; see comment at top of file.
Definition: rand.cpp:69
void fc_rand_seed(std::mt19937 &gen)
Seeds the given generator with a random value.
Definition: rand.cpp:113
#define fc_rand(_size)
Definition: rand.h:16
void report_final_scores(struct conn_list *dest)
Inform clients about player scores and statistics when the game ends.
Definition: report.cpp:1741
void report_wonders_of_the_world(struct conn_list *dest)
Send report listing all built and destroyed wonders, and wonders currently being built.
Definition: report.cpp:433
void report_demographics(struct connection *pconn)
Send demographics report; what gets reported depends on value of demographics server option.
Definition: report.cpp:1175
void make_history_report()
Produce random history report if it's time for one.
Definition: report.cpp:1718
void report_top_five_cities(struct conn_list *dest)
Send report listing the "best" 5 cities in the world.
Definition: report.cpp:354
void log_civ_score_free()
Free resources allocated for score logging system.
Definition: report.cpp:1474
void report_achievements(struct connection *pconn)
Send achievements list.
Definition: report.cpp:1237
void log_civ_score_now()
Create a log file of the civilizations so you can see what was happening.
Definition: report.cpp:1505
int player_tech_upkeep(const struct player *pplayer)
Calculate the bulb upkeep needed for all techs of a player.
Definition: research.cpp:1037
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
Definition: research.cpp:110
Tech_type_id research_goal_step(const struct research *presearch, Tech_type_id goal)
Return the next tech we should research to advance towards our goal.
Definition: research.cpp:714
bool research_is_valid(const struct research &presearch)
Checks whether the research object is valid in the current game.
Definition: research.cpp:125
std::vector< research > research_array
void rulesets_deinit()
Completely deinitialize ruleset system.
Definition: ruleset.cpp:8651
#define sanity_check()
Definition: sanitycheck.h:37
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Unconditionally save the game, with specified filename.
Definition: savemain.cpp:139
void calc_civ_score(struct player *pplayer)
Calculates the civilization score for the player.
Definition: score.cpp:255
int total_player_citizens(const struct player *pplayer)
Return the total number of citizens in the player's nation.
Definition: score.cpp:408
void script_server_signal_emit(const char *signal_name,...)
Invoke all the callback functions attached to a given signal.
void handle_conn_pong(struct connection *pconn)
Handle response to ping.
Definition: sernet.cpp:541
void close_connections_and_socket()
Close all network stuff: connections, listening sockets, metaserver connection...
Definition: sernet.cpp:106
void flush_packets()
Attempt to flush all information in the send buffers for upto 'netwait' seconds.
Definition: sernet.cpp:187
#define SERVER_SETTING_NONE
int setting_int_get(struct setting *pset)
Get value of integer setting.
Definition: settings.cpp:3502
void settings_game_start()
Save setting values at the start of the game.
Definition: settings.cpp:4404
void settings_free()
Deinitialize stuff related to this code module.
Definition: settings.cpp:4805
int setting_number(const struct setting *pset)
Returns the id to the given setting.
Definition: settings.cpp:3056
enum sset_type setting_type(const struct setting *pset)
Access function for the setting type.
Definition: settings.cpp:3092
struct setting * setting_by_number(int id)
Returns the setting to the given id.
Definition: settings.cpp:3031
struct setting * setting_by_name(const char *name)
Returns the setting to the given name.
Definition: settings.cpp:3039
struct setting_list * level[OLEVELS_NUM]
Definition: settings.cpp:167
const char * setting_name(const struct setting *pset)
Access function for the setting name.
Definition: settings.cpp:3065
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Compute the name of the current value of the setting.
Definition: settings.cpp:3946
void settings_turn()
Update stuff every turn that is related to this code module.
Definition: settings.cpp:4798
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Set the setting to 'val'.
Definition: settings.cpp:3720
int setting_bitwise_get(struct setting *pset)
Get value of bitwise setting.
Definition: settings.cpp:3936
bool setting_bool_get(struct setting *pset)
Get value of boolean setting.
Definition: settings.cpp:3391
void send_server_settings(struct conn_list *dest)
Tell the client about all server settings.
Definition: settings.cpp:4941
void free_nls()
Free memory allocated by Native Language Support.
Definition: shared.cpp:931
void init_nls()
Setup for Native Language Support, if configured to use it.
Definition: shared.cpp:871
#define ARRAY_SIZE(x)
Definition: shared.h:79
#define MIN(x, y)
Definition: shared.h:49
#define MAX(x, y)
Definition: shared.h:48
int rank_spaceship_arrival(struct player **result)
Rank launched player spaceships in order of arrival.
Definition: spacerace.cpp:451
double spaceship_arrival(const struct player *pplayer)
Return arrival year of player's spaceship (fractional, as one spaceship may arrive before another in ...
Definition: spacerace.cpp:437
void send_spaceship_info(struct player *src, struct conn_list *dest)
Send details of src's spaceship (or spaceships of all players if src is nullptr) to specified destina...
Definition: spacerace.cpp:120
void spaceship_arrived(struct player *pplayer)
Handle spaceship arrival.
Definition: spacerace.cpp:411
size_t size
Definition: specvec.h:64
void timing_log_init()
Initialize AI timing system.
Definition: srv_log.cpp:163
void timing_log_free()
Free AI timing system resources.
Definition: srv_log.cpp:177
void server_game_init(bool keep_ruleset_value)
Initialize game data for the server (corresponds to server_game_free).
Definition: srv_main.cpp:3179
void srv_scores()
Score calculation.
Definition: srv_main.cpp:2834
static int unit_wait_cmp(const struct unit_wait *const *a, const struct unit_wait *const *b)
Comparator for sorting unit_waits in chronological order.
Definition: srv_main.cpp:1203
void handle_nation_select_req(struct connection *pc, int player_no, Nation_type_id nation_no, bool is_male, const char *name, int style)
Handles a pick-nation packet from the client.
Definition: srv_main.cpp:2303
void srv_ready()
Set up one game.
Definition: srv_main.cpp:2888
static void ai_start_phase()
Called at the start of each (new) phase to do AI activities.
Definition: srv_main.cpp:1066
const char * aifill(int amount)
Fill or remove players to meet the given aifill.
Definition: srv_main.cpp:2440
void check_for_full_turn_done()
Check if turn is really done.
Definition: srv_main.cpp:2179
int mapimg_server_plrcolor_count()
Helper function for the mapimg module - number of player colors.
Definition: srv_main.cpp:3446
void identity_number_release(int id)
Mark identity number free.
Definition: srv_main.cpp:1964
void end_phase()
End a phase of movement.
Definition: srv_main.cpp:1397
int server_plr_tile_city_id_get(const struct tile *ptile, const struct player *pplayer)
Returns the id of the city the player map of 'pplayer' has at 'ptile' or IDENTITY_NUMBER_ZERO if the ...
Definition: srv_main.cpp:3254
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
void server_game_free()
Free game data that we reinitialize as part of a server soft restart.
Definition: srv_main.cpp:3204
bv_identity_numbers identity_numbers_used
Definition: srv_main.cpp:134
static void handle_observer_ready(struct connection *pconn)
Handle a player-ready packet from global observer.
Definition: srv_main.cpp:2368
BV_DEFINE(bv_identity_numbers, IDENTITY_NUMBER_SIZE)
static void do_reveal_effects()
Give map information to players with EFT_REVEAL_CITIES or EFT_REVEAL_MAP effects (traditionally from ...
Definition: srv_main.cpp:638
static void unit_wait_destroy(struct unit_wait *pwait)
Free function for unit_wait.
Definition: srv_main.cpp:3167
void handle_report_req(struct connection *pconn, enum report_type type)
Handle request asking report to be sent to client.
Definition: srv_main.cpp:1928
player * mapimg_server_tile_owner(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - tile owner.
Definition: srv_main.cpp:3385
bool force_end_of_sniff
Definition: srv_main.cpp:130
static void generate_players()
Assign random nations to players at game start.
Definition: srv_main.cpp:2596
void handle_player_ready(struct player *requestor, int player_no, bool is_ready)
Handle a player-ready packet.
Definition: srv_main.cpp:2386
static bool identity_number_is_used(int id)
Check whether identity number is currently allocated.
Definition: srv_main.cpp:1974
static int increment_identity_number()
Increment identity_number and return result.
Definition: srv_main.cpp:1982
static void do_have_contacts_effect()
Give contact to players with the EFT_HAVE_CONTACTS effect (traditionally from Marco Polo's Embassy).
Definition: srv_main.cpp:667
static enum server_states civserver_state
Definition: srv_main.cpp:124
static void update_diplomatics()
Check for cease-fires and armistices running out; update cancelling reasons and contact information.
Definition: srv_main.cpp:835
void save_game_auto(const char *save_reason, enum autosave_type type)
Save game with autosave filename.
Definition: srv_main.cpp:1788
const char * server_ss_name_get(server_setting_id id)
Returns the name of the server setting with the specified id.
Definition: srv_main.cpp:3281
bool check_for_game_over()
Returns TRUE if any one game end condition is fulfilled, FALSE otherwise.
Definition: srv_main.cpp:265
void start_game()
Start actual game.
Definition: srv_main.cpp:1830
static civtimer * eot_timer
Definition: srv_main.cpp:140
player * mapimg_server_tile_unit(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - unit owner.
Definition: srv_main.cpp:3426
void set_server_state(enum server_states newstate)
Set current server state.
Definition: srv_main.cpp:243
void end_turn()
Handle the end of each turn.
Definition: srv_main.cpp:1554
static void update_environmental_upset(enum environment_upset_type type, int *current, int *accum, int *level, int percent, void(*upset_action_fn)(int))
Handle environmental upsets, meaning currently pollution or fallout.
Definition: srv_main.cpp:717
void identity_number_reserve(int id)
Mark identity number allocated.
Definition: srv_main.cpp:1969
void server_quit()
Quit the server and exit.
Definition: srv_main.cpp:1869
struct server_arguments srvarg
Definition: srv_main.cpp:118
void init_game_seed()
Initialize the game seed.
Definition: srv_main.cpp:147
#define IDENTITY_NUMBER_SIZE
Definition: srv_main.cpp:132
known_type mapimg_server_tile_known(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - tile knowledge.
Definition: srv_main.cpp:3356
static void final_ruleset_adjustments()
Apply some final adjustments from the ruleset on to the game state.
Definition: srv_main.cpp:2861
static bool is_client_edit_packet(int type)
Returns TRUE if the packet type is an edit packet sent by the client.
Definition: srv_main.cpp:2015
bool game_was_started()
Returns iff the game was started once upon a time.
Definition: srv_main.cpp:251
static void notify_illegal_armistice_units(struct player *phost, struct player *pguest, int turns_left)
Notify about units at risk of disband due to armistice.
Definition: srv_main.cpp:761
bool server_ss_val_bool_get(server_setting_id id)
Returns the value of the boolean server setting with the specified id.
Definition: srv_main.cpp:3311
static void remove_illegal_armistice_units(struct player *plr1, struct player *plr2)
Remove illegal units when armistice turns into peace treaty.
Definition: srv_main.cpp:803
server_setting_id server_ss_by_name(const char *name)
Returns the id of the server setting with the specified name.
Definition: srv_main.cpp:3266
enum server_states server_state()
Return current server state.
Definition: srv_main.cpp:238
static void do_border_vision_effect()
Handle the vision granting effect EFT_BORDER_VISION.
Definition: srv_main.cpp:688
static void player_set_nation_full(struct player *pplayer, struct nation_type *pnation)
Tool for generate_players().
Definition: srv_main.cpp:2535
static void announce_player(struct player *pplayer)
Announce what nation player rules to everyone.
Definition: srv_main.cpp:2816
rgbcolor * mapimg_server_plrcolor_get(int i)
Helper function for the mapimg module - one player color.
Definition: srv_main.cpp:3451
static civtimer * between_turns
Definition: srv_main.cpp:142
void begin_phase(bool is_new_phase)
Begin a phase of movement.
Definition: srv_main.cpp:1213
bool server_packet_input(struct connection *pconn, void *packet, int type)
Returns FALSE if connection should be closed (because the clients was rejected).
Definition: srv_main.cpp:2024
void srv_init()
Initialize freeciv server.
Definition: srv_main.cpp:162
void handle_client_info(struct connection *pc, int obsolete, int emerg_version, const char *distribution)
Handle client info packet.
Definition: srv_main.cpp:222
int server_ss_val_int_get(server_setting_id id)
Returns the value of the integer server setting with the specified id.
Definition: srv_main.cpp:3326
unsigned int server_ss_val_bitwise_get(server_setting_id id)
Returns the value of the bitwise server setting with the specified id.
Definition: srv_main.cpp:3341
static bool has_been_srv_init
Definition: srv_main.cpp:137
void begin_turn(bool is_new_turn)
Handle the beginning of each turn.
Definition: srv_main.cpp:1083
void send_all_info(struct conn_list *dest)
Send all information for when game starts or client reconnects.
Definition: srv_main.cpp:607
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
static void kill_dying_players()
Check all players to see whether they are dying.
Definition: srv_main.cpp:1038
int identity_number()
Identity ids wrap at IDENTITY_NUMBER_SIZE, skipping IDENTITY_NUMBER_ZERO Setup in server_game_init()
Definition: srv_main.cpp:1993
enum sset_type server_ss_type_get(server_setting_id id)
Returns the type of the server setting with the specified id.
Definition: srv_main.cpp:3296
void update_nations_with_startpos()
Update information about which nations have start positions on the map.
Definition: srv_main.cpp:2239
terrain * mapimg_server_tile_terrain(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - tile terrain.
Definition: srv_main.cpp:3370
player * mapimg_server_tile_city(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - city owner.
Definition: srv_main.cpp:3401
#define IDENTITY_NUMBER_SKIP
Definition: srv_main.h:85
void stdinhand_turn()
Update stuff every turn that is related to this code module.
Definition: stdinhand.cpp:237
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Set an AI level from the server prompt.
Definition: stdinhand.cpp:2056
bool start_command(struct connection *caller, bool check, bool notify)
Handle start command.
Definition: stdinhand.cpp:6121
void stdinhand_free()
Deinitialize stuff related to this code module.
Definition: stdinhand.cpp:244
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Handle ai player ai toggling.
Definition: stdinhand.cpp:676
void set_running_game_access_level()
Adjust default command level on game start.
Definition: stdinhand.cpp:1570
Definition: city.h:291
struct player * owner
Definition: city.h:294
void(* unit_deallocate)(int unit_id)
Definition: game.h:288
struct civ_game::@28::@32 server
struct packet_ruleset_control control
Definition: game.h:74
struct civ_game::@30 callbacks
struct conn_list * est_connections
Definition: game.h:88
struct packet_game_info info
Definition: game.h:80
struct packet_scenario_info scenario
Definition: game.h:78
struct packet_timeout_info tinfo
Definition: game.h:82
struct government * government_during_revolution
Definition: game.h:85
int xsize
Definition: map_types.h:73
int ysize
Definition: map_types.h:73
QHash< struct tile *, struct startpos * > * startpos_table
Definition: map_types.h:77
struct civ_map::@39::@41 server
bool established
Definition: connection.h:131
struct player * playing
Definition: connection.h:142
enum cmdlevel access_level
Definition: connection.h:164
struct conn_list * self
Definition: connection.h:150
bool observer
Definition: connection.h:138
Nation leader.
Definition: nation.cpp:197
government * init_government
Definition: nation.h:103
struct player * player
Definition: nation.h:97
enum ai_level skill_level
Definition: player.h:109
int has_reason_to_cancel
Definition: player.h:197
int contact_turns_left
Definition: player.h:198
int auto_cancel_turn
Definition: player.h:200
int first_contact_turn
Definition: player.h:195
enum diplstate_type type
Definition: player.h:193
int culture
Definition: player.h:102
struct terrain * terrain
Definition: maphand.h:30
std::unique_ptr< vision_site > site
Definition: maphand.h:28
struct player * owner
Definition: maphand.h:31
Definition: player.h:231
bool random_name
Definition: player.h:277
struct player_ai ai_common
Definition: player.h:270
bool is_male
Definition: player.h:239
char username[MAX_LEN_NAME]
Definition: player.h:234
bool is_winner
Definition: player.h:251
bool is_connected
Definition: player.h:278
int nturns_idle
Definition: player.h:247
struct connection * current_conn
Definition: player.h:279
struct team * team
Definition: player.h:243
bool was_created
Definition: player.h:276
const struct ai_type * ai
Definition: player.h:271
struct unit_list * units
Definition: player.h:264
struct conn_list * connections
Definition: player.h:280
bool is_alive
Definition: player.h:250
struct player_score score
Definition: player.h:265
struct nation_type * nation
Definition: player.h:242
struct nation_style * style
Definition: player.h:261
bool is_ready
Definition: player.h:244
bool unassigned_user
Definition: player.h:235
Tech_type_id researching
Definition: research.h:45
Tech_type_id tech_goal
Definition: research.h:78
bool got_tech_multi
Definition: research.h:62
Tech_type_id researching_saved
Definition: research.h:55
bool got_tech
Definition: research.h:60
bool metaconnection_persistent
Definition: srv_main.h:32
bool user_specified_port
Definition: srv_main.h:41
bool auth_allow_guests
Definition: srv_main.h:62
bool fcdb_enabled
Definition: srv_main.h:59
bool metaserver_no_send
Definition: srv_main.h:30
QString saves_pathname
Definition: srv_main.h:49
bool auth_enabled
Definition: srv_main.h:61
QString scenarios_pathname
Definition: srv_main.h:50
bool auth_allow_newusers
Definition: srv_main.h:63
QString metaserver_addr
Definition: srv_main.h:31
Definition: servers.h:55
char *const value
Definition: settings.cpp:130
Definition: tile.h:42
struct unit_list * units
Definition: tile.h:50
int id
Definition: unit.h:120
Definition: unit.h:134
struct unit::@76::@79 server
struct player * owner
Definition: vision.h:116
struct civ_map map
Definition: world_object.h:21
struct nation_style * style_by_number(int id)
Return style of given id.
Definition: style.cpp:74
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
Definition: support.cpp:537
#define sz_strlcpy(dest, src)
Definition: support.h:140
const char * team_name_translation(const struct team *pteam)
Returns the name (translated) of the team.
Definition: team.cpp:393
int team_count()
Return the current number of teams.
Definition: team.cpp:354
const struct player_list * team_members(const struct team *pteam)
Returns the member list of the team.
Definition: team.cpp:427
#define teams_iterate_end
Definition: team.h:76
#define teams_iterate(_pteam)
Definition: team.h:71
#define A_UNSET
Definition: tech.h:41
#define A_UNKNOWN
Definition: tech.h:42
void init_tech(struct research *research, bool update)
Initializes tech data for the research.
Definition: techtools.cpp:1075
void choose_tech(struct research *research, Tech_type_id tech)
Called when a player chooses the tech he wants to research (or when the server chooses it for him aut...
Definition: techtools.cpp:987
void do_tech_parasite_effect(struct player *pplayer)
Give technologies to players with EFT_TECH_PARASITE (traditionally from the Great Library).
Definition: techtools.cpp:139
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 choose_random_tech(struct research *research)
Finds and chooses (sets) a random research target from among all those available until presearch->res...
Definition: techtools.cpp:972
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech)
Adds the given number of bulbs into the player's tech and (if necessary and 'check_tech' is TRUE) com...
Definition: techtools.cpp:650
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
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Remove extra and adjust other extras accordingly.
Definition: tile.cpp:605
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Return a known_type enumeration value for the tile.
Definition: tile.cpp:398
bool tile_extra_apply(struct tile *ptile, const extra_type *tgt)
Add extra and adjust other extras accordingly.
Definition: tile.cpp:578
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_worked(_tile)
Definition: tile.h:97
known_type
Definition: tile.h:28
@ TILE_KNOWN_SEEN
Definition: tile.h:31
#define tile_terrain(_tile)
Definition: tile.h:93
#define tile_has_extra(ptile, pextra)
Definition: tile.h:130
#define tile_owner(_tile)
Definition: tile.h:78
void timer_destroy(civtimer *t)
Deletes timer.
Definition: timing.cpp:66
void timer_start(civtimer *t)
Start timing, adding to previous accumulated time if timer has not been cleared.
Definition: timing.cpp:95
civtimer * timer_renew(civtimer *t, enum timer_timetype type, enum timer_use use)
Allocate a new timer, or reuse t, with specified "type" and "use".
Definition: timing.cpp:51
@ TIMER_ACTIVE
Definition: timing.h:25
@ TIMER_USER
Definition: timing.h:21
bool is_military_unit(const struct unit *punit)
Military units are capable of enforcing martial law.
Definition: unit.cpp:300
bool unit_is_cityfounder(const struct unit *punit)
Is a cityfounder unit?
Definition: unit.cpp:2389
#define unit_tile(_pu)
Definition: unit.h:371
#define unit_wait_list_link_iterate_end
Definition: unit.h:132
#define unit_owner(_pu)
Definition: unit.h:370
#define unit_wait_list_link_iterate(unit_wait_list, plink)
Definition: unit.h:130
#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
void update_unit_activities(struct player *pplayer)
Iterate through all units and update them.
Definition: unittools.cpp:646
void finalize_unit_phase_beginning(struct player *pplayer)
Iterate through all units and remember their current activities.
Definition: unittools.cpp:673
void execute_unit_orders(struct player *pplayer)
Iterate through all units and execute their orders.
Definition: unittools.cpp:659
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
void player_restore_units(struct player *pplayer)
Definition: unittools.cpp:481
bool unit_can_be_retired(struct unit *punit)
Units (usually barbarian units) may disband spontaneously if they are far from any enemy units or cit...
Definition: unittools.cpp:4906
void unit_activities_cancel_all_illegal_area(const struct tile *ptile)
Cancel all illegal activities done by units at the specified tile, and surrounding tiles.
Definition: unittools.cpp:801
void send_all_known_units(struct conn_list *dest)
For each specified connections, send information about all the units known to that player/conn.
Definition: unittools.cpp:2859
struct unit_type * get_role_unit(int role, int role_index)
Return index-th unit with specified role/flag.
Definition: unittype.cpp:1900
bool victory_enabled(enum victory_condition_type victory)
Whether victory condition is enabled.
Definition: victory.cpp:20
void vision_free(struct vision *vision)
Free the vision source.
Definition: vision.cpp:44
#define vision_layer_iterate(v)
Definition: vision.h:72
#define vision_layer_iterate_end
Definition: vision.h:77
void voting_turn()
Check running votes.
Definition: voting.cpp:731
void send_updated_vote_totals(struct conn_list *dest)
Sends a packet_vote_update to every conn in dest.
Definition: voting.cpp:884
void voting_free()
Free all memory used by this module.
Definition: voting.cpp:749
void clear_all_votes()
Remove all votes.
Definition: voting.cpp:219