Freeciv-3.1
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 "tech.h"
43#include "unitlist.h"
44
45/* common/scriptcore */
46#include "luascript_types.h"
47
48/* server */
49#include "aiiface.h"
50#include "barbarian.h"
51#include "citytools.h"
52#include "cityturn.h"
53#include "connecthand.h"
54#include "diplhand.h"
55#include "gamehand.h"
56#include "maphand.h"
57#include "mood.h"
58#include "notify.h"
59#include "plrhand.h"
60#include "sernet.h"
61#include "srv_main.h"
62#include "stdinhand.h"
63#include "spaceship.h"
64#include "spacerace.h"
65#include "techtools.h"
66#include "unittools.h"
67#include "voting.h"
68
69/* server/advisors */
70#include "advdata.h"
71#include "autosettlers.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,
87 web_packet);
88
89static void package_player_diplstate(struct player *plr1,
90 struct player *plr2,
91 struct packet_player_diplstate *packet_ds,
92 struct player *receiver,
93 enum plr_info_level min_info_level);
94static void package_player_info(struct player *plr,
95 struct packet_player_info *packet,
97 web_packet,
98 struct player *receiver,
99 enum plr_info_level min_info_level);
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 = NULL;
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. */
136 players_iterate(aplayer) {
137 if (gives_shared_vision(pplayer, aplayer)) {
138 remove_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. */
146 if (game.server.revealmap & REVEAL_MAP_DEAD) {
147 bool someone_alive = FALSE;
148
149 player_list_iterate(team_members(pplayer->team), pteam_member) {
150 if (pteam_member->is_alive) {
151 someone_alive = TRUE;
152 break;
153 }
155
156 if (!someone_alive) {
157 player_list_iterate(team_members(pplayer->team), pteam_member) {
158 map_know_and_see_all(pteam_member);
160 }
161 }
162
163 if (!is_barbarian(pplayer)) {
164 notify_player(NULL, NULL, 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 */
171 save_palace = game.server.savepalace;
172 game.server.savepalace = FALSE; /* Moving it around is dumb */
173 city_list_iterate_safe(pplayer->cities, pcity) {
174 if (pcity->original != pplayer && pcity->original != NULL
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 }
186 game.server.savepalace = save_palace;
187
188 /* let there be civil war */
189 if (game.info.gameloss_style & GAMELOSS_STYLE_CWAR) {
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
204 if (game.info.gameloss_style & GAMELOSS_STYLE_BARB) {
205 /* if parameter, create a barbarian, if possible */
206 barbarians = create_barbarian_player(LAND_BARBARIAN);
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 */
213 bool palace = game.server.savepalace;
214
216
217 log_verbose("Barbarians take the empire of %s", pplayer->name);
218 adv_data_phase_init(barbarians, TRUE);
219
220 /* Transfer any remaining cities */
221 city_list_iterate_safe(pplayer->cities, pcity) {
222 if (transfer_city(barbarians, pcity, -1, FALSE, FALSE, FALSE,
223 FALSE)) {
224 script_server_signal_emit("city_transferred", pcity, pplayer,
225 barbarians, "death-barbarians_get");
226 }
228
229 game.server.savepalace = palace;
230
231 resolve_unit_stacks(pplayer, barbarians, FALSE);
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) {
239 remove_city(pcity);
241 }
242
243 /* Remove all units that are still ours */
245 wipe_unit(punit, ULR_PLAYER_DIED, NULL);
247
248 /* Remove ownership of tiles */
249 whole_map_iterate(&(wld.map), ptile) {
250 if (tile_owner(ptile) == pplayer) {
251 map_claim_ownership(ptile, NULL, NULL, FALSE);
252 }
253 if (extra_owner(ptile) == pplayer) {
254 ptile->extras_owner = NULL;
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, NULL);
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, NULL, 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, NULL, 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,
337 bool revolution_finished)
338{
339 struct research *presearch;
340
341 if (revolution_finished) {
344 && NULL != pplayer->target_government);
346
347 gov->changed_to_times++;
348 }
349
350 pplayer->government = gov;
351 pplayer->target_government = NULL;
352
353 if (revolution_finished) {
354 log_debug("Revolution finished for %s. Government is %s. "
355 "Revofin %d (%d).", player_name(pplayer),
358 }
359
360 notify_player(pplayer, NULL, 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, NULL, 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%%."),
388 save_tax, save_luxury, save_science,
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);
399 research_update(presearch);
400 send_research_info(presearch, NULL);
401}
402
403/**********************************************************************/
410static int revolentype_length(enum revolen_type rltype,
411 struct government *gov)
412{
413 int max_turns;
414
415 switch (rltype) {
416 case REVOLEN_FIXED:
418 case REVOLEN_RANDOM:
423 max_turns = MAX(1, max_turns);
425 return fc_rand(max_turns) + 1;
426 }
427 return max_turns;
428 }
429
431
433}
434
435/**********************************************************************/
438int revolution_length(struct government *gov, struct player *plr)
439{
442 /* Targetless revolution not acceptable */
443 notify_player(plr, NULL, E_REVOLT_DONE, ftc_server,
444 _("You can't revolt without selecting target government."));
445 return -1;
446 }
447
449}
450
451/**********************************************************************/
456{
457 int turns;
459 bool anarchy;
460
461 if (!gov || !can_change_to_government(pplayer, gov)) {
462 return;
463 }
464
465 log_debug("Government changed for %s. Target government is %s; "
466 "old %s. Revofin %d, Turn %d.", player_name(pplayer),
470
471 anarchy = get_player_bonus(pplayer, EFT_NO_ANARCHY) <= 0;
472
473 /* Set revolution_finishes value. */
474 if (pplayer->revolution_finishes > 0) {
475 /* Player already has an active revolution. Note that the finish time
476 * may be in the future (we're waiting for it to finish), the current
477 * turn (it just finished - but isn't reset until the end of the turn)
478 * or even in the past (if the player is in anarchy and hasn't chosen
479 * a government). */
480 turns = pplayer->revolution_finishes - game.info.turn;
481 } else if ((is_ai(pplayer) && !has_handicap(pplayer, H_REVOLUTION))
482 || !anarchy) {
483 /* AI players without the H_REVOLUTION handicap can skip anarchy */
484 anarchy = FALSE;
485 turns = 0;
486 } else {
487 turns = revolution_length(gov, pplayer);
488 if (turns < 0) {
489 return;
490 }
491 }
492
493 if (anarchy && turns <= 0
495 /* Multiple changes attempted after single anarchy period */
498 notify_player(pplayer, NULL, E_REVOLT_DONE, ftc_server,
499 _("You can't revolt the same turn you finished previous revolution."));
500 return;
501 }
502 }
503
505 pplayer->target_government = gov;
506 pplayer->revolution_finishes = game.info.turn + turns;
507
508 log_debug("Revolution started for %s. Target government is %s. "
509 "Revofin %d (%d).", player_name(pplayer),
512
513 /* Now see if the revolution is instantaneous. */
514 if (turns <= 0
516 government_change(pplayer, pplayer->target_government, TRUE);
517 return;
518 } else if (turns > 0) {
519 notify_player(pplayer, NULL, E_REVOLT_START, ftc_server,
520 /* TRANS: this is a message event so don't make it
521 * too long. */
522 PL_("The %s have incited a revolt! "
523 "%d turn of anarchy will ensue! "
524 "Target government is %s.",
525 "The %s have incited a revolt! "
526 "%d turns of anarchy will ensue! "
527 "Target government is %s.",
528 turns),
530 turns,
532 } else {
534 notify_player(pplayer, NULL, E_REVOLT_START, ftc_server,
535 _("Revolution: returning to anarchy."));
536 }
537
538 check_player_max_rates(pplayer);
540 send_player_info_c(pplayer, pplayer->connections);
541
542 log_debug("Government change complete for %s. Target government is %s; "
543 "now %s. Turn %d; revofin %d.", player_name(pplayer),
547}
548
549/**********************************************************************/
553void update_revolution(struct player *pplayer)
554{
555 struct government *current_gov;
556
557 /* The player's revolution counter is stored in the revolution_finishes
558 * field. This value has the following meanings:
559 * - If negative (-1), then the player is not in a revolution. In this
560 * case the player should never be in anarchy.
561 * - If positive, the player is in the middle of a revolution. In this
562 * case the value indicates the turn in which the revolution finishes.
563 * * If this value is > than the current turn, then the revolution is
564 * in progress. In this case the player should always be in anarchy.
565 * * If the value is == to the current turn, then the revolution is
566 * finished. The player may now choose a government. However the
567 * value isn't reset until the end of the turn. If the player has
568 * chosen a government by the end of the turn, then the revolution is
569 * over and the value is reset to -1.
570 * * If the player doesn't pick a government then the revolution
571 * continues. At this point the value is <= to the current turn,
572 * and the player can leave the revolution at any time. The value
573 * is reset at the end of any turn when a non-anarchy government is
574 * chosen.
575 */
576 log_debug("Update revolution for %s. Current government %s, "
577 "target %s, revofin %d, turn %d.", player_name(pplayer),
579 pplayer->target_government
580 ? government_rule_name(pplayer->target_government) : "(none)",
582
583 current_gov = government_of_player(pplayer);
584
585 if (current_gov == game.government_during_revolution
586 && pplayer->revolution_finishes <= game.info.turn) {
588 /* If the revolution is over and a target government is set, go into
589 * the new government. */
590 log_debug("Update: finishing revolution for %s.", player_name(pplayer));
591 government_change(pplayer, pplayer->target_government, TRUE);
592 } else {
593 /* If the revolution is over but there's no target government set,
594 * alert the player. */
595 notify_player(pplayer, NULL, E_REVOLT_DONE, ftc_any,
596 _("You should choose a new government from the "
597 "government menu."));
598 }
600 && pplayer->revolution_finishes < game.info.turn) {
601 /* Reset the revolution counter. If the player has another revolution
602 * they'll have to re-enter anarchy. */
603 log_debug("Update: resetting revofin for %s.", player_name(pplayer));
604 pplayer->revolution_finishes = -1;
605 send_player_info_c(pplayer, pplayer->connections);
606 }
607}
608
609/**********************************************************************/
612void update_capital(struct player *pplayer)
613{
614 int max_value = 0;
615 struct city *primary_capital = NULL;
616 int same_value_count = 0;
617
618 city_list_iterate(pplayer->cities, pcity) {
619 int value = get_city_bonus(pcity, EFT_CAPITAL_CITY);
620
621 if (value > max_value) {
622 max_value = value;
623 primary_capital = pcity;
624 same_value_count = 1;
625 /* Mark it at least some kind of capital, might turn to named capital
626 * after all have been processed. */
627 pcity->capital = CAPITAL_SECONDARY;
628 } else if (value > 0) {
629 /* Mark it at least some kind of capital. */
630 pcity->capital = CAPITAL_SECONDARY;
631 if (value == max_value) {
632 fc_assert(same_value_count >= 1);
633 same_value_count++;
634 if (fc_rand(same_value_count) == 1) {
635 primary_capital = pcity;
636 }
637 }
638 } else {
639 /* Not capital at all */
640 pcity->capital = CAPITAL_NOT;
641 }
643
644 if (primary_capital != NULL) {
645 primary_capital->capital = CAPITAL_PRIMARY;
646 pplayer->primary_capital_id = primary_capital->id;
647 } else {
648 pplayer->primary_capital_id = 0;
649 }
650}
651
652/**********************************************************************/
657void check_player_max_rates(struct player *pplayer)
658{
659 struct player_economic old_econ = pplayer->economic;
660
662 if (old_econ.tax > pplayer->economic.tax) {
663 notify_player(pplayer, NULL, E_NEW_GOVERNMENT, ftc_server,
664 _("Tax rate exceeded the max rate; adjusted."));
665 }
666 if (old_econ.science > pplayer->economic.science) {
667 notify_player(pplayer, NULL, E_NEW_GOVERNMENT, ftc_server,
668 _("Science rate exceeded the max rate; adjusted."));
669 }
670 if (old_econ.luxury > pplayer->economic.luxury) {
671 notify_player(pplayer, NULL, E_NEW_GOVERNMENT, ftc_server,
672 _("Luxury rate exceeded the max rate; adjusted."));
673 }
674}
675
676/**********************************************************************/
686 struct player *pplayer2,
687 const struct unit_list
688 *pplayer_seen_units,
689 const struct unit_list
690 *pplayer2_seen_units)
691{
692 /* The client needs updated diplomatic state, because it is used
693 * during calculation of new states of occupied flags in cities */
694 send_player_all_c(pplayer, NULL);
695 send_player_all_c(pplayer2, NULL);
696 remove_allied_visibility(pplayer, pplayer2, pplayer_seen_units);
697 remove_allied_visibility(pplayer2, pplayer, pplayer2_seen_units);
698 resolve_unit_stacks(pplayer, pplayer2, TRUE);
699}
700
701/**********************************************************************/
704static void maybe_claim_base(struct tile *ptile, struct player *new_owner,
705 struct player *old_owner)
706{
707 bool claim = FALSE;
708
709 unit_list_iterate(ptile->units, punit) {
710 if (unit_owner(punit) == new_owner
712 claim = TRUE;
713 break;
714 }
716
717 if (claim) {
718 extra_type_by_cause_iterate(EC_BASE, pextra) {
719 map_claim_base(ptile, pextra, new_owner, old_owner);
721
722 ptile->extras_owner = new_owner;
723 }
724}
725
726/**********************************************************************/
729void enter_war(struct player *pplayer, struct player *pplayer2)
730{
731 /* Claim bases where units are already standing */
732 whole_map_iterate(&(wld.map), ptile) {
733 struct player *old_owner = extra_owner(ptile);
734
735 if (old_owner == pplayer2) {
736 maybe_claim_base(ptile, pplayer, old_owner);
737 } else if (old_owner == pplayer) {
738 maybe_claim_base(ptile, pplayer2, old_owner);
739 }
741}
742
743/**********************************************************************/
747{
748 pplayer->last_war_action = game.info.turn;
749 send_player_info_c(pplayer, NULL);
750}
751
752/**********************************************************************/
762 int other_player_id,
763 enum clause_type clause)
764{
765 enum diplstate_type old_type;
766 enum diplstate_type new_type;
767 enum dipl_reason diplcheck;
768 bool repeat = FALSE;
769 struct player *pplayer2 = player_by_number(other_player_id);
770 struct player_diplstate *ds_plrplr2, *ds_plr2plr;
771 struct unit_list *pplayer_seen_units, *pplayer2_seen_units;
772
773 if (NULL == pplayer2 || players_on_same_team(pplayer, pplayer2)) {
774 return;
775 }
776
777 old_type = player_diplstate_get(pplayer, pplayer2)->type;
778
779 if (clause == CLAUSE_VISION) {
780 if (!gives_shared_vision(pplayer, pplayer2)) {
781 return;
782 }
783 remove_shared_vision(pplayer, pplayer2);
784 notify_player(pplayer2, NULL, E_TREATY_BROKEN, ftc_server,
785 _("%s no longer gives us shared vision!"),
786 player_name(pplayer));
787 return;
788 }
789
790 diplcheck = pplayer_can_cancel_treaty(pplayer, pplayer2);
791
792 /* The senate may not allow you to break the treaty. In this case you
793 * must first dissolve the senate then you can break it. */
794 if (diplcheck == DIPL_SENATE_BLOCKING) {
795 notify_player(pplayer, NULL, E_TREATY_BROKEN, ftc_server,
796 _("The senate will not allow you to break treaty "
797 "with the %s. You must either dissolve the senate "
798 "or wait until a more timely moment."),
799 nation_plural_for_player(pplayer2));
800 return;
801 }
802
803 if (diplcheck != DIPL_OK) {
804 return;
805 }
806
807 reject_all_treaties(pplayer);
808 reject_all_treaties(pplayer2);
809 /* else, breaking a treaty */
810
811 /* check what the new status will be */
812 new_type = cancel_pact_result(old_type);
813
814 ds_plrplr2 = player_diplstate_get(pplayer, pplayer2);
815 ds_plr2plr = player_diplstate_get(pplayer2, pplayer);
816
817 if (old_type == DS_ALLIANCE) {
818 pplayer_seen_units = get_units_seen_via_ally(pplayer, pplayer2);
819 pplayer2_seen_units = get_units_seen_via_ally(pplayer2, pplayer);
820 } else {
821 pplayer_seen_units = NULL;
822 pplayer2_seen_units = NULL;
823 }
824
825 /* do the change */
826 ds_plrplr2->type = ds_plr2plr->type = new_type;
827 ds_plrplr2->turns_left = ds_plr2plr->turns_left = 16;
828
829 if (new_type == DS_WAR) {
832 }
833
834 /* If the old state was alliance, the players' units can share tiles
835 illegally, and we need to call resolve_unit_stacks() */
836 if (old_type == DS_ALLIANCE) {
837
838 fc_assert(pplayer_seen_units != NULL);
839 fc_assert(pplayer2_seen_units != NULL);
840
842 pplayer_seen_units,
843 pplayer2_seen_units);
844 unit_list_destroy(pplayer_seen_units);
845 unit_list_destroy(pplayer2_seen_units);
846 }
847
848 /* if there's a reason to cancel the pact, do it without penalty */
849 /* FIXME: in the current implementation if you break more than one
850 * treaty simultaneously it may success partially: the first treaty-breaking
851 * will happen but the second one will fail. */
852 if (get_player_bonus(pplayer, EFT_HAS_SENATE) > 0 && !repeat) {
853 if (ds_plrplr2->has_reason_to_cancel > 0) {
854 notify_player(pplayer, NULL, E_TREATY_BROKEN, ftc_server,
855 _("The senate passes your bill because of the "
856 "constant provocations of the %s."),
857 nation_plural_for_player(pplayer2));
858 } else if (new_type == DS_WAR) {
859 notify_player(pplayer, NULL, E_TREATY_BROKEN, ftc_server,
860 _("The senate refuses to break treaty with the %s, "
861 "but you have no trouble finding a new senate."),
862 nation_plural_for_player(pplayer2));
863 }
864 }
865 if (new_type == DS_WAR) {
866 call_incident(INCIDENT_WAR, CBR_VICTIM_ONLY, NULL, pplayer, pplayer2);
867
868 enter_war(pplayer, pplayer2);
869 }
870 ds_plrplr2->has_reason_to_cancel = 0;
871
872 send_player_all_c(pplayer, NULL);
873 send_player_all_c(pplayer2, NULL);
874
875 /*
876 * Refresh all cities which have a unit of the other side within
877 * city range.
878 */
881 sync_cities();
882
883 notify_player(pplayer, NULL, E_TREATY_BROKEN, ftc_server,
884 _("The diplomatic state between the %s "
885 "and the %s is now %s."),
887 nation_plural_for_player(pplayer2),
888 diplstate_type_translated_name(new_type));
889 notify_player(pplayer2, NULL, E_TREATY_BROKEN, ftc_server,
890 _(" %s canceled the diplomatic agreement! "
891 "The diplomatic state between the %s and the %s "
892 "is now %s."),
893 player_name(pplayer),
894 nation_plural_for_player(pplayer2),
896 diplstate_type_translated_name(new_type));
897
898 /* Check fall-out of a war declaration. */
899 players_iterate_alive(other) {
900 if (other != pplayer && other != pplayer2
901 && new_type == DS_WAR && pplayers_allied(pplayer2, other)
902 && pplayers_allied(pplayer, other)) {
903 if (!players_on_same_team(pplayer, other)) {
904 /* If an ally declares war on another ally, break off your alliance
905 * to the aggressor. This prevents in-alliance wars, which are not
906 * permitted. */
907 notify_player(other, NULL, E_TREATY_BROKEN, ftc_server,
908 _("%s has attacked your ally %s! "
909 "You cancel your alliance to the aggressor."),
910 player_name(pplayer),
911 player_name(pplayer2));
912 player_diplstate_get(other, pplayer)->has_reason_to_cancel = 1;
915 CLAUSE_ALLIANCE);
916 } else {
917 /* We are in the same team as the agressor; we cannot break
918 * alliance with them. We trust our team mate and break alliance
919 * with the attacked player */
920 notify_player(other, NULL, E_TREATY_BROKEN, ftc_server,
921 _("Your team mate %s declared war on %s. "
922 "You are obligated to cancel alliance with %s."),
923 player_name(pplayer),
924 nation_plural_for_player(pplayer2),
925 player_name(pplayer2));
926 handle_diplomacy_cancel_pact(other, player_number(pplayer2), CLAUSE_ALLIANCE);
927 }
928 }
930}
931
932/**********************************************************************/
935static void send_player_remove_info_c(const struct player_slot *pslot,
936 struct conn_list *dest)
937{
938 if (!dest) {
939 dest = game.est_connections;
940 }
941
943
944 conn_list_iterate(dest, pconn) {
947}
948
949/**********************************************************************/
959
960/**********************************************************************/
972
973/**********************************************************************/
983void send_player_all_c(struct player *src, struct conn_list *dest)
984{
985 send_player_info_c(src, dest);
986 send_player_diplstate_c(src, dest);
987}
988
989/**********************************************************************/
1000void send_player_info_c(struct player *src, struct conn_list *dest)
1001{
1002 if (0 < player_info_frozen_level) {
1003 return; /* Discard, see comment for player_info_freeze(). */
1004 }
1005
1006 if (src != NULL) {
1007 send_player_info_c_real(src, dest);
1008 return;
1009 }
1010
1011 players_iterate(pplayer) {
1012 send_player_info_c_real(pplayer, dest);
1014}
1015
1016/**********************************************************************/
1020static void send_player_info_c_real(struct player *src,
1021 struct conn_list *dest)
1022{
1023 struct packet_player_info info;
1024 struct packet_web_player_info_addition web_info;
1025
1026 fc_assert_ret(src != NULL);
1027
1028 if (!dest) {
1029 dest = game.est_connections;
1030 }
1031
1032 package_player_common(src, &info, &web_info);
1033
1034 conn_list_iterate(dest, pconn) {
1035 if (NULL == pconn->playing && pconn->observer) {
1036 /* Global observer. */
1037 package_player_info(src, &info, &web_info, pconn->playing, INFO_FULL);
1038 } else if (NULL != pconn->playing) {
1039 /* Players (including regular observers) */
1040 package_player_info(src, &info, &web_info,
1041 pconn->playing, INFO_MINIMUM);
1042 } else {
1043 package_player_info(src, &info, &web_info, NULL, INFO_MINIMUM);
1044 }
1045 send_packet_player_info(pconn, &info);
1046 web_send_packet(player_info_addition, pconn, &web_info);
1048}
1049
1050/**********************************************************************/
1059void send_player_diplstate_c(struct player *src, struct conn_list *dest)
1060{
1061 if (src != NULL) {
1063 return;
1064 }
1065
1066 players_iterate(pplayer) {
1067 send_player_diplstate_c_real(pplayer, dest);
1069}
1070
1071/**********************************************************************/
1075static void send_player_diplstate_c_real(struct player *plr1,
1076 struct conn_list *dest)
1077{
1078 fc_assert_ret(plr1 != NULL);
1079
1080 if (!dest) {
1081 dest = game.est_connections;
1082 }
1083
1084 conn_list_iterate(dest, pconn) {
1085 players_iterate(plr2) {
1086 struct packet_player_diplstate packet_ds;
1087
1088 if (NULL == pconn->playing && pconn->observer) {
1089 /* Global observer. */
1090 package_player_diplstate(plr1, plr2, &packet_ds, pconn->playing,
1091 INFO_FULL);
1092 } else if (NULL != pconn->playing) {
1093 /* Players (including regular observers) */
1094 package_player_diplstate(plr1, plr2, &packet_ds, pconn->playing,
1095 INFO_MINIMUM);
1096 } else {
1097 package_player_diplstate(plr1, plr2, &packet_ds, NULL,
1098 INFO_MINIMUM);
1099 }
1100 send_packet_player_diplstate(pconn, &packet_ds);
1103}
1104
1105/**********************************************************************/
1108static void package_player_common(struct player *plr,
1109 struct packet_player_info *packet,
1111 web_packet)
1112{
1113 int i;
1114 struct music_style *music;
1115
1116 packet->playerno = player_number(plr);
1117 sz_strlcpy(packet->name, player_name(plr));
1118 sz_strlcpy(packet->username, plr->username);
1119 packet->unassigned_user = plr->unassigned_user;
1120 packet->nation = plr->nation ? nation_number(plr->nation) : NATION_NONE;
1121 packet->is_male = plr->is_male;
1122 packet->team = plr->team ? team_number(plr->team) : team_count();
1123 packet->is_ready = plr->is_ready;
1124 packet->was_created = plr->was_created;
1125 packet->style = plr->style ? style_number(plr->style) : 0;
1126
1127 /* I think we could safely move the music style selection to
1128 * client side to not have it burden server side. Client could
1129 * actually avoid it completely when music disabled from the client options.
1130 * Client has no use for music styles of other players, and there should
1131 * be no such information about the player themself needed to determine
1132 * the music style that client does not know. */
1133 music = player_music_style(plr);
1134 if (music != NULL) {
1135 packet->music_style = music_style_number(music);
1136 } else {
1137 packet->music_style = -1; /* No music style available */
1138 }
1139
1140 packet->is_alive = plr->is_alive;
1141 packet->turns_alive = plr->turns_alive;
1142 packet->is_connected = plr->is_connected;
1143 packet->flags = plr->flags;
1144 packet->ai_skill_level = is_ai(plr)
1145 ? plr->ai_common.skill_level : 0;
1146 for (i = 0; i < player_slot_count(); i++) {
1147 packet->love[i] = plr->ai_common.love[i];
1148 }
1150
1151 packet->phase_done = plr->phase_done;
1152 packet->nturns_idle = plr->nturns_idle;
1153 packet->science_cost = plr->ai_common.science_cost;
1154
1155#ifdef FREECIV_WEB
1156 web_packet->playerno = player_number(plr);
1157#endif /* FREECIV_WEB */
1158}
1159
1160/**********************************************************************/
1169static void package_player_info(struct player *plr,
1170 struct packet_player_info *packet,
1172 web_packet,
1173 struct player *receiver,
1174 enum plr_info_level min_info_level)
1175{
1176 enum plr_info_level info_level;
1177 enum plr_info_level highest_team_level;
1178 struct government *pgov = NULL;
1179 Impr_type_id imp;
1180
1181 if (receiver) {
1182 info_level = player_info_level(plr, receiver);
1183 info_level = MAX(min_info_level, info_level);
1184 } else {
1185 info_level = min_info_level;
1186 }
1187
1188 /* multipliers */
1189 packet->multip_count = multiplier_count();
1190 if (info_level >= INFO_FULL) {
1191 multipliers_iterate(pmul) {
1192 int idx = multiplier_index(pmul);
1193
1194 packet->multiplier[idx] = plr->multipliers[idx].value;
1195 packet->multiplier_target[idx] = plr->multipliers[idx].target;
1196 packet->multiplier_changed[idx] = plr->multipliers[idx].changed;
1198 } else {
1199 multipliers_iterate(pmul) {
1200 int idx = multiplier_index(pmul);
1201
1202 packet->multiplier[idx] = 0;
1203 packet->multiplier_target[idx] = 0;
1204 packet->multiplier_changed[idx] = 0;
1206 }
1207
1208 /* We need to send all tech info for all players on the same
1209 * team, even if they are not in contact yet; otherwise we will
1210 * overwrite team research or confuse the client. */
1211 highest_team_level = info_level;
1212 players_iterate(aplayer) {
1213 if (players_on_same_team(plr, aplayer) && receiver) {
1214 highest_team_level = MAX(highest_team_level,
1215 player_info_level(aplayer, receiver));
1216 }
1218
1219 if (plr->rgb != NULL) {
1220 packet->color_valid = TRUE;
1221 packet->color_red = plr->rgb->r;
1222 packet->color_green = plr->rgb->g;
1223 packet->color_blue = plr->rgb->b;
1224 } else {
1225 /* In pregame, send the color we expect to use, for consistency with
1226 * '/list colors' etc. */
1227 const struct rgbcolor *preferred = player_preferred_color(plr);
1228
1229 if (preferred != NULL) {
1230 packet->color_valid = TRUE;
1231 packet->color_red = preferred->r;
1232 packet->color_green = preferred->g;
1233 packet->color_blue = preferred->b;
1234 } else {
1235 fc_assert(game.info.turn < 1); /* Game has not yet started */
1236 packet->color_valid = FALSE;
1237 /* Client shouldn't use these dummy values */
1238 packet->color_red = 0;
1239 packet->color_green = 0;
1240 packet->color_blue = 0;
1241 }
1242 }
1243 packet->color_changeable = player_color_changeable(plr, NULL);
1244
1245 /* Only send score if we have contact */
1246 if (info_level >= INFO_MEETING) {
1247 packet->score = plr->score.game;
1248 } else {
1249 packet->score = -1;
1250 }
1251
1252 if (info_level >= INFO_MEETING) {
1253 packet->gold = plr->economic.gold;
1254 pgov = government_of_player(plr);
1255 } else {
1256 packet->gold = 0;
1258 }
1259 packet->government = pgov ? government_number(pgov) : government_count();
1260
1261 /* Send diplomatic status of the player to everyone they are in
1262 * contact with. */
1263 if (info_level >= INFO_EMBASSY
1264 || (receiver
1265 && player_diplstate_get(receiver, plr)->contact_turns_left > 0)) {
1268 : government_count();
1269 memset(&packet->real_embassy, 0, sizeof(packet->real_embassy));
1270 players_iterate(pother) {
1271 packet->real_embassy[player_index(pother)] =
1272 player_has_real_embassy(plr, pother);
1275 } else {
1276 packet->target_government = packet->government;
1277 memset(&packet->real_embassy, 0, sizeof(packet->real_embassy));
1278 if (receiver && player_has_real_embassy(plr, receiver)) {
1279 packet->real_embassy[player_index(receiver)] = TRUE;
1280 }
1281
1283 if (receiver && gives_shared_vision(plr, receiver)) {
1284 BV_SET(packet->gives_shared_vision, player_index(receiver));
1285 }
1286 }
1287
1288 /* Make absolutely sure - in case you lose your embassy! */
1289 if (info_level >= INFO_EMBASSY
1290 || (receiver
1291 && player_diplstate_get(plr, receiver)->type == DS_TEAM)) {
1292 packet->tech_upkeep_32 = player_tech_upkeep(plr);
1293 } else {
1294 packet->tech_upkeep_32 = 0;
1295 }
1296 packet->tech_upkeep_16 = packet->tech_upkeep_32;
1297
1298 /* Send most civ info about the player only to players who have an
1299 * embassy. */
1300 if (highest_team_level >= INFO_EMBASSY) {
1301 packet->tax = plr->economic.tax;
1302 packet->science = plr->economic.science;
1303 packet->luxury = plr->economic.luxury;
1305 packet->culture = player_culture(plr);
1306 } else {
1307 packet->tax = 0;
1308 packet->science = 0;
1309 packet->luxury = 0;
1310 packet->revolution_finishes = -1;
1311 packet->culture = 0;
1312 }
1313
1314 if (info_level >= INFO_FULL
1315 || (receiver
1316 && player_diplstate_get(plr, receiver)->type == DS_TEAM)) {
1317 packet->mood = player_mood(plr);
1318 } else {
1319 packet->mood = MOOD_COUNT;
1320 }
1321
1322 if (info_level >= INFO_FULL) {
1323 packet->history = plr->history;
1324 packet->infrapoints = plr->economic.infra_points;
1325 } else {
1326 packet->history = 0;
1327 packet->infrapoints = 0;
1328 }
1329
1330 for (imp = 0; imp < B_LAST; imp++) {
1331 if (plr->wonders[imp] != WONDER_NOT_BUILT) {
1333 receiver, plr)) {
1334 packet->wonders[imp] = plr->wonders[imp];
1335 } else {
1336 packet->wonders[imp] = WONDER_NOT_BUILT;
1337 }
1338 } else {
1339 packet->wonders[imp] = WONDER_NOT_BUILT;
1340 }
1341 }
1342
1343#ifdef FREECIV_WEB
1344 if (info_level >= INFO_FULL) {
1346 } else {
1347 web_packet->expected_income = 0;
1348 }
1349#endif /* FREECIV_WEB */
1350}
1351
1352/**********************************************************************/
1361static void package_player_diplstate(struct player *plr1,
1362 struct player *plr2,
1363 struct packet_player_diplstate *packet_ds,
1364 struct player *receiver,
1365 enum plr_info_level min_info_level)
1366{
1367 enum plr_info_level info_level;
1368 struct player_diplstate *ds = player_diplstate_get(plr1, plr2);
1369
1370 if (receiver) {
1371 info_level = player_info_level(plr1, receiver);
1372 info_level = MAX(min_info_level, info_level);
1373 } else {
1374 info_level = min_info_level;
1375 }
1376
1377 packet_ds->plr1 = player_index(plr1);
1378 packet_ds->plr2 = player_index(plr2);
1379 /* A unique id for each combination is calculated here. */
1380 packet_ds->diplstate_id = packet_ds->plr1 * MAX_NUM_PLAYER_SLOTS
1381 + packet_ds->plr2;
1382
1383 /* Send diplomatic status of the player to everyone they are in
1384 * contact with (embassy, remaining contact turns, the receiver). */
1385 if (info_level >= INFO_EMBASSY
1386 || (receiver
1387 && player_diplstate_get(receiver, plr1)->contact_turns_left > 0)
1388 || (receiver && receiver == plr2)) {
1389 packet_ds->type = ds->type;
1390 packet_ds->turns_left = ds->turns_left;
1392 packet_ds->contact_turns_left = ds->contact_turns_left;
1393 } else {
1394 packet_ds->type = DS_WAR;
1395 packet_ds->turns_left = 0;
1396 packet_ds->has_reason_to_cancel = 0;
1397 packet_ds->contact_turns_left = 0;
1398 }
1399}
1400
1401/**********************************************************************/
1405 struct player *receiver)
1406{
1407 if (S_S_RUNNING > server_state()) {
1408 return INFO_MINIMUM;
1409 }
1410 if (plr == receiver) {
1411 return INFO_FULL;
1412 }
1413 if (receiver && team_has_embassy(receiver->team, plr)) {
1414 return INFO_EMBASSY;
1415 }
1416 if (receiver && could_intel_with_player(receiver, plr)) {
1417 return INFO_MEETING;
1418 }
1419 return INFO_MINIMUM;
1420}
1421
1422/**********************************************************************/
1426struct conn_list *player_reply_dest(struct player *pplayer)
1427{
1428 return (pplayer->current_conn ?
1429 pplayer->current_conn->self :
1430 pplayer->connections);
1431}
1432
1433/**********************************************************************/
1436static void call_first_contact(struct player *pplayer, struct player *aplayer)
1437{
1438 CALL_PLR_AI_FUNC(first_contact, pplayer, pplayer, aplayer);
1439}
1440
1441/**********************************************************************/
1451void server_player_init(struct player *pplayer, bool initmap,
1452 bool needs_team)
1453{
1454 player_status_reset(pplayer);
1455
1456 pplayer->server.got_first_city = FALSE;
1458 BV_CLR_ALL(pplayer->server.debug);
1459
1460 pplayer->server.border_vision = FALSE;
1461
1462 player_map_free(pplayer);
1463 pplayer->server.private_map = NULL;
1464
1465 if (initmap) {
1466 player_map_init(pplayer);
1467 }
1468 if (needs_team) {
1469 team_add_player(pplayer, NULL);
1470 }
1471
1472 /* This must be done after team information is initialised
1473 * as it might be needed to determine max rate effects.
1474 * Sometimes this server_player_init() gets called twice
1475 * with only latter one having needs_team set. We don't
1476 * want to call player_limit_to_max_rates() at first time
1477 * when team is not yet set. It's callers responsibility
1478 * to always have one server_player_init() call with
1479 * needs_team TRUE. */
1480 if (needs_team) {
1482 }
1483
1484 adv_data_default(pplayer);
1485
1486 /* We don't push this in calc_civ_score(), or it will be reset
1487 * every turn. */
1488 pplayer->score.units_built = 0;
1489 pplayer->score.units_killed = 0;
1490 pplayer->score.units_lost = 0;
1491
1492 /* No delegation. */
1493 pplayer->server.delegate_to[0] = '\0';
1494 pplayer->server.orig_username[0] = '\0';
1495
1496 handicaps_init(pplayer);
1497}
1498
1499/**********************************************************************/
1504const struct rgbcolor *player_preferred_color(struct player *pplayer)
1505{
1506 if (pplayer->rgb) {
1507 return pplayer->rgb;
1508 } else if (playercolor_count() == 0) {
1509 /* If a ruleset isn't loaded, there are no colors to choose from. */
1510 return NULL;
1512 if (pplayer->nation != NO_NATION_SELECTED) {
1513 return nation_color(nation_of_player(pplayer)); /* may be NULL */
1514 } else {
1515 return NULL; /* don't know nation, hence don't know color */
1516 }
1517 } else {
1518 /* Modes indexing into game-defined player colors */
1519 int colorid;
1520
1521 switch (game.server.plrcolormode) {
1522 case PLRCOL_PLR_SET: /* player color (set) */
1523 case PLRCOL_PLR_RANDOM: /* player color (random) */
1524 /* These depend on other players and will be assigned at game start. */
1525 return NULL;
1526 default:
1527 log_error("Invalid value for 'game.server.plrcolormode' (%d)!",
1529 fc__fallthrough; /* no break - using 'PLRCOL_PLR_ORDER' as fallback */
1530 case PLRCOL_PLR_ORDER: /* player color (ordered) */
1531 colorid = player_number(pplayer) % playercolor_count();
1532 break;
1533 case PLRCOL_TEAM_ORDER: /* team color (ordered) */
1534 colorid = team_number(pplayer->team) % playercolor_count();
1535 break;
1536 }
1537
1538 return playercolor_get(colorid);
1539 }
1540}
1541
1542/**********************************************************************/
1547bool player_color_changeable(const struct player *pplayer, const char **reason)
1548{
1550 if (reason) {
1551 *reason = _("Can only set player color prior to game start if "
1552 "'plrcolormode' is PLR_SET.");
1553 }
1554 return FALSE;
1555 }
1556 return TRUE;
1557}
1558
1559/**********************************************************************/
1565{
1566 struct rgbcolor_list *spare_colors =
1567 rgbcolor_list_copy(game.server.plr_colors);
1568 int needed = player_count();
1569
1570 players_iterate(pplayer) {
1571 const struct rgbcolor *autocolor;
1572 /* Assign the deterministic colors. */
1573 if (!pplayer->rgb
1574 && (autocolor = player_preferred_color(pplayer))) {
1575 player_set_color(pplayer, autocolor);
1576 }
1577 if (pplayer->rgb) {
1578 /* One fewer random color needed. */
1579 needed--;
1580 /* Try to avoid clashes between explicit and random colors. */
1581 rgbcolor_list_iterate(spare_colors, prgbcolor) {
1582 if (rgbcolors_are_equal(pplayer->rgb, prgbcolor)) {
1583 rgbcolor_list_remove(spare_colors, prgbcolor);
1584 }
1586 }
1588
1589 if (needed == 0) {
1590 /* No random colors needed */
1591 rgbcolor_list_destroy(spare_colors);
1592 return;
1593 }
1594
1596 /* Additionally, try to avoid color clashes with certain nations not
1597 * yet in play (barbarians). */
1598 allowed_nations_iterate(pnation) {
1599 const struct rgbcolor *ncol = nation_color(pnation);
1600 if (ncol && nation_barbarian_type(pnation) != NOT_A_BARBARIAN) {
1601 /* Don't use this color. */
1602 rgbcolor_list_iterate(spare_colors, prgbcolor) {
1603 if (rgbcolors_are_equal(ncol, prgbcolor)) {
1604 rgbcolor_list_remove(spare_colors, ncol);
1605 }
1607 }
1609 }
1610
1614
1615 if (needed > rgbcolor_list_size(spare_colors)) {
1616 log_verbose("Not enough unique colors for all players; there will be "
1617 "duplicates");
1618 /* Fallback: start again from full set of ruleset colors.
1619 * No longer attempt to avoid clashes with explicitly assigned colors. */
1620 rgbcolor_list_destroy(spare_colors);
1621 spare_colors = rgbcolor_list_copy(game.server.plr_colors);
1622 }
1623 /* We may still not have enough, if there are more players than
1624 * ruleset-defined colors. If so, top up with duplicates. */
1625 if (needed > rgbcolor_list_size(spare_colors)) {
1626 int i, origsize = rgbcolor_list_size(spare_colors);
1627 /* Shuffle so that duplicates aren't biased to start of list */
1628 rgbcolor_list_shuffle(spare_colors);
1629 /* Duplication process avoids one color being hit lots of times */
1630 for (i = origsize; i < needed; i++) {
1631 rgbcolor_list_append(spare_colors,
1632 rgbcolor_list_get(spare_colors, i - origsize));
1633 }
1634 }
1635 /* Shuffle (including mixing any duplicates up) */
1636 rgbcolor_list_shuffle(spare_colors);
1637
1638 /* Finally, assign shuffled colors to players. */
1639 players_iterate(pplayer) {
1640 if (!pplayer->rgb) {
1641 player_set_color(pplayer, rgbcolor_list_front(spare_colors));
1642 rgbcolor_list_pop_front(spare_colors);
1643 }
1645
1646 rgbcolor_list_destroy(spare_colors);
1647}
1648
1649/**********************************************************************/
1653void server_player_set_color(struct player *pplayer,
1654 const struct rgbcolor *prgbcolor)
1655{
1656 if (prgbcolor != NULL) {
1657 player_set_color(pplayer, prgbcolor);
1658 } else {
1659 /* This can legitimately be NULL in pregame. */
1661 rgbcolor_destroy(pplayer->rgb);
1662 pplayer->rgb = NULL;
1663 }
1664 /* Update clients */
1665 send_player_info_c(pplayer, NULL);
1666}
1667
1668/**********************************************************************/
1673const char *player_color_ftstr(struct player *pplayer)
1674{
1675 static char buf[64];
1676 char hex[16];
1677 const struct rgbcolor *prgbcolor;
1678
1679 fc_assert_ret_val(pplayer != NULL, NULL);
1680
1681 buf[0] = '\0';
1682 prgbcolor = player_preferred_color(pplayer);
1683 if (prgbcolor != NULL
1684 && rgbcolor_to_hex(prgbcolor, hex, sizeof(hex))) {
1685 struct ft_color plrcolor = FT_COLOR("#000000", hex);
1686
1687 featured_text_apply_tag(hex, buf, sizeof(buf), TTT_COLOR, 0,
1688 FT_OFFSET_UNSET, plrcolor);
1689 } else {
1690 cat_snprintf(buf, sizeof(buf), _("no color"));
1691 }
1692
1693 return buf;
1694}
1695
1696/**********************************************************************/
1700void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
1701{
1702 int sucount = strlen(game.server.start_units);
1703 int i;
1704
1705 for (i = 0; i < sucount; i++) {
1706 if (game.server.start_units[i] == 'k') {
1707 /* Every player should have king */
1708 struct unit_type *utype = crole_to_unit_type('k', pplayer);
1709
1710 if (utype != NULL) {
1711 create_unit(pplayer, ptile, utype, 0, 0, -1);
1712 }
1713 }
1714 }
1715}
1716
1717/**********************************************************************/
1724struct player *server_create_player(int player_id, const char *ai_tname,
1725 struct rgbcolor *prgbcolor,
1726 bool allow_ai_type_fallbacking)
1727{
1728 struct player_slot *pslot;
1729 struct player *pplayer;
1730
1731 pslot = player_slot_by_number(player_id);
1732 fc_assert(NULL == pslot || !player_slot_is_used(pslot));
1733
1734 pplayer = player_new(pslot);
1735 if (NULL == pplayer) {
1736 return NULL;
1737 }
1738
1739 if (allow_ai_type_fallbacking) {
1740 pplayer->savegame_ai_type_name = fc_strdup(ai_tname);
1741 ai_tname = ai_type_name_or_fallback(ai_tname);
1742 }
1743
1744 pplayer->ai = ai_type_by_name(ai_tname);
1745
1746 if (pplayer->ai == NULL) {
1747 player_destroy(pplayer);
1748 return NULL;
1749 }
1750
1751 adv_data_init(pplayer);
1752
1753 CALL_FUNC_EACH_AI(player_alloc, pplayer);
1754
1755 /* TODO: Do we really need this server_player_init() here? All our callers
1756 * will later make another server_player_init() call anyway, with boolean
1757 * parameters set to what they really need. */
1758 server_player_init(pplayer, FALSE, FALSE);
1759
1760 if (prgbcolor) {
1761 player_set_color(pplayer, prgbcolor);
1762 } /* else caller must ensure a color is assigned if game has started */
1763
1764 return pplayer;
1765}
1766
1767/**********************************************************************/
1773void server_remove_player(struct player *pplayer)
1774{
1775 const struct player_slot *pslot;
1776
1777 fc_assert_ret(NULL != pplayer);
1778
1779 /* save player slot */
1780 pslot = pplayer->slot;
1781
1782 log_normal(_("Removing player %s."), player_name(pplayer));
1783
1784 notify_conn(pplayer->connections, NULL, E_CONNECTION, ftc_server,
1785 _("You've been removed from the game!"));
1786
1787 notify_conn(game.est_connections, NULL, E_CONNECTION, ftc_server,
1788 _("%s has been removed from the game."),
1789 player_name(pplayer));
1790
1791 if (is_barbarian(pplayer)) {
1792 server.nbarbarians--;
1793 }
1794
1795 /* Don't use conn_list_iterate here because connection_detach() can be
1796 * recursive and free the next connection pointer. */
1797 while (conn_list_size(pplayer->connections) > 0) {
1798 connection_detach(conn_list_get(pplayer->connections, 0), FALSE);
1799 }
1800
1802 /* Clear data saved in the other player structs. */
1803 players_iterate(aplayer) {
1804 BV_CLR(aplayer->real_embassy, player_index(pplayer));
1805 if (gives_shared_vision(aplayer, pplayer)) {
1806 remove_shared_vision(aplayer, pplayer);
1807 }
1808 /* Also remove vision provided for the other players */
1809 if (gives_shared_vision(pplayer, aplayer)) {
1810 remove_shared_vision(pplayer, aplayer);
1811 }
1813
1814 /* Remove citizens of this player from the cities of all other players. */
1815 /* FIXME: add a special case if the server quits - no need to run this for
1816 * each player in that case. */
1818 cities_iterate(pcity) {
1819 if (city_owner(pcity) != pplayer) {
1820 citizens nationality = citizens_nation_get(pcity, pplayer->slot);
1821
1822 if (nationality != 0) {
1823 /* Change nationality of the citizens to the nationality of the
1824 * city owner. */
1825 citizens_nation_move(pcity, pplayer->slot, city_owner(pcity)->slot,
1826 nationality);
1828 }
1829 }
1831
1833 }
1834
1835 /* AI type lost control of this player */
1836 if (is_ai(pplayer)) {
1837 CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
1838 }
1839
1840 /* Clear all trade routes. This is needed for the other end not
1841 * to point to a city removed by player_clear() */
1842 city_list_iterate(pplayer->cities, pcity) {
1843 trade_routes_iterate_safe(pcity, proute) {
1844 struct trade_route *pback = remove_trade_route(pcity, proute,
1845 TRUE, TRUE);
1846
1847 FC_FREE(proute);
1848 FC_FREE(pback);
1851
1852 /* We have to clear all player data before the ai memory is freed because
1853 * some function may depend on it. */
1854 player_clear(pplayer, TRUE);
1855
1856 if (!map_is_empty()) {
1857 remove_player_from_maps(pplayer);
1858 }
1859 player_map_free(pplayer);
1860
1861 /* Destroy advisor and ai data. */
1862 CALL_FUNC_EACH_AI(player_free, pplayer);
1863
1864 handicaps_close(pplayer);
1865 ai_traits_close(pplayer);
1866 adv_data_close(pplayer);
1867 player_destroy(pplayer);
1868
1870 /* must be called after the player was destroyed */
1871 send_player_remove_info_c(pslot, NULL);
1872
1873 /* Recalculate borders. */
1875}
1876
1877/**********************************************************************/
1888{
1889 int maxrate, surplus;
1890 struct player_economic *economic;
1891
1892 /* AI players allowed to cheat */
1893 if (is_ai(pplayer) && !has_handicap(pplayer, H_RATES)) {
1894 return;
1895 }
1896
1897 economic = &(pplayer->economic);
1898
1899 maxrate = get_player_maxrate(pplayer);
1900
1901 surplus = 0;
1902 if (economic->luxury > maxrate) {
1903 surplus += economic->luxury - maxrate;
1904 economic->luxury = maxrate;
1905 }
1906 if (economic->tax > maxrate) {
1907 surplus += economic->tax - maxrate;
1908 economic->tax = maxrate;
1909 }
1910 if (economic->science > maxrate) {
1911 surplus += economic->science - maxrate;
1912 economic->science = maxrate;
1913 }
1914
1915 fc_assert(surplus % 10 == 0);
1916
1917 while (surplus > 0) {
1918 if (economic->science < maxrate) {
1919 economic->science += 10;
1920 } else if (economic->tax < maxrate) {
1921 economic->tax += 10;
1922 } else if (economic->luxury < maxrate) {
1923 economic->luxury += 10;
1924 } else {
1925 fc_assert_msg(FALSE, "Failed to distribute the surplus. "
1926 "maxrate = %d.", maxrate);
1927 }
1928 surplus -= 10;
1929 }
1930}
1931
1932/**********************************************************************/
1936static bool server_player_name_is_allowed(const struct connection *caller,
1937 const struct player *pplayer,
1938 const struct nation_type *pnation,
1939 const char *name, char *error_buf,
1940 size_t error_buf_len)
1941{
1942 /* An empty name is surely not allowed. */
1943 if (0 == strlen(name)) {
1944 fc_strlcpy(error_buf, _("Please choose a non-blank name."),
1945 error_buf_len);
1946 return FALSE;
1947 }
1948
1949 /* Any name already taken is not allowed. */
1950 players_iterate(other_player) {
1951 if (other_player == pplayer) {
1952 /* We don't care if we're the one using the name/nation. */
1953 continue;
1954 } else if (NULL != pnation && other_player->nation == pnation) {
1955 /* FIXME: currently cannot use nation_of_player(other_player) as the
1956 * nation debug code is buggy and doesn't test nation for NULL. */
1957 fc_strlcpy(error_buf, _("That nation is already in use."),
1958 error_buf_len);
1959 return FALSE;
1960 } else if (0 == fc_strcasecmp(player_name(other_player), name)) {
1961 fc_snprintf(error_buf, error_buf_len,
1962 _("Another player already has the name '%s'. Please "
1963 "choose another name."), name);
1964 return FALSE;
1965 }
1967
1968 if (NULL == pnation) {
1969 /* FIXME: currently cannot use nation_of_player(other_player) as the
1970 * nation debug code is buggy and doesn't test nation for NULL. */
1971 pnation = pplayer->nation;
1972 }
1973
1974 /* Any name from the default list is always allowed. */
1975 if (NULL != pnation && NULL != nation_leader_by_name(pnation, name)) {
1976 return TRUE;
1977 }
1978
1979 /* To prevent abuse, only players with HACK access (usually local
1980 * connections) can use non-ascii names. Otherwise players could use
1981 * confusing garbage names in multi-player games. */
1982 if (NULL != caller
1983 && caller->access_level < ALLOW_HACK
1984 && !is_ascii_name(name)) {
1985 fc_strlcpy(error_buf,
1986 _("Please choose a name containing only ASCII characters."),
1987 error_buf_len);
1988 return FALSE;
1989 }
1990
1991 return TRUE;
1992}
1993
1994/**********************************************************************/
1998bool server_player_set_name_full(const struct connection *caller,
1999 struct player *pplayer,
2000 const struct nation_type *pnation,
2001 const char *name,
2002 char *error_buf, size_t error_buf_len)
2003{
2004 char real_name[MAX_LEN_NAME];
2005 char buf[256];
2006 int i;
2007
2008 /* Always provide an error buffer. */
2009 if (NULL == error_buf) {
2010 error_buf = buf;
2011 error_buf_len = sizeof(buf);
2012 }
2013 error_buf[0] = '\0';
2014
2015 if (NULL != name) {
2016 /* Ensure this is a correct name. */
2017 sz_strlcpy(real_name, name);
2019 real_name[0] = fc_toupper(real_name[0]);
2020
2021 if (server_player_name_is_allowed(caller, pplayer, pnation, real_name,
2022 error_buf, error_buf_len)) {
2023 log_debug("Name of player nb %d set to \"%s\".",
2024 player_number(pplayer), real_name);
2025 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2026 return TRUE; /* Success! */
2027 } else {
2028 log_verbose("Failed to set the name of the player nb %d to \"%s\": %s",
2029 player_number(pplayer), real_name, error_buf);
2030 /* Fallthrough. */
2031 }
2032 }
2033
2034 if (NULL != caller) {
2035 /* If we want to test, let's fail here. */
2036 fc_assert(NULL != name);
2037 return FALSE;
2038 }
2039
2040 if (NULL != name) {
2041 /* Try to append a number to 'real_name'. */
2042 char test[MAX_LEN_NAME];
2043
2044 for (i = 2; i <= player_slot_count(); i++) {
2045 fc_snprintf(test, sizeof(test), "%s%d", real_name, i);
2046 if (server_player_name_is_allowed(caller, pplayer, pnation,
2047 test, error_buf, error_buf_len)) {
2048 log_verbose("Name of player nb %d set to \"%s\" instead.",
2049 player_number(pplayer), test);
2050 fc_strlcpy(pplayer->name, test, sizeof(pplayer->name));
2051 return TRUE;
2052 } else {
2053 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2054 player_number(pplayer), test, error_buf);
2055 }
2056 }
2057 }
2058
2059 /* Try a default name. */
2060 fc_snprintf(real_name, sizeof(real_name),
2061 _("Player no. %d"), player_number(pplayer));
2062 if (server_player_name_is_allowed(caller, pplayer, pnation,
2063 real_name, error_buf, error_buf_len)) {
2064 log_verbose("Name of player nb %d set to \"%s\".",
2065 player_number(pplayer), real_name);
2066 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2067 return TRUE;
2068 } else {
2069 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2070 player_number(pplayer), real_name, error_buf);
2071 }
2072
2073 /* Try a very default name... */
2074 for (i = 0; i < player_slot_count(); i++) {
2075 fc_snprintf(real_name, sizeof(real_name), _("Player no. %d"), i);
2076 if (server_player_name_is_allowed(caller, pplayer, pnation,
2077 real_name, error_buf, error_buf_len)) {
2078 log_verbose("Name of player nb %d to \"%s\".",
2079 player_number(pplayer), real_name);
2080 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2081 return TRUE;
2082 } else {
2083 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2084 player_number(pplayer), real_name, error_buf);
2085 }
2086 }
2087
2088 /* This is really not normal... Maybe the size of 'real_name'
2089 * is not enough big, or a bug in server_player_name_is_allowed(). */
2090 fc_strlcpy(pplayer->name, _("A poorly-named player"),
2091 sizeof(pplayer->name));
2092 return FALSE; /* Let's say it's a failure. */
2093}
2094
2095/**********************************************************************/
2098void server_player_set_name(struct player *pplayer, const char *name)
2099{
2100#ifndef FREECIV_NDEBUG
2101 bool ret =
2102#endif
2103 server_player_set_name_full(NULL, pplayer, NULL, name, NULL, 0);
2104
2105 fc_assert(ret);
2106}
2107
2108/**********************************************************************/
2114static enum diplstate_type
2115get_default_diplstate(const struct player *pplayer1,
2116 const struct player *pplayer2)
2117{
2118 players_iterate_alive(pplayer3) {
2119 if (pplayer3 != pplayer1
2120 && pplayer3 != pplayer2
2121 && pplayers_allied(pplayer3, pplayer1)
2122 && pplayers_allied(pplayer3, pplayer2)) {
2123 return DS_PEACE;
2124 }
2126
2127 return DS_WAR;
2128}
2129
2130/**********************************************************************/
2133void make_contact(struct player *pplayer1, struct player *pplayer2,
2134 struct tile *ptile)
2135{
2136 struct player_diplstate *ds_plr1plr2, *ds_plr2plr1;
2137
2138 if (pplayer1 == pplayer2
2139 || !pplayer1->is_alive
2140 || !pplayer2->is_alive) {
2141 return;
2142 }
2143
2144 ds_plr1plr2 = player_diplstate_get(pplayer1, pplayer2);
2145 ds_plr2plr1 = player_diplstate_get(pplayer2, pplayer1);
2146
2147 if (get_player_bonus(pplayer1, EFT_NO_DIPLOMACY) <= 0
2148 && get_player_bonus(pplayer2, EFT_NO_DIPLOMACY) <= 0) {
2151 }
2152 if (ds_plr1plr2->type == DS_NO_CONTACT) {
2153 enum diplstate_type new_state = get_default_diplstate(pplayer1,
2154 pplayer2);
2155
2156 set_diplstate_type(ds_plr1plr2, ds_plr2plr1, new_state);
2157 ds_plr1plr2->first_contact_turn = game.info.turn;
2158 ds_plr2plr1->first_contact_turn = game.info.turn;
2159 notify_player(pplayer1, ptile, E_FIRST_CONTACT, ftc_server,
2160 _("You have made contact with the %s, ruled by %s."),
2161 nation_plural_for_player(pplayer2),
2162 player_name(pplayer2));
2163 notify_player(pplayer2, ptile, E_FIRST_CONTACT, ftc_server,
2164 _("You have made contact with the %s, ruled by %s."),
2165 nation_plural_for_player(pplayer1),
2166 player_name(pplayer1));
2167 send_player_all_c(pplayer1, pplayer2->connections);
2168 send_player_all_c(pplayer2, pplayer1->connections);
2169 send_player_all_c(pplayer1, pplayer1->connections);
2170 send_player_all_c(pplayer2, pplayer2->connections);
2171 if (is_ai(pplayer1)) {
2172 call_first_contact(pplayer1, pplayer2);
2173 }
2174 if (is_ai(pplayer2)) {
2175 call_first_contact(pplayer2, pplayer1);
2176 }
2177 return;
2178 } else {
2179 fc_assert(ds_plr2plr1->type != DS_NO_CONTACT);
2180 }
2181 if (team_has_embassy(pplayer1->team, pplayer2)
2182 || team_has_embassy(pplayer2->team, pplayer1)) {
2183 return; /* Avoid sending too much info over the network */
2184 }
2185 send_player_all_c(pplayer1, pplayer1->connections);
2186 send_player_all_c(pplayer2, pplayer2->connections);
2187}
2188
2189/**********************************************************************/
2192void maybe_make_contact(struct tile *ptile, struct player *pplayer)
2193{
2194 square_iterate(&(wld.map), ptile, 1, tile1) {
2195 struct city *pcity = tile_city(tile1);
2196 if (pcity) {
2197 make_contact(pplayer, city_owner(pcity), ptile);
2198 }
2199 unit_list_iterate_safe(tile1->units, punit) {
2200 make_contact(pplayer, unit_owner(punit), ptile);
2203}
2204
2205/**********************************************************************/
2209{
2210 /* shuffled_order is defined global */
2211 int n = player_slot_count();
2212 int i;
2213
2214 log_debug("shuffle_players: creating shuffled order");
2215
2216 for (i = 0; i < n; i++) {
2217 shuffled_order[i] = i;
2218 }
2219
2220 /* randomize it */
2222
2223#ifdef FREECIV_DEBUG
2224 for (i = 0; i < n; i++) {
2225 log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2226 }
2227#endif /* FREECIV_DEBUG */
2228}
2229
2230/**********************************************************************/
2233void set_shuffled_players(int *shuffled_players)
2234{
2235 int i;
2236
2237 log_debug("set_shuffled_players: loading shuffled array %p",
2238 shuffled_players);
2239
2240 for (i = 0; i < player_slot_count(); i++) {
2241 shuffled_order[i] = shuffled_players[i];
2242 log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2243 }
2244}
2245
2246/**********************************************************************/
2252{
2253 struct player *pplayer;
2254
2255 pplayer = player_by_number(shuffled_order[i]);
2256 log_debug("shuffled_player(%d) = %d (%s)",
2257 i, shuffled_order[i], player_name(pplayer));
2258 return pplayer;
2259}
2260
2261/**********************************************************************/
2283struct nation_type *pick_a_nation(const struct nation_list *choices,
2284 bool ignore_conflicts,
2285 bool needs_startpos,
2286 enum barbarian_type barb_type)
2287{
2288 enum {
2289 UNAVAILABLE, AVAILABLE, PREFERRED, UNWANTED
2290 } nations_used[nation_count()], looking_for;
2291 int match[nation_count()], pick, idx;
2292 int num_avail_nations = 0, num_pref_nations = 0;
2293
2294 /* Values of nations_used:
2295 * UNAVAILABLE - nation is already used or is a special nation.
2296 * AVAILABLE - we can use this nation.
2297 * PREFERRED - we can use this nation and it is on the choices list.
2298 * UNWANTED - we can use this nation, but we really don't want to. */
2299 nations_iterate(pnation) {
2300 idx = nation_index(pnation);
2301
2302 if (!nation_is_in_current_set(pnation)
2303 || pnation->player
2304 || (needs_startpos && game.scenario.startpos_nations
2305 && pnation->server.no_startpos)
2306 || (barb_type != nation_barbarian_type(pnation))
2307 || (barb_type == NOT_A_BARBARIAN && !is_nation_playable(pnation))) {
2308 /* Nation is unplayable or already used: don't consider it.
2309 * (If nations aren't currently restricted to those with start
2310 * positions, we do nothing special here, but generate_players() will
2311 * tend to prefer them.) */
2312 nations_used[idx] = UNAVAILABLE;
2313 match[idx] = 0;
2314 continue;
2315 }
2316
2317 nations_used[idx] = AVAILABLE;
2318
2319 /* Determine which nations look good with nations already in the game,
2320 * or conflict with them. */
2321 match[idx] = 1;
2322 players_iterate(pplayer) {
2323 if (pplayer->nation != NO_NATION_SELECTED) {
2324 int x = nations_match(pnation, nation_of_player(pplayer),
2325 ignore_conflicts);
2326 if (x < 0) {
2327 log_debug("Nations '%s' (nb %d) and '%s' (nb %d) are in conflict.",
2328 nation_rule_name(pnation), nation_number(pnation),
2331 nations_used[idx] = UNWANTED;
2332 match[idx] -= x * 100;
2333 break;
2334 } else {
2335 match[idx] += x * 100;
2336 }
2337 }
2339
2340 if (AVAILABLE == nations_used[idx]) {
2341 num_avail_nations += match[idx];
2342 }
2344
2345 /* Mark as preferred those nations which are on the choices list and
2346 * which are AVAILABLE, but no UNWANTED */
2347 if (NULL != choices) {
2348 nation_list_iterate(choices, pnation) {
2349 idx = nation_index(pnation);
2350 if (nations_used[idx] == AVAILABLE) {
2351 num_pref_nations += match[idx];
2352 nations_used[idx] = PREFERRED;
2353 }
2355 }
2356
2357 if (0 < num_pref_nations || 0 < num_avail_nations) {
2358 if (0 < num_pref_nations) {
2359 /* Use a preferred nation only. */
2360 pick = fc_rand(num_pref_nations);
2361 looking_for = PREFERRED;
2362 log_debug("Picking a preferred nation.");
2363 } else {
2364 /* Use any available nation. */
2365 fc_assert(0 < num_avail_nations);
2366 pick = fc_rand(num_avail_nations);
2367 looking_for = AVAILABLE;
2368 log_debug("Picking an available nation.");
2369 }
2370
2371 nations_iterate(pnation) {
2372 idx = nation_index(pnation);
2373 if (nations_used[idx] == looking_for) {
2374 pick -= match[idx];
2375
2376 if (0 > pick) {
2377 return pnation;
2378 }
2379 }
2381 } else {
2382 /* No available nation: use unwanted nation... */
2383 struct nation_type *less_worst_nation = NO_NATION_SELECTED;
2384 int less_worst_score = -FC_INFINITY;
2385
2386 log_debug("Picking an unwanted nation.");
2387 nations_iterate(pnation) {
2388 idx = nation_index(pnation);
2389 if (UNWANTED == nations_used[idx]) {
2390 pick = -fc_rand(match[idx]);
2391 if (pick > less_worst_score) {
2392 less_worst_nation = pnation;
2393 less_worst_score = pick;
2394 }
2395 }
2397
2398 if (NO_NATION_SELECTED != less_worst_nation) {
2399 return less_worst_nation;
2400 }
2401 }
2402
2403 log_verbose("No nation found!");
2404
2405 return NO_NATION_SELECTED;
2406}
2407
2408/**********************************************************************/
2411static struct nation_set *current_nationset(void)
2412{
2414}
2415
2416/**********************************************************************/
2420bool nation_is_in_current_set(const struct nation_type *pnation)
2421{
2422 return nation_is_in_set(pnation, current_nationset());
2423}
2424
2425/**********************************************************************/
2430{
2431 server.playable_nations = 0;
2432 allowed_nations_iterate(pnation) {
2433 if (is_nation_playable(pnation)) {
2434 server.playable_nations++;
2435 }
2437}
2438
2439/**********************************************************************/
2444bool client_can_pick_nation(const struct nation_type *pnation)
2445{
2446 fc_assert_ret_val(pnation != NULL, FALSE);
2447 return nation_is_in_current_set(pnation)
2448 && is_nation_playable(pnation)
2450 || !pnation->server.no_startpos);
2451}
2452
2453/**********************************************************************/
2456static void send_nation_availability_real(struct conn_list *dest,
2457 bool nationset_change)
2458{
2459 struct packet_nation_availability packet;
2460
2461 packet.ncount = nation_count();
2463 nations_iterate(pnation) {
2464 packet.is_pickable[nation_index(pnation)] = client_can_pick_nation(pnation);
2466 lsend_packet_nation_availability(dest, &packet);
2467}
2468
2469/**********************************************************************/
2472void send_nation_availability(struct conn_list *dest,
2473 bool nationset_change)
2474{
2475 if (0 < player_info_frozen_level) {
2476 return; /* Discard, see comment for player_info_freeze(). */
2477 } else {
2479 }
2480}
2481
2482/**********************************************************************/
2490{
2491 int ncount = nation_set_count();
2492 int misfits[ncount];
2493
2494 memset(misfits, 0, sizeof(misfits));
2495
2496 nation_sets_iterate(pset) {
2497 players_iterate(pplayer) {
2498 if (pplayer->nation != NO_NATION_SELECTED
2499 && !nation_is_in_set(pplayer->nation, pset)) {
2500 misfits[nation_set_index(pset)]++;
2501 }
2504
2505 if (misfits[nation_set_index(current_nationset())] == 0) {
2506 /* Current set is OK. */
2507 return;
2508 }
2509
2510 /* Otherwise, pick the least bad set (requires unsetting fewest
2511 * players, possibly none). */
2512 {
2513 int i, least_misfits;
2514 const struct nation_set *best;
2515
2516 fc_assert(ncount > 0);
2517
2518 best = nation_set_by_number(0);
2519 least_misfits = misfits[0];
2520 for (i = 1; i < ncount && least_misfits != 0; i++) {
2521 if (best == NULL || misfits[i] < least_misfits) {
2522 best = nation_set_by_number(i);
2523 least_misfits = misfits[i];
2524 }
2525 }
2526
2527 log_verbose("Current nationset \"%s\" doesn't fit all existing players.",
2529 log_verbose("Selected nationset \"%s\".", nation_set_rule_name(best));
2531 sizeof(game.server.nationset));
2533 /* No need to refresh clients, as we're assumed to be in the middle of
2534 * loading a savegame and will send new setting/availability later
2535 * along with everything else */
2536 }
2537
2538 /* The set we chose may not fit all the players; as a last resort,
2539 * unset nations (caller must then arrange new assignments). */
2540 players_iterate(pplayer) {
2541 if (pplayer->nation != NO_NATION_SELECTED
2542 && !nation_is_in_current_set(pplayer->nation)) {
2543 log_verbose("Nation %s of player %s not in nationset \"%s\", unsetting.",
2544 nation_plural_for_player(pplayer), player_name(pplayer),
2547 }
2549}
2550
2551/**********************************************************************/
2554void reset_all_start_commands(bool plrchange)
2555{
2556 if (S_S_INITIAL != server_state()) {
2557 return;
2558 }
2559 players_iterate(pplayer) {
2560 if (pplayer->is_ready) {
2561 bool persistent = FALSE;
2562
2563 if (plrchange) {
2564 switch (game.info.persistent_ready)
2565 {
2566 case PERSISTENTR_DISABLED:
2567 persistent = FALSE;
2568 break;
2569 case PERSISTENTR_CONNECTED:
2570 persistent = pplayer->is_connected;
2571 break;
2572 }
2573 }
2574
2575 if (!persistent) {
2576 pplayer->is_ready = FALSE;
2578 }
2579 }
2581}
2582
2583/**********************************************************************/
2589static struct player *split_player(struct player *pplayer)
2590{
2591 struct research *new_research, *old_research;
2592 struct player *cplayer;
2593 struct nation_type *rebel_nation;
2594
2595 /* make a new player, or not */
2596 cplayer = server_create_player(-1, ai_name(pplayer->ai),
2597 NULL, FALSE);
2598 if (!cplayer) {
2599 return NULL;
2600 }
2601
2602 /* While this sets player->economic according to max rates as know at this point,
2603 * we redo that later, so that MaxRates effect requirements will be evaluated
2604 * with more completely set up player (e.g. correct government) */
2605 server_player_init(cplayer, TRUE, TRUE);
2606
2607 /* Rebel will always be an AI player */
2608 rebel_nation = pick_a_nation(nation_of_player(pplayer)->server.civilwar_nations,
2609 TRUE, FALSE, NOT_A_BARBARIAN);
2610 player_nation_defaults(cplayer, rebel_nation, TRUE);
2611
2613 /* Find a color for the new player. */
2615
2616 /* Send information about the used player slot to all connections. */
2617 send_player_info_c(cplayer, NULL);
2618
2619 sz_strlcpy(cplayer->username, _(ANON_USER_NAME));
2620 cplayer->unassigned_user = TRUE;
2621 cplayer->is_connected = FALSE;
2623 fc_assert(cplayer->revolution_finishes < 0);
2624 /* No capital for the split player. */
2625 cplayer->server.got_first_city = FALSE;
2626
2627 players_iterate(other_player) {
2628 struct player_diplstate *ds_co
2629 = player_diplstate_get(cplayer, other_player);
2630 struct player_diplstate *ds_oc
2631 = player_diplstate_get(other_player, cplayer);
2632
2633 if (get_player_bonus(other_player, EFT_NO_DIPLOMACY) > 0) {
2634 /* FIXME: What about No-contact war? */
2635 set_diplstate_type(ds_co, ds_oc, DS_WAR);
2636 } else {
2637 set_diplstate_type(ds_co, ds_oc, DS_NO_CONTACT);
2638 }
2639
2640 ds_co->has_reason_to_cancel = 0;
2641 ds_co->turns_left = 0;
2642 ds_co->contact_turns_left = 0;
2643 ds_oc->has_reason_to_cancel = 0;
2644 ds_oc->turns_left = 0;
2645 ds_oc->contact_turns_left = 0;
2646
2647 /* Send so that other_player sees updated diplomatic info;
2648 * pplayer will be sent later anyway
2649 */
2650 if (other_player != pplayer) {
2651 send_player_all_c(other_player, other_player->connections);
2652 }
2654
2655 /* Split the resources */
2656 cplayer->economic.gold = pplayer->economic.gold;
2657 cplayer->economic.gold /= 2;
2658 pplayer->economic.gold -= cplayer->economic.gold;
2659
2660 /* Copy the research */
2661 new_research = research_get(cplayer);
2662 old_research = research_get(pplayer);
2663
2664 new_research->bulbs_researched = 0;
2665 new_research->techs_researched = old_research->techs_researched;
2666 new_research->researching = old_research->researching;
2667 new_research->future_tech = old_research->future_tech;
2668 new_research->tech_goal = old_research->tech_goal;
2669
2671 if (TECH_KNOWN == research_invention_state(old_research, i)) {
2672 research_invention_set(new_research, i, TECH_KNOWN);
2673 new_research->inventions[i].bulbs_researched_saved
2674 = old_research->inventions[i].bulbs_researched_saved;
2675 }
2677 cplayer->phase_done = TRUE; /* Have other things to think
2678 about - paralysis */
2679 BV_CLR_ALL(cplayer->real_embassy); /* all embassies destroyed */
2680 research_update(new_research);
2681
2682 /* Do the ai */
2683 set_as_ai(cplayer);
2684 cplayer->ai_common.maxbuycost = pplayer->ai_common.maxbuycost;
2685 cplayer->ai_common.warmth = pplayer->ai_common.warmth;
2686 cplayer->ai_common.frost = pplayer->ai_common.frost;
2688
2689 /* change the original player */
2691 pplayer->target_government = pplayer->government;
2693 pplayer->revolution_finishes = game.info.turn + 1;
2694 }
2695 old_research->bulbs_researched = 0;
2696 old_research->researching_saved = A_UNKNOWN;
2697 BV_CLR_ALL(pplayer->real_embassy); /* all embassies destroyed */
2698
2699 /* give split player the embassies to their team mates back, if any */
2700 if (pplayer->team) {
2701 players_iterate(pdest) {
2702 if (pplayer->team == pdest->team
2703 && pplayer != pdest) {
2704 establish_embassy(pplayer, pdest);
2705 }
2707 }
2708 research_update(old_research);
2709
2711
2712 /* Copy the maps */
2713
2714 give_map_from_player_to_player(pplayer, cplayer);
2715
2716 pplayer->server.border_vision = cplayer->server.border_vision;
2717
2718 /* Not sure if this is necessary, but might be a good idea
2719 * to avoid doing some ai calculations with bogus data. */
2720 adv_data_phase_init(cplayer, TRUE);
2721 CALL_PLR_AI_FUNC(phase_begin, cplayer, cplayer, TRUE);
2722 CALL_PLR_AI_FUNC(gained_control, cplayer, cplayer);
2723 CALL_PLR_AI_FUNC(split_by_civil_war, pplayer, pplayer, cplayer);
2724 CALL_PLR_AI_FUNC(created_by_civil_war, cplayer, pplayer, cplayer);
2725
2727
2728 return cplayer;
2729}
2730
2731/**********************************************************************/
2739bool civil_war_possible(struct player *pplayer, bool conquering_city,
2740 bool honour_server_option)
2741{
2742 int n;
2743
2745 return FALSE;
2746 }
2747
2748 n = city_list_size(pplayer->cities);
2749
2750 if (n - (conquering_city?1:0) < GAME_MIN_CIVILWARSIZE) {
2751 return FALSE;
2752 }
2753 if (honour_server_option) {
2755 && n >= game.server.civilwarsize;
2756 } else {
2757 return TRUE;
2758 }
2759}
2760
2761/**********************************************************************/
2786bool civil_war_triggered(struct player *pplayer)
2787{
2788 /* Get base probabilities */
2789 int dice = fc_rand(100); /* Throw the dice */
2790 int prob = get_player_bonus(pplayer, EFT_CIVIL_WAR_CHANCE);
2791
2792 /* Now compute the contribution of the cities. */
2793 city_list_iterate(pplayer->cities, pcity) {
2794 if (city_unhappy(pcity)) {
2796 }
2797 if (city_celebrating(pcity)) {
2799 }
2801
2802 log_verbose("Civil war chance for %s: prob %d, dice %d",
2803 player_name(pplayer), prob, dice);
2804
2805 return (dice < prob);
2806}
2807
2808/**********************************************************************/
2836struct player *civil_war(struct player *pplayer)
2837{
2838 int i, j;
2839 struct player *cplayer;
2840 struct city *capital;
2841 struct city_list *defector_candidates;
2842 size_t plr_count;
2843
2844 /* It is possible that this function gets called after pplayer
2845 * died. Player pointers are safe even after death. */
2846 if (!pplayer->is_alive) {
2847 return NULL;
2848 }
2849
2850 plr_count = normal_player_count();
2851 if (plr_count >= MAX_NUM_PLAYERS) {
2852 /* No space to make additional player */
2853 log_normal(_("Could not throw %s into civil war - too many players"),
2854 nation_plural_for_player(pplayer));
2855 return NULL;
2856 }
2857
2858 if (plr_count >= game.server.max_players) {
2859 /* No space to make additional player */
2860 log_normal(_("Could not throw %s into civil war - maxplayers (%d) reached"),
2862 return NULL;
2863 }
2864
2865 if (plr_count >= server.playable_nations) {
2866 /* No nation for additional player */
2867 log_normal(_("Could not throw %s into civil war - no available nations"),
2868 nation_plural_for_player(pplayer));
2869 return NULL;
2870 }
2871
2872 /* It doesn't make sense to try to split an empire of 1 city.
2873 * This should have been enforced by civil_war_possible(). */
2874 fc_assert_ret_val(city_list_size(pplayer->cities) > 1, NULL);
2875
2876 defector_candidates = city_list_new();
2877 city_list_iterate(pplayer->cities, pcity) {
2878 bool gameloss_present = FALSE;
2879
2880 /* Capital (probably new capital) won't defect */
2881 if (is_capital(pcity)) {
2882 continue;
2883 }
2884
2885 /* City hosting victim's GameLoss unit won't defect */
2886 unit_list_iterate(city_tile(pcity)->units, punit) {
2887 if (unit_owner(punit) == pplayer
2888 && unit_has_type_flag(punit, UTYF_GAMELOSS)) {
2889 gameloss_present = TRUE;
2890 break;
2891 }
2893
2894 if (gameloss_present) {
2895 continue;
2896 }
2897
2898 city_list_append(defector_candidates, pcity);
2900
2901 if (city_list_size(defector_candidates) == 0) {
2902 log_verbose(_("Could not throw %s into civil war - no available cities"),
2903 nation_plural_for_player(pplayer));
2904 city_list_destroy(defector_candidates);
2905 return NULL;
2906 }
2907
2908 /* We're definitely going to create a new rebel player. */
2909
2910 cplayer = split_player(pplayer);
2911
2912 /* Before units, cities, so clients know name of new nation
2913 * (for debugging etc).
2914 */
2915 send_player_all_c(cplayer, NULL);
2916 send_player_all_c(pplayer, NULL);
2917
2918 /* Now split the empire */
2919
2920 log_verbose("%s civil war; created AI %s",
2923 notify_player(pplayer, NULL, E_CIVIL_WAR, ftc_server,
2924 _("Your nation is thrust into civil war."));
2925
2926 notify_player(pplayer, NULL, E_FIRST_CONTACT, ftc_server,
2927 /* TRANS: <leader> ... the Poles. */
2928 _("%s is the rebellious leader of the %s."),
2929 player_name(cplayer),
2930 nation_plural_for_player(cplayer));
2931
2932 j = city_list_size(defector_candidates); /* number left to process */
2933 /* Number to try to flip; ensure that at least one eligible city is
2934 * flipped */
2935 i = MAX(j/2, 1);
2936 city_list_iterate(defector_candidates, pcity) {
2937 fc_assert_action(!is_capital(pcity), continue);
2938 if (i >= j || (i > 0 && fc_rand(2) == 1)) {
2939 /* Transfer city and units supported by this city to the new owner.
2940 * We do NOT resolve stack conflicts here, but rather later.
2941 * Reason: if we have a transporter from one city which is carrying
2942 * a unit from another city, and both cities join the rebellion. If we
2943 * resolved stack conflicts for each city we would teleport the first
2944 * of the units we met since the other would have another owner. */
2945 if (transfer_city(cplayer, pcity, -1, FALSE, FALSE, FALSE, FALSE)) {
2946 log_verbose("%s declares allegiance to the %s.", city_name_get(pcity),
2948 notify_player(pplayer, pcity->tile, E_CITY_LOST, ftc_server,
2949 /* TRANS: <city> ... the Poles. */
2950 _("%s declares allegiance to the %s."),
2951 city_link(pcity),
2952 nation_plural_for_player(cplayer));
2953 script_server_signal_emit("city_transferred", pcity, pplayer,
2954 cplayer, "civil_war");
2955 }
2956 i--;
2957 }
2958 j--;
2960
2961 city_list_destroy(defector_candidates);
2962
2963 resolve_unit_stacks(pplayer, cplayer, FALSE);
2964
2965 i = city_list_size(cplayer->cities);
2966 fc_assert(i > 0); /* rebels should have got at least one city */
2967
2968 /* Choose a capital (random). */
2969 capital = city_list_get(cplayer->cities, fc_rand(i));
2971 give_midgame_initial_units(cplayer, city_tile(capital));
2972
2973 notify_player(NULL, NULL, E_CIVIL_WAR, ftc_server,
2974 /* TRANS: ... Danes ... Poles ... <7> cities. */
2975 PL_("Civil war partitions the %s;"
2976 " the %s now hold %d city.",
2977 "Civil war partitions the %s;"
2978 " the %s now hold %d cities.",
2979 i),
2980 nation_plural_for_player(pplayer),
2981 nation_plural_for_player(cplayer),
2982 i);
2983
2984 return cplayer;
2985}
2986
2987/**********************************************************************/
2992 *chunk)
2993{
2995}
2996
2997/**********************************************************************/
3001{
3002 send_attribute_block(pplayer, pplayer->current_conn);
3003}
3004
3005/**********************************************************************/
3009 int turn)
3010{
3011 if (turn != game.info.turn) {
3012 /* If this happens then the player actually pressed turn-done on a
3013 * previous turn but we didn't receive it until now. The player
3014 * probably didn't actually mean to end their turn! */
3015 return;
3016 }
3017 pplayer->phase_done = TRUE;
3018
3020
3021 send_player_all_c(pplayer, NULL);
3022}
3023
3024/**********************************************************************/
3028{
3029 return server.nbarbarians;
3030}
3031
3032/**********************************************************************/
3036{
3037 return player_count() - server.nbarbarians;
3038}
3039
3040/**********************************************************************/
3043void player_status_add(struct player *plr, enum player_status pstatus)
3044{
3045 BV_SET(plr->server.status, pstatus);
3046}
3047
3048/**********************************************************************/
3051bool player_status_check(struct player *plr, enum player_status pstatus)
3052{
3053 return BV_ISSET(plr->server.status, pstatus);
3054}
3055
3056/**********************************************************************/
3060{
3061 BV_CLR_ALL(plr->server.status);
3062 player_status_add(plr, PSTATUS_NORMAL);
3063}
3064
3065/**********************************************************************/
3068const char *player_delegation_get(const struct player *pplayer)
3069{
3070 if (pplayer == NULL || strlen(pplayer->server.delegate_to) == 0) {
3071 /* No delegation if there is no player. */
3072 return NULL;
3073 } else {
3074 return pplayer->server.delegate_to;
3075 }
3076}
3077
3078/**********************************************************************/
3081void player_delegation_set(struct player *pplayer, const char *username)
3082{
3083 fc_assert_ret(pplayer != NULL);
3084
3085 if (username == NULL || strlen(username) == 0) {
3086 pplayer->server.delegate_to[0] = '\0';
3087 } else {
3088 sz_strlcpy(pplayer->server.delegate_to, username);
3089 }
3090}
3091
3092/**********************************************************************/
3097bool player_delegation_active(const struct player *pplayer)
3098{
3099 return (pplayer && strlen(pplayer->server.orig_username) != 0);
3100}
3101
3102/**********************************************************************/
3105void send_delegation_info(const struct connection *pconn)
3106{
3107 if (game.info.is_new_game) {
3108 return;
3109 }
3110
3111 if (!pconn->observer
3112 && pconn->playing && player_delegation_get(pconn->playing) != NULL) {
3113 notify_conn(pconn->self, NULL, E_CONNECTION, ftc_server,
3114 /* TRANS: '/delegate cancel' is a server command and must not
3115 * be translated */
3116 _("User '%s' is currently allowed to take control of your "
3117 "player while you are away. Use '/delegate cancel' to "
3118 "revoke this access."),
3120 }
3121
3122 {
3123 bool any_delegations = FALSE;
3124 players_iterate(aplayer) {
3125 if (player_delegation_get(aplayer) != NULL
3126 && strcmp(player_delegation_get(aplayer), pconn->username) == 0) {
3127 notify_conn(pconn->self, NULL, E_CONNECTION, ftc_server,
3128 _("Control of player '%s' is delegated to you."),
3129 player_name(aplayer));
3130 any_delegations = TRUE;
3131 }
3133 if (any_delegations) {
3134 notify_conn(pconn->self, NULL, E_CONNECTION, ftc_server,
3135 /* TRANS: '/delegate take' is a server command and must not
3136 * be translated; but <player> should be translated. */
3137 _("Use '/delegate take <player>' to take control of a "
3138 "delegated player."));
3139 }
3140 }
3141}
3142
3143/**********************************************************************/
3149{
3150 players_iterate(pplayer) {
3151 if (player_delegation_get(pplayer)
3152 && fc_strcasecmp(name, pplayer->server.orig_username) == 0) {
3153 return pplayer;
3154 }
3156
3157 return NULL;
3158}
3159
3160/**********************************************************************/
3164{
3166 game.server.plr_colors = rgbcolor_list_new();
3167}
3168
3169/**********************************************************************/
3173{
3174 if (game.server.plr_colors == NULL) {
3175 return;
3176 }
3177
3178 if (rgbcolor_list_size(game.server.plr_colors) > 0) {
3180 rgbcolor_list_remove(game.server.plr_colors, prgbcolor);
3181 rgbcolor_destroy(prgbcolor);
3183 };
3184 rgbcolor_list_destroy(game.server.plr_colors);
3185 game.server.plr_colors = NULL;
3186}
3187
3188/**********************************************************************/
3191void playercolor_add(struct rgbcolor *prgbcolor)
3192{
3194
3195 rgbcolor_list_append(game.server.plr_colors, prgbcolor);
3196}
3197
3198/**********************************************************************/
3202{
3203 fc_assert_ret_val(game.server.plr_colors != NULL, NULL);
3204
3205 return rgbcolor_list_get(game.server.plr_colors, id);
3206}
3207
3208/**********************************************************************/
3212{
3214
3215 return rgbcolor_list_size(game.server.plr_colors);
3216}
3217
3218/**********************************************************************/
3221void handle_player_multiplier(struct player *pplayer, int count,
3222 const int *multipliers)
3223{
3224 int rval;
3225 int i;
3226
3227 if (count != multiplier_count()) {
3228 log_error("Bad number of multipliers %d from client for %s",
3229 count, player_name(pplayer));
3230 return;
3231 }
3232
3233 for (i = 0; i < count; i++) {
3234 struct multiplier *pmul = multiplier_by_number(i);
3235
3236 if (multiplier_can_be_changed(pmul, pplayer)) {
3237 if (multipliers[i] < pmul->start || multipliers[i] > pmul->stop) {
3238 log_error("Multiplier value %d for %s out of range for %s",
3240 player_name(pplayer));
3241 } else {
3242 rval = (multipliers[i] - pmul->start) / pmul->step * pmul->step + pmul->start;
3243 if (rval != multipliers[i]) {
3244 log_error("Multiplier value %d between valid values for %s for %s",
3246 player_name(pplayer));
3247 } else {
3248 pplayer->multipliers[i].target = multipliers[i];
3249 }
3250 }
3251 }
3252 }
3253
3254 send_player_info_c(pplayer, NULL);
3255}
3256
3257/**********************************************************************/
3260void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
3261{
3262 set_as_ai(pplayer);
3263
3264 set_ai_level_directer(pplayer, skill_level);
3265 cancel_all_meetings(pplayer);
3266 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
3267 if (is_player_phase(pplayer, game.info.phase)) {
3268 CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
3269 }
3270
3271 if (S_S_RUNNING == server_state()) {
3272 /* In case this was last player who has not pressed turn done. */
3274 }
3275
3276 fc_assert(pplayer->ai_common.skill_level == skill_level);
3277}
3278
3279/**********************************************************************/
3283{
3284 set_as_human(pplayer);
3285
3286 if (pplayer->ai_common.skill_level == AI_LEVEL_AWAY) {
3287 pplayer->ai_common.skill_level = ai_level_invalid();
3288 }
3289
3290 CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
3291
3292 /* Because the AI "cheats" with government rates but humans shouldn't. */
3293 if (!game.info.is_new_game) {
3294 check_player_max_rates(pplayer);
3295 }
3296 cancel_all_meetings(pplayer);
3297}
void adv_data_close(struct player *pplayer)
Definition advdata.c:741
void adv_data_init(struct player *pplayer)
Definition advdata.c:686
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:262
void adv_data_default(struct player *pplayer)
Definition advdata.c:718
const char * ai_name(const struct ai_type *ai)
Definition ai.c:329
const char * ai_type_name_or_fallback(const char *orig_name)
Definition ai.c:340
struct ai_type * ai_type_by_name(const char *search)
Definition ai.c:284
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
@ INCIDENT_WAR
Definition ai.h:46
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
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:233
void ai_traits_close(struct player *pplayer)
Definition aitraits.c:58
#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:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
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:1552
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
bool city_unhappy(const struct city *pcity)
Definition city.c:1599
bool city_celebrating(const struct city *pcity)
Definition city.c:1618
#define cities_iterate_end
Definition city.h:497
#define city_list_iterate_safe(citylist, _city)
Definition city.h:502
#define city_list_iterate(citylist, pcity)
Definition city.h:488
#define city_tile(_pcity_)
Definition city.h:544
#define cities_iterate(pcity)
Definition city.h:492
#define city_owner(_pcity_)
Definition city.h:543
#define city_list_iterate_end
Definition city.h:490
#define city_list_iterate_safe_end
Definition city.h:524
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1416
void sync_cities(void)
Definition citytools.c:3238
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3272
void remove_city(struct city *pcity)
Definition citytools.c:1684
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2849
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:1070
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:200
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:185
void city_refresh_queue_processing(void)
Definition cityturn.c:216
void connection_detach(struct connection *pconn, bool remove_unused_player)
#define conn_list_iterate(connlist, pconn)
Definition connection.h:113
#define conn_list_iterate_end
Definition connection.h:115
int player_culture(const struct player *plr)
Definition culture.c:46
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
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:724
void reject_all_treaties(struct player *pplayer)
Definition diplhand.c:962
void set_diplstate_type(struct player_diplstate *state1, struct player_diplstate *state2, enum diplstate_type type)
Definition diplhand.c:159
void cancel_all_meetings(struct player *pplayer)
Definition diplhand.c:950
bool could_intel_with_player(const struct player *pplayer, const struct player *aplayer)
Definition diptreaty.c:81
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:789
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1068
#define extra_type_by_cause_iterate_end
Definition extras.h:315
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
unsigned char citizens
Definition fc_types.h:358
int Impr_type_id
Definition fc_types.h:346
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
revolen_type
Definition fc_types.h:1134
@ REVOLEN_RANDOM
Definition fc_types.h:1136
@ REVOLEN_RANDQUICK
Definition fc_types.h:1138
@ REVOLEN_FIXED
Definition fc_types.h:1135
@ REVOLEN_QUICKENING
Definition fc_types.h:1137
int Government_type_id
Definition fc_types.h:351
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define MAX_LEN_NAME
Definition fc_types.h:66
#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:57
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:687
struct world wld
Definition game.c:58
#define GAME_DEFAULT_REVOLUTION_LENGTH
Definition game.h:711
#define GAME_MIN_CIVILWARSIZE
Definition game.h:470
#define GAME_MAX_CIVILWARSIZE
Definition game.h:471
struct unit_type * crole_to_unit_type(char crole, struct player *pplayer)
Definition gamehand.c:118
const char * government_name_translation(const struct government *pgovern)
Definition government.c:142
bool untargeted_revolution_allowed(void)
Definition government.c:565
Government_type_id government_count(void)
Definition government.c:70
struct government * government_by_number(const Government_type_id gov)
Definition government.c:102
struct government * government_of_player(const struct player *pplayer)
Definition government.c:113
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:153
bool can_change_to_government(struct player *pplayer, const struct government *gov)
Definition government.c:165
Government_type_id government_number(const struct government *pgovern)
Definition government.c:90
const char * government_rule_name(const struct government *pgovern)
Definition government.c:132
GType type
Definition repodlgs.c:1312
static GtkWidget * persistent
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)
#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:181
#define fc_assert_ret(condition)
Definition log.h:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
#define log_error(message,...)
Definition log.h:103
bool map_is_empty(void)
Definition map.c:149
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:385
#define square_iterate_end
Definition map.h:388
#define whole_map_iterate(_map, _tile)
Definition map.h:539
#define whole_map_iterate_end
Definition map.h:548
void player_map_init(struct player *pplayer)
Definition maphand.c:1202
void map_claim_base(struct tile *ptile, struct extra_type *pextra, struct player *powner, struct player *ploser)
Definition maphand.c:2384
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2191
void map_know_and_see_all(struct player *pplayer)
Definition maphand.c:1177
void give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:381
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1681
void player_map_free(struct player *pplayer)
Definition maphand.c:1218
void map_calculate_borders(void)
Definition maphand.c:2357
void remove_player_from_maps(struct player *pplayer)
Definition maphand.c:1239
#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:137
Nation_type_id nation_count(void)
Definition nation.c:506
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:485
struct nation_leader * nation_leader_by_name(const struct nation_type *pnation, const char *name)
Definition nation.c:266
int nations_match(const struct nation_type *pnation1, const struct nation_type *pnation2, bool ignore_conflicts)
Definition nation.c:1205
int nation_set_index(const struct nation_set *pset)
Definition nation.c:698
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:199
const struct rgbcolor * nation_color(const struct nation_type *pnation)
Definition nation.c:681
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Definition nation.c:836
int nation_set_count(void)
Definition nation.c:690
struct nation_set * nation_set_by_number(int id)
Definition nation.c:761
struct nation_set * nation_set_by_setting_value(const char *setting)
Definition nation.c:858
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:497
const char * nation_set_rule_name(const struct nation_set *pset)
Definition nation.c:806
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:210
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:658
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:83
#define nation_sets_iterate_end
Definition nation.h:304
#define nation_sets_iterate(NAME_pset)
Definition nation.h:300
#define nations_iterate_end
Definition nation.h:335
#define nation_list_iterate_end
Definition nation.h:85
#define nations_iterate(NAME_pnation)
Definition nation.h:332
#define NATION_NONE
Definition nation.h:32
#define NO_NATION_SELECTED
Definition nation.h:29
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:690
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
Definition packets.c:746
#define web_send_packet(packetname,...)
Definition packets.h:52
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:441
struct player * player_new(struct player_slot *pslot)
Definition player.c:486
struct player * player_by_number(const int player_id)
Definition player.c:840
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1452
int player_count(void)
Definition player.c:808
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Definition player.c:67
int player_slot_count(void)
Definition player.c:411
struct player_slot * player_slot_by_number(int player_id)
Definition player.c:456
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1262
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
void player_clear(struct player *pplayer, bool full)
Definition player.c:660
int player_slot_index(const struct player_slot *pslot)
Definition player.c:419
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:234
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:214
void player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition player.c:639
int player_index(const struct player *pplayer)
Definition player.c:820
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:852
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:92
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1461
void player_destroy(struct player *pplayer)
Definition player.c:747
#define players_iterate_end
Definition player.h:535
dipl_reason
Definition player.h:194
@ DIPL_SENATE_BLOCKING
Definition player.h:195
@ DIPL_OK
Definition player.h:195
#define players_iterate(_pplayer)
Definition player.h:530
#define player_list_iterate(playerlist, pplayer)
Definition player.h:553
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
#define is_ai(plr)
Definition player.h:234
#define player_list_iterate_end
Definition player.h:555
#define set_as_human(plr)
Definition player.h:235
#define players_iterate_alive_end
Definition player.h:545
@ PLRCOL_PLR_RANDOM
Definition player.h:52
@ PLRCOL_PLR_SET
Definition player.h:53
@ PLRCOL_NATION_ORDER
Definition player.h:55
@ PLRCOL_TEAM_ORDER
Definition player.h:54
@ PLRCOL_PLR_ORDER
Definition player.h:51
#define set_as_ai(plr)
Definition player.h:236
#define is_human(plr)
Definition player.h:233
#define players_iterate_alive(_pplayer)
Definition player.h:540
void handle_player_phase_done(struct player *pplayer, int turn)
Definition plrhand.c:3008
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2472
void handle_player_multiplier(struct player *pplayer, int count, const int *multipliers)
Definition plrhand.c:3221
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2098
int barbarian_count(void)
Definition plrhand.c:3027
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:983
static void send_player_remove_info_c(const struct player_slot *pslot, struct conn_list *dest)
Definition plrhand.c:935
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1724
const struct rgbcolor * player_preferred_color(struct player *pplayer)
Definition plrhand.c:1504
void player_update_last_war_action(struct player *pplayer)
Definition plrhand.c:746
void handle_player_attribute_chunk(struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
Definition plrhand.c:2990
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3043
int normal_player_count(void)
Definition plrhand.c:3035
static void send_player_info_c_real(struct player *src, struct conn_list *dest)
Definition plrhand.c:1020
static enum plr_info_level player_info_level(struct player *plr, struct player *receiver)
Definition plrhand.c:1404
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:1361
void player_set_under_human_control(struct player *pplayer)
Definition plrhand.c:3282
static void maybe_claim_base(struct tile *ptile, struct player *new_owner, struct player *old_owner)
Definition plrhand.c:704
void playercolor_free(void)
Definition plrhand.c:3172
static struct nation_set * current_nationset(void)
Definition plrhand.c:2411
void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
Definition plrhand.c:1700
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:1436
void player_limit_to_max_rates(struct player *pplayer)
Definition plrhand.c:1887
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2786
void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition plrhand.c:1653
void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
Definition plrhand.c:3260
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:1998
bool player_delegation_active(const struct player *pplayer)
Definition plrhand.c:3097
void player_info_thaw(void)
Definition plrhand.c:964
void player_info_freeze(void)
Definition plrhand.c:955
struct player * player_by_user_delegated(const char *name)
Definition plrhand.c:3148
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2192
void handle_player_attribute_block(struct player *pplayer)
Definition plrhand.c:3000
static void send_nation_availability_real(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2456
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:2283
static enum diplstate_type get_default_diplstate(const struct player *pplayer1, const struct player *pplayer2)
Definition plrhand.c:2115
void playercolor_init(void)
Definition plrhand.c:3163
void check_player_max_rates(struct player *pplayer)
Definition plrhand.c:657
void kill_player(struct player *pplayer)
Definition plrhand.c:125
const char * player_color_ftstr(struct player *pplayer)
Definition plrhand.c:1673
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1000
void set_shuffled_players(int *shuffled_players)
Definition plrhand.c:2233
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:2836
static int shuffled_order[MAX_NUM_PLAYER_SLOTS]
Definition plrhand.c:114
void player_status_reset(struct player *plr)
Definition plrhand.c:3059
void send_delegation_info(const struct connection *pconn)
Definition plrhand.c:3105
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:454
struct conn_list * player_reply_dest(struct player *pplayer)
Definition plrhand.c:1426
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:685
static int revolentype_length(enum revolen_type rltype, struct government *gov)
Definition plrhand.c:410
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3051
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2739
struct rgbcolor * playercolor_get(int id)
Definition plrhand.c:3201
void player_delegation_set(struct player *pplayer, const char *username)
Definition plrhand.c:3081
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:1936
int playercolor_count(void)
Definition plrhand.c:3211
void shuffle_players(void)
Definition plrhand.c:2208
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:1169
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1773
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:1451
static void send_player_diplstate_c_real(struct player *src, struct conn_list *dest)
Definition plrhand.c:1075
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:761
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Definition plrhand.c:2133
void playercolor_add(struct rgbcolor *prgbcolor)
Definition plrhand.c:3191
void update_capital(struct player *pplayer)
Definition plrhand.c:612
void count_playable_nations(void)
Definition plrhand.c:2429
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:1547
void assign_player_colors(void)
Definition plrhand.c:1564
static void package_player_common(struct player *plr, struct packet_player_info *packet, struct packet_web_player_info_addition *web_packet)
Definition plrhand.c:1108
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2444
void send_player_diplstate_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1059
static struct player * split_player(struct player *pplayer)
Definition plrhand.c:2589
struct player * shuffled_player(int i)
Definition plrhand.c:2251
const char * player_delegation_get(const struct player *pplayer)
Definition plrhand.c:3068
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2420
void enter_war(struct player *pplayer, struct player *pplayer2)
Definition plrhand.c:729
static int player_info_frozen_level
Definition plrhand.c:117
int revolution_length(struct government *gov, struct player *plr)
Definition plrhand.c:438
void fit_nationset_to_players(void)
Definition plrhand.c:2489
void reset_all_start_commands(bool plrchange)
Definition plrhand.c:2554
void update_revolution(struct player *pplayer)
Definition plrhand.c:553
plr_info_level
Definition plrhand.h:24
@ INFO_MEETING
Definition plrhand.h:24
@ INFO_MINIMUM
Definition plrhand.h:24
@ INFO_EMBASSY
Definition plrhand.h:24
@ INFO_FULL
Definition plrhand.h:24
#define allowed_nations_iterate(pnation)
Definition plrhand.h:67
#define allowed_nations_iterate_end
Definition plrhand.h:71
#define fc_rand(_size)
Definition rand.h:34
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Definition research.c:634
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1040
struct research * research_get(const struct player *pplayer)
Definition research.c:126
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
void research_update(struct research *presearch)
Definition research.c:499
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:2000
bool is_ascii_name(const char *name)
Definition shared.c:282
void remove_leading_trailing_spaces(char *s)
Definition shared.c:443
#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:128
void spaceship_init(struct player_spaceship *ship)
Definition spaceship.c:96
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2510
bool game_was_started(void)
Definition srv_main.c:339
void check_for_full_turn_done(void)
Definition srv_main.c:2145
enum server_states server_state(void)
Definition srv_main.c:323
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:2007
Definition city.h:309
int id
Definition city.h:315
enum capital_type capital
Definition city.h:317
int contactturns
Definition game.h:136
struct rgbcolor_list * plr_colors
Definition game.h:242
struct civ_game::@30::@34 server
char start_units[MAX_LEN_STARTUNIT]
Definition game.h:188
enum plrcolor_mode plrcolormode
Definition game.h:127
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:176
int civilwarsize
Definition game.h:134
bool savepalace
Definition game.h:186
char nationset[MAX_LEN_NAME]
Definition game.h:156
int max_players
Definition game.h:155
int revolution_length
Definition game.h:177
struct government * government_during_revolution
Definition game.h:94
struct player * playing
Definition connection.h:156
enum cmdlevel access_level
Definition connection.h:182
struct conn_list * self
Definition connection.h:168
bool observer
Definition connection.h:152
char username[MAX_LEN_NAME]
Definition connection.h:169
int changed_to_times
Definition government.h:61
enum barbarian_type barb_type
Definition nation.h:109
bool no_startpos
Definition nation.h:147
struct nation_type::@50::@52 server
enum gameloss_style gameloss_style
enum ai_level skill_level
enum revolen_type revolentype
enum persistent_ready persistent_ready
int civil_war_bonus_celebrating
bool is_pickable[MAX_NUM_NATIONS]
enum diplstate_type type
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]
bool real_embassy[MAX_NUM_PLAYER_SLOTS]
int multiplier_changed[MAX_NUM_MULTIPLIERS]
Nation_type_id nation
enum barbarian_type barbarian_type
char name[MAX_LEN_NAME]
Government_type_id government
int wonders[B_LAST]
enum ai_level skill_level
Definition player.h:122
enum barbarian_type barbarian_type
Definition player.h:128
int warmth
Definition player.h:127
int science_cost
Definition player.h:125
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:130
int maxbuycost
Definition player.h:120
int frost
Definition player.h:127
char contact_turns_left
Definition player.h:206
int first_contact_turn
Definition player.h:203
enum diplstate_type type
Definition player.h:201
char has_reason_to_cancel
Definition player.h:205
int infra_points
Definition player.h:74
int units_killed
Definition player.h:112
int units_lost
Definition player.h:113
int units_built
Definition player.h:111
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:318
int primary_capital_id
Definition player.h:275
bool is_male
Definition player.h:257
bool got_first_city
Definition player.h:320
int wonders[B_LAST]
Definition player.h:301
struct government * target_government
Definition player.h:259
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_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:299
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:310
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
struct player::@69::@71 server
bool is_ready
Definition player.h:262
int history
Definition player.h:312
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:308
bool unassigned_user
Definition player.h:253
Tech_type_id researching
Definition research.h:52
int future_tech
Definition research.h:42
Tech_type_id tech_goal
Definition research.h:85
struct research::research_invention inventions[A_ARRAY_SIZE]
Tech_type_id researching_saved
Definition research.h:62
int techs_researched
Definition research.h:42
int bulbs_researched
Definition research.h:53
int g
Definition rgbcolor.h:34
int b
Definition rgbcolor.h:34
int r
Definition rgbcolor.h:34
Definition tile.h:49
struct unit_list * units
Definition tile.h:57
struct player * extras_owner
Definition tile.h:62
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:969
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:787
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:995
char fc_toupper(char c)
Definition support.c:1271
#define sz_strlcpy(dest, src)
Definition support.h:167
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define fc__fallthrough
Definition support.h:109
int team_count(void)
Definition team.c:375
int team_number(const struct team *pteam)
Definition team.c:391
bool team_add_player(struct player *pplayer, struct team *pteam)
Definition team.c:467
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
#define advance_index_iterate_end
Definition tech.h:248
#define A_NONE
Definition tech.h:43
#define A_UNKNOWN
Definition tech.h:49
#define advance_index_iterate(_start, _index)
Definition tech.h:244
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:209
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_owner(_tile)
Definition tile.h:95
#define trade_routes_iterate_safe_end
#define trade_routes_iterate_safe(c, proute)
#define unit_owner(_pu)
Definition unit.h:394
#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:1430
void remove_allied_visibility(struct player *pplayer, struct player *aplayer, const struct unit_list *seen_units)
Definition unittools.c:1465
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1415
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:1616
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2248
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
void send_updated_vote_totals(struct conn_list *dest)
Definition voting.c:866