Freeciv21
Develop your civilization from humble roots to a global empire
plrhand.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 // utility
15 #include "bitvector.h"
16 #include "log.h"
17 #include "rand.h"
18 #include "shared.h"
19 #include "support.h"
20 
21 // common
22 #include "citizens.h"
23 #include "culture.h"
24 #include "diptreaty.h"
25 #include "game.h"
26 #include "government.h"
27 #include "improvement.h"
28 #include "map.h"
29 #include "multipliers.h"
30 #include "packets.h"
31 #include "player.h"
32 #include "research.h"
33 #include "rgbcolor.h"
34 #include "style.h"
35 #include "tech.h"
36 #include "unitlist.h"
37 
38 // server
39 #include "aiiface.h"
40 #include "barbarian.h"
41 #include "citytools.h"
42 #include "cityturn.h"
43 #include "connecthand.h"
44 #include "diplhand.h"
45 #include "gamehand.h"
46 #include "maphand.h"
47 #include "mood.h"
48 #include "notify.h"
49 #include "plrhand.h"
50 #include "spacerace.h"
51 #include "spaceship.h"
52 #include "srv_main.h"
53 #include "stdinhand.h"
54 #include "techtools.h"
55 #include "unittools.h"
56 #include "voting.h"
57 
58 /* server/advisors */
59 #include "advdata.h"
60 /* server/scripting */
61 #include "script_server.h"
62 
63 // ai
64 #include "aitraits.h"
65 #include "difficulty.h"
66 #include "handicaps.h"
67 
68 struct rgbcolor;
69 
70 static void package_player_common(struct player *plr,
71  struct packet_player_info *packet);
72 
73 static void
74 package_player_diplstate(struct player *plr1, struct player *plr2,
75  struct packet_player_diplstate *packet_ds,
76  struct player *receiver, bool full);
77 static void package_player_info(struct player *plr,
78  struct packet_player_info *packet,
79  struct player *receiver, bool send_all);
80 
81 static void send_player_remove_info_c(const struct player_slot *pslot,
82  struct conn_list *dest);
83 static void send_player_info_c_real(struct player *src,
84  struct conn_list *dest);
85 static void send_player_diplstate_c_real(struct player *src,
86  struct conn_list *dest);
87 
88 static void send_nation_availability_real(struct conn_list *dest,
89  bool nationset_change);
90 
91 // Used by shuffle_players() and shuffled_player().
93 
94 // Used by player_info_freeze() and player_info_thaw().
95 static int player_info_frozen_level = 0;
96 
103 void kill_player(struct player *pplayer)
104 {
105  bool save_palace;
106  struct player *barbarians = nullptr;
107 
108  pplayer->is_alive = false;
109 
110  // reset player status
111  player_status_reset(pplayer);
112 
113  // Remove shared vision from dead player to friends.
114  players_iterate(aplayer)
115  {
116  if (gives_shared_vision(pplayer, aplayer)) {
117  remove_shared_vision(pplayer, aplayer);
118  }
119  }
121 
122  cancel_all_meetings(pplayer);
123 
124  /* Show entire map for players who are *not* in a team if revealmap is set
125  * to REVEAL_MAP_DEAD. */
126  if (game.server.revealmap & REVEAL_MAP_DEAD) {
127  bool someone_alive = false;
128 
129  player_list_iterate(team_members(pplayer->team), pteam_member)
130  {
131  if (pteam_member->is_alive) {
132  someone_alive = true;
133  break;
134  }
135  }
137 
138  if (!someone_alive) {
139  player_list_iterate(team_members(pplayer->team), pteam_member)
140  {
141  map_know_and_see_all(pteam_member);
142  }
144  }
145  }
146 
147  if (!is_barbarian(pplayer)) {
148  notify_player(nullptr, nullptr, E_DESTROYED, ftc_server,
149  _("The %s are no more!"),
150  nation_plural_for_player(pplayer));
151  }
152 
153  /* Transfer back all cities not originally owned by player to their
154  rightful owners, if they are still around */
155  save_palace = game.server.savepalace;
156  game.server.savepalace = false; // moving it around is dumb
157  city_list_iterate_safe(pplayer->cities, pcity)
158  {
159  if (pcity->original != pplayer && pcity->original->is_alive) {
160  /* Transfer city to original owner, kill all its units outside of
161  a radius of 3, give verbose messages of every unit transferred,
162  and raze buildings according to raze chance (also removes palace) */
163  if (transfer_city(pcity->original, pcity, 3, true, true, true, true)) {
164  script_server_signal_emit("city_transferred", pcity, pplayer,
165  pcity->original, "death-back_to_original");
166  }
167  }
168  }
170  game.server.savepalace = save_palace;
171 
172  // let there be civil war
173  if (game.info.gameloss_style & GAMELOSS_STYLE_CWAR) {
174  if (city_list_size(pplayer->cities)
175  >= 2 + MIN(GAME_MIN_CIVILWARSIZE, 2)) {
176  qDebug("Civil war strikes the remaining empire of %s", pplayer->name);
177  /* out of sheer cruelty we reanimate the player
178  * so he can behold what happens to his empire */
179  pplayer->is_alive = true;
180  (void) civil_war(pplayer);
181  } else {
182  qDebug("The empire of %s is too small for civil war.", pplayer->name);
183  }
184  }
185  pplayer->is_alive = false;
186 
187  if (game.info.gameloss_style & GAMELOSS_STYLE_BARB) {
188  // if parameter, create a barbarian, if possible
189  barbarians = create_barbarian_player(LAND_BARBARIAN);
190  }
191 
192  // if there are barbarians around, they will take the remaining cities
193  // vae victis!
194  if (barbarians) {
195  // Moving victim's palace around is a waste of time, as they're dead
196  bool palace = game.server.savepalace;
197 
198  game.server.savepalace = false;
199 
200  qDebug("Barbarians take the empire of %s", pplayer->name);
201  adv_data_phase_init(barbarians, true);
202 
203  // Transfer any remaining cities
204  city_list_iterate_safe(pplayer->cities, pcity)
205  {
206  if (transfer_city(barbarians, pcity, -1, false, false, false, false)) {
207  script_server_signal_emit("city_transferred", pcity, pplayer,
208  barbarians, "death-barbarians_get");
209  }
210  }
212 
213  game.server.savepalace = palace;
214 
215  resolve_unit_stacks(pplayer, barbarians, false);
216 
217  /* Barbarians don't get free buildings like Palaces, so we don't
218  * call city_build_free_buildings().
219  * FIXME: maybe this should be a ruleset option? */
220  } else {
221  // Destroy any remaining cities
222  city_list_iterate(pplayer->cities, pcity) { remove_city(pcity); }
224  }
225 
226  // Remove all units that are still ours
227  unit_list_iterate_safe(pplayer->units, punit)
228  {
229  wipe_unit(punit, ULR_PLAYER_DIED, nullptr);
230  }
232 
233  // Remove ownership of tiles
234  whole_map_iterate(&(wld.map), ptile)
235  {
236  if (tile_owner(ptile) == pplayer) {
237  map_claim_ownership(ptile, nullptr, nullptr, false);
238  }
239  if (extra_owner(ptile) == pplayer) {
240  ptile->extras_owner = nullptr;
241  }
242  }
244 
245  /* Ensure this dead player doesn't win with a spaceship.
246  * Now that would be truly unbelievably dumb - Per */
247  spaceship_init(&pplayer->spaceship);
248  send_spaceship_info(pplayer, nullptr);
249 
251 }
252 
256 static int get_player_maxrate(struct player *pplayer)
257 {
258  int maxrate = get_player_bonus(pplayer, EFT_MAX_RATES);
259 
260  if (maxrate == 0) {
261  return 100; // effects not initialized yet
262  }
263 
264  // 34 + 33 + 33 = 100
265  return CLIP(34, maxrate, 100);
266 }
267 
272 void handle_player_rates(struct player *pplayer, int tax, int luxury,
273  int science)
274 {
275  int maxrate;
276 
277  if (S_S_RUNNING != server_state()) {
278  qCritical("received player_rates packet from %s before start",
279  player_name(pplayer));
280  notify_player(pplayer, nullptr, E_BAD_COMMAND, ftc_server,
281  _("Cannot change rates before game start."));
282  return;
283  }
284 
285  if (tax + luxury + science != 100) {
286  return;
287  }
288  if (tax < 0 || tax > 100 || luxury < 0 || luxury > 100 || science < 0
289  || science > 100) {
290  return;
291  }
292  maxrate = get_player_maxrate(pplayer);
293  if (tax > maxrate || luxury > maxrate || science > maxrate) {
294  const char *rtype;
295 
296  if (tax > maxrate) {
297  rtype = _("Tax");
298  } else if (luxury > maxrate) {
299  rtype = _("Luxury");
300  } else {
301  rtype = _("Science");
302  }
303 
304  notify_player(pplayer, nullptr, E_BAD_COMMAND, ftc_server,
305  _("%s rate exceeds the max rate for %s."), rtype,
306  government_name_for_player(pplayer));
307  } else {
308  pplayer->economic.tax = tax;
309  pplayer->economic.luxury = luxury;
310  pplayer->economic.science = science;
311 
312  city_refresh_for_player(pplayer);
313  send_player_info_c(pplayer, pplayer->connections);
314  }
315 }
316 
322 void government_change(struct player *pplayer, struct government *gov,
323  bool revolution_finished)
324 {
325  struct research *presearch;
326 
327  if (revolution_finished) {
330  && nullptr != pplayer->target_government);
331  fc_assert_ret(pplayer->revolution_finishes <= game.info.turn);
332 
333  gov->changed_to_times++;
334  }
335 
336  pplayer->government = gov;
337  pplayer->target_government = nullptr;
338 
339  if (revolution_finished) {
340  log_debug("Revolution finished for %s. Government is %s. "
341  "Revofin %d (%d).",
342  player_name(pplayer), government_rule_name(gov),
343  pplayer->revolution_finishes, game.info.turn);
344  }
345 
346  notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_server,
347  _("%s now governs the %s as a %s."), player_name(pplayer),
348  nation_plural_for_player(pplayer),
350 
351  if (is_human(pplayer)) {
352  // Keep luxuries if we have any. Try to max out science. -GJW
353  int max = get_player_maxrate(pplayer);
354 
355  // only change rates if one exceeds the maximal rate
356  if (pplayer->economic.science > max || pplayer->economic.tax > max
357  || pplayer->economic.luxury > max) {
358  int save_science = pplayer->economic.science;
359  int save_tax = pplayer->economic.tax;
360  int save_luxury = pplayer->economic.luxury;
361 
362  pplayer->economic.science = MIN(100 - pplayer->economic.luxury, max);
363  pplayer->economic.tax = MIN(
364  100 - pplayer->economic.luxury - pplayer->economic.science, max);
365  pplayer->economic.luxury =
366  100 - pplayer->economic.science - pplayer->economic.tax;
367 
368  notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_server,
369  _("The national budget for the %s are changed from "
370  "%3d%%/%3d%%/%3d%% (tax/luxury/science) to "
371  "%3d%%/%3d%%/%3d%%."),
372  nation_plural_for_player(pplayer), save_tax, save_luxury,
373  save_science, pplayer->economic.tax,
374  pplayer->economic.luxury, pplayer->economic.science);
375  }
376  }
377 
378  check_player_max_rates(pplayer);
379  city_refresh_for_player(pplayer);
380  send_player_info_c(pplayer, pplayer->connections);
381 
382  presearch = research_get(pplayer);
383  research_update(presearch);
384  send_research_info(presearch, nullptr);
385 }
386 
390 int revolution_length(struct government *gov, struct player *plr)
391 {
392  int turns;
393 
396  // Targetless revolution not acceptable
398  plr, nullptr, E_REVOLT_DONE, ftc_server,
399  _("You can't revolt without selecting target government."));
400  return -1;
401  }
402 
403  turns = GAME_DEFAULT_REVOLUTION_LENGTH; // To avoid compiler warning
404  switch (game.info.revolentype) {
405  case REVOLEN_FIXED:
406  turns = game.server.revolution_length;
407  break;
408  case REVOLEN_RANDOM:
409  turns = fc_rand(game.server.revolution_length) + 1;
410  break;
411  case REVOLEN_QUICKENING:
412  case REVOLEN_RANDQUICK:
413  turns = game.server.revolution_length - gov->changed_to_times;
414  turns = MAX(1, turns);
415  if (game.info.revolentype == REVOLEN_RANDQUICK) {
416  turns = fc_rand(turns) + 1;
417  }
418  break;
419  }
420 
421  return turns;
422 }
423 
429 {
430  int turns;
432  bool anarchy;
433 
434  if (!gov || !can_change_to_government(pplayer, gov)) {
435  return;
436  }
437 
438  log_debug("Government changed for %s. Target government is %s; "
439  "old %s. Revofin %d, Turn %d.",
440  player_name(pplayer), government_rule_name(gov),
442  pplayer->revolution_finishes, game.info.turn);
443 
444  anarchy = get_player_bonus(pplayer, EFT_NO_ANARCHY) <= 0;
445 
446  // Set revolution_finishes value.
447  if (pplayer->revolution_finishes > 0) {
448  /* Player already has an active revolution. Note that the finish time
449  * may be in the future (we're waiting for it to finish), the current
450  * turn (it just finished - but isn't reset until the end of the turn)
451  * or even in the past (if the player is in anarchy and hasn't chosen
452  * a government). */
453  turns = pplayer->revolution_finishes - game.info.turn;
454  } else if ((is_ai(pplayer) && !has_handicap(pplayer, H_REVOLUTION))
455  || !anarchy) {
456  // AI players without the H_REVOLUTION handicap can skip anarchy
457  turns = 0;
458  } else {
459  turns = revolution_length(gov, pplayer);
460  if (turns < 0) {
461  return;
462  }
463  }
464 
465  if (anarchy && turns <= 0
467  // Multiple changes attempted after single anarchy period
468  if (game.info.revolentype == REVOLEN_QUICKENING) {
469  notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_server,
470  _("You can't revolt the same turn you finished previous "
471  "revolution."));
472  return;
473  }
474  }
475 
477  pplayer->target_government = gov;
478  pplayer->revolution_finishes = game.info.turn + turns;
479 
480  log_debug("Revolution started for %s. Target government is %s. "
481  "Revofin %d (%d).",
482  player_name(pplayer),
484  pplayer->revolution_finishes, game.info.turn);
485 
486  // Now see if the revolution is instantaneous.
487  if (turns <= 0
489  government_change(pplayer, pplayer->target_government, true);
490  return;
491  } else if (turns > 0) {
492  notify_player(pplayer, nullptr, E_REVOLT_START, ftc_server,
493  /* TRANS: this is a message event so don't make it
494  * too long. */
495  PL_("The %s have incited a revolt! "
496  "%d turn of anarchy will ensue! "
497  "Target government is %s.",
498  "The %s have incited a revolt! "
499  "%d turns of anarchy will ensue! "
500  "Target government is %s.",
501  turns),
502  nation_plural_for_player(pplayer), turns,
504  } else {
507  notify_player(pplayer, nullptr, E_REVOLT_START, ftc_server,
508  _("Revolution: returning to anarchy."));
509  }
510 
511  check_player_max_rates(pplayer);
512  city_refresh_for_player(pplayer);
513  send_player_info_c(pplayer, pplayer->connections);
514 
515  log_debug("Government change complete for %s. Target government is %s; "
516  "now %s. Turn %d; revofin %d.",
517  player_name(pplayer),
520  game.info.turn, pplayer->revolution_finishes);
521 }
522 
527 void update_revolution(struct player *pplayer)
528 {
529  struct government *current_gov;
530 
531  /* The player's revolution counter is stored in the revolution_finishes
532  * field. This value has the following meanings:
533  * - If negative (-1), then the player is not in a revolution. In this
534  * case the player should never be in anarchy.
535  * - If positive, the player is in the middle of a revolution. In this
536  * case the value indicates the turn in which the revolution finishes.
537  * * If this value is > than the current turn, then the revolution is
538  * in progress. In this case the player should always be in anarchy.
539  * * If the value is == to the current turn, then the revolution is
540  * finished. The player may now choose a government. However the
541  * value isn't reset until the end of the turn. If the player has
542  * chosen a government by the end of the turn, then the revolution is
543  * over and the value is reset to -1.
544  * * If the player doesn't pick a government then the revolution
545  * continues. At this point the value is <= to the current turn,
546  * and the player can leave the revolution at any time. The value
547  * is reset at the end of any turn when a non-anarchy government is
548  * chosen.
549  */
550  log_debug("Update revolution for %s. Current government %s, "
551  "target %s, revofin %d, turn %d.",
552  player_name(pplayer),
554  pplayer->target_government
556  : "(none)",
557  pplayer->revolution_finishes, game.info.turn);
558 
559  current_gov = government_of_player(pplayer);
560 
561  if (current_gov == game.government_during_revolution
562  && pplayer->revolution_finishes <= game.info.turn) {
564  /* If the revolution is over and a target government is set, go into
565  * the new government. */
566  log_debug("Update: finishing revolution for %s.",
567  player_name(pplayer));
568  government_change(pplayer, pplayer->target_government, true);
569  } else {
570  /* If the revolution is over but there's no target government set,
571  * alert the player. */
572  notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_any,
573  _("You should choose a new government from the "
574  "government menu."));
575  }
576  } else if (government_of_player(pplayer)
578  && pplayer->revolution_finishes < game.info.turn) {
579  /* Reset the revolution counter. If the player has another revolution
580  * they'll have to re-enter anarchy. */
581  log_debug("Update: resetting revofin for %s.", player_name(pplayer));
582  pplayer->revolution_finishes = -1;
583  send_player_info_c(pplayer, pplayer->connections);
584  }
585 }
586 
590 void update_capital(struct player *pplayer)
591 {
592  int max_value = 0;
593  struct city *primary_capital = nullptr;
594  int same_value_count = 0;
595 
596  city_list_iterate(pplayer->cities, pcity)
597  {
598  int value = get_city_bonus(pcity, EFT_CAPITAL_CITY);
599 
600  if (value > max_value) {
601  max_value = value;
602  primary_capital = pcity;
603  same_value_count = 1;
604  /* Mark it at least some kind of capital, might turn to named capital
605  * after all have been processed. */
606  pcity->capital = CAPITAL_SECONDARY;
607  } else if (value > 0) {
608  // Mark it at least some kind of capital.
609  pcity->capital = CAPITAL_SECONDARY;
610  if (value == max_value) {
611  fc_assert(same_value_count >= 1);
612  same_value_count++;
613  if (fc_rand(same_value_count) == 1) {
614  primary_capital = pcity;
615  }
616  }
617  } else {
618  // Not capital at all
619  pcity->capital = CAPITAL_NOT;
620  }
621  }
623 
624  if (primary_capital != nullptr) {
625  primary_capital->capital = CAPITAL_PRIMARY;
626  pplayer->primary_capital_id = primary_capital->id;
627  } else {
628  pplayer->primary_capital_id = 0;
629  }
630 }
631 
637 void check_player_max_rates(struct player *pplayer)
638 {
639  struct player_economic old_econ = pplayer->economic;
640 
641  pplayer->economic = player_limit_to_max_rates(pplayer);
642  if (old_econ.tax > pplayer->economic.tax) {
643  notify_player(pplayer, nullptr, E_NEW_GOVERNMENT, ftc_server,
644  _("Tax rate exceeded the max rate; adjusted."));
645  }
646  if (old_econ.science > pplayer->economic.science) {
647  notify_player(pplayer, nullptr, E_NEW_GOVERNMENT, ftc_server,
648  _("Science rate exceeded the max rate; adjusted."));
649  }
650  if (old_econ.luxury > pplayer->economic.luxury) {
651  notify_player(pplayer, nullptr, E_NEW_GOVERNMENT, ftc_server,
652  _("Luxury rate exceeded the max rate; adjusted."));
653  }
654 }
655 
666  struct player *pplayer, struct player *pplayer2,
667  const struct unit_list *pplayer_seen_units,
668  const struct unit_list *pplayer2_seen_units)
669 {
670  /* The client needs updated diplomatic state, because it is used
671  * during calculation of new states of occupied flags in cities */
672  send_player_all_c(pplayer, nullptr);
673  send_player_all_c(pplayer2, nullptr);
674  remove_allied_visibility(pplayer, pplayer2, pplayer_seen_units);
675  remove_allied_visibility(pplayer2, pplayer, pplayer2_seen_units);
676  resolve_unit_stacks(pplayer, pplayer2, true);
677 }
678 
682 static void maybe_claim_base(struct tile *ptile, struct player *new_owner,
683  struct player *old_owner)
684 {
685  bool claim = false;
686 
687  unit_list_iterate(ptile->units, punit)
688  {
689  if (unit_owner(punit) == new_owner
690  && tile_has_claimable_base(ptile, unit_type_get(punit))) {
691  claim = true;
692  break;
693  }
694  }
696 
697  if (claim) {
698  extra_type_by_cause_iterate(EC_BASE, pextra)
699  {
700  map_claim_base(ptile, pextra, new_owner, old_owner);
701  }
703 
704  ptile->extras_owner = new_owner;
705  }
706 }
707 
711 void enter_war(struct player *pplayer, struct player *pplayer2)
712 {
713  // Claim bases where units are already standing
714  whole_map_iterate(&(wld.map), ptile)
715  {
716  struct player *old_owner = extra_owner(ptile);
717 
718  if (old_owner == pplayer2) {
719  maybe_claim_base(ptile, pplayer, old_owner);
720  } else if (old_owner == pplayer) {
721  maybe_claim_base(ptile, pplayer2, old_owner);
722  }
723  }
725 }
726 
731 {
732  pplayer->last_war_action = game.info.turn;
733  send_player_info_c(pplayer, nullptr);
734 }
735 
746  int other_player_id,
747  enum clause_type clause)
748 {
749  handle_diplomacy_cancel_pact_explicit(pplayer, other_player_id, clause,
750  is_human(pplayer));
751 }
752 
762  int other_player_id,
763  enum clause_type clause,
764  bool protect_alliances)
765 {
766  enum diplstate_type old_type;
767  enum diplstate_type new_type;
768  enum dipl_reason diplcheck;
769  bool repeat = false;
770  struct player *pplayer2 = player_by_number(other_player_id);
771  struct player_diplstate *ds_plrplr2, *ds_plr2plr;
772  struct unit_list *pplayer_seen_units, *pplayer2_seen_units;
773 
774  if (nullptr == pplayer2 || players_on_same_team(pplayer, pplayer2)) {
775  return;
776  }
777 
778  old_type = player_diplstate_get(pplayer, pplayer2)->type;
779 
780  if (clause == CLAUSE_VISION) {
781  if (!gives_shared_vision(pplayer, pplayer2)) {
782  return;
783  }
784  remove_shared_vision(pplayer, pplayer2);
785  notify_player(pplayer2, nullptr, E_TREATY_BROKEN, ftc_server,
786  _("%s no longer gives us shared vision!"),
787  player_name(pplayer));
788  return;
789  }
790 
791  diplcheck = pplayer_can_cancel_treaty(pplayer, pplayer2);
792 
793  /* The senate may not allow you to break the treaty. In this case you
794  * must first dissolve the senate then you can break it. */
795  if (diplcheck == DIPL_SENATE_BLOCKING) {
796  notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
797  _("The senate will not allow you to break treaty "
798  "with the %s. You must either dissolve the senate "
799  "or wait until a more timely moment."),
800  nation_plural_for_player(pplayer2));
801  return;
802  }
803 
804  if (diplcheck != DIPL_OK) {
805  return;
806  }
807 
808  // check what the new status will be
809  new_type = cancel_pact_result(old_type);
810 
811  // avoid accidentally breaking alliances
812  if (protect_alliances && new_type == DS_WAR) {
813  bool blocking_alliances = false;
814 
815  players_iterate_alive(pplayer3)
816  {
817  if (pplayer3 != pplayer && pplayer3 != pplayer2
818  && pplayers_allied(pplayer3, pplayer)
819  && pplayers_allied(pplayer3, pplayer2)) {
820  if (players_on_same_team(pplayer, pplayer3)) {
821  // if pplayer3 is an AI, let them break their alliance as we
822  // can't coordinate with them in a way, that they would cancel
823  // alliances in preparation of war on team level.
824  if (is_ai(pplayer3)) {
825  continue;
826  }
827 
829  pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
830  _("Your advisors discourage you from cancelling your pact "
831  "with the %s, as this would force your team mate %s to "
832  "break their alliance with the %s."),
833  nation_plural_for_player(pplayer2), player_name(pplayer3),
834  nation_plural_for_player(pplayer2));
835  } else {
836  notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
837  _("Your advisors discourage you from cancelling "
838  "your pact with the %s, as this would break your "
839  "alliance with the %s."),
840  nation_plural_for_player(pplayer2),
841  nation_plural_for_player(pplayer3));
842  }
843 
844  blocking_alliances = true;
845  }
846  }
848 
849  if (blocking_alliances) {
850  return;
851  }
852  }
853 
854  reject_all_treaties(pplayer);
855  reject_all_treaties(pplayer2);
856  // else, breaking a treaty
857 
858  // check what the new status will be
859  new_type = cancel_pact_result(old_type);
860 
861  ds_plrplr2 = player_diplstate_get(pplayer, pplayer2);
862  ds_plr2plr = player_diplstate_get(pplayer2, pplayer);
863 
864  if (old_type == DS_ALLIANCE) {
865  pplayer_seen_units = get_units_seen_via_ally(pplayer, pplayer2);
866  pplayer2_seen_units = get_units_seen_via_ally(pplayer2, pplayer);
867  } else {
868  pplayer_seen_units = nullptr;
869  pplayer2_seen_units = nullptr;
870  }
871 
872  // do the change
873  ds_plrplr2->type = ds_plr2plr->type = new_type;
874  ds_plrplr2->turns_left = ds_plr2plr->turns_left = 16;
875 
876  if (new_type == DS_WAR) {
879  }
880 
881  /* If the old state was alliance, the players' units can share tiles
882  illegally, and we need to call resolve_unit_stacks() */
883  if (old_type == DS_ALLIANCE) {
884  fc_assert(pplayer_seen_units != nullptr);
885  fc_assert(pplayer2_seen_units != nullptr);
886 
888  pplayer, pplayer2, pplayer_seen_units, pplayer2_seen_units);
889  unit_list_destroy(pplayer_seen_units);
890  unit_list_destroy(pplayer2_seen_units);
891  }
892 
893  // if there's a reason to cancel the pact, do it without penalty
894  /* FIXME: in the current implementation if you break more than one
895  * treaty simultaneously it may partially succed: the first treaty-breaking
896  * will happen but the second one will fail. */
897  if (get_player_bonus(pplayer, EFT_HAS_SENATE) > 0 && !repeat) {
898  if (ds_plrplr2->has_reason_to_cancel > 0) {
899  notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
900  _("The senate passes your bill because of the "
901  "constant provocations of the %s."),
902  nation_plural_for_player(pplayer2));
903  } else if (new_type == DS_WAR) {
904  notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
905  _("The senate refuses to break treaty with the %s, "
906  "but you have no trouble finding a new senate."),
907  nation_plural_for_player(pplayer2));
908  }
909  }
910  if (new_type == DS_WAR) {
911  call_incident(INCIDENT_WAR, CBR_VICTIM_ONLY, nullptr, pplayer, pplayer2);
912 
913  enter_war(pplayer, pplayer2);
914  }
915  ds_plrplr2->has_reason_to_cancel = 0;
916 
917  send_player_all_c(pplayer, nullptr);
918  send_player_all_c(pplayer2, nullptr);
919 
920  /*
921  * Refresh all cities which have a unit of the other side within
922  * city range.
923  */
926  sync_cities();
927 
928  notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
929  _("The diplomatic state between the %s "
930  "and the %s is now %s."),
931  nation_plural_for_player(pplayer),
932  nation_plural_for_player(pplayer2),
933  diplstate_type_translated_name(new_type));
934  notify_player(pplayer2, nullptr, E_TREATY_BROKEN, ftc_server,
935  _(" %s canceled the diplomatic agreement! "
936  "The diplomatic state between the %s and the %s "
937  "is now %s."),
938  player_name(pplayer), nation_plural_for_player(pplayer2),
939  nation_plural_for_player(pplayer),
940  diplstate_type_translated_name(new_type));
941 
942  // Check fall-out of a war declaration. This is only relevant if an AI
943  // declares war or if we cut through the web of alliances after an AI
944  // has declared war.
945  players_iterate_alive(other)
946  {
947  if (other != pplayer && other != pplayer2 && new_type == DS_WAR
948  && pplayers_allied(pplayer2, other)
949  && pplayers_allied(pplayer, other)) {
950  if (!players_on_same_team(pplayer, other)) {
951  /* If an ally declares war on another ally, break off your alliance
952  * to the aggressor. This prevents in-alliance wars, which are not
953  * permitted. */
954  notify_player(other, nullptr, E_TREATY_BROKEN, ftc_server,
955  _("%s has attacked your ally %s! "
956  "You cancel your alliance to the aggressor."),
957  player_name(pplayer), player_name(pplayer2));
958  player_diplstate_get(other, pplayer)->has_reason_to_cancel = 1;
961  CLAUSE_ALLIANCE, false);
962  } else {
963  /* We are in the same team as the agressor; we cannot break
964  * alliance with him. We trust our team mate and break alliance
965  * with the attacked player */
966  notify_player(other, nullptr, E_TREATY_BROKEN, ftc_server,
967  _("Your team mate %s declared war on %s. "
968  "You are obligated to cancel alliance with %s."),
969  player_name(pplayer),
970  nation_plural_for_player(pplayer2),
971  player_name(pplayer2));
973  CLAUSE_ALLIANCE, false);
974  }
975  }
976  }
978 }
979 
983 static void send_player_remove_info_c(const struct player_slot *pslot,
984  struct conn_list *dest)
985 {
986  if (!dest) {
987  dest = game.est_connections;
988  }
989 
991 
992  conn_list_iterate(dest, pconn)
993  {
994  dsend_packet_player_remove(pconn, player_slot_index(pslot));
995  }
997 }
998 
1006 
1012 {
1013  if (0 == --player_info_frozen_level) {
1015  send_player_info_c(nullptr, nullptr);
1016  }
1018 }
1019 
1031 void send_player_all_c(struct player *src, struct conn_list *dest)
1032 {
1033  send_player_info_c(src, dest);
1034  send_player_diplstate_c(src, dest);
1035 }
1036 
1048 void send_player_info_c(struct player *src, struct conn_list *dest)
1049 {
1050  if (0 < player_info_frozen_level) {
1051  return; // Discard, see comment for player_info_freeze().
1052  }
1053 
1054  if (src != nullptr) {
1055  send_player_info_c_real(src, dest);
1056  return;
1057  }
1058 
1059  players_iterate(pplayer) { send_player_info_c_real(pplayer, dest); }
1061 }
1062 
1067 static void send_player_info_c_real(struct player *src,
1068  struct conn_list *dest)
1069 {
1070  struct packet_player_info info;
1071 
1072  fc_assert_ret(src != nullptr);
1073 
1074  if (!dest) {
1075  dest = game.est_connections;
1076  }
1077 
1078  package_player_common(src, &info);
1079 
1080  conn_list_iterate(dest, pconn)
1081  {
1082  if (nullptr == pconn->playing && pconn->observer) {
1083  // Global observer.
1084  package_player_info(src, &info, nullptr, true);
1085  } else if (nullptr != pconn->playing) {
1086  // Players (including regular observers)
1087  package_player_info(src, &info, pconn->playing, false);
1088  } else {
1089  // Detached
1090  package_player_info(src, &info, nullptr, false);
1091  }
1092  send_packet_player_info(pconn, &info);
1093  }
1095 }
1096 
1106 void send_player_diplstate_c(struct player *src, struct conn_list *dest)
1107 {
1108  if (src != nullptr) {
1109  send_player_diplstate_c_real(src, dest);
1110  return;
1111  }
1112 
1113  players_iterate(pplayer) { send_player_diplstate_c_real(pplayer, dest); }
1115 }
1116 
1121 static void send_player_diplstate_c_real(struct player *plr1,
1122  struct conn_list *dest)
1123 {
1124  fc_assert_ret(plr1 != nullptr);
1125 
1126  if (!dest) {
1127  dest = game.est_connections;
1128  }
1129 
1130  conn_list_iterate(dest, pconn)
1131  {
1132  players_iterate(plr2)
1133  {
1134  struct packet_player_diplstate packet_ds;
1135 
1136  if (nullptr == pconn->playing && pconn->observer) {
1137  // Global observer.
1138  package_player_diplstate(plr1, plr2, &packet_ds, pconn->playing,
1139  true);
1140  } else {
1141  // Players (including regular observers)
1142  package_player_diplstate(plr1, plr2, &packet_ds, pconn->playing,
1143  false);
1144  }
1145  send_packet_player_diplstate(pconn, &packet_ds);
1146  }
1148  }
1150 }
1151 
1155 static void package_player_common(struct player *plr,
1156  struct packet_player_info *packet)
1157 {
1158  int i;
1159  struct music_style *music;
1160 
1161  packet->playerno = player_number(plr);
1162  sz_strlcpy(packet->name, player_name(plr));
1163  sz_strlcpy(packet->username, plr->username);
1164  packet->unassigned_user = plr->unassigned_user;
1165  packet->nation = plr->nation ? nation_index(plr->nation) : NATION_NONE;
1166  packet->is_male = plr->is_male;
1167  packet->team = plr->team ? team_number(plr->team) : team_count();
1168  packet->is_ready = plr->is_ready;
1169  packet->was_created = plr->was_created;
1170  packet->style = plr->style ? style_number(plr->style) : 0;
1171 
1172  /* I think we could safely move the music style selection to
1173  * client side to not have it burden server side. Client could
1174  * actually avoid it completely when music disabled from the client
1175  * options. Client has no use for music styles of other players, and there
1176  * should be no such information about the player him/herself needed to
1177  * determine the music style that client does not know. */
1178  music = player_music_style(plr);
1179  if (music != nullptr) {
1180  packet->music_style = music_style_number(music);
1181  } else {
1182  packet->music_style = -1; // No music style available
1183  }
1184 
1185  packet->is_alive = plr->is_alive;
1186  packet->turns_alive = plr->turns_alive;
1187  packet->is_connected = plr->is_connected;
1188  packet->flags = plr->flags;
1189  packet->ai_skill_level = is_ai(plr) ? plr->ai_common.skill_level : 0;
1190  for (i = 0; i < MAX_NUM_PLAYER_SLOTS; i++) {
1191  packet->love[i] = plr->ai_common.love[i];
1192  }
1193  packet->barbarian_type = plr->ai_common.barbarian_type;
1194 
1195  packet->phase_done = plr->phase_done;
1196  packet->nturns_idle = plr->nturns_idle;
1197 
1198  packet->science_cost = plr->ai_common.science_cost;
1199 }
1200 
1210 static void package_player_info(struct player *plr,
1211  struct packet_player_info *packet,
1212  struct player *receiver, bool send_all)
1213 {
1214  if (server_state() < S_S_RUNNING || (!send_all && !receiver)) {
1215  BV_CLR_ALL(packet->visible);
1216  } else if (send_all || players_on_same_team(plr, receiver)) {
1217  // Teamed players always share their information -- it's in their best
1218  // interest to communicate anyway.
1219  BV_SET_ALL(packet->visible);
1220  } else {
1221  BV_CLR_ALL(packet->visible);
1222 
1223  // Players on a team share the intelligence they gather -- it's in their
1224  // best interest to communicate anyway.
1225  const auto team = team_members(receiver->team);
1226  for (int i = 0; i < NI_COUNT; ++i) {
1227  player_list_iterate(team, team_mate)
1228  {
1229  if (get_player_intel_bonus(team_mate, plr,
1230  static_cast<national_intelligence>(i),
1231  EFT_NATION_INTELLIGENCE)
1232  > 0) {
1233  BV_SET(packet->visible, i);
1234  break;
1235  }
1236  }
1238  }
1239  }
1240 
1241  // multipliers
1242  packet->multip_count = multiplier_count();
1243  if (BV_ISSET(packet->visible, NI_MULTIPLIERS)) {
1244  multipliers_iterate(pmul)
1245  {
1246  packet->multiplier[multiplier_index(pmul)] =
1247  plr->multipliers[multiplier_index(pmul)];
1248  packet->multiplier_target[multiplier_index(pmul)] =
1250  }
1252  } else {
1253  multipliers_iterate(pmul)
1254  {
1255  packet->multiplier[multiplier_index(pmul)] = 0;
1256  packet->multiplier_target[multiplier_index(pmul)] = 0;
1257  }
1259  }
1260 
1261  // Wonder information
1262  if (BV_ISSET(packet->visible, NI_WONDERS)) {
1263  for (int i = 0; i < B_LAST; ++i) {
1264  // Lost, not built, doesn't exist (still need to fill the array),
1265  // global observers
1266  if (plr->wonders[i] <= 0 || i >= improvement_count()
1267  || receiver == nullptr) {
1268  packet->wonders[i] = plr->wonders[i];
1269  continue;
1270  }
1271 
1272  const auto pimprove = improvement_by_number(i);
1273  const auto pcity = game_city_by_number(plr->wonders[i]);
1274  const auto bonus = get_target_bonus_effects(
1275  nullptr, city_owner(pcity), receiver, pcity, pimprove, nullptr,
1276  nullptr, nullptr, nullptr, nullptr, nullptr, EFT_WONDER_VISIBLE);
1277  if (players_on_same_team(plr, receiver) || bonus > 0) {
1278  packet->wonders[i] = plr->wonders[i];
1279  } else {
1280  packet->wonders[i] = WONDER_NOT_BUILT;
1281  }
1282  }
1283  } else {
1284  for (int i = 0; i < B_LAST; ++i) {
1285  packet->wonders[i] = WONDER_NOT_BUILT;
1286  }
1287  }
1288 
1289  // Color is harmless, always send
1290  if (plr->rgb != nullptr) {
1291  packet->color_valid = true;
1292  packet->color_red = plr->rgb->r;
1293  packet->color_green = plr->rgb->g;
1294  packet->color_blue = plr->rgb->b;
1295  } else {
1296  /* In pregame, send the color we expect to use, for consistency with
1297  * '/list colors' etc. */
1298  const struct rgbcolor *preferred = player_preferred_color(plr);
1299  if (preferred != nullptr) {
1300  packet->color_valid = true;
1301  packet->color_red = preferred->r;
1302  packet->color_green = preferred->g;
1303  packet->color_blue = preferred->b;
1304  } else {
1305  fc_assert(game.info.turn < 1);
1306  packet->color_valid = false;
1307  // Client shouldn't use these dummy values
1308  packet->color_red = 0;
1309  packet->color_green = 0;
1310  packet->color_blue = 0;
1311  }
1312  }
1313  packet->color_changeable = player_color_changeable(plr, nullptr);
1314 
1315  // Only send score if we have contact
1316  if (BV_ISSET(packet->visible, NI_SCORE)) {
1317  packet->score = plr->score.game;
1318  } else {
1319  packet->score = 0;
1320  }
1321 
1322  if (BV_ISSET(packet->visible, NI_GOLD)) {
1323  packet->gold = plr->economic.gold;
1324  } else {
1325  packet->gold = 0;
1326  }
1327 
1328  {
1329  const government *pgov, *ptargetgov;
1330  if (BV_ISSET(packet->visible, NI_GOVERNMENT)) {
1331  pgov = government_of_player(plr);
1332  ptargetgov = plr->target_government;
1333  packet->revolution_finishes = plr->revolution_finishes;
1334  } else {
1336  ptargetgov = pgov;
1337  packet->revolution_finishes = -1;
1338  }
1339  packet->government = pgov ? government_number(pgov) : government_count();
1340  packet->target_government =
1341  ptargetgov ? government_number(ptargetgov) : government_count();
1342  }
1343 
1344  /* Send diplomatic status of the player to everyone they are in
1345  * contact with. */
1346  if (BV_ISSET(packet->visible, NI_DIPLOMACY)) {
1347  memset(&packet->real_embassy, 0, sizeof(packet->real_embassy));
1348  players_iterate(pother)
1349  {
1350  packet->real_embassy[player_index(pother)] =
1351  player_has_real_embassy(plr, pother);
1352  }
1354  packet->gives_shared_vision = plr->gives_shared_vision;
1355  } else {
1356  memset(&packet->real_embassy, 0, sizeof(packet->real_embassy));
1357  if (receiver && player_has_real_embassy(plr, receiver)) {
1358  packet->real_embassy[player_index(receiver)] = true;
1359  }
1360 
1361  BV_CLR_ALL(packet->gives_shared_vision);
1362  }
1363  if (receiver && gives_shared_vision(plr, receiver)) {
1364  BV_SET(packet->gives_shared_vision, player_index(receiver));
1365  }
1366 
1367  if (BV_ISSET(packet->visible, NI_TECHS)) {
1368  packet->tech_upkeep = player_tech_upkeep(plr);
1369  } else {
1370  packet->tech_upkeep = 0;
1371  }
1372 
1373  /* Send most civ info about the player only to players who have an
1374  * embassy. */
1375  if (BV_ISSET(packet->visible, NI_TAX_RATES)) {
1376  packet->tax = plr->economic.tax;
1377  packet->science = plr->economic.science;
1378  packet->luxury = plr->economic.luxury;
1379  } else {
1380  packet->tax = 0;
1381  packet->science = 0;
1382  packet->luxury = 0;
1383  }
1384 
1385  if (BV_ISSET(packet->visible, NI_CULTURE)) {
1386  packet->culture = player_culture(plr);
1387  } else {
1388  packet->culture = 0;
1389  }
1390 
1391  if (BV_ISSET(packet->visible, NI_MOOD)) {
1392  packet->mood = player_mood(plr);
1393  } else {
1394  packet->mood = MOOD_COUNT;
1395  }
1396 
1397  if (BV_ISSET(packet->visible, NI_HISTORY)) {
1398  packet->history = plr->history;
1399  } else {
1400  packet->history = 0;
1401  }
1402 }
1403 
1413 static void
1414 package_player_diplstate(struct player *plr1, struct player *plr2,
1415  struct packet_player_diplstate *packet_ds,
1416  struct player *receiver, bool full)
1417 {
1418  bool send_info = false;
1419 
1420  if (server_state() < S_S_RUNNING || (!full && !receiver)) {
1421  send_info = false;
1422  } else if (full || players_on_same_team(plr1, receiver)
1423  || players_on_same_team(plr2, receiver)) {
1424  send_info = true;
1425  } else {
1426  // Teamed players always share their information -- it's in their best
1427  // interest to communicate anyway.
1428  player_list_iterate(team_members(receiver->team), team_mate)
1429  {
1430  if (get_player_intel_bonus(team_mate, plr1, NI_DIPLOMACY,
1431  EFT_NATION_INTELLIGENCE)
1432  > 0
1433  || get_player_intel_bonus(team_mate, plr2, NI_DIPLOMACY,
1434  EFT_NATION_INTELLIGENCE)
1435  > 0) {
1436  send_info = true;
1437  break;
1438  }
1439  }
1441  }
1442 
1443  packet_ds->plr1 = player_index(plr1);
1444  packet_ds->plr2 = player_index(plr2);
1445  // A unique id for each combination is calculated here.
1446  packet_ds->diplstate_id =
1447  packet_ds->plr1 * MAX_NUM_PLAYER_SLOTS + packet_ds->plr2;
1448 
1449  /* Send diplomatic status of the player to everyone they are in
1450  * contact with (embassy, remaining contact turns, the receiver). */
1451  if (send_info) {
1452  const auto *ds = player_diplstate_get(plr1, plr2);
1453  packet_ds->type = ds->type;
1454  packet_ds->turns_left = ds->turns_left;
1455  packet_ds->has_reason_to_cancel = ds->has_reason_to_cancel;
1456  packet_ds->contact_turns_left = ds->contact_turns_left;
1457  } else {
1458  packet_ds->type = DS_WAR;
1459  packet_ds->turns_left = 0;
1460  packet_ds->has_reason_to_cancel = 0;
1461  packet_ds->contact_turns_left = 0;
1462  }
1463 }
1464 
1469 struct conn_list *player_reply_dest(struct player *pplayer)
1470 {
1471  return (pplayer->current_conn ? pplayer->current_conn->self
1472  : pplayer->connections);
1473 }
1474 
1478 static void call_first_contact(struct player *pplayer,
1479  struct player *aplayer)
1480 {
1481  CALL_PLR_AI_FUNC(first_contact, pplayer, pplayer, aplayer);
1482 }
1483 
1494 void server_player_init(struct player *pplayer, bool initmap,
1495  bool needs_team)
1496 {
1497  player_status_reset(pplayer);
1498 
1499  pplayer->server.got_first_city = false;
1500  BV_CLR_ALL(pplayer->server.really_gives_vision);
1501  BV_CLR_ALL(pplayer->server.debug);
1502 
1503  pplayer->server.border_vision = false;
1504 
1505  player_map_free(pplayer);
1506  pplayer->server.private_map = nullptr;
1507 
1508  if (initmap) {
1509  player_map_init(pplayer);
1510  }
1511  if (needs_team) {
1512  team_add_player(pplayer, nullptr);
1513  }
1514 
1515  /* This must be done after team information is initialised
1516  * as it might be needed to determine max rate effects.
1517  * Sometimes this server_player_init() gets called twice
1518  * with only latter one having needs_team set. We don't
1519  * want to call player_limit_to_max_rates() at first time
1520  * when team is not yet set. It's callers responsibility
1521  * to always have one server_player_init() call with
1522  * needs_team TRUE. */
1523  if (needs_team) {
1524  pplayer->economic = player_limit_to_max_rates(pplayer);
1525  }
1526 
1527  adv_data_default(pplayer);
1528 
1529  /* We don't push this in calc_civ_score(), or it will be reset
1530  * every turn. */
1531  pplayer->score.units_built = 0;
1532  pplayer->score.units_killed = 0;
1533  pplayer->score.units_lost = 0;
1534 
1535  // No delegation.
1536  pplayer->server.delegate_to[0] = '\0';
1537  pplayer->server.orig_username[0] = '\0';
1538 
1539  handicaps_init(pplayer);
1540 }
1541 
1547 const struct rgbcolor *player_preferred_color(struct player *pplayer)
1548 {
1549  if (pplayer->rgb) {
1550  return pplayer->rgb;
1551  } else if (playercolor_count() == 0) {
1552  // If a ruleset isn't loaded, there are no colors to choose from.
1553  return nullptr;
1554  } else if (game.server.plrcolormode == PLRCOL_NATION_ORDER) {
1555  if (pplayer->nation != NO_NATION_SELECTED) {
1556  return nation_color(nation_of_player(pplayer)); // may be nullptr
1557  } else {
1558  return nullptr; // don't know nation, hence don't know color
1559  }
1560  } else {
1561  // Modes indexing into game-defined player colors
1562  int colorid;
1563 
1564  switch (game.server.plrcolormode) {
1565  case PLRCOL_PLR_SET: // player color (set)
1566  case PLRCOL_PLR_RANDOM: // player color (random)
1567  // These depend on other players and will be assigned at game start.
1568  return nullptr;
1569  default:
1570  qCritical("Invalid value for 'game.server.plrcolormode' (%d)!",
1571  game.server.plrcolormode);
1572  fc__fallthrough; // no break - using 'PLRCOL_PLR_ORDER' as fallback
1573  case PLRCOL_PLR_ORDER: // player color (ordered)
1574  colorid = player_number(pplayer) % playercolor_count();
1575  break;
1576  case PLRCOL_TEAM_ORDER: // team color (ordered)
1577  colorid = team_number(pplayer->team) % playercolor_count();
1578  break;
1579  }
1580 
1581  return playercolor_get(colorid);
1582  }
1583 }
1584 
1590 bool player_color_changeable(const struct player *pplayer,
1591  const char **reason)
1592 {
1593  if (!game_was_started() && game.server.plrcolormode != PLRCOL_PLR_SET) {
1594  if (reason) {
1595  *reason = _("Can only set player color prior to game start if "
1596  "'plrcolormode' is PLR_SET.");
1597  }
1598  return false;
1599  }
1600  return true;
1601 }
1602 
1609 {
1610  struct rgbcolor_list *spare_colors =
1611  rgbcolor_list_copy(game.server.plr_colors);
1612  int needed = player_count();
1613 
1614  players_iterate(pplayer)
1615  {
1616  const struct rgbcolor *autocolor;
1617  // Assign the deterministic colors.
1618  if (!pplayer->rgb && (autocolor = player_preferred_color(pplayer))) {
1619  player_set_color(pplayer, autocolor);
1620  }
1621  if (pplayer->rgb) {
1622  // One fewer random color needed.
1623  needed--;
1624  // Try to avoid clashes between explicit and random colors.
1625  rgbcolor_list_iterate(spare_colors, prgbcolor)
1626  {
1627  if (rgbcolors_are_equal(pplayer->rgb, prgbcolor)) {
1628  rgbcolor_list_remove(spare_colors, prgbcolor);
1629  }
1630  }
1632  }
1633  }
1635 
1636  if (needed == 0) {
1637  // No random colors needed
1638  rgbcolor_list_destroy(spare_colors);
1639  return;
1640  }
1641 
1642  if (game.server.plrcolormode == PLRCOL_NATION_ORDER) {
1643  /* Additionally, try to avoid color clashes with certain nations not
1644  * yet in play (barbarians). */
1645  for (const auto &pnation : nations) {
1646  if (nation_is_in_current_set(&pnation)) {
1647  const struct rgbcolor *ncol = nation_color(&pnation);
1648  if (ncol && nation_barbarian_type(&pnation) != NOT_A_BARBARIAN) {
1649  // Don't use this color.
1650  rgbcolor_list_iterate(spare_colors, prgbcolor)
1651  {
1652  if (rgbcolors_are_equal(ncol, prgbcolor)) {
1653  rgbcolor_list_remove(spare_colors, ncol);
1654  }
1655  }
1657  }
1658  }
1659  }
1660  }
1661 
1662  fc_assert(game.server.plrcolormode == PLRCOL_PLR_RANDOM
1663  || game.server.plrcolormode == PLRCOL_PLR_SET
1664  || game.server.plrcolormode == PLRCOL_NATION_ORDER);
1665 
1666  if (needed > rgbcolor_list_size(spare_colors)) {
1667  qDebug("Not enough unique colors for all players; there will be "
1668  "duplicates");
1669  /* Fallback: start again from full set of ruleset colors.
1670  * No longer attempt to avoid clashes with explicitly assigned colors. */
1671  rgbcolor_list_destroy(spare_colors);
1672  spare_colors = rgbcolor_list_copy(game.server.plr_colors);
1673  }
1674  /* We may still not have enough, if there are more players than
1675  * ruleset-defined colors. If so, top up with duplicates. */
1676  if (needed > rgbcolor_list_size(spare_colors)) {
1677  int i, origsize = rgbcolor_list_size(spare_colors);
1678  // Shuffle so that duplicates aren't biased to start of list
1679  rgbcolor_list_shuffle(spare_colors);
1680  // Duplication process avoids one color being hit lots of times
1681  for (i = origsize; i < needed; i++) {
1682  rgbcolor_list_append(spare_colors,
1683  rgbcolor_list_get(spare_colors, i - origsize));
1684  }
1685  }
1686  // Shuffle (including mixing any duplicates up)
1687  rgbcolor_list_shuffle(spare_colors);
1688 
1689  // Finally, assign shuffled colors to players.
1690  players_iterate(pplayer)
1691  {
1692  if (!pplayer->rgb) {
1693  player_set_color(pplayer, rgbcolor_list_front(spare_colors));
1694  rgbcolor_list_pop_front(spare_colors);
1695  }
1696  }
1698 
1699  rgbcolor_list_destroy(spare_colors);
1700 }
1701 
1706 void server_player_set_color(struct player *pplayer,
1707  const struct rgbcolor *prgbcolor)
1708 {
1709  if (prgbcolor != nullptr) {
1710  player_set_color(pplayer, prgbcolor);
1711  } else {
1712  // This can legitimately be nullptr in pregame.
1714  rgbcolor_destroy(pplayer->rgb);
1715  pplayer->rgb = nullptr;
1716  }
1717  // Update clients
1718  send_player_info_c(pplayer, nullptr);
1719 }
1720 
1726 const char *player_color_ftstr(struct player *pplayer)
1727 {
1728  static char buf[64];
1729  char hex[16];
1730  const struct rgbcolor *prgbcolor;
1731 
1732  fc_assert_ret_val(pplayer != nullptr, nullptr);
1733 
1734  buf[0] = '\0';
1735  prgbcolor = player_preferred_color(pplayer);
1736  if (prgbcolor != nullptr && rgbcolor_to_hex(prgbcolor, hex, sizeof(hex))) {
1737  struct ft_color plrcolor = FT_COLOR("#000000", hex);
1738 
1739  featured_text_apply_tag(hex, buf, sizeof(buf), TTT_COLOR, 0,
1740  FT_OFFSET_UNSET, plrcolor);
1741  } else {
1742  cat_snprintf(buf, sizeof(buf), _("no color"));
1743  }
1744 
1745  return buf;
1746 }
1747 
1752 void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
1753 {
1754  int sucount = qstrlen(game.server.start_units);
1755  int i;
1756 
1757  for (i = 0; i < sucount; i++) {
1758  if (game.server.start_units[i] == 'k') {
1759  // Every player should have king
1760  struct unit_type *utype = crole_to_unit_type('k', pplayer);
1761 
1762  if (utype != nullptr) {
1763  create_unit(pplayer, ptile, utype, 0, 0, -1);
1764  }
1765  }
1766  }
1767 }
1768 
1776 struct player *server_create_player(int player_id, const char *ai_tname,
1777  struct rgbcolor *prgbcolor,
1778  bool allow_ai_type_fallbacking)
1779 {
1780  struct player_slot *pslot;
1781  struct player *pplayer;
1782 
1783  pslot = player_slot_by_number(player_id);
1784  fc_assert(nullptr == pslot || !player_slot_is_used(pslot));
1785 
1786  pplayer = player_new(pslot);
1787  if (nullptr == pplayer) {
1788  return nullptr;
1789  }
1790 
1791  if (allow_ai_type_fallbacking) {
1792  pplayer->savegame_ai_type_name = fc_strdup(ai_tname);
1793  ai_tname = ai_type_name_or_fallback(ai_tname);
1794  }
1795 
1796  pplayer->ai = ai_type_by_name(ai_tname);
1797 
1798  if (pplayer->ai == nullptr) {
1799  player_destroy(pplayer);
1800  return nullptr;
1801  }
1802 
1803  adv_data_init(pplayer);
1804 
1805  CALL_FUNC_EACH_AI(player_alloc, pplayer);
1806 
1807  /* TODO: Do we really need this server_player_init() here? All our callers
1808  * will later make another server_player_init() call anyway, with
1809  * boolean parameters set to what they really need. */
1810  server_player_init(pplayer, false, false);
1811 
1812  if (prgbcolor) {
1813  player_set_color(pplayer, prgbcolor);
1814  } // else caller must ensure a color is assigned if game has started
1815 
1816  return pplayer;
1817 }
1818 
1825 void server_remove_player(struct player *pplayer)
1826 {
1827  const struct player_slot *pslot;
1828 
1829  fc_assert_ret(nullptr != pplayer);
1830 
1831  // save player slot
1832  pslot = pplayer->slot;
1833 
1834  qInfo(_("Removing player %s."), player_name(pplayer));
1835 
1836  notify_conn(pplayer->connections, nullptr, E_CONNECTION, ftc_server,
1837  _("You've been removed from the game!"));
1838 
1839  notify_conn(game.est_connections, nullptr, E_CONNECTION, ftc_server,
1840  _("%s has been removed from the game."), player_name(pplayer));
1841 
1842  if (is_barbarian(pplayer)) {
1843  server.nbarbarians--;
1844  }
1845 
1846  /* Don't use conn_list_iterate here because connection_detach() can be
1847  * recursive and free the next connection pointer. */
1848  while (conn_list_size(pplayer->connections) > 0) {
1849  connection_detach(conn_list_get(pplayer->connections, 0), false);
1850  }
1851 
1853  // Clear data saved in the other player structs.
1854  players_iterate(aplayer)
1855  {
1856  BV_CLR(aplayer->real_embassy, player_index(pplayer));
1857  if (gives_shared_vision(aplayer, pplayer)) {
1858  remove_shared_vision(aplayer, pplayer);
1859  }
1860  }
1862 
1863  // Remove citizens of this player from the cities of all other players.
1864  /* FIXME: add a special case if the server quits - no need to run this for
1865  * each player in that case. */
1866  if (game.info.citizen_nationality) {
1867  cities_iterate(pcity)
1868  {
1869  if (city_owner(pcity) != pplayer) {
1870  citizens nationality = citizens_nation_get(pcity, pplayer->slot);
1871 
1872  if (nationality != 0) {
1873  /* Change nationality of the citizens to the nationality of the
1874  * city owner. */
1875  citizens_nation_move(pcity, pplayer->slot, city_owner(pcity)->slot,
1876  nationality);
1877  city_refresh_queue_add(pcity);
1878  }
1879  }
1880  }
1882 
1884  }
1885 
1886  // AI type lost control of this player
1887  CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
1888 
1889  /* Clear all trade routes. This is needed for the other end not
1890  * to point to a city removed by player_clear() */
1891  city_list_iterate(pplayer->cities, pcity)
1892  {
1893  trade_routes_iterate_safe(pcity, proute)
1894  {
1895  struct trade_route *pback =
1896  remove_trade_route(pcity, proute, true, true);
1897 
1898  delete proute;
1899  delete pback;
1900  proute = nullptr;
1901  pback = nullptr;
1902  }
1904  }
1906 
1907  /* We have to clear all player data before the ai memory is freed because
1908  * some function may depend on it. */
1909  player_clear(pplayer, true);
1910 
1911  if (!map_is_empty()) {
1912  remove_player_from_maps(pplayer);
1913  }
1914  player_map_free(pplayer);
1915 
1916  // Destroy advisor and ai data.
1917  CALL_FUNC_EACH_AI(player_free, pplayer);
1918 
1919  handicaps_close(pplayer);
1920  ai_traits_close(pplayer);
1921  adv_data_close(pplayer);
1922  player_destroy(pplayer);
1923 
1924  send_updated_vote_totals(nullptr);
1925  // must be called after the player was destroyed
1926  send_player_remove_info_c(pslot, nullptr);
1927 
1928  // Recalculate borders.
1930 }
1931 
1942 struct player_economic player_limit_to_max_rates(struct player *pplayer)
1943 {
1944  int maxrate, surplus;
1945  struct player_economic economic;
1946 
1947  // ai players allowed to cheat
1948  if (is_ai(pplayer)) {
1949  return pplayer->economic;
1950  }
1951 
1952  economic = pplayer->economic;
1953 
1954  maxrate = get_player_maxrate(pplayer);
1955 
1956  surplus = 0;
1957  if (economic.luxury > maxrate) {
1958  surplus += economic.luxury - maxrate;
1959  economic.luxury = maxrate;
1960  }
1961  if (economic.tax > maxrate) {
1962  surplus += economic.tax - maxrate;
1963  economic.tax = maxrate;
1964  }
1965  if (economic.science > maxrate) {
1966  surplus += economic.science - maxrate;
1967  economic.science = maxrate;
1968  }
1969 
1970  fc_assert(surplus % 10 == 0);
1971  while (surplus > 0) {
1972  if (economic.science < maxrate) {
1973  economic.science += 10;
1974  } else if (economic.tax < maxrate) {
1975  economic.tax += 10;
1976  } else if (economic.luxury < maxrate) {
1977  economic.luxury += 10;
1978  } else {
1979  fc_assert_msg(false,
1980  "Failed to distribute the surplus. "
1981  "maxrate = %d.",
1982  maxrate);
1983  }
1984  surplus -= 10;
1985  }
1986 
1987  return economic;
1988 }
1989 
1994 static bool server_player_name_is_allowed(const struct connection *caller,
1995  const struct player *pplayer,
1996  const struct nation_type *pnation,
1997  const char *name, char *error_buf,
1998  size_t error_buf_len)
1999 {
2000  // An empty name is surely not allowed.
2001  if (0 == qstrlen(name)) {
2002  fc_strlcpy(error_buf, _("Please choose a non-blank name."),
2003  error_buf_len);
2004  return false;
2005  }
2006 
2007  // Any name already taken is not allowed.
2008  players_iterate(other_player)
2009  {
2010  if (other_player == pplayer) {
2011  /* We don't care if we're the one using the name/nation. */
2012  continue;
2013  } else if (nullptr != pnation && other_player->nation == pnation) {
2014  /* FIXME: currently cannot use nation_of_player(other_player) as the
2015  * nation debug code is buggy and doesn't test nation for nullptr. */
2016  fc_strlcpy(error_buf, _("That nation is already in use."),
2017  error_buf_len);
2018  return false;
2019  } else if (0 == fc_strcasecmp(player_name(other_player), name)) {
2020  fc_snprintf(error_buf, error_buf_len,
2021  _("Another player already has the name '%s'. Please "
2022  "choose another name."),
2023  name);
2024  return false;
2025  }
2026  }
2028 
2029  if (nullptr == pnation) {
2030  /* FIXME: currently cannot use nation_of_player(other_player) as the
2031  * nation debug code is buggy and doesn't test nation for nullptr. */
2032  pnation = pplayer->nation;
2033  }
2034 
2035  // Any name from the default list is always allowed.
2036  if (nullptr != pnation
2037  && nullptr != nation_leader_by_name(pnation, name)) {
2038  return true;
2039  }
2040 
2041  /* To prevent abuse, only players with HACK access (usually local
2042  * connections) can use non-ascii names. Otherwise players could use
2043  * confusing garbage names in multi-player games. */
2044  if (nullptr != caller && caller->access_level < ALLOW_HACK
2045  && !is_ascii_name(name)) {
2046  fc_strlcpy(error_buf,
2047  _("Please choose a name containing only ASCII characters."),
2048  error_buf_len);
2049  return false;
2050  }
2051 
2052  return true;
2053 }
2054 
2059 bool server_player_set_name_full(const struct connection *caller,
2060  struct player *pplayer,
2061  const struct nation_type *pnation,
2062  const char *name, char *error_buf,
2063  size_t error_buf_len)
2064 {
2065  char real_name[MAX_LEN_NAME];
2066  char buf[256];
2067  int i;
2068 
2069  // Always provide an error buffer.
2070  if (nullptr == error_buf) {
2071  error_buf = buf;
2072  error_buf_len = sizeof(buf);
2073  }
2074  error_buf[0] = '\0';
2075 
2076  if (nullptr != name) {
2077  // Ensure this is a correct name.
2078  sz_strlcpy(real_name, name);
2079  remove_leading_trailing_spaces(real_name);
2080  real_name[0] = QChar::toUpper(real_name[0]);
2081 
2082  if (server_player_name_is_allowed(caller, pplayer, pnation, real_name,
2083  error_buf, error_buf_len)) {
2084  log_debug("Name of player nb %d set to \"%s\".",
2085  player_number(pplayer), real_name);
2086  fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2087  return true; // Success!
2088  } else {
2089  qDebug("Failed to set the name of the player nb %d to \"%s\": %s",
2090  player_number(pplayer), real_name, error_buf);
2091  // Fallthrough.
2092  }
2093  }
2094 
2095  if (nullptr != caller) {
2096  // If we want to test, let's fail here.
2097  fc_assert(nullptr != name);
2098  return false;
2099  }
2100 
2101  if (nullptr != name) {
2102  // Try to append a number to 'real_name'.
2103  char test[MAX_LEN_NAME];
2104 
2105  for (i = 2; i <= MAX_NUM_PLAYER_SLOTS; i++) {
2106  fc_snprintf(test, sizeof(test), "%s%d", real_name, i);
2107  if (server_player_name_is_allowed(caller, pplayer, pnation, test,
2108  error_buf, error_buf_len)) {
2109  qDebug("Name of player nb %d set to \"%s\" instead.",
2110  player_number(pplayer), test);
2111  fc_strlcpy(pplayer->name, test, sizeof(pplayer->name));
2112  return true;
2113  } else {
2114  log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2115  player_number(pplayer), test, error_buf);
2116  }
2117  }
2118  }
2119 
2120  // Try a default name.
2121  fc_snprintf(real_name, sizeof(real_name), _("Player no. %d"),
2122  player_number(pplayer));
2123  if (server_player_name_is_allowed(caller, pplayer, pnation, real_name,
2124  error_buf, error_buf_len)) {
2125  qDebug("Name of player nb %d set to \"%s\".", player_number(pplayer),
2126  real_name);
2127  fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2128  return true;
2129  } else {
2130  log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2131  player_number(pplayer), real_name, error_buf);
2132  }
2133 
2134  // Try a very default name...
2135  for (i = 0; i < MAX_NUM_PLAYER_SLOTS; i++) {
2136  fc_snprintf(real_name, sizeof(real_name), _("Player no. %d"), i);
2137  if (server_player_name_is_allowed(caller, pplayer, pnation, real_name,
2138  error_buf, error_buf_len)) {
2139  qDebug("Name of player nb %d to \"%s\".", player_number(pplayer),
2140  real_name);
2141  fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2142  return true;
2143  } else {
2144  log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2145  player_number(pplayer), real_name, error_buf);
2146  }
2147  }
2148 
2149  /* This is really not normal... Maybe the size of 'real_name'
2150  * is not enough big, or a bug in server_player_name_is_allowed(). */
2151  fc_strlcpy(pplayer->name, _("A poorly-named player"),
2152  sizeof(pplayer->name));
2153  return false; // Let's say it's a failure.
2154 }
2155 
2159 void server_player_set_name(struct player *pplayer, const char *name)
2160 {
2161  bool ret;
2162 
2163  ret = server_player_set_name_full(nullptr, pplayer, nullptr, name, nullptr,
2164  0);
2165  fc_assert(true == ret);
2166 }
2167 
2175 static enum diplstate_type
2176 get_default_diplstate(const struct player *pplayer1,
2177  const struct player *pplayer2)
2178 {
2179  if (game.server.initial_diplomatic_state < DS_ALLIANCE) {
2180  players_iterate_alive(pplayer3)
2181  {
2182  if (pplayer3 != pplayer1 && pplayer3 != pplayer2
2183  && pplayers_allied(pplayer3, pplayer1)
2184  && pplayers_allied(pplayer3, pplayer2)) {
2185  return DS_PEACE;
2186  }
2187  }
2189  }
2190 
2191  return game.server.initial_diplomatic_state;
2192 }
2193 
2197 void make_contact(struct player *pplayer1, struct player *pplayer2,
2198  struct tile *ptile)
2199 {
2200  struct player_diplstate *ds_plr1plr2, *ds_plr2plr1;
2201 
2202  if (pplayer1 == pplayer2 || !pplayer1->is_alive || !pplayer2->is_alive) {
2203  return;
2204  }
2205 
2206  ds_plr1plr2 = player_diplstate_get(pplayer1, pplayer2);
2207  ds_plr2plr1 = player_diplstate_get(pplayer2, pplayer1);
2208 
2209  if (get_player_bonus(pplayer1, EFT_NO_DIPLOMACY) <= 0
2210  && get_player_bonus(pplayer2, EFT_NO_DIPLOMACY) <= 0) {
2211  ds_plr1plr2->contact_turns_left = game.server.contactturns;
2212  ds_plr2plr1->contact_turns_left = game.server.contactturns;
2213  }
2214  if (ds_plr1plr2->type == DS_NO_CONTACT) {
2215  enum diplstate_type new_state =
2216  get_default_diplstate(pplayer1, pplayer2);
2217  if (new_state == DS_CEASEFIRE || new_state == DS_ARMISTICE) {
2218  ds_plr1plr2->turns_left = TURNS_LEFT;
2219  ds_plr2plr1->turns_left = TURNS_LEFT;
2220  }
2221 
2222  ds_plr1plr2->type = new_state;
2223  ds_plr2plr1->type = new_state;
2224 
2225  ds_plr1plr2->first_contact_turn = game.info.turn;
2226  ds_plr2plr1->first_contact_turn = game.info.turn;
2227  notify_player(pplayer1, ptile, E_FIRST_CONTACT, ftc_server,
2228  _("You have made contact with the %s, ruled by %s."),
2229  nation_plural_for_player(pplayer2), player_name(pplayer2));
2230  notify_player(pplayer2, ptile, E_FIRST_CONTACT, ftc_server,
2231  _("You have made contact with the %s, ruled by %s."),
2232  nation_plural_for_player(pplayer1), player_name(pplayer1));
2233  if (new_state == DS_ARMISTICE) {
2234  fc_assert(ds_plr1plr2->turns_left == ds_plr2plr1->turns_left);
2235  /* Non-default relation after contact, so send a message
2236  * Could just modify to send message in any case. */
2237  /* TRANS: ... the Poles ... Polish territory */
2238  const char *msg =
2239  PL_("You are in armistice with the %s. In %d turn, "
2240  "it will become a peace treaty. Move your "
2241  "military units out of %s territory to avoid them "
2242  "being disbanded.",
2243  "You are in armistice with the %s. In %d turns, "
2244  "it will become a peace treaty. Move any "
2245  "military units out of %s territory to avoid them "
2246  "being disbanded.",
2247  ds_plr1plr2->turns_left);
2248  notify_player(pplayer1, NULL, E_TREATY_PEACE, ftc_server, msg,
2249  nation_plural_for_player(pplayer2),
2250  ds_plr1plr2->turns_left,
2251  nation_adjective_for_player(pplayer2));
2252  notify_player(pplayer2, NULL, E_TREATY_PEACE, ftc_server, msg,
2253  nation_plural_for_player(pplayer1),
2254  ds_plr1plr2->turns_left,
2255  nation_adjective_for_player(pplayer1));
2256  }
2257  send_player_all_c(pplayer1, pplayer2->connections);
2258  send_player_all_c(pplayer2, pplayer1->connections);
2259  send_player_all_c(pplayer1, pplayer1->connections);
2260  send_player_all_c(pplayer2, pplayer2->connections);
2261  if (is_ai(pplayer1)) {
2262  call_first_contact(pplayer1, pplayer2);
2263  }
2264  if (is_ai(pplayer2)) {
2265  call_first_contact(pplayer2, pplayer1);
2266  }
2267  return;
2268  } else {
2269  fc_assert(ds_plr2plr1->type != DS_NO_CONTACT);
2270  }
2271  if (player_has_embassy(pplayer1, pplayer2)
2272  || player_has_embassy(pplayer2, pplayer1)) {
2273  return; // Avoid sending too much info over the network
2274  }
2275  send_player_all_c(pplayer1, pplayer1->connections);
2276  send_player_all_c(pplayer2, pplayer2->connections);
2277 }
2278 
2282 void maybe_make_contact(struct tile *ptile, struct player *pplayer)
2283 {
2284  square_iterate(&(wld.map), ptile, 1, tile1)
2285  {
2286  struct city *pcity = tile_city(tile1);
2287  if (pcity) {
2288  make_contact(pplayer, city_owner(pcity), ptile);
2289  }
2290  unit_list_iterate_safe(tile1->units, punit)
2291  {
2292  make_contact(pplayer, unit_owner(punit), ptile);
2293  }
2295  }
2297 }
2298 
2303 {
2304  // shuffled_order is defined global
2305  int n = MAX_NUM_PLAYER_SLOTS;
2306  int i;
2307 
2308  log_debug("shuffle_players: creating shuffled order");
2309 
2310  for (i = 0; i < n; i++) {
2311  shuffled_order[i] = i;
2312  }
2313 
2314  // randomize it
2316 
2317 #ifdef FREECIV_DEBUG
2318  for (i = 0; i < n; i++) {
2319  log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2320  }
2321 #endif // FREECIV_DEBUG
2322 }
2323 
2327 void set_shuffled_players(int *shuffled_players)
2328 {
2329  int i;
2330 
2331  log_debug("set_shuffled_players: loading shuffled array %p",
2332  shuffled_players);
2333 
2334  for (i = 0; i < MAX_NUM_PLAYER_SLOTS; i++) {
2335  shuffled_order[i] = shuffled_players[i];
2336  log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2337  }
2338 }
2339 
2345 struct player *shuffled_player(int i)
2346 {
2347  struct player *pplayer;
2348 
2349  pplayer = player_by_number(shuffled_order[i]);
2350  log_debug("shuffled_player(%d) = %d (%s)", i, shuffled_order[i],
2351  player_name(pplayer));
2352  return pplayer;
2353 }
2354 
2377 struct nation_type *pick_a_nation(const struct nation_list *choices,
2378  bool ignore_conflicts, bool needs_startpos,
2379  enum barbarian_type barb_type)
2380 {
2381  enum {
2382  UNAVAILABLE,
2383  AVAILABLE,
2384  PREFERRED,
2385  UNWANTED
2386  } nations_used[game.control.nation_count],
2387  looking_for;
2388  int match[game.control.nation_count], pick, idx;
2389  int num_avail_nations = 0, num_pref_nations = 0;
2390 
2391  /* Values of nations_used:
2392  * UNAVAILABLE - nation is already used or is a special nation.
2393  * AVAILABLE - we can use this nation.
2394  * PREFERRED - we can use this nation and it is on the choices list.
2395  * UNWANTED - we can use this nation, but we really don't want to. */
2396  for (auto &pnation : nations) {
2397  idx = nation_index(&pnation);
2398 
2399  if (!nation_is_in_current_set(&pnation) || pnation.player
2400  || (needs_startpos && game.scenario.startpos_nations
2401  && pnation.server.no_startpos)
2402  || (barb_type != nation_barbarian_type(&pnation))
2403  || (barb_type == NOT_A_BARBARIAN && !is_nation_playable(&pnation))) {
2404  /* Nation is unplayable or already used: don't consider it.
2405  * (If nations aren't currently restricted to those with start
2406  * positions, we do nothing special here, but generate_players() will
2407  * tend to prefer them.) */
2408  nations_used[idx] = UNAVAILABLE;
2409  match[idx] = 0;
2410  continue;
2411  }
2412 
2413  nations_used[idx] = AVAILABLE;
2414 
2415  /* Determine which nations look good with nations already in the game,
2416  * or conflict with them. */
2417  match[idx] = 1;
2418  players_iterate(pplayer)
2419  {
2420  if (pplayer->nation != NO_NATION_SELECTED) {
2421  int x = nations_match(&pnation, nation_of_player(pplayer),
2422  ignore_conflicts);
2423  if (x < 0) {
2424  log_debug("Nations '%s' (nb %d) and '%s' (nb %d) are in conflict.",
2425  nation_rule_name(&pnation), nation_index(&pnation),
2427  nation_index(nation_of_player(pplayer)));
2428  nations_used[idx] = UNWANTED;
2429  match[idx] -= x * 100;
2430  break;
2431  } else {
2432  match[idx] += x * 100;
2433  }
2434  }
2435  }
2437 
2438  if (AVAILABLE == nations_used[idx]) {
2439  num_avail_nations += match[idx];
2440  }
2441  }
2442 
2443  /* Mark as preferred those nations which are on the choices list and
2444  * which are AVAILABLE, but no UNWANTED */
2445  if (nullptr != choices) {
2446  nation_list_iterate(choices, pnation)
2447  {
2448  idx = nation_index(pnation);
2449  if (nations_used[idx] == AVAILABLE) {
2450  num_pref_nations += match[idx];
2451  nations_used[idx] = PREFERRED;
2452  }
2453  }
2455  }
2456 
2457  if (0 < num_pref_nations || 0 < num_avail_nations) {
2458  if (0 < num_pref_nations) {
2459  // Use a preferred nation only.
2460  pick = fc_rand(num_pref_nations);
2461  looking_for = PREFERRED;
2462  log_debug("Picking a preferred nation.");
2463  } else {
2464  // Use any available nation.
2465  fc_assert(0 < num_avail_nations);
2466  pick = fc_rand(num_avail_nations);
2467  looking_for = AVAILABLE;
2468  log_debug("Picking an available nation.");
2469  }
2470 
2471  for (auto &pnation : nations) {
2472  idx = nation_index(&pnation);
2473  if (nations_used[idx] == looking_for) {
2474  pick -= match[idx];
2475 
2476  if (0 > pick) {
2477  return &pnation;
2478  }
2479  }
2480  }
2481  } else {
2482  // No available nation: use unwanted nation...
2483  struct nation_type *less_worst_nation = NO_NATION_SELECTED;
2484  int less_worst_score = -FC_INFINITY;
2485 
2486  log_debug("Picking an unwanted nation.");
2487  for (auto &pnation : nations) {
2488  idx = nation_index(&pnation);
2489  if (UNWANTED == nations_used[idx]) {
2490  pick = -fc_rand(match[idx]);
2491  if (pick > less_worst_score) {
2492  less_worst_nation = &pnation;
2493  less_worst_score = pick;
2494  }
2495  }
2496  }
2497 
2498  if (NO_NATION_SELECTED != less_worst_nation) {
2499  return less_worst_nation;
2500  }
2501  }
2502 
2503  qDebug("No nation found!");
2504 
2505  return NO_NATION_SELECTED;
2506 }
2507 
2512 {
2513  return nation_set_by_setting_value(game.server.nationset);
2514 }
2515 
2520 bool nation_is_in_current_set(const struct nation_type *pnation)
2521 {
2522  return nation_is_in_set(pnation, current_nationset());
2523 }
2524 
2530 {
2531  server.playable_nations = 0;
2532  for (const auto &pnation : nations) {
2533  if (nation_is_in_current_set(&pnation)) {
2534  if (is_nation_playable(&pnation)) {
2535  server.playable_nations++;
2536  }
2537  }
2538  }
2539 }
2540 
2546 bool client_can_pick_nation(const struct nation_type *pnation)
2547 {
2548  fc_assert_ret_val(pnation != nullptr, false);
2549  return nation_is_in_current_set(pnation) && is_nation_playable(pnation)
2550  && (!game.scenario.startpos_nations
2551  || !pnation->server.no_startpos);
2552 }
2553 
2557 static void send_nation_availability_real(struct conn_list *dest,
2558  bool nationset_change)
2559 {
2560  struct packet_nation_availability packet;
2561 
2562  packet.ncount = game.control.nation_count;
2563  packet.nationset_change = nationset_change;
2564  for (const auto &pnation : nations) {
2565  packet.is_pickable[nation_index(&pnation)] =
2566  client_can_pick_nation(&pnation);
2567  }
2568  lsend_packet_nation_availability(dest, &packet);
2569 }
2570 
2574 void send_nation_availability(struct conn_list *dest, bool nationset_change)
2575 {
2576  if (0 < player_info_frozen_level) {
2577  return; // Discard, see comment for player_info_freeze().
2578  } else {
2579  send_nation_availability_real(dest, nationset_change);
2580  }
2581 }
2582 
2589 {
2590  int misfits[nation_set_count()];
2591  nation_sets_iterate(pset)
2592  {
2593  misfits[nation_set_index(pset)] = 0;
2594  players_iterate(pplayer)
2595  {
2596  if (pplayer->nation != NO_NATION_SELECTED
2597  && !nation_is_in_set(pplayer->nation, pset)) {
2598  misfits[nation_set_index(pset)]++;
2599  }
2600  }
2602  }
2604 
2605  if (misfits[nation_set_index(current_nationset())] == 0) {
2606  // Current set is OK.
2607  return;
2608  }
2609 
2610  /* Otherwise, pick the least worst set (requires unsetting fewest
2611  * players, possibly none). */
2612  {
2613  // Quell compiler warning; but least_misfits initializer won't be used
2614  int i, least_misfits = -1;
2615  const struct nation_set *best = nullptr;
2616  fc_assert(nation_set_count() > 0);
2617  for (i = 0; i < nation_set_count(); i++) {
2618  if (best == nullptr || misfits[i] < least_misfits) {
2619  best = nation_set_by_number(i);
2620  least_misfits = misfits[i];
2621  if (least_misfits == 0) {
2622  // Not going to do any better.
2623  break;
2624  }
2625  }
2626  }
2627  fc_assert(least_misfits >= 0);
2628 
2629  qDebug("Current nationset \"%s\" doesn't fit all existing players.",
2631  qDebug("Selected nationset \"%s\".", nation_set_rule_name(best));
2632  fc_strlcpy(game.server.nationset, nation_set_rule_name(best),
2633  sizeof(game.server.nationset));
2635  /* No need to refresh clients, as we're assumed to be in the middle of
2636  * loading a savegame and will send new setting/availability later
2637  * along with everything else */
2638  }
2639 
2640  /* The set we chose may not fit all the players; as a last resort,
2641  * unset nations (caller must then arrange new assignments). */
2642  players_iterate(pplayer)
2643  {
2644  if (pplayer->nation != NO_NATION_SELECTED
2645  && !nation_is_in_current_set(pplayer->nation)) {
2646  qDebug("Nation %s of player %s not in nationset \"%s\", unsetting.",
2647  nation_plural_for_player(pplayer), player_name(pplayer),
2650  }
2651  }
2653 }
2654 
2658 void reset_all_start_commands(bool plrchange)
2659 {
2660  if (S_S_INITIAL != server_state()) {
2661  return;
2662  }
2663  players_iterate(pplayer)
2664  {
2665  if (pplayer->is_ready) {
2666  bool persistent = false;
2667 
2668  if (plrchange) {
2669  switch (game.info.persistent_ready) {
2670  case PERSISTENTR_DISABLED:
2671  persistent = false;
2672  break;
2673  case PERSISTENTR_CONNECTED:
2674  persistent = pplayer->is_connected;
2675  break;
2676  }
2677  }
2678 
2679  if (!persistent) {
2680  pplayer->is_ready = false;
2682  }
2683  }
2684  }
2686 }
2687 
2694 static struct player *split_player(struct player *pplayer)
2695 {
2696  struct research *new_research, *old_research;
2697  struct player *cplayer;
2698  struct nation_type *rebel_nation;
2699 
2700  // make a new player, or not
2701  cplayer = server_create_player(-1, ai_name(pplayer->ai), nullptr, false);
2702  if (!cplayer) {
2703  return nullptr;
2704  }
2705  server_player_init(cplayer, true, true);
2706 
2707  // Rebel will always be an AI player
2708  rebel_nation =
2709  pick_a_nation(nation_of_player(pplayer)->server.civilwar_nations, true,
2710  false, NOT_A_BARBARIAN);
2711  player_nation_defaults(cplayer, rebel_nation, true);
2712 
2714  // Find a color for the new player.
2716 
2717  // Send information about the used player slot to all connections.
2718  send_player_info_c(cplayer, nullptr);
2719 
2720  sz_strlcpy(cplayer->username, _(ANON_USER_NAME));
2721  cplayer->unassigned_user = true;
2722  cplayer->is_connected = false;
2724  fc_assert(cplayer->revolution_finishes < 0);
2725  // No capital for the splitted player.
2726  cplayer->server.got_first_city = false;
2727 
2728  players_iterate(other_player)
2729  {
2730  struct player_diplstate *ds_co =
2731  player_diplstate_get(cplayer, other_player);
2732  struct player_diplstate *ds_oc =
2733  player_diplstate_get(other_player, cplayer);
2734 
2735  if (get_player_bonus(other_player, EFT_NO_DIPLOMACY) > 0) {
2736  ds_co->type = DS_WAR;
2737  ds_oc->type = DS_WAR;
2738  } else {
2739  ds_co->type = DS_NO_CONTACT;
2740  ds_oc->type = DS_NO_CONTACT;
2741  }
2742 
2743  ds_co->has_reason_to_cancel = 0;
2744  ds_co->turns_left = 0;
2745  ds_co->contact_turns_left = 0;
2746  ds_oc->has_reason_to_cancel = 0;
2747  ds_oc->turns_left = 0;
2748  ds_oc->contact_turns_left = 0;
2749 
2750  /* Send so that other_player sees updated diplomatic info;
2751  * pplayer will be sent later anyway
2752  */
2753  if (other_player != pplayer) {
2754  send_player_all_c(other_player, other_player->connections);
2755  }
2756  }
2758 
2759  // Split the resources
2760  cplayer->economic.gold = pplayer->economic.gold;
2761  cplayer->economic.gold /= 2;
2762  pplayer->economic.gold -= cplayer->economic.gold;
2763 
2764  // Copy the research
2765  new_research = research_get(cplayer);
2766  old_research = research_get(pplayer);
2767 
2768  new_research->bulbs_researched = 0;
2769  new_research->techs_researched = old_research->techs_researched;
2770  new_research->researching = old_research->researching;
2771  new_research->tech_goal = old_research->tech_goal;
2772 
2774  {
2775  if (TECH_KNOWN == research_invention_state(old_research, i)) {
2776  research_invention_set(new_research, i, TECH_KNOWN);
2777  new_research->inventions[i].bulbs_researched_saved =
2778  old_research->inventions[i].bulbs_researched_saved;
2779  }
2780  }
2782  cplayer->phase_done = true; /* Have other things to think
2783  about - paralysis */
2784  BV_CLR_ALL(cplayer->real_embassy); // all embassies destroyed
2785  research_update(new_research);
2786 
2787  // Do the ai
2788  set_as_ai(cplayer);
2789  cplayer->ai_common.maxbuycost = pplayer->ai_common.maxbuycost;
2790  cplayer->ai_common.warmth = pplayer->ai_common.warmth;
2791  cplayer->ai_common.frost = pplayer->ai_common.frost;
2792  set_ai_level_direct(cplayer, ai_level(game.info.skill_level));
2793 
2794  // change the original player
2796  pplayer->target_government = pplayer->government;
2798  pplayer->revolution_finishes = game.info.turn + 1;
2799  }
2800  old_research->bulbs_researched = 0;
2801  old_research->researching_saved = A_UNKNOWN;
2802  BV_CLR_ALL(pplayer->real_embassy); // all embassies destroyed
2803 
2804  // give splitted player the embassies to his team mates back, if any
2805  if (pplayer->team) {
2806  players_iterate(pdest)
2807  {
2808  if (pplayer->team == pdest->team && pplayer != pdest) {
2809  establish_embassy(pplayer, pdest);
2810  }
2811  }
2813  }
2814  research_update(old_research);
2815 
2816  pplayer->economic = player_limit_to_max_rates(pplayer);
2817 
2818  // copy the maps
2819 
2820  give_map_from_player_to_player(pplayer, cplayer);
2821 
2822  pplayer->server.border_vision = cplayer->server.border_vision;
2823 
2824  /* Not sure if this is necessary, but might be a good idea
2825  * to avoid doing some ai calculations with bogus data. */
2826  adv_data_phase_init(cplayer, true);
2827  CALL_PLR_AI_FUNC(phase_begin, cplayer, cplayer, true);
2828  CALL_PLR_AI_FUNC(gained_control, cplayer, cplayer);
2829  CALL_PLR_AI_FUNC(split_by_civil_war, pplayer, pplayer, cplayer);
2830  CALL_PLR_AI_FUNC(created_by_civil_war, cplayer, pplayer, cplayer);
2831 
2832  return cplayer;
2833 }
2834 
2843 bool civil_war_possible(struct player *pplayer, bool conquering_city,
2844  bool honour_server_option)
2845 {
2846  int n;
2847 
2848  if (!game.info.civil_war_enabled) {
2849  return false;
2850  }
2851 
2852  n = city_list_size(pplayer->cities);
2853 
2854  if (n - (conquering_city ? 1 : 0) < GAME_MIN_CIVILWARSIZE) {
2855  return false;
2856  }
2857  if (honour_server_option) {
2858  return game.server.civilwarsize < GAME_MAX_CIVILWARSIZE
2859  && n >= game.server.civilwarsize;
2860  } else {
2861  return true;
2862  }
2863 }
2864 
2890 bool civil_war_triggered(struct player *pplayer)
2891 {
2892  // Get base probabilities
2893  int dice = fc_rand(100); // Throw the dice
2894  int prob = get_player_bonus(pplayer, EFT_CIVIL_WAR_CHANCE);
2895 
2896  // Now compute the contribution of the cities.
2897  city_list_iterate(pplayer->cities, pcity)
2898  {
2899  if (city_unhappy(pcity)) {
2900  prob += game.info.civil_war_bonus_unhappy;
2901  }
2902  if (city_celebrating(pcity)) {
2903  prob += game.info.civil_war_bonus_celebrating;
2904  }
2905  }
2907 
2908  qDebug("Civil war chance for %s: prob %d, dice %d", player_name(pplayer),
2909  prob, dice);
2910 
2911  return (dice < prob);
2912 }
2913 
2942 struct player *civil_war(struct player *pplayer)
2943 {
2944  int i, j;
2945  struct player *cplayer;
2946  struct city *capital;
2947  struct city_list *defector_candidates;
2948 
2949  /* It is possible that this function gets called after pplayer
2950  * died. Player pointers are safe even after death. */
2951  if (!pplayer->is_alive) {
2952  return nullptr;
2953  }
2954 
2956  // No space to make additional player
2957  qInfo(_("Could not throw %s into civil war - too many players"),
2958  nation_plural_for_player(pplayer));
2959  return nullptr;
2960  }
2961  if (normal_player_count() >= server.playable_nations) {
2962  // No nation for additional player
2963  qInfo(_("Could not throw %s into civil war - no available nations"),
2964  nation_plural_for_player(pplayer));
2965  return nullptr;
2966  }
2967 
2968  /* It doesn't make sense to try to split an empire of 1 city.
2969  * This should have been enforced by civil_war_possible(). */
2970  fc_assert_ret_val(city_list_size(pplayer->cities) > 1, nullptr);
2971 
2972  defector_candidates = city_list_new();
2973  city_list_iterate(pplayer->cities, pcity)
2974  {
2975  bool gameloss_present = false;
2976 
2977  // Capital (probably new capital) won't defect
2978  if (is_capital(pcity)) {
2979  continue;
2980  }
2981 
2982  // City hosting victim's GameLoss unit won't defect
2983  unit_list_iterate(city_tile(pcity)->units, punit)
2984  {
2985  if (unit_owner(punit) == pplayer
2986  && unit_has_type_flag(punit, UTYF_GAMELOSS)) {
2987  gameloss_present = true;
2988  break;
2989  }
2990  }
2992  if (gameloss_present) {
2993  continue;
2994  }
2995 
2996  city_list_append(defector_candidates, pcity);
2997  }
2999 
3000  if (city_list_size(defector_candidates) == 0) {
3001  qDebug(_("Could not throw %s into civil war - no available cities"),
3002  nation_plural_for_player(pplayer));
3003  city_list_destroy(defector_candidates);
3004  return nullptr;
3005  }
3006 
3007  // We're definitely going to create a new rebel player.
3008 
3009  if (normal_player_count() == game.server.max_players) {
3010  // 'maxplayers' must be increased to allow for a new player.
3011 
3012  // This assert should never be called due to the first check above.
3013  fc_assert_ret_val(game.server.max_players < MAX_NUM_PLAYERS, nullptr);
3014 
3015  game.server.max_players++;
3016  log_debug("Increased 'maxplayers' to allow the creation of a new player "
3017  "due to civil war.");
3018  }
3019 
3020  cplayer = split_player(pplayer);
3021 
3022  /* Before units, cities, so clients know name of new nation
3023  * (for debugging etc).
3024  */
3025  send_player_all_c(cplayer, nullptr);
3026  send_player_all_c(pplayer, nullptr);
3027 
3028  // Now split the empire
3029 
3030  qDebug("%s civil war; created AI %s",
3033  notify_player(pplayer, nullptr, E_CIVIL_WAR, ftc_server,
3034  _("Your nation is thrust into civil war."));
3035 
3036  notify_player(pplayer, nullptr, E_FIRST_CONTACT, ftc_server,
3037  // TRANS: <leader> ... the Poles.
3038  _("%s is the rebellious leader of the %s."),
3039  player_name(cplayer), nation_plural_for_player(cplayer));
3040 
3041  j = city_list_size(defector_candidates); // number left to process
3042  /* Number to try to flip; ensure that at least one eligible city is
3043  * flipped */
3044  i = MAX(j / 2, 1);
3045  city_list_iterate(defector_candidates, pcity)
3046  {
3047  fc_assert_action(!is_capital(pcity), continue);
3048  if (i >= j || (i > 0 && fc_rand(2) == 1)) {
3049  /* Transfer city and units supported by this city to the new owner.
3050  * We do NOT resolve stack conflicts here, but rather later.
3051  * Reason: if we have a transporter from one city which is carrying
3052  * a unit from another city, and both cities join the rebellion. If we
3053  * resolved stack conflicts for each city we would teleport the first
3054  * of the units we met since the other would have another owner. */
3055  if (transfer_city(cplayer, pcity, -1, false, false, false, false)) {
3056  qDebug("%s declares allegiance to the %s.", city_name_get(pcity),
3058  notify_player(pplayer, pcity->tile, E_CITY_LOST, ftc_server,
3059  // TRANS: <city> ... the Poles.
3060  _("%s declares allegiance to the %s."),
3061  city_link(pcity), nation_plural_for_player(cplayer));
3062  script_server_signal_emit("city_transferred", pcity, pplayer,
3063  cplayer, "civil_war");
3064  }
3065  i--;
3066  }
3067  j--;
3068  }
3070 
3071  city_list_destroy(defector_candidates);
3072 
3073  resolve_unit_stacks(pplayer, cplayer, false);
3074 
3075  i = city_list_size(cplayer->cities);
3076  fc_assert(i > 0); // rebels should have got at least one city
3077 
3078  // Choose a capital (random).
3079  capital = city_list_get(cplayer->cities, fc_rand(i));
3080  city_build_free_buildings(capital);
3081  give_midgame_initial_units(cplayer, city_tile(capital));
3082 
3083  notify_player(nullptr, nullptr, E_CIVIL_WAR, ftc_server,
3084  // TRANS: ... Danes ... Poles ... <7> cities.
3085  PL_("Civil war partitions the %s;"
3086  " the %s now hold %d city.",
3087  "Civil war partitions the %s;"
3088  " the %s now hold %d cities.",
3089  i),
3090  nation_plural_for_player(pplayer),
3091  nation_plural_for_player(cplayer), i);
3092 
3093  return cplayer;
3094 }
3095 
3100  struct player *pplayer,
3101  const struct packet_player_attribute_chunk *chunk)
3102 {
3103  generic_handle_player_attribute_chunk(pplayer, chunk);
3104 }
3105 
3110 {
3111  send_attribute_block(pplayer, pplayer->current_conn);
3112 }
3113 
3118 void handle_player_phase_done(struct player *pplayer, int turn)
3119 {
3120  if (turn != game.info.turn) {
3121  /* If this happens then the player actually pressed turn-done on a
3122  * previous turn but we didn't receive it until now. The player
3123  * probably didn't actually mean to end their turn! */
3124  return;
3125  } else if (game.server.fixedlength) {
3126  // Disallow Turn Done if the turn has a fixed length
3127  return;
3128  }
3129 
3130  pplayer->phase_done = true;
3131 
3133 
3134  send_player_all_c(pplayer, nullptr);
3135 }
3136 
3140 int normal_player_count() { return player_count() - server.nbarbarians; }
3141 
3145 void player_status_add(struct player *plr, enum player_status pstatus)
3146 {
3147  BV_SET(plr->server.status, pstatus);
3148 }
3149 
3153 bool player_status_check(struct player *plr, enum player_status pstatus)
3154 {
3155  return BV_ISSET(plr->server.status, pstatus);
3156 }
3157 
3161 void player_status_reset(struct player *plr)
3162 {
3163  BV_CLR_ALL(plr->server.status);
3164  player_status_add(plr, PSTATUS_NORMAL);
3165 }
3166 
3170 const char *player_delegation_get(const struct player *pplayer)
3171 {
3172  if (pplayer == nullptr || qstrlen(pplayer->server.delegate_to) == 0) {
3173  // No delegation if there is no player.
3174  return nullptr;
3175  } else {
3176  return pplayer->server.delegate_to;
3177  }
3178 }
3179 
3183 void player_delegation_set(struct player *pplayer, const char *username)
3184 {
3185  fc_assert_ret(pplayer != nullptr);
3186 
3187  if (username == nullptr || qstrlen(username) == 0) {
3188  pplayer->server.delegate_to[0] = '\0';
3189  } else {
3190  sz_strlcpy(pplayer->server.delegate_to, username);
3191  }
3192 }
3193 
3199 bool player_delegation_active(const struct player *pplayer)
3200 {
3201  return (pplayer && qstrlen(pplayer->server.orig_username) != 0);
3202 }
3203 
3207 void send_delegation_info(const struct connection *pconn)
3208 {
3209  if (game.info.is_new_game) {
3210  return;
3211  }
3212 
3213  if (!pconn->observer && pconn->playing
3214  && player_delegation_get(pconn->playing) != nullptr) {
3215  notify_conn(pconn->self, nullptr, E_CONNECTION, ftc_server,
3216  /* TRANS: '/delegate cancel' is a server command and must not
3217  * be translated */
3218  _("User '%s' is currently allowed to take control of your "
3219  "player while you are away. Use '/delegate cancel' to "
3220  "revoke this access."),
3221  player_delegation_get(pconn->playing));
3222  }
3223 
3224  {
3225  bool any_delegations = false;
3226  players_iterate(aplayer)
3227  {
3228  if (player_delegation_get(aplayer) != nullptr
3229  && strcmp(player_delegation_get(aplayer), pconn->username) == 0) {
3230  notify_conn(pconn->self, nullptr, E_CONNECTION, ftc_server,
3231  _("Control of player '%s' is delegated to you."),
3232  player_name(aplayer));
3233  any_delegations = true;
3234  }
3235  }
3237  if (any_delegations) {
3238  notify_conn(pconn->self, nullptr, E_CONNECTION, ftc_server,
3239  /* TRANS: '/delegate take' is a server command and must not
3240  * be translated; but <player> should be translated. */
3241  _("Use '/delegate take <player>' to take control of a "
3242  "delegated player."));
3243  }
3244  }
3245 }
3246 
3253 {
3254  players_iterate(pplayer)
3255  {
3256  if (player_delegation_get(pplayer)
3257  && fc_strcasecmp(name, pplayer->server.orig_username) == 0) {
3258  return pplayer;
3259  }
3260  }
3262 
3263  return nullptr;
3264 }
3265 
3270 {
3271  fc_assert_ret(game.server.plr_colors == nullptr);
3272  game.server.plr_colors = rgbcolor_list_new();
3273 }
3274 
3279 {
3280  if (game.server.plr_colors == nullptr) {
3281  return;
3282  }
3283 
3284  if (rgbcolor_list_size(game.server.plr_colors) > 0) {
3285  rgbcolor_list_iterate(game.server.plr_colors, prgbcolor)
3286  {
3287  rgbcolor_list_remove(game.server.plr_colors, prgbcolor);
3288  rgbcolor_destroy(prgbcolor);
3289  }
3291  };
3292  rgbcolor_list_destroy(game.server.plr_colors);
3293  game.server.plr_colors = nullptr;
3294 }
3295 
3299 void playercolor_add(struct rgbcolor *prgbcolor)
3300 {
3301  fc_assert_ret(game.server.plr_colors != nullptr);
3302 
3303  rgbcolor_list_append(game.server.plr_colors, prgbcolor);
3304 }
3305 
3309 struct rgbcolor *playercolor_get(int id)
3310 {
3311  fc_assert_ret_val(game.server.plr_colors != nullptr, nullptr);
3312 
3313  return rgbcolor_list_get(game.server.plr_colors, id);
3314 }
3315 
3320 {
3321  fc_assert_ret_val(game.server.plr_colors != nullptr, 0);
3322 
3323  return rgbcolor_list_size(game.server.plr_colors);
3324 }
3325 
3329 void handle_player_multiplier(struct player *pplayer, int count,
3330  const int *multipliers)
3331 {
3332  int rval;
3333  int i;
3334 
3335  if (count != multiplier_count()) {
3336  qCritical("Bad number of multipliers %d from client for %s", count,
3337  player_name(pplayer));
3338  return;
3339  }
3340 
3341  for (i = 0; i < count; i++) {
3342  struct multiplier *pmul = multiplier_by_number(i);
3343 
3344  if (multiplier_can_be_changed(pmul, pplayer)) {
3345  if (multipliers[i] < pmul->start || multipliers[i] > pmul->stop) {
3346  qCritical("Multiplier value %d for %s out of range for %s",
3348  player_name(pplayer));
3349  } else {
3350  rval = (multipliers[i] - pmul->start) / pmul->step * pmul->step
3351  + pmul->start;
3352  if (rval != multipliers[i]) {
3353  qCritical("Multiplier value %d between valid values for %s for %s",
3355  player_name(pplayer));
3356  } else {
3357  pplayer->multipliers_target[i] = multipliers[i];
3358  }
3359  }
3360  }
3361  }
3362 
3363  send_player_info_c(pplayer, nullptr);
3364 }
3365 
3369 void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
3370 {
3371  set_as_ai(pplayer);
3372 
3373  set_ai_level_directer(pplayer, skill_level);
3374  cancel_all_meetings(pplayer);
3375  CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
3376  if (is_player_phase(pplayer, game.info.phase)) {
3377  CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
3378  }
3379 
3380  if (S_S_RUNNING == server_state()) {
3381  // In case this was last player who has not pressed turn done.
3383  }
3384 
3385  fc_assert(pplayer->ai_common.skill_level == skill_level);
3386 }
3387 
3392 {
3393  set_as_human(pplayer);
3394 
3395  if (pplayer->ai_common.skill_level == AI_LEVEL_AWAY) {
3396  pplayer->ai_common.skill_level = ai_level_invalid();
3397  }
3398 
3399  CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
3400 
3401  // Because the AI "cheats" with government rates but humans shouldn't.
3402  if (!game.info.is_new_game) {
3403  check_player_max_rates(pplayer);
3404  }
3405  cancel_all_meetings(pplayer);
3406 }
void adv_data_close(struct player *pplayer)
Free memory for advisor data.
Definition: advdata.cpp:739
void adv_data_init(struct player *pplayer)
Allocate memory for advisor data.
Definition: advdata.cpp:685
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_default(struct player *pplayer)
Initialize with sane values.
Definition: advdata.cpp:720
const char * ai_name(const struct ai_type *ai)
Return the name of the ai type.
Definition: ai.cpp:99
struct ai_type * ai_type_by_name(const char *search)
Find ai type with given name.
Definition: ai.cpp:59
const char * ai_type_name_or_fallback(const char *orig_name)
Return usable ai type name, if possible.
Definition: ai.cpp:110
#define CALL_FUNC_EACH_AI(_func,...)
Definition: ai.h:393
@ INCIDENT_WAR
Definition: ai.h:40
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition: ai.h:383
void call_incident(enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *violator, struct player *victim)
Call incident function of victim.
Definition: aiiface.cpp:235
void ai_traits_close(struct player *pplayer)
Free resources associated with player ai traits.
Definition: aitraits.cpp:54
struct player * create_barbarian_player(enum barbarian_type type)
Creates the land/sea barbarian player and inits some stuff.
Definition: barbarian.cpp:82
#define BV_SET_ALL(bv)
Definition: bitvector.h:66
#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 citizens_nation_move(struct city *pcity, const struct player_slot *pslot_from, const struct player_slot *pslot_to, int move)
Convert a (positive or negative) value to the citizens from one nation to another.
Definition: citizens.cpp:123
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Get the number of citizens with the given nationality.
Definition: citizens.cpp:65
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
bool is_capital(const struct city *pcity)
Return TRUE iff this city is its nation's capital.
Definition: city.cpp:1495
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
Definition: city.cpp:1095
const char * city_name_get(const struct city *pcity)
Return the name of the city.
Definition: city.cpp:1077
bool city_unhappy(const struct city *pcity)
Return TRUE iff the city is unhappy.
Definition: city.cpp:1544
bool city_celebrating(const struct city *pcity)
cities celebrate only after consecutive happy turns
Definition: city.cpp:1564
#define cities_iterate_end
Definition: city.h:493
#define city_list_iterate_safe(citylist, _city)
Definition: city.h:500
#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
#define city_list_iterate_safe_end
Definition: city.h:521
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Remove the trade route between pc1 and pc2 (if one exists).
Definition: citytools.cpp:2791
void city_build_free_buildings(struct city *pcity)
Give to a new city the free (initial) buildings.
Definition: citytools.cpp:1433
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 remove_city(struct city *pcity)
Remove a city from the game.
Definition: citytools.cpp:1676
bool transfer_city(struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
Handles all transactions in relation to transferring a city.
Definition: citytools.cpp:1084
void sync_cities()
Make sure all players (clients) have up-to-date information about all their cities.
Definition: citytools.cpp:3150
void city_refresh_queue_add(struct city *pcity)
Queue pending city_refresh() for later.
Definition: cityturn.cpp:188
void city_refresh_queue_processing()
Refresh the listed cities.
Definition: cityturn.cpp:204
void city_refresh_for_player(struct player *pplayer)
Called on government change or wonder completion or stuff like that – Syela.
Definition: cityturn.cpp:171
void connection_detach(struct connection *pconn, bool remove_unused_player)
Remove pconn as a client connected to pplayer: Updates pconn->playing, pconn->playing->connections,...
#define conn_list_iterate(connlist, pconn)
Definition: connection.h:99
#define conn_list_iterate_end
Definition: connection.h:101
int player_culture(const struct player *plr)
Return current culture score of the player.
Definition: culture.cpp:40
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 establish_embassy(struct player *pplayer, struct player *aplayer)
Create an embassy.
Definition: diplhand.cpp:689
void reject_all_treaties(struct player *pplayer)
Reject all treaties currently being negotiated.
Definition: diplhand.cpp:911
void cancel_all_meetings(struct player *pplayer)
Cancels all meetings of player.
Definition: diplhand.cpp:897
const int TURNS_LEFT
Definition: diplhand.h:26
int get_target_bonus_effects(struct effect_list *plist, const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, enum effect_type effect_type, enum vision_layer vision_layer, enum national_intelligence nintel)
Returns the effect bonus of a given type for any target.
Definition: effects.cpp:611
int get_player_intel_bonus(const struct player *pplayer, const struct player *pother, enum national_intelligence nintel, enum effect_type effect_type)
Gets the player effect bonus of a national intelligence.
Definition: effects.cpp:779
int get_city_bonus(const struct city *pcity, enum effect_type effect_type, enum vision_layer vlayer)
Returns the effect bonus at a city.
Definition: effects.cpp:688
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
Definition: effects.cpp:673
struct player * extra_owner(const struct tile *ptile)
Who owns extras on tile.
Definition: extras.cpp:1013
#define extra_type_by_cause_iterate_end
Definition: extras.h:307
#define extra_type_by_cause_iterate(_cause, _extra)
Definition: extras.h:299
unsigned char citizens
Definition: fc_types.h:305
#define MAX_NUM_PLAYERS
Definition: fc_types.h:28
@ REVOLEN_RANDOM
Definition: fc_types.h:1089
@ REVOLEN_RANDQUICK
Definition: fc_types.h:1091
@ REVOLEN_FIXED
Definition: fc_types.h:1088
@ REVOLEN_QUICKENING
Definition: fc_types.h:1090
int Government_type_id
Definition: fc_types.h:298
#define MAX_NUM_PLAYER_SLOTS
Definition: fc_types.h:24
#define MAX_LEN_NAME
Definition: fc_types.h:61
#define PL_(String1, String2, n)
Definition: fcintl.h:54
#define _(String)
Definition: fcintl.h:50
size_t featured_text_apply_tag(const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Apply a tag to a text.
const struct ft_color ftc_server
const struct ft_color ftc_any
const char * city_link(const struct city *pcity)
Get a text link to a city.
#define FT_OFFSET_UNSET
Definition: featured_text.h:95
@ TTT_COLOR
#define FT_COLOR(fg, bg)
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
struct world wld
Definition: game.cpp:48
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
Definition: game.cpp:103
#define GAME_DEFAULT_REVOLUTION_LENGTH
Definition: game.h:676
#define GAME_MIN_CIVILWARSIZE
Definition: game.h:451
#define GAME_MAX_CIVILWARSIZE
Definition: game.h:452
struct unit_type * crole_to_unit_type(char crole, struct player *pplayer)
Get unit_type for given role character.
Definition: gamehand.cpp:108
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
Definition: government.cpp:107
struct government * government_by_number(const Government_type_id gov)
Return the government with the given index.
Definition: government.cpp:96
const char * government_name_for_player(const struct player *pplayer)
Return the (translated) name of the given government of a player.
Definition: government.cpp:147
bool untargeted_revolution_allowed()
Is it possible to start a revolution without specifying the target government in the current game?
Definition: government.cpp:462
Government_type_id government_count()
Return the number of governments.
Definition: government.cpp:64
const char * government_rule_name(const struct government *pgovern)
Return the (untranslated) rule name of the government.
Definition: government.cpp:126
bool can_change_to_government(struct player *pplayer, const struct government *gov)
Can change to government if appropriate tech exists, and one of:
Definition: government.cpp:159
Government_type_id government_number(const struct government *pgovern)
Return the government index.
Definition: government.cpp:84
const char * government_name_translation(const struct government *pgovern)
Return the (translated) name of the given government.
Definition: government.cpp:136
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
AI players may have handicaps - allowing them to cheat or preventing them from using certain algorith...
Definition: handicaps.cpp:62
void handicaps_init(struct player *pplayer)
Initialize handicaps for player.
Definition: handicaps.cpp:26
void handicaps_close(struct player *pplayer)
Free resources associated with player handicaps.
Definition: handicaps.cpp:37
@ H_REVOLUTION
Definition: handicaps.h:29
Impr_type_id improvement_count()
Return the number of improvements.
struct impr_type * improvement_by_number(const Impr_type_id id)
Returns the improvement type for the given index/ID.
#define WONDER_NOT_BUILT
Definition: improvement.h:144
#define B_LAST
Definition: improvement.h:33
const char * name
Definition: inputfile.cpp:118
#define fc_assert_msg(condition, message,...)
Definition: log.h:96
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
#define fc_assert_action(condition, action)
Definition: log.h:104
#define log_debug(message,...)
Definition: log.h:65
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
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition: map.h:312
#define square_iterate_end
Definition: map.h:315
#define whole_map_iterate(_map, _tile)
Definition: map.h:473
#define whole_map_iterate_end
Definition: map.h:480
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_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Claim ownership of a single tile.
Definition: maphand.cpp:2070
void map_claim_base(struct tile *ptile, const extra_type *pextra, struct player *powner, struct player *ploser)
Claim base to player's ownership.
Definition: maphand.cpp:2273
void map_know_and_see_all(struct player *pplayer)
Call this function to unfog all tiles.
Definition: maphand.cpp:1151
void give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Give information about whole map (all tiles) from player to player.
Definition: maphand.cpp:368
void remove_shared_vision(struct player *pfrom, struct player *pto)
Removes shared vision from between two players.
Definition: maphand.cpp:1634
void player_map_free(struct player *pplayer)
Free a player's private map.
Definition: maphand.cpp:1191
void remove_player_from_maps(struct player *pplayer)
Remove all knowledge of a player from main map and other players' private maps, and send updates to c...
Definition: maphand.cpp:1210
enum mood_type player_mood(struct player *pplayer)
What is the player mood?
Definition: mood.cpp:24
struct multiplier * multiplier_by_number(Multiplier_type_id id)
Returns multiplier associated to given number.
Definition: multipliers.cpp:54
const char * multiplier_rule_name(const struct multiplier *pmul)
Return the (untranslated) rule name of the multiplier.
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
Can player change multiplier value.
static struct multiplier multipliers[MAX_NUM_MULTIPLIERS]
Definition: multipliers.cpp:20
Multiplier_type_id multiplier_count()
Return number of loaded multipliers in the ruleset.
Definition: multipliers.cpp:85
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_set * nation_set_by_number(int id)
Return the nation set with the given index.
Definition: nation.cpp:640
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
int nations_match(const struct nation_type *pnation1, const struct nation_type *pnation2, bool ignore_conflicts)
Returns how much two nations look good in the same game.
Definition: nation.cpp:1065
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
int nation_set_index(const struct nation_set *pset)
Return the nation set index.
Definition: nation.cpp:582
const char * nation_rule_name(const struct nation_type *pnation)
Return the (untranslated) rule name of the nation (adjective form).
Definition: nation.cpp:115
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
struct nation_set * nation_set_by_setting_value(const char *setting)
Returns the nation set that would be selected by the given value of the 'nationset' server setting.
Definition: nation.cpp:736
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
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Check if the given nation is in a given set.
Definition: nation.cpp:712
const struct rgbcolor * nation_color(const struct nation_type *pnation)
Returns nation's player color preference, or nullptr if none.
Definition: nation.cpp:568
const char * nation_set_rule_name(const struct nation_set *pset)
Return the (untranslated) rule name of a nation set.
Definition: nation.cpp:682
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
Nation_type_id nation_index(const struct nation_type *pnation)
Return the nation index.
Definition: nation.cpp:464
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
Definition: nation.cpp:419
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_list_iterate(nationlist, pnation)
Definition: nation.h:72
#define nation_sets_iterate_end
Definition: nation.h:286
#define nation_sets_iterate(NAME_pset)
Definition: nation.h:283
#define nation_list_iterate_end
Definition: nation.h:74
#define NATION_NONE
Definition: nation.h:24
#define NO_NATION_SELECTED
Definition: nation.h:21
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 generic_handle_player_attribute_chunk(struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
Updates pplayer->attribute_block according to the given packet.
Definition: packets.cpp:639
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
struct player_slot * player_slot_by_number(int player_id)
Return the possibly unused and uninitialized player slot.
Definition: player.cpp:410
bool player_slot_is_used(const struct player_slot *pslot)
Returns TRUE is this slot is "used" i.e.
Definition: player.cpp:395
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
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Return the diplomatic state that cancelling a pact will end up in.
Definition: player.cpp:65
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
void player_clear(struct player *pplayer, bool full)
Clear all player data.
Definition: player.cpp:615
int player_slot_index(const struct player_slot *pslot)
Returns the index of the player slot.
Definition: player.cpp:373
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Returns whether pplayer has a real embassy with pplayer2, established from a diplomat,...
Definition: player.cpp:206
void player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Set the player's color.
Definition: player.cpp:598
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
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
The senate may not allow you to break the treaty.
Definition: player.cpp:90
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
Definition: player.cpp:1334
struct player * player_new(struct player_slot *pslot)
Creates a new player for the slot.
Definition: player.cpp:442
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Check if pplayer has an embassy with pplayer2.
Definition: player.cpp:195
bool gives_shared_vision(const struct player *me, const struct player *them)
Return TRUE iff the player me gives shared vision to player them.
Definition: player.cpp:1414
void player_destroy(struct player *pplayer)
Destroys and remove a player from the game.
Definition: player.cpp:684
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
dipl_reason
Definition: player.h:183
@ DIPL_SENATE_BLOCKING
Definition: player.h:186
@ DIPL_OK
Definition: player.h:184
#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 set_as_human(plr)
Definition: player.h:228
#define players_iterate_alive_end
Definition: player.h:532
@ PLRCOL_PLR_RANDOM
Definition: player.h:35
@ PLRCOL_PLR_SET
Definition: player.h:36
@ PLRCOL_NATION_ORDER
Definition: player.h:38
@ PLRCOL_TEAM_ORDER
Definition: player.h:37
@ PLRCOL_PLR_ORDER
Definition: player.h:34
#define set_as_ai(plr)
Definition: player.h:229
#define is_human(plr)
Definition: player.h:226
#define players_iterate_alive(_pplayer)
Definition: player.h:526
void handle_player_phase_done(struct player *pplayer, int turn)
(Hmm, how should "turn done" work for multi-connected non-observer players?)
Definition: plrhand.cpp:3118
struct conn_list * player_reply_dest(struct player *pplayer)
Convenience function to return "reply" destination connection list for player: pplayer->current_conn ...
Definition: plrhand.cpp:1469
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Tell clients which nations can be picked given current server settings.
Definition: plrhand.cpp:2574
void handle_player_multiplier(struct player *pplayer, int count, const int *multipliers)
Sets player's multipliers.
Definition: plrhand.cpp:3329
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
static void send_player_remove_info_c(const struct player_slot *pslot, struct conn_list *dest)
Send information about removed (unused) players.
Definition: plrhand.cpp:983
void player_update_last_war_action(struct player *pplayer)
Update last war action timestamp (affects player mood).
Definition: plrhand.cpp:730
void handle_player_attribute_chunk(struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
The client has send as a chunk of the attribute block.
Definition: plrhand.cpp:3099
void player_status_add(struct player *plr, enum player_status pstatus)
Add a status flag to a player.
Definition: plrhand.cpp:3145
static struct nation_set * current_nationset()
Return the nationset currently in effect.
Definition: plrhand.cpp:2511
struct player * civil_war(struct player *pplayer)
Capturing a nation's primary capital is a devastating blow.
Definition: plrhand.cpp:2942
static void send_player_info_c_real(struct player *src, struct conn_list *dest)
Really send information.
Definition: plrhand.cpp:1067
void playercolor_init()
Initialise the player colors.
Definition: plrhand.cpp:3269
void player_set_under_human_control(struct player *pplayer)
Toggle player under human control.
Definition: plrhand.cpp:3391
static void maybe_claim_base(struct tile *ptile, struct player *new_owner, struct player *old_owner)
If there's any units of new_owner on tile, they claim bases.
Definition: plrhand.cpp:682
void count_playable_nations()
Update the server's cached number of playable nations.
Definition: plrhand.cpp:2529
void playercolor_free()
Free the memory allocated for the player color.
Definition: plrhand.cpp:3278
void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
Gives units that every player should have.
Definition: plrhand.cpp:1752
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
static int get_player_maxrate(struct player *pplayer)
Return player maxrate in legal range.
Definition: plrhand.cpp:256
static void call_first_contact(struct player *pplayer, struct player *aplayer)
Call first_contact function if such is defined for player.
Definition: plrhand.cpp:1478
static void package_player_common(struct player *plr, struct packet_player_info *packet)
Package player information that is always sent.
Definition: plrhand.cpp:1155
static struct player * split_player(struct player *pplayer)
This function creates a new player and copies all of it's science research etc.
Definition: plrhand.cpp:2694
bool civil_war_triggered(struct player *pplayer)
civil_war_triggered: The capture of a primary capital is not a sure fire way to throw and empire into...
Definition: plrhand.cpp:2890
void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Set the player's color.
Definition: plrhand.cpp:1706
void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
Toggle player to AI mode.
Definition: plrhand.cpp:3369
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
bool player_delegation_active(const struct player *pplayer)
Returns TRUE if a delegation is active.
Definition: plrhand.cpp:3199
struct player * player_by_user_delegated(const char *name)
For a given user, if there is some player that the user originally controlled but is currently delega...
Definition: plrhand.cpp:3252
static void package_player_info(struct player *plr, struct packet_player_info *packet, struct player *receiver, bool send_all)
Package player info depending on info_level.
Definition: plrhand.cpp:1210
void assign_player_colors()
Permanently assign colors to any players that don't already have them.
Definition: plrhand.cpp:1608
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Check if we make contact with anyone.
Definition: plrhand.cpp:2282
void handle_player_attribute_block(struct player *pplayer)
The client request an attribute block.
Definition: plrhand.cpp:3109
static void send_nation_availability_real(struct conn_list *dest, bool nationset_change)
Helper doing the actual work for send_nation_availability() (q.v.).
Definition: plrhand.cpp:2557
struct rgbcolor * playercolor_get(int id)
Get the player color with the index 'id'.
Definition: plrhand.cpp:3309
static enum diplstate_type get_default_diplstate(const struct player *pplayer1, const struct player *pplayer2)
Returns the default diplomatic state between 2 players.
Definition: plrhand.cpp:2176
void check_player_max_rates(struct player *pplayer)
The following checks that government rates are acceptable for the present form of government.
Definition: plrhand.cpp:637
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 set_shuffled_players(int *shuffled_players)
Initialize the shuffled players list (as from a loaded savegame).
Definition: plrhand.cpp:2327
static int shuffled_order[MAX_NUM_PLAYER_SLOTS]
Definition: plrhand.cpp:92
void player_status_reset(struct player *plr)
Reset player status to 'normal'.
Definition: plrhand.cpp:3161
void send_delegation_info(const struct connection *pconn)
Send information about delegations to reconnecting users.
Definition: plrhand.cpp:3207
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Called by the client or AI to change government.
Definition: plrhand.cpp:427
void update_players_after_alliance_breakup(struct player *pplayer, struct player *pplayer2, const struct unit_list *pplayer_seen_units, const struct unit_list *pplayer2_seen_units)
After the alliance is breaken, we need to do two things:
Definition: plrhand.cpp:665
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
static void package_player_diplstate(struct player *plr1, struct player *plr2, struct packet_player_diplstate *packet_ds, struct player *receiver, bool full)
Package player diplstate depending on info_level.
Definition: plrhand.cpp:1414
bool player_status_check(struct player *plr, enum player_status pstatus)
Check player status flag.
Definition: plrhand.cpp:3153
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Check if civil war is possible for a player.
Definition: plrhand.cpp:2843
void player_delegation_set(struct player *pplayer, const char *username)
Define a delegation.
Definition: plrhand.cpp:3183
static bool server_player_name_is_allowed(const struct connection *caller, const struct player *pplayer, const struct nation_type *pnation, const char *name, char *error_buf, size_t error_buf_len)
Check if this name is allowed for the player.
Definition: plrhand.cpp:1994
void fit_nationset_to_players()
Try to select a nation set that fits the current players' nations, or failing that,...
Definition: plrhand.cpp:2588
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 player_info_freeze()
Do not compute and send PACKET_PLAYER_INFO or PACKET_NATION_AVAILABILITY until a call to player_info_...
Definition: plrhand.cpp:1005
void government_change(struct player *pplayer, struct government *gov, bool revolution_finished)
Finish the revolution and set the player's government.
Definition: plrhand.cpp:322
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 handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Handles a player cancelling a "pact" with another player.
Definition: plrhand.cpp:745
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Update contact info.
Definition: plrhand.cpp:2197
void playercolor_add(struct rgbcolor *prgbcolor)
Add a color to the list of all available player colors.
Definition: plrhand.cpp:3299
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 player_info_thaw()
If the frozen level is back to 0, send all players' infos, and nation availability,...
Definition: plrhand.cpp:1011
static void send_player_diplstate_c_real(struct player *src, struct conn_list *dest)
Really send information.
Definition: plrhand.cpp:1121
void handle_player_rates(struct player *pplayer, int tax, int luxury, int science)
Handle a client or AI request to change the tax/luxury/science rates.
Definition: plrhand.cpp:272
bool player_color_changeable(const struct player *pplayer, const char **reason)
Return whether a player's color can currently be set with the '/playercolor' command.
Definition: plrhand.cpp:1590
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
struct player * shuffled_player(int i)
Returns the i'th shuffled player, or nullptr.
Definition: plrhand.cpp:2345
const struct rgbcolor * player_preferred_color(struct player *pplayer)
If a player's color will be predictable when colors are assigned (or assignment has already happened)...
Definition: plrhand.cpp:1547
const char * player_delegation_get(const struct player *pplayer)
Returns the username that control of the player is delegated to, if any.
Definition: plrhand.cpp:3170
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
void send_player_diplstate_c(struct player *src, struct conn_list *dest)
Identical to send_player_info_c(), but sends the diplstate of the player.
Definition: plrhand.cpp:1106
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
static int player_info_frozen_level
Definition: plrhand.cpp:95
int revolution_length(struct government *gov, struct player *plr)
Get length of a revolution.
Definition: plrhand.cpp:390
const char * player_color_ftstr(struct player *pplayer)
Return the player color as featured text string.
Definition: plrhand.cpp:1726
void reset_all_start_commands(bool plrchange)
Called when something is changed; this resets everyone's readiness.
Definition: plrhand.cpp:2658
void update_revolution(struct player *pplayer)
See if the player has finished their revolution.
Definition: plrhand.cpp:527
#define fc_rand(_size)
Definition: rand.h:16
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Set research knowledge about tech to given state.
Definition: research.cpp:627
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
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
Definition: research.cpp:609
void research_update(struct research *presearch)
Mark as TECH_PREREQS_KNOWN each tech which is available, not known and which has all requirements ful...
Definition: research.cpp:486
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Free rgbcolor structure.
Definition: rgbcolor.cpp:65
bool rgbcolors_are_equal(const struct rgbcolor *c1, const struct rgbcolor *c2)
Test whether two rgbcolor structures represent the exact same color value.
Definition: rgbcolor.cpp:52
bool rgbcolor_to_hex(const struct rgbcolor *prgbcolor, char *hex, size_t hex_len)
Convert a rgb color to a hex string (like 0xff0000 for red [255, 0, 0]).
Definition: rgbcolor.cpp:130
#define rgbcolor_list_iterate_end
Definition: rgbcolor.h:37
#define rgbcolor_list_iterate(rgbcolorlist, prgbcolor)
Definition: rgbcolor.h:35
void script_server_signal_emit(const char *signal_name,...)
Invoke all the callback functions attached to a given signal.
void script_server_remove_exported_object(void *object)
Mark any, if exported, full userdata representing 'object' in the current script state as 'Nonexisten...
void array_shuffle(int *array, int n)
Randomize the elements of an array using the Fisher-Yates shuffle.
Definition: shared.cpp:1228
bool is_ascii_name(const char *name)
This is used in sundry places to make sure that names of cities, players etc.
Definition: shared.cpp:223
void remove_leading_trailing_spaces(char *s)
Removes leading and trailing spaces in string pointed to by 's'.
Definition: shared.cpp:353
#define CLIP(lower, current, upper)
Definition: shared.h:51
#define MIN(x, y)
Definition: shared.h:49
#define FC_INFINITY
Definition: shared.h:32
#define MAX(x, y)
Definition: shared.h:48
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_init(struct player_spaceship *ship)
Initialize spaceship struct; could also be used to "cancel" a spaceship (eg, if/when capital-capture ...
Definition: spaceship.cpp:45
void check_for_full_turn_done()
Check if turn is really done.
Definition: srv_main.cpp:2179
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Set nation for player with nation default values.
Definition: srv_main.cpp:2545
bool game_was_started()
Returns iff the game was started once upon a time.
Definition: srv_main.cpp:251
enum server_states server_state()
Return current server state.
Definition: srv_main.cpp:238
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Set an AI level from the server prompt.
Definition: stdinhand.cpp:2056
Definition: city.h:291
int id
Definition: city.h:296
enum capital_type capital
Definition: city.h:298
struct civ_game::@28::@32 server
struct packet_ruleset_control control
Definition: game.h:74
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 government * government_during_revolution
Definition: game.h:85
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
char username[MAX_LEN_NAME]
Definition: connection.h:151
int changed_to_times
Definition: government.h:43
government()
Allocate resources associated with the given government.
Definition: government.cpp:407
Functions for handling the nations.
Definition: nation.cpp:33
struct nation_type::@48::@50 server
enum barbarian_type barb_type
Definition: nation.h:89
enum ai_level skill_level
Definition: player.h:109
enum barbarian_type barbarian_type
Definition: player.h:115
int warmth
Definition: player.h:114
int science_cost
Definition: player.h:112
int love[MAX_NUM_PLAYER_SLOTS]
Definition: player.h:117
int maxbuycost
Definition: player.h:107
int frost
Definition: player.h:114
int has_reason_to_cancel
Definition: player.h:197
int contact_turns_left
Definition: player.h:198
int first_contact_turn
Definition: player.h:195
enum diplstate_type type
Definition: player.h:193
int units_killed
Definition: player.h:99
int units_lost
Definition: player.h:100
int game
Definition: player.h:103
int units_built
Definition: player.h:98
Definition: player.h:231
struct city_list * cities
Definition: player.h:263
struct player_ai ai_common
Definition: player.h:270
bv_plr_flags flags
Definition: player.h:274
int primary_capital_id
Definition: player.h:257
bool is_male
Definition: player.h:239
int wonders[B_LAST]
Definition: player.h:283
struct government * target_government
Definition: player.h:241
char username[MAX_LEN_NAME]
Definition: player.h:234
bool is_connected
Definition: player.h:278
int revolution_finishes
Definition: player.h:255
struct player::@65::@67 server
int nturns_idle
Definition: player.h:247
struct government * government
Definition: player.h:240
struct connection * current_conn
Definition: player.h:279
struct team * team
Definition: player.h:243
char * savegame_ai_type_name
Definition: player.h:272
int turns_alive
Definition: player.h:248
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
bv_player real_embassy
Definition: player.h:259
struct player_economic economic
Definition: player.h:266
struct player_spaceship spaceship
Definition: player.h:268
char name[MAX_LEN_NAME]
Definition: player.h:233
bv_player gives_shared_vision
Definition: player.h:281
struct player_score score
Definition: player.h:265
int multipliers[MAX_NUM_MULTIPLIERS]
Definition: player.h:296
struct nation_type * nation
Definition: player.h:242
struct nation_style * style
Definition: player.h:261
int multipliers_target[MAX_NUM_MULTIPLIERS]
Definition: player.h:298
bool phase_done
Definition: player.h:245
struct player_slot * slot
Definition: player.h:232
bool is_ready
Definition: player.h:244
int history
Definition: player.h:300
int last_war_action
Definition: player.h:252
struct rgbcolor * rgb
Definition: player.h:293
bool unassigned_user
Definition: player.h:235
Tech_type_id researching
Definition: research.h:45
Tech_type_id tech_goal
Definition: research.h:78
Tech_type_id researching_saved
Definition: research.h:55
int techs_researched
Definition: research.h:35
struct research::research_invention inventions[A_LAST]
int bulbs_researched
Definition: research.h:46
int g
Definition: rgbcolor.h:27
int b
Definition: rgbcolor.h:27
int r
Definition: rgbcolor.h:27
Definition: servers.h:55
Definition: team.cpp:35
Definition: tile.h:42
struct unit_list * units
Definition: tile.h:50
struct player * extras_owner
Definition: tile.h:55
struct civ_map map
Definition: world_object.h:21
struct music_style * player_music_style(struct player *plr)
Return music style for player.
Definition: style.cpp:172
int music_style_number(const struct music_style *pms)
Return the music style id.
Definition: style.cpp:148
int style_number(const struct nation_style *pstyle)
Return the style id.
Definition: style.cpp:54
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
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
Definition: support.cpp:412
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89
int cat_snprintf(char *str, size_t n, const char *format,...)
cat_snprintf is like a combination of fc_snprintf and fc_strlcat; it does snprintf to the end of an e...
Definition: support.cpp:564
#define sz_strlcpy(dest, src)
Definition: support.h:140
#define fc_strdup(str)
Definition: support.h:111
#define fc__fallthrough
Definition: support.h:49
void team_add_player(struct player *pplayer, struct team *pteam)
Set a player to a team.
Definition: team.cpp:438
int team_count()
Return the current number of teams.
Definition: team.cpp:354
int team_number(const struct team *pteam)
Return the team index/number/id.
Definition: team.cpp:364
const struct player_list * team_members(const struct team *pteam)
Returns the member list of the team.
Definition: team.cpp:427
#define advance_index_iterate_end
Definition: tech.h:226
#define A_NONE
Definition: tech.h:36
#define A_UNKNOWN
Definition: tech.h:42
#define advance_index_iterate(_start, _index)
Definition: tech.h:221
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Send research info for 'presearch' to 'dest'.
Definition: techtools.cpp:273
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Check if tile contains base providing effect for unit.
Definition: tile.cpp:203
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_owner(_tile)
Definition: tile.h:78
#define trade_routes_iterate_safe_end
Definition: traderoutes.h:148
#define trade_routes_iterate_safe(c, proute)
Definition: traderoutes.h:133
#define unit_owner(_pu)
Definition: unit.h:370
#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 remove_allied_visibility(struct player *pplayer, struct player *aplayer, const struct unit_list *seen_units)
When two players cancel an alliance, a lot of units that were visible may no longer be visible (this ...
Definition: unittools.cpp:1593
struct unit * create_unit(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left)
Wrapper of the below.
Definition: unittools.cpp:1762
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
When in civil war or an alliance breaks there will potentially be units from both sides coexisting on...
Definition: unittools.cpp:1537
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Remove the unit, and passengers if it is a carrying any.
Definition: unittools.cpp:2248
struct unit_list * get_units_seen_via_ally(const struct player *pplayer, const struct player *aplayer)
Returns the list of the units seen by 'pplayer' potentially seen only thanks to an alliance with 'apl...
Definition: unittools.cpp:1552
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
Definition: unittype.cpp:176
void send_updated_vote_totals(struct conn_list *dest)
Sends a packet_vote_update to every conn in dest.
Definition: voting.cpp:884