Freeciv-3.3
Loading...
Searching...
No Matches
plrhand.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdarg.h>
19
20/* utility */
21#include "bitvector.h"
22#include "fcintl.h"
23#include "log.h"
24#include "mem.h"
25#include "rand.h"
26#include "shared.h"
27#include "support.h"
28
29/* common */
30#include "citizens.h"
31#include "culture.h"
32#include "diptreaty.h"
33#include "government.h"
34#include "map.h"
35#include "movement.h"
36#include "multipliers.h"
37#include "nation.h"
38#include "packets.h"
39#include "player.h"
40#include "research.h"
41#include "rgbcolor.h"
42#include "specialist.h"
43#include "tech.h"
44#include "unitlist.h"
45
46/* common/scriptcore */
47#include "luascript_types.h"
48
49/* server */
50#include "aiiface.h"
51#include "barbarian.h"
52#include "citytools.h"
53#include "cityturn.h"
54#include "connecthand.h"
55#include "diplhand.h"
56#include "gamehand.h"
57#include "maphand.h"
58#include "mood.h"
59#include "notify.h"
60#include "plrhand.h"
61#include "sernet.h"
62#include "srv_main.h"
63#include "stdinhand.h"
64#include "spaceship.h"
65#include "spacerace.h"
66#include "techtools.h"
67#include "unittools.h"
68#include "voting.h"
69
70/* server/advisors */
71#include "advdata.h"
72
73/* server/scripting */
74#include "script_server.h"
75
76/* ai */
77#include "aitraits.h"
78#include "difficulty.h"
79#include "handicaps.h"
80
81
82struct rgbcolor;
83
84static void package_player_common(struct player *plr,
85 struct packet_player_info *packet,
88
89static void package_player_diplstate(struct player *plr1,
90 struct player *plr2,
92 struct player *receiver,
94static void package_player_info(struct player *plr,
95 struct packet_player_info *packet,
98 struct player *receiver,
100static enum plr_info_level player_info_level(struct player *plr,
101 struct player *receiver);
102
103static void send_player_remove_info_c(const struct player_slot *pslot,
104 struct conn_list *dest);
105static void send_player_info_c_real(struct player *src,
106 struct conn_list *dest);
107static void send_player_diplstate_c_real(struct player *src,
108 struct conn_list *dest);
109
110static void send_nation_availability_real(struct conn_list *dest,
111 bool nationset_change);
112
113/* Used by shuffle_players() and shuffled_player(). */
115
116/* Used by player_info_freeze() and player_info_thaw(). */
118
119/**********************************************************************/
125void kill_player(struct player *pplayer)
126{
127 bool save_palace;
128 struct player *barbarians = nullptr;
129
130 pplayer->is_alive = FALSE;
131
132 /* Reset player status */
133 player_status_reset(pplayer);
134
135 /* Remove shared vision from dead player to friends. */
137 if (gives_shared_vision(pplayer, aplayer)) {
139 }
141
142 cancel_all_meetings(pplayer);
143
144 /* Show entire map for players who are *not* in a team if revealmap is set
145 * to REVEAL_MAP_DEAD. */
147 bool someone_alive = FALSE;
148
150 if (pteam_member->is_alive) {
152 break;
153 }
155
156 if (!someone_alive) {
160 }
161 }
162
163 if (!is_barbarian(pplayer)) {
164 notify_player(nullptr, nullptr, E_DESTROYED, ftc_server,
165 _("The %s are no more!"),
166 nation_plural_for_player(pplayer));
167 }
168
169 /* Transfer back all cities not originally owned by player to their
170 rightful owners, if they are still around */
172 game.server.savepalace = FALSE; /* Moving it around is dumb */
174 if (pcity->original != pplayer && pcity->original != nullptr
175 && pcity->original->is_alive) {
176 /* Transfer city to original owner, kill all its units outside of
177 a radius of 3, give verbose messages of every unit transferred,
178 and raze buildings according to raze chance (also removes palace) */
179 if (transfer_city(pcity->original, pcity, 3, TRUE, TRUE, TRUE,
180 TRUE)) {
181 script_server_signal_emit("city_transferred", pcity, pplayer,
182 pcity->original, "death-back_to_original");
183 }
184 }
187
188 /* Let there be civil war */
190 if (city_list_size(pplayer->cities) >= 2 + MIN(GAME_MIN_CIVILWARSIZE, 2)) {
191 log_verbose("Civil war strikes the remaining empire of %s",
192 pplayer->name);
193 /* Out of sheer cruelty we reanimate the player
194 * so they can behold what happens to their empire */
195 pplayer->is_alive = TRUE;
196 (void) civil_war(pplayer);
197 } else {
198 log_verbose("The empire of %s is too small for civil war.",
199 pplayer->name);
200 }
201 }
202 pplayer->is_alive = FALSE;
203
205 /* If parameter, create a barbarian, if possible */
207 }
208
209 /* if there are barbarians around, they will take the remaining cities */
210 /* vae victis! */
211 if (barbarians) {
212 /* Moving victim's palace around is a waste of time, as they're dead */
214
216
217 log_verbose("Barbarians take the empire of %s", pplayer->name);
219
220 /* Transfer any remaining cities */
223 FALSE)) {
224 script_server_signal_emit("city_transferred", pcity, pplayer,
225 barbarians, "death-barbarians_get");
226 }
228
230
232
233 /* Barbarians don't get free buildings like Palaces, so we don't
234 * call city_build_free_buildings().
235 * FIXME: maybe this should be a ruleset option? */
236 } else {
237 /* Destroy any remaining cities */
238 city_list_iterate(pplayer->cities, pcity) {
241 }
242
243 /* Remove all units that are still ours */
247
248 /* Remove ownership of tiles */
249 whole_map_iterate(&(wld.map), ptile) {
250 if (tile_owner(ptile) == pplayer) {
251 map_claim_ownership(ptile, nullptr, nullptr, FALSE);
252 }
253 if (extra_owner(ptile) == pplayer) {
254 ptile->extras_owner = nullptr;
255 }
257
258 /* Ensure this dead player doesn't win with a spaceship.
259 * Now that would be truly unbelievably dumb - Per */
260 spaceship_init(&pplayer->spaceship);
261 send_spaceship_info(pplayer, nullptr);
262
264}
265
266/**********************************************************************/
269static int get_player_maxrate(struct player *pplayer)
270{
271 int maxrate = get_player_bonus(pplayer, EFT_MAX_RATES);
272
273 if (maxrate == 0) {
274 return 100; /* effects not initialized yet */
275 }
276
277 /* 34 + 33 + 33 = 100 */
278 return CLIP(34, maxrate, 100);
279}
280
281/**********************************************************************/
285void handle_player_rates(struct player *pplayer,
286 int tax, int luxury, int science)
287{
288 int maxrate;
289
290 if (S_S_RUNNING != server_state()) {
291 log_error("received player_rates packet from %s before start",
292 player_name(pplayer));
293 notify_player(pplayer, nullptr, E_BAD_COMMAND, ftc_server,
294 _("Cannot change rates before game start."));
295 return;
296 }
297
298 if (tax + luxury + science != 100) {
299 return;
300 }
301 if (tax < 0 || tax > 100 || luxury < 0 || luxury > 100 || science < 0
302 || science > 100) {
303 return;
304 }
305 maxrate = get_player_maxrate(pplayer);
306 if (tax > maxrate || luxury > maxrate || science > maxrate) {
307 const char *rtype;
308
309 if (tax > maxrate) {
310 rtype = _("Tax");
311 } else if (luxury > maxrate) {
312 rtype = _("Luxury");
313 } else {
314 rtype = _("Science");
315 }
316
317 notify_player(pplayer, nullptr, E_BAD_COMMAND, ftc_server,
318 _("%s rate exceeds the max rate for %s."),
319 rtype,
321 } else {
322 pplayer->economic.tax = tax;
323 pplayer->economic.luxury = luxury;
324 pplayer->economic.science = science;
325
327 send_player_info_c(pplayer, pplayer->connections);
328 }
329}
330
331/**********************************************************************/
336void government_change(struct player *pplayer, struct government *gov,
338{
339 struct research *presearch;
340
344 && nullptr != pplayer->target_government);
346
347 gov->changed_to_times++;
348 }
349
350 pplayer->government = gov;
351 pplayer->target_government = nullptr;
352
354 log_debug("Revolution finished for %s. Government is %s. "
355 "Revofin %d (%d).", player_name(pplayer),
358 }
359
360 notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_server,
361 _("%s now governs the %s as a %s."),
362 player_name(pplayer),
365
366 if (is_human(pplayer)) {
367 /* Keep luxuries if we have any. Try to max out science. -GJW */
368 int max = get_player_maxrate(pplayer);
369
370 /* Only change rates if one exceeds the maximal rate */
371 if (pplayer->economic.science > max || pplayer->economic.tax > max
372 || pplayer->economic.luxury > max) {
373 int save_science = pplayer->economic.science;
374 int save_tax = pplayer->economic.tax;
375 int save_luxury = pplayer->economic.luxury;
376
377 pplayer->economic.science = MIN(100 - pplayer->economic.luxury, max);
378 pplayer->economic.tax = MIN(100 - pplayer->economic.luxury
379 - pplayer->economic.science, max);
380 pplayer->economic.luxury = 100 - pplayer->economic.science
381 - pplayer->economic.tax;
382
383 notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_server,
384 _("The tax rates for the %s are changed from "
385 "%3d%%/%3d%%/%3d%% (tax/luxury/science) to "
386 "%3d%%/%3d%%/%3d%%."),
389 pplayer->economic.tax, pplayer->economic.luxury,
390 pplayer->economic.science);
391 }
392 }
393
394 check_player_max_rates(pplayer);
396 send_player_info_c(pplayer, pplayer->connections);
397
398 presearch = research_get(pplayer);
401}
402
403/**********************************************************************/
411{
412 int ransom = fc_rand(1 + pvictim->economic.gold);
413 int n = 1 + fc_rand(3);
414
415 /* Give map */
419 _("You looted parts of %s map!"),
421 }
422
423 log_debug("victim has money: %d", pvictim->economic.gold);
424
425 if (ransom > 0) {
428 PL_("You loot %d gold!", "You loot %d gold!", ransom),
429 ransom);
430 }
431 pvictor->economic.gold += ransom;
432 pvictim->economic.gold -= ransom;
433
434 while (n > 0) {
436
437 /* steal_a_tech() handles also notifying of the player */
439
440 if (ttid == A_NONE) {
441 log_debug("Worthless enemy doesn't have more techs to steal.");
442 break;
443 } else {
444 log_debug("Pressed tech %s from captured enemy",
446 if (!fc_rand(3)) {
447 break; /* Out of luck */
448 }
449 n--;
450 }
451 }
452
453 {
454 /* Try to submit some cities */
455 int vcsize = city_list_size(pvictim->cities);
456 int evcsize = vcsize;
457 int conqsize;
458
459 if (evcsize < 3) {
460 evcsize = 0;
461 } else {
462 evcsize -=3;
463 }
464
465 /* About a quarter on average with high numbers less probable */
467
468 log_debug("conqsize=%d", conqsize);
469
470 if (conqsize > 0) {
472 bool submit = FALSE;
473
474 game.server.savepalace = FALSE; /* Moving it around is dumb */
475
477 /* Kindly ask the citizens to submit */
478 if (fc_rand(vcsize) < conqsize) {
479 submit = TRUE;
480 }
481 vcsize--;
482 if (submit) {
483 conqsize--;
484 /* Transfer city to the victorious player
485 * kill all its units outside of a radius of 7,
486 * give verbose messages of every unit transferred,
487 * and raze buildings according to raze chance
488 * (also removes palace) */
491 /* TRANS: Getting a city as loot */
492 _("You conquer %s as loot!"),
494
497 submit = FALSE;
498 }
499 if (conqsize <= 0) {
500 break;
501 }
504 }
505 }
506}
507
508/**********************************************************************/
516 struct government *gov)
517{
518 int max_turns;
519 int change_speed;
520
521 switch (rltype) {
522 case REVOLEN_FIXED:
524 case REVOLEN_RANDOM:
528 /* If everyone changes to this government once, the last 50% of players doing so
529 * will get the minimum time (1 turn) */
530 change_speed = (player_count() / 2)
532 /* It never takes zero players to make revlen shorter */
535 max_turns = MAX(1, max_turns);
537 return fc_rand(max_turns) + 1;
538 }
539 return max_turns;
540 }
541
543
545}
546
547/**********************************************************************/
550int revolution_length(struct government *gov, struct player *plr)
551{
554 /* Targetless revolution not acceptable */
556 _("You can't revolt without selecting target government."));
557 return -1;
558 }
559
561}
562
563/**********************************************************************/
568{
569 int turns;
571 bool anarchy;
572
573 if (!gov || !can_change_to_government(pplayer, gov)) {
574 return;
575 }
576
577 log_debug("Government changed for %s. Target government is %s; "
578 "old %s. Revofin %d, Turn %d.", player_name(pplayer),
582
583 anarchy = get_player_bonus(pplayer, EFT_NO_ANARCHY) <= 0;
584
585 /* Set revolution_finishes value. */
586 if (pplayer->revolution_finishes > 0) {
587 /* Player already has an active revolution. Note that the finish time
588 * may be in the future (we're waiting for it to finish), the current
589 * turn (it just finished - but isn't reset until the end of the turn)
590 * or even in the past (if the player is in anarchy and hasn't chosen
591 * a government). */
592 turns = pplayer->revolution_finishes - game.info.turn;
593 } else if ((is_ai(pplayer) && !has_handicap(pplayer, H_REVOLUTION))
594 || !anarchy) {
595 /* AI players without the H_REVOLUTION handicap can skip anarchy */
596 anarchy = FALSE;
597 turns = 0;
598 } else {
599 turns = revolution_length(gov, pplayer);
600 if (turns < 0) {
601 return;
602 }
603 }
604
605 if (anarchy && turns <= 0
607 /* Multiple changes attempted after single anarchy period */
610 notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_server,
611 _("You can't revolt the same turn you finished previous revolution."));
612 return;
613 }
614 }
615
617 pplayer->target_government = gov;
618 pplayer->revolution_finishes = game.info.turn + turns;
619
620 log_debug("Revolution started for %s. Target government is %s. "
621 "Revofin %d (%d).", player_name(pplayer),
624
625 CALL_PLR_AI_FUNC(revolution_start, pplayer, pplayer);
626
627 /* Now see if the revolution is instantaneous. */
628 if (turns <= 0
630 notify_player(pplayer, nullptr, E_REVOLT_START, ftc_server,
631 /* TRANS: Switching to a new form of government */
632 _("The %s will switch to %s in the end of "
633 "the player phase."),
636 return;
637 } else if (turns > 0) {
638 notify_player(pplayer, nullptr, E_REVOLT_START, ftc_server,
639 /* TRANS: This is a message event so don't make it
640 * too long. */
641 PL_("The %s have incited a revolt! "
642 "%d turn of anarchy will ensue! "
643 "Target government is %s.",
644 "The %s have incited a revolt! "
645 "%d turns of anarchy will ensue! "
646 "Target government is %s.",
647 turns),
649 turns,
651 } else {
653
654 notify_player(pplayer, nullptr, E_REVOLT_START, ftc_server,
655 _("Revolution: returning to anarchy."));
656 }
657
658 check_player_max_rates(pplayer);
660 send_player_info_c(pplayer, pplayer->connections);
661
662 log_debug("Government change complete for %s. Target government is %s; "
663 "now %s. Turn %d; revofin %d.", player_name(pplayer),
667}
668
669/**********************************************************************/
673void update_revolution(struct player *pplayer)
674{
675 struct government *current_gov;
676
677 /* The player's revolution counter is stored in the revolution_finishes
678 * field. This value has the following meanings:
679 * - If negative (-1), then the player is not in a revolution. In this
680 * case the player should never be in anarchy.
681 * - If positive, the player is in the middle of a revolution. In this
682 * case the value indicates the turn in which the revolution finishes.
683 * * If this value is > than the current turn, then the revolution is
684 * in progress. In this case the player should always be in anarchy.
685 * * If the value is == to the current turn, then the revolution is
686 * finished. The player may now choose a government. However the
687 * value isn't reset until the end of the turn. If the player has
688 * chosen a government by the end of the turn, then the revolution is
689 * over and the value is reset to -1.
690 * * If the player doesn't pick a government then the revolution
691 * continues. At this point the value is <= to the current turn,
692 * and the player can leave the revolution at any time. The value
693 * is reset at the end of any turn when a non-anarchy government is
694 * chosen.
695 */
696 log_debug("Update revolution for %s. Current government %s, "
697 "target %s, revofin %d, turn %d.", player_name(pplayer),
699 pplayer->target_government
700 ? government_rule_name(pplayer->target_government) : "(none)",
702
704
706 && pplayer->revolution_finishes <= game.info.turn) {
708 /* If the revolution is over and a target government is set, go into
709 * the new government. */
710 log_debug("Update: finishing revolution for %s.", player_name(pplayer));
711 government_change(pplayer, pplayer->target_government, TRUE);
712 } else {
713 /* If the revolution is over but there's no target government set,
714 * alert the player. */
715 notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_any,
716 _("You should choose a new government from the "
717 "government menu."));
718 }
720 && pplayer->revolution_finishes < game.info.turn) {
721 /* Reset the revolution counter. If the player has another revolution
722 * they'll have to re-enter anarchy. */
723 log_debug("Update: resetting revofin for %s.", player_name(pplayer));
724 pplayer->revolution_finishes = -1;
725 send_player_info_c(pplayer, pplayer->connections);
726 }
727}
728
729/**********************************************************************/
732void update_capital(struct player *pplayer)
733{
734 int max_value = 0;
735 struct city *primary_capital = nullptr;
736 int same_value_count = 0;
737
738 city_list_iterate(pplayer->cities, pcity) {
740
741 if (value > max_value) {
742 max_value = value;
745 /* Mark it at least some kind of capital, might turn to named capital
746 * after all have been processed. */
747 pcity->capital = CAPITAL_SECONDARY;
748 } else if (value > 0) {
749 /* Mark it at least some kind of capital. */
750 pcity->capital = CAPITAL_SECONDARY;
751 if (value == max_value) {
754 if (fc_rand(same_value_count) == 1) {
756 }
757 }
758 } else {
759 /* Not capital at all */
760 pcity->capital = CAPITAL_NOT;
761 }
763
764 if (primary_capital != nullptr) {
766 pplayer->primary_capital_id = primary_capital->id;
767 } else {
768 pplayer->primary_capital_id = 0;
769 }
770}
771
772/**********************************************************************/
777void check_player_max_rates(struct player *pplayer)
778{
779 struct player_economic old_econ = pplayer->economic;
780
782 if (old_econ.tax > pplayer->economic.tax) {
783 notify_player(pplayer, nullptr, E_NEW_GOVERNMENT, ftc_server,
784 _("Tax rate exceeded the max rate; adjusted."));
785 }
786 if (old_econ.science > pplayer->economic.science) {
787 notify_player(pplayer, nullptr, E_NEW_GOVERNMENT, ftc_server,
788 _("Science rate exceeded the max rate; adjusted."));
789 }
790 if (old_econ.luxury > pplayer->economic.luxury) {
791 notify_player(pplayer, nullptr, E_NEW_GOVERNMENT, ftc_server,
792 _("Luxury rate exceeded the max rate; adjusted."));
793 }
794}
795
796/**********************************************************************/
806 struct player *pplayer2,
807 const struct unit_list
809 const struct unit_list
811{
812 /* The client needs updated diplomatic state, because it is used
813 * during calculation of new states of occupied flags in cities */
814 send_player_all_c(pplayer, nullptr);
815 send_player_all_c(pplayer2, nullptr);
819}
820
821/**********************************************************************/
824static void maybe_claim_base(struct tile *ptile, struct player *new_owner,
825 struct player *old_owner)
826{
827 bool claim = FALSE;
828
829 unit_list_iterate(ptile->units, punit) {
832 claim = TRUE;
833 break;
834 }
836
837 if (claim) {
839 map_claim_base(ptile, pextra, new_owner, old_owner);
841
842 ptile->extras_owner = new_owner;
843 }
844}
845
846/**********************************************************************/
849void enter_war(struct player *pplayer, struct player *pplayer2)
850{
851 /* Claim bases where units are already standing */
852 whole_map_iterate(&(wld.map), ptile) {
853 struct player *old_owner = extra_owner(ptile);
854
855 if (old_owner == pplayer2) {
856 maybe_claim_base(ptile, pplayer, old_owner);
857 } else if (old_owner == pplayer) {
859 }
861}
862
863/**********************************************************************/
867{
868 pplayer->last_war_action = game.info.turn;
869 send_player_info_c(pplayer, nullptr);
870}
871
872/**********************************************************************/
884 int other_player_id,
885 enum clause_type clause)
886{
890 bool repeat = FALSE;
891 struct player *pplayer2 = player_by_number(other_player_id);
893 struct unit_list *pplayer_seen_units, *pplayer2_seen_units;
894
895 if (nullptr == pplayer2 || players_on_same_team(pplayer, pplayer2)) {
896 return;
897 }
898
900
901 if (clause == CLAUSE_VISION) {
902 if (!gives_shared_vision(pplayer, pplayer2)) {
903 return;
904 }
907 _("%s no longer gives us shared vision!"),
908 player_name(pplayer));
909 return;
910 }
911
912 if (clause == CLAUSE_SHARED_TILES) {
913 if (!gives_shared_tiles(pplayer, pplayer2)) {
914 return;
915 }
917 whole_map_iterate(&(wld.map), ptile) {
918 if (tile_owner(ptile) == pplayer && ptile->worked != nullptr
919 && city_owner(ptile->worked) == pplayer2) {
920 struct city *pcity = ptile->worked;
921
923 pcity->specialists[DEFAULT_SPECIALIST]++;
924 }
927 _("%s no longer shares tiles with us!"),
928 player_name(pplayer));
929 return;
930 }
931
933
934 /* The senate may not allow you to break the treaty. In this case you
935 * must first dissolve the senate then you can break it. */
937 notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
938 _("The senate will not allow you to break treaty "
939 "with the %s. You must either dissolve the senate "
940 "or wait until a more timely moment."),
942 return;
943 }
944
945 if (diplcheck != DIPL_OK) {
946 return;
947 }
948
949 reject_all_treaties(pplayer);
951 /* Else, breaking a treaty */
952
953 /* Check what the new status will be */
955
956 if (new_type == old_type) {
957 /* No change */
958 return;
959 }
960
963
964 if (old_type == DS_ALLIANCE) {
967 } else {
968 pplayer_seen_units = nullptr;
969 pplayer2_seen_units = nullptr;
970 }
971
972 /* Do the change */
973 ds_plrplr2->type = ds_plr2plr->type = new_type;
974 ds_plrplr2->turns_left = ds_plr2plr->turns_left = 16;
975
976 if (new_type == DS_WAR) {
979 }
980
981 /* If the old state was alliance, the players' units can share tiles
982 illegally, and we need to call resolve_unit_stacks() */
983 if (old_type == DS_ALLIANCE) {
984
985 fc_assert(pplayer_seen_units != nullptr);
986 fc_assert(pplayer2_seen_units != nullptr);
987
993 }
994
995 /* If there's a reason to cancel the pact, do it without penalty */
996 /* FIXME: in the current implementation if you break more than one
997 * treaty simultaneously it may success partially: the first treaty-breaking
998 * will happen but the second one will fail. */
999 if (get_player_bonus(pplayer, EFT_HAS_SENATE) > 0 && !repeat) {
1000 if (ds_plrplr2->has_reason_to_cancel > 0) {
1001 notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
1002 _("The senate passes your bill because of the "
1003 "constant provocations of the %s."),
1005 } else if (new_type == DS_WAR) {
1006 notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
1007 _("The senate refuses to break treaty with the %s, "
1008 "but you have no trouble finding a new senate."),
1010 }
1011 }
1012 if (new_type == DS_WAR) {
1014
1015 enter_war(pplayer, pplayer2);
1016 }
1017 ds_plrplr2->has_reason_to_cancel = 0;
1018
1019 send_player_all_c(pplayer, nullptr);
1020 send_player_all_c(pplayer2, nullptr);
1021
1022 /*
1023 * Refresh all cities which have a unit of the other side within
1024 * city range.
1025 */
1028 sync_cities();
1029
1030 notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
1031 _("The diplomatic state between the %s "
1032 "and the %s is now %s."),
1033 nation_plural_for_player(pplayer),
1037 _(" %s canceled the diplomatic agreement! "
1038 "The diplomatic state between the %s and the %s "
1039 "is now %s."),
1040 player_name(pplayer),
1042 nation_plural_for_player(pplayer),
1044
1045 /* Check fall-out of a war declaration. */
1047 if (other != pplayer && other != pplayer2
1049 && pplayers_allied(pplayer, other)) {
1050 if (!players_on_same_team(pplayer, other)) {
1051 /* If an ally declares war on another ally, break off your alliance
1052 * to the aggressor. This prevents in-alliance wars, which are not
1053 * permitted. */
1055 _("%s has attacked your ally %s! "
1056 "You cancel your alliance to the aggressor."),
1057 player_name(pplayer),
1063 } else {
1064 /* We are in the same team as the aggressor; we cannot break
1065 * alliance with them. We trust our team mate and break alliance
1066 * with the attacked player */
1068 _("Your team mate %s declared war on %s. "
1069 "You are obligated to cancel alliance with %s."),
1070 player_name(pplayer),
1074 }
1075 }
1077}
1078
1079/**********************************************************************/
1082static void send_player_remove_info_c(const struct player_slot *pslot,
1083 struct conn_list *dest)
1084{
1085 if (!dest) {
1086 dest = game.est_connections;
1087 }
1088
1090
1091 conn_list_iterate(dest, pconn) {
1094}
1095
1096/**********************************************************************/
1103{
1105}
1106
1107/**********************************************************************/
1112{
1113 if (0 == --player_info_frozen_level) {
1115 send_player_info_c(nullptr, nullptr);
1116 }
1117
1119}
1120
1121/**********************************************************************/
1132void send_player_all_c(struct player *src, struct conn_list *dest)
1133{
1134 send_player_info_c(src, dest);
1135 send_player_diplstate_c(src, dest);
1136}
1137
1138/**********************************************************************/
1149void send_player_info_c(struct player *src, struct conn_list *dest)
1150{
1151 if (0 < player_info_frozen_level) {
1152 return; /* Discard, see comment for player_info_freeze(). */
1153 }
1154
1155 if (src != nullptr) {
1156 send_player_info_c_real(src, dest);
1157 return;
1158 }
1159
1160 players_iterate(pplayer) {
1161 send_player_info_c_real(pplayer, dest);
1163}
1164
1165/**********************************************************************/
1169static void send_player_info_c_real(struct player *src,
1170 struct conn_list *dest)
1171{
1172 struct packet_player_info info;
1175
1176 fc_assert_ret(src != nullptr);
1177
1178 if (!dest) {
1179 dest = game.est_connections;
1180 }
1181
1182 if (any_web_conns()) {
1183 webp_ptr = &web_info;
1184 } else {
1185 webp_ptr = nullptr;
1186 }
1187
1188 package_player_common(src, &info, webp_ptr);
1189
1190 conn_list_iterate(dest, pconn) {
1191 if (nullptr == pconn->playing && pconn->observer) {
1192 /* Global observer. */
1193 package_player_info(src, &info, webp_ptr, pconn->playing, INFO_FULL);
1194 } else if (nullptr != pconn->playing) {
1195 /* Players (including regular observers) */
1196 package_player_info(src, &info, webp_ptr,
1197 pconn->playing, INFO_MINIMUM);
1198 } else {
1199 package_player_info(src, &info, webp_ptr, nullptr, INFO_MINIMUM);
1200 }
1204}
1205
1206/**********************************************************************/
1215void send_player_diplstate_c(struct player *src, struct conn_list *dest)
1216{
1217 if (src != nullptr) {
1219 return;
1220 }
1221
1222 players_iterate(pplayer) {
1223 send_player_diplstate_c_real(pplayer, dest);
1225}
1226
1227/**********************************************************************/
1231static void send_player_diplstate_c_real(struct player *plr1,
1232 struct conn_list *dest)
1233{
1234 fc_assert_ret(plr1 != nullptr);
1235
1236 if (!dest) {
1237 dest = game.est_connections;
1238 }
1239
1240 conn_list_iterate(dest, pconn) {
1241 players_iterate(plr2) {
1243
1244 if (nullptr == pconn->playing && pconn->observer) {
1245 /* Global observer. */
1247 INFO_FULL);
1248 } else if (nullptr != pconn->playing) {
1249 /* Players (including regular observers) */
1251 INFO_MINIMUM);
1252 } else {
1254 INFO_MINIMUM);
1255 }
1259}
1260
1261/**********************************************************************/
1264static void package_player_common(struct player *plr,
1265 struct packet_player_info *packet,
1267 web_packet)
1268{
1269 int i;
1270 struct music_style *music;
1271
1272 packet->playerno = player_number(plr);
1273 sz_strlcpy(packet->name, player_name(plr));
1274 sz_strlcpy(packet->username, plr->username);
1275 packet->unassigned_user = plr->unassigned_user;
1276 packet->nation = plr->nation ? nation_number(plr->nation) : NATION_NONE;
1277 packet->is_male = plr->is_male;
1278 packet->team = plr->team ? team_number(plr->team) : team_count();
1279 packet->is_ready = plr->is_ready;
1280 packet->was_created = plr->was_created;
1281 packet->style = plr->style ? style_number(plr->style) : 0;
1282
1283 /* I think we could safely move the music style selection to
1284 * client side to not have it burden server side. Client could
1285 * actually avoid it completely when music disabled from the client options.
1286 * Client has no use for music styles of other players, and there should
1287 * be no such information about the player themself needed to determine
1288 * the music style that client does not know. */
1290 if (music != nullptr) {
1292 } else {
1293 packet->music_style = -1; /* No music style available */
1294 }
1295
1296 packet->is_alive = plr->is_alive;
1297 packet->turns_alive = plr->turns_alive;
1298 packet->is_connected = plr->is_connected;
1299 packet->flags = plr->flags;
1300 packet->ai_skill_level = is_ai(plr)
1301 ? plr->ai_common.skill_level : 0;
1302 for (i = 0; i < player_slot_count(); i++) {
1303 packet->love[i] = plr->ai_common.love[i];
1304 }
1306
1307 packet->phase_done = plr->phase_done;
1308 packet->nturns_idle = plr->nturns_idle;
1309 packet->science_cost = plr->ai_common.science_cost;
1310
1311#ifdef FREECIV_WEB
1312 if (web_packet != nullptr) {
1313 web_packet->playerno = player_number(plr);
1314 }
1315#endif /* FREECIV_WEB */
1316}
1317
1318/**********************************************************************/
1327static void package_player_info(struct player *plr,
1328 struct packet_player_info *packet,
1330 web_packet,
1331 struct player *receiver,
1333{
1336 struct government *pgov = nullptr;
1338
1339 if (receiver) {
1340 info_level = player_info_level(plr, receiver);
1342 } else {
1344 }
1345
1346 /* Multipliers */
1347 packet->multip_count = multiplier_count();
1348 if (info_level >= INFO_FULL) {
1349 multipliers_iterate(pmul) {
1350 int idx = multiplier_index(pmul);
1351
1352 packet->multiplier[idx] = plr->multipliers[idx].value;
1353 packet->multiplier_target[idx] = plr->multipliers[idx].target;
1354 packet->multiplier_changed[idx] = plr->multipliers[idx].changed;
1356 } else {
1357 multipliers_iterate(pmul) {
1358 int idx = multiplier_index(pmul);
1359
1360 packet->multiplier[idx] = 0;
1361 packet->multiplier_target[idx] = 0;
1362 packet->multiplier_changed[idx] = 0;
1364 }
1365
1366 /* We need to send all tech info for all players on the same
1367 * team, even if they are not in contact yet; otherwise we will
1368 * overwrite team research or confuse the client. */
1371 if (players_on_same_team(plr, aplayer) && receiver) {
1373 player_info_level(aplayer, receiver));
1374 }
1376
1377 if (plr->rgb != nullptr) {
1378 packet->color_valid = TRUE;
1379 packet->color_red = plr->rgb->r;
1380 packet->color_green = plr->rgb->g;
1381 packet->color_blue = plr->rgb->b;
1382 } else {
1383 /* In pregame, send the color we expect to use, for consistency with
1384 * '/list colors' etc. */
1385 const struct rgbcolor *preferred = player_preferred_color(plr);
1386
1387 if (preferred != nullptr) {
1388 packet->color_valid = TRUE;
1389 packet->color_red = preferred->r;
1390 packet->color_green = preferred->g;
1391 packet->color_blue = preferred->b;
1392 } else {
1393 fc_assert(game.info.turn < 1); /* Game has not yet started */
1394 packet->color_valid = FALSE;
1395 /* Client shouldn't use these dummy values */
1396 packet->color_red = 0;
1397 packet->color_green = 0;
1398 packet->color_blue = 0;
1399 }
1400 }
1401 packet->color_changeable = player_color_changeable(plr, nullptr);
1402
1403 /* Only send score if we have contact */
1404 if (info_level >= INFO_MEETING) {
1405 packet->score = plr->score.game;
1406 } else {
1407 packet->score = -1;
1408 }
1409
1410 packet->autoselect_weight = plr->autoselect_weight;
1411
1412 if (info_level >= INFO_MEETING) {
1413 packet->gold = plr->economic.gold;
1415 } else {
1416 packet->gold = 0;
1417 pgov = NULL;
1418 }
1420
1421 /* Send diplomatic status of the player to everyone they are in
1422 * contact with. */
1424 || (receiver
1425 && player_diplstate_get(receiver, plr)->contact_turns_left > 0)) {
1428 : government_count();
1429 packet->real_embassy = plr->real_embassy;
1432 } else {
1433 packet->target_government = packet->government;
1434 BV_CLR_ALL(packet->real_embassy);
1437
1438 if (receiver != nullptr) {
1439 int ridx = player_index(receiver);
1440
1441 if (player_has_real_embassy(plr, receiver)) {
1442 BV_SET(packet->real_embassy, ridx);
1443 }
1444
1445 if (gives_shared_vision(plr, receiver)) {
1447 }
1448
1449 if (gives_shared_tiles(plr, receiver)) {
1450 BV_SET(packet->gives_shared_tiles, ridx);
1451 }
1452 }
1453 }
1454
1455 /* Make absolutely sure - in case you lose your embassy! */
1457 || (receiver
1458 && player_diplstate_get(plr, receiver)->type == DS_TEAM)) {
1459 packet->tech_upkeep = player_tech_upkeep(plr);
1460 } else {
1461 packet->tech_upkeep = 0;
1462 }
1463
1464 /* Send most civ info about the player only to players who have an
1465 * embassy. */
1467 packet->tax = plr->economic.tax;
1468 packet->science = plr->economic.science;
1469 packet->luxury = plr->economic.luxury;
1471 packet->culture = player_culture(plr);
1472 } else {
1473 packet->tax = 0;
1474 packet->science = 0;
1475 packet->luxury = 0;
1476 packet->revolution_finishes = -1;
1477 packet->culture = 0;
1478 }
1479
1480 if (info_level >= INFO_FULL
1481 || (receiver
1482 && player_diplstate_get(plr, receiver)->type == DS_TEAM)) {
1483 packet->mood = player_mood(plr);
1484 } else {
1485 packet->mood = MOOD_COUNT;
1486 }
1487
1488 if (info_level >= INFO_FULL) {
1489 packet->history = plr->history;
1490 packet->infrapoints = plr->economic.infra_points;
1491 } else {
1492 packet->history = 0;
1493 packet->infrapoints = 0;
1494 }
1495
1496 for (imp = 0; imp < B_LAST; imp++) {
1497 if (plr->wonders[imp] != WONDER_NOT_BUILT) {
1499 receiver, plr,
1501 packet->wonders[imp] = plr->wonders[imp];
1502 } else {
1503 packet->wonders[imp] = WONDER_NOT_BUILT;
1504 }
1505 } else {
1506 packet->wonders[imp] = WONDER_NOT_BUILT;
1507 }
1508 }
1509
1510#ifdef FREECIV_WEB
1511 if (web_packet != nullptr) {
1512 if (info_level >= INFO_FULL) {
1513 web_packet->expected_income = player_get_expected_income(plr);
1514 } else {
1515 web_packet->expected_income = 0;
1516 }
1517 }
1518#endif /* FREECIV_WEB */
1519}
1520
1521/**********************************************************************/
1530static void package_player_diplstate(struct player *plr1,
1531 struct player *plr2,
1533 struct player *receiver,
1535{
1537 struct player_diplstate *ds = player_diplstate_get(plr1, plr2);
1538
1539 if (receiver) {
1540 info_level = player_info_level(plr1, receiver);
1542 } else {
1544 }
1545
1546 packet_ds->plr1 = player_index(plr1);
1547 packet_ds->plr2 = player_index(plr2);
1548 /* A unique id for each combination is calculated here. */
1549 packet_ds->diplstate_id = packet_ds->plr1 * MAX_NUM_PLAYER_SLOTS
1550 + packet_ds->plr2;
1551
1552 /* Send diplomatic status of the player to everyone they are in
1553 * contact with (embassy, remaining contact turns, the receiver). */
1555 || (receiver
1556 && player_diplstate_get(receiver, plr1)->contact_turns_left > 0)
1557 || (receiver && receiver == plr2)) {
1558 packet_ds->type = ds->type;
1559 packet_ds->turns_left = ds->turns_left;
1560 packet_ds->has_reason_to_cancel = ds->has_reason_to_cancel;
1561 packet_ds->contact_turns_left = ds->contact_turns_left;
1562 } else {
1563 packet_ds->type = DS_WAR;
1564 packet_ds->turns_left = 0;
1565 packet_ds->has_reason_to_cancel = 0;
1566 packet_ds->contact_turns_left = 0;
1567 }
1568}
1569
1570/**********************************************************************/
1574 struct player *receiver)
1575{
1576 if (S_S_RUNNING > server_state()) {
1577 return INFO_MINIMUM;
1578 }
1579 if (plr == receiver) {
1580 return INFO_FULL;
1581 }
1582 if (receiver && team_has_embassy(receiver->team, plr)) {
1583 return INFO_EMBASSY;
1584 }
1585 if (receiver && could_intel_with_player(receiver, plr)) {
1586 return INFO_MEETING;
1587 }
1588
1589 return INFO_MINIMUM;
1590}
1591
1592/**********************************************************************/
1596struct conn_list *player_reply_dest(struct player *pplayer)
1597{
1598 return (pplayer->current_conn ?
1599 pplayer->current_conn->self :
1600 pplayer->connections);
1601}
1602
1603/**********************************************************************/
1606static void call_first_contact(struct player *pplayer, struct player *aplayer)
1607{
1608 CALL_PLR_AI_FUNC(first_contact, pplayer, pplayer, aplayer);
1609}
1610
1611/**********************************************************************/
1621void server_player_init(struct player *pplayer, bool initmap,
1622 bool needs_team)
1623{
1624 player_status_reset(pplayer);
1625
1626 BV_CLR(pplayer->flags, PLRF_FIRST_CITY);
1628 BV_CLR_ALL(pplayer->server.debug);
1629
1630 pplayer->server.border_vision = FALSE;
1631
1632 player_map_free(pplayer);
1633 pplayer->server.private_map = nullptr;
1634
1635 if (initmap) {
1636 player_map_init(pplayer);
1637 }
1638 if (needs_team) {
1639 team_add_player(pplayer, nullptr);
1640 fc_assert(pplayer->team != nullptr);
1641 }
1642
1643 /* This must be done after team information is initialised
1644 * as it might be needed to determine max rate effects.
1645 * Sometimes this server_player_init() gets called twice
1646 * with only latter one having needs_team set. We don't
1647 * want to call player_limit_to_max_rates() at first time
1648 * when team is not yet set. It's callers responsibility
1649 * to always have one server_player_init() call with
1650 * needs_team TRUE. */
1651 if (needs_team) {
1653 }
1654
1655 adv_data_default(pplayer);
1656
1657 /* We don't push this in calc_civ_score(), or it will be reset
1658 * every turn. */
1659 pplayer->score.units_built = 0;
1660 pplayer->score.units_killed = 0;
1661 pplayer->score.units_lost = 0;
1662 pplayer->score.units_used = 0;
1663
1664 /* No delegation. */
1665 pplayer->server.delegate_to[0] = '\0';
1666 pplayer->server.orig_username[0] = '\0';
1667
1668 handicaps_init(pplayer);
1669}
1670
1671/**********************************************************************/
1676const struct rgbcolor *player_preferred_color(struct player *pplayer)
1677{
1678 if (pplayer->rgb) {
1679 return pplayer->rgb;
1680 } else if (playercolor_count() == 0) {
1681 /* If a ruleset isn't loaded, there are no colors to choose from. */
1682 return nullptr;
1684 if (pplayer->nation != NO_NATION_SELECTED) {
1685 return nation_color(nation_of_player(pplayer)); /* May be nullptr */
1686 } else {
1687 return nullptr; /* Don't know nation, hence don't know color */
1688 }
1689 } else {
1690 /* Modes indexing into game-defined player colors */
1691 int colorid;
1692
1693 switch (game.server.plrcolormode) {
1694 case PLRCOL_PLR_SET: /* Player color (set) */
1695 case PLRCOL_PLR_RANDOM: /* Player color (random) */
1696 /* These depend on other players and will be assigned at game start. */
1697 return nullptr;
1698 default:
1699 log_error("Invalid value for 'game.server.plrcolormode' (%d)!",
1701 fc__fallthrough; /* No break - using 'PLRCOL_PLR_ORDER' as fallback */
1702 case PLRCOL_PLR_ORDER: /* Player color (ordered) */
1704 break;
1705 case PLRCOL_TEAM_ORDER: /* Team color (ordered) */
1706 colorid = team_number(pplayer->team) % playercolor_count();
1707 break;
1708 }
1709
1710 return playercolor_get(colorid);
1711 }
1712}
1713
1714/**********************************************************************/
1719bool player_color_changeable(const struct player *pplayer, const char **reason)
1720{
1722 if (reason) {
1723 *reason = _("Can only set player color prior to game start if "
1724 "'plrcolormode' is PLR_SET.");
1725 }
1726 return FALSE;
1727 }
1728
1729 return TRUE;
1730}
1731
1732/**********************************************************************/
1738{
1741 int needed = player_count();
1742
1743 players_iterate(pplayer) {
1744 const struct rgbcolor *autocolor;
1745 /* Assign the deterministic colors. */
1746 if (!pplayer->rgb
1747 && (autocolor = player_preferred_color(pplayer))) {
1748 player_set_color(pplayer, autocolor);
1749 }
1750 if (pplayer->rgb) {
1751 /* One fewer random color needed. */
1752 needed--;
1753 /* Try to avoid clashes between explicit and random colors. */
1755 if (rgbcolors_are_equal(pplayer->rgb, prgbcolor)) {
1757 }
1759 }
1761
1762 if (needed == 0) {
1763 /* No random colors needed */
1765 return;
1766 }
1767
1769 /* Additionally, try to avoid color clashes with certain nations not
1770 * yet in play (barbarians). */
1771 allowed_nations_iterate(pnation) {
1772 const struct rgbcolor *ncol = nation_color(pnation);
1773 if (ncol && nation_barbarian_type(pnation) != NOT_A_BARBARIAN) {
1774 /* Don't use this color. */
1778 }
1780 }
1782 }
1783
1787
1788 if (needed > rgbcolor_list_size(spare_colors)) {
1789 log_verbose("Not enough unique colors for all players; there will be "
1790 "duplicates");
1791 /* Fallback: start again from full set of ruleset colors.
1792 * No longer attempt to avoid clashes with explicitly assigned colors. */
1795 }
1796 /* We may still not have enough, if there are more players than
1797 * ruleset-defined colors. If so, top up with duplicates. */
1798 if (needed > rgbcolor_list_size(spare_colors)) {
1800 /* Shuffle so that duplicates aren't biased to start of list */
1802 /* Duplication process avoids one color being hit lots of times */
1803 for (i = origsize; i < needed; i++) {
1806 }
1807 }
1808 /* Shuffle (including mixing any duplicates up) */
1810
1811 /* Finally, assign shuffled colors to players. */
1812 players_iterate(pplayer) {
1813 if (!pplayer->rgb) {
1816 }
1818
1820}
1821
1822/**********************************************************************/
1826void server_player_set_color(struct player *pplayer,
1827 const struct rgbcolor *prgbcolor)
1828{
1829 if (prgbcolor != nullptr) {
1830 player_set_color(pplayer, prgbcolor);
1831 } else {
1832 /* This can legitimately be nullptr in pregame. */
1834 rgbcolor_destroy(pplayer->rgb);
1835 pplayer->rgb = nullptr;
1836 }
1837 /* Update clients */
1838 send_player_info_c(pplayer, nullptr);
1839}
1840
1841/**********************************************************************/
1846const char *player_color_ftstr(struct player *pplayer)
1847{
1848 static char buf[64];
1849 char hex[16];
1850 const struct rgbcolor *prgbcolor;
1851
1852 fc_assert_ret_val(pplayer != nullptr, nullptr);
1853
1854 buf[0] = '\0';
1856 if (prgbcolor != nullptr
1857 && rgbcolor_to_hex(prgbcolor, hex, sizeof(hex))) {
1858 struct ft_color plrcolor = FT_COLOR("#000000", hex);
1859
1862 } else {
1863 cat_snprintf(buf, sizeof(buf), _("no color"));
1864 }
1865
1866 return buf;
1867}
1868
1869/**********************************************************************/
1873void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
1874{
1876 int i;
1877
1878 for (i = 0; i < sucount; i++) {
1879 if (game.server.start_units[i] == 'k') {
1880 /* Every player should have king */
1881 struct unit_type *utype = crole_to_unit_type('k', pplayer);
1882
1883 if (utype != nullptr) {
1884 create_unit(pplayer, ptile, utype, 0, 0, -1);
1885 }
1886 }
1887 }
1888}
1889
1890/**********************************************************************/
1897struct player *server_create_player(int player_id, const char *ai_tname,
1898 struct rgbcolor *prgbcolor,
1900{
1901 struct player_slot *pslot;
1902 struct player *pplayer;
1903
1904 pslot = player_slot_by_number(player_id);
1905 fc_assert(nullptr == pslot || !player_slot_is_used(pslot));
1906
1907 pplayer = player_new(pslot);
1908 if (nullptr == pplayer) {
1909 return nullptr;
1910 }
1911
1915 }
1916
1917 pplayer->ai = ai_type_by_name(ai_tname);
1918
1919 if (pplayer->ai == nullptr) {
1920 player_destroy(pplayer);
1921 return nullptr;
1922 }
1923
1924 adv_data_init(pplayer);
1925
1926 CALL_FUNC_EACH_AI(player_alloc, pplayer);
1927
1928 /* TODO: Do we really need this server_player_init() here? All our callers
1929 * will later make another server_player_init() call anyway, with boolean
1930 * parameters set to what they really need. */
1931 server_player_init(pplayer, FALSE, FALSE);
1932
1933 if (prgbcolor) {
1934 player_set_color(pplayer, prgbcolor);
1935 } /* Else caller must ensure a color is assigned if game has started */
1936
1937 return pplayer;
1938}
1939
1940/**********************************************************************/
1946void server_remove_player(struct player *pplayer)
1947{
1948 const struct player_slot *pslot;
1949
1950 fc_assert_ret(nullptr != pplayer);
1951
1952 /* Save player slot */
1953 pslot = pplayer->slot;
1954
1955 log_normal(_("Removing player %s."), player_name(pplayer));
1956
1957 notify_conn(pplayer->connections, nullptr, E_CONNECTION, ftc_server,
1958 _("You've been removed from the game!"));
1959
1961 _("%s has been removed from the game."),
1962 player_name(pplayer));
1963
1964 if (is_barbarian(pplayer)) {
1965 server.nbarbarians--;
1966 }
1967
1968 /* Don't use conn_list_iterate here because connection_detach() can be
1969 * recursive and free the next connection pointer. */
1970 while (conn_list_size(pplayer->connections) > 0) {
1972 }
1973
1975 /* Clear data saved in the other player structs. */
1977 BV_CLR(aplayer->real_embassy, player_index(pplayer));
1978 if (gives_shared_vision(aplayer, pplayer)) {
1979 remove_shared_vision(aplayer, pplayer);
1980 }
1981 /* Also remove vision provided for the other players */
1982 if (gives_shared_vision(pplayer, aplayer)) {
1983 remove_shared_vision(pplayer, aplayer);
1984 }
1986
1987 /* Remove citizens of this player from the cities of all other players. */
1988 /* FIXME: add a special case if the server quits - no need to run this for
1989 * each player in that case. */
1992 if (city_owner(pcity) != pplayer) {
1993 citizens nationality = citizens_nation_get(pcity, pplayer->slot);
1994
1995 if (nationality != 0) {
1996 /* Change nationality of the citizens to the nationality of the
1997 * city owner. */
1999 nationality);
2001 }
2002 }
2004
2006 }
2007
2008 /* AI type lost control of this player */
2009 if (is_ai(pplayer)) {
2010 CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
2011 }
2012
2013 /* Clear all trade routes. This is needed for the other end not
2014 * to point to a city removed by player_clear() */
2015 city_list_iterate(pplayer->cities, pcity) {
2018 TRUE, TRUE);
2019
2020 FC_FREE(proute);
2021 FC_FREE(pback);
2024
2025 /* We have to clear all player data before the ai memory is freed because
2026 * some function may depend on it. */
2027 player_clear(pplayer, TRUE);
2028
2029 if (!map_is_empty()) {
2030 remove_player_from_maps(pplayer);
2031 }
2032 player_map_free(pplayer);
2033
2034 /* Destroy advisor and ai data. */
2035 CALL_FUNC_EACH_AI(player_free, pplayer);
2036
2037 handicaps_close(pplayer);
2038 ai_traits_close(pplayer);
2039 adv_data_close(pplayer);
2040 player_destroy(pplayer);
2041
2042 send_updated_vote_totals(nullptr);
2043 /* Must be called after the player was destroyed */
2044 send_player_remove_info_c(pslot, nullptr);
2045
2046 /* Recalculate borders. */
2048}
2049
2050/**********************************************************************/
2061{
2062 int maxrate, surplus;
2063 struct player_economic *economic;
2064
2065 /* AI players allowed to cheat */
2066 if (is_ai(pplayer) && !has_handicap(pplayer, H_RATES)) {
2067 return;
2068 }
2069
2070 economic = &(pplayer->economic);
2071
2072 maxrate = get_player_maxrate(pplayer);
2073
2074 surplus = 0;
2075 if (economic->luxury > maxrate) {
2076 surplus += economic->luxury - maxrate;
2077 economic->luxury = maxrate;
2078 }
2079 if (economic->tax > maxrate) {
2080 surplus += economic->tax - maxrate;
2081 economic->tax = maxrate;
2082 }
2083 if (economic->science > maxrate) {
2084 surplus += economic->science - maxrate;
2085 economic->science = maxrate;
2086 }
2087
2088 fc_assert(surplus % 10 == 0);
2089
2090 while (surplus > 0) {
2091 if (economic->science < maxrate) {
2092 economic->science += 10;
2093 } else if (economic->tax < maxrate) {
2094 economic->tax += 10;
2095 } else if (economic->luxury < maxrate) {
2096 economic->luxury += 10;
2097 } else {
2098 fc_assert_msg(FALSE, "Failed to distribute the surplus. "
2099 "maxrate = %d.", maxrate);
2100 }
2101 surplus -= 10;
2102 }
2103}
2104
2105/**********************************************************************/
2109static bool server_player_name_is_allowed(const struct connection *caller,
2110 const struct player *pplayer,
2111 const struct nation_type *pnation,
2112 const char *name, char *error_buf,
2113 size_t error_buf_len)
2114{
2115 /* An empty name is surely not allowed. */
2116 if (0 == strlen(name)) {
2117 fc_strlcpy(error_buf, _("Please choose a non-blank name."),
2119 return FALSE;
2120 }
2121
2122 /* Any name already taken is not allowed. */
2123 players_iterate(other_player) {
2124 if (other_player == pplayer) {
2125 /* We don't care if we're the one using the name/nation. */
2126 continue;
2127 } else if (nullptr != pnation && other_player->nation == pnation) {
2128 /* FIXME: currently cannot use nation_of_player(other_player) as the
2129 * nation debug code is buggy and doesn't test nation for nullptr. */
2130 fc_strlcpy(error_buf, _("That nation is already in use."),
2132 return FALSE;
2133 } else if (0 == fc_strcasecmp(player_name(other_player), name)) {
2135 _("Another player already has the name '%s'. Please "
2136 "choose another name."), name);
2137 return FALSE;
2138 }
2140
2141 if (nullptr == pnation) {
2142 /* FIXME: currently cannot use nation_of_player(other_player) as the
2143 * nation debug code is buggy and doesn't test nation for nullptr. */
2144 pnation = pplayer->nation;
2145 }
2146
2147 /* Any name from the default list is always allowed. */
2148 if (nullptr != pnation && nullptr != nation_leader_by_name(pnation, name)) {
2149 return TRUE;
2150 }
2151
2152 /* To prevent abuse, only players with HACK access (usually local
2153 * connections) can use non-ascii names. Otherwise players could use
2154 * confusing garbage names in multi-player games. */
2155 if (nullptr != caller
2156 && caller->access_level < ALLOW_HACK
2157 && !is_ascii_name(name)) {
2159 _("Please choose a name containing only ASCII characters."),
2161 return FALSE;
2162 }
2163
2164 return TRUE;
2165}
2166
2167/**********************************************************************/
2171bool server_player_set_name_full(const struct connection *caller,
2172 struct player *pplayer,
2173 const struct nation_type *pnation,
2174 const char *name,
2175 char *error_buf, size_t error_buf_len)
2176{
2177 char real_name[MAX_LEN_NAME];
2178 char buf[256];
2179 int i;
2180
2181 /* Always provide an error buffer. */
2182 if (nullptr == error_buf) {
2183 error_buf = buf;
2184 error_buf_len = sizeof(buf);
2185 }
2186 error_buf[0] = '\0';
2187
2188 if (nullptr != name) {
2189 /* Ensure this is a correct name. */
2193
2194 if (server_player_name_is_allowed(caller, pplayer, pnation, real_name,
2196 log_debug("Name of player nb %d set to \"%s\".",
2197 player_number(pplayer), real_name);
2198 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2199 return TRUE; /* Success! */
2200 } else {
2201 log_verbose("Failed to set the name of the player nb %d to \"%s\": %s",
2202 player_number(pplayer), real_name, error_buf);
2203 /* Fallthrough. */
2204 }
2205 }
2206
2207 if (nullptr != caller) {
2208 /* If we want to test, let's fail here. */
2209 fc_assert(nullptr != name);
2210 return FALSE;
2211 }
2212
2213 if (nullptr != name) {
2214 /* Try to append a number to 'real_name'. */
2215 char test[MAX_LEN_NAME];
2216
2217 for (i = 2; i <= player_slot_count(); i++) {
2218 fc_snprintf(test, sizeof(test), "%s%d", real_name, i);
2219 if (server_player_name_is_allowed(caller, pplayer, pnation,
2221 log_verbose("Name of player nb %d set to \"%s\" instead.",
2222 player_number(pplayer), test);
2223 fc_strlcpy(pplayer->name, test, sizeof(pplayer->name));
2224 return TRUE;
2225 } else {
2226 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2227 player_number(pplayer), test, error_buf);
2228 }
2229 }
2230 }
2231
2232 /* Try a default name. */
2234 _("Player no. %d"), player_number(pplayer));
2235 if (server_player_name_is_allowed(caller, pplayer, pnation,
2237 log_verbose("Name of player nb %d set to \"%s\".",
2238 player_number(pplayer), real_name);
2239 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2240 return TRUE;
2241 } else {
2242 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2243 player_number(pplayer), real_name, error_buf);
2244 }
2245
2246 /* Try a very default name... */
2247 for (i = 0; i < player_slot_count(); i++) {
2248 fc_snprintf(real_name, sizeof(real_name), _("Player no. %d"), i);
2249 if (server_player_name_is_allowed(caller, pplayer, pnation,
2251 log_verbose("Name of player nb %d to \"%s\".",
2252 player_number(pplayer), real_name);
2253 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2254 return TRUE;
2255 } else {
2256 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2257 player_number(pplayer), real_name, error_buf);
2258 }
2259 }
2260
2261 /* This is really not normal... Maybe the size of 'real_name'
2262 * is not enough big, or a bug in server_player_name_is_allowed(). */
2263 fc_strlcpy(pplayer->name, _("A poorly-named player"),
2264 sizeof(pplayer->name));
2265 return FALSE; /* Let's say it's a failure. */
2266}
2267
2268/**********************************************************************/
2271void server_player_set_name(struct player *pplayer, const char *name)
2272{
2273#ifndef FREECIV_NDEBUG
2274 bool ret =
2275#endif
2276 server_player_set_name_full(nullptr, pplayer, nullptr, name, nullptr, 0);
2277
2278 fc_assert(ret);
2279}
2280
2281/**********************************************************************/
2287static enum diplstate_type
2289 const struct player *pplayer2)
2290{
2292 if (pplayer3 != pplayer1
2293 && pplayer3 != pplayer2
2296 return DS_PEACE;
2297 }
2299
2300 return DS_WAR;
2301}
2302
2303/**********************************************************************/
2307 struct tile *ptile)
2308{
2310
2311 if (pplayer1 == pplayer2
2312 || !pplayer1->is_alive
2313 || !pplayer2->is_alive) {
2314 return;
2315 }
2316
2319
2322 ds_plr1plr2->contact_turns_left = game.server.contactturns;
2323 ds_plr2plr1->contact_turns_left = game.server.contactturns;
2324 }
2325 if (ds_plr1plr2->type == DS_NO_CONTACT) {
2327 pplayer2);
2328
2330 ds_plr1plr2->first_contact_turn = game.info.turn;
2331 ds_plr2plr1->first_contact_turn = game.info.turn;
2333 _("You have made contact with the %s, ruled by %s."),
2337 _("You have made contact with the %s, ruled by %s."),
2340 send_player_all_c(pplayer1, pplayer2->connections);
2341 send_player_all_c(pplayer2, pplayer1->connections);
2342 send_player_all_c(pplayer1, pplayer1->connections);
2343 send_player_all_c(pplayer2, pplayer2->connections);
2344 if (is_ai(pplayer1)) {
2346 }
2347 if (is_ai(pplayer2)) {
2349 }
2350 return;
2351 } else {
2353 }
2355 || team_has_embassy(pplayer2->team, pplayer1)) {
2356 return; /* Avoid sending too much info over the network */
2357 }
2358 /* Send correct info about players to each other
2359 * before sending updated contact info to each player.
2360 * This makes sure that the client does not assume that
2361 * it already has contact provided info, when it actually
2362 * is only going to get it in the next packet. */
2363 send_player_info_c(pplayer1, pplayer2->connections);
2364 send_player_info_c(pplayer2, pplayer1->connections);
2365 send_player_all_c(pplayer1, pplayer1->connections);
2366 send_player_all_c(pplayer2, pplayer2->connections);
2367}
2368
2369/**********************************************************************/
2372void maybe_make_contact(struct tile *ptile, struct player *pplayer)
2373{
2374 square_iterate(&(wld.map), ptile, 1, tile1) {
2375 struct city *pcity = tile_city(tile1);
2376
2377 if (pcity) {
2378 make_contact(pplayer, city_owner(pcity), ptile);
2379 }
2382 continue; /* Flagless unit can't make contact */
2383 }
2384 make_contact(pplayer, unit_owner(punit), ptile);
2387}
2388
2389/**********************************************************************/
2393{
2394 /* shuffled_order is defined global */
2395 int n = player_slot_count();
2396 int i;
2397
2398 log_debug("shuffle_players: creating shuffled order");
2399
2400 for (i = 0; i < n; i++) {
2401 shuffled_order[i] = i;
2402 }
2403
2404 /* Randomize it */
2406
2407#ifdef FREECIV_DEBUG
2408 for (i = 0; i < n; i++) {
2409 log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2410 }
2411#endif /* FREECIV_DEBUG */
2412}
2413
2414/**********************************************************************/
2418{
2419 int i;
2420
2421 log_debug("set_shuffled_players: loading shuffled array %p",
2423
2424 for (i = 0; i < player_slot_count(); i++) {
2426 log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2427 }
2428}
2429
2430/**********************************************************************/
2436{
2437 struct player *pplayer;
2438
2439 pplayer = player_by_number(shuffled_order[i]);
2440 log_debug("shuffled_player(%d) = %d (%s)",
2441 i, shuffled_order[i], player_name(pplayer));
2442 return pplayer;
2443}
2444
2445/**********************************************************************/
2468 bool ignore_conflicts,
2469 bool needs_startpos,
2470 enum barbarian_type barb_type)
2471{
2472 enum {
2475 int match[nation_count()], pick, idx;
2477
2478 /* Values of nations_used:
2479 * UNAVAILABLE - nation is already used or is a special nation.
2480 * AVAILABLE - we can use this nation.
2481 * PREFERRED - we can use this nation and it is on the choices list.
2482 * UNWANTED - we can use this nation, but we really don't want to. */
2483 nations_iterate(pnation) {
2484 idx = nation_index(pnation);
2485
2486 if (!nation_is_in_current_set(pnation)
2487 || pnation->player
2489 && pnation->server.no_startpos)
2490 || (barb_type != nation_barbarian_type(pnation))
2491 || (barb_type == NOT_A_BARBARIAN && !is_nation_playable(pnation))) {
2492 /* Nation is unplayable or already used: don't consider it.
2493 * (If nations aren't currently restricted to those with start
2494 * positions, we do nothing special here, but generate_players() will
2495 * tend to prefer them.) */
2497 match[idx] = 0;
2498 continue;
2499 }
2500
2501 nations_used[idx] = AVAILABLE;
2502
2503 /* Determine which nations look good with nations already in the game,
2504 * or conflict with them. */
2505 match[idx] = 1;
2506 players_iterate(pplayer) {
2507 if (pplayer->nation != NO_NATION_SELECTED) {
2508 int x = nations_match(pnation, nation_of_player(pplayer),
2510 if (x < 0) {
2511 log_debug("Nations '%s' (nb %d) and '%s' (nb %d) are in conflict.",
2512 nation_rule_name(pnation), nation_number(pnation),
2515 nations_used[idx] = UNWANTED;
2516 match[idx] -= x * 100;
2517 break;
2518 } else {
2519 match[idx] += x * 100;
2520 }
2521 }
2523
2524 if (AVAILABLE == nations_used[idx]) {
2525 num_avail_nations += match[idx];
2526 }
2528
2529 /* Mark as preferred those nations which are on the choices list and
2530 * which are AVAILABLE, but no UNWANTED */
2531 if (nullptr != choices) {
2532 nation_list_iterate(choices, pnation) {
2533 idx = nation_index(pnation);
2534 if (nations_used[idx] == AVAILABLE) {
2535 num_pref_nations += match[idx];
2536 nations_used[idx] = PREFERRED;
2537 }
2539 }
2540
2541 if (0 < num_pref_nations || 0 < num_avail_nations) {
2542 if (0 < num_pref_nations) {
2543 /* Use a preferred nation only. */
2546 log_debug("Picking a preferred nation.");
2547 } else {
2548 /* Use any available nation. */
2552 log_debug("Picking an available nation.");
2553 }
2554
2555 nations_iterate(pnation) {
2556 idx = nation_index(pnation);
2557 if (nations_used[idx] == looking_for) {
2558 pick -= match[idx];
2559
2560 if (0 > pick) {
2561 return pnation;
2562 }
2563 }
2565 } else {
2566 /* No available nation: use unwanted nation... */
2569
2570 log_debug("Picking an unwanted nation.");
2571 nations_iterate(pnation) {
2572 idx = nation_index(pnation);
2573 if (UNWANTED == nations_used[idx]) {
2574 pick = -fc_rand(match[idx]);
2575 if (pick > less_worst_score) {
2576 less_worst_nation = pnation;
2578 }
2579 }
2581
2583 return less_worst_nation;
2584 }
2585 }
2586
2587 log_verbose("No nation found!");
2588
2589 return NO_NATION_SELECTED;
2590}
2591
2592/**********************************************************************/
2595static struct nation_set *current_nationset(void)
2596{
2598}
2599
2600/**********************************************************************/
2604bool nation_is_in_current_set(const struct nation_type *pnation)
2605{
2606 return nation_is_in_set(pnation, current_nationset());
2607}
2608
2609/**********************************************************************/
2614{
2615 server.playable_nations = 0;
2616 allowed_nations_iterate(pnation) {
2617 if (is_nation_playable(pnation)) {
2618 server.playable_nations++;
2619 }
2621}
2622
2623/**********************************************************************/
2628bool client_can_pick_nation(const struct nation_type *pnation)
2629{
2630 fc_assert_ret_val(pnation != nullptr, FALSE);
2631 return nation_is_in_current_set(pnation)
2632 && is_nation_playable(pnation)
2634 || !pnation->server.no_startpos);
2635}
2636
2637/**********************************************************************/
2641 bool nationset_change)
2642{
2643 struct packet_nation_availability packet;
2644
2645 packet.ncount = nation_count();
2647 nations_iterate(pnation) {
2648 packet.is_pickable[nation_index(pnation)] = client_can_pick_nation(pnation);
2650 lsend_packet_nation_availability(dest, &packet);
2651}
2652
2653/**********************************************************************/
2657 bool nationset_change)
2658{
2659 if (0 < player_info_frozen_level) {
2660 return; /* Discard, see comment for player_info_freeze(). */
2661 } else {
2663 }
2664}
2665
2666/**********************************************************************/
2674{
2675 int ncount = nation_set_count();
2676 int misfits[ncount];
2677
2678 memset(misfits, 0, sizeof(misfits));
2679
2681 players_iterate(pplayer) {
2682 if (pplayer->nation != NO_NATION_SELECTED
2683 && !nation_is_in_set(pplayer->nation, pset)) {
2685 }
2688
2690 /* Current set is OK. */
2691 return;
2692 }
2693
2694 /* Otherwise, pick the least bad set (requires unsetting fewest
2695 * players, possibly none). */
2696 {
2697 int i, least_misfits;
2698 const struct nation_set *best;
2699
2700 fc_assert(ncount > 0);
2701
2702 best = nation_set_by_number(0);
2704 for (i = 1; i < ncount && least_misfits != 0; i++) {
2705 if (best == nullptr || misfits[i] < least_misfits) {
2706 best = nation_set_by_number(i);
2708 }
2709 }
2710
2711 log_verbose("Current nationset \"%s\" doesn't fit all existing players.",
2713 log_verbose("Selected nationset \"%s\".", nation_set_rule_name(best));
2715 sizeof(game.server.nationset));
2717 /* No need to refresh clients, as we're assumed to be in the middle of
2718 * loading a savegame and will send new setting/availability later
2719 * along with everything else */
2720 }
2721
2722 /* The set we chose may not fit all the players; as a last resort,
2723 * unset nations (caller must then arrange new assignments). */
2724 players_iterate(pplayer) {
2725 if (pplayer->nation != NO_NATION_SELECTED
2726 && !nation_is_in_current_set(pplayer->nation)) {
2727 log_verbose("Nation %s of player %s not in nationset \"%s\", unsetting.",
2728 nation_plural_for_player(pplayer), player_name(pplayer),
2731 }
2733}
2734
2735/**********************************************************************/
2739{
2740 if (S_S_INITIAL != server_state()) {
2741 return;
2742 }
2743 players_iterate(pplayer) {
2744 if (pplayer->is_ready) {
2745 bool persistent = FALSE;
2746
2747 if (plrchange) {
2748 switch (game.info.persistent_ready)
2749 {
2751 persistent = FALSE;
2752 break;
2754 persistent = pplayer->is_connected;
2755 break;
2756 }
2757 }
2758
2759 if (!persistent) {
2760 pplayer->is_ready = FALSE;
2762 }
2763 }
2765}
2766
2767/**********************************************************************/
2773static struct player *split_player(struct player *pplayer)
2774{
2776 struct player *cplayer;
2777 struct nation_type *rebel_nation;
2778
2779 /* Make a new player, or not */
2780 cplayer = server_create_player(-1, ai_name(pplayer->ai),
2781 nullptr, FALSE);
2782 if (!cplayer) {
2783 return nullptr;
2784 }
2785
2786 /* While this sets player->economic according to max rates as known
2787 * at this point, we redo that later, so that MaxRates effect
2788 * requirements will be evaluated with more completely set up player
2789 * (e.g. correct government) */
2791
2792 /* Rebel will always be an AI player */
2793 rebel_nation = pick_a_nation(nation_of_player(pplayer)->server.civilwar_nations,
2796
2798 /* Find a color for the new player. */
2800
2801 /* Send information about the used player slot to all connections. */
2802 send_player_info_c(cplayer, nullptr);
2803
2804 sz_strlcpy(cplayer->username, _(ANON_USER_NAME));
2805 cplayer->unassigned_user = TRUE;
2806 cplayer->is_connected = FALSE;
2808 fc_assert(cplayer->revolution_finishes < 0);
2809 /* No capital for the split player. */
2811
2812 players_iterate(other_player) {
2813 struct player_diplstate *ds_co
2814 = player_diplstate_get(cplayer, other_player);
2815 struct player_diplstate *ds_oc
2816 = player_diplstate_get(other_player, cplayer);
2817
2818 if (get_player_bonus(other_player, EFT_NO_DIPLOMACY) > 0) {
2819 /* FIXME: What about No-contact war? */
2821 } else {
2823 }
2824
2825 ds_co->has_reason_to_cancel = 0;
2826 ds_co->turns_left = 0;
2827 ds_co->contact_turns_left = 0;
2828 ds_oc->has_reason_to_cancel = 0;
2829 ds_oc->turns_left = 0;
2830 ds_oc->contact_turns_left = 0;
2831
2832 /* Send so that other_player sees updated diplomatic info;
2833 * pplayer will be sent later anyway
2834 */
2835 if (other_player != pplayer) {
2836 send_player_all_c(other_player, other_player->connections);
2837 }
2839
2840 /* Split the resources */
2841 cplayer->economic.gold = pplayer->economic.gold;
2842 cplayer->economic.gold /= 2;
2843 pplayer->economic.gold -= cplayer->economic.gold;
2844
2845 /* Copy the research */
2847 old_research = research_get(pplayer);
2848
2849 new_research->bulbs_researched = 0;
2850 new_research->techs_researched = old_research->techs_researched;
2851 new_research->researching = old_research->researching;
2852 new_research->future_tech = old_research->future_tech;
2853 new_research->tech_goal = old_research->tech_goal;
2854
2858 new_research->inventions[i].bulbs_researched_saved
2859 = old_research->inventions[i].bulbs_researched_saved;
2860 }
2862 cplayer->phase_done = TRUE; /* Have other things to think
2863 about - paralysis */
2864 BV_CLR_ALL(cplayer->real_embassy); /* All embassies destroyed */
2866
2867 /* Do the AI */
2869 cplayer->ai_common.maxbuycost = pplayer->ai_common.maxbuycost;
2870 cplayer->ai_common.warmth = pplayer->ai_common.warmth;
2871 cplayer->ai_common.frost = pplayer->ai_common.frost;
2873
2874 /* Change the original player */
2876 pplayer->target_government = pplayer->government;
2878 pplayer->revolution_finishes = game.info.turn + 1;
2879 }
2880 old_research->bulbs_researched = 0;
2881 old_research->researching_saved = A_UNKNOWN;
2882 BV_CLR_ALL(pplayer->real_embassy); /* All embassies destroyed */
2883
2884 /* Give split player the embassies to their team mates back, if any */
2885 if (pplayer->team) {
2887 if (pplayer->team == pdest->team
2888 && pplayer != pdest) {
2889 establish_embassy(pplayer, pdest);
2890 }
2892 }
2894
2896
2897 /* Copy the maps */
2898
2900
2901 pplayer->server.border_vision = cplayer->server.border_vision;
2902
2903 /* Not sure if this is necessary, but might be a good idea
2904 * to avoid doing some ai calculations with bogus data. */
2906 CALL_PLR_AI_FUNC(phase_begin, cplayer, cplayer, TRUE);
2907 CALL_PLR_AI_FUNC(gained_control, cplayer, cplayer);
2908 CALL_PLR_AI_FUNC(split_by_civil_war, pplayer, pplayer, cplayer);
2909 CALL_PLR_AI_FUNC(created_by_civil_war, cplayer, pplayer, cplayer);
2910
2912
2913 return cplayer;
2914}
2915
2916/**********************************************************************/
2924bool civil_war_possible(struct player *pplayer, bool conquering_city,
2926{
2927 int n;
2928 const struct civ_map *nmap = &(wld.map);
2929
2931 return FALSE;
2932 }
2933
2934 n = city_list_size(pplayer->cities);
2935
2936 if (n - (conquering_city ? 1 : 0) < GAME_MIN_CIVILWARSIZE) {
2937 return FALSE;
2938 }
2941 && n >= game.server.civilwarsize;
2942 } else {
2943 return TRUE;
2944 }
2945}
2946
2947/**********************************************************************/
2972bool civil_war_triggered(struct player *pplayer)
2973{
2974 /* Get base probabilities */
2975 int dice = fc_rand(100); /* Throw the dice */
2976 int prob = get_player_bonus(pplayer, EFT_CIVIL_WAR_CHANCE);
2977
2978 /* Now compute the contribution of the cities. */
2979 city_list_iterate(pplayer->cities, pcity) {
2982
2983 log_verbose("Civil war chance for %s: prob %d, dice %d",
2984 player_name(pplayer), prob, dice);
2985
2986 return (dice < prob);
2987}
2988
2989/**********************************************************************/
3017struct player *civil_war(struct player *pplayer)
3018{
3019 int i, j;
3020 struct player *cplayer;
3021 struct city *capital;
3022 struct city_list *defector_candidates;
3023 size_t plr_count;
3024
3025 /* It is possible that this function gets called after pplayer
3026 * died. Player pointers are safe even after death. */
3027 if (!pplayer->is_alive) {
3028 return nullptr;
3029 }
3030
3032 if (plr_count >= MAX_NUM_PLAYERS) {
3033 /* No space to make additional player */
3034 log_normal(_("Could not throw %s into civil war - too many players"),
3035 nation_plural_for_player(pplayer));
3036 return nullptr;
3037 }
3038
3040 /* No space to make additional player */
3041 log_normal(_("Could not throw %s into civil war - maxplayers (%d) reached"),
3043 return nullptr;
3044 }
3045
3046 if (plr_count >= server.playable_nations) {
3047 /* No nation for additional player */
3048 log_normal(_("Could not throw %s into civil war - no available nations"),
3049 nation_plural_for_player(pplayer));
3050 return nullptr;
3051 }
3052
3053 /* It doesn't make sense to try to split an empire of 1 city.
3054 * This should have been enforced by civil_war_possible(). */
3055 fc_assert_ret_val(city_list_size(pplayer->cities) > 1, nullptr);
3056
3058 city_list_iterate(pplayer->cities, pcity) {
3059 bool gameloss_present = FALSE;
3060
3061 /* Capital (probably new capital) won't defect */
3062 if (is_capital(pcity)) {
3063 continue;
3064 }
3065
3066 /* City hosting victim's GameLoss unit won't defect */
3068 if (unit_owner(punit) == pplayer
3071 break;
3072 }
3074
3075 if (gameloss_present) {
3076 continue;
3077 }
3078
3081
3083 log_verbose(_("Could not throw %s into civil war - no available cities"),
3084 nation_plural_for_player(pplayer));
3086
3087 return nullptr;
3088 }
3089
3090 /* We're definitely going to create a new rebel player. */
3091
3092 cplayer = split_player(pplayer);
3093
3094 /* Before units, cities, so clients know name of new nation
3095 * (for debugging etc).
3096 */
3097 send_player_all_c(cplayer, nullptr);
3098 send_player_all_c(pplayer, nullptr);
3099
3100 /* Now split the empire */
3101
3102 log_verbose("%s civil war; created AI %s",
3105 notify_player(pplayer, nullptr, E_CIVIL_WAR, ftc_server,
3106 _("Your nation is thrust into civil war."));
3107
3108 notify_player(pplayer, nullptr, E_FIRST_CONTACT, ftc_server,
3109 /* TRANS: <leader> ... the Poles. */
3110 _("%s is the rebellious leader of the %s."),
3113
3114 j = city_list_size(defector_candidates); /* number left to process */
3115 /* Number to try to flip; ensure that at least one eligible city is
3116 * flipped */
3117 i = MAX(j/2, 1);
3119 fc_assert_action(!is_capital(pcity), continue);
3120 if (i >= j || (i > 0 && fc_rand(2) == 1)) {
3121 /* Transfer city and units supported by this city to the new owner.
3122 * We do NOT resolve stack conflicts here, but rather later.
3123 * Reason: if we have a transporter from one city which is carrying
3124 * a unit from another city, and both cities join the rebellion. If we
3125 * resolved stack conflicts for each city we would teleport the first
3126 * of the units we met since the other would have another owner. */
3128 log_verbose("%s declares allegiance to the %s.", city_name_get(pcity),
3131 /* TRANS: <city> ... the Poles. */
3132 _("%s declares allegiance to the %s."),
3135 script_server_signal_emit("city_transferred", pcity, pplayer,
3136 cplayer, "civil_war");
3137 }
3138 i--;
3139 }
3140 j--;
3142
3144
3146
3147 i = city_list_size(cplayer->cities);
3148 fc_assert(i > 0); /* Rebels should have got at least one city */
3149
3150 /* Choose a capital (random). */
3151 capital = city_list_get(cplayer->cities, fc_rand(i));
3154
3155 notify_player(nullptr, nullptr, E_CIVIL_WAR, ftc_server,
3156 /* TRANS: ... Danes ... Poles ... <7> cities. */
3157 PL_("Civil war partitions the %s;"
3158 " the %s now hold %d city.",
3159 "Civil war partitions the %s;"
3160 " the %s now hold %d cities.",
3161 i),
3162 nation_plural_for_player(pplayer),
3164 i);
3165
3166 return cplayer;
3167}
3168
3169/**********************************************************************/
3174 *chunk)
3175{
3177}
3178
3179/**********************************************************************/
3183{
3184 send_attribute_block(pplayer, pplayer->current_conn);
3185}
3186
3187/**********************************************************************/
3191 int turn)
3192{
3193 if (turn != game.info.turn) {
3194 /* If this happens then the player actually pressed turn-done on a
3195 * previous turn but we didn't receive it until now. The player
3196 * probably didn't actually mean to end their turn! */
3197 return;
3198 }
3199
3200 pplayer->phase_done = TRUE;
3201
3203
3204 send_player_all_c(pplayer, nullptr);
3205}
3206
3207/**********************************************************************/
3211{
3212 return server.nbarbarians;
3213}
3214
3215/**********************************************************************/
3219{
3220 return player_count() - server.nbarbarians;
3221}
3222
3223/**********************************************************************/
3227{
3228 BV_SET(plr->server.status, pstatus);
3229}
3230
3231/**********************************************************************/
3235{
3236 return BV_ISSET(plr->server.status, pstatus);
3237}
3238
3239/**********************************************************************/
3243{
3244 BV_CLR_ALL(plr->server.status);
3246}
3247
3248/**********************************************************************/
3251const char *player_delegation_get(const struct player *pplayer)
3252{
3253 if (pplayer == nullptr || strlen(pplayer->server.delegate_to) == 0) {
3254 /* No delegation if there is no player. */
3255 return nullptr;
3256 } else {
3257 return pplayer->server.delegate_to;
3258 }
3259}
3260
3261/**********************************************************************/
3264void player_delegation_set(struct player *pplayer, const char *username)
3265{
3266 fc_assert_ret(pplayer != nullptr);
3267
3268 if (username == nullptr || strlen(username) == 0) {
3269 pplayer->server.delegate_to[0] = '\0';
3270 } else {
3271 sz_strlcpy(pplayer->server.delegate_to, username);
3272 }
3273}
3274
3275/**********************************************************************/
3280bool player_delegation_active(const struct player *pplayer)
3281{
3282 return (pplayer && strlen(pplayer->server.orig_username) != 0);
3283}
3284
3285/**********************************************************************/
3289{
3290 if (game.info.is_new_game) {
3291 return;
3292 }
3293
3294 if (!pconn->observer
3295 && pconn->playing && player_delegation_get(pconn->playing) != nullptr) {
3296 notify_conn(pconn->self, nullptr, E_CONNECTION, ftc_server,
3297 /* TRANS: '/delegate cancel' is a server command and must not
3298 * be translated */
3299 _("User '%s' is currently allowed to take control of your "
3300 "player while you are away. Use '/delegate cancel' to "
3301 "revoke this access."),
3302 player_delegation_get(pconn->playing));
3303 }
3304
3305 {
3306 bool any_delegations = FALSE;
3307
3309 if (player_delegation_get(aplayer) != nullptr
3310 && strcmp(player_delegation_get(aplayer), pconn->username) == 0) {
3311 notify_conn(pconn->self, nullptr, E_CONNECTION, ftc_server,
3312 _("Control of player '%s' is delegated to you."),
3315 }
3317 if (any_delegations) {
3318 notify_conn(pconn->self, nullptr, E_CONNECTION, ftc_server,
3319 /* TRANS: '/delegate take' is a server command and must not
3320 * be translated; but <player> should be translated. */
3321 _("Use '/delegate take <player>' to take control of a "
3322 "delegated player."));
3323 }
3324 }
3325}
3326
3327/**********************************************************************/
3333{
3334 players_iterate(pplayer) {
3335 if (player_delegation_get(pplayer)
3336 && fc_strcasecmp(name, pplayer->server.orig_username) == 0) {
3337 return pplayer;
3338 }
3340
3341 return nullptr;
3342}
3343
3344/**********************************************************************/
3348{
3349 fc_assert_ret(game.server.plr_colors == nullptr);
3350
3352}
3353
3354/**********************************************************************/
3372
3373/**********************************************************************/
3382
3383/**********************************************************************/
3387{
3388 fc_assert_ret_val(game.server.plr_colors != nullptr, nullptr);
3389
3391}
3392
3393/**********************************************************************/
3397{
3398 fc_assert_ret_val(game.server.plr_colors != nullptr, -1);
3399
3401}
3402
3403/**********************************************************************/
3406void handle_player_multiplier(struct player *pplayer, int count,
3407 const int *multipliers)
3408{
3409 int rval;
3410 int i;
3411
3412 if (count != multiplier_count()) {
3413 log_error("Bad number of multipliers %d from client for %s",
3414 count, player_name(pplayer));
3415 return;
3416 }
3417
3418 for (i = 0; i < count; i++) {
3419 struct multiplier *pmul = multiplier_by_number(i);
3420
3421 if (multiplier_can_be_changed(pmul, pplayer)) {
3422 if (multipliers[i] < pmul->start || multipliers[i] > pmul->stop) {
3423 log_error("Multiplier value %d for %s out of range for %s",
3425 player_name(pplayer));
3426 } else {
3427 rval = (multipliers[i] - pmul->start) / pmul->step * pmul->step + pmul->start;
3428 if (rval != multipliers[i]) {
3429 log_error("Multiplier value %d between valid values for %s for %s",
3431 player_name(pplayer));
3432 } else {
3433 pplayer->multipliers[i].target = multipliers[i];
3434 }
3435 }
3436 }
3437 }
3438
3439 send_player_info_c(pplayer, nullptr);
3440}
3441
3442/**********************************************************************/
3445void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
3446{
3447 set_as_ai(pplayer);
3448
3449 set_ai_level_directer(pplayer, skill_level);
3450 cancel_all_meetings(pplayer);
3451 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
3452 if (is_player_phase(pplayer, game.info.phase)) {
3453 CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
3454 }
3455
3456 if (S_S_RUNNING == server_state()) {
3457 /* In case this was last player who has not pressed turn done. */
3459 }
3460
3461 fc_assert(pplayer->ai_common.skill_level == skill_level);
3462}
3463
3464/**********************************************************************/
3468{
3469 set_as_human(pplayer);
3470
3471 if (pplayer->ai_common.skill_level == AI_LEVEL_AWAY) {
3473 }
3474
3475 CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
3476
3477 /* Because AI "cheats" with government rates but humans shouldn't. */
3478 if (!game.info.is_new_game) {
3479 check_player_max_rates(pplayer);
3480 }
3481 cancel_all_meetings(pplayer);
3482}
3483
3484/**********************************************************************/
3488{
3489 char buf[200 + MAX_LEN_NAME];
3490
3491 /* gold_upkeep_style check currently redundant, but something we need
3492 * once homeless_gold_upkeep retired. */
3495 unit_list_iterate(pplayer->units, punit) {
3496 if (is_unit_homeless(punit)) {
3497 int gold = utype_upkeep_cost(unit_type_get(punit), pplayer, O_GOLD);
3498
3499 punit->upkeep[O_GOLD] = gold;
3500 punit->server.upkeep_paid[O_GOLD] = gold;
3501
3502 pplayer->economic.gold -= gold;
3503 }
3505 }
3506
3507 if (pplayer->economic.gold < 0) {
3508 switch (game.info.gold_upkeep_style) {
3509 case GOLD_UPKEEP_CITY:
3510 break;
3511 case GOLD_UPKEEP_MIXED:
3512 /* Nation pays for units. */
3514 break;
3515 case GOLD_UPKEEP_NATION:
3516 /* Nation pays for units and buildings. */
3518 break;
3519 }
3520 }
3521
3522 /* This test includes the cost of the units because
3523 * units are paid for in update_city_activity() or
3524 * player_balance_treasury_units(). */
3525 if (old_gold - (old_gold - pplayer->economic.gold) * 3 < 0) {
3526 notify_player(pplayer, nullptr, E_LOW_ON_FUNDS, ftc_server,
3527 _("WARNING, we're LOW on FUNDS %s."),
3528 ruler_title_for_player(pplayer, buf, sizeof(buf)));
3529 }
3530
3531#if 0
3532 /* Uncomment to unbalance the game, like in civ1 (CLG). */
3533 if (pplayer->got_tech && pplayer->research->researched > 0) {
3534 pplayer->research->researched = 0;
3535 }
3536#endif
3537
3538 if (pplayer->economic.infra_points < 0) {
3539 pplayer->economic.infra_points = 0;
3540 }
3541
3542 pplayer->history += nation_history_gain(pplayer);
3543
3545 /* Reduce the number of bulbs by the amount needed for tech upkeep and
3546 * check for finished research */
3547 update_bulbs(pplayer, -player_tech_upkeep(pplayer), TRUE, FALSE);
3548}
bool is_action_enabled_player(const struct civ_map *nmap, const action_id wanted_action, const struct player *actor_plr)
Definition actions.c:3482
void adv_data_close(struct player *pplayer)
Definition advdata.c:762
void adv_data_init(struct player *pplayer)
Definition advdata.c:706
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:270
void adv_data_default(struct player *pplayer)
Definition advdata.c:739
const char * ai_name(const struct ai_type *ai)
Definition ai.c:335
const char * ai_type_name_or_fallback(const char *orig_name)
Definition ai.c:346
struct ai_type * ai_type_by_name(const char *search)
Definition ai.c:290
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
@ INCIDENT_WAR
Definition ai.h:46
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
void call_incident(enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *violator, struct player *victim)
Definition aiiface.c:220
void ai_traits_close(struct player *pplayer)
Definition aitraits.c:59
#define n
Definition astring.c:77
struct player * create_barbarian_player(enum barbarian_type type)
Definition barbarian.c:97
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
#define BV_CLR(bv, bit)
Definition bitvector.h:94
void citizens_nation_move(struct city *pcity, const struct player_slot *pslot_from, const struct player_slot *pslot_to, int move)
Definition citizens.c:130
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
bool is_capital(const struct city *pcity)
Definition city.c:1579
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
#define cities_iterate_end
Definition city.h:514
#define city_list_iterate_safe(citylist, _city)
Definition city.h:519
#define city_list_iterate(citylist, pcity)
Definition city.h:505
#define city_tile(_pcity_)
Definition city.h:561
#define cities_iterate(pcity)
Definition city.h:509
#define city_owner(_pcity_)
Definition city.h:560
#define city_list_iterate_end
Definition city.h:507
#define city_list_iterate_safe_end
Definition city.h:541
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3284
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1435
void sync_cities(void)
Definition citytools.c:3358
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3392
void remove_city(struct city *pcity)
Definition citytools.c:1713
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2950
bool transfer_city(struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
Definition citytools.c:1077
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:197
bool player_balance_treasury_units_and_buildings(struct player *pplayer)
Definition cityturn.c:3238
bool player_balance_treasury_units(struct player *pplayer)
Definition cityturn.c:3301
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:182
void city_refresh_queue_processing(void)
Definition cityturn.c:213
char * incite_cost
Definition comments.c:76
void connection_detach(struct connection *pconn, bool remove_unused_player)
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
#define conn_list_iterate_end
Definition connection.h:110
int player_culture(const struct player *plr)
Definition culture.c:49
int nation_history_gain(const struct player *pplayer)
Definition culture.c:66
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:77
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Definition difficulty.c:39
void establish_embassy(struct player *pplayer, struct player *aplayer)
Definition diplhand.c:698
void reject_all_treaties(struct player *pplayer)
Definition diplhand.c:935
void set_diplstate_type(struct player_diplstate *state1, struct player_diplstate *state2, enum diplstate_type type)
Definition diplhand.c:122
void cancel_all_meetings(struct player *pplayer)
Definition diplhand.c:923
bool could_intel_with_player(const struct player *pplayer, const struct player *aplayer)
Definition diptreaty.c:84
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1128
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
int Tech_type_id
Definition fc_types.h:237
unsigned char citizens
Definition fc_types.h:248
int Impr_type_id
Definition fc_types.h:236
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
revolen_type
Definition fc_types.h:990
@ REVOLEN_RANDOM
Definition fc_types.h:992
@ REVOLEN_RANDQUICK
Definition fc_types.h:994
@ REVOLEN_FIXED
Definition fc_types.h:991
@ REVOLEN_QUICKENING
Definition fc_types.h:993
int Government_type_id
Definition fc_types.h:241
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define MAX_LEN_NAME
Definition fc_types.h:67
@ O_GOLD
Definition fc_types.h:102
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
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,...)
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
const struct ft_color ftc_any
#define FT_OFFSET_UNSET
@ TTT_COLOR
#define FT_COLOR(fg, bg)
struct civ_game game
Definition game.c:61
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:712
struct world wld
Definition game.c:62
#define GAME_DEFAULT_REVOLUTION_LENGTH
Definition game.h:744
#define GAME_MIN_CIVILWARSIZE
Definition game.h:497
#define any_web_conns()
Definition game.h:324
#define GAME_MAX_CIVILWARSIZE
Definition game.h:498
struct unit_type * crole_to_unit_type(char crole, struct player *pplayer)
Definition gamehand.c:120
const char * government_name_translation(const struct government *pgovern)
Definition government.c:143
bool untargeted_revolution_allowed(void)
Definition government.c:580
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Definition government.c:405
Government_type_id government_count(void)
Definition government.c:71
struct government * government_by_number(const Government_type_id gov)
Definition government.c:103
struct government * government_of_player(const struct player *pplayer)
Definition government.c:114
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:154
bool can_change_to_government(struct player *pplayer, const struct government *gov)
Definition government.c:180
Government_type_id government_number(const struct government *pgovern)
Definition government.c:91
const char * government_rule_name(const struct government *pgovern)
Definition government.c:133
static GtkWidget * persistent
GType type
Definition repodlgs.c:1313
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
void handicaps_init(struct player *pplayer)
Definition handicaps.c:29
void handicaps_close(struct player *pplayer)
Definition handicaps.c:42
@ H_REVOLUTION
Definition handicaps.h:30
@ H_RATES
Definition handicaps.h:23
struct impr_type * improvement_by_number(const Impr_type_id id)
bool wonder_visible_to_player(const struct impr_type *wonder, const struct player *pplayer, const struct player *owner, enum fc_tristate embassy)
#define WONDER_NOT_BUILT
#define B_LAST
Definition improvement.h:42
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert_ret(condition)
Definition log.h:192
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_normal(message,...)
Definition log.h:108
#define log_error(message,...)
Definition log.h:104
bool map_is_empty(void)
Definition map.c:148
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:397
#define square_iterate_end
Definition map.h:400
#define whole_map_iterate(_map, _tile)
Definition map.h:582
#define whole_map_iterate_end
Definition map.h:591
void player_map_init(struct player *pplayer)
Definition maphand.c:1236
void map_claim_base(struct tile *ptile, struct extra_type *pextra, struct player *powner, struct player *ploser)
Definition maphand.c:2366
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2181
void map_know_and_see_all(struct player *pplayer)
Definition maphand.c:1211
void give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:382
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1708
void player_map_free(struct player *pplayer)
Definition maphand.c:1252
void map_calculate_borders(void)
Definition maphand.c:2339
void remove_player_from_maps(struct player *pplayer)
Definition maphand.c:1273
bool give_distorted_map(struct player *pfrom, struct player *pto, int prob, bool reveal_cities)
Definition maphand.c:2662
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
enum mood_type player_mood(struct player *pplayer)
Definition mood.c:28
const char * multiplier_rule_name(const struct multiplier *pmul)
Multiplier_type_id multiplier_count(void)
Definition multipliers.c:88
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
static struct multiplier multipliers[MAX_NUM_MULTIPLIERS]
Definition multipliers.c:23
struct multiplier * multiplier_by_number(Multiplier_type_id id)
Definition multipliers.c:57
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
#define multipliers_iterate_end
Definition multipliers.h:67
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
Nation_type_id nation_count(void)
Definition nation.c:507
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:486
struct nation_leader * nation_leader_by_name(const struct nation_type *pnation, const char *name)
Definition nation.c:267
int nations_match(const struct nation_type *pnation1, const struct nation_type *pnation2, bool ignore_conflicts)
Definition nation.c:1206
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
int nation_set_index(const struct nation_set *pset)
Definition nation.c:699
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:200
const struct rgbcolor * nation_color(const struct nation_type *pnation)
Definition nation.c:682
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Definition nation.c:837
int nation_set_count(void)
Definition nation.c:691
struct nation_set * nation_set_by_number(int id)
Definition nation.c:762
struct nation_set * nation_set_by_setting_value(const char *setting)
Definition nation.c:859
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:498
const char * nation_set_rule_name(const struct nation_set *pset)
Definition nation.c:807
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:211
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:659
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:84
#define nation_sets_iterate_end
Definition nation.h:305
#define nation_sets_iterate(NAME_pset)
Definition nation.h:301
#define nations_iterate_end
Definition nation.h:336
#define nation_list_iterate_end
Definition nation.h:86
#define nations_iterate(NAME_pnation)
Definition nation.h:333
#define NATION_NONE
Definition nation.h:33
#define NO_NATION_SELECTED
Definition nation.h:30
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:238
void generic_handle_player_attribute_chunk(struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
Definition packets.c:697
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
Definition packets.c:753
#define web_send_packet(packetname, pconn,...)
Definition packets.h:56
int dsend_packet_player_remove(struct connection *pc, int playerno)
int send_packet_player_diplstate(struct connection *pc, const struct packet_player_diplstate *packet)
int send_packet_player_info(struct connection *pc, const struct packet_player_info *packet)
void lsend_packet_nation_availability(struct conn_list *dest, const struct packet_nation_availability *packet)
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:448
struct player * player_new(struct player_slot *pslot)
Definition player.c:493
struct player * player_by_number(const int player_id)
Definition player.c:849
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1480
int player_count(void)
Definition player.c:817
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Definition player.c:68
int player_slot_count(void)
Definition player.c:418
struct player_slot * player_slot_by_number(int player_id)
Definition player.c:463
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1286
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
void player_clear(struct player *pplayer, bool full)
Definition player.c:669
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:240
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:220
void player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition player.c:648
int player_index(const struct player *pplayer)
Definition player.c:829
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:861
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:98
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
bool gives_shared_tiles(const struct player *me, const struct player *them)
Definition player.c:1497
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1489
void player_destroy(struct player *pplayer)
Definition player.c:756
#define players_iterate_end
Definition player.h:542
dipl_reason
Definition player.h:192
@ DIPL_SENATE_BLOCKING
Definition player.h:193
@ DIPL_OK
Definition player.h:193
#define players_iterate(_pplayer)
Definition player.h:537
#define player_list_iterate(playerlist, pplayer)
Definition player.h:560
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#define is_ai(plr)
Definition player.h:232
#define player_list_iterate_end
Definition player.h:562
#define set_as_human(plr)
Definition player.h:233
#define players_iterate_alive_end
Definition player.h:552
@ PLRCOL_PLR_RANDOM
Definition player.h:54
@ PLRCOL_PLR_SET
Definition player.h:55
@ PLRCOL_NATION_ORDER
Definition player.h:57
@ PLRCOL_TEAM_ORDER
Definition player.h:56
@ PLRCOL_PLR_ORDER
Definition player.h:53
#define set_as_ai(plr)
Definition player.h:234
#define is_human(plr)
Definition player.h:231
#define players_iterate_alive(_pplayer)
Definition player.h:547
void handle_player_phase_done(struct player *pplayer, int turn)
Definition plrhand.c:3190
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2656
void handle_player_multiplier(struct player *pplayer, int count, const int *multipliers)
Definition plrhand.c:3406
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2271
int barbarian_count(void)
Definition plrhand.c:3210
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1132
static void send_player_remove_info_c(const struct player_slot *pslot, struct conn_list *dest)
Definition plrhand.c:1082
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1897
const struct rgbcolor * player_preferred_color(struct player *pplayer)
Definition plrhand.c:1676
void player_update_last_war_action(struct player *pplayer)
Definition plrhand.c:866
void handle_player_attribute_chunk(struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
Definition plrhand.c:3172
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3226
int normal_player_count(void)
Definition plrhand.c:3218
static void send_player_info_c_real(struct player *src, struct conn_list *dest)
Definition plrhand.c:1169
static enum plr_info_level player_info_level(struct player *plr, struct player *receiver)
Definition plrhand.c:1573
static void package_player_diplstate(struct player *plr1, struct player *plr2, struct packet_player_diplstate *packet_ds, struct player *receiver, enum plr_info_level min_info_level)
Definition plrhand.c:1530
void player_set_under_human_control(struct player *pplayer)
Definition plrhand.c:3467
static void maybe_claim_base(struct tile *ptile, struct player *new_owner, struct player *old_owner)
Definition plrhand.c:824
void playercolor_free(void)
Definition plrhand.c:3357
static struct nation_set * current_nationset(void)
Definition plrhand.c:2595
void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
Definition plrhand.c:1873
static int get_player_maxrate(struct player *pplayer)
Definition plrhand.c:269
static void call_first_contact(struct player *pplayer, struct player *aplayer)
Definition plrhand.c:1606
void player_limit_to_max_rates(struct player *pplayer)
Definition plrhand.c:2060
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2972
void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition plrhand.c:1826
void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
Definition plrhand.c:3445
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)
Definition plrhand.c:2171
bool player_delegation_active(const struct player *pplayer)
Definition plrhand.c:3280
void player_info_thaw(void)
Definition plrhand.c:1111
void player_info_freeze(void)
Definition plrhand.c:1102
struct player * player_by_user_delegated(const char *name)
Definition plrhand.c:3332
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2372
void handle_player_attribute_block(struct player *pplayer)
Definition plrhand.c:3182
static void send_nation_availability_real(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2640
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
Definition plrhand.c:2467
static enum diplstate_type get_default_diplstate(const struct player *pplayer1, const struct player *pplayer2)
Definition plrhand.c:2288
void playercolor_init(void)
Definition plrhand.c:3347
void check_player_max_rates(struct player *pplayer)
Definition plrhand.c:777
void kill_player(struct player *pplayer)
Definition plrhand.c:125
const char * player_color_ftstr(struct player *pplayer)
Definition plrhand.c:1846
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1149
void set_shuffled_players(int *shuffled_players)
Definition plrhand.c:2417
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:3017
static int shuffled_order[MAX_NUM_PLAYER_SLOTS]
Definition plrhand.c:114
void player_status_reset(struct player *plr)
Definition plrhand.c:3242
void send_delegation_info(const struct connection *pconn)
Definition plrhand.c:3288
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:566
void update_national_activities(struct player *pplayer, int old_gold)
Definition plrhand.c:3487
struct conn_list * player_reply_dest(struct player *pplayer)
Definition plrhand.c:1596
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)
Definition plrhand.c:805
static int revolentype_length(enum revolen_type rltype, struct government *gov)
Definition plrhand.c:515
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3234
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2924
struct rgbcolor * playercolor_get(int id)
Definition plrhand.c:3386
void player_delegation_set(struct player *pplayer, const char *username)
Definition plrhand.c:3264
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)
Definition plrhand.c:2109
int playercolor_count(void)
Definition plrhand.c:3396
void shuffle_players(void)
Definition plrhand.c:2392
static void package_player_info(struct player *plr, struct packet_player_info *packet, struct packet_web_player_info_addition *web_packet, struct player *receiver, enum plr_info_level min_info_level)
Definition plrhand.c:1327
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1946
void government_change(struct player *pplayer, struct government *gov, bool revolution_finished)
Definition plrhand.c:336
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1621
static void send_player_diplstate_c_real(struct player *src, struct conn_list *dest)
Definition plrhand.c:1231
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:883
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Definition plrhand.c:2306
void playercolor_add(struct rgbcolor *prgbcolor)
Definition plrhand.c:3376
void update_capital(struct player *pplayer)
Definition plrhand.c:732
void count_playable_nations(void)
Definition plrhand.c:2613
void handle_player_rates(struct player *pplayer, int tax, int luxury, int science)
Definition plrhand.c:285
bool player_color_changeable(const struct player *pplayer, const char **reason)
Definition plrhand.c:1719
void assign_player_colors(void)
Definition plrhand.c:1737
static void package_player_common(struct player *plr, struct packet_player_info *packet, struct packet_web_player_info_addition *web_packet)
Definition plrhand.c:1264
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2628
void send_player_diplstate_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1215
static struct player * split_player(struct player *pplayer)
Definition plrhand.c:2773
struct player * shuffled_player(int i)
Definition plrhand.c:2435
void player_loot_player(struct player *pvictor, struct player *pvictim)
Definition plrhand.c:410
const char * player_delegation_get(const struct player *pplayer)
Definition plrhand.c:3251
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2604
void enter_war(struct player *pplayer, struct player *pplayer2)
Definition plrhand.c:849
static int player_info_frozen_level
Definition plrhand.c:117
int revolution_length(struct government *gov, struct player *plr)
Definition plrhand.c:550
void fit_nationset_to_players(void)
Definition plrhand.c:2673
void reset_all_start_commands(bool plrchange)
Definition plrhand.c:2738
void update_revolution(struct player *pplayer)
Definition plrhand.c:673
plr_info_level
Definition plrhand.h:25
@ INFO_MEETING
Definition plrhand.h:25
@ INFO_MINIMUM
Definition plrhand.h:25
@ INFO_EMBASSY
Definition plrhand.h:25
@ INFO_FULL
Definition plrhand.h:25
#define allowed_nations_iterate(pnation)
Definition plrhand.h:69
#define allowed_nations_iterate_end
Definition plrhand.h:73
#define fc_rand(_size)
Definition rand.h:56
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Definition research.c:637
const char * research_advance_rule_name(const struct research *presearch, Tech_type_id tech)
Definition research.c:240
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1058
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
void research_update(struct research *presearch)
Definition research.c:501
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
bool rgbcolors_are_equal(const struct rgbcolor *c1, const struct rgbcolor *c2)
Definition rgbcolor.c:62
bool rgbcolor_to_hex(const struct rgbcolor *prgbcolor, char *hex, size_t hex_len)
Definition rgbcolor.c:142
#define rgbcolor_list_iterate_end
Definition rgbcolor.h:45
#define rgbcolor_list_iterate(rgbcolorlist, prgbcolor)
Definition rgbcolor.h:43
void script_server_signal_emit(const char *signal_name,...)
void script_server_remove_exported_object(void *object)
void array_shuffle(int *array, int n)
Definition shared.c:2020
bool is_ascii_name(const char *name)
Definition shared.c:286
void remove_leading_trailing_spaces(char *s)
Definition shared.c:444
@ TRI_YES
Definition shared.h:46
@ TRI_NO
Definition shared.h:46
#define CLIP(lower, current, upper)
Definition shared.h:57
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
#define MAX(x, y)
Definition shared.h:54
void send_spaceship_info(struct player *src, struct conn_list *dest)
Definition spacerace.c:129
void spaceship_init(struct player_spaceship *ship)
Definition spaceship.c:96
#define DEFAULT_SPECIALIST
Definition specialist.h:43
struct sprite int x
Definition sprite_g.h:31
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2667
bool game_was_started(void)
Definition srv_main.c:356
void check_for_full_turn_done(void)
Definition srv_main.c:2302
enum server_states server_state(void)
Definition srv_main.c:340
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:2000
Definition city.h:317
enum capital_type capital
Definition city.h:325
int contactturns
Definition game.h:144
struct rgbcolor_list * plr_colors
Definition game.h:252
char start_units[MAX_LEN_STARTUNIT]
Definition game.h:196
enum plrcolor_mode plrcolormode
Definition game.h:135
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
struct packet_scenario_info scenario
Definition game.h:87
unsigned revealmap
Definition game.h:184
int civilwarsize
Definition game.h:142
bool savepalace
Definition game.h:194
char nationset[MAX_LEN_NAME]
Definition game.h:164
struct civ_game::@32::@36 server
int max_players
Definition game.h:163
int revolution_length
Definition game.h:185
struct government * government_during_revolution
Definition game.h:94
enum cmdlevel access_level
Definition connection.h:177
struct conn_list * self
Definition connection.h:163
int changed_to_times
Definition government.h:64
enum barbarian_type barb_type
Definition nation.h:110
bool no_startpos
Definition nation.h:148
struct nation_type::@54::@56 server
enum gameloss_style gameloss_style
enum gold_upkeep_style gold_upkeep_style
enum ai_level skill_level
enum revolen_type revolentype
enum persistent_ready persistent_ready
bool is_pickable[MAX_NUM_NATIONS]
enum ai_level ai_skill_level
int multiplier[MAX_NUM_MULTIPLIERS]
char username[MAX_LEN_NAME]
bv_plr_flags flags
enum mood_type mood
bv_player gives_shared_vision
int love[MAX_NUM_PLAYER_SLOTS]
Government_type_id target_government
int multiplier_target[MAX_NUM_MULTIPLIERS]
int multiplier_changed[MAX_NUM_MULTIPLIERS]
bv_player gives_shared_tiles
Nation_type_id nation
enum barbarian_type barbarian_type
char name[MAX_LEN_NAME]
Government_type_id government
bv_player real_embassy
int wonders[B_LAST]
enum ai_level skill_level
Definition player.h:116
enum barbarian_type barbarian_type
Definition player.h:122
int warmth
Definition player.h:121
int science_cost
Definition player.h:119
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:124
int maxbuycost
Definition player.h:114
int frost
Definition player.h:121
char contact_turns_left
Definition player.h:204
enum diplstate_type type
Definition player.h:199
char has_reason_to_cancel
Definition player.h:203
int infra_points
Definition player.h:67
int units_killed
Definition player.h:105
int units_used
Definition player.h:108
int units_lost
Definition player.h:106
int units_built
Definition player.h:104
struct city_list * cities
Definition player.h:281
struct player_ai ai_common
Definition player.h:288
bv_plr_flags flags
Definition player.h:292
bv_pstatus status
Definition player.h:322
int primary_capital_id
Definition player.h:275
bool is_male
Definition player.h:257
int wonders[B_LAST]
Definition player.h:305
struct government * target_government
Definition player.h:259
int autoselect_weight
Definition player.h:299
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_connected
Definition player.h:296
int revolution_finishes
Definition player.h:273
int nturns_idle
Definition player.h:265
struct government * government
Definition player.h:258
struct connection * current_conn
Definition player.h:297
struct team * team
Definition player.h:261
char * savegame_ai_type_name
Definition player.h:290
int turns_alive
Definition player.h:266
bool was_created
Definition player.h:294
const struct ai_type * ai
Definition player.h:289
struct unit_list * units
Definition player.h:282
struct conn_list * connections
Definition player.h:298
bool is_alive
Definition player.h:268
bv_player real_embassy
Definition player.h:277
struct player::@73::@75 server
struct player_economic economic
Definition player.h:284
char delegate_to[MAX_LEN_NAME]
Definition player.h:339
struct player_spaceship spaceship
Definition player.h:286
char name[MAX_LEN_NAME]
Definition player.h:251
bv_player gives_shared_vision
Definition player.h:302
struct player_score score
Definition player.h:283
struct player_tile * private_map
Definition player.h:324
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:314
bv_player really_gives_vision
Definition player.h:329
struct nation_type * nation
Definition player.h:260
struct nation_style * style
Definition player.h:279
bool border_vision
Definition player.h:327
bool phase_done
Definition player.h:263
struct player_slot * slot
Definition player.h:250
bv_player gives_shared_tiles
Definition player.h:304
bool is_ready
Definition player.h:262
int history
Definition player.h:316
bv_debug debug
Definition player.h:332
char orig_username[MAX_LEN_NAME]
Definition player.h:347
int last_war_action
Definition player.h:270
struct rgbcolor * rgb
Definition player.h:312
bool unassigned_user
Definition player.h:253
Tech_type_id researching_saved
Definition research.h:62
int g
Definition rgbcolor.h:34
int b
Definition rgbcolor.h:34
int r
Definition rgbcolor.h:34
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
struct player * extras_owner
Definition tile.h:63
int upkeep[O_LAST]
Definition unit.h:149
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:141
int upkeep_paid[O_LAST]
Definition unit.h:258
struct civ_map map
struct music_style * player_music_style(struct player *plr)
Definition style.c:185
int music_style_number(const struct music_style *pms)
Definition style.c:161
int style_number(const struct nation_style *pstyle)
Definition style.c:68
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
char fc_toupper(char c)
Definition support.c:1262
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define fc__fallthrough
Definition support.h:119
int team_count(void)
Definition team.c:376
int team_number(const struct team *pteam)
Definition team.c:392
bool team_add_player(struct player *pplayer, struct team *pteam)
Definition team.c:468
const struct player_list * team_members(const struct team *pteam)
Definition team.c:457
#define advance_index_iterate_end
Definition tech.h:244
#define A_NONE
Definition tech.h:43
#define A_UNSET
Definition tech.h:48
#define A_UNKNOWN
Definition tech.h:49
#define advance_index_iterate(_start, _index)
Definition tech.h:240
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1306
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech, bool free_bulbs)
Definition techtools.c:726
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:215
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_owner(_tile)
Definition tile.h:97
#define trade_routes_iterate_safe_end
#define trade_routes_iterate_safe(c, proute)
#define unit_owner(_pu)
Definition unit.h:405
#define is_unit_homeless(_pu_)
Definition unit.h:404
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
struct unit_list * get_units_seen_via_ally(const struct player *pplayer, const struct player *aplayer)
Definition unittools.c:1422
void remove_allied_visibility(struct player *pplayer, struct player *aplayer, const struct unit_list *seen_units)
Definition unittools.c:1457
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1407
struct unit * create_unit(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left)
Definition unittools.c:1611
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2145
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:194
void send_updated_vote_totals(struct conn_list *dest)
Definition voting.c:866