Freeciv-3.1: /fast/freeciv/nightly/S3_1/server/plrhand.c Source File

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,
86 struct packet_web_player_info_addition *
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,
96 struct packet_web_player_info_addition *
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(). */
114 static int shuffled_order[MAX_NUM_PLAYER_SLOTS];
115
116/* Used by player_info_freeze() and player_info_thaw(). */
117 static int player_info_frozen_level = 0;
118
119/**********************************************************************/
125 void 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 }
140 } players_iterate_end;
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 }
154 } player_list_iterate_end;
155
156 if (!someone_alive) {
157 player_list_iterate(team_members(pplayer->team), pteam_member) {
158 map_know_and_see_all(pteam_member);
159 } player_list_iterate_end;
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 }
185 } city_list_iterate_safe_end;
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
215 game.server.savepalace = FALSE;
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 }
227 } city_list_iterate_safe_end;
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);
240 } city_list_iterate_end;
241 }
242
243 /* Remove all units that are still ours */
244 unit_list_iterate_safe(pplayer->units, punit) {
245 wipe_unit(punit, ULR_PLAYER_DIED, NULL);
246 } unit_list_iterate_safe_end;
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 }
256 } whole_map_iterate_end;
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
263 send_player_info_c(pplayer, game.est_connections);
264}
265
266/**********************************************************************/
269 static 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/**********************************************************************/
285 void 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,
320 government_name_for_player(pplayer));
321 } else {
322 pplayer->economic.tax = tax;
323 pplayer->economic.luxury = luxury;
324 pplayer->economic.science = science;
325
326 city_refresh_for_player(pplayer);
327 send_player_info_c(pplayer, pplayer->connections);
328 }
329}
330
331/**********************************************************************/
336 void government_change(struct player *pplayer, struct government *gov,
337 bool revolution_finished)
338{
339 struct research *presearch;
340
341 if (revolution_finished) {
342 fc_assert_ret(pplayer->target_government
343 != game.government_during_revolution
344 && NULL != pplayer->target_government);
345 fc_assert_ret(pplayer->revolution_finishes <= game.info.turn);
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),
356 government_rule_name(gov),
357 pplayer->revolution_finishes, game.info.turn);
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),
363 nation_plural_for_player(pplayer),
364 government_name_translation(gov));
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%%."),
387 nation_plural_for_player(pplayer),
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);
395 city_refresh_for_player(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/**********************************************************************/
410 static int revolentype_length(enum revolen_type rltype,
411 struct government *gov)
412{
413 int max_turns;
414
415 switch (rltype) {
416 case REVOLEN_FIXED:
417 return game.server.revolution_length;
418 case REVOLEN_RANDOM:
419 return fc_rand(game.server.revolution_length) + 1;
420 case REVOLEN_QUICKENING:
421 case REVOLEN_RANDQUICK:
422 max_turns = game.server.revolution_length - gov->changed_to_times;
423 max_turns = MAX(1, max_turns);
424 if (game.info.revolentype == REVOLEN_RANDQUICK) {
425 return fc_rand(max_turns) + 1;
426 }
427 return max_turns;
428 }
429
430 fc_assert(FALSE);
431
432 return GAME_DEFAULT_REVOLUTION_LENGTH;
433}
434
435/**********************************************************************/
438 int revolution_length(struct government *gov, struct player *plr)
439{
440 if (!untargeted_revolution_allowed()
441 && gov == game.government_during_revolution) {
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
448 return revolentype_length(game.info.revolentype, gov);
449}
450
451/**********************************************************************/
454 void handle_player_change_government(struct player *pplayer,
455 Government_type_id government)
456{
457 int turns;
458 struct government *gov = government_by_number(government);
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),
467 government_rule_name(gov),
468 government_rule_name(government_of_player(pplayer)),
469 pplayer->revolution_finishes, game.info.turn);
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
494 && pplayer->government != game.government_during_revolution) {
495 /* Multiple changes attempted after single anarchy period */
496 if (game.info.revolentype == REVOLEN_QUICKENING
497 || game.info.revolentype == REVOLEN_RANDQUICK) {
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
504 pplayer->government = game.government_during_revolution;
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),
510 government_rule_name(pplayer->target_government),
511 pplayer->revolution_finishes, game.info.turn);
512
513 /* Now see if the revolution is instantaneous. */
514 if (turns <= 0
515 && pplayer->target_government != game.government_during_revolution) {
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),
529 nation_plural_for_player(pplayer),
530 turns,
531 government_name_translation(pplayer->target_government));
532 } else {
533 fc_assert(pplayer->target_government == game.government_during_revolution);
534 notify_player(pplayer, NULL, E_REVOLT_START, ftc_server,
535 _("Revolution: returning to anarchy."));
536 }
537
538 check_player_max_rates(pplayer);
539 city_refresh_for_player(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),
544 government_rule_name(pplayer->target_government),
545 government_rule_name(government_of_player(pplayer)),
546 game.info.turn, pplayer->revolution_finishes);
547}
548
549/**********************************************************************/
553 void 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),
578 government_rule_name(government_of_player(pplayer)),
579 pplayer->target_government
580 ? government_rule_name(pplayer->target_government) : "(none)",
581 pplayer->revolution_finishes, game.info.turn);
582
583 current_gov = government_of_player(pplayer);
584
585 if (current_gov == game.government_during_revolution
586 && pplayer->revolution_finishes <= game.info.turn) {
587 if (pplayer->target_government != game.government_during_revolution) {
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 }
599 } else if (government_of_player(pplayer) != game.government_during_revolution
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/**********************************************************************/
612 void 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 }
642 } city_list_iterate_end;
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/**********************************************************************/
657 void check_player_max_rates(struct player *pplayer)
658{
659 struct player_economic old_econ = pplayer->economic;
660
661 player_limit_to_max_rates(pplayer);
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/**********************************************************************/
685 void update_players_after_alliance_breakup(struct player *pplayer,
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/**********************************************************************/
704 static 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
711 && tile_has_claimable_base(ptile, unit_type_get(punit))) {
712 claim = TRUE;
713 break;
714 }
715 } unit_list_iterate_end;
716
717 if (claim) {
718 extra_type_by_cause_iterate(EC_BASE, pextra) {
719 map_claim_base(ptile, pextra, new_owner, old_owner);
720 } extra_type_by_cause_iterate_end;
721
722 ptile->extras_owner = new_owner;
723 }
724}
725
726/**********************************************************************/
729 void 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 }
740 } whole_map_iterate_end;
741}
742
743/**********************************************************************/
746 void player_update_last_war_action(struct player *pplayer)
747{
748 pplayer->last_war_action = game.info.turn;
749 send_player_info_c(pplayer, NULL);
750}
751
752/**********************************************************************/
761 void handle_diplomacy_cancel_pact(struct player *pplayer,
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) {
830 player_update_last_war_action(pplayer);
831 player_update_last_war_action(pplayer2);
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
841 update_players_after_alliance_breakup(pplayer, pplayer2,
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 */
879 city_map_update_all_cities_for_player(pplayer);
880 city_map_update_all_cities_for_player(pplayer2);
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."),
886 nation_plural_for_player(pplayer),
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),
895 nation_plural_for_player(pplayer),
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;
913 player_update_last_war_action(other);
914 handle_diplomacy_cancel_pact(other, player_number(pplayer),
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 }
929 } players_iterate_alive_end;
930}
931
932/**********************************************************************/
935 static 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
942 fc_assert_ret(!player_slot_is_used(pslot));
943
944 conn_list_iterate(dest, pconn) {
945 dsend_packet_player_remove(pconn, player_slot_index(pslot));
946 } conn_list_iterate_end;
947}
948
949/**********************************************************************/
955 void player_info_freeze(void)
956{
957 player_info_frozen_level++;
958}
959
960/**********************************************************************/
964 void player_info_thaw(void)
965{
966 if (0 == --player_info_frozen_level) {
967 send_nation_availability_real(game.est_connections, FALSE);
968 send_player_info_c(NULL, NULL);
969 }
970 fc_assert(0 <= player_info_frozen_level);
971}
972
973/**********************************************************************/
983 void 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/**********************************************************************/
1000 void 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);
1013 } players_iterate_end;
1014}
1015
1016/**********************************************************************/
1020 static 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);
1047 } conn_list_iterate_end;
1048}
1049
1050/**********************************************************************/
1059 void send_player_diplstate_c(struct player *src, struct conn_list *dest)
1060{
1061 if (src != NULL) {
1062 send_player_diplstate_c_real(src, dest);
1063 return;
1064 }
1065
1066 players_iterate(pplayer) {
1067 send_player_diplstate_c_real(pplayer, dest);
1068 } players_iterate_end;
1069}
1070
1071/**********************************************************************/
1075 static 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);
1101 } players_iterate_end;
1102 } conn_list_iterate_end;
1103}
1104
1105/**********************************************************************/
1108 static void package_player_common(struct player *plr,
1109 struct packet_player_info *packet,
1110 struct packet_web_player_info_addition *
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 }
1149 packet->barbarian_type = plr->ai_common.barbarian_type;
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/**********************************************************************/
1169 static void package_player_info(struct player *plr,
1170 struct packet_player_info *packet,
1171 struct packet_web_player_info_addition *
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;
1197 } multipliers_iterate_end;
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;
1205 } multipliers_iterate_end;
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 }
1217 } players_iterate_end;
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;
1257 pgov = game.government_during_revolution;
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)) {
1266 packet->target_government = plr->target_government
1267 ? government_number(plr->target_government)
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);
1273 } players_iterate_end;
1274 packet->gives_shared_vision = plr->gives_shared_vision;
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
1282 BV_CLR_ALL(packet->gives_shared_vision);
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 = player_tech_upkeep(plr);
1293 } else {
1294 packet->tech_upkeep = 0;
1295 }
1296
1297 /* Send most civ info about the player only to players who have an
1298 * embassy. */
1299 if (highest_team_level >= INFO_EMBASSY) {
1300 packet->tax = plr->economic.tax;
1301 packet->science = plr->economic.science;
1302 packet->luxury = plr->economic.luxury;
1303 packet->revolution_finishes = plr->revolution_finishes;
1304 packet->culture = player_culture(plr);
1305 } else {
1306 packet->tax = 0;
1307 packet->science = 0;
1308 packet->luxury = 0;
1309 packet->revolution_finishes = -1;
1310 packet->culture = 0;
1311 }
1312
1313 if (info_level >= INFO_FULL
1314 || (receiver
1315 && player_diplstate_get(plr, receiver)->type == DS_TEAM)) {
1316 packet->mood = player_mood(plr);
1317 } else {
1318 packet->mood = MOOD_COUNT;
1319 }
1320
1321 if (info_level >= INFO_FULL) {
1322 packet->history = plr->history;
1323 packet->infrapoints = plr->economic.infra_points;
1324 } else {
1325 packet->history = 0;
1326 packet->infrapoints = 0;
1327 }
1328
1329 for (imp = 0; imp < B_LAST; imp++) {
1330 if (plr->wonders[imp] != WONDER_NOT_BUILT) {
1331 if (wonder_visible_to_player(improvement_by_number(imp),
1332 receiver, plr)) {
1333 packet->wonders[imp] = plr->wonders[imp];
1334 } else {
1335 packet->wonders[imp] = WONDER_NOT_BUILT;
1336 }
1337 } else {
1338 packet->wonders[imp] = WONDER_NOT_BUILT;
1339 }
1340 }
1341
1342#ifdef FREECIV_WEB
1343 if (info_level >= INFO_FULL) {
1344 web_packet->expected_income = player_get_expected_income(plr);
1345 } else {
1346 web_packet->expected_income = 0;
1347 }
1348#endif /* FREECIV_WEB */
1349}
1350
1351/**********************************************************************/
1360 static void package_player_diplstate(struct player *plr1,
1361 struct player *plr2,
1362 struct packet_player_diplstate *packet_ds,
1363 struct player *receiver,
1364 enum plr_info_level min_info_level)
1365{
1366 enum plr_info_level info_level;
1367 struct player_diplstate *ds = player_diplstate_get(plr1, plr2);
1368
1369 if (receiver) {
1370 info_level = player_info_level(plr1, receiver);
1371 info_level = MAX(min_info_level, info_level);
1372 } else {
1373 info_level = min_info_level;
1374 }
1375
1376 packet_ds->plr1 = player_index(plr1);
1377 packet_ds->plr2 = player_index(plr2);
1378 /* A unique id for each combination is calculated here. */
1379 packet_ds->diplstate_id = packet_ds->plr1 * MAX_NUM_PLAYER_SLOTS
1380 + packet_ds->plr2;
1381
1382 /* Send diplomatic status of the player to everyone they are in
1383 * contact with (embassy, remaining contact turns, the receiver). */
1384 if (info_level >= INFO_EMBASSY
1385 || (receiver
1386 && player_diplstate_get(receiver, plr1)->contact_turns_left > 0)
1387 || (receiver && receiver == plr2)) {
1388 packet_ds->type = ds->type;
1389 packet_ds->turns_left = ds->turns_left;
1390 packet_ds->has_reason_to_cancel = ds->has_reason_to_cancel;
1391 packet_ds->contact_turns_left = ds->contact_turns_left;
1392 } else {
1393 packet_ds->type = DS_WAR;
1394 packet_ds->turns_left = 0;
1395 packet_ds->has_reason_to_cancel = 0;
1396 packet_ds->contact_turns_left = 0;
1397 }
1398}
1399
1400/**********************************************************************/
1403 static enum plr_info_level player_info_level(struct player *plr,
1404 struct player *receiver)
1405{
1406 if (S_S_RUNNING > server_state()) {
1407 return INFO_MINIMUM;
1408 }
1409 if (plr == receiver) {
1410 return INFO_FULL;
1411 }
1412 if (receiver && team_has_embassy(receiver->team, plr)) {
1413 return INFO_EMBASSY;
1414 }
1415 if (receiver && could_intel_with_player(receiver, plr)) {
1416 return INFO_MEETING;
1417 }
1418 return INFO_MINIMUM;
1419}
1420
1421/**********************************************************************/
1425 struct conn_list *player_reply_dest(struct player *pplayer)
1426{
1427 return (pplayer->current_conn ?
1428 pplayer->current_conn->self :
1429 pplayer->connections);
1430}
1431
1432/**********************************************************************/
1435 static void call_first_contact(struct player *pplayer, struct player *aplayer)
1436{
1437 CALL_PLR_AI_FUNC(first_contact, pplayer, pplayer, aplayer);
1438}
1439
1440/**********************************************************************/
1450 void server_player_init(struct player *pplayer, bool initmap,
1451 bool needs_team)
1452{
1453 player_status_reset(pplayer);
1454
1455 pplayer->server.got_first_city = FALSE;
1456 BV_CLR_ALL(pplayer->server.really_gives_vision);
1457 BV_CLR_ALL(pplayer->server.debug);
1458
1459 pplayer->server.border_vision = FALSE;
1460
1461 player_map_free(pplayer);
1462 pplayer->server.private_map = NULL;
1463
1464 if (initmap) {
1465 player_map_init(pplayer);
1466 }
1467 if (needs_team) {
1468 team_add_player(pplayer, NULL);
1469 }
1470
1471 /* This must be done after team information is initialised
1472 * as it might be needed to determine max rate effects.
1473 * Sometimes this server_player_init() gets called twice
1474 * with only latter one having needs_team set. We don't
1475 * want to call player_limit_to_max_rates() at first time
1476 * when team is not yet set. It's callers responsibility
1477 * to always have one server_player_init() call with
1478 * needs_team TRUE. */
1479 if (needs_team) {
1480 player_limit_to_max_rates(pplayer);
1481 }
1482
1483 adv_data_default(pplayer);
1484
1485 /* We don't push this in calc_civ_score(), or it will be reset
1486 * every turn. */
1487 pplayer->score.units_built = 0;
1488 pplayer->score.units_killed = 0;
1489 pplayer->score.units_lost = 0;
1490
1491 /* No delegation. */
1492 pplayer->server.delegate_to[0] = '\0';
1493 pplayer->server.orig_username[0] = '\0';
1494
1495 handicaps_init(pplayer);
1496}
1497
1498/**********************************************************************/
1503 const struct rgbcolor *player_preferred_color(struct player *pplayer)
1504{
1505 if (pplayer->rgb) {
1506 return pplayer->rgb;
1507 } else if (playercolor_count() == 0) {
1508 /* If a ruleset isn't loaded, there are no colors to choose from. */
1509 return NULL;
1510 } else if (game.server.plrcolormode == PLRCOL_NATION_ORDER) {
1511 if (pplayer->nation != NO_NATION_SELECTED) {
1512 return nation_color(nation_of_player(pplayer)); /* may be NULL */
1513 } else {
1514 return NULL; /* don't know nation, hence don't know color */
1515 }
1516 } else {
1517 /* Modes indexing into game-defined player colors */
1518 int colorid;
1519
1520 switch (game.server.plrcolormode) {
1521 case PLRCOL_PLR_SET: /* player color (set) */
1522 case PLRCOL_PLR_RANDOM: /* player color (random) */
1523 /* These depend on other players and will be assigned at game start. */
1524 return NULL;
1525 default:
1526 log_error("Invalid value for 'game.server.plrcolormode' (%d)!",
1527 game.server.plrcolormode);
1528 fc__fallthrough; /* no break - using 'PLRCOL_PLR_ORDER' as fallback */
1529 case PLRCOL_PLR_ORDER: /* player color (ordered) */
1530 colorid = player_number(pplayer) % playercolor_count();
1531 break;
1532 case PLRCOL_TEAM_ORDER: /* team color (ordered) */
1533 colorid = team_number(pplayer->team) % playercolor_count();
1534 break;
1535 }
1536
1537 return playercolor_get(colorid);
1538 }
1539}
1540
1541/**********************************************************************/
1546 bool player_color_changeable(const struct player *pplayer, const char **reason)
1547{
1548 if (!game_was_started() && game.server.plrcolormode != PLRCOL_PLR_SET) {
1549 if (reason) {
1550 *reason = _("Can only set player color prior to game start if "
1551 "'plrcolormode' is PLR_SET.");
1552 }
1553 return FALSE;
1554 }
1555 return TRUE;
1556}
1557
1558/**********************************************************************/
1563 void assign_player_colors(void)
1564{
1565 struct rgbcolor_list *spare_colors =
1566 rgbcolor_list_copy(game.server.plr_colors);
1567 int needed = player_count();
1568
1569 players_iterate(pplayer) {
1570 const struct rgbcolor *autocolor;
1571 /* Assign the deterministic colors. */
1572 if (!pplayer->rgb
1573 && (autocolor = player_preferred_color(pplayer))) {
1574 player_set_color(pplayer, autocolor);
1575 }
1576 if (pplayer->rgb) {
1577 /* One fewer random color needed. */
1578 needed--;
1579 /* Try to avoid clashes between explicit and random colors. */
1580 rgbcolor_list_iterate(spare_colors, prgbcolor) {
1581 if (rgbcolors_are_equal(pplayer->rgb, prgbcolor)) {
1582 rgbcolor_list_remove(spare_colors, prgbcolor);
1583 }
1584 } rgbcolor_list_iterate_end;
1585 }
1586 } players_iterate_end;
1587
1588 if (needed == 0) {
1589 /* No random colors needed */
1590 rgbcolor_list_destroy(spare_colors);
1591 return;
1592 }
1593
1594 if (game.server.plrcolormode == PLRCOL_NATION_ORDER) {
1595 /* Additionally, try to avoid color clashes with certain nations not
1596 * yet in play (barbarians). */
1597 allowed_nations_iterate(pnation) {
1598 const struct rgbcolor *ncol = nation_color(pnation);
1599 if (ncol && nation_barbarian_type(pnation) != NOT_A_BARBARIAN) {
1600 /* Don't use this color. */
1601 rgbcolor_list_iterate(spare_colors, prgbcolor) {
1602 if (rgbcolors_are_equal(ncol, prgbcolor)) {
1603 rgbcolor_list_remove(spare_colors, ncol);
1604 }
1605 } rgbcolor_list_iterate_end;
1606 }
1607 } allowed_nations_iterate_end;
1608 }
1609
1610 fc_assert(game.server.plrcolormode == PLRCOL_PLR_RANDOM
1611 || game.server.plrcolormode == PLRCOL_PLR_SET
1612 || game.server.plrcolormode == PLRCOL_NATION_ORDER);
1613
1614 if (needed > rgbcolor_list_size(spare_colors)) {
1615 log_verbose("Not enough unique colors for all players; there will be "
1616 "duplicates");
1617 /* Fallback: start again from full set of ruleset colors.
1618 * No longer attempt to avoid clashes with explicitly assigned colors. */
1619 rgbcolor_list_destroy(spare_colors);
1620 spare_colors = rgbcolor_list_copy(game.server.plr_colors);
1621 }
1622 /* We may still not have enough, if there are more players than
1623 * ruleset-defined colors. If so, top up with duplicates. */
1624 if (needed > rgbcolor_list_size(spare_colors)) {
1625 int i, origsize = rgbcolor_list_size(spare_colors);
1626 /* Shuffle so that duplicates aren't biased to start of list */
1627 rgbcolor_list_shuffle(spare_colors);
1628 /* Duplication process avoids one color being hit lots of times */
1629 for (i = origsize; i < needed; i++) {
1630 rgbcolor_list_append(spare_colors,
1631 rgbcolor_list_get(spare_colors, i - origsize));
1632 }
1633 }
1634 /* Shuffle (including mixing any duplicates up) */
1635 rgbcolor_list_shuffle(spare_colors);
1636
1637 /* Finally, assign shuffled colors to players. */
1638 players_iterate(pplayer) {
1639 if (!pplayer->rgb) {
1640 player_set_color(pplayer, rgbcolor_list_front(spare_colors));
1641 rgbcolor_list_pop_front(spare_colors);
1642 }
1643 } players_iterate_end;
1644
1645 rgbcolor_list_destroy(spare_colors);
1646}
1647
1648/**********************************************************************/
1652 void server_player_set_color(struct player *pplayer,
1653 const struct rgbcolor *prgbcolor)
1654{
1655 if (prgbcolor != NULL) {
1656 player_set_color(pplayer, prgbcolor);
1657 } else {
1658 /* This can legitimately be NULL in pregame. */
1659 fc_assert_ret(!game_was_started());
1660 rgbcolor_destroy(pplayer->rgb);
1661 pplayer->rgb = NULL;
1662 }
1663 /* Update clients */
1664 send_player_info_c(pplayer, NULL);
1665}
1666
1667/**********************************************************************/
1672 const char *player_color_ftstr(struct player *pplayer)
1673{
1674 static char buf[64];
1675 char hex[16];
1676 const struct rgbcolor *prgbcolor;
1677
1678 fc_assert_ret_val(pplayer != NULL, NULL);
1679
1680 buf[0] = '\0';
1681 prgbcolor = player_preferred_color(pplayer);
1682 if (prgbcolor != NULL
1683 && rgbcolor_to_hex(prgbcolor, hex, sizeof(hex))) {
1684 struct ft_color plrcolor = FT_COLOR("#000000", hex);
1685
1686 featured_text_apply_tag(hex, buf, sizeof(buf), TTT_COLOR, 0,
1687 FT_OFFSET_UNSET, plrcolor);
1688 } else {
1689 cat_snprintf(buf, sizeof(buf), _("no color"));
1690 }
1691
1692 return buf;
1693}
1694
1695/**********************************************************************/
1699 void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
1700{
1701 int sucount = strlen(game.server.start_units);
1702 int i;
1703
1704 for (i = 0; i < sucount; i++) {
1705 if (game.server.start_units[i] == 'k') {
1706 /* Every player should have king */
1707 struct unit_type *utype = crole_to_unit_type('k', pplayer);
1708
1709 if (utype != NULL) {
1710 create_unit(pplayer, ptile, utype, 0, 0, -1);
1711 }
1712 }
1713 }
1714}
1715
1716/**********************************************************************/
1723 struct player *server_create_player(int player_id, const char *ai_tname,
1724 struct rgbcolor *prgbcolor,
1725 bool allow_ai_type_fallbacking)
1726{
1727 struct player_slot *pslot;
1728 struct player *pplayer;
1729
1730 pslot = player_slot_by_number(player_id);
1731 fc_assert(NULL == pslot || !player_slot_is_used(pslot));
1732
1733 pplayer = player_new(pslot);
1734 if (NULL == pplayer) {
1735 return NULL;
1736 }
1737
1738 if (allow_ai_type_fallbacking) {
1739 pplayer->savegame_ai_type_name = fc_strdup(ai_tname);
1740 ai_tname = ai_type_name_or_fallback(ai_tname);
1741 }
1742
1743 pplayer->ai = ai_type_by_name(ai_tname);
1744
1745 if (pplayer->ai == NULL) {
1746 player_destroy(pplayer);
1747 return NULL;
1748 }
1749
1750 adv_data_init(pplayer);
1751
1752 CALL_FUNC_EACH_AI(player_alloc, pplayer);
1753
1754 /* TODO: Do we really need this server_player_init() here? All our callers
1755 * will later make another server_player_init() call anyway, with boolean
1756 * parameters set to what they really need. */
1757 server_player_init(pplayer, FALSE, FALSE);
1758
1759 if (prgbcolor) {
1760 player_set_color(pplayer, prgbcolor);
1761 } /* else caller must ensure a color is assigned if game has started */
1762
1763 return pplayer;
1764}
1765
1766/**********************************************************************/
1772 void server_remove_player(struct player *pplayer)
1773{
1774 const struct player_slot *pslot;
1775
1776 fc_assert_ret(NULL != pplayer);
1777
1778 /* save player slot */
1779 pslot = pplayer->slot;
1780
1781 log_normal(_("Removing player %s."), player_name(pplayer));
1782
1783 notify_conn(pplayer->connections, NULL, E_CONNECTION, ftc_server,
1784 _("You've been removed from the game!"));
1785
1786 notify_conn(game.est_connections, NULL, E_CONNECTION, ftc_server,
1787 _("%s has been removed from the game."),
1788 player_name(pplayer));
1789
1790 if (is_barbarian(pplayer)) {
1791 server.nbarbarians--;
1792 }
1793
1794 /* Don't use conn_list_iterate here because connection_detach() can be
1795 * recursive and free the next connection pointer. */
1796 while (conn_list_size(pplayer->connections) > 0) {
1797 connection_detach(conn_list_get(pplayer->connections, 0), FALSE);
1798 }
1799
1800 script_server_remove_exported_object(pplayer);
1801 /* Clear data saved in the other player structs. */
1802 players_iterate(aplayer) {
1803 BV_CLR(aplayer->real_embassy, player_index(pplayer));
1804 if (gives_shared_vision(aplayer, pplayer)) {
1805 remove_shared_vision(aplayer, pplayer);
1806 }
1807 /* Also remove vision provided for the other players */
1808 if (gives_shared_vision(pplayer, aplayer)) {
1809 remove_shared_vision(pplayer, aplayer);
1810 }
1811 } players_iterate_end;
1812
1813 /* Remove citizens of this player from the cities of all other players. */
1814 /* FIXME: add a special case if the server quits - no need to run this for
1815 * each player in that case. */
1816 if (game.info.citizen_nationality) {
1817 cities_iterate(pcity) {
1818 if (city_owner(pcity) != pplayer) {
1819 citizens nationality = citizens_nation_get(pcity, pplayer->slot);
1820
1821 if (nationality != 0) {
1822 /* Change nationality of the citizens to the nationality of the
1823 * city owner. */
1824 citizens_nation_move(pcity, pplayer->slot, city_owner(pcity)->slot,
1825 nationality);
1826 city_refresh_queue_add(pcity);
1827 }
1828 }
1829 } cities_iterate_end
1830
1831 city_refresh_queue_processing();
1832 }
1833
1834 /* AI type lost control of this player */
1835 if (is_ai(pplayer)) {
1836 CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
1837 }
1838
1839 /* Clear all trade routes. This is needed for the other end not
1840 * to point to a city removed by player_clear() */
1841 city_list_iterate(pplayer->cities, pcity) {
1842 trade_routes_iterate_safe(pcity, proute) {
1843 struct trade_route *pback = remove_trade_route(pcity, proute,
1844 TRUE, TRUE);
1845
1846 FC_FREE(proute);
1847 FC_FREE(pback);
1848 } trade_routes_iterate_safe_end;
1849 } city_list_iterate_end;
1850
1851 /* We have to clear all player data before the ai memory is freed because
1852 * some function may depend on it. */
1853 player_clear(pplayer, TRUE);
1854
1855 if (!map_is_empty()) {
1856 remove_player_from_maps(pplayer);
1857 }
1858 player_map_free(pplayer);
1859
1860 /* Destroy advisor and ai data. */
1861 CALL_FUNC_EACH_AI(player_free, pplayer);
1862
1863 handicaps_close(pplayer);
1864 ai_traits_close(pplayer);
1865 adv_data_close(pplayer);
1866 player_destroy(pplayer);
1867
1868 send_updated_vote_totals(NULL);
1869 /* must be called after the player was destroyed */
1870 send_player_remove_info_c(pslot, NULL);
1871
1872 /* Recalculate borders. */
1873 map_calculate_borders();
1874}
1875
1876/**********************************************************************/
1886 void player_limit_to_max_rates(struct player *pplayer)
1887{
1888 int maxrate, surplus;
1889 struct player_economic *economic;
1890
1891 /* AI players allowed to cheat */
1892 if (is_ai(pplayer) && !has_handicap(pplayer, H_RATES)) {
1893 return;
1894 }
1895
1896 economic = &(pplayer->economic);
1897
1898 maxrate = get_player_maxrate(pplayer);
1899
1900 surplus = 0;
1901 if (economic->luxury > maxrate) {
1902 surplus += economic->luxury - maxrate;
1903 economic->luxury = maxrate;
1904 }
1905 if (economic->tax > maxrate) {
1906 surplus += economic->tax - maxrate;
1907 economic->tax = maxrate;
1908 }
1909 if (economic->science > maxrate) {
1910 surplus += economic->science - maxrate;
1911 economic->science = maxrate;
1912 }
1913
1914 fc_assert(surplus % 10 == 0);
1915
1916 while (surplus > 0) {
1917 if (economic->science < maxrate) {
1918 economic->science += 10;
1919 } else if (economic->tax < maxrate) {
1920 economic->tax += 10;
1921 } else if (economic->luxury < maxrate) {
1922 economic->luxury += 10;
1923 } else {
1924 fc_assert_msg(FALSE, "Failed to distribute the surplus. "
1925 "maxrate = %d.", maxrate);
1926 }
1927 surplus -= 10;
1928 }
1929}
1930
1931/**********************************************************************/
1935 static bool server_player_name_is_allowed(const struct connection *caller,
1936 const struct player *pplayer,
1937 const struct nation_type *pnation,
1938 const char *name, char *error_buf,
1939 size_t error_buf_len)
1940{
1941 /* An empty name is surely not allowed. */
1942 if (0 == strlen(name)) {
1943 fc_strlcpy(error_buf, _("Please choose a non-blank name."),
1944 error_buf_len);
1945 return FALSE;
1946 }
1947
1948 /* Any name already taken is not allowed. */
1949 players_iterate(other_player) {
1950 if (other_player == pplayer) {
1951 /* We don't care if we're the one using the name/nation. */
1952 continue;
1953 } else if (NULL != pnation && other_player->nation == pnation) {
1954 /* FIXME: currently cannot use nation_of_player(other_player) as the
1955 * nation debug code is buggy and doesn't test nation for NULL. */
1956 fc_strlcpy(error_buf, _("That nation is already in use."),
1957 error_buf_len);
1958 return FALSE;
1959 } else if (0 == fc_strcasecmp(player_name(other_player), name)) {
1960 fc_snprintf(error_buf, error_buf_len,
1961 _("Another player already has the name '%s'. Please "
1962 "choose another name."), name);
1963 return FALSE;
1964 }
1965 } players_iterate_end;
1966
1967 if (NULL == pnation) {
1968 /* FIXME: currently cannot use nation_of_player(other_player) as the
1969 * nation debug code is buggy and doesn't test nation for NULL. */
1970 pnation = pplayer->nation;
1971 }
1972
1973 /* Any name from the default list is always allowed. */
1974 if (NULL != pnation && NULL != nation_leader_by_name(pnation, name)) {
1975 return TRUE;
1976 }
1977
1978 /* To prevent abuse, only players with HACK access (usually local
1979 * connections) can use non-ascii names. Otherwise players could use
1980 * confusing garbage names in multi-player games. */
1981 if (NULL != caller
1982 && caller->access_level < ALLOW_HACK
1983 && !is_ascii_name(name)) {
1984 fc_strlcpy(error_buf,
1985 _("Please choose a name containing only ASCII characters."),
1986 error_buf_len);
1987 return FALSE;
1988 }
1989
1990 return TRUE;
1991}
1992
1993/**********************************************************************/
1997 bool server_player_set_name_full(const struct connection *caller,
1998 struct player *pplayer,
1999 const struct nation_type *pnation,
2000 const char *name,
2001 char *error_buf, size_t error_buf_len)
2002{
2003 char real_name[MAX_LEN_NAME];
2004 char buf[256];
2005 int i;
2006
2007 /* Always provide an error buffer. */
2008 if (NULL == error_buf) {
2009 error_buf = buf;
2010 error_buf_len = sizeof(buf);
2011 }
2012 error_buf[0] = '\0';
2013
2014 if (NULL != name) {
2015 /* Ensure this is a correct name. */
2016 sz_strlcpy(real_name, name);
2017 remove_leading_trailing_spaces(real_name);
2018 real_name[0] = fc_toupper(real_name[0]);
2019
2020 if (server_player_name_is_allowed(caller, pplayer, pnation, real_name,
2021 error_buf, error_buf_len)) {
2022 log_debug("Name of player nb %d set to \"%s\".",
2023 player_number(pplayer), real_name);
2024 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2025 return TRUE; /* Success! */
2026 } else {
2027 log_verbose("Failed to set the name of the player nb %d to \"%s\": %s",
2028 player_number(pplayer), real_name, error_buf);
2029 /* Fallthrough. */
2030 }
2031 }
2032
2033 if (NULL != caller) {
2034 /* If we want to test, let's fail here. */
2035 fc_assert(NULL != name);
2036 return FALSE;
2037 }
2038
2039 if (NULL != name) {
2040 /* Try to append a number to 'real_name'. */
2041 char test[MAX_LEN_NAME];
2042
2043 for (i = 2; i <= player_slot_count(); i++) {
2044 fc_snprintf(test, sizeof(test), "%s%d", real_name, i);
2045 if (server_player_name_is_allowed(caller, pplayer, pnation,
2046 test, error_buf, error_buf_len)) {
2047 log_verbose("Name of player nb %d set to \"%s\" instead.",
2048 player_number(pplayer), test);
2049 fc_strlcpy(pplayer->name, test, sizeof(pplayer->name));
2050 return TRUE;
2051 } else {
2052 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2053 player_number(pplayer), test, error_buf);
2054 }
2055 }
2056 }
2057
2058 /* Try a default name. */
2059 fc_snprintf(real_name, sizeof(real_name),
2060 _("Player no. %d"), player_number(pplayer));
2061 if (server_player_name_is_allowed(caller, pplayer, pnation,
2062 real_name, error_buf, error_buf_len)) {
2063 log_verbose("Name of player nb %d set to \"%s\".",
2064 player_number(pplayer), real_name);
2065 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2066 return TRUE;
2067 } else {
2068 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2069 player_number(pplayer), real_name, error_buf);
2070 }
2071
2072 /* Try a very default name... */
2073 for (i = 0; i < player_slot_count(); i++) {
2074 fc_snprintf(real_name, sizeof(real_name), _("Player no. %d"), i);
2075 if (server_player_name_is_allowed(caller, pplayer, pnation,
2076 real_name, error_buf, error_buf_len)) {
2077 log_verbose("Name of player nb %d to \"%s\".",
2078 player_number(pplayer), real_name);
2079 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2080 return TRUE;
2081 } else {
2082 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2083 player_number(pplayer), real_name, error_buf);
2084 }
2085 }
2086
2087 /* This is really not normal... Maybe the size of 'real_name'
2088 * is not enough big, or a bug in server_player_name_is_allowed(). */
2089 fc_strlcpy(pplayer->name, _("A poorly-named player"),
2090 sizeof(pplayer->name));
2091 return FALSE; /* Let's say it's a failure. */
2092}
2093
2094/**********************************************************************/
2097 void server_player_set_name(struct player *pplayer, const char *name)
2098{
2099#ifndef FREECIV_NDEBUG
2100 bool ret =
2101#endif
2102 server_player_set_name_full(NULL, pplayer, NULL, name, NULL, 0);
2103
2104 fc_assert(ret);
2105}
2106
2107/**********************************************************************/
2113static enum diplstate_type
2114get_default_diplstate(const struct player *pplayer1,
2115 const struct player *pplayer2)
2116{
2117 players_iterate_alive(pplayer3) {
2118 if (pplayer3 != pplayer1
2119 && pplayer3 != pplayer2
2120 && pplayers_allied(pplayer3, pplayer1)
2121 && pplayers_allied(pplayer3, pplayer2)) {
2122 return DS_PEACE;
2123 }
2124 } players_iterate_alive_end;
2125
2126 return DS_WAR;
2127}
2128
2129/**********************************************************************/
2132 void make_contact(struct player *pplayer1, struct player *pplayer2,
2133 struct tile *ptile)
2134{
2135 struct player_diplstate *ds_plr1plr2, *ds_plr2plr1;
2136
2137 if (pplayer1 == pplayer2
2138 || !pplayer1->is_alive
2139 || !pplayer2->is_alive) {
2140 return;
2141 }
2142
2143 ds_plr1plr2 = player_diplstate_get(pplayer1, pplayer2);
2144 ds_plr2plr1 = player_diplstate_get(pplayer2, pplayer1);
2145
2146 if (get_player_bonus(pplayer1, EFT_NO_DIPLOMACY) <= 0
2147 && get_player_bonus(pplayer2, EFT_NO_DIPLOMACY) <= 0) {
2148 ds_plr1plr2->contact_turns_left = game.server.contactturns;
2149 ds_plr2plr1->contact_turns_left = game.server.contactturns;
2150 }
2151 if (ds_plr1plr2->type == DS_NO_CONTACT) {
2152 enum diplstate_type new_state = get_default_diplstate(pplayer1,
2153 pplayer2);
2154
2155 set_diplstate_type(ds_plr1plr2, ds_plr2plr1, new_state);
2156 ds_plr1plr2->first_contact_turn = game.info.turn;
2157 ds_plr2plr1->first_contact_turn = game.info.turn;
2158 notify_player(pplayer1, ptile, E_FIRST_CONTACT, ftc_server,
2159 _("You have made contact with the %s, ruled by %s."),
2160 nation_plural_for_player(pplayer2),
2161 player_name(pplayer2));
2162 notify_player(pplayer2, ptile, E_FIRST_CONTACT, ftc_server,
2163 _("You have made contact with the %s, ruled by %s."),
2164 nation_plural_for_player(pplayer1),
2165 player_name(pplayer1));
2166 send_player_all_c(pplayer1, pplayer2->connections);
2167 send_player_all_c(pplayer2, pplayer1->connections);
2168 send_player_all_c(pplayer1, pplayer1->connections);
2169 send_player_all_c(pplayer2, pplayer2->connections);
2170 if (is_ai(pplayer1)) {
2171 call_first_contact(pplayer1, pplayer2);
2172 }
2173 if (is_ai(pplayer2)) {
2174 call_first_contact(pplayer2, pplayer1);
2175 }
2176 return;
2177 } else {
2178 fc_assert(ds_plr2plr1->type != DS_NO_CONTACT);
2179 }
2180 if (team_has_embassy(pplayer1->team, pplayer2)
2181 || team_has_embassy(pplayer2->team, pplayer1)) {
2182 return; /* Avoid sending too much info over the network */
2183 }
2184 send_player_all_c(pplayer1, pplayer1->connections);
2185 send_player_all_c(pplayer2, pplayer2->connections);
2186}
2187
2188/**********************************************************************/
2191 void maybe_make_contact(struct tile *ptile, struct player *pplayer)
2192{
2193 square_iterate(&(wld.map), ptile, 1, tile1) {
2194 struct city *pcity = tile_city(tile1);
2195 if (pcity) {
2196 make_contact(pplayer, city_owner(pcity), ptile);
2197 }
2198 unit_list_iterate_safe(tile1->units, punit) {
2199 make_contact(pplayer, unit_owner(punit), ptile);
2200 } unit_list_iterate_safe_end;
2201 } square_iterate_end;
2202}
2203
2204/**********************************************************************/
2207 void shuffle_players(void)
2208{
2209 /* shuffled_order is defined global */
2210 int n = player_slot_count();
2211 int i;
2212
2213 log_debug("shuffle_players: creating shuffled order");
2214
2215 for (i = 0; i < n; i++) {
2216 shuffled_order[i] = i;
2217 }
2218
2219 /* randomize it */
2220 array_shuffle(shuffled_order, n);
2221
2222#ifdef FREECIV_DEBUG
2223 for (i = 0; i < n; i++) {
2224 log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2225 }
2226#endif /* FREECIV_DEBUG */
2227}
2228
2229/**********************************************************************/
2232 void set_shuffled_players(int *shuffled_players)
2233{
2234 int i;
2235
2236 log_debug("set_shuffled_players: loading shuffled array %p",
2237 shuffled_players);
2238
2239 for (i = 0; i < player_slot_count(); i++) {
2240 shuffled_order[i] = shuffled_players[i];
2241 log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2242 }
2243}
2244
2245/**********************************************************************/
2250 struct player *shuffled_player(int i)
2251{
2252 struct player *pplayer;
2253
2254 pplayer = player_by_number(shuffled_order[i]);
2255 log_debug("shuffled_player(%d) = %d (%s)",
2256 i, shuffled_order[i], player_name(pplayer));
2257 return pplayer;
2258}
2259
2260/**********************************************************************/
2282 struct nation_type *pick_a_nation(const struct nation_list *choices,
2283 bool ignore_conflicts,
2284 bool needs_startpos,
2285 enum barbarian_type barb_type)
2286{
2287 enum {
2288 UNAVAILABLE, AVAILABLE, PREFERRED, UNWANTED
2289 } nations_used[nation_count()], looking_for;
2290 int match[nation_count()], pick, idx;
2291 int num_avail_nations = 0, num_pref_nations = 0;
2292
2293 /* Values of nations_used:
2294 * UNAVAILABLE - nation is already used or is a special nation.
2295 * AVAILABLE - we can use this nation.
2296 * PREFERRED - we can use this nation and it is on the choices list.
2297 * UNWANTED - we can use this nation, but we really don't want to. */
2298 nations_iterate(pnation) {
2299 idx = nation_index(pnation);
2300
2301 if (!nation_is_in_current_set(pnation)
2302 || pnation->player
2303 || (needs_startpos && game.scenario.startpos_nations
2304 && pnation->server.no_startpos)
2305 || (barb_type != nation_barbarian_type(pnation))
2306 || (barb_type == NOT_A_BARBARIAN && !is_nation_playable(pnation))) {
2307 /* Nation is unplayable or already used: don't consider it.
2308 * (If nations aren't currently restricted to those with start
2309 * positions, we do nothing special here, but generate_players() will
2310 * tend to prefer them.) */
2311 nations_used[idx] = UNAVAILABLE;
2312 match[idx] = 0;
2313 continue;
2314 }
2315
2316 nations_used[idx] = AVAILABLE;
2317
2318 /* Determine which nations look good with nations already in the game,
2319 * or conflict with them. */
2320 match[idx] = 1;
2321 players_iterate(pplayer) {
2322 if (pplayer->nation != NO_NATION_SELECTED) {
2323 int x = nations_match(pnation, nation_of_player(pplayer),
2324 ignore_conflicts);
2325 if (x < 0) {
2326 log_debug("Nations '%s' (nb %d) and '%s' (nb %d) are in conflict.",
2327 nation_rule_name(pnation), nation_number(pnation),
2328 nation_rule_name(nation_of_player(pplayer)),
2329 nation_number(nation_of_player(pplayer)));
2330 nations_used[idx] = UNWANTED;
2331 match[idx] -= x * 100;
2332 break;
2333 } else {
2334 match[idx] += x * 100;
2335 }
2336 }
2337 } players_iterate_end;
2338
2339 if (AVAILABLE == nations_used[idx]) {
2340 num_avail_nations += match[idx];
2341 }
2342 } nations_iterate_end;
2343
2344 /* Mark as preferred those nations which are on the choices list and
2345 * which are AVAILABLE, but no UNWANTED */
2346 if (NULL != choices) {
2347 nation_list_iterate(choices, pnation) {
2348 idx = nation_index(pnation);
2349 if (nations_used[idx] == AVAILABLE) {
2350 num_pref_nations += match[idx];
2351 nations_used[idx] = PREFERRED;
2352 }
2353 } nation_list_iterate_end;
2354 }
2355
2356 if (0 < num_pref_nations || 0 < num_avail_nations) {
2357 if (0 < num_pref_nations) {
2358 /* Use a preferred nation only. */
2359 pick = fc_rand(num_pref_nations);
2360 looking_for = PREFERRED;
2361 log_debug("Picking a preferred nation.");
2362 } else {
2363 /* Use any available nation. */
2364 fc_assert(0 < num_avail_nations);
2365 pick = fc_rand(num_avail_nations);
2366 looking_for = AVAILABLE;
2367 log_debug("Picking an available nation.");
2368 }
2369
2370 nations_iterate(pnation) {
2371 idx = nation_index(pnation);
2372 if (nations_used[idx] == looking_for) {
2373 pick -= match[idx];
2374
2375 if (0 > pick) {
2376 return pnation;
2377 }
2378 }
2379 } nations_iterate_end;
2380 } else {
2381 /* No available nation: use unwanted nation... */
2382 struct nation_type *less_worst_nation = NO_NATION_SELECTED;
2383 int less_worst_score = -FC_INFINITY;
2384
2385 log_debug("Picking an unwanted nation.");
2386 nations_iterate(pnation) {
2387 idx = nation_index(pnation);
2388 if (UNWANTED == nations_used[idx]) {
2389 pick = -fc_rand(match[idx]);
2390 if (pick > less_worst_score) {
2391 less_worst_nation = pnation;
2392 less_worst_score = pick;
2393 }
2394 }
2395 } nations_iterate_end;
2396
2397 if (NO_NATION_SELECTED != less_worst_nation) {
2398 return less_worst_nation;
2399 }
2400 }
2401
2402 log_verbose("No nation found!");
2403
2404 return NO_NATION_SELECTED;
2405}
2406
2407/**********************************************************************/
2410 static struct nation_set *current_nationset(void)
2411{
2412 return nation_set_by_setting_value(game.server.nationset);
2413}
2414
2415/**********************************************************************/
2419 bool nation_is_in_current_set(const struct nation_type *pnation)
2420{
2421 return nation_is_in_set(pnation, current_nationset());
2422}
2423
2424/**********************************************************************/
2428 void count_playable_nations(void)
2429{
2430 server.playable_nations = 0;
2431 allowed_nations_iterate(pnation) {
2432 if (is_nation_playable(pnation)) {
2433 server.playable_nations++;
2434 }
2435 } allowed_nations_iterate_end;
2436}
2437
2438/**********************************************************************/
2443 bool client_can_pick_nation(const struct nation_type *pnation)
2444{
2445 fc_assert_ret_val(pnation != NULL, FALSE);
2446 return nation_is_in_current_set(pnation)
2447 && is_nation_playable(pnation)
2448 && (!game.scenario.startpos_nations
2449 || !pnation->server.no_startpos);
2450}
2451
2452/**********************************************************************/
2455 static void send_nation_availability_real(struct conn_list *dest,
2456 bool nationset_change)
2457{
2458 struct packet_nation_availability packet;
2459
2460 packet.ncount = nation_count();
2461 packet.nationset_change = nationset_change;
2462 nations_iterate(pnation) {
2463 packet.is_pickable[nation_index(pnation)] = client_can_pick_nation(pnation);
2464 } nations_iterate_end;
2465 lsend_packet_nation_availability(dest, &packet);
2466}
2467
2468/**********************************************************************/
2471 void send_nation_availability(struct conn_list *dest,
2472 bool nationset_change)
2473{
2474 if (0 < player_info_frozen_level) {
2475 return; /* Discard, see comment for player_info_freeze(). */
2476 } else {
2477 send_nation_availability_real(dest, nationset_change);
2478 }
2479}
2480
2481/**********************************************************************/
2488 void fit_nationset_to_players(void)
2489{
2490 int ncount = nation_set_count();
2491 int misfits[ncount];
2492
2493 memset(misfits, 0, sizeof(misfits));
2494
2495 nation_sets_iterate(pset) {
2496 players_iterate(pplayer) {
2497 if (pplayer->nation != NO_NATION_SELECTED
2498 && !nation_is_in_set(pplayer->nation, pset)) {
2499 misfits[nation_set_index(pset)]++;
2500 }
2501 } players_iterate_end;
2502 } nation_sets_iterate_end;
2503
2504 if (misfits[nation_set_index(current_nationset())] == 0) {
2505 /* Current set is OK. */
2506 return;
2507 }
2508
2509 /* Otherwise, pick the least bad set (requires unsetting fewest
2510 * players, possibly none). */
2511 {
2512 int i, least_misfits;
2513 const struct nation_set *best;
2514
2515 fc_assert(ncount > 0);
2516
2517 best = nation_set_by_number(0);
2518 least_misfits = misfits[0];
2519 for (i = 1; i < ncount && least_misfits != 0; i++) {
2520 if (best == NULL || misfits[i] < least_misfits) {
2521 best = nation_set_by_number(i);
2522 least_misfits = misfits[i];
2523 }
2524 }
2525
2526 log_verbose("Current nationset \"%s\" doesn't fit all existing players.",
2527 nation_set_rule_name(current_nationset()));
2528 log_verbose("Selected nationset \"%s\".", nation_set_rule_name(best));
2529 fc_strlcpy(game.server.nationset, nation_set_rule_name(best),
2530 sizeof(game.server.nationset));
2531 count_playable_nations();
2532 /* No need to refresh clients, as we're assumed to be in the middle of
2533 * loading a savegame and will send new setting/availability later
2534 * along with everything else */
2535 }
2536
2537 /* The set we chose may not fit all the players; as a last resort,
2538 * unset nations (caller must then arrange new assignments). */
2539 players_iterate(pplayer) {
2540 if (pplayer->nation != NO_NATION_SELECTED
2541 && !nation_is_in_current_set(pplayer->nation)) {
2542 log_verbose("Nation %s of player %s not in nationset \"%s\", unsetting.",
2543 nation_plural_for_player(pplayer), player_name(pplayer),
2544 nation_set_rule_name(current_nationset()));
2545 player_set_nation(pplayer, NO_NATION_SELECTED);
2546 }
2547 } players_iterate_end;
2548}
2549
2550/**********************************************************************/
2553 void reset_all_start_commands(bool plrchange)
2554{
2555 if (S_S_INITIAL != server_state()) {
2556 return;
2557 }
2558 players_iterate(pplayer) {
2559 if (pplayer->is_ready) {
2560 bool persistent = FALSE;
2561
2562 if (plrchange) {
2563 switch (game.info.persistent_ready)
2564 {
2565 case PERSISTENTR_DISABLED:
2566 persistent = FALSE;
2567 break;
2568 case PERSISTENTR_CONNECTED:
2569 persistent = pplayer->is_connected;
2570 break;
2571 }
2572 }
2573
2574 if (!persistent) {
2575 pplayer->is_ready = FALSE;
2576 send_player_info_c(pplayer, game.est_connections);
2577 }
2578 }
2579 } players_iterate_end;
2580}
2581
2582/**********************************************************************/
2588 static struct player *split_player(struct player *pplayer)
2589{
2590 struct research *new_research, *old_research;
2591 struct player *cplayer;
2592 struct nation_type *rebel_nation;
2593
2594 /* make a new player, or not */
2595 cplayer = server_create_player(-1, ai_name(pplayer->ai),
2596 NULL, FALSE);
2597 if (!cplayer) {
2598 return NULL;
2599 }
2600
2601 /* While this sets player->economic according to max rates as know at this point,
2602 * we redo that later, so that MaxRates effect requirements will be evaluated
2603 * with more completely set up player (e.g. correct government) */
2604 server_player_init(cplayer, TRUE, TRUE);
2605
2606 /* Rebel will always be an AI player */
2607 rebel_nation = pick_a_nation(nation_of_player(pplayer)->server.civilwar_nations,
2608 TRUE, FALSE, NOT_A_BARBARIAN);
2609 player_nation_defaults(cplayer, rebel_nation, TRUE);
2610
2611 fc_assert(game_was_started());
2612 /* Find a color for the new player. */
2613 assign_player_colors();
2614
2615 /* Send information about the used player slot to all connections. */
2616 send_player_info_c(cplayer, NULL);
2617
2618 sz_strlcpy(cplayer->username, _(ANON_USER_NAME));
2619 cplayer->unassigned_user = TRUE;
2620 cplayer->is_connected = FALSE;
2621 cplayer->government = init_government_of_nation(nation_of_player(cplayer));
2622 fc_assert(cplayer->revolution_finishes < 0);
2623 /* No capital for the splitted player. */
2624 cplayer->server.got_first_city = FALSE;
2625
2626 players_iterate(other_player) {
2627 struct player_diplstate *ds_co
2628 = player_diplstate_get(cplayer, other_player);
2629 struct player_diplstate *ds_oc
2630 = player_diplstate_get(other_player, cplayer);
2631
2632 if (get_player_bonus(other_player, EFT_NO_DIPLOMACY) > 0) {
2633 /* FIXME: What about No-contact war? */
2634 set_diplstate_type(ds_co, ds_oc, DS_WAR);
2635 } else {
2636 set_diplstate_type(ds_co, ds_oc, DS_NO_CONTACT);
2637 }
2638
2639 ds_co->has_reason_to_cancel = 0;
2640 ds_co->turns_left = 0;
2641 ds_co->contact_turns_left = 0;
2642 ds_oc->has_reason_to_cancel = 0;
2643 ds_oc->turns_left = 0;
2644 ds_oc->contact_turns_left = 0;
2645
2646 /* Send so that other_player sees updated diplomatic info;
2647 * pplayer will be sent later anyway
2648 */
2649 if (other_player != pplayer) {
2650 send_player_all_c(other_player, other_player->connections);
2651 }
2652 } players_iterate_end;
2653
2654 /* Split the resources */
2655 cplayer->economic.gold = pplayer->economic.gold;
2656 cplayer->economic.gold /= 2;
2657 pplayer->economic.gold -= cplayer->economic.gold;
2658
2659 /* Copy the research */
2660 new_research = research_get(cplayer);
2661 old_research = research_get(pplayer);
2662
2663 new_research->bulbs_researched = 0;
2664 new_research->techs_researched = old_research->techs_researched;
2665 new_research->researching = old_research->researching;
2666 new_research->future_tech = old_research->future_tech;
2667 new_research->tech_goal = old_research->tech_goal;
2668
2669 advance_index_iterate(A_NONE, i) {
2670 if (TECH_KNOWN == research_invention_state(old_research, i)) {
2671 research_invention_set(new_research, i, TECH_KNOWN);
2672 new_research->inventions[i].bulbs_researched_saved
2673 = old_research->inventions[i].bulbs_researched_saved;
2674 }
2675 } advance_index_iterate_end;
2676 cplayer->phase_done = TRUE; /* Have other things to think
2677 about - paralysis */
2678 BV_CLR_ALL(cplayer->real_embassy); /* all embassies destroyed */
2679 research_update(new_research);
2680
2681 /* Do the ai */
2682 set_as_ai(cplayer);
2683 cplayer->ai_common.maxbuycost = pplayer->ai_common.maxbuycost;
2684 cplayer->ai_common.warmth = pplayer->ai_common.warmth;
2685 cplayer->ai_common.frost = pplayer->ai_common.frost;
2686 set_ai_level_direct(cplayer, game.info.skill_level);
2687
2688 /* change the original player */
2689 if (government_of_player(pplayer) != game.government_during_revolution) {
2690 pplayer->target_government = pplayer->government;
2691 pplayer->government = game.government_during_revolution;
2692 pplayer->revolution_finishes = game.info.turn + 1;
2693 }
2694 old_research->bulbs_researched = 0;
2695 old_research->researching_saved = A_UNKNOWN;
2696 BV_CLR_ALL(pplayer->real_embassy); /* all embassies destroyed */
2697
2698 /* give splitted player the embassies to their team mates back, if any */
2699 if (pplayer->team) {
2700 players_iterate(pdest) {
2701 if (pplayer->team == pdest->team
2702 && pplayer != pdest) {
2703 establish_embassy(pplayer, pdest);
2704 }
2705 } players_iterate_end;
2706 }
2707 research_update(old_research);
2708
2709 player_limit_to_max_rates(pplayer);
2710
2711 /* Copy the maps */
2712
2713 give_map_from_player_to_player(pplayer, cplayer);
2714
2715 pplayer->server.border_vision = cplayer->server.border_vision;
2716
2717 /* Not sure if this is necessary, but might be a good idea
2718 * to avoid doing some ai calculations with bogus data. */
2719 adv_data_phase_init(cplayer, TRUE);
2720 CALL_PLR_AI_FUNC(phase_begin, cplayer, cplayer, TRUE);
2721 CALL_PLR_AI_FUNC(gained_control, cplayer, cplayer);
2722 CALL_PLR_AI_FUNC(split_by_civil_war, pplayer, pplayer, cplayer);
2723 CALL_PLR_AI_FUNC(created_by_civil_war, cplayer, pplayer, cplayer);
2724
2725 player_limit_to_max_rates(cplayer);
2726
2727 return cplayer;
2728}
2729
2730/**********************************************************************/
2738 bool civil_war_possible(struct player *pplayer, bool conquering_city,
2739 bool honour_server_option)
2740{
2741 int n;
2742
2743 if (!game.info.civil_war_enabled) {
2744 return FALSE;
2745 }
2746
2747 n = city_list_size(pplayer->cities);
2748
2749 if (n - (conquering_city?1:0) < GAME_MIN_CIVILWARSIZE) {
2750 return FALSE;
2751 }
2752 if (honour_server_option) {
2753 return game.server.civilwarsize < GAME_MAX_CIVILWARSIZE
2754 && n >= game.server.civilwarsize;
2755 } else {
2756 return TRUE;
2757 }
2758}
2759
2760/**********************************************************************/
2785 bool civil_war_triggered(struct player *pplayer)
2786{
2787 /* Get base probabilities */
2788 int dice = fc_rand(100); /* Throw the dice */
2789 int prob = get_player_bonus(pplayer, EFT_CIVIL_WAR_CHANCE);
2790
2791 /* Now compute the contribution of the cities. */
2792 city_list_iterate(pplayer->cities, pcity) {
2793 if (city_unhappy(pcity)) {
2794 prob += game.info.civil_war_bonus_unhappy;
2795 }
2796 if (city_celebrating(pcity)) {
2797 prob += game.info.civil_war_bonus_celebrating;
2798 }
2799 } city_list_iterate_end;
2800
2801 log_verbose("Civil war chance for %s: prob %d, dice %d",
2802 player_name(pplayer), prob, dice);
2803
2804 return (dice < prob);
2805}
2806
2807/**********************************************************************/
2835 struct player *civil_war(struct player *pplayer)
2836{
2837 int i, j;
2838 struct player *cplayer;
2839 struct city *capital;
2840 struct city_list *defector_candidates;
2841 size_t plr_count;
2842
2843 /* It is possible that this function gets called after pplayer
2844 * died. Player pointers are safe even after death. */
2845 if (!pplayer->is_alive) {
2846 return NULL;
2847 }
2848
2849 plr_count = normal_player_count();
2850 if (plr_count >= MAX_NUM_PLAYERS) {
2851 /* No space to make additional player */
2852 log_normal(_("Could not throw %s into civil war - too many players"),
2853 nation_plural_for_player(pplayer));
2854 return NULL;
2855 }
2856
2857 if (plr_count >= game.server.max_players) {
2858 /* No space to make additional player */
2859 log_normal(_("Could not throw %s into civil war - maxplayers (%d) reached"),
2860 nation_plural_for_player(pplayer), game.server.max_players);
2861 return NULL;
2862 }
2863
2864 if (plr_count >= server.playable_nations) {
2865 /* No nation for additional player */
2866 log_normal(_("Could not throw %s into civil war - no available nations"),
2867 nation_plural_for_player(pplayer));
2868 return NULL;
2869 }
2870
2871 /* It doesn't make sense to try to split an empire of 1 city.
2872 * This should have been enforced by civil_war_possible(). */
2873 fc_assert_ret_val(city_list_size(pplayer->cities) > 1, NULL);
2874
2875 defector_candidates = city_list_new();
2876 city_list_iterate(pplayer->cities, pcity) {
2877 bool gameloss_present = FALSE;
2878
2879 /* Capital (probably new capital) won't defect */
2880 if (is_capital(pcity)) {
2881 continue;
2882 }
2883
2884 /* City hosting victim's GameLoss unit won't defect */
2885 unit_list_iterate(city_tile(pcity)->units, punit) {
2886 if (unit_owner(punit) == pplayer
2887 && unit_has_type_flag(punit, UTYF_GAMELOSS)) {
2888 gameloss_present = TRUE;
2889 break;
2890 }
2891 } unit_list_iterate_end;
2892
2893 if (gameloss_present) {
2894 continue;
2895 }
2896
2897 city_list_append(defector_candidates, pcity);
2898 } city_list_iterate_end;
2899
2900 if (city_list_size(defector_candidates) == 0) {
2901 log_verbose(_("Could not throw %s into civil war - no available cities"),
2902 nation_plural_for_player(pplayer));
2903 city_list_destroy(defector_candidates);
2904 return NULL;
2905 }
2906
2907 /* We're definitely going to create a new rebel player. */
2908
2909 cplayer = split_player(pplayer);
2910
2911 /* Before units, cities, so clients know name of new nation
2912 * (for debugging etc).
2913 */
2914 send_player_all_c(cplayer, NULL);
2915 send_player_all_c(pplayer, NULL);
2916
2917 /* Now split the empire */
2918
2919 log_verbose("%s civil war; created AI %s",
2920 nation_rule_name(nation_of_player(pplayer)),
2921 nation_rule_name(nation_of_player(cplayer)));
2922 notify_player(pplayer, NULL, E_CIVIL_WAR, ftc_server,
2923 _("Your nation is thrust into civil war."));
2924
2925 notify_player(pplayer, NULL, E_FIRST_CONTACT, ftc_server,
2926 /* TRANS: <leader> ... the Poles. */
2927 _("%s is the rebellious leader of the %s."),
2928 player_name(cplayer),
2929 nation_plural_for_player(cplayer));
2930
2931 j = city_list_size(defector_candidates); /* number left to process */
2932 /* Number to try to flip; ensure that at least one eligible city is
2933 * flipped */
2934 i = MAX(j/2, 1);
2935 city_list_iterate(defector_candidates, pcity) {
2936 fc_assert_action(!is_capital(pcity), continue);
2937 if (i >= j || (i > 0 && fc_rand(2) == 1)) {
2938 /* Transfer city and units supported by this city to the new owner.
2939 * We do NOT resolve stack conflicts here, but rather later.
2940 * Reason: if we have a transporter from one city which is carrying
2941 * a unit from another city, and both cities join the rebellion. If we
2942 * resolved stack conflicts for each city we would teleport the first
2943 * of the units we met since the other would have another owner. */
2944 if (transfer_city(cplayer, pcity, -1, FALSE, FALSE, FALSE, FALSE)) {
2945 log_verbose("%s declares allegiance to the %s.", city_name_get(pcity),
2946 nation_rule_name(nation_of_player(cplayer)));
2947 notify_player(pplayer, pcity->tile, E_CITY_LOST, ftc_server,
2948 /* TRANS: <city> ... the Poles. */
2949 _("%s declares allegiance to the %s."),
2950 city_link(pcity),
2951 nation_plural_for_player(cplayer));
2952 script_server_signal_emit("city_transferred", pcity, pplayer,
2953 cplayer, "civil_war");
2954 }
2955 i--;
2956 }
2957 j--;
2958 } city_list_iterate_end;
2959
2960 city_list_destroy(defector_candidates);
2961
2962 resolve_unit_stacks(pplayer, cplayer, FALSE);
2963
2964 i = city_list_size(cplayer->cities);
2965 fc_assert(i > 0); /* rebels should have got at least one city */
2966
2967 /* Choose a capital (random). */
2968 capital = city_list_get(cplayer->cities, fc_rand(i));
2969 city_build_free_buildings(capital);
2970 give_midgame_initial_units(cplayer, city_tile(capital));
2971
2972 notify_player(NULL, NULL, E_CIVIL_WAR, ftc_server,
2973 /* TRANS: ... Danes ... Poles ... <7> cities. */
2974 PL_("Civil war partitions the %s;"
2975 " the %s now hold %d city.",
2976 "Civil war partitions the %s;"
2977 " the %s now hold %d cities.",
2978 i),
2979 nation_plural_for_player(pplayer),
2980 nation_plural_for_player(cplayer),
2981 i);
2982
2983 return cplayer;
2984}
2985
2986/**********************************************************************/
2989 void handle_player_attribute_chunk(struct player *pplayer,
2990 const struct packet_player_attribute_chunk
2991 *chunk)
2992{
2993 generic_handle_player_attribute_chunk(pplayer, chunk);
2994}
2995
2996/**********************************************************************/
2999 void handle_player_attribute_block(struct player *pplayer)
3000{
3001 send_attribute_block(pplayer, pplayer->current_conn);
3002}
3003
3004/**********************************************************************/
3007 void handle_player_phase_done(struct player *pplayer,
3008 int turn)
3009{
3010 if (turn != game.info.turn) {
3011 /* If this happens then the player actually pressed turn-done on a
3012 * previous turn but we didn't receive it until now. The player
3013 * probably didn't actually mean to end their turn! */
3014 return;
3015 }
3016 pplayer->phase_done = TRUE;
3017
3018 check_for_full_turn_done();
3019
3020 send_player_all_c(pplayer, NULL);
3021}
3022
3023/**********************************************************************/
3026 int barbarian_count(void)
3027{
3028 return server.nbarbarians;
3029}
3030
3031/**********************************************************************/
3034 int normal_player_count(void)
3035{
3036 return player_count() - server.nbarbarians;
3037}
3038
3039/**********************************************************************/
3042 void player_status_add(struct player *plr, enum player_status pstatus)
3043{
3044 BV_SET(plr->server.status, pstatus);
3045}
3046
3047/**********************************************************************/
3050 bool player_status_check(struct player *plr, enum player_status pstatus)
3051{
3052 return BV_ISSET(plr->server.status, pstatus);
3053}
3054
3055/**********************************************************************/
3058 void player_status_reset(struct player *plr)
3059{
3060 BV_CLR_ALL(plr->server.status);
3061 player_status_add(plr, PSTATUS_NORMAL);
3062}
3063
3064/**********************************************************************/
3067 const char *player_delegation_get(const struct player *pplayer)
3068{
3069 if (pplayer == NULL || strlen(pplayer->server.delegate_to) == 0) {
3070 /* No delegation if there is no player. */
3071 return NULL;
3072 } else {
3073 return pplayer->server.delegate_to;
3074 }
3075}
3076
3077/**********************************************************************/
3080 void player_delegation_set(struct player *pplayer, const char *username)
3081{
3082 fc_assert_ret(pplayer != NULL);
3083
3084 if (username == NULL || strlen(username) == 0) {
3085 pplayer->server.delegate_to[0] = '\0';
3086 } else {
3087 sz_strlcpy(pplayer->server.delegate_to, username);
3088 }
3089}
3090
3091/**********************************************************************/
3096 bool player_delegation_active(const struct player *pplayer)
3097{
3098 return (pplayer && strlen(pplayer->server.orig_username) != 0);
3099}
3100
3101/**********************************************************************/
3104 void send_delegation_info(const struct connection *pconn)
3105{
3106 if (game.info.is_new_game) {
3107 return;
3108 }
3109
3110 if (!pconn->observer
3111 && pconn->playing && player_delegation_get(pconn->playing) != NULL) {
3112 notify_conn(pconn->self, NULL, E_CONNECTION, ftc_server,
3113 /* TRANS: '/delegate cancel' is a server command and must not
3114 * be translated */
3115 _("User '%s' is currently allowed to take control of your "
3116 "player while you are away. Use '/delegate cancel' to "
3117 "revoke this access."),
3118 player_delegation_get(pconn->playing));
3119 }
3120
3121 {
3122 bool any_delegations = FALSE;
3123 players_iterate(aplayer) {
3124 if (player_delegation_get(aplayer) != NULL
3125 && strcmp(player_delegation_get(aplayer), pconn->username) == 0) {
3126 notify_conn(pconn->self, NULL, E_CONNECTION, ftc_server,
3127 _("Control of player '%s' is delegated to you."),
3128 player_name(aplayer));
3129 any_delegations = TRUE;
3130 }
3131 } players_iterate_end;
3132 if (any_delegations) {
3133 notify_conn(pconn->self, NULL, E_CONNECTION, ftc_server,
3134 /* TRANS: '/delegate take' is a server command and must not
3135 * be translated; but <player> should be translated. */
3136 _("Use '/delegate take <player>' to take control of a "
3137 "delegated player."));
3138 }
3139 }
3140}
3141
3142/**********************************************************************/
3147 struct player *player_by_user_delegated(const char *name)
3148{
3149 players_iterate(pplayer) {
3150 if (player_delegation_get(pplayer)
3151 && fc_strcasecmp(name, pplayer->server.orig_username) == 0) {
3152 return pplayer;
3153 }
3154 } players_iterate_end;
3155
3156 return NULL;
3157}
3158
3159/**********************************************************************/
3162 void playercolor_init(void)
3163{
3164 fc_assert_ret(game.server.plr_colors == NULL);
3165 game.server.plr_colors = rgbcolor_list_new();
3166}
3167
3168/**********************************************************************/
3171 void playercolor_free(void)
3172{
3173 if (game.server.plr_colors == NULL) {
3174 return;
3175 }
3176
3177 if (rgbcolor_list_size(game.server.plr_colors) > 0) {
3178 rgbcolor_list_iterate(game.server.plr_colors, prgbcolor) {
3179 rgbcolor_list_remove(game.server.plr_colors, prgbcolor);
3180 rgbcolor_destroy(prgbcolor);
3181 } rgbcolor_list_iterate_end;
3182 };
3183 rgbcolor_list_destroy(game.server.plr_colors);
3184 game.server.plr_colors = NULL;
3185}
3186
3187/**********************************************************************/
3190 void playercolor_add(struct rgbcolor *prgbcolor)
3191{
3192 fc_assert_ret(game.server.plr_colors != NULL);
3193
3194 rgbcolor_list_append(game.server.plr_colors, prgbcolor);
3195}
3196
3197/**********************************************************************/
3200 struct rgbcolor *playercolor_get(int id)
3201{
3202 fc_assert_ret_val(game.server.plr_colors != NULL, NULL);
3203
3204 return rgbcolor_list_get(game.server.plr_colors, id);
3205}
3206
3207/**********************************************************************/
3210 int playercolor_count(void)
3211{
3212 fc_assert_ret_val(game.server.plr_colors != NULL, -1);
3213
3214 return rgbcolor_list_size(game.server.plr_colors);
3215}
3216
3217/**********************************************************************/
3220 void handle_player_multiplier(struct player *pplayer, int count,
3221 const int *multipliers)
3222{
3223 int rval;
3224 int i;
3225
3226 if (count != multiplier_count()) {
3227 log_error("Bad number of multipliers %d from client for %s",
3228 count, player_name(pplayer));
3229 return;
3230 }
3231
3232 for (i = 0; i < count; i++) {
3233 struct multiplier *pmul = multiplier_by_number(i);
3234
3235 if (multiplier_can_be_changed(pmul, pplayer)) {
3236 if (multipliers[i] < pmul->start || multipliers[i] > pmul->stop) {
3237 log_error("Multiplier value %d for %s out of range for %s",
3238 multipliers[i], multiplier_rule_name(pmul),
3239 player_name(pplayer));
3240 } else {
3241 rval = (multipliers[i] - pmul->start) / pmul->step * pmul->step + pmul->start;
3242 if (rval != multipliers[i]) {
3243 log_error("Multiplier value %d between valid values for %s for %s",
3244 multipliers[i], multiplier_rule_name(pmul),
3245 player_name(pplayer));
3246 } else {
3247 pplayer->multipliers[i].target = multipliers[i];
3248 }
3249 }
3250 }
3251 }
3252
3253 send_player_info_c(pplayer, NULL);
3254}
3255
3256/**********************************************************************/
3259 void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
3260{
3261 set_as_ai(pplayer);
3262
3263 set_ai_level_directer(pplayer, skill_level);
3264 cancel_all_meetings(pplayer);
3265 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
3266 if (is_player_phase(pplayer, game.info.phase)) {
3267 CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
3268 }
3269
3270 if (S_S_RUNNING == server_state()) {
3271 /* In case this was last player who has not pressed turn done. */
3272 check_for_full_turn_done();
3273 }
3274
3275 fc_assert(pplayer->ai_common.skill_level == skill_level);
3276}
3277
3278/**********************************************************************/
3281 void player_set_under_human_control(struct player *pplayer)
3282{
3283 set_as_human(pplayer);
3284
3285 if (pplayer->ai_common.skill_level == AI_LEVEL_AWAY) {
3286 pplayer->ai_common.skill_level = ai_level_invalid();
3287 }
3288
3289 CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
3290
3291 /* Because the AI "cheats" with government rates but humans shouldn't. */
3292 if (!game.info.is_new_game) {
3293 check_player_max_rates(pplayer);
3294 }
3295 cancel_all_meetings(pplayer);
3296}
adv_data_close
void adv_data_close(struct player *pplayer)
Definition advdata.c:741
adv_data_init
void adv_data_init(struct player *pplayer)
Definition advdata.c:686
adv_data_phase_init
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:262
adv_data_default
void adv_data_default(struct player *pplayer)
Definition advdata.c:718
advdata.h
ai_name
const char * ai_name(const struct ai_type *ai)
Definition ai.c:329
ai_type_name_or_fallback
const char * ai_type_name_or_fallback(const char *orig_name)
Definition ai.c:340
ai_type_by_name
struct ai_type * ai_type_by_name(const char *search)
Definition ai.c:284
CALL_FUNC_EACH_AI
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
INCIDENT_WAR
@ INCIDENT_WAR
Definition ai.h:46
CALL_PLR_AI_FUNC
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
call_incident
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
aiiface.h
ai_traits_close
void ai_traits_close(struct player *pplayer)
Definition aitraits.c:58
aitraits.h
n
#define n
Definition astring.c:77
autosettlers.h
create_barbarian_player
struct player * create_barbarian_player(enum barbarian_type type)
Definition barbarian.c:97
barbarian.h
bitvector.h
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
BV_CLR
#define BV_CLR(bv, bit)
Definition bitvector.h:86
citizens_nation_move
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_nation_get
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
citizens.h
is_capital
bool is_capital(const struct city *pcity)
Definition city.c:1544
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1106
city_unhappy
bool city_unhappy(const struct city *pcity)
Definition city.c:1591
city_celebrating
bool city_celebrating(const struct city *pcity)
Definition city.c:1610
cities_iterate_end
#define cities_iterate_end
Definition city.h:497
city_list_iterate_safe
#define city_list_iterate_safe(citylist, _city)
Definition city.h:502
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:488
city_tile
#define city_tile(_pcity_)
Definition city.h:544
cities_iterate
#define cities_iterate(pcity)
Definition city.h:492
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:490
city_list_iterate_safe_end
#define city_list_iterate_safe_end
Definition city.h:524
city_build_free_buildings
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1410
sync_cities
void sync_cities(void)
Definition citytools.c:3224
city_map_update_all_cities_for_player
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3258
remove_city
void remove_city(struct city *pcity)
Definition citytools.c:1675
remove_trade_route
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2835
transfer_city
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:1065
citytools.h
city_refresh_queue_add
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:199
city_refresh_for_player
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:184
city_refresh_queue_processing
void city_refresh_queue_processing(void)
Definition cityturn.c:215
cityturn.h
connection_detach
void connection_detach(struct connection *pconn, bool remove_unused_player)
Definition connecthand.c:765
connecthand.h
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:113
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:115
player_culture
int player_culture(const struct player *plr)
Definition culture.c:46
culture.h
punit
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
set_ai_level_directer
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Definition difficulty.c:39
difficulty.h
establish_embassy
void establish_embassy(struct player *pplayer, struct player *aplayer)
Definition diplhand.c:724
reject_all_treaties
void reject_all_treaties(struct player *pplayer)
Definition diplhand.c:962
set_diplstate_type
void set_diplstate_type(struct player_diplstate *state1, struct player_diplstate *state2, enum diplstate_type type)
Definition diplhand.c:159
cancel_all_meetings
void cancel_all_meetings(struct player *pplayer)
Definition diplhand.c:950
diplhand.h
could_intel_with_player
bool could_intel_with_player(const struct player *pplayer, const struct player *aplayer)
Definition diptreaty.c:81
diptreaty.h
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:789
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
extra_owner
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1068
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:315
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
citizens
unsigned char citizens
Definition fc_types.h:358
Impr_type_id
int Impr_type_id
Definition fc_types.h:346
MAX_NUM_PLAYERS
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
revolen_type
revolen_type
Definition fc_types.h:1134
REVOLEN_RANDOM
@ REVOLEN_RANDOM
Definition fc_types.h:1136
REVOLEN_RANDQUICK
@ REVOLEN_RANDQUICK
Definition fc_types.h:1138
REVOLEN_FIXED
@ REVOLEN_FIXED
Definition fc_types.h:1135
REVOLEN_QUICKENING
@ REVOLEN_QUICKENING
Definition fc_types.h:1137
Government_type_id
int Government_type_id
Definition fc_types.h:351
MAX_NUM_PLAYER_SLOTS
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
fcintl.h
PL_
#define PL_(String1, String2, n)
Definition fcintl.h:71
_
#define _(String)
Definition fcintl.h:67
featured_text_apply_tag
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,...)
Definition featured_text.c:993
ftc_server
const struct ft_color ftc_server
Definition featured_text.c:77
city_link
const char * city_link(const struct city *pcity)
Definition featured_text.c:1072
ftc_any
const struct ft_color ftc_any
Definition featured_text.c:73
FT_OFFSET_UNSET
#define FT_OFFSET_UNSET
Definition featured_text.h:104
TTT_COLOR
@ TTT_COLOR
Definition featured_text.h:125
FT_COLOR
#define FT_COLOR(fg, bg)
Definition featured_text.h:145
game
struct civ_game game
Definition game.c:57
is_player_phase
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:687
wld
struct world wld
Definition game.c:58
GAME_DEFAULT_REVOLUTION_LENGTH
#define GAME_DEFAULT_REVOLUTION_LENGTH
Definition game.h:711
GAME_MIN_CIVILWARSIZE
#define GAME_MIN_CIVILWARSIZE
Definition game.h:470
GAME_MAX_CIVILWARSIZE
#define GAME_MAX_CIVILWARSIZE
Definition game.h:471
crole_to_unit_type
struct unit_type * crole_to_unit_type(char crole, struct player *pplayer)
Definition gamehand.c:118
gamehand.h
government_name_translation
const char * government_name_translation(const struct government *pgovern)
Definition government.c:142
untargeted_revolution_allowed
bool untargeted_revolution_allowed(void)
Definition government.c:564
government_count
Government_type_id government_count(void)
Definition government.c:70
government_by_number
struct government * government_by_number(const Government_type_id gov)
Definition government.c:102
government_of_player
struct government * government_of_player(const struct player *pplayer)
Definition government.c:113
government_name_for_player
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:153
can_change_to_government
bool can_change_to_government(struct player *pplayer, const struct government *gov)
Definition government.c:165
government_number
Government_type_id government_number(const struct government *pgovern)
Definition government.c:90
government_rule_name
const char * government_rule_name(const struct government *pgovern)
Definition government.c:132
government.h
type
GType type
Definition repodlgs.c:1312
persistent
static GtkWidget * persistent
Definition rallypointdlg.c:40
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps_init
void handicaps_init(struct player *pplayer)
Definition handicaps.c:29
handicaps_close
void handicaps_close(struct player *pplayer)
Definition handicaps.c:42
handicaps.h
H_REVOLUTION
@ H_REVOLUTION
Definition handicaps.h:30
H_RATES
@ H_RATES
Definition handicaps.h:23
improvement_by_number
struct impr_type * improvement_by_number(const Impr_type_id id)
Definition improvement.c:192
wonder_visible_to_player
bool wonder_visible_to_player(const struct impr_type *wonder, const struct player *pplayer, const struct player *owner)
Definition improvement.c:921
WONDER_NOT_BUILT
#define WONDER_NOT_BUILT
Definition improvement.h:152
B_LAST
#define B_LAST
Definition improvement.h:42
name
const char * name
Definition inputfile.c:127
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
log_verbose
#define log_verbose(message,...)
Definition log.h:109
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
fc_assert_action
#define fc_assert_action(condition, action)
Definition log.h:187
log_debug
#define log_debug(message,...)
Definition log.h:115
log_normal
#define log_normal(message,...)
Definition log.h:107
log_error
#define log_error(message,...)
Definition log.h:103
luascript_types.h
map_is_empty
bool map_is_empty(void)
Definition map.c:149
map.h
square_iterate
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:385
square_iterate_end
#define square_iterate_end
Definition map.h:388
whole_map_iterate
#define whole_map_iterate(_map, _tile)
Definition map.h:539
whole_map_iterate_end
#define whole_map_iterate_end
Definition map.h:548
player_map_init
void player_map_init(struct player *pplayer)
Definition maphand.c:1199
map_claim_base
void map_claim_base(struct tile *ptile, struct extra_type *pextra, struct player *powner, struct player *ploser)
Definition maphand.c:2366
map_claim_ownership
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2173
map_know_and_see_all
void map_know_and_see_all(struct player *pplayer)
Definition maphand.c:1174
give_map_from_player_to_player
void give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:381
remove_shared_vision
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1678
player_map_free
void player_map_free(struct player *pplayer)
Definition maphand.c:1215
map_calculate_borders
void map_calculate_borders(void)
Definition maphand.c:2339
remove_player_from_maps
void remove_player_from_maps(struct player *pplayer)
Definition maphand.c:1236
maphand.h
mem.h
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
player_mood
enum mood_type player_mood(struct player *pplayer)
Definition mood.c:28
mood.h
movement.h
multiplier_rule_name
const char * multiplier_rule_name(const struct multiplier *pmul)
Definition multipliers.c:106
multiplier_count
Multiplier_type_id multiplier_count(void)
Definition multipliers.c:88
multiplier_can_be_changed
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
Definition multipliers.c:137
multipliers
static struct multiplier multipliers[MAX_NUM_MULTIPLIERS]
Definition multipliers.c:23
multiplier_by_number
struct multiplier * multiplier_by_number(Multiplier_type_id id)
Definition multipliers.c:57
multiplier_index
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
multipliers.h
multipliers_iterate
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
multipliers_iterate_end
#define multipliers_iterate_end
Definition multipliers.h:67
nation_rule_name
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
nation_count
Nation_type_id nation_count(void)
Definition nation.c:506
nation_number
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:485
nation_leader_by_name
struct nation_leader * nation_leader_by_name(const struct nation_type *pnation, const char *name)
Definition nation.c:266
nations_match
int nations_match(const struct nation_type *pnation1, const struct nation_type *pnation2, bool ignore_conflicts)
Definition nation.c:1205
nation_set_index
int nation_set_index(const struct nation_set *pset)
Definition nation.c:698
nation_of_player
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
is_nation_playable
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:199
nation_color
const struct rgbcolor * nation_color(const struct nation_type *pnation)
Definition nation.c:681
nation_is_in_set
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Definition nation.c:836
nation_set_count
int nation_set_count(void)
Definition nation.c:690
nation_set_by_number
struct nation_set * nation_set_by_number(int id)
Definition nation.c:761
nation_set_by_setting_value
struct nation_set * nation_set_by_setting_value(const char *setting)
Definition nation.c:858
nation_index
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:497
nation_set_rule_name
const char * nation_set_rule_name(const struct nation_set *pset)
Definition nation.c:806
nation_barbarian_type
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:210
nation_plural_for_player
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
init_government_of_nation
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:658
nation.h
nation_list_iterate
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:83
nation_sets_iterate_end
#define nation_sets_iterate_end
Definition nation.h:304
nation_sets_iterate
#define nation_sets_iterate(NAME_pset)
Definition nation.h:300
nations_iterate_end
#define nations_iterate_end
Definition nation.h:335
nation_list_iterate_end
#define nation_list_iterate_end
Definition nation.h:85
nations_iterate
#define nations_iterate(NAME_pnation)
Definition nation.h:332
NATION_NONE
#define NATION_NONE
Definition nation.h:32
NO_NATION_SELECTED
#define NO_NATION_SELECTED
Definition nation.h:29
notify_player
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:292
notify_conn
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:239
notify.h
generic_handle_player_attribute_chunk
void generic_handle_player_attribute_chunk(struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
Definition packets.c:690
send_attribute_block
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
Definition packets.c:746
packets.h
web_send_packet
#define web_send_packet(packetname,...)
Definition packets.h:52
dsend_packet_player_remove
int dsend_packet_player_remove(struct connection *pc, int playerno)
Definition packets_gen.c:32736
send_packet_player_diplstate
int send_packet_player_diplstate(struct connection *pc, const struct packet_player_diplstate *packet)
Definition packets_gen.c:36425
send_packet_player_info
int send_packet_player_info(struct connection *pc, const struct packet_player_info *packet)
Definition packets_gen.c:35010
lsend_packet_nation_availability
void lsend_packet_nation_availability(struct conn_list *dest, const struct packet_nation_availability *packet)
Definition packets_gen.c:64409
player_slot_is_used
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:441
player_new
struct player * player_new(struct player_slot *pslot)
Definition player.c:486
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:840
players_on_same_team
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1452
player_count
int player_count(void)
Definition player.c:808
cancel_pact_result
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Definition player.c:67
player_slot_count
int player_slot_count(void)
Definition player.c:411
player_slot_by_number
struct player_slot * player_slot_by_number(int player_id)
Definition player.c:456
player_get_expected_income
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1262
player_number
int player_number(const struct player *pplayer)
Definition player.c:828
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:886
player_clear
void player_clear(struct player *pplayer, bool full)
Definition player.c:660
player_slot_index
int player_slot_index(const struct player_slot *pslot)
Definition player.c:419
player_has_real_embassy
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:234
team_has_embassy
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:214
player_set_color
void player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition player.c:639
player_index
int player_index(const struct player *pplayer)
Definition player.c:820
player_set_nation
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:852
pplayer_can_cancel_treaty
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:92
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
gives_shared_vision
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1461
player_destroy
void player_destroy(struct player *pplayer)
Definition player.c:747
player.h
players_iterate_end
#define players_iterate_end
Definition player.h:535
dipl_reason
dipl_reason
Definition player.h:194
DIPL_SENATE_BLOCKING
@ DIPL_SENATE_BLOCKING
Definition player.h:195
DIPL_OK
@ DIPL_OK
Definition player.h:195
players_iterate
#define players_iterate(_pplayer)
Definition player.h:530
player_list_iterate
#define player_list_iterate(playerlist, pplayer)
Definition player.h:553
ANON_USER_NAME
#define ANON_USER_NAME
Definition player.h:48
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
is_ai
#define is_ai(plr)
Definition player.h:234
player_list_iterate_end
#define player_list_iterate_end
Definition player.h:555
set_as_human
#define set_as_human(plr)
Definition player.h:235
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:545
PLRCOL_PLR_RANDOM
@ PLRCOL_PLR_RANDOM
Definition player.h:52
PLRCOL_PLR_SET
@ PLRCOL_PLR_SET
Definition player.h:53
PLRCOL_NATION_ORDER
@ PLRCOL_NATION_ORDER
Definition player.h:55
PLRCOL_TEAM_ORDER
@ PLRCOL_TEAM_ORDER
Definition player.h:54
PLRCOL_PLR_ORDER
@ PLRCOL_PLR_ORDER
Definition player.h:51
set_as_ai
#define set_as_ai(plr)
Definition player.h:236
is_human
#define is_human(plr)
Definition player.h:233
players_iterate_alive
#define players_iterate_alive(_pplayer)
Definition player.h:540
handle_player_phase_done
void handle_player_phase_done(struct player *pplayer, int turn)
Definition plrhand.c:3007
send_nation_availability
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2471
handle_player_multiplier
void handle_player_multiplier(struct player *pplayer, int count, const int *multipliers)
Definition plrhand.c:3220
server_player_set_name
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2097
barbarian_count
int barbarian_count(void)
Definition plrhand.c:3026
send_player_all_c
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:983
send_player_remove_info_c
static void send_player_remove_info_c(const struct player_slot *pslot, struct conn_list *dest)
Definition plrhand.c:935
server_create_player
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1723
player_preferred_color
const struct rgbcolor * player_preferred_color(struct player *pplayer)
Definition plrhand.c:1503
player_update_last_war_action
void player_update_last_war_action(struct player *pplayer)
Definition plrhand.c:746
handle_player_attribute_chunk
void handle_player_attribute_chunk(struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
Definition plrhand.c:2989
player_status_add
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3042
normal_player_count
int normal_player_count(void)
Definition plrhand.c:3034
send_player_info_c_real
static void send_player_info_c_real(struct player *src, struct conn_list *dest)
Definition plrhand.c:1020
player_info_level
static enum plr_info_level player_info_level(struct player *plr, struct player *receiver)
Definition plrhand.c:1403
package_player_diplstate
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:1360
player_set_under_human_control
void player_set_under_human_control(struct player *pplayer)
Definition plrhand.c:3281
maybe_claim_base
static void maybe_claim_base(struct tile *ptile, struct player *new_owner, struct player *old_owner)
Definition plrhand.c:704
playercolor_free
void playercolor_free(void)
Definition plrhand.c:3171
current_nationset
static struct nation_set * current_nationset(void)
Definition plrhand.c:2410
give_midgame_initial_units
void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
Definition plrhand.c:1699
get_player_maxrate
static int get_player_maxrate(struct player *pplayer)
Definition plrhand.c:269
call_first_contact
static void call_first_contact(struct player *pplayer, struct player *aplayer)
Definition plrhand.c:1435
player_limit_to_max_rates
void player_limit_to_max_rates(struct player *pplayer)
Definition plrhand.c:1886
civil_war_triggered
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2785
server_player_set_color
void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition plrhand.c:1652
player_set_to_ai_mode
void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
Definition plrhand.c:3259
server_player_set_name_full
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:1997
player_delegation_active
bool player_delegation_active(const struct player *pplayer)
Definition plrhand.c:3096
player_info_thaw
void player_info_thaw(void)
Definition plrhand.c:964
player_info_freeze
void player_info_freeze(void)
Definition plrhand.c:955
player_by_user_delegated
struct player * player_by_user_delegated(const char *name)
Definition plrhand.c:3147
maybe_make_contact
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2191
handle_player_attribute_block
void handle_player_attribute_block(struct player *pplayer)
Definition plrhand.c:2999
send_nation_availability_real
static void send_nation_availability_real(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2455
pick_a_nation
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:2282
get_default_diplstate
static enum diplstate_type get_default_diplstate(const struct player *pplayer1, const struct player *pplayer2)
Definition plrhand.c:2114
playercolor_init
void playercolor_init(void)
Definition plrhand.c:3162
check_player_max_rates
void check_player_max_rates(struct player *pplayer)
Definition plrhand.c:657
kill_player
void kill_player(struct player *pplayer)
Definition plrhand.c:125
player_color_ftstr
const char * player_color_ftstr(struct player *pplayer)
Definition plrhand.c:1672
send_player_info_c
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1000
set_shuffled_players
void set_shuffled_players(int *shuffled_players)
Definition plrhand.c:2232
civil_war
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:2835
shuffled_order
static int shuffled_order[MAX_NUM_PLAYER_SLOTS]
Definition plrhand.c:114
player_status_reset
void player_status_reset(struct player *plr)
Definition plrhand.c:3058
send_delegation_info
void send_delegation_info(const struct connection *pconn)
Definition plrhand.c:3104
handle_player_change_government
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:454
player_reply_dest
struct conn_list * player_reply_dest(struct player *pplayer)
Definition plrhand.c:1425
update_players_after_alliance_breakup
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
revolentype_length
static int revolentype_length(enum revolen_type rltype, struct government *gov)
Definition plrhand.c:410
player_status_check
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3050
civil_war_possible
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2738
playercolor_get
struct rgbcolor * playercolor_get(int id)
Definition plrhand.c:3200
player_delegation_set
void player_delegation_set(struct player *pplayer, const char *username)
Definition plrhand.c:3080
server_player_name_is_allowed
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:1935
playercolor_count
int playercolor_count(void)
Definition plrhand.c:3210
shuffle_players
void shuffle_players(void)
Definition plrhand.c:2207
package_player_info
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
server_remove_player
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1772
government_change
void government_change(struct player *pplayer, struct government *gov, bool revolution_finished)
Definition plrhand.c:336
server_player_init
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1450
send_player_diplstate_c_real
static void send_player_diplstate_c_real(struct player *src, struct conn_list *dest)
Definition plrhand.c:1075
handle_diplomacy_cancel_pact
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:761
make_contact
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Definition plrhand.c:2132
playercolor_add
void playercolor_add(struct rgbcolor *prgbcolor)
Definition plrhand.c:3190
update_capital
void update_capital(struct player *pplayer)
Definition plrhand.c:612
count_playable_nations
void count_playable_nations(void)
Definition plrhand.c:2428
handle_player_rates
void handle_player_rates(struct player *pplayer, int tax, int luxury, int science)
Definition plrhand.c:285
player_color_changeable
bool player_color_changeable(const struct player *pplayer, const char **reason)
Definition plrhand.c:1546
assign_player_colors
void assign_player_colors(void)
Definition plrhand.c:1563
package_player_common
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
client_can_pick_nation
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2443
send_player_diplstate_c
void send_player_diplstate_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1059
split_player
static struct player * split_player(struct player *pplayer)
Definition plrhand.c:2588
shuffled_player
struct player * shuffled_player(int i)
Definition plrhand.c:2250
player_delegation_get
const char * player_delegation_get(const struct player *pplayer)
Definition plrhand.c:3067
nation_is_in_current_set
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2419
enter_war
void enter_war(struct player *pplayer, struct player *pplayer2)
Definition plrhand.c:729
player_info_frozen_level
static int player_info_frozen_level
Definition plrhand.c:117
revolution_length
int revolution_length(struct government *gov, struct player *plr)
Definition plrhand.c:438
fit_nationset_to_players
void fit_nationset_to_players(void)
Definition plrhand.c:2488
reset_all_start_commands
void reset_all_start_commands(bool plrchange)
Definition plrhand.c:2553
update_revolution
void update_revolution(struct player *pplayer)
Definition plrhand.c:553
plrhand.h
plr_info_level
plr_info_level
Definition plrhand.h:24
INFO_MEETING
@ INFO_MEETING
Definition plrhand.h:24
INFO_MINIMUM
@ INFO_MINIMUM
Definition plrhand.h:24
INFO_EMBASSY
@ INFO_EMBASSY
Definition plrhand.h:24
INFO_FULL
@ INFO_FULL
Definition plrhand.h:24
allowed_nations_iterate
#define allowed_nations_iterate(pnation)
Definition plrhand.h:67
allowed_nations_iterate_end
#define allowed_nations_iterate_end
Definition plrhand.h:71
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:34
research_invention_set
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Definition research.c:634
player_tech_upkeep
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1040
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:126
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
research_update
void research_update(struct research *presearch)
Definition research.c:499
research.h
rgbcolor_destroy
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
rgbcolors_are_equal
bool rgbcolors_are_equal(const struct rgbcolor *c1, const struct rgbcolor *c2)
Definition rgbcolor.c:62
rgbcolor_to_hex
bool rgbcolor_to_hex(const struct rgbcolor *prgbcolor, char *hex, size_t hex_len)
Definition rgbcolor.c:142
rgbcolor.h
rgbcolor_list_iterate_end
#define rgbcolor_list_iterate_end
Definition rgbcolor.h:45
rgbcolor_list_iterate
#define rgbcolor_list_iterate(rgbcolorlist, prgbcolor)
Definition rgbcolor.h:43
script_server_signal_emit
void script_server_signal_emit(const char *signal_name,...)
Definition script_server.c:408
script_server_remove_exported_object
void script_server_remove_exported_object(void *object)
Definition script_server.c:207
script_server.h
sernet.h
array_shuffle
void array_shuffle(int *array, int n)
Definition shared.c:1997
is_ascii_name
bool is_ascii_name(const char *name)
Definition shared.c:282
remove_leading_trailing_spaces
void remove_leading_trailing_spaces(char *s)
Definition shared.c:443
shared.h
CLIP
#define CLIP(lower, current, upper)
Definition shared.h:57
MIN
#define MIN(x, y)
Definition shared.h:55
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
MAX
#define MAX(x, y)
Definition shared.h:54
send_spaceship_info
void send_spaceship_info(struct player *src, struct conn_list *dest)
Definition spacerace.c:128
spacerace.h
spaceship_init
void spaceship_init(struct player_spaceship *ship)
Definition spaceship.c:96
spaceship.h
player_nation_defaults
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2510
game_was_started
bool game_was_started(void)
Definition srv_main.c:339
check_for_full_turn_done
void check_for_full_turn_done(void)
Definition srv_main.c:2145
server_state
enum server_states server_state(void)
Definition srv_main.c:323
srv_main.h
set_ai_level_direct
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:2003
stdinhand.h
city
Definition city.h:309
city::id
int id
Definition city.h:315
city::capital
enum capital_type capital
Definition city.h:317
civ_game::contactturns
int contactturns
Definition game.h:136
civ_game::plr_colors
struct rgbcolor_list * plr_colors
Definition game.h:242
civ_game::server
struct civ_game::@30::@34 server
civ_game::start_units
char start_units[MAX_LEN_STARTUNIT]
Definition game.h:188
civ_game::plrcolormode
enum plrcolor_mode plrcolormode
Definition game.h:127
civ_game::est_connections
struct conn_list * est_connections
Definition game.h:97
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::scenario
struct packet_scenario_info scenario
Definition game.h:87
civ_game::revealmap
unsigned revealmap
Definition game.h:176
civ_game::civilwarsize
int civilwarsize
Definition game.h:134
civ_game::savepalace
bool savepalace
Definition game.h:186
civ_game::nationset
char nationset[MAX_LEN_NAME]
Definition game.h:156
civ_game::max_players
int max_players
Definition game.h:155
civ_game::revolution_length
int revolution_length
Definition game.h:177
civ_game::government_during_revolution
struct government * government_during_revolution
Definition game.h:94
connection
Definition connection.h:141
connection::playing
struct player * playing
Definition connection.h:156
connection::access_level
enum cmdlevel access_level
Definition connection.h:182
connection::self
struct conn_list * self
Definition connection.h:168
connection::observer
bool observer
Definition connection.h:152
connection::username
char username[MAX_LEN_NAME]
Definition connection.h:169
ft_color
Definition featured_text.h:141
government
Definition government.h:52
government::changed_to_times
int changed_to_times
Definition government.h:60
multiplier_value::value
int value
Definition player.h:241
multiplier_value::target
int target
Definition player.h:243
multiplier_value::changed
int changed
Definition player.h:245
multiplier
Definition multipliers.h:31
multiplier::start
int start
Definition multipliers.h:35
multiplier::step
int step
Definition multipliers.h:37
multiplier::stop
int stop
Definition multipliers.h:36
music_style
Definition style.h:29
nation_set
Definition nation.c:40
nation_type
Definition nation.h:97
nation_type::barb_type
enum barbarian_type barb_type
Definition nation.h:109
nation_type::no_startpos
bool no_startpos
Definition nation.h:147
nation_type::server
struct nation_type::@50::@52 server
packet_game_info::gameloss_style
enum gameloss_style gameloss_style
Definition packets_gen.h:232
packet_game_info::citizen_nationality
bool citizen_nationality
Definition packets_gen.h:143
packet_game_info::is_new_game
bool is_new_game
Definition packets_gen.h:186
packet_game_info::civil_war_enabled
bool civil_war_enabled
Definition packets_gen.h:246
packet_game_info::skill_level
enum ai_level skill_level
Definition packets_gen.h:222
packet_game_info::revolentype
enum revolen_type revolentype
Definition packets_gen.h:169
packet_game_info::civil_war_bonus_unhappy
int civil_war_bonus_unhappy
Definition packets_gen.h:248
packet_game_info::turn
int turn
Definition packets_gen.h:241
packet_game_info::phase
int phase
Definition packets_gen.h:206
packet_game_info::persistent_ready
enum persistent_ready persistent_ready
Definition packets_gen.h:122
packet_game_info::civil_war_bonus_celebrating
int civil_war_bonus_celebrating
Definition packets_gen.h:247
packet_nation_availability
Definition packets_gen.h:1180
packet_nation_availability::ncount
int ncount
Definition packets_gen.h:1181
packet_nation_availability::is_pickable
bool is_pickable[MAX_NUM_NATIONS]
Definition packets_gen.h:1182
packet_nation_availability::nationset_change
bool nationset_change
Definition packets_gen.h:1183
packet_player_attribute_chunk
Definition packets_gen.h:591
packet_player_diplstate
Definition packets_gen.h:598
packet_player_diplstate::plr1
int plr1
Definition packets_gen.h:600
packet_player_diplstate::diplstate_id
int diplstate_id
Definition packets_gen.h:599
packet_player_diplstate::type
enum diplstate_type type
Definition packets_gen.h:602
packet_player_diplstate::has_reason_to_cancel
int has_reason_to_cancel
Definition packets_gen.h:604
packet_player_diplstate::turns_left
int turns_left
Definition packets_gen.h:603
packet_player_diplstate::plr2
int plr2
Definition packets_gen.h:601
packet_player_diplstate::contact_turns_left
int contact_turns_left
Definition packets_gen.h:605
packet_player_info
Definition packets_gen.h:519
packet_player_info::ai_skill_level
enum ai_level ai_skill_level
Definition packets_gen.h:549
packet_player_info::phase_done
bool phase_done
Definition packets_gen.h:536
packet_player_info::is_alive
bool is_alive
Definition packets_gen.h:539
packet_player_info::is_male
bool is_male
Definition packets_gen.h:525
packet_player_info::luxury
int luxury
Definition packets_gen.h:543
packet_player_info::turns_alive
int turns_alive
Definition packets_gen.h:538
packet_player_info::color_red
int color_red
Definition packets_gen.h:557
packet_player_info::is_ready
bool is_ready
Definition packets_gen.h:535
packet_player_info::multiplier
int multiplier[MAX_NUM_MULTIPLIERS]
Definition packets_gen.h:563
packet_player_info::username
char username[MAX_LEN_NAME]
Definition packets_gen.h:522
packet_player_info::tech_upkeep
int tech_upkeep
Definition packets_gen.h:545
packet_player_info::style
int style
Definition packets_gen.h:531
packet_player_info::culture
int culture
Definition packets_gen.h:553
packet_player_info::flags
bv_plr_flags flags
Definition packets_gen.h:560
packet_player_info::mood
enum mood_type mood
Definition packets_gen.h:530
packet_player_info::color_green
int color_green
Definition packets_gen.h:558
packet_player_info::color_valid
bool color_valid
Definition packets_gen.h:555
packet_player_info::gives_shared_vision
bv_player gives_shared_vision
Definition packets_gen.h:551
packet_player_info::team
int team
Definition packets_gen.h:534
packet_player_info::love
int love[MAX_NUM_PLAYER_SLOTS]
Definition packets_gen.h:554
packet_player_info::was_created
bool was_created
Definition packets_gen.h:526
packet_player_info::target_government
Government_type_id target_government
Definition packets_gen.h:528
packet_player_info::multiplier_target
int multiplier_target[MAX_NUM_MULTIPLIERS]
Definition packets_gen.h:564
packet_player_info::real_embassy
bool real_embassy[MAX_NUM_PLAYER_SLOTS]
Definition packets_gen.h:529
packet_player_info::is_connected
bool is_connected
Definition packets_gen.h:547
packet_player_info::unassigned_user
bool unassigned_user
Definition packets_gen.h:523
packet_player_info::multiplier_changed
int multiplier_changed[MAX_NUM_MULTIPLIERS]
Definition packets_gen.h:565
packet_player_info::nturns_idle
int nturns_idle
Definition packets_gen.h:537
packet_player_info::score
int score
Definition packets_gen.h:524
packet_player_info::multip_count
int multip_count
Definition packets_gen.h:562
packet_player_info::nation
Nation_type_id nation
Definition packets_gen.h:533
packet_player_info::science_cost
int science_cost
Definition packets_gen.h:546
packet_player_info::barbarian_type
enum barbarian_type barbarian_type
Definition packets_gen.h:550
packet_player_info::name
char name[MAX_LEN_NAME]
Definition packets_gen.h:521
packet_player_info::government
Government_type_id government
Definition packets_gen.h:527
packet_player_info::wonders
int wonders[B_LAST]
Definition packets_gen.h:561
packet_player_info::tax
int tax
Definition packets_gen.h:541
packet_player_info::music_style
int music_style
Definition packets_gen.h:532
packet_player_info::history
int history
Definition packets_gen.h:552
packet_player_info::science
int science
Definition packets_gen.h:542
packet_player_info::gold
int gold
Definition packets_gen.h:540
packet_player_info::revolution_finishes
int revolution_finishes
Definition packets_gen.h:548
packet_player_info::color_changeable
bool color_changeable
Definition packets_gen.h:556
packet_player_info::color_blue
int color_blue
Definition packets_gen.h:559
packet_player_info::infrapoints
int infrapoints
Definition packets_gen.h:544
packet_player_info::playerno
int playerno
Definition packets_gen.h:520
packet_scenario_info::startpos_nations
bool startpos_nations
Definition packets_gen.h:1609
packet_web_player_info_addition
Definition packets_gen.h:1873
packet_web_player_info_addition::expected_income
int expected_income
Definition packets_gen.h:1875
packet_web_player_info_addition::playerno
int playerno
Definition packets_gen.h:1874
player_ai::skill_level
enum ai_level skill_level
Definition player.h:122
player_ai::barbarian_type
enum barbarian_type barbarian_type
Definition player.h:128
player_ai::warmth
int warmth
Definition player.h:127
player_ai::science_cost
int science_cost
Definition player.h:125
player_ai::love
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:130
player_ai::maxbuycost
int maxbuycost
Definition player.h:120
player_ai::frost
int frost
Definition player.h:127
player_diplstate
Definition player.h:200
player_diplstate::contact_turns_left
char contact_turns_left
Definition player.h:206
player_diplstate::turns_left
char turns_left
Definition player.h:204
player_diplstate::first_contact_turn
int first_contact_turn
Definition player.h:203
player_diplstate::type
enum diplstate_type type
Definition player.h:201
player_diplstate::has_reason_to_cancel
char has_reason_to_cancel
Definition player.h:205
player_economic
Definition player.h:69
player_economic::luxury
int luxury
Definition player.h:73
player_economic::science
int science
Definition player.h:72
player_economic::tax
int tax
Definition player.h:71
player_economic::infra_points
int infra_points
Definition player.h:74
player_economic::gold
int gold
Definition player.h:70
player_score::units_killed
int units_killed
Definition player.h:112
player_score::units_lost
int units_lost
Definition player.h:113
player_score::game
int game
Definition player.h:116
player_score::units_built
int units_built
Definition player.h:111
player_slot
Definition player.c:45
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::ai_common
struct player_ai ai_common
Definition player.h:288
player::flags
bv_plr_flags flags
Definition player.h:292
player::status
bv_pstatus status
Definition player.h:318
player::primary_capital_id
int primary_capital_id
Definition player.h:275
player::is_male
bool is_male
Definition player.h:257
player::got_first_city
bool got_first_city
Definition player.h:320
player::wonders
int wonders[B_LAST]
Definition player.h:301
player::target_government
struct government * target_government
Definition player.h:259
player::username
char username[MAX_LEN_NAME]
Definition player.h:252
player::is_connected
bool is_connected
Definition player.h:296
player::revolution_finishes
int revolution_finishes
Definition player.h:273
player::nturns_idle
int nturns_idle
Definition player.h:265
player::government
struct government * government
Definition player.h:258
player::current_conn
struct connection * current_conn
Definition player.h:297
player::team
struct team * team
Definition player.h:261
player::savegame_ai_type_name
char * savegame_ai_type_name
Definition player.h:290
player::turns_alive
int turns_alive
Definition player.h:266
player::was_created
bool was_created
Definition player.h:294
player::ai
const struct ai_type * ai
Definition player.h:289
player::units
struct unit_list * units
Definition player.h:282
player::connections
struct conn_list * connections
Definition player.h:298
player::is_alive
bool is_alive
Definition player.h:268
player::real_embassy
bv_player real_embassy
Definition player.h:277
player::economic
struct player_economic economic
Definition player.h:284
player::delegate_to
char delegate_to[MAX_LEN_NAME]
Definition player.h:339
player::spaceship
struct player_spaceship spaceship
Definition player.h:286
player::name
char name[MAX_LEN_NAME]
Definition player.h:251
player::gives_shared_vision
bv_player gives_shared_vision
Definition player.h:299
player::score
struct player_score score
Definition player.h:283
player::private_map
struct player_tile * private_map
Definition player.h:324
player::multipliers
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:310
player::really_gives_vision
bv_player really_gives_vision
Definition player.h:329
player::nation
struct nation_type * nation
Definition player.h:260
player::style
struct nation_style * style
Definition player.h:279
player::border_vision
bool border_vision
Definition player.h:327
player::phase_done
bool phase_done
Definition player.h:263
player::slot
struct player_slot * slot
Definition player.h:250
player::server
struct player::@69::@71 server
player::is_ready
bool is_ready
Definition player.h:262
player::history
int history
Definition player.h:312
player::debug
bv_debug debug
Definition player.h:332
player::orig_username
char orig_username[MAX_LEN_NAME]
Definition player.h:347
player::last_war_action
int last_war_action
Definition player.h:270
player::rgb
struct rgbcolor * rgb
Definition player.h:308
player::unassigned_user
bool unassigned_user
Definition player.h:253
research::research_invention::bulbs_researched_saved
int bulbs_researched_saved
Definition research.h:80
research
Definition research.h:39
research::researching
Tech_type_id researching
Definition research.h:52
research::future_tech
int future_tech
Definition research.h:42
research::tech_goal
Tech_type_id tech_goal
Definition research.h:85
research::inventions
struct research::research_invention inventions[A_ARRAY_SIZE]
research::researching_saved
Tech_type_id researching_saved
Definition research.h:62
research::techs_researched
int techs_researched
Definition research.h:42
research::bulbs_researched
int bulbs_researched
Definition research.h:53
rgbcolor
Definition rgbcolor.h:33
rgbcolor::g
int g
Definition rgbcolor.h:34
rgbcolor::b
int b
Definition rgbcolor.h:34
rgbcolor::r
int r
Definition rgbcolor.h:34
server
Definition servers.h:29
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
tile::extras_owner
struct player * extras_owner
Definition tile.h:62
trade_route
Definition traderoutes.h:83
unit_type
Definition unittype.h:481
world::map
struct civ_map map
Definition world_object.h:38
player_music_style
struct music_style * player_music_style(struct player *plr)
Definition style.c:185
music_style_number
int music_style_number(const struct music_style *pms)
Definition style.c:161
style_number
int style_number(const struct nation_style *pstyle)
Definition style.c:68
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
fc_strlcpy
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:787
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:995
fc_toupper
char fc_toupper(char c)
Definition support.c:1271
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
fc__fallthrough
#define fc__fallthrough
Definition support.h:109
team_count
int team_count(void)
Definition team.c:375
team_number
int team_number(const struct team *pteam)
Definition team.c:391
team_add_player
bool team_add_player(struct player *pplayer, struct team *pteam)
Definition team.c:467
team_members
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
tech.h
advance_index_iterate_end
#define advance_index_iterate_end
Definition tech.h:248
A_NONE
#define A_NONE
Definition tech.h:43
A_UNKNOWN
#define A_UNKNOWN
Definition tech.h:49
advance_index_iterate
#define advance_index_iterate(_start, _index)
Definition tech.h:244
send_research_info
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
techtools.h
tile_has_claimable_base
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:209
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_owner
#define tile_owner(_tile)
Definition tile.h:95
trade_routes_iterate_safe_end
#define trade_routes_iterate_safe_end
Definition traderoutes.h:155
trade_routes_iterate_safe
#define trade_routes_iterate_safe(c, proute)
Definition traderoutes.h:137
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_safe
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_list_iterate_safe_end
#define unit_list_iterate_safe_end
Definition unitlist.h:61
get_units_seen_via_ally
struct unit_list * get_units_seen_via_ally(const struct player *pplayer, const struct player *aplayer)
Definition unittools.c:1433
remove_allied_visibility
void remove_allied_visibility(struct player *pplayer, struct player *aplayer, const struct unit_list *seen_units)
Definition unittools.c:1468
resolve_unit_stacks
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1418
create_unit
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:1619
wipe_unit
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2251
unittools.h
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
send_updated_vote_totals
void send_updated_vote_totals(struct conn_list *dest)
Definition voting.c:866
voting.h